Commit 73a643cec597b52c0f0e2f70fb48e57f7fecbb7d

Authored by Antonio Terceiro
2 parents 0bd3c635 7f19dfe8

Merge branch 'event_duration' into 'master'

Fix how the duration of events are calculated



See merge request !733
Showing 2 changed files with 11 additions and 1 deletions   Show diff stats
app/models/event.rb
... ... @@ -110,7 +110,7 @@ class Event < Article
110 110 end
111 111  
112 112 def duration
113   - (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24)
  113 + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) + 1
114 114 end
115 115  
116 116 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
... ...