Commit e168cf92fee529d1091604b632159e3f815c2c0b

Authored by Victor Costa
1 parent 75125b2a

Change community track to allow visualization of inactive steps

plugins/community_track/lib/community_track_plugin/activation_job.rb
@@ -6,7 +6,7 @@ class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id) @@ -6,7 +6,7 @@ class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id)
6 6
7 def perform 7 def perform
8 step = CommunityTrackPlugin::Step.find(step_id) 8 step = CommunityTrackPlugin::Step.find(step_id)
9 - step.publish 9 + step.toggle_activation
10 end 10 end
11 11
12 end 12 end
plugins/community_track/lib/community_track_plugin/step.rb
@@ -18,7 +18,7 @@ class CommunityTrackPlugin::Step < Folder @@ -18,7 +18,7 @@ class CommunityTrackPlugin::Step < Folder
18 after_save :schedule_activation 18 after_save :schedule_activation
19 19
20 before_create do |step| 20 before_create do |step|
21 - step.published = false 21 + step.accept_comments = false
22 true 22 true
23 end 23 end
24 24
@@ -55,7 +55,7 @@ class CommunityTrackPlugin::Step < Folder @@ -55,7 +55,7 @@ class CommunityTrackPlugin::Step < Folder
55 end 55 end
56 56
57 def accept_comments? 57 def accept_comments?
58 - true 58 + accept_comments
59 end 59 end
60 60
61 def self.enabled_tools 61 def self.enabled_tools
@@ -82,18 +82,23 @@ class CommunityTrackPlugin::Step < Folder @@ -82,18 +82,23 @@ class CommunityTrackPlugin::Step < Folder
82 end 82 end
83 83
84 def schedule_activation 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 CommunityTrackPlugin::ActivationJob.find(id).destroy_all 88 CommunityTrackPlugin::ActivationJob.find(id).destroy_all
90 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date) 89 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date)
91 end 90 end
92 end 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 end 102 end
98 103
99 def tool_class 104 def tool_class
plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb
@@ -15,24 +15,14 @@ class ActivationJobTest &lt; ActiveSupport::TestCase @@ -15,24 +15,14 @@ class ActivationJobTest &lt; ActiveSupport::TestCase
15 assert CommunityTrackPlugin::ActivationJob.find(step_id) 15 assert CommunityTrackPlugin::ActivationJob.find(step_id)
16 end 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 @step.start_date = Date.today 19 @step.start_date = Date.today
20 @step.end_date = Date.today + 2.days 20 @step.end_date = Date.today + 2.days
21 - @step.published = false 21 + @step.accept_comments = false
22 @step.save! 22 @step.save!
23 CommunityTrackPlugin::ActivationJob.new(@step.id).perform 23 CommunityTrackPlugin::ActivationJob.new(@step.id).perform
24 @step.reload 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 end 26 end
37 27
38 end 28 end
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -21,10 +21,10 @@ class StepTest &lt; ActiveSupport::TestCase @@ -21,10 +21,10 @@ class StepTest &lt; ActiveSupport::TestCase
21 assert CommunityTrackPlugin::Step.short_description 21 assert CommunityTrackPlugin::Step.short_description
22 end 22 end
23 23
24 - should 'set published to false on create' do 24 + should 'set accept_comments to false on create' do
25 today = Date.today 25 today = Date.today
26 step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) 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 end 28 end
29 29
30 should 'do not allow step creation with a parent that is not a track' do 30 should 'do not allow step creation with a parent that is not a track' do
@@ -97,6 +97,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -97,6 +97,7 @@ class StepTest &lt; ActiveSupport::TestCase
97 should 'create delayed job' do 97 should 'create delayed job' do
98 @step.start_date = Date.today 98 @step.start_date = Date.today
99 @step.end_date = Date.today 99 @step.end_date = Date.today
  100 + @step.accept_comments = false
100 @step.schedule_activation 101 @step.schedule_activation
101 assert_equal 1, Delayed::Job.count 102 assert_equal 1, Delayed::Job.count
102 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 103 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
@@ -106,6 +107,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -106,6 +107,7 @@ class StepTest &lt; ActiveSupport::TestCase
106 @step.start_date = Date.today 107 @step.start_date = Date.today
107 @step.end_date = Date.today 108 @step.end_date = Date.today
108 @step.schedule_activation 109 @step.schedule_activation
  110 + assert_equal 1, Delayed::Job.count
