Commit 08bbc6ffead4b90b31ab220f1eee9d672c6e0aeb
1 parent
c2f481ce
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 | 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/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 | |
| 46 | + def show_time(time, use_numbers = true, year = true, left_time = false) | |
| 47 | + if time && use_numbers | |
| 48 | 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 | 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 |
| ... | ... | @@ -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/models/event.rb
| ... | ... | @@ -23,7 +23,7 @@ class Event < 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 < 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 < 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 < 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 | ... | ... |
app/views/cms/_event.html.erb
| ... | ... | @@ -8,9 +8,9 @@ |
| 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 | +<%= 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 | 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 @@ |
| 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.css
| ... | ... | @@ -1502,7 +1502,8 @@ table#recaptcha_table tr:hover td { |
| 1502 | 1502 | |
| 1503 | 1503 | .event-date { |
| 1504 | 1504 | background: url('/images/calendar_date_select/calendar-icon.png') no-repeat left center; |
| 1505 | - padding: 5px; | |
| 1505 | + padding: 2px; | |
| 1506 | + padding-left: 15px; | |
| 1506 | 1507 | } |
| 1507 | 1508 | |
| 1508 | 1509 | .event-link { | ... | ... |
test/functional/events_controller_test.rb
| ... | ... | @@ -8,12 +8,12 @@ class EventsControllerTest < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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/dates_helper_test.rb
| ... | ... | @@ -84,7 +84,7 @@ class DatesHelperTest < 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 | ... | ... |
test/unit/event_test.rb
| ... | ... | @@ -29,15 +29,9 @@ class EventTest < 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 < 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 | assert !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 | assert !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,32 @@ class EventTest < 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 | + 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 | 101 | display = instance_eval(&event.to_html) |
| 114 | 102 | |
| 115 | 103 | assert_tag_in_string display, :content => Regexp.new("January 1, 2008") |
| ... | ... | @@ -148,7 +136,7 @@ class EventTest < ActiveSupport::TestCase |
| 148 | 136 | profile = create_user('testuser').person |
| 149 | 137 | event = create(Event, :profile => profile, :name => 'test', |
| 150 | 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 | 141 | assert_match '<p>first paragraph </p>', event.first_paragraph |
| 154 | 142 | end |
| ... | ... | @@ -161,7 +149,7 @@ class EventTest < ActiveSupport::TestCase |
| 161 | 149 | |
| 162 | 150 | should 'filter HTML in body' do |
| 163 | 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 | 154 | assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)' |
| 167 | 155 | assert_no_tag_in_string e.body, :tag => 'script' |
| ... | ... | @@ -169,7 +157,7 @@ class EventTest < ActiveSupport::TestCase |
| 169 | 157 | |
| 170 | 158 | should 'filter HTML in name' do |
| 171 | 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 | 162 | assert_tag_in_string e.name, :tag => 'p', :content => 'a paragraph (valid)' |
| 175 | 163 | assert_no_tag_in_string e.name, :tag => 'script' |
| ... | ... | @@ -184,8 +172,8 @@ class EventTest < ActiveSupport::TestCase |
| 184 | 172 | |
| 185 | 173 | should 'list all events' do |
| 186 | 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 | 177 | profile.events << [event1, event2] |
| 190 | 178 | assert_includes profile.events, event1 |
| 191 | 179 | assert_includes profile.events, event2 |
| ... | ... | @@ -194,7 +182,7 @@ class EventTest < ActiveSupport::TestCase |
| 194 | 182 | should 'list events by day' do |
| 195 | 183 | profile = fast_create(Profile) |
| 196 | 184 | |
| 197 | - today = Date.today | |
| 185 | + today = DateTime.now | |
| 198 | 186 | yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day) |
| 199 | 187 | today_event = build(Event, :name => 'Ze Birthday', :start_date => today) |
| 200 | 188 | tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day) |
| ... | ... | @@ -207,7 +195,7 @@ class EventTest < ActiveSupport::TestCase |
| 207 | 195 | should 'list events by month' do |
| 208 | 196 | profile = fast_create(Profile) |
| 209 | 197 | |
| 210 | - today = Date.new(2013, 10, 6) | |
| 198 | + today = DateTime.new(2013, 10, 6) | |
| 211 | 199 | |
| 212 | 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 | 218 | should 'event by month ordered by start date'do |
| 231 | 219 | profile = fast_create(Profile) |
| 232 | 220 | |
| 233 | - today = Date.new(2013, 10, 6) | |
| 221 | + today = DateTime.new(2013, 10, 6) | |
| 234 | 222 | |
| 235 | 223 | event_1 = Event.new(:name => 'Maria Birthday', :start_date => today + 1.day) |
| 236 | 224 | event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day) |
| ... | ... | @@ -248,7 +236,7 @@ class EventTest < ActiveSupport::TestCase |
| 248 | 236 | should 'list events in a range' do |
| 249 | 237 | profile = fast_create(Profile) |
| 250 | 238 | |
| 251 | - today = Date.today | |
| 239 | + today = DateTime.now | |
| 252 | 240 | event_in_range = build(Event, :name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
| 253 | 241 | event_in_day = build(Event, :name => 'Ze Birthday', :start_date => today) |
| 254 | 242 | |
| ... | ... | @@ -262,7 +250,7 @@ class EventTest < ActiveSupport::TestCase |
| 262 | 250 | should 'not list events out of range' do |
| 263 | 251 | profile = fast_create(Profile) |
| 264 | 252 | |
| 265 | - today = Date.today | |
| 253 | + today = DateTime.now | |
| 266 | 254 | event_in_range1 = build(Event, :name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
| 267 | 255 | event_in_range2 = build(Event, :name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day) |
| 268 | 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 | 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) |
| ... | ... | @@ -1599,7 +1599,7 @@ class ProfileTest < 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 | ... | ... |