diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-28 10:45:20 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-28 10:45:20 +0100 |
commit | ee723d9e6645bc7987cb2b7cc9cd320950536201 (patch) | |
tree | f5beec1ffc37c9530485c0cd5be15c56210ae2da /spec/controllers/admin_request_controller_spec.rb | |
parent | e98bfd6e9ed7e6bb151d0eb5c216cad0fed6a40c (diff) | |
parent | 5c1a88c88ba69cec3924ec8a1d69d8784acaef3c (diff) |
Merge branch 'release/0.6.4'0.6.4
Diffstat (limited to 'spec/controllers/admin_request_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin_request_controller_spec.rb | 155 |
1 files changed, 137 insertions, 18 deletions
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index b0468822a..252818452 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -27,12 +27,31 @@ describe AdminRequestController, "when administering requests" do it "saves edits to a request" do info_requests(:fancy_dog_request).title.should == "Why do you have & such a fancy dog?" - post :update, { :id => info_requests(:fancy_dog_request), :info_request => { :title => "Renamed", :prominence => "normal", :described_state => "waiting_response", :awaiting_description => false, :allow_new_responses_from => 'anybody', :handle_rejected_responses => 'bounce' } } + post :update, { :id => info_requests(:fancy_dog_request), + :info_request => { :title => "Renamed", + :prominence => "normal", + :described_state => "waiting_response", + :awaiting_description => false, + :allow_new_responses_from => 'anybody', + :handle_rejected_responses => 'bounce' } } response.flash[:notice].should include('successful') ir = InfoRequest.find(info_requests(:fancy_dog_request).id) ir.title.should == "Renamed" end + it 'expires the request cache when saving edits to it' do + info_request = info_requests(:fancy_dog_request) + @controller.should_receive(:expire_for_request).with(info_request) + post :update, { :id => info_request, + :info_request => { :title => "Renamed", + :prominence => "normal", + :described_state => "waiting_response", + :awaiting_description => false, + :allow_new_responses_from => 'anybody', + :handle_rejected_responses => 'bounce' } } + + end + it "edits an outgoing message" do get :edit_outgoing, :id => outgoing_messages(:useless_outgoing_message) end @@ -45,6 +64,16 @@ describe AdminRequestController, "when administering requests" do ir.body.should include("delicious cat") end + describe 'when fully destroying a request' do + + it 'expires the file cache for that request' do + info_request = info_requests(:badger_request) + @controller.should_receive(:expire_for_request).with(info_request) + get :fully_destroy, { :id => info_request } + end + + end + end describe AdminRequestController, "when administering the holding pen" do @@ -80,12 +109,13 @@ describe AdminRequestController, "when administering the holding pen" do InfoRequest.holding_pen_request.incoming_messages.length.should == 1 new_im = InfoRequest.holding_pen_request.incoming_messages[0] ir.incoming_messages.length.should == 1 - post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title + post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title ir = InfoRequest.find_by_url_title(ir.url_title) ir.incoming_messages.length.should == 2 response.should redirect_to(:controller=>'admin_request', :action=>'show', :id=>101) InfoRequest.holding_pen_request.incoming_messages.length.should == 0 end + it "allows redelivery to more than one request" do ir1 = info_requests(:fancy_dog_request) ir1.allow_new_responses_from = 'nobody' @@ -99,7 +129,7 @@ describe AdminRequestController, "when administering the holding pen" do InfoRequest.holding_pen_request.incoming_messages.length.should == 1 new_im = InfoRequest.holding_pen_request.incoming_messages[0] - post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => "#{ir1.url_title},#{ir2.url_title}" + post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => "#{ir1.url_title},#{ir2.url_title}" ir1.reload ir1.incoming_messages.length.should == 2 ir2.reload @@ -108,6 +138,15 @@ describe AdminRequestController, "when administering the holding pen" do InfoRequest.holding_pen_request.incoming_messages.length.should == 0 end + it 'expires the file cache for the previous request' do + current_info_request = info_requests(:fancy_dog_request) + destination_info_request = info_requests(:naughty_chicken_request) + incoming_message = incoming_messages(:useless_incoming_message) + @controller.should_receive(:expire_for_request).with(current_info_request) + post :redeliver_incoming, :redeliver_incoming_message_id => incoming_message.id, + :url_title => destination_info_request.url_title + end + it "guesses a misdirected request" do ir = info_requests(:fancy_dog_request) ir.handle_rejected_responses = 'holding_pen' @@ -124,11 +163,31 @@ describe AdminRequestController, "when administering the holding pen" do assigns[:info_requests][0].should == ir end - it "destroys an incoming message" do - im = incoming_messages(:useless_incoming_message) - raw_email = im.raw_email.filepath - post :destroy_incoming, :incoming_message_id => im.id - assert_equal File.exists?(raw_email), false + describe 'when destroying an incoming message' do + + before do + @im = incoming_messages(:useless_incoming_message) + @controller.stub!(:expire_for_request) + end + + it "destroys the raw email file" do + raw_email = @im.raw_email.filepath + assert_equal File.exists?(raw_email), true + post :destroy_incoming, :incoming_message_id => @im.id + assert_equal File.exists?(raw_email), false + end + + it 'asks the incoming message to fully destroy itself' do + IncomingMessage.stub!(:find).and_return(@im) + @im.should_receive(:fully_destroy) + post :destroy_incoming, :incoming_message_id => @im.id + end + + it 'expires the file cache for the associated info_request' do + @controller.should_receive(:expire_for_request).with(@im.info_request) + post :destroy_incoming, :incoming_message_id => @im.id + end + end it "shows a suitable default 'your email has been hidden' message" do @@ -141,16 +200,76 @@ describe AdminRequestController, "when administering the holding pen" do assigns[:request_hidden_user_explanation].should include("not a valid FOI") end - it "hides requests and sends a notification email that it has done so" do - ir = info_requests(:fancy_dog_request) - post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" - ir.reload - ir.prominence.should == "requester_only" - ir.described_state.should == "vexatious" - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /Foo/ + describe 'when hiding requests' do + + it "hides requests and sends a notification email that it has done so" do + ir = info_requests(:fancy_dog_request) + post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" + ir.reload + ir.prominence.should == "requester_only" + ir.described_state.should == "vexatious" + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /Foo/ + end + + it 'expires the file cache for the request' do + ir = info_requests(:fancy_dog_request) + @controller.should_receive(:expire_for_request).with(ir) + post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" + end + + describe 'when hiding an external request' do + + before do + @controller.stub!(:expire_for_request) + @info_request = mock_model(InfoRequest, :prominence= => nil, + :log_event => nil, + :set_described_state => nil, + :save! => nil, + :user => nil, + :user_name => 'External User', + :is_external? => true) + InfoRequest.stub!(:find).with(@info_request.id.to_s).and_return(@info_request) + @default_params = { :id => @info_request.id, + :explanation => 'Foo', + :reason => 'vexatious' } + end + + def make_request(params=@default_params) + post :hide_request, params + end + + it 'should redirect the the admin page for the request' do + make_request + response.should redirect_to(:controller => 'admin_request', + :action => 'show', + :id => @info_request.id) + end + + it 'should set the request prominence to "requester_only"' do + @info_request.should_receive(:prominence=).with('requester_only') + @info_request.should_receive(:save!) + make_request + end + + it 'should not send a notification email' do + ContactMailer.should_not_receive(:deliver_from_admin_message) + make_request + end + + it 'should add a notice to the flash saying that the request has been hidden' do + make_request + response.flash[:notice].should == "This external request has been hidden" + end + + it 'should expire the file cache for the request' do + @controller.should_receive(:expire_for_request) + make_request + end + end + end end |