approve_article_test.rb
3.47 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require File.dirname(__FILE__) + '/../test_helper'
class ApproveArticleTest < ActiveSupport::TestCase
def setup
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@profile = create_user('test_user').person
end
attr_reader :profile
should 'have name, reference article and profile' do
article = profile.articles.create!(:name => 'test article')
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
assert_equal 'test name', a.name
assert_equal article, a.article
assert_equal profile, a.target
end
should 'create published article when finished' do
article = profile.articles.create!(:name => 'test article')
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
assert_difference PublishedArticle, :count do
a.finish
end
end
should 'override target notification message method from Task' do
p1 = profile
p2 = create_user('testuser2').person
task = AddFriend.new(:person => p1, :friend => p2)
assert_nothing_raised NotImplementedError do
task.target_notification_message
end
end
should 'have parent if defined' do
article = profile.articles.create!(:name => 'test article')
folder = profile.articles.create!(:name => 'test folder', :type => 'Folder')
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id)
assert_equal folder, a.article_parent
end
should 'not have parent if not defined' do
article = profile.articles.create!(:name => 'test article')
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
assert_nil a.article_parent
end
should 'alert when reference article is removed' do
article = profile.articles.create!(:name => 'test article')
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
article.destroy
a.reload
assert_match /text was removed/, a.description
end
should 'preserve article_parent' do
article = profile.articles.create!(:name => 'test article')
a = ApproveArticle.new(:article_parent => article)
assert_equal article, a.article_parent
end
should 'handle blank names' do
article = profile.articles.create!(:name => 'test article')
community = Community.create!(:name => 'test comm')
a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
assert_difference PublishedArticle, :count do
a.finish
end
end
should 'notify target if group is moderated' do
article = profile.articles.create!(:name => 'test article')
community = Community.create!(:name => 'test comm', :moderated_articles => true)
a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
assert !ActionMailer::Base.deliveries.empty?
end
should 'not notify target if group is not moderated' do
article = profile.articles.create!(:name => 'test article')
community = Community.create!(:name => 'test comm', :moderated_articles => false)
a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
assert ActionMailer::Base.deliveries.empty?
end
end