aboutsummaryrefslogtreecommitdiffstats
path: root/spec/integration/admin_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/integration/admin_spec.rb')
-rw-r--r--spec/integration/admin_spec.rb61
1 files changed, 40 insertions, 21 deletions
diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb
index 8e6351d2c..bdd6e9d8c 100644
--- a/spec/integration/admin_spec.rb
+++ b/spec/integration/admin_spec.rb
@@ -5,29 +5,25 @@ describe "When administering the site" do
before do
AlaveteliConfiguration.stub!(:skip_admin_auth).and_return(false)
+ confirm(:admin_user)
+ @admin = login(:admin_user)
end
it "allows an admin to log in as another user" do
- # First log in as Joe Admin
- confirm(:admin_user)
- admin = login(:admin_user)
-
- # Now fetch the "log in as" link to log in as Bob
- admin.get_via_redirect "/en/admin/user/login_as/#{users(:bob_smith_user).id}"
- admin.response.should be_success
- admin.session[:user_id].should == users(:bob_smith_user).id
+ # post to the "log in as" url to log in as Bob
+ @admin.post_via_redirect "/en/admin/users/#{users(:bob_smith_user).id}/login_as"
+ @admin.response.should be_success
+ @admin.session[:user_id].should == users(:bob_smith_user).id
end
it 'does not allow a non-admin user to login as another user' do
robin = login(:robin_user)
- robin.get_via_redirect "/en/admin/user/login_as/#{users(:bob_smith_user).id}"
+ robin.post_via_redirect "/en/admin/users/#{users(:bob_smith_user).id}/login_as"
robin.response.should be_success
robin.session[:user_id].should_not == users(:bob_smith_user).id
end
it "allows redelivery of an incoming message to a closed request" do
- confirm(:admin_user)
- admin = login(:admin_user)
ir = info_requests(:fancy_dog_request)
close_request(ir)
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
@@ -36,10 +32,9 @@ describe "When administering the site" 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_params = {'redeliver_incoming_message_id' => new_im.id,
- 'url_title' => ir.url_title}
- admin.post '/en/admin/incoming/redeliver', post_params
- admin.response.location.should == 'http://www.example.com/en/admin/request/show/101'
+ post_params = { 'url_title' => ir.url_title }
+ @admin.post "/en/admin/incoming_messages/#{new_im.id}/redeliver", post_params
+ @admin.response.location.should == 'http://www.example.com/en/admin/requests/101'
ir = InfoRequest.find_by_url_title(ir.url_title)
ir.incoming_messages.length.should == 2
@@ -47,8 +42,6 @@ describe "When administering the site" do
end
it "allows redelivery of an incoming message to more than one request" do
- confirm(:admin_user)
- admin = login(:admin_user)
ir1 = info_requests(:fancy_dog_request)
close_request(ir1)
@@ -60,15 +53,41 @@ describe "When administering the site" do
InfoRequest.holding_pen_request.incoming_messages.length.should == 1
new_im = InfoRequest.holding_pen_request.incoming_messages[0]
- post_params = {'redeliver_incoming_message_id' => new_im.id,
- 'url_title' => "#{ir1.url_title},#{ir2.url_title}"}
- admin.post '/en/admin/incoming/redeliver', post_params
+ post_params = { 'url_title' => "#{ir1.url_title},#{ir2.url_title}" }
+ @admin.post "/en/admin/incoming_messages/#{new_im.id}/redeliver", post_params
ir1.reload
ir1.incoming_messages.length.should == 2
ir2.reload
ir2.incoming_messages.length.should == 2
- admin.response.location.should == 'http://www.example.com/en/admin/request/show/106'
+ @admin.response.location.should == 'http://www.example.com/en/admin/requests/106'
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
end
+ describe 'when administering the holding pen' do
+
+ it "shows a rejection reason for an incoming message from an invalid address" do
+ ir = FactoryGirl.create(:info_request, :allow_new_responses_from => 'authority_only',
+ :handle_rejected_responses => 'holding_pen')
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com")
+ raw_email = InfoRequest.holding_pen_request.get_last_public_response.raw_email
+ @admin.get "/en/admin/raw_emails/#{raw_email.id}"
+ @admin.response.should contain "Only the authority can reply to this request"
+ end
+
+ it "guesses a misdirected request" do
+ ir = FactoryGirl.create(:info_request, :allow_new_responses_from => 'authority_only',
+ :handle_rejected_responses => 'holding_pen')
+ 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_public_response.raw_email
+ # 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
+ @admin.get "/en/admin/raw_emails/#{interesting_email.id}"
+ @admin.response.should contain "Could not identify the request"
+ @admin.response.should contain ir.title
+ end
+
+
+ end
end