Commit e021f7019f269a3e98f262676689ff9966c64701
1 parent
180ad529
Exists in
master
and in
6 other branches
change event start date and ende date to datetime
Showing
12 changed files
with
111 additions
and
90 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -92,10 +92,10 @@ class SearchController < PublicController | @@ -92,10 +92,10 @@ class SearchController < PublicController | ||
92 | 92 | ||
93 | def events | 93 | def events |
94 | if params[:year].blank? && params[:year].blank? && params[:day].blank? | 94 | if params[:year].blank? && params[:year].blank? && params[:day].blank? |
95 | - @date = Date.today | 95 | + @date = DateTime.now |
96 | else | 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 | day = (params[:day] ? params[:day].to_i : 1) | 99 | day = (params[:day] ? params[:day].to_i : 1) |
100 | @date = build_date(year, month, day) | 100 | @date = build_date(year, month, day) |
101 | end | 101 | end |
@@ -106,9 +106,7 @@ class SearchController < PublicController | @@ -106,9 +106,7 @@ class SearchController < PublicController | ||
106 | @events = @category ? | 106 | @events = @category ? |
107 | environment.events.by_day(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) : | 107 | environment.events.by_day(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) : |
108 | environment.events.by_day(@date).paginate(:per_page => per_page, :page => params[:page]) | 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 | @events = @category ? | 110 | @events = @category ? |
113 | environment.events.by_month(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) : | 111 | environment.events.by_month(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) : |
114 | environment.events.by_month(@date).paginate(:per_page => per_page, :page => params[:page]) | 112 | environment.events.by_month(@date).paginate(:per_page => per_page, :page => params[:page]) |
app/helpers/dates_helper.rb
@@ -43,9 +43,14 @@ module DatesHelper | @@ -43,9 +43,14 @@ module DatesHelper | ||
43 | end | 43 | end |
44 | 44 | ||
45 | # formats a datetime for displaying. | 45 | # formats a datetime for displaying. |
46 | - def show_time(time) | ||
47 | - if time | 46 | + def show_time(time, use_numbers = true, year = true, left_time = false) |
47 | + if time && use_numbers | ||
48 | _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") } | 48 | _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(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 | else | 54 | else |
50 | '' | 55 | '' |
51 | end | 56 | end |
@@ -53,7 +58,7 @@ module DatesHelper | @@ -53,7 +58,7 @@ module DatesHelper | ||
53 | 58 | ||
54 | def show_period(date1, date2 = nil, use_numbers = false) | 59 | def show_period(date1, date2 = nil, use_numbers = false) |
55 | if (date1 == date2) || (date2.nil?) | 60 | if (date1 == date2) || (date2.nil?) |
56 | - show_date(date1, use_numbers) | 61 | + show_time(date1, use_numbers) |
57 | else | 62 | else |
58 | if date1.year == date2.year | 63 | if date1.year == date2.year |
59 | if date1.month == date2.month | 64 | if date1.month == date2.month |
@@ -106,18 +111,18 @@ module DatesHelper | @@ -106,18 +111,18 @@ module DatesHelper | ||
106 | 111 | ||
107 | def build_date(year, month, day = 1) | 112 | def build_date(year, month, day = 1) |
108 | if year.blank? and month.blank? and day.blank? | 113 | if year.blank? and month.blank? and day.blank? |
109 | - Date.today | 114 | + DateTime.now |
110 | else | 115 | else |
111 | if year.blank? | 116 | if year.blank? |
112 | - year = Date.today.year | 117 | + year = DateTime.now.year |
113 | end | 118 | end |
114 | if month.blank? | 119 | if month.blank? |
115 | - month = Date.today.month | 120 | + month = DateTime.now.month |
116 | end | 121 | end |
117 | if day.blank? | 122 | if day.blank? |
118 | day = 1 | 123 | day = 1 |
119 | end | 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 | end | 126 | end |
122 | end | 127 | end |
123 | 128 |
app/helpers/events_helper.rb
@@ -16,7 +16,7 @@ module EventsHelper | @@ -16,7 +16,7 @@ module EventsHelper | ||
16 | 16 | ||
17 | content_tag( 'tr', | 17 | content_tag( 'tr', |
18 | content_tag('td', | 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 | content_tag('div',link_to(article.name,article.url),:class => 'event-title') + | 20 | content_tag('div',link_to(article.name,article.url),:class => 'event-title') + |
21 | content_tag('div',(article.address.nil? or article.address == '') ? '' : (_('Place: ') + article.address),:class => 'event-place') | 21 | content_tag('div',(article.address.nil? or article.address == '') ? '' : (_('Place: ') + article.address),:class => 'event-place') |
22 | ) | 22 | ) |
app/models/event.rb
@@ -23,7 +23,7 @@ class Event < Article | @@ -23,7 +23,7 @@ class Event < Article | ||
23 | 23 | ||
24 | def initialize(*args) | 24 | def initialize(*args) |
25 | super(*args) | 25 | super(*args) |
26 | - self.start_date ||= Date.today | 26 | + self.start_date ||= DateTime.now |
27 | end | 27 | end |
28 | 28 | ||
29 | validates_presence_of :title, :start_date | 29 | validates_presence_of :title, :start_date |
@@ -35,7 +35,7 @@ class Event < Article | @@ -35,7 +35,7 @@ class Event < Article | ||
35 | end | 35 | end |
36 | 36 | ||
37 | scope :by_day, lambda { |date| | 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 | :order => 'start_date ASC' | 39 | :order => 'start_date ASC' |
40 | } | 40 | } |
41 | } | 41 | } |
@@ -80,7 +80,7 @@ class Event < Article | @@ -80,7 +80,7 @@ class Event < Article | ||
80 | 80 | ||
81 | def self.date_range(year, month) | 81 | def self.date_range(year, month) |
82 | if year.nil? || month.nil? | 82 | if year.nil? || month.nil? |
83 | - today = Date.today | 83 | + today = DateTime.now |
84 | year = today.year | 84 | year = today.year |
85 | month = today.month | 85 | month = today.month |
86 | else | 86 | else |
@@ -88,7 +88,7 @@ class Event < Article | @@ -88,7 +88,7 @@ class Event < Article | ||
88 | month = month.to_i | 88 | month = month.to_i |
89 | end | 89 | end |
90 | 90 | ||
91 | - first_day = Date.new(year, month, 1) | 91 | + first_day = DateTime.new(year, month, 1) |
92 | last_day = first_day + 1.month - 1.day | 92 | last_day = first_day + 1.month - 1.day |
93 | 93 | ||
94 | first_day..last_day | 94 | first_day..last_day |
app/views/cms/_event.html.erb
@@ -8,9 +8,9 @@ | @@ -8,9 +8,9 @@ | ||
8 | <%= render :partial => 'general_fields' %> | 8 | <%= render :partial => 'general_fields' %> |
9 | <%= render :partial => 'translatable' %> | 9 | <%= render :partial => 'translatable' %> |
10 | 10 | ||
11 | -<%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> | 11 | +<%= labelled_form_field(_('Start date'), date_field('article[start_date]', @article.start_date,_('%Y-%m-%d'), {:time => true}, {:id => 'article_start_date'} )) %> |
12 | 12 | ||
13 | -<%= labelled_form_field(_('End date'), pick_date(:article, :end_date)) %> | 13 | +<%= labelled_form_field(_('End date'), date_field('article[end_date]', @article.end_date, _('%Y-%m-%d'), {:time => true}, {:id => 'article_end_date'})) %> |
14 | 14 | ||
15 | <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> | 15 | <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> |
16 | 16 |
db/migrate/20150722042714_change_article_date_to_datetime.rb
0 → 100644
@@ -0,0 +1,27 @@ | @@ -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 |
public/designs/themes/base/style.scss
@@ -1505,7 +1505,8 @@ table#recaptcha_table tr:hover td { | @@ -1505,7 +1505,8 @@ table#recaptcha_table tr:hover td { | ||
1505 | 1505 | ||
1506 | .event-date { | 1506 | .event-date { |
1507 | background: url('/images/calendar_date_select/calendar-icon.png') no-repeat left center; | 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 | .event-link { | 1512 | .event-link { |
test/functional/events_controller_test.rb
@@ -8,12 +8,12 @@ class EventsControllerTest < ActionController::TestCase | @@ -8,12 +8,12 @@ class EventsControllerTest < ActionController::TestCase | ||
8 | attr_reader :profile | 8 | attr_reader :profile |
9 | 9 | ||
10 | should 'list today events by default' do | 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 | get :events, :profile => profile.identifier | 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 | assert_tag :tag => 'div', :attributes => {:id => "agenda-items"}, | 17 | assert_tag :tag => 'div', :attributes => {:id => "agenda-items"}, |
18 | :descendant => {:tag => 'h3', :content => "Events for #{today}"}, | 18 | :descendant => {:tag => 'h3', :content => "Events for #{today}"}, |
19 | :descendant => {:tag => 'tr', :content => "Joao Birthday"}, | 19 | :descendant => {:tag => 'tr', :content => "Joao Birthday"}, |
@@ -23,15 +23,15 @@ class EventsControllerTest < ActionController::TestCase | @@ -23,15 +23,15 @@ class EventsControllerTest < ActionController::TestCase | ||
23 | should 'display calendar of current month' do | 23 | should 'display calendar of current month' do |
24 | get :events, :profile => profile.identifier | 24 | get :events, :profile => profile.identifier |
25 | 25 | ||
26 | - month = Date.today.strftime("%B %Y") | 26 | + month = DateTime.now.strftime("%B %Y") |
27 | assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /#{month}/} | 27 | assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /#{month}/} |
28 | end | 28 | end |
29 | 29 | ||
30 | should 'display links to previous and next month' do | 30 | should 'display links to previous and next month' do |
31 | get :events, :profile => profile.identifier | 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 | prev_month_name = prev_month.strftime("%B") | 35 | prev_month_name = prev_month.strftime("%B") |
36 | next_month_name = next_month.strftime("%B") | 36 | next_month_name = next_month.strftime("%B") |
37 | assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{prev_month.year}/#{prev_month.month}"}, :content => prev_month_name | 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 < ActionController::TestCase | @@ -40,14 +40,14 @@ class EventsControllerTest < ActionController::TestCase | ||
40 | 40 | ||
41 | should 'see the events paginated' do | 41 | should 'see the events paginated' do |
42 | 30.times do |i| | 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 | end | 44 | end |
45 | get :events, :profile => profile.identifier | 45 | get :events, :profile => profile.identifier |
46 | assert_equal 20, assigns(:events).size | 46 | assert_equal 20, assigns(:events).size |
47 | end | 47 | end |
48 | 48 | ||
49 | should 'show events of specific day' do | 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 | get :events_by_day, :profile => profile.identifier, :year => 2009, :month => 10, :day => 28 | 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 < ActionController::TestCase | @@ -305,7 +305,7 @@ class SearchControllerTest < ActionController::TestCase | ||
305 | 305 | ||
306 | should 'search for events' do | 306 | should 'search for events' do |
307 | person = create_user('teste').person | 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 | get :events, :query => 'event to be found' | 310 | get :events, :query => 'event to be found' |
311 | 311 | ||
@@ -314,10 +314,10 @@ class SearchControllerTest < ActionController::TestCase | @@ -314,10 +314,10 @@ class SearchControllerTest < ActionController::TestCase | ||
314 | 314 | ||
315 | should 'return events of the day' do | 315 | should 'return events of the day' do |
316 | person = create_user('someone').person | 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 | ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago) | 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 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year | 322 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year |
323 | assert_equal [ev1], assigns(:events) | 323 | assert_equal [ev1], assigns(:events) |
@@ -325,9 +325,11 @@ class SearchControllerTest < ActionController::TestCase | @@ -325,9 +325,11 @@ class SearchControllerTest < ActionController::TestCase | ||
325 | 325 | ||
326 | should 'return events of the day with category' do | 326 | should 'return events of the day with category' do |
327 | person = create_user('someone').person | 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 | ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago) | 333 | ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago) |
332 | 334 | ||
333 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/') | 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 < ActionController::TestCase | @@ -337,8 +339,8 @@ class SearchControllerTest < ActionController::TestCase | ||
337 | 339 | ||
338 | should 'return events of today when no date specified' do | 340 | should 'return events of today when no date specified' do |
339 | person = create_user('someone').person | 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 | get :events | 345 | get :events |
344 | 346 | ||
@@ -349,9 +351,9 @@ class SearchControllerTest < ActionController::TestCase | @@ -349,9 +351,9 @@ class SearchControllerTest < ActionController::TestCase | ||
349 | person = create_user('someone').person | 351 | person = create_user('someone').person |
350 | 352 | ||
351 | ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], | 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 | ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], | 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 | get :events | 358 | get :events |
357 | 359 | ||
@@ -362,8 +364,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -362,8 +364,8 @@ class SearchControllerTest < ActionController::TestCase | ||
362 | should 'list events for a given month' do | 364 | should 'list events for a given month' do |
363 | person = create_user('testuser').person | 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 | get :events, :year => '2008', :month => '1' | 370 | get :events, :year => '2008', :month => '1' |
369 | 371 | ||
@@ -373,7 +375,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -373,7 +375,7 @@ class SearchControllerTest < ActionController::TestCase | ||
373 | should 'see the events paginated' do | 375 | should 'see the events paginated' do |
374 | person = create_user('testuser').person | 376 | person = create_user('testuser').person |
375 | 30.times do |i| | 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 | end | 379 | end |
378 | get :events | 380 | get :events |
379 | assert_equal 20, assigns(:events).size | 381 | assert_equal 20, assigns(:events).size |
@@ -416,7 +418,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -416,7 +418,7 @@ class SearchControllerTest < ActionController::TestCase | ||
416 | end | 418 | end |
417 | 419 | ||
418 | should 'display current year/month by default as caption of current month' do | 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 | get :events | 423 | get :events |
422 | assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /August 2008/} | 424 | assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /August 2008/} |
@@ -475,7 +477,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -475,7 +477,7 @@ class SearchControllerTest < ActionController::TestCase | ||
475 | 477 | ||
476 | should 'show events of specific day' do | 478 | should 'show events of specific day' do |
477 | person = create_user('anotheruser').person | 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 | get :events_by_day, :year => 2009, :month => 10, :day => 28 | 482 | get :events_by_day, :year => 2009, :month => 10, :day => 28 |
481 | 483 | ||
@@ -484,8 +486,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -484,8 +486,8 @@ class SearchControllerTest < ActionController::TestCase | ||
484 | 486 | ||
485 | should 'ignore filter of events if category not exists' do | 487 | should 'ignore filter of events if category not exists' do |
486 | person = create_user('anotheruser').person | 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 | id_of_unexistent_category = Category.last.id + 10 | 492 | id_of_unexistent_category = Category.last.id + 10 |
491 | 493 | ||
@@ -772,7 +774,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -772,7 +774,7 @@ class SearchControllerTest < ActionController::TestCase | ||
772 | protected | 774 | protected |
773 | 775 | ||
774 | def create_event(profile, options) | 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 | ev.profile = profile | 778 | ev.profile = profile |
777 | ev.save! | 779 | ev.save! |
778 | ev | 780 | ev |
test/unit/dates_helper_test.rb
@@ -84,7 +84,7 @@ class DatesHelperTest < ActiveSupport::TestCase | @@ -84,7 +84,7 @@ class DatesHelperTest < ActiveSupport::TestCase | ||
84 | end | 84 | end |
85 | 85 | ||
86 | should 'fallback to current year/month in show_month' do | 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 | assert_equal 'November 2008', show_month(nil, nil) | 88 | assert_equal 'November 2008', show_month(nil, nil) |
89 | assert_equal 'November 2008', show_month('', '') | 89 | assert_equal 'November 2008', show_month('', '') |
90 | end | 90 | end |
test/unit/event_test.rb
@@ -29,15 +29,9 @@ class EventTest < ActiveSupport::TestCase | @@ -29,15 +29,9 @@ class EventTest < ActiveSupport::TestCase | ||
29 | assert_equal 'South Noosfero street, 88', e.address | 29 | assert_equal 'South Noosfero street, 88', e.address |
30 | end | 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 | should 'set start date default value as today' do | 32 | should 'set start date default value as today' do |
39 | e = Event.new | 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 | end | 35 | end |
42 | 36 | ||
43 | should 'require start date' do | 37 | should 'require start date' do |
@@ -45,38 +39,32 @@ class EventTest < ActiveSupport::TestCase | @@ -45,38 +39,32 @@ class EventTest < ActiveSupport::TestCase | ||
45 | e.start_date = nil | 39 | e.start_date = nil |
46 | e.valid? | 40 | e.valid? |
47 | assert e.errors[:start_date.to_s].present? | 41 | assert e.errors[:start_date.to_s].present? |
48 | - e.start_date = Date.today | 42 | + e.start_date = DateTime.now |
49 | e.valid? | 43 | e.valid? |
50 | refute e.errors[:start_date.to_s].present? | 44 | refute e.errors[:start_date.to_s].present? |
51 | end | 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 | should 'use its own icon' do | 47 | should 'use its own icon' do |
60 | assert_equal 'event', Event.icon_name | 48 | assert_equal 'event', Event.icon_name |
61 | end | 49 | end |
62 | 50 | ||
63 | should 'not allow end date before start date' do | 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 | e.valid? | 53 | e.valid? |
66 | assert e.errors[:start_date.to_s].present? | 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 | e.valid? | 57 | e.valid? |
70 | refute e.errors[:start_date.to_s].present? | 58 | refute e.errors[:start_date.to_s].present? |
71 | end | 59 | end |
72 | 60 | ||
73 | should 'find by range of dates' do | 61 | should 'find by range of dates' do |
74 | profile = create_user('testuser').person | 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 | assert_includes found, e1 | 68 | assert_includes found, e1 |
81 | assert_includes found, e2 | 69 | assert_includes found, e2 |
82 | assert_not_includes found, e3 | 70 | assert_not_includes found, e3 |
@@ -84,32 +72,32 @@ class EventTest < ActiveSupport::TestCase | @@ -84,32 +72,32 @@ class EventTest < ActiveSupport::TestCase | ||
84 | 72 | ||
85 | should 'filter events by range' do | 73 | should 'filter events by range' do |
86 | profile = create_user('testuser').person | 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 | end | 77 | end |
90 | 78 | ||
91 | should 'provide period for searching in month' do | 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 | end | 83 | end |
96 | 84 | ||
97 | should 'support string arguments to Event#date_range' do | 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 | end | 87 | end |
100 | 88 | ||
101 | should 'provide range of dates for event with both dates filled' do | 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 | end | 92 | end |
105 | 93 | ||
106 | should 'provide range of dates for event with only start date' do | 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 | end | 97 | end |
110 | 98 | ||
111 | should 'provide nice display format' do | 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 | + event = build(Event, :start_date => DateTime.new(2008,1,1), :end_date => DateTime.new(2008,1,1), :link => 'http://www.myevent.org', :body => '<p>my somewhat short description</p>') |
113 | display = instance_eval(&event.to_html) | 101 | display = instance_eval(&event.to_html) |
114 | 102 | ||
115 | assert_tag_in_string display, :content => Regexp.new("January 1, 2008") | 103 | assert_tag_in_string display, :content => Regexp.new("January 1, 2008") |
@@ -148,7 +136,7 @@ class EventTest < ActiveSupport::TestCase | @@ -148,7 +136,7 @@ class EventTest < ActiveSupport::TestCase | ||
148 | profile = create_user('testuser').person | 136 | profile = create_user('testuser').person |
149 | event = create(Event, :profile => profile, :name => 'test', | 137 | event = create(Event, :profile => profile, :name => 'test', |
150 | :body => '<p>first paragraph </p><p>second paragraph </p>', | 138 | :body => '<p>first paragraph </p><p>second paragraph </p>', |
151 | - :link => 'www.colivre.coop.br', :start_date => Date.today) | 139 | + :link => 'www.colivre.coop.br', :start_date => DateTime.now) |
152 | 140 | ||
153 | assert_match '<p>first paragraph </p>', event.first_paragraph | 141 | assert_match '<p>first paragraph </p>', event.first_paragraph |
154 | end | 142 | end |
@@ -161,7 +149,7 @@ class EventTest < ActiveSupport::TestCase | @@ -161,7 +149,7 @@ class EventTest < ActiveSupport::TestCase | ||
161 | 149 | ||
162 | should 'filter HTML in body' do | 150 | should 'filter HTML in body' do |
163 | profile = create_user('testuser').person | 151 | 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) | 152 | + 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 | 153 | ||
166 | assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)' | 154 | assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)' |
167 | assert_no_tag_in_string e.body, :tag => 'script' | 155 | assert_no_tag_in_string e.body, :tag => 'script' |
@@ -169,7 +157,7 @@ class EventTest < ActiveSupport::TestCase | @@ -169,7 +157,7 @@ class EventTest < ActiveSupport::TestCase | ||
169 | 157 | ||
170 | should 'filter HTML in name' do | 158 | should 'filter HTML in name' do |
171 | profile = create_user('testuser').person | 159 | 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) | 160 | + 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 | 161 | ||
174 | assert_tag_in_string e.name, :tag => 'p', :content => 'a paragraph (valid)' | 162 | assert_tag_in_string e.name, :tag => 'p', :content => 'a paragraph (valid)' |
175 | assert_no_tag_in_string e.name, :tag => 'script' | 163 | assert_no_tag_in_string e.name, :tag => 'script' |
@@ -184,8 +172,8 @@ class EventTest < ActiveSupport::TestCase | @@ -184,8 +172,8 @@ class EventTest < ActiveSupport::TestCase | ||
184 | 172 | ||
185 | should 'list all events' do | 173 | should 'list all events' do |
186 | profile = fast_create(Profile) | 174 | 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) | 175 | + event1 = build(Event, :name => 'Ze Birthday', :start_date => DateTime.now) |
176 | + event2 = build(Event, :name => 'Mane Birthday', :start_date => DateTime.now >> 1) | ||
189 | profile.events << [event1, event2] | 177 | profile.events << [event1, event2] |
190 | assert_includes profile.events, event1 | 178 | assert_includes profile.events, event1 |
191 | assert_includes profile.events, event2 | 179 | assert_includes profile.events, event2 |
@@ -194,7 +182,7 @@ class EventTest < ActiveSupport::TestCase | @@ -194,7 +182,7 @@ class EventTest < ActiveSupport::TestCase | ||
194 | should 'list events by day' do | 182 | should 'list events by day' do |
195 | profile = fast_create(Profile) | 183 | profile = fast_create(Profile) |
196 | 184 | ||
197 | - today = Date.today | 185 | + today = DateTime.now |
198 | yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day) | 186 | yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day) |
199 | today_event = build(Event, :name => 'Ze Birthday', :start_date => today) | 187 | today_event = build(Event, :name => 'Ze Birthday', :start_date => today) |
200 | tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day) | 188 | tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day) |
@@ -207,7 +195,7 @@ class EventTest < ActiveSupport::TestCase | @@ -207,7 +195,7 @@ class EventTest < ActiveSupport::TestCase | ||
207 | should 'list events by month' do | 195 | should 'list events by month' do |
208 | profile = fast_create(Profile) | 196 | profile = fast_create(Profile) |
209 | 197 | ||
210 | - today = Date.new(2013, 10, 6) | 198 | + today = DateTime.new(2013, 10, 6) |
211 | 199 | ||
212 | last_month_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.month) | 200 | last_month_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.month) |
213 | 201 | ||
@@ -230,7 +218,7 @@ class EventTest < ActiveSupport::TestCase | @@ -230,7 +218,7 @@ class EventTest < ActiveSupport::TestCase | ||
230 | should 'event by month ordered by start date'do | 218 | should 'event by month ordered by start date'do |
231 | profile = fast_create(Profile) | 219 | profile = fast_create(Profile) |
232 | 220 | ||
233 | - today = Date.new(2013, 10, 6) | 221 | + today = DateTime.new(2013, 10, 6) |
234 | 222 | ||
235 | event_1 = Event.new(:name => 'Maria Birthday', :start_date => today + 1.day) | 223 | event_1 = Event.new(:name => 'Maria Birthday', :start_date => today + 1.day) |
236 | event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day) | 224 | event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day) |
@@ -248,7 +236,7 @@ class EventTest < ActiveSupport::TestCase | @@ -248,7 +236,7 @@ class EventTest < ActiveSupport::TestCase | ||
248 | should 'list events in a range' do | 236 | should 'list events in a range' do |
249 | profile = fast_create(Profile) | 237 | profile = fast_create(Profile) |
250 | 238 | ||
251 | - today = Date.today | 239 | + today = DateTime.now |
252 | event_in_range = build(Event, :name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 240 | event_in_range = build(Event, :name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
253 | event_in_day = build(Event, :name => 'Ze Birthday', :start_date => today) | 241 | event_in_day = build(Event, :name => 'Ze Birthday', :start_date => today) |
254 | 242 | ||
@@ -262,7 +250,7 @@ class EventTest < ActiveSupport::TestCase | @@ -262,7 +250,7 @@ class EventTest < ActiveSupport::TestCase | ||
262 | should 'not list events out of range' do | 250 | should 'not list events out of range' do |
263 | profile = fast_create(Profile) | 251 | profile = fast_create(Profile) |
264 | 252 | ||
265 | - today = Date.today | 253 | + today = DateTime.now |
266 | event_in_range1 = build(Event, :name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 254 | event_in_range1 = build(Event, :name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
267 | event_in_range2 = build(Event, :name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day) | 255 | event_in_range2 = build(Event, :name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day) |
268 | event_out_of_range = build(Event, :name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day) | 256 | event_out_of_range = build(Event, :name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day) |
test/unit/profile_test.rb
@@ -1573,7 +1573,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1573,7 +1573,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1573 | should 'list events by day' do | 1573 | should 'list events by day' do |
1574 | profile = fast_create(Profile) | 1574 | profile = fast_create(Profile) |
1575 | 1575 | ||
1576 | - today = Date.today | 1576 | + today = DateTime.now |
1577 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) | 1577 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) |
1578 | today_event = Event.new(:name => 'Ze Birthday', :start_date => today) | 1578 | today_event = Event.new(:name => 'Ze Birthday', :start_date => today) |
1579 | tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day) | 1579 | tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day) |
@@ -1599,7 +1599,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1599,7 +1599,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1599 | should 'list events in a range' do | 1599 | should 'list events in a range' do |
1600 | profile = fast_create(Profile) | 1600 | profile = fast_create(Profile) |
1601 | 1601 | ||
1602 | - today = Date.today | 1602 | + today = DateTime.now |
1603 | event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 1603 | event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
1604 | event_in_day = Event.new(:name => 'Ze Birthday', :start_date => today) | 1604 | event_in_day = Event.new(:name => 'Ze Birthday', :start_date => today) |
1605 | 1605 |