cirandas.net

ref: master

plugins/tolerance_time/test/unit/article_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
require 'test_helper'

class ArticleTest < ActiveSupport::TestCase
  should 'create a publication after publishing the article' do
    article = fast_create(Article, :published => false, :profile_id => fast_create(Profile).id)
    assert_nil ToleranceTimePlugin::Publication.find_by target: article

    article.published = true
    article.save!
    assert_not_nil ToleranceTimePlugin::Publication.find_by target: article
  end

  should 'destroy publication if the article is destroyed' do
    profile = fast_create(Profile)
    article = fast_create(Article, :profile_id => profile.id)
    article_publication = ToleranceTimePlugin::Publication.create!(:target => article)
    article.destroy
    assert_raise ActiveRecord::RecordNotFound do
      article_publication.reload
    end
  end

  should 'destroy publication if the article is changed to not published' do
    profile = fast_create(Profile)
    article = fast_create(Article, :profile_id => profile.id)
    article_publication = ToleranceTimePlugin::Publication.create!(:target => article)
    article.published = false
    article.save!
    assert_raise ActiveRecord::RecordNotFound do
      article_publication.reload
    end
  end
end