ref: master
plugins/newsletter/test/unit/newsletter_plugin_moderate_newsletter_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 |
require 'test_helper' class NewsletterPluginModerateNewsletterTest < ActiveSupport::TestCase should 'validates presence of newsletter_id' do task = NewsletterPlugin::ModerateNewsletter.new task.valid? assert task.errors.include?(:newsletter_id) task.newsletter_id = 1 task.valid? refute task.errors.include?(:newsletter_id) end should 'create mailing on perform' do person = create_user('john').person newsletter = NewsletterPlugin::Newsletter.create!(:environment => fast_create(Environment), :person => person, :enabled => true) task = NewsletterPlugin::ModerateNewsletter.create!( :newsletter_id => newsletter.id, :target => newsletter.environment ) assert_difference 'NewsletterPlugin::NewsletterMailing.count', 1 do task.finish end end should 'set posts for mailing body on perform' do person = create_user('john').person blog = fast_create(Blog, profile_id: person.id) post_1 = fast_create(TextArticle, :name => 'First post', :profile_id => person.id, :parent_id => blog.id, :body => 'Test') post_2 = fast_create(TextArticle, :name => 'Second post', :profile_id => person.id, :parent_id => blog.id, :body => 'Test') post_3 = fast_create(TextArticle, :name => 'Third post', :profile_id => person.id, :parent_id => blog.id, :body => 'Test') newsletter = NewsletterPlugin::Newsletter.create!(:environment => person.environment, :person => person, :enabled => true) newsletter.blog_ids = [blog.id] newsletter.save! task = NewsletterPlugin::ModerateNewsletter.create!( :newsletter_id => newsletter.id, :target => newsletter.environment, :post_ids => [post_1.id.to_s,post_2.id.to_s] ) task.finish assert_match /First post/, NewsletterPlugin::NewsletterMailing.last.body assert_match /Second post/, NewsletterPlugin::NewsletterMailing.last.body assert_no_match /Third post/, NewsletterPlugin::NewsletterMailing.last.body end end |