diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/info_request_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/purge_request_spec.rb | 9 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 46 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 29 |
5 files changed, 63 insertions, 31 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 544852f91..728a538f9 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 = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment') - @mock_response_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response') + @mock_comment_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment', :response? => false) + @mock_response_event = safe_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/public_body_spec.rb b/spec/models/public_body_spec.rb index c2e0a6353..0b1bfccd7 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -210,7 +210,7 @@ describe PublicBody, "when searching" do end it "should cope with same url_name across multiple locales" do - PublicBody.with_locale(:es) do + I18n.with_locale(:es) do # use the unique spanish name to retrieve and edit body = PublicBody.find_by_url_name_with_historic('etgq') body.short_name = 'tgq' # Same as english version @@ -231,7 +231,7 @@ end describe PublicBody, " when dealing public body locales" do it "shouldn't fail if it internal_admin_body was created in a locale other than the default" do # first time, do it with the non-default locale - PublicBody.with_locale(:es) do + I18n.with_locale(:es) do PublicBody.internal_admin_body end @@ -378,7 +378,7 @@ describe PublicBody, " when loading CSV files" do PublicBody.count.should == original_count + 3 - # XXX Not sure why trying to do a PublicBody.with_locale fails here. Seems related to + # XXX Not sure why trying to do a I18n.with_locale fails here. Seems related to # the way categories are loaded every time from the PublicBody class. For now we just # test some translation was done. body = PublicBody.find_by_name('North West Fake Authority') 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/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index 0f09e6926..40133eedc 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestMailer, " when receiving incoming mail" do @@ -27,7 +28,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 +48,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 +68,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 @@ -98,7 +99,7 @@ describe RequestMailer, " when receiving incoming mail" do mail.multipart?.should == true mail.parts.size.should == 2 message_part = mail.parts[0].to_s - bounced_mail = MailHandler.mail_from_raw_email(mail.parts[1].body, decode=false) + bounced_mail = MailHandler.mail_from_raw_email(mail.parts[1].body) bounced_mail.to.should == [ ir.incoming_email ] bounced_mail.from.should == [ 'geraldinequango@localhost' ] bounced_mail.body.include?("That's so totally a rubbish question").should be_true @@ -152,7 +153,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 @@ -327,6 +328,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.create_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', @@ -345,15 +367,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 - Configuration::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.deliver_requires_admin(@info_request) - - 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.deliver_requires_admin(@info_request, nil, "Something has gone wrong") + mail.body.should include 'Something has gone wrong' end + end diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 9bf03c3d0..97f12b8f5 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -160,20 +160,19 @@ describe TrackMailer do describe 'delivering the email' do - before do + before :each do @post_redirect = mock_model(PostRedirect, :save! => true, :email_token => "token") PostRedirect.stub!(:new).and_return(@post_redirect) ActionMailer::Base.deliveries = [] + @user = mock_model(User, + :name_and_email => MailHandler.address_from_name_and_email('Tippy Test', 'tippy@localhost'), + :url_name => 'tippy_test' + ) + TrackMailer.deliver_event_digest(@user, []) # no items in it email for minimal test end it 'should deliver one email, with right headers' do - @user = mock_model(User, - :name_and_email => MailHandler.address_from_name_and_email('Tippy Test', 'tippy@localhost'), - :url_name => 'tippy_test' - ) - - TrackMailer.deliver_event_digest(@user, []) # no items in it email for minimal test deliveries = ActionMailer::Base.deliveries if deliveries.size > 1 # debugging if there is an error deliveries.each do |d| @@ -190,6 +189,22 @@ describe TrackMailer do deliveries.clear end + + context "force ssl is off" do + # Force SSL is off in the tests. Since the code that selectively switches the protocols + # is in the initialiser for Rails it's hard to test. Hmmm... + # We could Configuration.stub!(:force_ssl).and_return(true) but the config/environment.rb + # wouldn't get reloaded + + it "should have http links in the email" do + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + + mail.body.should include("http://") + mail.body.should_not include("https://") + end + end end end |