Commit e7f5b1b3f2f760a7c9c933bf2a0f0711d814d5c9

Authored by Leandro Santos
1 parent 648f0e6b

adapting community track plugin for datetime values

plugins/community_track/lib/community_track_plugin/step.rb
@@ -29,8 +29,8 @@ class CommunityTrackPlugin::Step < Folder @@ -29,8 +29,8 @@ class CommunityTrackPlugin::Step < Folder
29 29
30 def initialize(*args) 30 def initialize(*args)
31 super(*args) 31 super(*args)
32 - self.start_date ||= Date.today  
33 - self.end_date ||= Date.today + 1.day 32 + self.start_date ||= DateTime.now
  33 + self.end_date ||= DateTime.now + 1.day
34 end 34 end
35 35
36 def set_hidden_position 36 def set_hidden_position
@@ -72,20 +72,20 @@ class CommunityTrackPlugin::Step < Folder @@ -72,20 +72,20 @@ class CommunityTrackPlugin::Step < Folder
72 end 72 end
73 73
74 def active? 74 def active?
75 - (start_date..end_date).include?(Date.today) 75 + (start_date..end_date).cover?(DateTime.now)
76 end 76 end
77 77
78 def finished? 78 def finished?
79 - Date.today > end_date 79 + DateTime.now > end_date
80 end 80 end
81 81
82 def waiting? 82 def waiting?
83 - Date.today < start_date 83 + DateTime.now < start_date
84 end 84 end
85 85
86 def schedule_activation 86 def schedule_activation
87 return if !changes['start_date'] && !changes['end_date'] 87 return if !changes['start_date'] && !changes['end_date']
88 - if Date.today <= end_date || accept_comments 88 + if DateTime.now <= end_date || accept_comments
89 schedule_date = !accept_comments ? start_date : end_date + 1.day 89 schedule_date = !accept_comments ? start_date : end_date + 1.day
90 CommunityTrackPlugin::ActivationJob.find(id).destroy_all 90 CommunityTrackPlugin::ActivationJob.find(id).destroy_all
91 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), :run_at => schedule_date) 91 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), :run_at => schedule_date)
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
@@ -6,7 +6,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -6,7 +6,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
6 def setup 6 def setup
7 @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community') 7 @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community')
8 @track = create_track('track', @profile) 8 @track = create_track('track', @profile)
9 - @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name) 9 + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => DateTime.now.end_of_day, :start_date => DateTime.now.beginning_of_day, :tool_type => TinyMceArticle.name)
10 10
11 user = create_user('testinguser') 11 user = create_user('testinguser')
12 login_as(user.login) 12 login_as(user.login)
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -9,7 +9,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -9,7 +9,7 @@ class StepTest &lt; ActiveSupport::TestCase
9 @track.add_category(@category) 9 @track.add_category(@category)
10 @track.save! 10 @track.save!
11 11
12 - @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 12 + @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => DateTime.now.end_of_day, :start_date => DateTime.now.beginning_of_day - 1.day)
13 Delayed::Job.destroy_all 13 Delayed::Job.destroy_all
14 end 14 end
15 15
@@ -22,39 +22,39 @@ class StepTest &lt; ActiveSupport::TestCase @@ -22,39 +22,39 @@ class StepTest &lt; ActiveSupport::TestCase
22 end 22 end
23 23
24 should 'set accept_comments to false on create' do 24 should 'set accept_comments to false on create' do
25 - today = Date.today 25 + today = DateTime.now
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 refute step.accept_comments 27 refute 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
31 - today = Date.today 31 + today = DateTime.now
32 blog = fast_create(Blog) 32 blog = fast_create(Blog)
33 step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) 33 step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true)
34 refute step.save 34 refute step.save
35 end 35 end
36 36
37 should 'do not allow step creation without a parent' do 37 should 'do not allow step creation without a parent' do
38 - today = Date.today 38 + today = DateTime.now
39 step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true) 39 step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true)
40 refute step.save 40 refute step.save
41 end 41 end
42 42
43 should 'create step if end date is equal to start date' do 43 should 'create step if end date is equal to start date' do
44 - @step.start_date = Date.today  
45 - @step.end_date = Date.today 44 + @step.start_date = DateTime.now
  45 + @step.end_date = DateTime.now
46 assert @step.save 46 assert @step.save
47 end 47 end
48 48
49 should 'create step if end date is after start date' do 49 should 'create step if end date is after start date' do
50 - @step.start_date = Date.today  
51 - @step.end_date = Date.today + 1.day 50 + @step.start_date = DateTime.now
  51 + @step.end_date = DateTime.now + 1.day
52 assert @step.save 52 assert @step.save
53 end 53 end
54 54
55 should 'do not create step if end date is before start date' do 55 should 'do not create step if end date is before start date' do
56 - @step.start_date = Date.today  
57 - @step.end_date = Date.today - 1.day 56 + @step.start_date = DateTime.now
  57 + @step.end_date = DateTime.now - 1.day
