Commit fdf745228a50447a5fd3e22d1f76b5b131c94873

Authored by Leandro Santos
2 parents 180ad529 e7f5b1b3

Merge branch 'article_datetime' into 'master'

Put start and end dates as datetime for articles

change the start_date and end_date from date to datetime

See merge request !634
app/controllers/public/search_controller.rb
... ... @@ -92,10 +92,10 @@ class SearchController < PublicController
92 92  
93 93 def events
94 94 if params[:year].blank? && params[:year].blank? && params[:day].blank?
95   - @date = Date.today
  95 + @date = DateTime.now
96 96 else
97   - year = (params[:year] ? params[:year].to_i : Date.today.year)
98   - month = (params[:month] ? params[:month].to_i : Date.today.month)
  97 + year = (params[:year] ? params[:year].to_i : DateTime.now.year)
  98 + month = (params[:month] ? params[:month].to_i : DateTime.now.month)
99 99 day = (params[:day] ? params[:day].to_i : 1)
100 100 @date = build_date(year, month, day)
101 101 end
... ... @@ -106,9 +106,7 @@ class SearchController < PublicController
106 106 @events = @category ?
107 107 environment.events.by_day(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) :
108 108 environment.events.by_day(@date).paginate(:per_page => per_page, :page => params[:page])
109   - end
110   -
111   - if params[:year] || params[:month]
  109 + elsif params[:year] || params[:month]
112 110 @events = @category ?
113 111 environment.events.by_month(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) :
114 112 environment.events.by_month(@date).paginate(:per_page => per_page, :page => params[:page])
... ...
app/helpers/content_viewer_helper.rb
... ... @@ -51,7 +51,7 @@ module ContentViewerHelper
51 51 elsif date_format == 'past_time'
52 52 left_time = true
53 53 end
54   - content_tag('span', show_date(article.published_at, use_numbers , year, left_time), :class => 'date')
  54 + content_tag('span', show_time(article.published_at, use_numbers , year, left_time), :class => 'date')
55 55 end
56 56  
57 57 def link_to_comments(article, args = {})
... ...
app/helpers/dates_helper.rb
... ... @@ -43,9 +43,14 @@ module DatesHelper
43 43 end
44 44  
45 45 # formats a datetime for displaying.
46   - def show_time(time)
47   - if time
48   - _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
  46 + def show_time(time, use_numbers = false, year = true, left_time = false)
  47 + if time && use_numbers
  48 + _('%{month}/%{day}/%{year}, %{hour}:%{minutes}') % { :year => (year ? time.year : ''), :month => time.month, :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
  49 + elsif time && left_time
  50 + date_format = time_ago_in_words(time)
  51 + elsif time
  52 + date_format = year ? _('%{month_name} %{day}, %{year} %{hour}:%{minutes}') : _('%{month_name} %{day} %{hour}:%{minutes}')
  53 + date_format % { :day => time.day, :month_name => month_name(time.month), :year => time.year, :hour => time.hour, :minutes => time.strftime("%M") }
49 54 else
50 55 ''
51 56 end
... ... @@ -53,7 +58,7 @@ module DatesHelper
53 58  
54 59 def show_period(date1, date2 = nil, use_numbers = false)
55 60 if (date1 == date2) || (date2.nil?)
56   - show_date(date1, use_numbers)
  61 + show_time(date1, use_numbers)
57 62 else
58 63 if date1.year == date2.year
59 64 if date1.month == date2.month
... ... @@ -72,8 +77,8 @@ module DatesHelper
72 77 end
73 78 else
74 79 _('from %{date1} to %{date2}') % {
75   - :date1 => show_date(date1, use_numbers),
76   - :date2 => show_date(date2, use_numbers)
  80 + :date1 => show_time(date1, use_numbers),
  81 + :date2 => show_time(date2, use_numbers)
77 82 }
78 83 end
79 84 end
... ... @@ -106,18 +111,18 @@ module DatesHelper
106 111  
107 112 def build_date(year, month, day = 1)
108 113 if year.blank? and month.blank? and day.blank?
109   - Date.today
  114 + DateTime.now
110 115 else
111 116 if year.blank?
112   - year = Date.today.year
  117 + year = DateTime.now.year
113 118 end
114 119 if month.blank?
115   - month = Date.today.month
  120 + month = DateTime.now.month
116 121 end
117 122 if day.blank?
118 123 day = 1
119 124 end
120   - Date.new(year.to_i, month.to_i, day.to_i)
  125 + DateTime.new(year.to_i, month.to_i, day.to_i)
121 126 end
122 127 end
123 128  
... ...
app/helpers/events_helper.rb
... ... @@ -16,7 +16,7 @@ module EventsHelper
16 16  
17 17 content_tag( 'tr',
18 18 content_tag('td',
19   - content_tag('div', show_date(article.start_date) + ( article.end_date.nil? ? '' : (_(" to ") + show_date(article.end_date))),:class => 'event-date' ) +
  19 + content_tag('div', show_time(article.start_date) + ( article.end_date.nil? ? '' : (_(" to ") + show_time(article.end_date))),:class => 'event-date' ) +
20 20 content_tag('div',link_to(article.name,article.url),:class => 'event-title') +
21 21 content_tag('div',(article.address.nil? or article.address == '') ? '' : (_('Place: ') + article.address),:class => 'event-place')
22 22 )
... ...
app/helpers/forms_helper.rb
... ... @@ -151,7 +151,7 @@ module FormsHelper
151 151 datepicker_options[:close_text] ||= _('Done')
152 152 datepicker_options[:constrain_input] ||= true
153 153 datepicker_options[:current_text] ||= _('Today')
154   - datepicker_options[:date_format] ||= 'mm/dd/yy'
  154 + datepicker_options[:date_format] ||= 'yy/mm/dd'
155 155 datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
156 156 datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')]
157 157 datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')]
... ... @@ -236,7 +236,7 @@ module FormsHelper
236 236 weekHeader: #{datepicker_options[:week_header].to_json},
237 237 yearRange: #{datepicker_options[:year_range].to_json},
238 238 yearSuffix: #{datepicker_options[:year_suffix].to_json}
239   - })
  239 + }).datepicker('setDate', new Date('#{value}'))
