Commit c208417afc2774b7a6f9f8bc8bb69a7357fdd163
Committed by
Victor Costa
1 parent
741e19ae
Exists in
theme-brasil-digital-from-staging
and in
4 other branches
Fix how the duration of events are calculated
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
app/models/event.rb
@@ -111,7 +111,7 @@ class Event < Article | @@ -111,7 +111,7 @@ class Event < Article | ||
111 | end | 111 | end |
112 | 112 | ||
113 | def duration | 113 | def duration |
114 | - (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) | 114 | + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) + 1 |
115 | end | 115 | end |
116 | 116 | ||
117 | alias_method :article_lead, :lead | 117 | alias_method :article_lead, :lead |
test/unit/event_test.rb
@@ -323,4 +323,14 @@ class EventTest < ActiveSupport::TestCase | @@ -323,4 +323,14 @@ class EventTest < ActiveSupport::TestCase | ||
323 | assert a.can_display_media_panel? | 323 | assert a.can_display_media_panel? |
324 | end | 324 | end |
325 | 325 | ||
326 | + should 'calculate duration of events with start and end date' do | ||
327 | + e = build(Event, :start_date => DateTime.new(2015, 1, 1), :end_date => DateTime.new(2015, 1, 5)) | ||
328 | + assert_equal 5, e.duration | ||
329 | + end | ||
330 | + | ||
331 | + should 'calculate duration of event with only start_date' do | ||
332 | + e = build(Event, :start_date => DateTime.new(2015, 1, 1)) | ||
333 | + assert_equal 1, e.duration | ||
334 | + end | ||
335 | + | ||
326 | end | 336 | end |