discussion_block_test.rb
8.4 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
require_relative '../test_helper'
class DiscussionBlockTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
@environment.enable_plugin(CommentParagraphPlugin)
end
attr_reader :environment
should 'describe itself' do
assert_not_equal Block.description, CommentParagraphPlugin::DiscussionBlock.description
end
should 'holder be nil if there is no box' do
b = CommentParagraphPlugin::DiscussionBlock.new
assert_nil b.holder
end
should 'holder be nil if there is no box owner to the box' do
b = CommentParagraphPlugin::DiscussionBlock.new
box = Box.new
b.box = box
assert_nil b.holder
end
should 'holder be nil if there is no portal community in environment' do
b = CommentParagraphPlugin::DiscussionBlock.new
environment.boxes<< Box.new
b.box = environment.boxes.last
assert_nil environment.portal_community
assert_nil b.holder
end
should 'holder be the portal community for environments blocks' do
community = fast_create(Community)
environment.portal_community= community
environment.save!
environment.boxes<< Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = environment.boxes.last
assert_equal environment.portal_community, b.holder
end
should 'holder be the person for people blocks' do
person = fast_create(Person)
person.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = person.boxes.last
assert_equal person, b.holder
end
should 'holder be the community for communities blocks' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
assert_equal community, b.holder
end
should 'holder be the enterprise for enterprises blocks' do
enterprise = fast_create(Enterprise)
enterprise.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = enterprise.boxes.last
assert_equal enterprise, b.holder
end
should 'discussions return only discussion articles' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
b.save
a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
fast_create(Event, :profile_id => community.id)
fast_create(TinyMceArticle, :profile_id => community.id)
a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
assert_equivalent [a1, a2], b.discussions
end
should 'return only not opened discussions if discussion status is not opened' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
b.discussion_status = CommentParagraphPlugin::DiscussionBlock::STATUS_NOT_OPENED
b.save
a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now + 1.day)
a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now )
a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 1.day)
a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 2.day, :end_date => DateTime.now - 1.day)
assert_equivalent [a1], b.discussions
end
should 'return only available discussions if discussion status is available' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
b.discussion_status = CommentParagraphPlugin::DiscussionBlock::STATUS_AVAILABLE
b.save
a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now + 1.day)
a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now )
a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 1.day)
a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 2.day, :end_date => DateTime.now - 1.day)
a5 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :end_date => DateTime.now + 1.day)
assert_equivalent [a2, a3, a5], b.discussions
end
should 'return only closed discussions if discussion status is closed' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
b.discussion_status = CommentParagraphPlugin::DiscussionBlock::STATUS_CLOSED
b.save
a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now + 1.day)
a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now )
a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 1.day)
a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, :start_date => DateTime.now - 2.day, :end_date => DateTime.now - 1.day)
assert_equivalent [a4], b.discussions
end
end
require 'boxes_helper'
class DiscussionBlockViewTest < ActionView::TestCase
include BoxesHelper
should 'show the title and the child titles when the block is set to title only mode' do
profile = create_user('testuser').person
block = CommentParagraphPlugin::DiscussionBlock.new
block.stubs(:holder).returns(profile)
block.presentation_mode = 'title_only'
ActionView::Base.any_instance.stubs(:block_title).returns("Block Title")
ActionView::Base.any_instance.stubs(:profile).returns(profile)
content = render_block_content(block)
assert_match /discussion-title/, content
assert_no_match /discussion-abstract/, content
end
should 'show the title and the child titles and abstracts when the block is set to title and abstract mode' do
profile = create_user('testuser').person
block = CommentParagraphPlugin::DiscussionBlock.new
block.stubs(:holder).returns(profile)
block.presentation_mode = 'title_and_abstract'
ActionView::Base.any_instance.stubs(:block_title).returns("Block Title")
ActionView::Base.any_instance.stubs(:profile).returns(profile)
content = render_block_content(block)
assert_match /discussion-abstract/, content
end
should 'show the title and the child full content when the block has no mode set' do
profile = create_user('testuser').person
block = CommentParagraphPlugin::DiscussionBlock.new
block.stubs(:holder).returns(profile)
block.presentation_mode = ''
ActionView::Base.any_instance.stubs(:block_title).returns("Block Title")
ActionView::Base.any_instance.stubs(:profile).returns(profile)
content = render_block_content(block)
assert_match /discussion-full/, content
end
should 'return discussions in api_content' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
b.save
a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
fast_create(Event, :profile_id => community.id)
fast_create(TinyMceArticle, :profile_id => community.id)
a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
assert_equivalent [a2.id, a1.id], b.api_content['articles'].map {|a| a[:id]}
end
should 'sort discussions by start_date, end_date and created_at' do
community = fast_create(Community)
community.boxes << Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
b.box = community.boxes.last
b.save
a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now)
a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now)
a3 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now + 1.day)
a4 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id, start_date: Time.now + 1, end_date: Time.now + 1.day)
assert_equal [a1.id, a2.id, a3.id, a4.id], b.discussions.map(&:id)
end
end