240 240 </script>
241 241 ".html_safe
242 242 result
... ...
app/models/event.rb
... ... @@ -23,7 +23,7 @@ class Event &lt; Article
23 23  
24 24 def initialize(*args)
25 25 super(*args)
26   - self.start_date ||= Date.today
  26 + self.start_date ||= DateTime.now
27 27 end
28 28  
29 29 validates_presence_of :title, :start_date
... ... @@ -35,7 +35,7 @@ class Event &lt; Article
35 35 end
36 36  
37 37 scope :by_day, lambda { |date|
38   - { :conditions => ['start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date}],
  38 + { :conditions => [' start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)', {:start_date => date.beginning_of_day, :end_date => date.end_of_day}],
39 39 :order => 'start_date ASC'
40 40 }
41 41 }
... ... @@ -80,7 +80,7 @@ class Event &lt; Article
80 80  
81 81 def self.date_range(year, month)
82 82 if year.nil? || month.nil?
83   - today = Date.today
  83 + today = DateTime.now
84 84 year = today.year
85 85 month = today.month
86 86 else
... ... @@ -88,7 +88,7 @@ class Event &lt; Article
88 88 month = month.to_i
89 89 end
90 90  
91   - first_day = Date.new(year, month, 1)
  91 + first_day = DateTime.new(year, month, 1)
92 92 last_day = first_day + 1.month - 1.day
93 93  
94 94 first_day..last_day
... ... @@ -114,7 +114,7 @@ class Event &lt; Article
114 114 end
115 115  
116 116 def duration
117   - ((self.end_date || self.start_date) - self.start_date).to_i
  117 + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24)
118 118 end
119 119  
120 120 alias_method :article_lead, :lead
... ...
app/views/cms/_event.html.erb
... ... @@ -8,9 +8,8 @@
8 8 <%= render :partial => 'general_fields' %>
9 9 <%= render :partial => 'translatable' %>
10 10  
11   -<%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %>
  11 +<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, _('%Y-%m-%d %H:%M'), {:time => true}, {:id => 'article_start_date'} ) %>
12 12  
13   -<%= labelled_form_field(_('End date'), pick_date(:article, :end_date)) %>
14 13  
15 14 <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %>
16 15  
... ...
app/views/content_viewer/_publishing_info.html.erb
1 1 <span class="publishing-info">
2 2 <span class="date">
3   - <%= show_date(@page.published_at) %>
  3 + <%= show_time(@page.published_at) %>
4 4 </span>
5 5 <span class="author">
6 6 <%= _(", by %s") % (@page.author ? link_to(@page.author_name, @page.author_url) : @page.author_name) %>
... ...
db/migrate/20150722042714_change_article_date_to_datetime.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class ChangeArticleDateToDatetime < ActiveRecord::Migration
  2 +
  3 + def up
  4 + change_table :articles do |t|
  5 + t.change :start_date, :datetime
  6 + t.change :end_date, :datetime
  7 + end
  8 +
  9 + change_table :article_versions do |t|
  10 + t.change :start_date, :datetime
  11 + t.change :end_date, :datetime
  12 + end
  13 + end
  14 +
  15 + def down
  16 + change_table :articles do |t|
  17 + t.change :start_date, :date
  18 + t.change :end_date, :date
  19 + end
  20 +
  21 + change_table :article_versions do |t|
  22 + t.change :start_date, :date
  23 + t.change :end_date, :date
  24 + end
  25 + end
  26 +
  27 +end
... ...
plugins/community_track/lib/community_track_plugin/step.rb
... ... @@ -29,8 +29,8 @@ class CommunityTrackPlugin::Step &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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
... ...
plugins/event/lib/event_plugin/event_block.rb
... ... @@ -30,13 +30,13 @@ class EventPlugin::EventBlock &lt; Block
30 30 events = user.nil? ? events.public : events.display_filter(user,nil)
31 31  
32 32 if future_only
33   - events = events.where('start_date >= ?', Date.today)
  33 + events = events.where('start_date >= ?', DateTime.now.beginning_of_day)
34 34 end
35 35  
36 36 if date_distance_limit > 0
37 37 events = events.by_range([
38   - Date.today - date_distance_limit,
39   - Date.today + date_distance_limit
  38 + DateTime.now.beginning_of_day - date_distance_limit,
  39 + DateTime.now.beginning_of_day + date_distance_limit
40 40 ])
41 41 end
42 42  
... ...
plugins/event/test/functional/event_block_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2  
  3 +