58 refute @step.save 58 refute @step.save
59 end 59 end
60 60
@@ -71,20 +71,20 @@ class StepTest &lt; ActiveSupport::TestCase @@ -71,20 +71,20 @@ class StepTest &lt; ActiveSupport::TestCase
71 end 71 end
72 72
73 should 'be active if today is between start and end dates' do 73 should 'be active if today is between start and end dates' do
74 - @step.start_date = Date.today  
75 - @step.end_date = Date.today + 1.day 74 + @step.start_date = DateTime.now
  75 + @step.end_date = DateTime.now + 1.day
76 assert @step.active? 76 assert @step.active?
77 end 77 end
78 78
79 should 'be finished if today is after the end date' do 79 should 'be finished if today is after the end date' do
80 - @step.start_date = Date.today - 2.day  
81 - @step.end_date = Date.today - 1.day 80 + @step.start_date = DateTime.now - 2.day
  81 + @step.end_date = DateTime.now - 1.day
82 assert @step.finished? 82 assert @step.finished?
83 end 83 end
84 84
85 should 'be waiting if today is before the end date' do 85 should 'be waiting if today is before the end date' do
86 - @step.start_date = Date.today + 1.day  
87 - @step.end_date = Date.today + 2.day 86 + @step.start_date = DateTime.now + 1.day
  87 + @step.end_date = DateTime.now + 2.day
88 assert @step.waiting? 88 assert @step.waiting?
89 end 89 end
90 90
@@ -95,17 +95,17 @@ class StepTest &lt; ActiveSupport::TestCase @@ -95,17 +95,17 @@ class StepTest &lt; ActiveSupport::TestCase
95 end 95 end
96 96
97 should 'create delayed job' do 97 should 'create delayed job' do
98 - @step.start_date = Date.today  
99 - @step.end_date = Date.today 98 + @step.start_date = DateTime.now.beginning_of_day
  99 + @step.end_date = DateTime.now.end_of_day
100 @step.accept_comments = false 100 @step.accept_comments = false
101 @step.schedule_activation 101 @step.schedule_activation
102 assert_equal 1, Delayed::Job.count 102 assert_equal 1, Delayed::Job.count
103 - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 103 + assert_equal @step.start_date, Delayed::Job.first.run_at
104 end 104 end
105 105
106 should 'do not duplicate delayed job' do 106 should 'do not duplicate delayed job' do
107 - @step.start_date = Date.today  
108 - @step.end_date = Date.today 107 + @step.start_date = DateTime.now
  108 + @step.end_date = DateTime.now
109 @step.schedule_activation 109 @step.schedule_activation
110 assert_equal 1, Delayed::Job.count 110 assert_equal 1, Delayed::Job.count
111 @step.schedule_activation 111 @step.schedule_activation
@@ -113,30 +113,30 @@ class StepTest &lt; ActiveSupport::TestCase @@ -113,30 +113,30 @@ class StepTest &lt; ActiveSupport::TestCase
113 end 113 end
114 114
115 should 'create delayed job when a step is saved' do 115 should 'create delayed job when a step is saved' do
116 - @step.start_date = Date.today  
117 - @step.end_date = Date.today 116 + @step.start_date = DateTime.now.beginning_of_day
  117 + @step.end_date = DateTime.now.end_of_day
118 @step.save! 118 @step.save!
119 - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 119 + assert_equal @step.start_date, Delayed::Job.first.run_at
120 end 120 end
121 121
122 should 'create delayed job even if start date has passed' do 122 should 'create delayed job even if start date has passed' do
123 - @step.start_date = Date.today - 2.days  
124 - @step.end_date = Date.today 123 + @step.start_date = DateTime.now - 2.days
  124 + @step.end_date = DateTime.now.end_of_day
125 @step.accept_comments = false 125 @step.accept_comments = false
126 @step.schedule_activation 126 @step.schedule_activation
127 - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 127 + assert_equal @step.start_date, Delayed::Job.first.run_at
128 end 128 end
129 129
130 should 'create delayed job if end date has passed' do 130 should 'create delayed job if end date has passed' do
131 - @step.start_date = Date.today - 5.days  
132 - @step.end_date = Date.today - 2.days 131 + @step.start_date = DateTime.now - 5.days
  132 + @step.end_date = DateTime.now - 2.days
133 @step.schedule_activation 133 @step.schedule_activation
134 - 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
135 end 135 end
136 136
137 should 'do not schedule delayed job if save but do not modify date fields' do 137 should 'do not schedule delayed job if save but do not modify date fields' do
138 - @step.start_date = Date.today  
139 - @step.end_date = Date.today 138 + @step.start_date = DateTime.now
  139 + @step.end_date = DateTime.now.end_of_day
