ref: master
plugins/newsletter/test/unit/newsletter_plugin_newsletter_mailing_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
require 'test_helper' class NewsletterPluginNewsletterMailingTest < ActiveSupport::TestCase def setup ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] end should 'require source id' do mailing = NewsletterPlugin::NewsletterMailing.new mailing.valid? assert mailing.errors[:source_id].any? mailing.source_id = NewsletterPlugin::Newsletter.create!(:environment => fast_create(Environment), :person => fast_create(Person)).id mailing.valid? refute mailing.errors[:source_id].any? end should 'deliver mail from noreply environment email address' do environment = fast_create(Environment, :noreply_email => 'noreply@localhost') person = fast_create Person newsletter = NewsletterPlugin::Newsletter.create!(:environment => environment, :person => person, :enabled => true) mailing = NewsletterPlugin::NewsletterMailing.create!( :source => newsletter, :subject => newsletter.subject, :body => newsletter.body, :person => newsletter.person, :locale => environment.default_locale, ) response = NewsletterPlugin::NewsletterMailing::Sender.notification(mailing, 'recipient@example.com').deliver assert_equal 'noreply@localhost', response.from.join end should 'also send to additional recipients' do environment = fast_create(Environment, :name => 'Network') person = create_user('betty', :environment_id => environment.id).person newsletter = NewsletterPlugin::Newsletter.create!(:environment => environment, :person => person) newsletter.additional_recipients = [{name: 'example', email: 'exemple@mail.co'}, {name: 'jon', email: 'jonsnow@mail.co'}] newsletter.save! mailing = NewsletterPlugin::NewsletterMailing.create!( :source => newsletter, :subject => newsletter.subject, :body => newsletter.body, :person => newsletter.person, :locale => newsletter.environment.default_locale, ) process_delayed_job_queue assert_equal 3, ActionMailer::Base.deliveries.count end should 'generate url to view mailing' do newsletter = NewsletterPlugin::Newsletter.create!( :environment => fast_create(Environment), :person => fast_create(Person), :enabled => true ) mailing = NewsletterPlugin::NewsletterMailing.create!( :source => newsletter, :subject => newsletter.subject, :body => newsletter.body, :person => newsletter.person, :locale => newsletter.environment.default_locale, ) assert_equal "http://localhost/plugin/newsletter/mailing/#{mailing.id}", mailing.url end end |