3 4 # Re-raise errors caught by the controller.
4 5 class HomeController
5   - #append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  6 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
6 7 def rescue_action(e)
7 8 raise e
8 9 end
... ... @@ -15,7 +16,7 @@ class HomeControllerTest &lt; ActionController::TestCase
15 16 @env.enable_plugin('EventPlugin')
16 17  
17 18 @p1 = fast_create(Person, :environment_id => @env.id)
18   - @e1a = fast_create(Event, :name=>'Event p1 A', :profile_id=>@p1.id)
  19 + @e1a = Event.create!(:name=>'Event p1 A', :profile =>@p1)
19 20  
20 21 box = Box.create!(:owner => @env)
21 22 @block = EventPlugin::EventBlock.create!(:box => box)
... ... @@ -27,6 +28,7 @@ class HomeControllerTest &lt; ActionController::TestCase
27 28  
28 29 should 'see events microdata sturcture' do
29 30 get :index
  31 +#raise response.body.inspect
30 32 assert_select '.event-plugin_event-block ul.events'
31 33 assert_select ev
32 34 assert_select ev + 'a[itemprop="url"]'
... ... @@ -41,15 +43,15 @@ class HomeControllerTest &lt; ActionController::TestCase
41 43  
42 44 should 'see event duration' do
43 45 @e1a.slug = 'event1a'
44   - @e1a.start_date = Date.today
45   - @e1a.end_date = Date.today + 1.day
  46 + @e1a.start_date = DateTime.now
  47 + @e1a.end_date = DateTime.now + 1.day
46 48 @e1a.save!
47 49 get :index
48 50 assert_select ev + 'time.duration[itemprop="endDate"]', /1 day/
49 51  
50 52 @e1a.slug = 'event1a'
51   - @e1a.start_date = Date.today
52   - @e1a.end_date = Date.today + 2.day
  53 + @e1a.start_date = DateTime.now
  54 + @e1a.end_date = DateTime.now + 2.day
53 55 @e1a.save!
54 56 get :index
55 57 assert_select ev + 'time.duration[itemprop="endDate"]', /2 days/
... ... @@ -60,8 +62,8 @@ class HomeControllerTest &lt; ActionController::TestCase
60 62 assert_select ev + 'time.duration[itemprop="endDate"]', false
61 63  
62 64 @e1a.slug = 'event1a'
63   - @e1a.start_date = Date.today
64   - @e1a.end_date = Date.today
  65 + @e1a.start_date = DateTime.now
  66 + @e1a.end_date = DateTime.now
65 67 @e1a.save!
66 68 get :index
67 69 assert_select ev + 'time.duration[itemprop="endDate"]', false
... ...
plugins/event/views/blocks/event.html.erb
... ... @@ -2,7 +2,7 @@
2 2  
3 3 <ul class="events">
4 4 <% block.events(user).map do |event| %>
5   - <% days_left = ( event.start_date - Date.today ).round %>
  5 + <% days_left = ( (event.start_date - DateTime.now)/60/60/24 ).round %>
