diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-03-03 14:13:17 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-03-03 14:13:17 +1100 |
commit | 0c983bd341192a3529193e5fcfa60cce0e05a2c2 (patch) | |
tree | 7056e3ee175680da5ee2c640c20c090463bbe8fd /spec/controllers/request_controller_spec.rb | |
parent | 9f6d66fbf16a37ee277f480a07043113ccf1dff8 (diff) |
Simplify controller test by mock behaviour in Ability
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 58 |
1 files changed, 13 insertions, 45 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index fa7c946d5..a82b3d952 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1245,7 +1245,6 @@ describe RequestController, "describe_state_requires_admin" do let (:info_request) { info_requests(:fancy_dog_request) } before :each do - info_request.stub!(:is_old_unclassified?).and_return(false) InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) end @@ -1257,65 +1256,34 @@ describe RequestController, "describe_state_requires_admin" do post_redirect = PostRedirect.get_last_post_redirect response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) end - - context "request is old and unclassified" do - before (:each) { info_request.stub!(:is_old_unclassified?).and_return(true) } - - it "should redirect to the login page" do - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" - - # Ugh. - post_redirect = PostRedirect.get_last_post_redirect - response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) - end - end - - end - - context "logged in as owner of request" do - before (:each) { session[:user_id] = info_request.user_id } - - it "should set the state when classified as requires_admin" do - info_request.should_receive(:set_described_state).with("requires_admin", nil, "Something weird happened") - - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" - end end - context "logged in but not owner of request" do + context "logged in" do let(:user) { users(:silly_name_user) } + before (:each) { session[:user_id] = user.id } - before :each do - session[:user_id] = user.id - info_request.user_id.should_not == user.id - end - - it "should not allow you to change the state" do - info_request.should_not_receive(:set_described_state) - - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" - response.should render_template('user/wrong_user') - end - - context "request is old and unclassified" do - before (:each) { info_request.stub!(:is_old_unclassified?).and_return(true) } + context "with permission to change the state" do + before (:each) do + Ability.should_receive(:can_update_request_state?).with(user, info_request).and_return(true) + end - it "should set the state" do + it "should set the state when classified as requires_admin" do info_request.should_receive(:set_described_state).with("requires_admin", nil, "Something weird happened") post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" end end - context "and has admin powers" do - before :each do - user.update_attribute(:admin_level, "super") + context "without permission to change the state" do + before :each do + Ability.should_receive(:can_update_request_state?).with(user, info_request).and_return(false) end - it "should set the state" do - info_request.should_receive(:set_described_state).with("requires_admin", nil, "Something weird happened") + it "should not allow you to change the state" do + info_request.should_not_receive(:set_described_state) post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" + response.should render_template('user/wrong_user') end end end |