140 @step.save! 140 @step.save!
141 assert_equal 1, Delayed::Job.count 141 assert_equal 1, Delayed::Job.count
142 Delayed::Job.destroy_all 142 Delayed::Job.destroy_all
@@ -149,13 +149,13 @@ class StepTest &lt; ActiveSupport::TestCase @@ -149,13 +149,13 @@ class StepTest &lt; ActiveSupport::TestCase
149 refute @step.position 149 refute @step.position
150 @step.save! 150 @step.save!
151 assert_equal 1, @step.position 151 assert_equal 1, @step.position
152 - step2 = CommunityTrackPlugin::Step.new(:name => 'Step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 152 + step2 = CommunityTrackPlugin::Step.new(:name => 'Step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => DateTime.now.end_of_day, :start_date => DateTime.now.beginning_of_day)
153 step2.save! 153 step2.save!
154 assert_equal 2, step2.position 154 assert_equal 2, step2.position
155 end 155 end
156 156
157 should 'accept comments if step is active' do 157 should 'accept comments if step is active' do
158 - @step.start_date = Date.today 158 + @step.start_date = DateTime.now
159 @step.save! 159 @step.save!
160 refute @step.accept_comments 160 refute @step.accept_comments
161 @step.toggle_activation 161 @step.toggle_activation
@@ -164,8 +164,8 @@ class StepTest &lt; ActiveSupport::TestCase @@ -164,8 +164,8 @@ class StepTest &lt; ActiveSupport::TestCase
164 end 164 end
165 165
166 should 'do not accept comments if step is not active' do 166 should 'do not accept comments if step is not active' do
167 - @step.start_date = Date.today + 2.days  
168 - @step.end_date = Date.today + 3.days 167 + @step.start_date = DateTime.now + 2.days
  168 + @step.end_date = DateTime.now + 3.days
169 @step.save! 169 @step.save!
170 refute @step.published 170 refute @step.published
171 @step.toggle_activation 171 @step.toggle_activation
@@ -174,14 +174,14 @@ class StepTest &lt; ActiveSupport::TestCase @@ -174,14 +174,14 @@ class StepTest &lt; ActiveSupport::TestCase
174 end 174 end
175 175
176 should 'do not accept comments if step is not active anymore' do 176 should 'do not accept comments if step is not active anymore' do
177 - @step.start_date = Date.today 177 + @step.end_date = DateTime.now.end_of_day
178 @step.save! 178 @step.save!
179 @step.toggle_activation 179 @step.toggle_activation
180 @step.reload 180 @step.reload
181 assert @step.accept_comments 181 assert @step.accept_comments
182 182
183 - @step.start_date = Date.today - 2.days  
184 - @step.end_date = Date.today - 1.day 183 + @step.start_date = DateTime.now - 2.days
  184 + @step.end_date = DateTime.now - 1.day
185 @step.save! 185 @step.save!
186 @step.toggle_activation 186 @step.toggle_activation
187 @step.reload 187 @step.reload
@@ -203,7 +203,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -203,7 +203,7 @@ class StepTest &lt; ActiveSupport::TestCase
203 end 203 end
204 204
205 should 'change position to botton if a hidden step becomes visible' do 205 should 'change position to botton if a hidden step becomes visible' do
206 - step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 206 + step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => DateTime.now.end_of_day, :start_date => DateTime.now.beginning_of_day)
207 step1.save! 207 step1.save!
208 @step.hidden = true 208 @step.hidden = true
209 @step.save! 209 @step.save!
@@ -215,7 +215,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -215,7 +215,7 @@ class StepTest &lt; ActiveSupport::TestCase
215 215
216 should 'decrement lower items positions if a step becomes hidden' do 216 should 'decrement lower items positions if a step becomes hidden' do
217 @step.save! 217 @step.save!
218 - step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 218 + step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => DateTime.now.end_of_day, :start_date => DateTime.now.beginning_of_day)
219 step1.save! 219 step1.save!
220 assert_equal 2, step1.position 220 assert_equal 2, step1.position
221 @step.hidden = true 221 @step.hidden = true
@@ -225,7 +225,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -225,7 +225,7 @@ class StepTest &lt; ActiveSupport::TestCase
225 end 225 end
226 226
227 should 'do not publish a hidden step' do 227 should 'do not publish a hidden step' do
228 - @step.start_date = Date.today 228 + @step.start_date = DateTime.now
229 @step.hidden = true 229 @step.hidden = true
230 @step.save! 230 @step.save!
231 refute @step.published 231 refute @step.published
@@ -266,7 +266,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -266,7 +266,7 @@ class StepTest &lt; ActiveSupport::TestCase
266 end 266 end
267 267
268 should 'enable comments on children when step is activated' do 268 should 'enable comments on children when step is activated' do
269 - @step.start_date = Date.today 269 + @step.start_date = DateTime.now
270 @step.save! 270 @step.save!
271 refute @step.accept_comments 271 refute @step.accept_comments
272 article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false) 272 article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false)
@@ -276,8 +276,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -276,8 +276,7 @@ class StepTest &lt; ActiveSupport::TestCase
276 end 276 end
277 277
278 should 'enable comments on children when step is active' do 278 should 'enable comments on children when step is active' do
279 - @step.start_date = Date.today  
280 - @step.start_date = Date.today 279 + @step.start_date = DateTime.now
281 @step.save! 280 @step.save!
282 refute @step.accept_comments 281 refute @step.accept_comments
283 @step.toggle_activation 282 @step.toggle_activation