6 6 <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Event" class="event">
7 7 <%= render(
8 8 :file => 'event_plugin/event_block_item',
... ...
public/designs/themes/base/style.scss
... ... @@ -1505,7 +1505,8 @@ table#recaptcha_table tr:hover td {
1505 1505  
1506 1506 .event-date {
1507 1507 background: url('/images/calendar_date_select/calendar-icon.png') no-repeat left center;
1508   - padding: 5px;
  1508 + padding: 2px;
  1509 + padding-left: 15px;
1509 1510 }
1510 1511  
1511 1512 .event-link {
... ...
test/functional/events_controller_test.rb
... ... @@ -8,12 +8,12 @@ class EventsControllerTest &lt; ActionController::TestCase
8 8 attr_reader :profile
9 9  
10 10 should 'list today events by default' do
11   - profile.events << Event.new(:name => 'Joao Birthday', :start_date => Date.today)
12   - profile.events << Event.new(:name => 'Maria Birthday', :start_date => Date.today)
  11 + profile.events << Event.new(:name => 'Joao Birthday', :start_date => DateTime.now)
  12 + profile.events << Event.new(:name => 'Maria Birthday', :start_date => DateTime.now)
13 13  
14 14 get :events, :profile => profile.identifier
15 15  
16   - today = Date.today.strftime("%B %d, %Y")
  16 + today = DateTime.now.strftime("%B %d, %Y")
17 17 assert_tag :tag => 'div', :attributes => {:id => "agenda-items"},
18 18 :descendant => {:tag => 'h3', :content => "Events for #{today}"},
19 19 :descendant => {:tag => 'tr', :content => "Joao Birthday"},
... ... @@ -23,15 +23,15 @@ class EventsControllerTest &lt; ActionController::TestCase
23 23 should 'display calendar of current month' do
24 24 get :events, :profile => profile.identifier
25 25  
26   - month = Date.today.strftime("%B %Y")
  26 + month = DateTime.now.strftime("%B %Y")
27 27 assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /#{month}/}
28 28 end
29 29  
30 30 should 'display links to previous and next month' do
31 31 get :events, :profile => profile.identifier
32 32  
33   - prev_month = Date.today - 1.month
34   - next_month = Date.today + 1.month
  33 + prev_month = DateTime.now - 1.month
  34 + next_month = DateTime.now + 1.month
35 35 prev_month_name = prev_month.strftime("%B")
36 36 next_month_name = next_month.strftime("%B")
37 37 assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{prev_month.year}/#{prev_month.month}"}, :content => prev_month_name
... ... @@ -40,14 +40,14 @@ class EventsControllerTest &lt; ActionController::TestCase
40 40  
41 41 should 'see the events paginated' do
42 42 30.times do |i|
43   - profile.events << Event.new(:name => "Lesson #{i}", :start_date => Date.today)
  43 + profile.events << Event.new(:name => "Lesson #{i}", :start_date => DateTime.now)
44 44 end
45 45 get :events, :profile => profile.identifier
46 46 assert_equal 20, assigns(:events).size
47 47 end
48 48  
49 49 should 'show events of specific day' do
50   - profile.events << Event.new(:name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28))
  50 + profile.events << Event.new(:name => 'Joao Birthday', :start_date => DateTime.new(2009, 10, 28))
51 51  
52 52 get :events_by_day, :profile => profile.identifier, :year => 2009, :month => 10, :day => 28
53 53  
... ...
test/functional/search_controller_test.rb
... ... @@ -305,7 +305,7 @@ class SearchControllerTest &lt; ActionController::TestCase
305 305  
306 306 should 'search for events' do
307 307 person = create_user('teste').person
308   - event = create_event(person, :name => 'an event to be found', :start_date => Date.today)
  308 + event = create_event(person, :name => 'an event to be found', :start_date => DateTime.now)
309 309  
310 310 get :events, :query => 'event to be found'
311 311  
... ... @@ -314,10 +314,10 @@ class SearchControllerTest &lt; ActionController::TestCase
314 314  
315 315 should 'return events of the day' do
316 316 person = create_user('someone').person
317   - ten_days_ago = Date.today - 10.day
  317 + ten_days_ago = DateTime.now - 10.day
318 318  
319 319 ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago)
320   - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month)
  320 + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => DateTime.now - 2.month)
321 321  
322 322 get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year
323 323 assert_equal [ev1], assigns(:events)
... ... @@ -325,9 +325,11 @@ class SearchControllerTest &lt; ActionController::TestCase
325 325  
326 326 should 'return events of the day with category' do
327 327 person = create_user('someone').person
328   - ten_days_ago = Date.today - 10.day
  328 + ten_days_ago = DateTime.now - 10.day
329 329  
330   - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago)
  330 + ev1 = create_event(person, :name => 'event 1', :start_date => ten_days_ago)
  331 + ev1.categories = [@category]
  332 +
331 333 ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago)
332 334  
333 335 get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/')
... ... @@ -337,8 +339,8 @@ class SearchControllerTest &lt; ActionController::TestCase
337 339  
338 340 should 'return events of today when no date specified' do
339 341 person = create_user('someone').person
340   - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today)
341   - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month)
  342 + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => DateTime.now)
  343 + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => DateTime.now - 2.month)
342 344  
343 345 get :events
344 346  
... ... @@ -349,9 +351,9 @@ class SearchControllerTest &lt; ActionController::TestCase
349 351 person = create_user('someone').person
350 352  
351 353 ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id],
352   - :start_date => Date.today + 2.month)
  354 + :start_date => DateTime.now + 2.month)
353 355 ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id],
354   - :start_date => Date.today + 2.day)
  356 + :start_date => DateTime.now + 2.day)
355 357  
356 358 get :events
357 359  
... ... @@ -362,8 +364,8 @@ class SearchControllerTest &lt; ActionController::TestCase
362 364 should 'list events for a given month' do
363 365 person = create_user('testuser').person
364 366  
365   - create_event(person, :name => 'upcoming event 1', :category_ids => [@category.id], :start_date => Date.new(2008, 1, 25))
366   - create_event(person, :name => 'upcoming event 2', :category_ids => [@category.id], :start_date => Date.new(2008, 4, 27))
  367 + create_event(person, :name => 'upcoming event 1', :category_ids => [@category.id], :start_date => DateTime.new(2008, 1, 25))
  368 + create_event(person, :name => 'upcoming event 2', :category_ids => [@category.id], :start_date => DateTime.new(2008, 4, 27))
367 369  
368 370 get :events, :year => '2008', :month => '1'
369 371  
... ... @@ -373,7 +375,7 @@ class SearchControllerTest &lt; ActionController::TestCase
373 375 should 'see the events paginated' do
374 376 person = create_user('testuser').person
375 377 30.times do |i|
376   - create_event(person, :name => "Event #{i}", :start_date => Date.today)
  378 + create_event(person, :name => "Event #{i}", :start_date => DateTime.now)
377 379 end
378 380 get :events
379 381 assert_equal 20, assigns(:events).size
... ... @@ -416,7 +418,7 @@ class SearchControllerTest &lt; ActionController::TestCase
416 418 end
417 419  
418 420 should 'display current year/month by default as caption of current month' do
419   - Date.expects(:today).returns(Date.new(2008, 8, 1)).at_least_once
  421 + DateTime.expects(:now).returns(DateTime.new(2008, 8, 1)).at_least_once
