[Git][noosfero/noosfero][master] 2 commits: Fix how the duration of events are calculated

Antonio Terceiro gitlab at mg.gitlab.com
Fri Nov 20 14:37:10 BRST 2015


Antonio Terceiro pushed to branch master at Noosfero / noosfero


Commits:
7f19dfe8 by Daniela Feitosa at 2015-11-20T13:10:25Z
Fix how the duration of events are calculated

- - - - -
73a643ce by Antonio Terceiro at 2015-11-20T16:36:55Z
Merge branch 'event_duration' into 'master'

Fix how the duration of events are calculated



See merge request !733
- - - - -


2 changed files:

- app/models/event.rb
- test/unit/event_test.rb


Changes:

=====================================
app/models/event.rb
=====================================
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -110,7 +110,7 @@ class Event < Article
   end
 
   def duration
-    (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24)
+    (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) + 1
   end
 
   alias_method :article_lead, :lead


=====================================
test/unit/event_test.rb
=====================================
--- a/test/unit/event_test.rb
+++ b/test/unit/event_test.rb
@@ -323,4 +323,14 @@ class EventTest < ActiveSupport::TestCase
     assert a.can_display_media_panel?
   end
 
+  should 'calculate duration of events with start and end date' do
+    e = build(Event, :start_date => DateTime.new(2015, 1, 1), :end_date => DateTime.new(2015, 1, 5))
+    assert_equal 5, e.duration
+  end
+
+  should 'calculate duration of event with only start_date' do
+    e = build(Event, :start_date => DateTime.new(2015, 1, 1))
+    assert_equal 1, e.duration
+  end
+
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/0bd3c63526f1799eb58b25ace288938aff47fdb1...73a643cec597b52c0f0e2f70fb48e57f7fecbb7d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151120/d0e5ce3c/attachment.html>


More information about the Noosfero-dev mailing list