spec/weeler/action_controller/acts/restful_spec.rb in weeler-1.0.2 vs spec/weeler/action_controller/acts/restful_spec.rb in weeler-1.0.3
- old
+ new
@@ -1,21 +1,27 @@
require 'spec_helper'
-describe Weeler::ActionController::Acts::Restful, :type => :controller do
+class Weeler::FoosController < Weeler::ContentController; end
+describe Weeler::ActionController::Acts::Restful, type: :controller do
+
before(:each) do
FactoryGirl.create_list(:dummy_post, 2)
end
- before(:all) do
- Dummy::Application.reload_routes!
+ before do
+ routes.draw do
+ mount_weeler_at "/weeler-admin" do
+ weeler_resources :foos
+ end
+ end
end
- describe "acts_as_restful", :type => :controller do
+ describe "acts_as_restful" do
context "permited title with array" do
- controller(Weeler::ContentController) do
+ controller Weeler::FoosController do
acts_as_restful Post, permit_params: [:title]
end
describe "model" do
it "returns current controller model" do
@@ -23,26 +29,36 @@
end
end
describe "actions" do
describe "GET #index" do
- it "returns success" do
+ specify "index returns success" do
+ routes.draw { get "index" => "weeler/foos#index" }
+
get "index"
- response.should be_success
+ expect(response).to be_success
end
- it "assigns posts" do
+ specify "assigns posts" do
+ routes.draw { get "index" => "weeler/foos#index" }
+
get "index"
expect(assigns(:items).size).to eq(2)
end
end
describe "POST #create" do
it "redirects to edit path" do
+ # routes.draw do
+ # mount_weeler_at "/weeler-admin" do
+ # weeler_resources :foos
+ # end
+ # end
+
post "create", post: attributes_for(:dummy_post)
post = Post.last
- expect(response).to redirect_to("http://test.host/anonymous/#{post.id}/edit")
+ expect(response).to redirect_to("http://test.host/weeler-admin/foos/#{post.id}/edit")
end
it "sets only permited params" do
post "create", post: attributes_for(:dummy_post, body: "Heila")
post = Post.last
@@ -52,18 +68,18 @@
end
describe "GET #edit" do
it "returns success status" do
get "edit", id: Post.last.id
- response.should be_success
+ expect(response).to be_success
end
end
describe "GET #new" do
it "returns success status" do
get "new"
- response.should be_success
+ expect(response).to be_success
end
end
describe "PUT #update" do
it "sets only permited params" do
@@ -82,11 +98,11 @@
expect { post.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
specify "POST #order" do
- routes.draw { post "order" => "anonymous#order" }
+ routes.draw { post "order" => "weeler/foos#order" }
post "order", orders: "order[]=2&order[]=1"
post1 = Post.order(sequence: :asc).first
post2 = Post.order(sequence: :asc).last
expect(post1.sequence).to eq(0)
@@ -95,11 +111,11 @@
end
end
end
context "no permited params" do
- controller(Weeler::ContentController) do
+ controller Weeler::FoosController do
acts_as_restful Post
end
describe "actions" do
describe "POST #create" do
@@ -109,19 +125,19 @@
expect(post.title).to eq(nil)
expect(post.body).to eq(nil)
end
it "warns developer" do
- controller.should_receive(:warn).with("[UNPERMITED PARAMS] To permiting {\"title\"=>\"Foo lala\", \"body\"=>\"Heila\"} params, add 'permit_params: [:title, :body]' option to 'acts_as_restful'")
- post "create", post: attributes_for(:dummy_post, title: "Foo lala", body: "Heila")
+ warning_message = "[UNPERMITED PARAMS] To permiting {\"title\"=>\"Foo lala\", \"body\"=>\"Heila\"} params, add 'permit_params: [:title, :body]' option to 'acts_as_restful'\n"
+ expect { post("create", post: attributes_for(:dummy_post, title: "Foo lala", body: "Heila")) }.to output(warning_message).to_stderr
end
end
end
end
context "permited all with block" do
- controller(Weeler::ContentController) do
+ controller Weeler::FoosController do
acts_as_restful Post, permit_params: -> (params) { params.require(:post).permit! }
end
describe "actions" do
describe "POST #create" do
@@ -135,10 +151,10 @@
end
end
context "permited all with block" do
- controller(Weeler::ContentController) do
+ controller Weeler::FoosController do
acts_as_restful Post, order_by: {id: :desc}, permit_params: [:title]
end
describe "GET #index" do
it "users order by for ordering" do