420 422  
421 423 get :events
422 424 assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /August 2008/}
... ... @@ -475,7 +477,7 @@ class SearchControllerTest &lt; ActionController::TestCase
475 477  
476 478 should 'show events of specific day' do
477 479 person = create_user('anotheruser').person
478   - event = create_event(person, :name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28))
  480 + event = create_event(person, :name => 'Joao Birthday', :start_date => DateTime.new(2009, 10, 28))
479 481  
480 482 get :events_by_day, :year => 2009, :month => 10, :day => 28
481 483  
... ... @@ -484,8 +486,8 @@ class SearchControllerTest &lt; ActionController::TestCase
484 486  
485 487 should 'ignore filter of events if category not exists' do
486 488 person = create_user('anotheruser').person
487   - create_event(person, :name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28), :category_ids => [@category.id])
488   - create_event(person, :name => 'Maria Birthday', :start_date => Date.new(2009, 10, 28))
  489 + create_event(person, :name => 'Joao Birthday', :start_date => DateTime.new(2009, 10, 28), :category_ids => [@category.id])
  490 + create_event(person, :name => 'Maria Birthday', :start_date => DateTime.new(2009, 10, 28))
489 491  
490 492 id_of_unexistent_category = Category.last.id + 10
491 493  
... ... @@ -772,7 +774,7 @@ class SearchControllerTest &lt; ActionController::TestCase
772 774 protected
773 775  
774 776 def create_event(profile, options)
775   - ev = build(Event, { :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options))
  777 + ev = build(Event, { :name => 'some event', :start_date => DateTime.new(2008,1,1) }.merge(options))
776 778 ev.profile = profile
777 779 ev.save!
778 780 ev
... ...
test/unit/content_viewer_helper_test.rb
... ... @@ -16,14 +16,14 @@ class ContentViewerHelperTest &lt; ActionView::TestCase
16 16 blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id)
17 17 post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog)
18 18 result = article_title(post)
19   - assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
  19 + assert_tag_in_string result, :tag => 'span', :content => show_time(post.published_at)
20 20 end
21 21  
22 22 should 'display published-at for forum posts' do
23 23 forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id)
24 24 post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => forum)
25 25 result = article_title(post)
26   - assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
  26 + assert_tag_in_string result, :tag => 'span', :content => show_time(post.published_at)
27 27 end
28 28  
29 29 should 'not display published-at for non-blog and non-forum posts' do
... ...
test/unit/dates_helper_test.rb
... ... @@ -21,23 +21,23 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
21 21 should 'generate period with two dates' do
22 22 date1 = mock
23 23 date1.stubs(:year).returns('A')
24   - expects(:show_date).with(date1, anything).returns('XXX')
  24 + expects(:show_time).with(date1, anything).returns('XXX')
25 25 date2 = mock
26 26 date2.stubs(:year).returns('B')
27   - expects(:show_date).with(date2, anything).returns('YYY')
  27 + expects(:show_time).with(date2, anything).returns('YYY')
28 28 expects(:_).with('from %{date1} to %{date2}').returns('from %{date1} to %{date2}')
29 29 assert_equal 'from XXX to YYY', show_period(date1, date2)
30 30 end
31 31  
32 32 should 'generate period with in two diferent years' do
33   - date1 = Date.new(1920, 1, 2)
34   - date2 = Date.new(1992, 4, 6)
35   - assert_equal 'from January 2, 1920 to April 6, 1992', show_period(date1, date2)
  33 + date1 = DateTime.new(1920, 1, 2)
  34 + date2 = DateTime.new(1992, 4, 6)
  35 + assert_equal 'from January 2, 1920 0:00 to April 6, 1992 0:00', show_period(date1, date2)
36 36 end
37 37  
38 38 should 'generate period with in two diferent months of the same year' do
39   - date1 = Date.new(2013, 2, 1)
40   - date2 = Date.new(2013, 3, 1)
  39 + date1 = DateTime.new(2013, 2, 1)
  40 + date2 = DateTime.new(2013, 3, 1)
41 41 assert_equal 'from February 1 to March 1, 2013', show_period(date1, date2)
42 42 end
43 43  
... ... @@ -49,13 +49,13 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
49 49  
50 50 should 'generate period with two equal dates' do
51 51 date1 = mock
52   - expects(:show_date).with(date1, anything).returns('XXX')
  52 + expects(:show_time).with(date1, anything).returns('XXX')
53 53 assert_equal 'XXX', show_period(date1, date1)
54 54 end
55 55  
56 56 should 'generate period with one date only' do
57 57 date1 = mock
58   - expects(:show_date).with(date1, anything).returns('XXX')
  58 + expects(:show_time).with(date1, anything).returns('XXX')
59 59 assert_equal 'XXX', show_period(date1)
60 60 end
61 61  
... ... @@ -84,7 +84,7 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
84 84 end
85 85  
86 86 should 'fallback to current year/month in show_month' do
87   - Date.expects(:today).returns(Date.new(2008,11,1)).at_least_once
  87 + DateTime.expects(:now).returns(DateTime.new(2008,11,1)).at_least_once