109 @step.schedule_activation 111 @step.schedule_activation
110 assert_equal 1, Delayed::Job.count 112 assert_equal 1, Delayed::Job.count
111 end 113 end
@@ -120,30 +122,21 @@ class StepTest &lt; ActiveSupport::TestCase @@ -120,30 +122,21 @@ class StepTest &lt; ActiveSupport::TestCase
120 should 'create delayed job even if start date has passed' do 122 should 'create delayed job even if start date has passed' do
121 @step.start_date = Date.today - 2.days 123 @step.start_date = Date.today - 2.days
122 @step.end_date = Date.today 124 @step.end_date = Date.today
  125 + @step.accept_comments = false
123 @step.schedule_activation 126 @step.schedule_activation
124 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 127 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
125 end 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 @step.start_date = Date.today - 5.days 131 @step.start_date = Date.today - 5.days
129 @step.end_date = Date.today - 2.days 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 @step.schedule_activation 133 @step.schedule_activation
140 assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date 134 assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date
141 end 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 @step.start_date = Date.today 138 @step.start_date = Date.today
145 @step.end_date = Date.today 139 @step.end_date = Date.today
146 - @step.published = false  
147 @step.save! 140 @step.save!
148 assert_equal 1, Delayed::Job.count 141 assert_equal 1, Delayed::Job.count
149 Delayed::Job.destroy_all 142 Delayed::Job.destroy_all
@@ -161,38 +154,38 @@ class StepTest &lt; ActiveSupport::TestCase @@ -161,38 +154,38 @@ class StepTest &lt; ActiveSupport::TestCase
161 assert_equal 2, step2.position 154 assert_equal 2, step2.position
162 end 155 end
163 156
164 - should 'publish step if it is active' do 157 + should 'accept comments if step is active' do
165 @step.start_date = Date.today 158 @step.start_date = Date.today
166 @step.save! 159 @step.save!
167 - assert !@step.published  
168 - @step.publish 160 + assert !@step.accept_comments
  161 + @step.toggle_activation
169 @step.reload 162 @step.reload
170 - assert @step.published 163 + assert @step.accept_comments
171 end 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 @step.start_date = Date.today + 2.days 167 @step.start_date = Date.today + 2.days
175 @step.end_date = Date.today + 3.days 168 @step.end_date = Date.today + 3.days
176 @step.save! 169 @step.save!
177 assert !@step.published 170 assert !@step.published
178 - @step.publish 171 + @step.toggle_activation
179 @step.reload 172 @step.reload
180 assert !@step.published 173 assert !@step.published
181 end 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 @step.start_date = Date.today 177 @step.start_date = Date.today
185 @step.save! 178 @step.save!
186 - @step.publish 179 + @step.toggle_activation
187 @step.reload 180 @step.reload
188 - assert @step.published 181 + assert @step.accept_comments
189 182
190 @step.start_date = Date.today - 2.days 183 @step.start_date = Date.today - 2.days
191 @step.end_date = Date.today - 1.day 184 @step.end_date = Date.today - 1.day
192 @step.save! 185 @step.save!
193 - @step.publish 186 + @step.toggle_activation
194 @step.reload 187 @step.reload
195 - assert !@step.published 188 + assert !@step.accept_comments
196 end 189 end
197 190
198 should 'set position to zero if step is hidden' do 191 should 'set position to zero if step is hidden' do
@@ -236,7 +229,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -236,7 +229,7 @@ class StepTest &lt; ActiveSupport::TestCase
236 @step.hidden = true 229 @step.hidden = true
237 @step.save! 230 @step.save!
238 assert !@step.published 231 assert !@step.published
239 - @step.publish 232 + @step.toggle_activation
240 @step.reload 233 @step.reload
241 assert !@step.published 234 assert !@step.published
242 end 235 end
@@ -272,4 +265,24 @@ class StepTest &lt; ActiveSupport::TestCase @@ -272,4 +265,24 @@ class StepTest &lt; ActiveSupport::TestCase
272 assert step.end_date 265 assert step.end_date
273 end 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 end 288 end