diff options
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/track_mailer_spec.rb | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb index 07f0e073e..509d08331 100644 --- a/spec/mailers/track_mailer_spec.rb +++ b/spec/mailers/track_mailer_spec.rb @@ -69,11 +69,15 @@ describe TrackMailer do @xapian_search = mock('xapian search', :results => []) @found_event = mock_model(InfoRequestEvent, :described_at => @track_thing.created_at + 1.day) @search_result = {:model => @found_event} - InfoRequest.stub!(:full_search).and_return(@xapian_search) + ActsAsXapian::Search.stub!(:new).and_return(@xapian_search) end it 'should ask for the events returned by the tracking query' do - InfoRequest.should_receive(:full_search).with([InfoRequestEvent], 'test query', 'described_at', true, nil, 100, 1).and_return(@xapian_search) + ActsAsXapian::Search.should_receive(:new).with([InfoRequestEvent], 'test query', + :sort_by_prefix => 'described_at', + :sort_by_ascending => true, + :collapse_by_prefix => nil, + :limit => 100).and_return(@xapian_search) TrackMailer.alert_tracks end @@ -162,20 +166,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.event_digest(@user, []).deliver # 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.event_digest(@user, []).deliver # 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| @@ -192,6 +195,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 AlaveteliConfiguration.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 |