88 88 assert_equal 'November 2008', show_month(nil, nil)
89 89 assert_equal 'November 2008', show_month('', '')
90 90 end
... ... @@ -118,16 +118,16 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
118 118 end
119 119  
120 120 should 'format time' do
121   - assert_equal '22 November 2008, 15:34', show_time(Time.mktime(2008, 11, 22, 15, 34, 0, 0))
  121 + assert_equal 'November 22, 2008 15:34', show_time(Time.mktime(2008, 11, 22, 15, 34, 0, 0))
122 122 end
123 123  
124 124 should 'format time with 2 digits minutes' do
125   - assert_equal '22 November 2008, 15:04', show_time(Time.mktime(2008, 11, 22, 15, 04, 0, 0))
  125 + assert_equal 'November 22, 2008 15:04', show_time(Time.mktime(2008, 11, 22, 15, 04, 0, 0))
126 126 end
127 127  
128 128 should 'translate time' do
129 129 time = Time.parse('25 May 2009, 12:47')
130   - assert_equal '25 May 2009, 12:47', show_time(time)
  130 + assert_equal 'May 25, 2009 12:47', show_time(time)
131 131 end
132 132  
133 133 should 'handle nil time' do
... ...
test/unit/event_test.rb
... ... @@ -29,15 +29,9 @@ class EventTest &lt; ActiveSupport::TestCase
29 29 assert_equal 'South Noosfero street, 88', e.address
30 30 end
31 31  
32   - should 'have a start date' do
33   - e = Event.new
34   - e.start_date = Date.today
35   - assert_kind_of Date, e.start_date
36   - end
37   -
38 32 should 'set start date default value as today' do
39 33 e = Event.new
40   - assert_equal Date.today, e.start_date
  34 + assert_in_delta DateTime.now.to_i, e.start_date.to_i, 1
41 35 end
42 36  
43 37 should 'require start date' do
... ... @@ -45,38 +39,32 @@ class EventTest &lt; ActiveSupport::TestCase
45 39 e.start_date = nil
46 40 e.valid?
47 41 assert e.errors[:start_date.to_s].present?
48   - e.start_date = Date.today
  42 + e.start_date = DateTime.now
49 43 e.valid?
50 44 refute e.errors[:start_date.to_s].present?
51 45 end
52 46  
53   - should 'have a end date' do
54   - e = Event.new
55   - e.end_date = Date.today
56   - assert_kind_of Date, e.end_date
57   - end
58   -
59 47 should 'use its own icon' do
60 48 assert_equal 'event', Event.icon_name
61 49 end
62 50  
63 51 should 'not allow end date before start date' do
64   - e = build(Event, :start_date => Date.new(2008, 01, 01), :end_date => Date.new(2007,01,01))
  52 + e = build(Event, :start_date => DateTime.new(2008, 01, 01), :end_date => DateTime.new(2007,01,01))
65 53 e.valid?
66 54 assert e.errors[:start_date.to_s].present?
67 55  
68   - e.end_date = Date.new(2008,01,05)
  56 + e.end_date = DateTime.new(2008,01,05)
69 57 e.valid?
70 58 refute e.errors[:start_date.to_s].present?
71 59 end
72 60  
73 61 should 'find by range of dates' do
74 62 profile = create_user('testuser').person
75   - e1 = create(Event, :name => 'e1', :start_date => Date.new(2008,1,1), :profile => profile)
76   - e2 = create(Event, :name => 'e2', :start_date => Date.new(2008,2,1), :profile => profile)
77   - e3 = create(Event, :name => 'e3', :start_date => Date.new(2008,3,1), :profile => profile)
  63 + e1 = create(Event, :name => 'e1', :start_date => DateTime.new(2008,1,1), :profile => profile)
  64 + e2 = create(Event, :name => 'e2', :start_date => DateTime.new(2008,2,1), :profile => profile)
  65 + e3 = create(Event, :name => 'e3', :start_date => DateTime.new(2008,3,1), :profile => profile)
78 66  
79   - found = Event.by_range(Date.new(2008, 1, 1)..Date.new(2008, 2, 28))
  67 + found = Event.by_range(DateTime.new(2008, 1, 1)..DateTime.new(2008, 2, 28))
80 68 assert_includes found, e1
81 69 assert_includes found, e2
82 70 assert_not_includes found, e3
... ... @@ -84,32 +72,33 @@ class EventTest &lt; ActiveSupport::TestCase
84 72  
85 73 should 'filter events by range' do
86 74 profile = create_user('testuser').person
87   - e1 = create(Event, :name => 'e1', :start_date => Date.new(2008,1,15), :profile => profile)
88   - assert_includes profile.events.by_range(Date.new(2008, 1, 10)..Date.new(2008, 1, 20)), e1
  75 + e1 = create(Event, :name => 'e1', :start_date => DateTime.new(2008,1,15), :profile => profile)
  76 + assert_includes profile.events.by_range(DateTime.new(2008, 1, 10)..DateTime.new(2008, 1, 20)), e1
