diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 105 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/fixtures/files/incoming-request-empty.email | 8 | ||||
-rw-r--r-- | spec/fixtures/info_request_events.yml | 11 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 12 | ||||
-rw-r--r-- | spec/fixtures/outgoing_messages.yml | 11 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 15 | ||||
-rw-r--r-- | spec/fixtures/public_body_translations.yml | 13 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 22 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/integration/request_controller_spec.rb | 41 | ||||
-rw-r--r-- | spec/lib/ability_spec.rb | 51 | ||||
-rw-r--r-- | spec/mailers/request_mailer_spec.rb | 43 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/purge_request_spec.rb | 9 | ||||
-rw-r--r-- | spec/script/mailin-spec.rb | 21 | ||||
-rw-r--r-- | spec/script/mailin_spec.rb | 37 | ||||
-rw-r--r-- | spec/views/request/show.html.erb_spec.rb | 4 |
19 files changed, 344 insertions, 75 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 38e874469..7b2876aff 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -62,6 +62,11 @@ describe PublicBodyController, "when showing a body" do RoutingFilter.active = true end + it "should remember the filter (view) setting on redirecting" do + get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful' + response.should redirect_to show_public_body_successful_url(:url_name => "etgq") + end + it "should redirect to newest name if you use historic name of public body in URL" do get :show, :url_name => "hdink", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 842b4e47c..396182f00 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -337,12 +337,12 @@ describe RequestController, "when showing one request" do it 'should not show the describe state form' do make_request - response.should_not have_selector('div.describe_state_form') + response.should_not have_tag('div.describe_state_form') end it 'should not ask the user to use the describe state form' do make_request - response.should_not have_selector('p#request_status', :content => "answer the question above") + response.should_not have_tag('p#request_status', :text => /answer the question above/) end end @@ -1251,8 +1251,7 @@ describe RequestController, "when classifying an information request" do end it 'should redirect to the request page' do - post :describe_state, :id => @external_request.id, - :submitted_describe_state => 1 + post :describe_state, :id => @external_request.id response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @external_request.url_title) @@ -1272,8 +1271,7 @@ describe RequestController, "when classifying an information request" do def post_status(status) post :describe_state, :incoming_message => { :described_state => status }, :id => @dog_request.id, - :last_info_request_event_id => @dog_request.last_event_id_needing_description, - :submitted_describe_state => 1 + :last_info_request_event_id => @dog_request.last_event_id_needing_description end it "should require login" do @@ -1283,6 +1281,7 @@ describe RequestController, "when classifying an information request" do end it 'should ask whether the request is old and unclassified' do + session[:user_id] = users(:silly_name_user).id @dog_request.should_receive(:is_old_unclassified?) post_status('rejected') end @@ -1322,7 +1321,7 @@ describe RequestController, "when classifying an information request" do it 'should classify the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user), nil) post_status('rejected') end @@ -1350,6 +1349,26 @@ describe RequestController, "when classifying an information request" do flash[:notice].should == 'Thank you for updating this request!' end + context "playing the classification game" do + before :each do + session[:request_game] = true + end + + it "should continue the game after classifying a request" do + post_status("rejected") + flash[:notice].should =~ /There are some more requests below for you to classify/ + response.should redirect_to categorise_play_url + end + end + + it "should send a mail from the user who changed the state to requires_admin" do + post :describe_state, :incoming_message => { :described_state => "requires_admin", :message => "a message" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email + end end end @@ -1365,7 +1384,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil) post_status('rejected') end @@ -1418,7 +1437,7 @@ describe RequestController, "when classifying an information request" do it 'should update the status of the request' do @dog_request.stub!(:calculate_status).and_return('rejected') - @dog_request.should_receive(:set_described_state).with('rejected') + @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil) post_status('rejected') end @@ -1453,6 +1472,22 @@ describe RequestController, "when classifying an information request" do @dog_request.stub!(:each).and_return([@dog_request]) end + it "should let you know when you forget to select a status" do + post :describe_state, :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) + flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.") + end + + it "should not change the status if the request has changed while viewing it" do + @dog_request.stub!(:last_event_id_needing_description).and_return(2) + + post :describe_state, :incoming_message => { :described_state => "rejected" }, + :id => @dog_request.id, :last_info_request_event_id => 1 + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) + flash[:error].should =~ /The request has been updated since you originally loaded this page/ + end + it "should successfully classify response if logged in as user controlling request" do post_status('rejected') response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) @@ -1473,22 +1508,34 @@ describe RequestController, "when classifying an information request" do post_status('rejected') end - it "should send email when classified as requires_admin" do - post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description, :submitted_describe_state => 1 - response.should redirect_to(:controller => 'help', :action => 'contact') + it "should go to the page asking for more information when classified as requires_admin" do + post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to describe_state_message_url(:url_title => @dog_request.url_title, :described_state => "requires_admin") @dog_request.reload - @dog_request.awaiting_description.should == false - @dog_request.described_state.should == 'requires_admin' - @dog_request.get_last_response_event.calculated_state.should == 'requires_admin' + @dog_request.described_state.should_not == 'requires_admin' + + ActionMailer::Base.deliveries.should be_empty + end + + context "message is included when classifying as requires_admin" do + it "should send an email including the message" do + post :describe_state, + :incoming_message => { + :described_state => "requires_admin", + :message => "Something weird happened" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /as needing admin/ - mail.from_addrs.first.to_s.should == @request_owner.email + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /as needing admin/ + mail.body.should =~ /Something weird happened/ + end end + it 'should say it is showing advice as to what to do next' do post_status('rejected') flash[:notice].should match(/Here is what to do now/) @@ -1598,12 +1645,22 @@ describe RequestController, "when classifying an information request" do expect_redirect('internal_review', request_url) end - it 'should redirect to the "help general url" when status is updated to "requires admin"' do - expect_redirect('requires_admin', "help/contact") + it 'should redirect to the "request url" when status is updated to "requires admin"' do + post :describe_state, :incoming_message => { + :described_state => 'requires_admin', + :message => "A message" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) end - it 'should redirect to the "help general url" when status is updated to "error message"' do - expect_redirect('error_message', "help/contact") + it 'should redirect to the "request url" when status is updated to "error message"' do + post :describe_state, :incoming_message => { + :described_state => 'error_message', + :message => "A message" }, + :id => @dog_request.id, + :last_info_request_event_id => @dog_request.last_event_id_needing_description + response.should redirect_to show_request_url(:url_title => @dog_request.url_title) end it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 8d9d7637b..e9501b1ed 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -57,7 +57,6 @@ end describe TrackController, "when sending alerts for a track" do render_views - include LinkToHelper # for main_url before(:each) do load_raw_emails_data @@ -104,7 +103,7 @@ describe TrackController, "when sending alerts for a track" do # Given we can't click the link, check the token is right instead post_redirect = PostRedirect.find_by_email_token(mail_token) - expected_url = main_url("/user/" + users(:silly_name_user).url_name + "#email_subscriptions") # XXX can't call URL making functions here, what is correct way to do this? + expected_url = show_user_url(:url_name => users(:silly_name_user).url_name, :anchor => "email_subscriptions") post_redirect.uri.should == expected_url # Check nothing more is delivered if we try again diff --git a/spec/fixtures/files/incoming-request-empty.email b/spec/fixtures/files/incoming-request-empty.email new file mode 100644 index 000000000..890a14f21 --- /dev/null +++ b/spec/fixtures/files/incoming-request-empty.email @@ -0,0 +1,8 @@ +From: EMAIL_FROM +To: FOI Person <EMAIL_TO> +Bcc: +Subject: Re: Nothing to see here. +Reply-To: +In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail> + + diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml index c1a00ad47..3907703d8 100644 --- a/spec/fixtures/info_request_events.yml +++ b/spec/fixtures/info_request_events.yml @@ -171,3 +171,14 @@ anonymous_external_outgoing_message_event: created_at: 2009-01-03 02:23:45.6789100 described_state: waiting_response calculated_state: waiting_response + +other_request_outgoing_message_event: + id: 916 + params_yaml: "--- \n\ + :outgoing_message_id: 10\n" + outgoing_message_id: 10 + info_request_id: 111 + event_type: sent + created_at: <%= Time.now %> + described_state: waiting_response + calculated_state: waiting_response diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index 9361ec486..97effd036 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -107,3 +107,15 @@ anonymous_external_request: awaiting_description: false comments_allowed: true idhash: 7654321a +other_request: + id: 111 + title: Another request + url_title: another_request + created_at: 2010-01-01 02:23:45.6789100 + updated_at: 2010-01-01 02:23:45.6789100 + public_body_id: 7 + user_id: 6 + described_state: waiting_response + awaiting_description: false + comments_allowed: true + idhash: b234567 diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml index 55df8473e..c71ee08bf 100644 --- a/spec/fixtures/outgoing_messages.yml +++ b/spec/fixtures/outgoing_messages.yml @@ -108,3 +108,14 @@ anonymous_external_outgoing_message: updated_at: 2009-01-12 01:56:58.586598 what_doing: normal_sort +other_outgoing_message: + id: 10 + info_request_id: 111 + message_type: initial_request + status: sent + body: "Just another request" + last_sent_at: <%= Time.now %> + created_at: 2009-01-12 01:56:58.586598 + updated_at: 2009-01-12 01:56:58.586598 + what_doing: normal_sort + diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index 615c4bcb6..65cba4b28 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -72,3 +72,18 @@ sensible_walks_public_body: created_at: 2008-10-25 10:51:01.161639 api_key: 5 info_requests_count: 1 +other_public_body: + id: 7 + version: 1 + name: 'Another Public Body' + first_letter: A + request_email: other@localhost + short_name: Another Public Body + url_name: another_public_body + notes: More notes + updated_at: 2008-10-25 10:51:01.161639 + last_edit_comment: Another edit + last_edit_editor: louise + created_at: 2008-10-25 10:51:01.161639 + api_key: 6 + info_requests_count: 0 diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml index 24b14c470..61e07fb5b 100644 --- a/spec/fixtures/public_body_translations.yml +++ b/spec/fixtures/public_body_translations.yml @@ -88,3 +88,16 @@ sensible_walks_en_public_body_translation: notes: I bet you’ve never heard of it. publication_scheme: "" disclosure_log: "" + +other_public_body_translation: + id: 8 + public_body_id: 7 + locale: en + name: "Another Public Body" + first_letter: A + request_email: other@localhost + short_name: Another Public Body + url_name: another_public_body + notes: More notes + publication_scheme: "" + disclosure_log: "" diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index d6391c5e8..c9730d855 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -1,4 +1,4 @@ -bob_smith_user: +bob_smith_user: id: "1" name: Bob Smith url_name: bob_smith @@ -13,7 +13,7 @@ bob_smith_user: locale: 'en' about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.' receive_email_alerts: true -silly_name_user: +silly_name_user: id: "2" name: "Silly <em>Name</em>" url_name: silly_emnameem @@ -28,7 +28,7 @@ silly_name_user: locale: 'en' about_me: '' receive_email_alerts: true -admin_user: +admin_user: id: "3" name: Joe Admin url_name: joe_admin @@ -43,7 +43,7 @@ admin_user: locale: '' about_me: '' receive_email_alerts: true -unconfirmed_user: +unconfirmed_user: id: "4" name: "Unconfirmed" url_name: unconfirmed @@ -71,3 +71,17 @@ robin_user: ban_text: '' about_me: 'I am the best' receive_email_alerts: true +another_user: + id: 6 + name: Another User + url_name: another_user + email: another@localhost + salt: "-6116981980.392287733335677" + hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword + updated_at: 2012-01-01 10:39:15.491593 + created_at: 2012-01-01 10:39:15.491593 + email_confirmed: true + admin_level: 'none' + ban_text: '' + about_me: 'Just another user' + receive_email_alerts: true diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 63daf1a75..5233f3f7f 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -16,11 +16,11 @@ describe LinkToHelper do it 'should return a path like /request/test_title' do - request_url(@mock_request).should == '/request/test_title' + request_path(@mock_request).should == '/request/test_title' end it 'should return a path including any extra parameters passed' do - request_url(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1' + request_path(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1' end end diff --git a/spec/integration/request_controller_spec.rb b/spec/integration/request_controller_spec.rb new file mode 100644 index 000000000..24667bdf1 --- /dev/null +++ b/spec/integration/request_controller_spec.rb @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe RequestController, "when classifying an information request" do + + describe 'when the request is internal' do + + before(:each) do + @dog_request = info_requests(:fancy_dog_request) + # This should happen automatically before each test but doesn't with these integration + # tests for some reason. + ActionMailer::Base.deliveries = [] + end + + describe 'when logged in as the requestor' do + + before :each do + @request_owner = @dog_request.user + visit signin_path + fill_in "Your e-mail:", :with => @request_owner.email + fill_in "Password:", :with => "jonespassword" + click_button "Sign in" + end + + it "should send an email including the message" do + visit describe_state_message_path(:url_title => @dog_request.url_title, + :described_state => "requires_admin") + fill_in "Please tell us more:", :with => "Okay. I don't quite understand." + click_button "Submit status and send message" + + response.should contain "Thank you! We'll look into what happened and try and fix it up." + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /as needing admin/ + mail.body.should =~ /Okay. I don't quite understand./ + end + end + end +end diff --git a/spec/lib/ability_spec.rb b/spec/lib/ability_spec.rb new file mode 100644 index 000000000..f075d0f32 --- /dev/null +++ b/spec/lib/ability_spec.rb @@ -0,0 +1,51 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe Ability do + describe ".can_update_request_state?" do + context "old and unclassified request" do + let(:request) { mock_model(InfoRequest, :is_old_unclassified? => true) } + + context "logged out" do + let(:user) { nil } + before(:each) { request.stub!(:is_owning_user?).and_return(false) } + it { Ability::can_update_request_state?(user, request).should be_false } + end + + context "logged in but not owner of request" do + let(:user) { mock_model(User) } + before(:each) { request.stub!(:is_owning_user?).and_return(false) } + + it { Ability::can_update_request_state?(user, request).should be_true } + end + end + + context "new request" do + let(:request) { mock_model(InfoRequest, :is_old_unclassified? => false) } + + context "logged out" do + let(:user) { nil } + before(:each) { request.stub!(:is_owning_user?).and_return(false) } + + it { Ability::can_update_request_state?(user, request).should be_false } + end + + context "logged in" do + let(:user) { mock_model(User) } + + # An owner of a request can also be someone with admin powers + context "as owner of request" do + before(:each) { request.stub!(:is_owning_user?).and_return(true) } + + it { Ability::can_update_request_state?(user, request).should be_true } + end + + context "but not owner of request" do + before(:each) { request.stub!(:is_owning_user?).and_return(false) } + + it { Ability::can_update_request_state?(user, request).should be_false } + end + end + end + end +end + diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 9597045eb..68cef2f0b 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -27,7 +27,7 @@ describe RequestMailer, " when receiving incoming mail" do receive_incoming_mail('incoming-request-plain.email', 'dummy@localhost') ir.incoming_messages.size.should == 1 InfoRequest.holding_pen_request.incoming_messages.size.should == 1 - last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last last_event.params[:rejected_reason].should == "Could not identify the request from the email address" deliveries = ActionMailer::Base.deliveries @@ -47,7 +47,7 @@ describe RequestMailer, " when receiving incoming mail" do receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "") ir.incoming_messages.size.should == 1 InfoRequest.holding_pen_request.incoming_messages.size.should == 1 - last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last last_event.params[:rejected_reason].should =~ /there is no "From" address/ deliveries = ActionMailer::Base.deliveries @@ -67,7 +67,7 @@ describe RequestMailer, " when receiving incoming mail" do receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com") ir.incoming_messages.size.should == 1 InfoRequest.holding_pen_request.incoming_messages.size.should == 1 - last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last last_event.params[:rejected_reason].should =~ /Only the authority can reply/ deliveries = ActionMailer::Base.deliveries @@ -152,7 +152,7 @@ describe RequestMailer, " when receiving incoming mail" do receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) ir.incoming_messages.size.should == 1 InfoRequest.holding_pen_request.incoming_messages.size.should == 1 # arrives in holding pen - last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last last_event.params[:rejected_reason].should =~ /allow new responses from nobody/ # should be a message to admin regarding holding pen @@ -329,6 +329,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla end + +describe RequestMailer, 'when sending a new response email' do + + before do + @user = mock_model(User, :name_and_email => 'test name and email') + @public_body = mock_model(PublicBody, :name => 'Test public body') + @info_request = mock_model(InfoRequest, :user => @user, + :law_used_full => 'Freedom of Information', + :title => 'Here is a character that needs quoting …', + :public_body => @public_body, + :display_status => 'Refused.', + :url_title => 'test_request') + @incoming_message = mock_model(IncomingMessage, :info_request => @info_request) + end + + it 'should not error when sending mails requests with characters requiring quoting in the subject' do + @mail = RequestMailer.new_response(@info_request, @incoming_message) + end + +end + describe RequestMailer, 'requires_admin' do before(:each) do user = mock_model(User, :name_and_email => 'Bruce Jones', @@ -347,15 +368,9 @@ describe RequestMailer, 'requires_admin' do mail.body.should include('http://test.host/en/admin/request/show/123') end - context 'has an ADMIN_BASE_URL set' do - before(:each) do - AlaveteliConfiguration::should_receive(:admin_base_url).and_return('http://our.proxy.server/admin/alaveteli/') - end - - it 'body should contain the full admin URL' do - mail = RequestMailer.requires_admin(@info_request).deliver - - mail.body.should include('http://our.proxy.server/admin/alaveteli/request/show/123') - end + it "body should contain the message from the user" do + mail = RequestMailer.requires_admin(@info_request, nil, "Something has gone wrong").deliver + mail.body.should include 'Something has gone wrong' end + end diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index a1a6e6c27..3eb88b2bb 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -426,8 +426,8 @@ 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') - @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response') + @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) @info_request = InfoRequest.new(:prominence => 'normal', :awaiting_description => true, :info_request_events => [@mock_response_event, @mock_comment_event]) diff --git a/spec/models/purge_request_spec.rb b/spec/models/purge_request_spec.rb index 94fe01317..7b67fca52 100644 --- a/spec/models/purge_request_spec.rb +++ b/spec/models/purge_request_spec.rb @@ -1,12 +1,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'fakeweb' -describe PurgeRequest, "purging things" do +describe PurgeRequest, "purging things" do before do + PurgeRequest.destroy_all FakeWeb.last_request = nil end - it 'should issue purge requests to the server' do + it 'should issue purge requests to the server' do req = PurgeRequest.new(:url => "/begone_from_here", :model => "don't care", :model_id => "don't care") @@ -16,7 +17,7 @@ describe PurgeRequest, "purging things" do PurgeRequest.all().count.should == 0 end - it 'should fail silently for a misconfigured server' do + it 'should fail silently for a misconfigured server' do FakeWeb.register_uri(:get, %r|brokenv|, :body => "BROKEN") config = MySociety::Config.load_default() config['VARNISH_HOST'] = "brokencache" @@ -29,4 +30,4 @@ describe PurgeRequest, "purging things" do PurgeRequest.all().count.should == 0 end end - + diff --git a/spec/script/mailin-spec.rb b/spec/script/mailin-spec.rb deleted file mode 100644 index d80789635..000000000 --- a/spec/script/mailin-spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -require "external_command" - -def mailin_test(email_filename) - Dir.chdir Rails.root do - xc = ExternalCommand.new("script/mailin") - xc.run(load_file_fixture(email_filename)) - xc.err.should == "" - return xc - end -end - -describe "When importing mail into the application" do - - it "should not produce any output and should return a 0 code on importing a plain email" do - r = mailin_test("incoming-request-plain.email") - r.status.should == 0 - r.out.should == "" - end - -end
\ No newline at end of file diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb new file mode 100644 index 000000000..acd06ff3b --- /dev/null +++ b/spec/script/mailin_spec.rb @@ -0,0 +1,37 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require "external_command" + +def mailin_test(email_filename) + Dir.chdir Rails.root do + xc = ExternalCommand.new("script/mailin") + mail = load_file_fixture(email_filename) + ir = info_requests(:other_request) + mail.gsub!('EMAIL_TO', ir.incoming_email) + mail.gsub!('EMAIL_FROM', 'responder@localhost') + xc.run(mail) + xc.err.should == "" + return xc + end +end + +describe "When importing mail into the application" do + + # Turn off transactional fixtures for this suite - incoming message is imported + # outside the transaction via ExternalCommand, so needs to be destroyed outside the + # transaction + self.use_transactional_fixtures = false + + it "should not produce any output and should return a 0 code on importing a plain email" do + r = mailin_test("incoming-request-empty.email") + r.status.should == 0 + r.out.should == "" + end + + # Destroy the incoming message so that it doesn't affect other tests + after do + ir = info_requests(:other_request) + incoming_message = ir.incoming_messages[0] + incoming_message.fully_destroy + end + +end diff --git a/spec/views/request/show.html.erb_spec.rb b/spec/views/request/show.html.erb_spec.rb index 7fc96a36c..1c1ab8476 100644 --- a/spec/views/request/show.html.erb_spec.rb +++ b/spec/views/request/show.html.erb_spec.rb @@ -85,7 +85,7 @@ describe 'request/show' do it 'should show a link to follow up the last response with clarification' do request_page - expected_url = "http://test.host/en/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" + expected_url = "/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" response.should have_selector("a", :href => expected_url, :content => 'send a follow up message') end @@ -100,7 +100,7 @@ describe 'request/show' do it 'should show a link to follow up the request without reference to a specific response' do request_page - expected_url = "http://test.host/en/request/#{@mock_request.id}/response#followup" + expected_url = "/request/#{@mock_request.id}/response#followup" response.should have_selector("a", :href => expected_url, :content => 'send a follow up message') end end |