From 9ad9422aa8f137d7f7b0ce547e951c78332e7fd9 Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Fri, 4 Dec 2009 15:56:31 +0000 Subject: Change salutation from "Sir or Madam" to name of authority. --- spec/controllers/request_controller_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 e4404d4d0..752f25bb6 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -263,7 +263,7 @@ describe RequestController, "when creating a new request" do end it "should accept a public body parameter" do - get :new, :info_request => { :public_body_id => @body.id } + get :new, :public_body_id => @body.id assigns[:info_request].public_body.should == @body response.should render_template('new') end @@ -382,7 +382,7 @@ describe RequestController, "when making a new request" do @user.stub!(:can_file_requests?).and_return(true) User.stub!(:find).and_return(@user) - @body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true) + @body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true, :name => "Test Quango") PublicBody.stub!(:find).and_return(@body) end @@ -729,7 +729,7 @@ describe RequestController, "when classifying an information request" do end it 'should redirect to the "respond to last url" when status is updated to "gone postal"' do - expect_redirect('gone_postal', "request/#{@dog_request.id}/response/1?gone_postal=1") + expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}?gone_postal=1") end it 'should redirect to the "request url" when status is updated to "internal review"' do @@ -744,8 +744,8 @@ describe RequestController, "when classifying an information request" do expect_redirect('error_message', "help/contact") end - it 'should redirect to the "request url" when status is updated to "user_withdrawn"' do - expect_redirect('user_withdrawn', request_url) + it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do + expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}") end end -- cgit v1.2.3 From bc2cf7b39c998a5a7e3f4cf8f00eeaf1365bc8ad Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Sun, 13 Dec 2009 01:31:45 +0000 Subject: Fix some tests. --- spec/controllers/request_controller_spec.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 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 752f25bb6..2056cde06 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -683,7 +683,11 @@ describe RequestController, "when classifying an information request" do def request_url "request/#{@dog_request.url_title}" end - + + def unhappy_url + "help/unhappy/#{@dog_request.url_title}" + end + def expect_redirect(status, redirect_path) post_status(status) response.should redirect_to("http://test.host/#{redirect_path}") @@ -691,16 +695,26 @@ describe RequestController, "when classifying an information request" do it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1) + @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40) + expect_redirect("waiting_response", "request/#{@dog_request.url_title}") flash[:notice].should match(/should get a response/) end it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1) + @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40) expect_redirect('waiting_response', request_url) flash[:notice].should match(/should have got a response/) end - + + it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do + @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-2) + @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date-1) + expect_redirect('waiting_response', unhappy_url) + flash[:notice].should match(/is long overdue/) + end + it 'should redirect to the "request url" when status is updated to "not held"' do expect_redirect('not_held', request_url) end @@ -825,6 +839,10 @@ describe RequestController, "sending overdue request alerts" do fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views it "should send an overdue alert mail to creators of overdue requests" do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days + chicken_request.save! + RequestMailer.alert_overdue_requests deliveries = ActionMailer::Base.deliveries -- cgit v1.2.3 From 4e68260ee214a94e7bc5ba30fd1fe816920f4d7d Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Wed, 16 Dec 2009 21:33:34 +0000 Subject: Save the model that was changed. --- 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 2056cde06..ec396aa3b 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -841,7 +841,7 @@ describe RequestController, "sending overdue request alerts" do it "should send an overdue alert mail to creators of overdue requests" do chicken_request = info_requests(:naughty_chicken_request) chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days - chicken_request.save! + chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests -- cgit v1.2.3 From ea6c021db0dd273b1dee3874adb9e17d3a65db58 Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Wed, 16 Dec 2009 21:50:08 +0000 Subject: Fix overdue email text for new policy and for schools. --- spec/controllers/request_controller_spec.rb | 21 +++++++++++++++++++-- 1 file changed, 19 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 ec396aa3b..1ab68cd03 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -848,7 +848,7 @@ describe RequestController, "sending overdue request alerts" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body.should =~ /promptly, as required by law/ + mail.body.should =~ /promptly, as normally\s+required by law/ mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email mail.body =~ /(http:\/\/.*\/c\/(.*))/ @@ -863,7 +863,24 @@ describe RequestController, "sending overdue request alerts" do assigns[:info_request].should == info_requests(:naughty_chicken_request) end - it "should send not actualy send the overdue alert if the user is banned" do + it "should include clause for schools when sending an overdue alert mail to creators of overdue requests" do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days + chicken_request.outgoing_messages[0].save! + + chicken_request.public_body.tag_string = "school" + chicken_request.public_body.save! + + RequestMailer.alert_overdue_requests + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /promptly, as normally\s+required by law during term time/ + mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + end + + it "should send not actually send the overdue alert if the user is banned" do user = info_requests(:naughty_chicken_request).user user.ban_text = 'Banned' user.save! -- cgit v1.2.3 From 82819ffac0cd7925aada731ff7bfe5eabd64b4a3 Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Wed, 16 Dec 2009 22:03:06 +0000 Subject: Email when request becomes long overdue --- spec/controllers/request_controller_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 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 1ab68cd03..6a8f3538a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -891,6 +891,31 @@ describe RequestController, "sending overdue request alerts" do deliveries.size.should == 0 end + it "should send a very overdue alert mail to creators of very overdue requests" do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].save! + + RequestMailer.alert_overdue_requests + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /as required by law/ + mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + + mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail_url = $1 + mail_token = $2 + + session[:user_id].should be_nil + controller.test_code_redirect_by_email_token(mail_token, self) # XXX hack to avoid having to call User controller for email link + session[:user_id].should == info_requests(:naughty_chicken_request).user.id + + response.should render_template('show_response') + assigns[:info_request].should == info_requests(:naughty_chicken_request) + end + end describe RequestController, "sending unclassified new response reminder alerts" do -- cgit v1.2.3 From 3222dc3827b3bcc6669efb633a970b11b0ed3fa3 Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Tue, 22 Dec 2009 10:37:19 +0000 Subject: Fix bug that stopped re-editing requests working --- spec/controllers/request_controller_spec.rb | 9 +++++++++ 1 file changed, 9 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 6a8f3538a..9474b1d77 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -285,6 +285,15 @@ describe RequestController, "when creating a new request" do response.should render_template('preview') end + it "should allow re-editing of a request" do + post :new, :info_request => { :public_body_id => @body.id, + :title => "Why is your quango called Geraldine?"}, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, + :submitted_new_request => 1, :preview => 0, + :reedit => "Re-edit this request" + response.should render_template('new') + end + it "should redirect to sign in page when input is good and nobody is logged in" do params = { :info_request => { :public_body_id => @body.id, :title => "Why is your quango called Geraldine?"}, -- cgit v1.2.3 From 2a29145dad6ae8cdf599b7a23eb9c9d96b26fe7f Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Tue, 22 Dec 2009 10:43:50 +0000 Subject: Test for previewing followups --- 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 9474b1d77..2d9ff9208 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -798,7 +798,18 @@ describe RequestController, "when sending a followup message" do response.should render_template('show_response') end + it "should show preview when input is good" do + session[:user_id] = users(:bob_smith_user).id + post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort'}, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1, :preview => 1 + response.should render_template('followup_preview') + end + it "should allow re-editing of a preview" do + session[:user_id] = users(:bob_smith_user).id + post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort'}, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1, :preview => 0, :reedit => "Re-edit this request" + response.should render_template('show_response') + end + it "should send the follow up message if you are the right user" do # fake that this is a clarification info_requests(:fancy_dog_request).set_described_state('waiting_clarification') -- cgit v1.2.3 From 576eb84deee7ba08eaaf32c2456f0441ecf2a55b Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Wed, 3 Mar 2010 19:36:15 +0000 Subject: Test code for FOI officer upload --- spec/controllers/request_controller_spec.rb | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 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 2d9ff9208..c0cc1ac26 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1111,6 +1111,91 @@ describe RequestController, "when viewing comments" do end +describe RequestController, "authority uploads a response from the web interface" do + fixtures :info_requests, :info_request_events, :public_bodies, :users + + before(:all) do + # domain after the @ is used for authentication of FOI officers, so to test it + # we need a user which isn't at localhost. + @normal_user = User.new(:name => "Mr. Normal", :email => "normal-user@flourish.org", + :password => PostRedirect.generate_random_token) + @normal_user.save! + + @foi_officer_user = User.new(:name => "The Geraldine Quango", :email => "geraldine-requests@localhost", + :password => PostRedirect.generate_random_token) + @foi_officer_user.save! + end + + it "should require login to view the form to upload" do + @ir = info_requests(:fancy_dog_request) + @ir.public_body.is_foi_officer?(@normal_user).should == false + session[:user_id] = @normal_user.id + + get :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.should render_template('user/wrong_user') + end + + it "should let you view upload form if you are an FOI officer" do + @ir = info_requests(:fancy_dog_request) + @ir.public_body.is_foi_officer?(@foi_officer_user).should == true + session[:user_id] = @foi_officer_user.id + + get :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.should render_template('request/upload_response') + end + + it "should prevent uploads if you are not a requester" do + @ir = info_requests(:fancy_dog_request) + incoming_before = @ir.incoming_messages.size + session[:user_id] = @normal_user.id + + # post up a photo of the parrot + parrot_upload = fixture_file_upload('parrot.png','image/png') + post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', + :body => "Find attached a picture of a parrot", + :file_1 => parrot_upload, + :submitted_upload_response => 1 + response.should render_template('user/wrong_user') + end + + it "should prevent entirely blank uploads" do + session[:user_id] = @foi_officer_user.id + + post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', :body => "", :submitted_upload_response => 1 + response.should render_template('request/upload_response') + flash[:error].should match(/Please type a message/) + end + + # How do I test a file upload in rails? + # http://stackoverflow.com/questions/1178587/how-do-i-test-a-file-upload-in-rails + it "should let the requester upload a file" do + @ir = info_requests(:fancy_dog_request) + incoming_before = @ir.incoming_messages.size + session[:user_id] = @foi_officer_user.id + + # post up a photo of the parrot + parrot_upload = fixture_file_upload('parrot.png','image/png') + post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', + :body => "Find attached a picture of a parrot", + :file_1 => parrot_upload, + :submitted_upload_response => 1 + + response.should redirect_to(:action => 'show', :url_title => 'why_do_you_have_such_a_fancy_dog') + flash[:notice].should match(/Thank you for responding to this FOI request/) + + # check there is a new attachment + incoming_after = @ir.incoming_messages.size + incoming_after.should == incoming_before + 1 + + # check new attachment looks vaguely OK + new_im = @ir.incoming_messages[-1] + new_im.mail.body.should match(/Find attached a picture of a parrot/) + attachments = new_im.get_attachments_for_display + attachments.size.should == 1 + attachments[0].filename.should == "parrot.png" + end +end + -- cgit v1.2.3 From d4477ab12d3050e7ff3a4df76842d5e778648b6f Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Wed, 3 Mar 2010 19:55:10 +0000 Subject: Check size of attachment --- 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 c0cc1ac26..27647e04e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1193,6 +1193,7 @@ describe RequestController, "authority uploads a response from the web interface attachments = new_im.get_attachments_for_display attachments.size.should == 1 attachments[0].filename.should == "parrot.png" + attachments[0].display_size.should == "94K" end end -- cgit v1.2.3 From d67b0bb2ba8afe77a8fd621d3f0dade374a6076c Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Tue, 8 Jun 2010 15:48:36 +0100 Subject: Updated formatting. --- 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 27647e04e..b6d4e4c3f 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -921,7 +921,7 @@ describe RequestController, "sending overdue request alerts" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body.should =~ /as required by law/ + mail.body.should =~ /required by law/ mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email mail.body =~ /(http:\/\/.*\/c\/(.*))/ -- cgit v1.2.3