89 77 end
90 78  
91 79 should 'provide period for searching in month' do
92   - assert_equal Date.new(2008, 1, 1)..Date.new(2008,1,31), Event.date_range(2008, 1)
93   - assert_equal Date.new(2008, 2, 1)..Date.new(2008,2,29), Event.date_range(2008, 2)
94   - assert_equal Date.new(2007, 2, 1)..Date.new(2007,2,28), Event.date_range(2007, 2)
  80 + assert_equal DateTime.new(2008, 1, 1)..DateTime.new(2008,1,31), Event.date_range(2008, 1)
  81 + assert_equal DateTime.new(2008, 2, 1)..DateTime.new(2008,2,29), Event.date_range(2008, 2)
  82 + assert_equal DateTime.new(2007, 2, 1)..DateTime.new(2007,2,28), Event.date_range(2007, 2)
95 83 end
96 84  
97 85 should 'support string arguments to Event#date_range' do
98   - assert_equal Date.new(2008,1,1)..Date.new(2008,1,31), Event.date_range('2008', '1')
  86 + assert_equal DateTime.new(2008,1,1)..DateTime.new(2008,1,31), Event.date_range('2008', '1')
99 87 end
100 88  
101 89 should 'provide range of dates for event with both dates filled' do
102   - e = build(Event, :start_date => Date.new(2008, 1, 1), :end_date => Date.new(2008, 1, 5))
103   - assert_equal (Date.new(2008,1,1)..Date.new(2008,1,5)), e.date_range
  90 + e = build(Event, :start_date => DateTime.new(2008, 1, 1), :end_date => DateTime.new(2008, 1, 5))
  91 + assert_equal (DateTime.new(2008,1,1)..DateTime.new(2008,1,5)), e.date_range
104 92 end
105 93  
106 94 should 'provide range of dates for event with only start date' do
107   - e = build(Event, :start_date => Date.new(2008, 1, 1))
108   - assert_equal (Date.new(2008,1,1)..Date.new(2008,1,1)), e.date_range
  95 + e = build(Event, :start_date => DateTime.new(2008, 1, 1))
  96 + assert_equal (DateTime.new(2008,1,1)..DateTime.new(2008,1,1)), e.date_range
109 97 end
110 98  
111 99 should 'provide nice display format' do
112   - event = build(Event, :start_date => Date.new(2008,1,1), :end_date => Date.new(2008,1,1), :link => 'http://www.myevent.org', :body => '<p>my somewhat short description</p>')
  100 + date = Time.zone.local(2008, 1, 1, 0, 0, 0)
  101 + event = build(Event, :start_date => date, :end_date => date, :link => 'http://www.myevent.org', :body => '<p>my somewhat short description</p>')
113 102 display = instance_eval(&event.to_html)
114 103  
115 104 assert_tag_in_string display, :content => Regexp.new("January 1, 2008")
... ... @@ -148,7 +137,7 @@ class EventTest &lt; ActiveSupport::TestCase
148 137 profile = create_user('testuser').person
149 138 event = create(Event, :profile => profile, :name => 'test',
150 139 :body => '<p>first paragraph </p><p>second paragraph </p>',
151   - :link => 'www.colivre.coop.br', :start_date => Date.today)
  140 + :link => 'www.colivre.coop.br', :start_date => DateTime.now)
152 141  
153 142 assert_match '<p>first paragraph </p>', event.first_paragraph
154 143 end
... ... @@ -161,7 +150,7 @@ class EventTest &lt; ActiveSupport::TestCase
161 150  
162 151 should 'filter HTML in body' do
163 152 profile = create_user('testuser').person
164   - e = create(Event, :profile => profile, :name => 'test', :body => '<p>a paragraph (valid)</p><script type="text/javascript">/* this is invalid */</script>"', :link => 'www.colivre.coop.br', :start_date => Date.today)
  153 + e = create(Event, :profile => profile, :name => 'test', :body => '<p>a paragraph (valid)</p><script type="text/javascript">/* this is invalid */</script>"', :link => 'www.colivre.coop.br', :start_date => DateTime.now)
165 154  
166 155 assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)'
167 156 assert_no_tag_in_string e.body, :tag => 'script'
... ... @@ -169,7 +158,7 @@ class EventTest &lt; ActiveSupport::TestCase
169 158  
170 159 should 'filter HTML in name' do
171 160 profile = create_user('testuser').person
172   - e = create(Event, :profile => profile, :name => '<p>a paragraph (valid)</p><script type="text/javascript">/* this is invalid */</script>"', :link => 'www.colivre.coop.br', :start_date => Date.today)
  161 + e = create(Event, :profile => profile, :name => '<p>a paragraph (valid)</p><script type="text/javascript">/* this is invalid */</script>"', :link => 'www.colivre.coop.br', :start_date => DateTime.now)
173 162  
174 163 assert_tag_in_string e.name, :tag => 'p', :content => 'a paragraph (valid)'
175 164 assert_no_tag_in_string e.name, :tag => 'script'
... ... @@ -184,8 +173,8 @@ class EventTest &lt; ActiveSupport::TestCase
184 173  
185 174 should 'list all events' do
186 175 profile = fast_create(Profile)
187   - event1 = build(Event, :name => 'Ze Birthday', :start_date => Date.today)
188   - event2 = build(Event, :name => 'Mane Birthday', :start_date => Date.today >> 1)
  176 + event1 = build(Event, :name => 'Ze Birthday', :start_date => DateTime.now)
  177 + event2 = build(Event, :name => 'Mane Birthday', :start_date => DateTime.now >> 1)
