diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_request_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/mailers/request_mailer_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 63 | ||||
-rw-r--r-- | spec/views/request/show.html.erb_spec.rb | 88 |
5 files changed, 120 insertions, 60 deletions
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 42b4bcbc1..c374ff90d 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -77,7 +77,7 @@ describe AdminRequestController, "when administering the holding pen" do ir.handle_rejected_responses = 'holding_pen' ir.save! receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com") - get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_response.raw_email.id + get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_public_response.raw_email.id response.should contain "Only the authority can reply to this request" end @@ -88,7 +88,8 @@ describe AdminRequestController, "when administering the holding pen" do ir.save! mail_to = "request-#{ir.id}-asdfg@example.com" receive_incoming_mail('incoming-request-plain.email', mail_to) - interesting_email = InfoRequest.holding_pen_request.get_last_response.raw_email.id + interesting_email = InfoRequest.holding_pen_request.get_last_public_response +.raw_email.id # now we add another message to the queue, which we're not interested in receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "") InfoRequest.holding_pen_request.incoming_messages.length.should == 2 diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index c5ee8cbf7..ec10d99d8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1596,7 +1596,7 @@ describe RequestController, "when classifying an information request" do @dog_request.reload @dog_request.awaiting_description.should == false @dog_request.described_state.should == 'rejected' - @dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event) + @dog_request.get_last_public_response_event.should == info_request_events(:useless_incoming_message_event) @dog_request.info_request_events.last.event_type.should == "status_update" @dog_request.info_request_events.last.calculated_state.should == 'rejected' end @@ -1749,13 +1749,13 @@ describe RequestController, "when classifying an information request" do it 'should redirect to the "response url" when there is a last response' do incoming_message = mock_model(IncomingMessage) - @dog_request.stub!(:get_last_response).and_return(incoming_message) + @dog_request.stub!(:get_last_public_response).and_return(incoming_message) expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}") end it 'should redirect to the "response no followup url" when there are no events needing description' do - @dog_request.stub!(:get_last_response).and_return(nil) + @dog_request.stub!(:get_last_public_response).and_return(nil) expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response") end @@ -1794,7 +1794,7 @@ describe RequestController, "when classifying an information request" do context 'when status is updated to "gone postal"' do it 'should redirect to the "respond to last url"' do - expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}?gone_postal=1") + expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_public_response.id}?gone_postal=1") end end @@ -1836,7 +1836,7 @@ describe RequestController, "when classifying an information request" do context 'when status is updated to "user_withdrawn"' do it 'should redirect to the "respond to last url url" ' do - expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}") + expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_public_response.id}") end end @@ -1889,7 +1889,7 @@ describe RequestController, "when sending a followup message" do # fake that this is a clarification info_requests(:fancy_dog_request).set_described_state('waiting_clarification') info_requests(:fancy_dog_request).described_state.should == 'waiting_clarification' - info_requests(:fancy_dog_request).get_last_response_event.calculated_state.should == 'waiting_clarification' + info_requests(:fancy_dog_request).get_last_public_response_event.calculated_state.should == 'waiting_clarification' # make the followup session[:user_id] = users(:bob_smith_user).id @@ -1907,7 +1907,7 @@ describe RequestController, "when sending a followup message" do # and that the status changed info_requests(:fancy_dog_request).reload info_requests(:fancy_dog_request).described_state.should == 'waiting_response' - info_requests(:fancy_dog_request).get_last_response_event.calculated_state.should == 'waiting_clarification' + info_requests(:fancy_dog_request).get_last_public_response_event.calculated_state.should == 'waiting_clarification' end it "should give an error if the same followup is submitted twice" do diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 23806b35b..f30beae82 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -204,10 +204,10 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp before do Time.stub!(:now).and_return(Time.utc(2007, 11, 12, 23, 59)) @mock_event = mock_model(InfoRequestEvent) - @mock_response = mock_model(IncomingMessage) + @mock_response = mock_model(IncomingMessage, :user_can_view? => true) @mock_user = mock_model(User) - @mock_request = mock_model(InfoRequest, :get_last_response_event_id => @mock_event.id, - :get_last_response => @mock_response, + @mock_request = mock_model(InfoRequest, :get_last_public_response_event_id => @mock_event.id, + :get_last_public_response => @mock_response, :user_id => 2, :url_title => 'test_title', :user => @mock_user) @@ -252,7 +252,7 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp end it 'should raise an error if a request does not have a last response event id' do - @mock_request.stub!(:get_last_response_event_id).and_return(nil) + @mock_request.stub!(:get_last_public_response_event_id).and_return(nil) expected_message = "internal error, no last response while making alert new response reminder, request id #{@mock_request.id}" lambda{ send_alerts }.should raise_error(expected_message) end @@ -289,7 +289,7 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp mock_sent_alert.should_receive(:info_request=).with(@mock_request) mock_sent_alert.should_receive(:user=).with(@mock_user) mock_sent_alert.should_receive(:alert_type=).with('new_response_reminder_1') - mock_sent_alert.should_receive(:info_request_event_id=).with(@mock_request.get_last_response_event_id) + mock_sent_alert.should_receive(:info_request_event_id=).with(@mock_request.get_last_public_response_event_id) mock_sent_alert.should_receive(:save!) send_alerts end diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 2846fa6dc..a6f877b20 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -451,8 +451,14 @@ describe InfoRequest do before do Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59)) - @mock_comment_event = mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment', :response? => false) - @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response', :response? => true) + @mock_comment_event = mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, + :event_type => 'comment', + :response? => false) + mock_incoming_message = mock_model(IncomingMessage, :all_can_view? => true) + @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, + :event_type => 'response', + :response? => true, + :incoming_message => mock_incoming_message) @info_request = InfoRequest.new(:prominence => 'normal', :awaiting_description => true, :info_request_events => [@mock_response_event, @mock_comment_event]) @@ -589,6 +595,59 @@ describe InfoRequest do end end + describe 'when asked for the last public response event' do + + before do + @info_request = FactoryGirl.create(:info_request_with_incoming) + @incoming_message = @info_request.incoming_messages.first + end + + it 'should not return an event with a hidden prominence message' do + @incoming_message.prominence = 'hidden' + @incoming_message.save! + @info_request.get_last_public_response_event.should == nil + end + + it 'should not return an event with a requester_only prominence message' do + @incoming_message.prominence = 'requester_only' + @incoming_message.save! + @info_request.get_last_public_response_event.should == nil + end + + it 'should return an event with a normal prominence message' do + @incoming_message.prominence = 'normal' + @incoming_message.save! + @info_request.get_last_public_response_event.should == @incoming_message.response_event + end + end + + describe 'when asked for the last public outgoing event' do + + before do + @info_request = FactoryGirl.create(:info_request) + @outgoing_message = @info_request.outgoing_messages.first + end + + it 'should not return an event with a hidden prominence message' do + @outgoing_message.prominence = 'hidden' + @outgoing_message.save! + @info_request.get_last_public_outgoing_event.should == nil + end + + it 'should not return an event with a requester_only prominence message' do + @outgoing_message.prominence = 'requester_only' + @outgoing_message.save! + @info_request.get_last_public_outgoing_event.should == nil + end + + it 'should return an event with a normal prominence message' do + @outgoing_message.prominence = 'normal' + @outgoing_message.save! + @info_request.get_last_public_outgoing_event.should == @outgoing_message.info_request_events.first + end + + end + describe 'when generating json for the api' do before do diff --git a/spec/views/request/show.html.erb_spec.rb b/spec/views/request/show.html.erb_spec.rb index 4578268b2..6e63b9b43 100644 --- a/spec/views/request/show.html.erb_spec.rb +++ b/spec/views/request/show.html.erb_spec.rb @@ -1,8 +1,8 @@ require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'request/show' do - - before do + + before do @mock_body = mock_model(PublicBody, :name => 'test body', :url_name => 'test_body', :is_school? => false) @@ -10,101 +10,101 @@ describe 'request/show' do :url_name => 'test_user', :profile_photo => nil) @mock_request = mock_model(InfoRequest, :title => 'test request', - :awaiting_description => false, + :awaiting_description => false, :law_used_with_a => 'A Freedom of Information request', :law_used_full => 'Freedom of Information', :public_body => @mock_body, - :user => @mock_user, - :user_name => @mock_user.name, + :user => @mock_user, + :user_name => @mock_user.name, :is_external? => false, - :calculate_status => 'waiting_response', + :calculate_status => 'waiting_response', :date_response_required_by => Date.today, :prominence => 'normal', :comments_allowed? => true, :all_can_view? => true, :url_title => 'test_request') end - + def request_page assign :info_request, @mock_request assign :info_request_events, [] assign :status, @mock_request.calculate_status render end - - describe 'when a status update has been requested' do - - before do + + describe 'when a status update has been requested' do + + before do assign :update_status, true end - + it 'should show the first form for describing the state of the request' do request_page response.should have_selector("div.describe_state_form#describe_state_form_1") - end - + end + end - - describe 'when it is awaiting a description' do - - before do + + describe 'when it is awaiting a description' do + + before do @mock_request.stub!(:awaiting_description).and_return(true) end - + it 'should show the first form for describing the state of the request' do request_page response.should have_selector("div.describe_state_form#describe_state_form_1") end - - it 'should show the second form for describing the state of the request' do + + it 'should show the second form for describing the state of the request' do request_page response.should have_selector("div.describe_state_form#describe_state_form_2") end - + end - - describe 'when the user is the request owner' do - - before do + + describe 'when the user is the request owner' do + + before do assign :is_owning_user, true end - - describe 'when the request status is "waiting clarification"' do - - before do + + describe 'when the request status is "waiting clarification"' do + + before do @mock_request.stub!(:calculate_status).and_return('waiting_clarification') end - - describe 'when there is a last response' do - + + describe 'when there is a last response' do + before do @mock_response = mock_model(IncomingMessage) - @mock_request.stub!(:get_last_response).and_return(@mock_response) + @mock_request.stub!(:get_last_public_response).and_return(@mock_response) end - - it 'should show a link to follow up the last response with clarification' do + + it 'should show a link to follow up the last response with clarification' do request_page expected_url = "/en/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" response.should have_selector("a", :href => expected_url, :content => 'send a follow up message') end - + end - + describe 'when there is no last response' do - - before do - @mock_request.stub!(:get_last_response).and_return(nil) + + before do + @mock_request.stub!(:get_last_public_response).and_return(nil) end - - it 'should show a link to follow up the request without reference to a specific response' do + + it 'should show a link to follow up the request without reference to a specific response' do request_page expected_url = "/en/request/#{@mock_request.id}/response#followup" response.should have_selector("a", :href => expected_url, :content => 'send a follow up message') end end end - + end end |