Commit e7f5b1b3f2f760a7c9c933bf2a0f0711d814d5c9
1 parent
648f0e6b
Exists in
master
and in
6 other branches
adapting community track plugin for datetime values
Showing
3 changed files
with
51 additions
and
52 deletions
Show diff stats
plugins/community_track/lib/community_track_plugin/step.rb
... | ... | @@ -29,8 +29,8 @@ class CommunityTrackPlugin::Step < Folder |
29 | 29 | |
30 | 30 | def initialize(*args) |
31 | 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 | 34 | end |
35 | 35 | |
36 | 36 | def set_hidden_position |
... | ... | @@ -72,20 +72,20 @@ class CommunityTrackPlugin::Step < Folder |
72 | 72 | end |
73 | 73 | |
74 | 74 | def active? |
75 | - (start_date..end_date).include?(Date.today) | |
75 | + (start_date..end_date).cover?(DateTime.now) | |
76 | 76 | end |
77 | 77 | |
78 | 78 | def finished? |
79 | - Date.today > end_date | |
79 | + DateTime.now > end_date | |
80 | 80 | end |
81 | 81 | |
82 | 82 | def waiting? |
83 | - Date.today < start_date | |
83 | + DateTime.now < start_date | |
84 | 84 | end |
85 | 85 | |
86 | 86 | def schedule_activation |
87 | 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 | 89 | schedule_date = !accept_comments ? start_date : end_date + 1.day |
90 | 90 | CommunityTrackPlugin::ActivationJob.find(id).destroy_all |
91 | 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 < ActionController::TestCase |
6 | 6 | def setup |
7 | 7 | @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community') |
8 | 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 | 11 | user = create_user('testinguser') |
12 | 12 | login_as(user.login) | ... | ... |
plugins/community_track/test/unit/community_track_plugin/step_test.rb
... | ... | @@ -9,7 +9,7 @@ class StepTest < ActiveSupport::TestCase |
9 | 9 | @track.add_category(@category) |
10 | 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 | 13 | Delayed::Job.destroy_all |
14 | 14 | end |
15 | 15 | |
... | ... | @@ -22,39 +22,39 @@ class StepTest < ActiveSupport::TestCase |
22 | 22 | end |
23 | 23 | |
24 | 24 | should 'set accept_comments to false on create' do |
25 | - today = Date.today | |
25 | + today = DateTime.now | |
26 | 26 | step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) |
27 | 27 | refute 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 |
31 | - today = Date.today | |
31 | + today = DateTime.now | |
32 | 32 | blog = fast_create(Blog) |
33 | 33 | step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) |
34 | 34 | refute step.save |
35 | 35 | end |
36 | 36 | |
37 | 37 | should 'do not allow step creation without a parent' do |
38 | - today = Date.today | |
38 | + today = DateTime.now | |
39 | 39 | step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true) |
40 | 40 | refute step.save |
41 | 41 | end |
42 | 42 | |
43 | 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 | 46 | assert @step.save |
47 | 47 | end |
48 | 48 | |
49 | 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 | 52 | assert @step.save |
53 | 53 | end |
54 | 54 | |
55 | 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 | 58 | refute @step.save |
59 | 59 | end |
60 | 60 | |
... | ... | @@ -71,20 +71,20 @@ class StepTest < ActiveSupport::TestCase |
71 | 71 | end |
72 | 72 | |
73 | 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 | 76 | assert @step.active? |
77 | 77 | end |
78 | 78 | |
79 | 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 | 82 | assert @step.finished? |
83 | 83 | end |
84 | 84 | |
85 | 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 | 88 | assert @step.waiting? |
89 | 89 | end |
90 | 90 | |
... | ... | @@ -95,17 +95,17 @@ class StepTest < ActiveSupport::TestCase |
95 | 95 | end |
96 | 96 | |
97 | 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 | 100 | @step.accept_comments = false |
101 | 101 | @step.schedule_activation |
102 | 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 | 104 | end |
105 | 105 | |
106 | 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 | 109 | @step.schedule_activation |
110 | 110 | assert_equal 1, Delayed::Job.count |
111 | 111 | @step.schedule_activation |
... | ... | @@ -113,30 +113,30 @@ class StepTest < ActiveSupport::TestCase |
113 | 113 | end |
114 | 114 | |
115 | 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 | 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 | 120 | end |
121 | 121 | |
122 | 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 | 125 | @step.accept_comments = false |
126 | 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 | 128 | end |
129 | 129 | |
130 | 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 | 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 | 135 | end |
136 | 136 | |
137 | 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 | 140 | @step.save! |
141 | 141 | assert_equal 1, Delayed::Job.count |
142 | 142 | Delayed::Job.destroy_all |
... | ... | @@ -149,13 +149,13 @@ class StepTest < ActiveSupport::TestCase |
149 | 149 | refute @step.position |
150 | 150 | @step.save! |
151 | 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 | 153 | step2.save! |
154 | 154 | assert_equal 2, step2.position |
155 | 155 | end |
156 | 156 | |
157 | 157 | should 'accept comments if step is active' do |
158 | - @step.start_date = Date.today | |
158 | + @step.start_date = DateTime.now | |
159 | 159 | @step.save! |
160 | 160 | refute @step.accept_comments |
161 | 161 | @step.toggle_activation |
... | ... | @@ -164,8 +164,8 @@ class StepTest < ActiveSupport::TestCase |
164 | 164 | end |
165 | 165 | |
166 | 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 | 169 | @step.save! |
170 | 170 | refute @step.published |
171 | 171 | @step.toggle_activation |
... | ... | @@ -174,14 +174,14 @@ class StepTest < ActiveSupport::TestCase |
174 | 174 | end |
175 | 175 | |
176 | 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 | 178 | @step.save! |
179 | 179 | @step.toggle_activation |
180 | 180 | @step.reload |
181 | 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 | 185 | @step.save! |
186 | 186 | @step.toggle_activation |
187 | 187 | @step.reload |
... | ... | @@ -203,7 +203,7 @@ class StepTest < ActiveSupport::TestCase |
203 | 203 | end |
204 | 204 | |
205 | 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 | 207 | step1.save! |
208 | 208 | @step.hidden = true |
209 | 209 | @step.save! |
... | ... | @@ -215,7 +215,7 @@ class StepTest < ActiveSupport::TestCase |
215 | 215 | |
216 | 216 | should 'decrement lower items positions if a step becomes hidden' do |
217 | 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 | 219 | step1.save! |
220 | 220 | assert_equal 2, step1.position |
221 | 221 | @step.hidden = true |
... | ... | @@ -225,7 +225,7 @@ class StepTest < ActiveSupport::TestCase |
225 | 225 | end |
226 | 226 | |
227 | 227 | should 'do not publish a hidden step' do |
228 | - @step.start_date = Date.today | |
228 | + @step.start_date = DateTime.now | |
229 | 229 | @step.hidden = true |
230 | 230 | @step.save! |
231 | 231 | refute @step.published |
... | ... | @@ -266,7 +266,7 @@ class StepTest < ActiveSupport::TestCase |
266 | 266 | end |
267 | 267 | |
268 | 268 | should 'enable comments on children when step is activated' do |
269 | - @step.start_date = Date.today | |
269 | + @step.start_date = DateTime.now | |
270 | 270 | @step.save! |
271 | 271 | refute @step.accept_comments |
272 | 272 | article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false) |
... | ... | @@ -276,8 +276,7 @@ class StepTest < ActiveSupport::TestCase |
276 | 276 | end |
277 | 277 | |
278 | 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 | 280 | @step.save! |
282 | 281 | refute @step.accept_comments |
283 | 282 | @step.toggle_activation | ... | ... |