189 178 profile.events << [event1, event2]
190 179 assert_includes profile.events, event1
191 180 assert_includes profile.events, event2
... ... @@ -194,7 +183,7 @@ class EventTest &lt; ActiveSupport::TestCase
194 183 should 'list events by day' do
195 184 profile = fast_create(Profile)
196 185  
197   - today = Date.today
  186 + today = DateTime.now
198 187 yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day)
199 188 today_event = build(Event, :name => 'Ze Birthday', :start_date => today)
200 189 tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day)
... ... @@ -207,7 +196,7 @@ class EventTest &lt; ActiveSupport::TestCase
207 196 should 'list events by month' do
208 197 profile = fast_create(Profile)
209 198  
210   - today = Date.new(2013, 10, 6)
  199 + today = DateTime.new(2013, 10, 6)
211 200  
212 201 last_month_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.month)
213 202  
... ... @@ -230,7 +219,7 @@ class EventTest &lt; ActiveSupport::TestCase
230 219 should 'event by month ordered by start date'do
231 220 profile = fast_create(Profile)
232 221  
233   - today = Date.new(2013, 10, 6)
  222 + today = DateTime.new(2013, 10, 6)
234 223  
235 224 event_1 = Event.new(:name => 'Maria Birthday', :start_date => today + 1.day)
236 225 event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day)
... ... @@ -248,7 +237,7 @@ class EventTest &lt; ActiveSupport::TestCase
248 237 should 'list events in a range' do
249 238 profile = fast_create(Profile)
250 239  
251   - today = Date.today
  240 + today = DateTime.now
252 241 event_in_range = build(Event, :name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day)
253 242 event_in_day = build(Event, :name => 'Ze Birthday', :start_date => today)
254 243  
... ... @@ -262,7 +251,7 @@ class EventTest &lt; ActiveSupport::TestCase
262 251 should 'not list events out of range' do
263 252 profile = fast_create(Profile)
264 253  
265   - today = Date.today
  254 + today = DateTime.now
266 255 event_in_range1 = build(Event, :name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day)
267 256 event_in_range2 = build(Event, :name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day)
268 257 event_out_of_range = build(Event, :name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day)
... ...
test/unit/profile_test.rb
... ... @@ -1563,8 +1563,8 @@ class ProfileTest &lt; ActiveSupport::TestCase
1563 1563  
1564 1564 should 'list all events' do
1565 1565 profile = fast_create(Profile)
1566   - event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today)
1567   - event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1)
  1566 + event1 = Event.new(:name => 'Ze Birthday', :start_date => DateTime.now)
  1567 + event2 = Event.new(:name => 'Mane Birthday', :start_date => DateTime.now >> 1)
1568 1568 profile.events << [event1, event2]
1569 1569 assert_includes profile.events, event1
1570 1570 assert_includes profile.events, event2
... ... @@ -1573,7 +1573,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1573 1573 should 'list events by day' do
1574 1574 profile = fast_create(Profile)
1575 1575  
1576   - today = Date.today
  1576 + today = DateTime.now
1577 1577 yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day)
1578 1578 today_event = Event.new(:name => 'Ze Birthday', :start_date => today)
1579 1579 tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day)
... ... @@ -1586,7 +1586,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1586 1586 should 'list events by month' do
1587 1587 profile = fast_create(Profile)
1588 1588  
1589   - today = Date.new(2014, 03, 2)
  1589 + today = DateTime.new(2014, 03, 2)
1590 1590 yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day)
1591 1591 today_event = Event.new(:name => 'Ze Birthday', :start_date => today)
1592 1592 tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day)
... ... @@ -1599,7 +1599,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1599 1599 should 'list events in a range' do
1600 1600 profile = fast_create(Profile)
1601 1601  
1602   - today = Date.today
  1602 + today = DateTime.now
1603 1603 event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day)
1604 1604 event_in_day = Event.new(:name => 'Ze Birthday', :start_date => today)
1605 1605  
... ... @@ -1613,7 +1613,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1613 1613 should 'not list events out of range' do
1614 1614 profile = fast_create(Profile)
1615 1615  
1616   - today = Date.today
  1616 + today = DateTime.now
1617 1617 event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day)
1618 1618 event_in_range2 = Event.new(:name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day)
1619 1619 event_out_of_range = Event.new(:name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day)
... ... @@ -1627,9 +1627,9 @@ class ProfileTest &lt; ActiveSupport::TestCase
1627 1627  
1628 1628 should 'sort events by date' do
1629 1629 profile = fast_create(Profile)
1630   - event1 = Event.new(:name => 'Noosfero Hackaton', :start_date => Date.today)
1631   - event2 = Event.new(:name => 'Debian Day', :start_date => Date.today - 1)
1632   - event3 = Event.new(:name => 'Fisl 10', :start_date => Date.today + 1)
  1630 + event1 = Event.new(:name => 'Noosfero Hackaton', :start_date => DateTime.now)
  1631 + event2 = Event.new(:name => 'Debian Day', :start_date => DateTime.now - 1)
  1632 + event3 = Event.new(:name => 'Fisl 10', :start_date => DateTime.now + 1)
1633 1633 profile.events << [event1, event2, event3]
1634 1634 assert_equal [event2, event1, event3], profile.events
1635 1635 end
... ...