approve_article_test.rb
2.87 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
require File.dirname(__FILE__) + '/../test_helper'
class ApproveArticleTest < ActiveSupport::TestCase
should 'have name, reference article and profile' do
profile = create_user('test_user').person
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
profile = create_user('test_user').person
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 = create_user('testuser1').person
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
profile = create_user('test_user').person
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
profile = create_user('test_user').person
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
profile = create_user('test_user').person
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
profile = create_user('test_user').person
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
profile = create_user('test_user').person
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
end