diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-22 10:37:16 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-22 10:37:16 +0100 |
commit | 6afb00eeb973e843e7a56ff20c9783ad0c5dc9c2 (patch) | |
tree | fa492518913c13daea2ee8e38f6a8aedafa9a276 | |
parent | 2939511069bbafe45a53174da4c5bd880ac109a8 (diff) |
Allow external requests to be hidden from the admin interface.
-rw-r--r-- | app/controllers/admin_request_controller.rb | 16 | ||||
-rw-r--r-- | spec/controllers/admin_request_controller_spec.rb | 50 |
2 files changed, 60 insertions, 6 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index ecbc35e1e..c5abf8769 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -362,14 +362,18 @@ class AdminRequestController < AdminController info_request.set_described_state(params[:reason]) info_request.save! - ContactMailer.deliver_from_admin_message( - info_request.user, - subject, - params[:explanation] - ) + if ! info_request.is_external? + ContactMailer.deliver_from_admin_message( + info_request.user, + subject, + params[:explanation] + ) + flash[:notice] = _("Your message to {{recipient_user_name}} has been sent",:recipient_user_name=>CGI.escapeHTML(info_request.user.name)) + else + flash[:notice] = _("This external request has been hidden") + end # expire cached files expire_for_request(info_request) - flash[:notice] = _("Your message to {{recipient_user_name}} has been sent",:recipient_user_name=>CGI.escapeHTML(info_request.user.name)) redirect_to request_admin_url(info_request) end end diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index eb6f7aebc..252818452 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -220,6 +220,56 @@ describe AdminRequestController, "when administering the holding pen" do 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 |