Commit e168cf92fee529d1091604b632159e3f815c2c0b
1 parent
75125b2a
Exists in
master
and in
28 other branches
Change community track to allow visualization of inactive steps
Showing
4 changed files
with
57 additions
and
49 deletions
Show diff stats
plugins/community_track/lib/community_track_plugin/activation_job.rb
plugins/community_track/lib/community_track_plugin/step.rb
... | ... | @@ -18,7 +18,7 @@ class CommunityTrackPlugin::Step < Folder |
18 | 18 | after_save :schedule_activation |
19 | 19 | |
20 | 20 | before_create do |step| |
21 | - step.published = false | |
21 | + step.accept_comments = false | |
22 | 22 | true |
23 | 23 | end |
24 | 24 | |
... | ... | @@ -55,7 +55,7 @@ class CommunityTrackPlugin::Step < Folder |
55 | 55 | end |
56 | 56 | |
57 | 57 | def accept_comments? |
58 | - true | |
58 | + accept_comments | |
59 | 59 | end |
60 | 60 | |
61 | 61 | def self.enabled_tools |
... | ... | @@ -82,18 +82,23 @@ class CommunityTrackPlugin::Step < Folder |
82 | 82 | end |
83 | 83 | |
84 | 84 | def schedule_activation |
85 | - return if !changes['start_date'] && !changes['end_date'] && !changes['published'] | |
86 | - today = Date.today | |
87 | - if today <= end_date || published | |
88 | - schedule_date = !published ? start_date : end_date + 1.day | |
85 | + return if !changes['start_date'] && !changes['end_date'] | |
86 | + if Date.today <= end_date || accept_comments | |
87 | + schedule_date = !accept_comments ? start_date : end_date + 1.day | |
89 | 88 | CommunityTrackPlugin::ActivationJob.find(id).destroy_all |
90 | 89 | Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date) |
91 | 90 | end |
92 | 91 | end |
93 | 92 | |
94 | - def publish | |
95 | - self[:published] = active? && !hidden | |
96 | - save! | |
93 | + def toggle_activation | |
94 | + accept_comments = active? | |
95 | + # set accept_comments = true on all children | |
96 | + self.class.toggle_activation(self, accept_comments) | |
97 | + end | |
98 | + | |
99 | + def self.toggle_activation(article, accept_comments) | |
100 | + article.update_attribute(:accept_comments, accept_comments) | |
101 | + article.children.each {|a| toggle_activation(a, accept_comments)} | |
97 | 102 | end |
98 | 103 | |
99 | 104 | def tool_class | ... | ... |
plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb
... | ... | @@ -15,24 +15,14 @@ class ActivationJobTest < ActiveSupport::TestCase |
15 | 15 | assert CommunityTrackPlugin::ActivationJob.find(step_id) |
16 | 16 | end |
17 | 17 | |
18 | - should 'change publish to true on perform delayed job in a active step' do | |
18 | + should 'change accept_comments to true on perform delayed job in a active step' do | |
19 | 19 | @step.start_date = Date.today |
20 | 20 | @step.end_date = Date.today + 2.days |
21 | - @step.published = false | |
21 | + @step.accept_comments = false | |
22 | 22 | @step.save! |
23 | 23 | CommunityTrackPlugin::ActivationJob.new(@step.id).perform |
24 | 24 | @step.reload |
25 | - assert @step.published | |
26 | - end | |
27 | - | |
28 | - should 'reschedule delayed job after change publish to true' do | |
29 | - @step.start_date = Date.today | |
30 | - @step.end_date = Date.today + 2.days | |
31 | - @step.published = false | |
32 | - @step.save! | |
33 | - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date | |
34 | - process_delayed_job_queue | |
35 | - assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date | |
25 | + assert @step.accept_comments | |
36 | 26 | end |
37 | 27 | |
38 | 28 | end | ... | ... |
plugins/community_track/test/unit/community_track_plugin/step_test.rb
... | ... | @@ -21,10 +21,10 @@ class StepTest < ActiveSupport::TestCase |
21 | 21 | assert CommunityTrackPlugin::Step.short_description |
22 | 22 | end |
23 | 23 | |
24 | - should 'set published to false on create' do | |
24 | + should 'set accept_comments to false on create' do | |
25 | 25 | today = Date.today |
26 | 26 | step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) |
27 | - assert !step.published | |
27 | + assert !step.accept_comments | |
28 | 28 | end |
29 | 29 | |
30 | 30 | should 'do not allow step creation with a parent that is not a track' do |
... | ... | @@ -97,6 +97,7 @@ class StepTest < ActiveSupport::TestCase |
97 | 97 | should 'create delayed job' do |
98 | 98 | @step.start_date = Date.today |
99 | 99 | @step.end_date = Date.today |
100 | + @step.accept_comments = false | |
100 | 101 | @step.schedule_activation |
101 | 102 | assert_equal 1, Delayed::Job.count |
102 | 103 | assert_equal @step.start_date, Delayed::Job.first.run_at.to_date |
... | ... | @@ -106,6 +107,7 @@ class StepTest < ActiveSupport::TestCase |
106 | 107 | @step.start_date = Date.today |
107 | 108 | @step.end_date = Date.today |
108 | 109 | @step.schedule_activation |
110 | + assert_equal 1, Delayed::Job.count | |
109 | 111 | @step.schedule_activation |
110 | 112 | assert_equal 1, Delayed::Job.count |
111 | 113 | end |
... | ... | @@ -120,30 +122,21 @@ class StepTest < ActiveSupport::TestCase |
120 | 122 | should 'create delayed job even if start date has passed' do |
121 | 123 | @step.start_date = Date.today - 2.days |
122 | 124 | @step.end_date = Date.today |
125 | + @step.accept_comments = false | |
123 | 126 | @step.schedule_activation |
124 | 127 | assert_equal @step.start_date, Delayed::Job.first.run_at.to_date |
125 | 128 | end |
126 | 129 | |
127 | - should 'do not create delayed job if end date has passed and step is not published' do | |
130 | + should 'create delayed job if end date has passed' do | |
128 | 131 | @step.start_date = Date.today - 5.days |
129 | 132 | @step.end_date = Date.today - 2.days |
130 | - @step.published = false | |
131 | - @step.schedule_activation | |
132 | - assert_equal 0, Delayed::Job.count | |
133 | - end | |
134 | - | |
135 | - should 'create delayed job if end date has passed and step is published' do | |
136 | - @step.start_date = Date.today - 5.days | |
137 | - @step.end_date = Date.today - 2.days | |
138 | - @step.published = true | |
139 | 133 | @step.schedule_activation |
140 | 134 | assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date |
141 | 135 | end |
142 | 136 | |
143 | - should 'do not schedule delayed job if save but do not modify date fields and published status' do | |
137 | + should 'do not schedule delayed job if save but do not modify date fields' do | |
144 | 138 | @step.start_date = Date.today |
145 | 139 | @step.end_date = Date.today |
146 | - @step.published = false | |
147 | 140 | @step.save! |
148 | 141 | assert_equal 1, Delayed::Job.count |
149 | 142 | Delayed::Job.destroy_all |
... | ... | @@ -161,38 +154,38 @@ class StepTest < ActiveSupport::TestCase |
161 | 154 | assert_equal 2, step2.position |
162 | 155 | end |
163 | 156 | |
164 | - should 'publish step if it is active' do | |
157 | + should 'accept comments if step is active' do | |
165 | 158 | @step.start_date = Date.today |
166 | 159 | @step.save! |
167 | - assert !@step.published | |
168 | - @step.publish | |
160 | + assert !@step.accept_comments | |
161 | + @step.toggle_activation | |
169 | 162 | @step.reload |
170 | - assert @step.published | |
163 | + assert @step.accept_comments | |
171 | 164 | end |
172 | 165 | |
173 | - should 'do not publish step if it is not active' do | |
166 | + should 'do not accept comments if step is not active' do | |
174 | 167 | @step.start_date = Date.today + 2.days |
175 | 168 | @step.end_date = Date.today + 3.days |
176 | 169 | @step.save! |
177 | 170 | assert !@step.published |
178 | - @step.publish | |
171 | + @step.toggle_activation | |
179 | 172 | @step.reload |
180 | 173 | assert !@step.published |
181 | 174 | end |
182 | 175 | |
183 | - should 'unpublish step if it is not active anymore' do | |
176 | + should 'do not accept comments if step is not active anymore' do | |
184 | 177 | @step.start_date = Date.today |
185 | 178 | @step.save! |
186 | - @step.publish | |
179 | + @step.toggle_activation | |
187 | 180 | @step.reload |
188 | - assert @step.published | |
181 | + assert @step.accept_comments | |
189 | 182 | |
190 | 183 | @step.start_date = Date.today - 2.days |
191 | 184 | @step.end_date = Date.today - 1.day |
192 | 185 | @step.save! |
193 | - @step.publish | |
186 | + @step.toggle_activation | |
194 | 187 | @step.reload |
195 | - assert !@step.published | |
188 | + assert !@step.accept_comments | |
196 | 189 | end |
197 | 190 | |
198 | 191 | should 'set position to zero if step is hidden' do |
... | ... | @@ -236,7 +229,7 @@ class StepTest < ActiveSupport::TestCase |
236 | 229 | @step.hidden = true |
237 | 230 | @step.save! |
238 | 231 | assert !@step.published |
239 | - @step.publish | |
232 | + @step.toggle_activation | |
240 | 233 | @step.reload |
241 | 234 | assert !@step.published |
242 | 235 | end |
... | ... | @@ -272,4 +265,24 @@ class StepTest < ActiveSupport::TestCase |
272 | 265 | assert step.end_date |
273 | 266 | end |
274 | 267 | |
268 | + should 'enable comments on children when step is activated' do | |
269 | + @step.start_date = Date.today | |
270 | + @step.save! | |
271 | + assert !@step.accept_comments | |
272 | + article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false) | |
273 | + assert !article.accept_comments | |
274 | + @step.toggle_activation | |
275 | + assert article.reload.accept_comments | |
276 | + end | |
277 | + | |
278 | + should 'enable comments on children when step is active' do | |
279 | + @step.start_date = Date.today | |
280 | + @step.start_date = Date.today | |
281 | + @step.save! | |
282 | + assert !@step.accept_comments | |
283 | + @step.toggle_activation | |
284 | + article = Article.create!(:parent => @step, :profile => @step.profile, :accept_comments => false, :name => "article") | |
285 | + assert article.reload.accept_comments | |
286 | + end | |
287 | + | |
275 | 288 | end | ... | ... |