diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-03-03 10:23:40 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-03-03 10:23:40 +1100 |
commit | acd121b46103b2115a2e7499fc80e23ddf03cee2 (patch) | |
tree | 8a5fdbd7be5e2789af4c004167164c020340425d | |
parent | faa70e9445a0a31fe0a49217ff2135b31ccce4ac (diff) |
Refactor tests a little
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 6adba4464..9df100d76 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1242,12 +1242,26 @@ describe RequestController, "when viewing an individual response for reply/follo end describe RequestController, "describe_state_requires_admin" do + let (:info_request) { info_requests(:fancy_dog_request) } + + before :each do + InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) + end + + context "logged out" do + 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 + context "logged in as owner of request" do - it "should set the state when classified as requires_admin" do - info_request = info_requests(:fancy_dog_request) - session[:user_id] = info_request.user_id + before (:each) { session[:user_id] = info_request.user_id } - InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) + 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" @@ -1255,30 +1269,18 @@ describe RequestController, "describe_state_requires_admin" do end context "logged in but not owner of request" do - it "should not allow you to change the state" do - info_request = info_requests(:fancy_dog_request) + before :each do session[:user_id] = users(:silly_name_user).id info_request.user_id.should_not == users(:silly_name_user).id + end - InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) + 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 - - context "logged out" do - it "should redirect to the login page" do - info_request = info_requests(:fancy_dog_request) - InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) - 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 describe RequestController, "when classifying an information request" do |