Commit 9c951c50f1ecea130a344c96fe52383b6579dcf5

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent ea3ea3a8

Fix how the duration of events are calculated

(cherry picked from commit 7f19dfe82f9ec7ce00daa20fc2c728a351f8c629)
Showing 2 changed files with 11 additions and 1 deletions   Show diff stats
app/models/event.rb
... ... @@ -114,7 +114,7 @@ class Event < Article
114 114 end
115 115  
116 116 def duration
117   - (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24)
  117 + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) + 1
118 118 end
119 119  
120 120 alias_method :article_lead, :lead
... ...
test/unit/event_test.rb
... ... @@ -323,4 +323,14 @@ class EventTest < ActiveSupport::TestCase
323 323 assert a.can_display_media_panel?
324 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 336 end
... ...