From 9d32b11bca733ed95308fcd7c129c209c87fb8f2 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sat, 2 Mar 2013 07:05:18 +1100 Subject: Test for forgetting to select the status --- spec/controllers/request_controller_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 21dd0853a..f4c501018 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1448,6 +1448,14 @@ describe RequestController, "when classifying an information request" do @dog_request.stub!(:each).and_return([@dog_request]) end + it "should let you know when you forget to select a status" do + post :describe_state, :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description, + :submitted_describe_state => 1 + response.should redirect_to request_url(@dog_request) + flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.") + end + it "should successfully classify response if logged in as user controlling request" do post_status('rejected') response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) -- cgit v1.2.3 From f52554c212e32bb2ff37abfb58d7eecdcd8d4cee Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sat, 2 Mar 2013 11:02:59 +1100 Subject: Test for situation where request changes while user is looking at it and they change the status --- spec/controllers/request_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f4c501018..fbd0c5ec5 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1456,6 +1456,16 @@ describe RequestController, "when classifying an information request" do flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.") end + it "should not change the status if the request has changed while viewing it" do + @dog_request.stub!(:last_event_id_needing_description).and_return(2) + + post :describe_state, :incoming_message => { :described_state => "rejected" }, + :id => @dog_request.id, :last_info_request_event_id => 1, + :submitted_describe_state => 1 + response.should redirect_to request_url(@dog_request) + flash[:error].should =~ /The request has been updated since you originally loaded this page/ + end + it "should successfully classify response if logged in as user controlling request" do post_status('rejected') response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) -- cgit v1.2.3 From c6eb7777a8d467ab6befc0974e44beb4f47f737a Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sat, 2 Mar 2013 13:43:57 +1100 Subject: Test for what happens when user is playing the classification game --- spec/controllers/request_controller_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index fbd0c5ec5..788ea9785 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1347,6 +1347,17 @@ describe RequestController, "when classifying an information request" do flash[:notice].should == 'Thank you for updating this request!' end + context "playing the classification game" do + before :each do + session[:request_game] = true + end + + it "should continue the game after classifying a request" do + post_status("rejected") + flash[:notice].should =~ /There are some more requests below for you to classify/ + response.should redirect_to play_url + end + end end end -- cgit v1.2.3 From fa624fc7f17b6b4b6710817ed63291386e525f9c Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sat, 2 Mar 2013 14:27:20 +1100 Subject: Use routes to only allow post to RequestController#describe_state --- spec/controllers/request_controller_spec.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 788ea9785..fdde54eeb 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1250,8 +1250,7 @@ describe RequestController, "when classifying an information request" do end it 'should redirect to the request page' do - post :describe_state, :id => @external_request.id, - :submitted_describe_state => 1 + post :describe_state, :id => @external_request.id response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @external_request.url_title) @@ -1271,8 +1270,7 @@ describe RequestController, "when classifying an information request" do def post_status(status) post :describe_state, :incoming_message => { :described_state => status }, :id => @dog_request.id, - :last_info_request_event_id => @dog_request.last_event_id_needing_description, - :submitted_describe_state => 1 + :last_info_request_event_id => @dog_request.last_event_id_needing_description end it "should require login" do @@ -1461,8 +1459,7 @@ describe RequestController, "when classifying an information request" do it "should let you know when you forget to select a status" do post :describe_state, :id => @dog_request.id, - :last_info_request_event_id => @dog_request.last_event_id_needing_description, - :submitted_describe_state => 1 + :last_info_request_event_id => @dog_request.last_event_id_needing_description response.should redirect_to request_url(@dog_request) flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.") end @@ -1471,8 +1468,7 @@ describe RequestController, "when classifying an information request" do @dog_request.stub!(:last_event_id_needing_description).and_return(2) post :describe_state, :incoming_message => { :described_state => "rejected" }, - :id => @dog_request.id, :last_info_request_event_id => 1, - :submitted_describe_state => 1 + :id => @dog_request.id, :last_info_request_event_id => 1 response.should redirect_to request_url(@dog_request) flash[:error].should =~ /The request has been updated since you originally loaded this page/ end @@ -1498,7 +1494,7 @@ describe RequestController, "when classifying an information request" do end it "should send email when classified as requires_admin" do - post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description, :submitted_describe_state => 1 + post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description response.should redirect_to(:controller => 'help', :action => 'contact') @dog_request.reload -- cgit v1.2.3 From 43230ddb09284bce0ef8635f805acc2a1190809a Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 28 Feb 2013 16:04:30 +1100 Subject: New request controller action for requires_admin state with message --- spec/controllers/request_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index fdde54eeb..6fcf43cab 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1509,6 +1509,22 @@ describe RequestController, "when classifying an information request" do mail.from_addrs.first.to_s.should == @request_owner.name_and_email end + it "should send an email with a message when classified as requires_admin" do + post :describe_state_requires_admin, :message => "Something weird happened", :id => @dog_request.id + + @dog_request.reload + @dog_request.awaiting_description.should == false + @dog_request.described_state.should == 'requires_admin' + @dog_request.get_last_response_event.calculated_state.should == 'requires_admin' + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /as needing admin/ + mail.body.should =~ /Something weird happened/ + mail.from_addrs.first.to_s.should == @request_owner.name_and_email + end + it 'should say it is showing advice as to what to do next' do post_status('rejected') flash[:notice].should match(/Here is what to do now/) -- cgit v1.2.3 From 260bd5bf263683919bac17ce8dfebd153a45e8aa Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sat, 2 Mar 2013 15:18:25 +1100 Subject: Switch to pretty urls --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 6fcf43cab..25ad1df5f 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1510,7 +1510,7 @@ describe RequestController, "when classifying an information request" do end it "should send an email with a message when classified as requires_admin" do - post :describe_state_requires_admin, :message => "Something weird happened", :id => @dog_request.id + post :describe_state_requires_admin, :message => "Something weird happened", :url_title => @dog_request.url_title @dog_request.reload @dog_request.awaiting_description.should == false -- cgit v1.2.3 From 00c188d129696353c48a2598ec7c747b8a90d658 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sun, 3 Mar 2013 09:40:21 +1100 Subject: Add basic authentication to new action --- spec/controllers/request_controller_spec.rb | 42 ++++++++++++++++++----------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 25ad1df5f..be9df90c4 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1241,6 +1241,32 @@ describe RequestController, "when viewing an individual response for reply/follo end +describe RequestController, "describe_state_requires_admin" do + 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 + + InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) + 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 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 describe 'if the request is external' do @@ -1509,22 +1535,6 @@ describe RequestController, "when classifying an information request" do mail.from_addrs.first.to_s.should == @request_owner.name_and_email end - it "should send an email with a message when classified as requires_admin" do - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => @dog_request.url_title - - @dog_request.reload - @dog_request.awaiting_description.should == false - @dog_request.described_state.should == 'requires_admin' - @dog_request.get_last_response_event.calculated_state.should == 'requires_admin' - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /as needing admin/ - mail.body.should =~ /Something weird happened/ - mail.from_addrs.first.to_s.should == @request_owner.name_and_email - end - it 'should say it is showing advice as to what to do next' do post_status('rejected') flash[:notice].should match(/Here is what to do now/) -- cgit v1.2.3 From faa70e9445a0a31fe0a49217ff2135b31ccce4ac Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sun, 3 Mar 2013 10:12:49 +1100 Subject: only can make the change as the owner of a request --- spec/controllers/request_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index be9df90c4..6adba4464 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1254,6 +1254,20 @@ describe RequestController, "describe_state_requires_admin" do end 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) + session[:user_id] = users(:silly_name_user).id + info_request.user_id.should_not == users(:silly_name_user).id + + InfoRequest.should_receive(:find_by_url_title!).with("info_request").and_return(info_request) + 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) -- cgit v1.2.3 From acd121b46103b2115a2e7499fc80e23ddf03cee2 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sun, 3 Mar 2013 10:23:40 +1100 Subject: Refactor tests a little --- spec/controllers/request_controller_spec.rb | 40 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') 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 -- cgit v1.2.3 From d189203172c931d255c685cecd3a10d6f8555fbc Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sun, 3 Mar 2013 11:05:53 +1100 Subject: admin user can change status --- spec/controllers/request_controller_spec.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9df100d76..005a77f17 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1269,9 +1269,11 @@ describe RequestController, "describe_state_requires_admin" do end context "logged in but not owner of request" do + let(:user) { users(:silly_name_user) } + before :each do - session[:user_id] = users(:silly_name_user).id - info_request.user_id.should_not == users(:silly_name_user).id + session[:user_id] = user.id + info_request.user_id.should_not == user.id end it "should not allow you to change the state" do @@ -1280,6 +1282,18 @@ describe RequestController, "describe_state_requires_admin" do post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" response.should render_template('user/wrong_user') end + + context "and has admin powers" do + before :each do + user.update_attribute(:admin_level, "super") + end + + it "should set the state" 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 end end -- cgit v1.2.3 From d785bf7e0ad702116706672d964e228612d0b797 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sun, 3 Mar 2013 11:56:46 +1100 Subject: Can update status when request is old and unclassified --- spec/controllers/request_controller_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 005a77f17..fa7c946d5 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1245,6 +1245,7 @@ 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 @@ -1256,6 +1257,19 @@ 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 @@ -1283,6 +1297,16 @@ describe RequestController, "describe_state_requires_admin" do 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) } + + it "should set the state" 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") -- cgit v1.2.3 From 0c983bd341192a3529193e5fcfa60cce0e05a2c2 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Sun, 3 Mar 2013 14:13:17 +1100 Subject: Simplify controller test by mock behaviour in Ability --- spec/controllers/request_controller_spec.rb | 58 +++++++---------------------- 1 file changed, 13 insertions(+), 45 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') 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 -- cgit v1.2.3 From ab8f4379a6b43cd5578a6a7d6268cb904e69b2ff Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 4 Mar 2013 08:54:57 +1100 Subject: Inline temporary variables --- spec/controllers/request_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index a82b3d952..0f39d01ce 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1328,6 +1328,7 @@ describe RequestController, "when classifying an information request" do end it 'should ask whether the request is old and unclassified' do + session[:user_id] = users(:silly_name_user).id @dog_request.should_receive(:is_old_unclassified?) post_status('rejected') end -- cgit v1.2.3 From 28e65f615c24b96225d24f3f1e0c03f229f8fe4e Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 4 Mar 2013 09:38:07 +1100 Subject: Fix bug when user not owner of request changing state to requires_admin email should come from user making the change --- spec/controllers/request_controller_spec.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 0f39d01ce..567add473 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1366,7 +1366,7 @@ describe RequestController, "when classifying an information request" do it 'should classify the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user)) post_status('rejected') end @@ -1405,6 +1405,15 @@ describe RequestController, "when classifying an information request" do response.should redirect_to play_url end end + + it "should send a mail from the user who changed the state to requires_admin" do + post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email + end end end @@ -1420,7 +1429,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user) post_status('rejected') end @@ -1471,7 +1480,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user) post_status('rejected') end -- cgit v1.2.3 From 65deec2c6a9388d87a66e40a7b3a38adf16af6a4 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 4 Mar 2013 15:57:59 +1100 Subject: Record who changes the state --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 567add473..899ce9572 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1268,7 +1268,7 @@ describe RequestController, "describe_state_requires_admin" do end 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") + info_request.should_receive(:set_described_state).with("requires_admin", user, "Something weird happened") post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" end -- cgit v1.2.3 From 25aad2807e04e2f0bc5dc339140915d6ca8ef3c7 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 4 Mar 2013 16:10:23 +1100 Subject: Don't allow external requests to have their state changed --- spec/controllers/request_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 899ce9572..4fd674b53 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1256,6 +1256,20 @@ 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 "external request" do + before (:each) { info_request.should_receive(:is_external?).and_return(true) } + + it "should not set the state" do + info_request.should_not_receive(:set_described_state) + post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" + end + + it "should redirect to the request page" do + post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" + response.should redirect_to request_url(info_request) + end + end end context "logged in" do -- cgit v1.2.3 From 78f2cb7a5d5ffabaf186e70e6fa02e60cbd724bc Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 5 Mar 2013 16:13:28 +1100 Subject: Remove code added previously because on the wrong track --- spec/controllers/request_controller_spec.rb | 62 ----------------------------- 1 file changed, 62 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 4fd674b53..219c04c4a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1241,68 +1241,6 @@ 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 - - context "external request" do - before (:each) { info_request.should_receive(:is_external?).and_return(true) } - - it "should not set the state" do - info_request.should_not_receive(:set_described_state) - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" - end - - it "should redirect to the request page" do - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" - response.should redirect_to request_url(info_request) - end - end - end - - context "logged in" do - let(:user) { users(:silly_name_user) } - before (:each) { session[:user_id] = user.id } - - 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 when classified as requires_admin" do - info_request.should_receive(:set_described_state).with("requires_admin", user, "Something weird happened") - - post :describe_state_requires_admin, :message => "Something weird happened", :url_title => "info_request" - end - end - - 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 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 -end - describe RequestController, "when classifying an information request" do describe 'if the request is external' do -- cgit v1.2.3 From 760ad672373427f139eaa37701d607bcd338cb7d Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 5 Mar 2013 17:29:32 +1100 Subject: Can also record a message when posting to RequestController#describe_state --- spec/controllers/request_controller_spec.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 219c04c4a..c42a3a3f2 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1318,7 +1318,7 @@ describe RequestController, "when classifying an information request" do it 'should classify the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user)) + @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user), nil) post_status('rejected') end @@ -1381,7 +1381,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected', @admin_user) + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil) post_status('rejected') end @@ -1432,7 +1432,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected', @admin_user) + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil) post_status('rejected') end @@ -1519,6 +1519,24 @@ describe RequestController, "when classifying an information request" do mail.from_addrs.first.to_s.should == @request_owner.name_and_email end + context "message is included when classifying as requires_admin" do + it "should send an email including the message" do + post :describe_state, + :incoming_message => { + :described_state => "requires_admin", + :message => "Something weird happened" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /as needing admin/ + mail.body.should =~ /Something weird happened/ + end + end + + it 'should say it is showing advice as to what to do next' do post_status('rejected') flash[:notice].should match(/Here is what to do now/) -- cgit v1.2.3 From 32a4d1295ce9772b5a482be7afbb5fa29c2b2ba1 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Wed, 6 Mar 2013 13:48:29 +1100 Subject: Now direct changes of state to error_message and requires_admin to a new page asking for more info --- spec/controllers/request_controller_spec.rb | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index c42a3a3f2..f35523532 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1359,7 +1359,7 @@ describe RequestController, "when classifying an information request" do end it "should send a mail from the user who changed the state to requires_admin" do - post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description + post :describe_state, :incoming_message => { :described_state => "requires_admin", :message => "a message" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 @@ -1503,20 +1503,14 @@ describe RequestController, "when classifying an information request" do post_status('rejected') end - it "should send email when classified as requires_admin" do + it "should go to the page asking for more information when classified as requires_admin" do post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description - response.should redirect_to(:controller => 'help', :action => 'contact') + response.should redirect_to describe_state_message_url(:url_title => @dog_request.url_title, :described_state => "requires_admin") @dog_request.reload - @dog_request.awaiting_description.should == false - @dog_request.described_state.should == 'requires_admin' - @dog_request.get_last_response_event.calculated_state.should == 'requires_admin' + @dog_request.described_state.should_not == 'requires_admin' - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /as needing admin/ - mail.from_addrs.first.to_s.should == @request_owner.name_and_email + ActionMailer::Base.deliveries.should be_empty end context "message is included when classifying as requires_admin" do @@ -1647,12 +1641,22 @@ describe RequestController, "when classifying an information request" do expect_redirect('internal_review', request_url) end - it 'should redirect to the "help general url" when status is updated to "requires admin"' do - expect_redirect('requires_admin', "help/contact") + it 'should redirect to the "request url" when status is updated to "requires admin"' do + post :describe_state, :incoming_message => { + :described_state => 'requires_admin', + :message => "A message" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) end - it 'should redirect to the "help general url" when status is updated to "error message"' do - expect_redirect('error_message', "help/contact") + it 'should redirect to the "request url" when status is updated to "error message"' do + post :describe_state, :incoming_message => { + :described_state => 'error_message', + :message => "A message" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) end it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do -- cgit v1.2.3