Commit fdf745228a50447a5fd3e22d1f76b5b131c94873
Exists in
master
and in
29 other branches
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
Showing
22 changed files
with
205 additions
and
183 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/content_viewer_helper.rb
@@ -51,7 +51,7 @@ module ContentViewerHelper | @@ -51,7 +51,7 @@ module ContentViewerHelper | ||
51 | elsif date_format == 'past_time' | 51 | elsif date_format == 'past_time' |
52 | left_time = true | 52 | left_time = true |
53 | end | 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 | end | 55 | end |
56 | 56 | ||
57 | def link_to_comments(article, args = {}) | 57 | def link_to_comments(article, args = {}) |
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 | ||
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 | 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 |
@@ -72,8 +77,8 @@ module DatesHelper | @@ -72,8 +77,8 @@ module DatesHelper | ||
72 | end | 77 | end |
73 | else | 78 | else |
74 | _('from %{date1} to %{date2}') % { | 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 | end | 83 | end |
79 | end | 84 | end |
@@ -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/helpers/forms_helper.rb
@@ -151,7 +151,7 @@ module FormsHelper | @@ -151,7 +151,7 @@ module FormsHelper | ||
151 | datepicker_options[:close_text] ||= _('Done') | 151 | datepicker_options[:close_text] ||= _('Done') |
152 | datepicker_options[:constrain_input] ||= true | 152 | datepicker_options[:constrain_input] ||= true |
153 | datepicker_options[:current_text] ||= _('Today') | 153 | datepicker_options[:current_text] ||= _('Today') |
154 | - datepicker_options[:date_format] ||= 'mm/dd/yy' | 154 | + datepicker_options[:date_format] ||= 'yy/mm/dd' |
155 | datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] | 155 | datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] |
156 | datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')] | 156 | datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')] |
157 | datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')] | 157 | datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')] |
@@ -236,7 +236,7 @@ module FormsHelper | @@ -236,7 +236,7 @@ module FormsHelper | ||
236 | weekHeader: #{datepicker_options[:week_header].to_json}, | 236 | weekHeader: #{datepicker_options[:week_header].to_json}, |
237 | yearRange: #{datepicker_options[:year_range].to_json}, | 237 | yearRange: #{datepicker_options[:year_range].to_json}, |
238 | yearSuffix: #{datepicker_options[:year_suffix].to_json} | 238 | yearSuffix: #{datepicker_options[:year_suffix].to_json} |
239 | - }) | 239 | + }).datepicker('setDate', new Date('#{value}')) |
240 | </script> | 240 | </script> |
241 | ".html_safe | 241 | ".html_safe |
242 | result | 242 | result |
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 |
@@ -114,7 +114,7 @@ class Event < Article | @@ -114,7 +114,7 @@ class Event < Article | ||
114 | end | 114 | end |
115 | 115 | ||
116 | def duration | 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 | end | 118 | end |
119 | 119 | ||
120 | alias_method :article_lead, :lead | 120 | alias_method :article_lead, :lead |
app/views/cms/_event.html.erb
@@ -8,9 +8,8 @@ | @@ -8,9 +8,8 @@ | ||
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 | +<%= 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 | <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> | 14 | <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> |
16 | 15 |
app/views/content_viewer/_publishing_info.html.erb
1 | <span class="publishing-info"> | 1 | <span class="publishing-info"> |
2 | <span class="date"> | 2 | <span class="date"> |
3 | - <%= show_date(@page.published_at) %> | 3 | + <%= show_time(@page.published_at) %> |
4 | </span> | 4 | </span> |
5 | <span class="author"> | 5 | <span class="author"> |
6 | <%= _(", by %s") % (@page.author ? link_to(@page.author_name, @page.author_url) : @page.author_name) %> | 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 @@ | @@ -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 < Folder | @@ -29,8 +29,8 @@ class CommunityTrackPlugin::Step < Folder | ||
29 | 29 | ||
30 | def initialize(*args) | 30 | def initialize(*args) |
31 | super(*args) | 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 | end | 34 | end |
35 | 35 | ||
36 | def set_hidden_position | 36 | def set_hidden_position |
@@ -72,20 +72,20 @@ class CommunityTrackPlugin::Step < Folder | @@ -72,20 +72,20 @@ class CommunityTrackPlugin::Step < Folder | ||
72 | end | 72 | end |
73 | 73 | ||
74 | def active? | 74 | def active? |
75 | - (start_date..end_date).include?(Date.today) | 75 | + (start_date..end_date).cover?(DateTime.now) |
76 | end | 76 | end |
77 | 77 | ||
78 | def finished? | 78 | def finished? |
79 | - Date.today > end_date | 79 | + DateTime.now > end_date |
80 | end | 80 | end |
81 | 81 | ||
82 | def waiting? | 82 | def waiting? |
83 | - Date.today < start_date | 83 | + DateTime.now < start_date |
84 | end | 84 | end |
85 | 85 | ||
86 | def schedule_activation | 86 | def schedule_activation |
87 | return if !changes['start_date'] && !changes['end_date'] | 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 | schedule_date = !accept_comments ? start_date : end_date + 1.day | 89 | schedule_date = !accept_comments ? start_date : end_date + 1.day |
90 | CommunityTrackPlugin::ActivationJob.find(id).destroy_all | 90 | CommunityTrackPlugin::ActivationJob.find(id).destroy_all |
91 | Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), :run_at => schedule_date) | 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 < ActionController::TestCase | @@ -6,7 +6,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
6 | def setup | 6 | def setup |
7 | @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community') | 7 | @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community') |
8 | @track = create_track('track', @profile) | 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 | user = create_user('testinguser') | 11 | user = create_user('testinguser') |
12 | login_as(user.login) | 12 | login_as(user.login) |
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -9,7 +9,7 @@ class StepTest < ActiveSupport::TestCase | @@ -9,7 +9,7 @@ class StepTest < ActiveSupport::TestCase | ||
9 | @track.add_category(@category) | 9 | @track.add_category(@category) |
10 | @track.save! | 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 | Delayed::Job.destroy_all | 13 | Delayed::Job.destroy_all |
14 | end | 14 | end |
15 | 15 | ||
@@ -22,39 +22,39 @@ class StepTest < ActiveSupport::TestCase | @@ -22,39 +22,39 @@ class StepTest < ActiveSupport::TestCase | ||
22 | end | 22 | end |
23 | 23 | ||
24 | should 'set accept_comments to false on create' do | 24 | should 'set accept_comments to false on create' do |
25 | - today = Date.today | 25 | + today = DateTime.now |
26 | step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) | 26 | step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) |
27 | refute step.accept_comments | 27 | refute step.accept_comments |
28 | end | 28 | end |
29 | 29 | ||
30 | should 'do not allow step creation with a parent that is not a track' do | 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 | blog = fast_create(Blog) | 32 | blog = fast_create(Blog) |
33 | step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) | 33 | step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) |
34 | refute step.save | 34 | refute step.save |
35 | end | 35 | end |
36 | 36 | ||
37 | should 'do not allow step creation without a parent' do | 37 | should 'do not allow step creation without a parent' do |
38 | - today = Date.today | 38 | + today = DateTime.now |
39 | step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true) | 39 | step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true) |
40 | refute step.save | 40 | refute step.save |
41 | end | 41 | end |
42 | 42 | ||
43 | should 'create step if end date is equal to start date' do | 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 | assert @step.save | 46 | assert @step.save |
47 | end | 47 | end |
48 | 48 | ||
49 | should 'create step if end date is after start date' do | 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 | assert @step.save | 52 | assert @step.save |
53 | end | 53 | end |
54 | 54 | ||
55 | should 'do not create step if end date is before start date' do | 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 | refute @step.save | 58 | refute @step.save |
59 | end | 59 | end |
60 | 60 | ||
@@ -71,20 +71,20 @@ class StepTest < ActiveSupport::TestCase | @@ -71,20 +71,20 @@ class StepTest < ActiveSupport::TestCase | ||
71 | end | 71 | end |
72 | 72 | ||
73 | should 'be active if today is between start and end dates' do | 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 | assert @step.active? | 76 | assert @step.active? |
77 | end | 77 | end |
78 | 78 | ||
79 | should 'be finished if today is after the end date' do | 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 | assert @step.finished? | 82 | assert @step.finished? |
83 | end | 83 | end |
84 | 84 | ||
85 | should 'be waiting if today is before the end date' do | 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 | assert @step.waiting? | 88 | assert @step.waiting? |
89 | end | 89 | end |
90 | 90 | ||
@@ -95,17 +95,17 @@ class StepTest < ActiveSupport::TestCase | @@ -95,17 +95,17 @@ class StepTest < ActiveSupport::TestCase | ||
95 | end | 95 | end |
96 | 96 | ||
97 | should 'create delayed job' do | 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 | @step.accept_comments = false | 100 | @step.accept_comments = false |
101 | @step.schedule_activation | 101 | @step.schedule_activation |
102 | assert_equal 1, Delayed::Job.count | 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 | end | 104 | end |
105 | 105 | ||
106 | should 'do not duplicate delayed job' do | 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 | @step.schedule_activation | 109 | @step.schedule_activation |
110 | assert_equal 1, Delayed::Job.count | 110 | assert_equal 1, Delayed::Job.count |
111 | @step.schedule_activation | 111 | @step.schedule_activation |
@@ -113,30 +113,30 @@ class StepTest < ActiveSupport::TestCase | @@ -113,30 +113,30 @@ class StepTest < ActiveSupport::TestCase | ||
113 | end | 113 | end |
114 | 114 | ||
115 | should 'create delayed job when a step is saved' do | 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 | @step.save! | 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 | end | 120 | end |
121 | 121 | ||
122 | should 'create delayed job even if start date has passed' do | 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 | @step.accept_comments = false | 125 | @step.accept_comments = false |
126 | @step.schedule_activation | 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 | end | 128 | end |
129 | 129 | ||
130 | should 'create delayed job if end date has passed' do | 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 | @step.schedule_activation | 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 | end | 135 | end |
136 | 136 | ||
137 | should 'do not schedule delayed job if save but do not modify date fields' do | 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 | @step.save! | 140 | @step.save! |
141 | assert_equal 1, Delayed::Job.count | 141 | assert_equal 1, Delayed::Job.count |
142 | Delayed::Job.destroy_all | 142 | Delayed::Job.destroy_all |
@@ -149,13 +149,13 @@ class StepTest < ActiveSupport::TestCase | @@ -149,13 +149,13 @@ class StepTest < ActiveSupport::TestCase | ||
149 | refute @step.position | 149 | refute @step.position |
150 | @step.save! | 150 | @step.save! |
151 | assert_equal 1, @step.position | 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 | step2.save! | 153 | step2.save! |
154 | assert_equal 2, step2.position | 154 | assert_equal 2, step2.position |
155 | end | 155 | end |
156 | 156 | ||
157 | should 'accept comments if step is active' do | 157 | should 'accept comments if step is active' do |
158 | - @step.start_date = Date.today | 158 | + @step.start_date = DateTime.now |
159 | @step.save! | 159 | @step.save! |
160 | refute @step.accept_comments | 160 | refute @step.accept_comments |
161 | @step.toggle_activation | 161 | @step.toggle_activation |
@@ -164,8 +164,8 @@ class StepTest < ActiveSupport::TestCase | @@ -164,8 +164,8 @@ class StepTest < ActiveSupport::TestCase | ||
164 | end | 164 | end |
165 | 165 | ||
166 | should 'do not accept comments if step is not active' do | 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 | @step.save! | 169 | @step.save! |
170 | refute @step.published | 170 | refute @step.published |
171 | @step.toggle_activation | 171 | @step.toggle_activation |
@@ -174,14 +174,14 @@ class StepTest < ActiveSupport::TestCase | @@ -174,14 +174,14 @@ class StepTest < ActiveSupport::TestCase | ||
174 | end | 174 | end |
175 | 175 | ||
176 | should 'do not accept comments if step is not active anymore' do | 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 | @step.save! | 178 | @step.save! |
179 | @step.toggle_activation | 179 | @step.toggle_activation |
180 | @step.reload | 180 | @step.reload |
181 | assert @step.accept_comments | 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 | @step.save! | 185 | @step.save! |
186 | @step.toggle_activation | 186 | @step.toggle_activation |
187 | @step.reload | 187 | @step.reload |
@@ -203,7 +203,7 @@ class StepTest < ActiveSupport::TestCase | @@ -203,7 +203,7 @@ class StepTest < ActiveSupport::TestCase | ||
203 | end | 203 | end |
204 | 204 | ||
205 | should 'change position to botton if a hidden step becomes visible' do | 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 | step1.save! | 207 | step1.save! |
208 | @step.hidden = true | 208 | @step.hidden = true |
209 | @step.save! | 209 | @step.save! |
@@ -215,7 +215,7 @@ class StepTest < ActiveSupport::TestCase | @@ -215,7 +215,7 @@ class StepTest < ActiveSupport::TestCase | ||
215 | 215 | ||
216 | should 'decrement lower items positions if a step becomes hidden' do | 216 | should 'decrement lower items positions if a step becomes hidden' do |
217 | @step.save! | 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 | step1.save! | 219 | step1.save! |
220 | assert_equal 2, step1.position | 220 | assert_equal 2, step1.position |
221 | @step.hidden = true | 221 | @step.hidden = true |
@@ -225,7 +225,7 @@ class StepTest < ActiveSupport::TestCase | @@ -225,7 +225,7 @@ class StepTest < ActiveSupport::TestCase | ||
225 | end | 225 | end |
226 | 226 | ||
227 | should 'do not publish a hidden step' do | 227 | should 'do not publish a hidden step' do |
228 | - @step.start_date = Date.today | 228 | + @step.start_date = DateTime.now |
229 | @step.hidden = true | 229 | @step.hidden = true |
230 | @step.save! | 230 | @step.save! |
231 | refute @step.published | 231 | refute @step.published |
@@ -266,7 +266,7 @@ class StepTest < ActiveSupport::TestCase | @@ -266,7 +266,7 @@ class StepTest < ActiveSupport::TestCase | ||
266 | end | 266 | end |
267 | 267 | ||
268 | should 'enable comments on children when step is activated' do | 268 | should 'enable comments on children when step is activated' do |
269 | - @step.start_date = Date.today | 269 | + @step.start_date = DateTime.now |
270 | @step.save! | 270 | @step.save! |
271 | refute @step.accept_comments | 271 | refute @step.accept_comments |
272 | article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false) | 272 | article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false) |
@@ -276,8 +276,7 @@ class StepTest < ActiveSupport::TestCase | @@ -276,8 +276,7 @@ class StepTest < ActiveSupport::TestCase | ||
276 | end | 276 | end |
277 | 277 | ||
278 | should 'enable comments on children when step is active' do | 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 | @step.save! | 280 | @step.save! |
282 | refute @step.accept_comments | 281 | refute @step.accept_comments |
283 | @step.toggle_activation | 282 | @step.toggle_activation |
plugins/event/lib/event_plugin/event_block.rb
@@ -30,13 +30,13 @@ class EventPlugin::EventBlock < Block | @@ -30,13 +30,13 @@ class EventPlugin::EventBlock < Block | ||
30 | events = user.nil? ? events.public : events.display_filter(user,nil) | 30 | events = user.nil? ? events.public : events.display_filter(user,nil) |
31 | 31 | ||
32 | if future_only | 32 | if future_only |
33 | - events = events.where('start_date >= ?', Date.today) | 33 | + events = events.where('start_date >= ?', DateTime.now.beginning_of_day) |
34 | end | 34 | end |
35 | 35 | ||
36 | if date_distance_limit > 0 | 36 | if date_distance_limit > 0 |
37 | events = events.by_range([ | 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 | end | 41 | end |
42 | 42 |
plugins/event/test/functional/event_block_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | ||
3 | + | ||
3 | # Re-raise errors caught by the controller. | 4 | # Re-raise errors caught by the controller. |
4 | class HomeController | 5 | class HomeController |
5 | - #append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 6 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
6 | def rescue_action(e) | 7 | def rescue_action(e) |
7 | raise e | 8 | raise e |
8 | end | 9 | end |
@@ -15,7 +16,7 @@ class HomeControllerTest < ActionController::TestCase | @@ -15,7 +16,7 @@ class HomeControllerTest < ActionController::TestCase | ||
15 | @env.enable_plugin('EventPlugin') | 16 | @env.enable_plugin('EventPlugin') |
16 | 17 | ||
17 | @p1 = fast_create(Person, :environment_id => @env.id) | 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 | box = Box.create!(:owner => @env) | 21 | box = Box.create!(:owner => @env) |
21 | @block = EventPlugin::EventBlock.create!(:box => box) | 22 | @block = EventPlugin::EventBlock.create!(:box => box) |
@@ -27,6 +28,7 @@ class HomeControllerTest < ActionController::TestCase | @@ -27,6 +28,7 @@ class HomeControllerTest < ActionController::TestCase | ||
27 | 28 | ||
28 | should 'see events microdata sturcture' do | 29 | should 'see events microdata sturcture' do |
29 | get :index | 30 | get :index |
31 | +#raise response.body.inspect | ||
30 | assert_select '.event-plugin_event-block ul.events' | 32 | assert_select '.event-plugin_event-block ul.events' |
31 | assert_select ev | 33 | assert_select ev |
32 | assert_select ev + 'a[itemprop="url"]' | 34 | assert_select ev + 'a[itemprop="url"]' |
@@ -41,15 +43,15 @@ class HomeControllerTest < ActionController::TestCase | @@ -41,15 +43,15 @@ class HomeControllerTest < ActionController::TestCase | ||
41 | 43 | ||
42 | should 'see event duration' do | 44 | should 'see event duration' do |
43 | @e1a.slug = 'event1a' | 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 | @e1a.save! | 48 | @e1a.save! |
47 | get :index | 49 | get :index |
48 | assert_select ev + 'time.duration[itemprop="endDate"]', /1 day/ | 50 | assert_select ev + 'time.duration[itemprop="endDate"]', /1 day/ |
49 | 51 | ||
50 | @e1a.slug = 'event1a' | 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 | @e1a.save! | 55 | @e1a.save! |
54 | get :index | 56 | get :index |
55 | assert_select ev + 'time.duration[itemprop="endDate"]', /2 days/ | 57 | assert_select ev + 'time.duration[itemprop="endDate"]', /2 days/ |
@@ -60,8 +62,8 @@ class HomeControllerTest < ActionController::TestCase | @@ -60,8 +62,8 @@ class HomeControllerTest < ActionController::TestCase | ||
60 | assert_select ev + 'time.duration[itemprop="endDate"]', false | 62 | assert_select ev + 'time.duration[itemprop="endDate"]', false |
61 | 63 | ||
62 | @e1a.slug = 'event1a' | 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 | @e1a.save! | 67 | @e1a.save! |
66 | get :index | 68 | get :index |
67 | assert_select ev + 'time.duration[itemprop="endDate"]', false | 69 | assert_select ev + 'time.duration[itemprop="endDate"]', false |
plugins/event/views/blocks/event.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | <ul class="events"> | 3 | <ul class="events"> |
4 | <% block.events(user).map do |event| %> | 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 | <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Event" class="event"> | 6 | <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Event" class="event"> |
7 | <%= render( | 7 | <%= render( |
8 | :file => 'event_plugin/event_block_item', | 8 | :file => 'event_plugin/event_block_item', |
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/content_viewer_helper_test.rb
@@ -16,14 +16,14 @@ class ContentViewerHelperTest < ActionView::TestCase | @@ -16,14 +16,14 @@ class ContentViewerHelperTest < ActionView::TestCase | ||
16 | blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | 16 | blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) |
17 | post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog) | 17 | post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog) |
18 | result = article_title(post) | 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 | end | 20 | end |
21 | 21 | ||
22 | should 'display published-at for forum posts' do | 22 | should 'display published-at for forum posts' do |
23 | forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id) | 23 | forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id) |
24 | post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => forum) | 24 | post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => forum) |
25 | result = article_title(post) | 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 | end | 27 | end |
28 | 28 | ||
29 | should 'not display published-at for non-blog and non-forum posts' do | 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 < ActiveSupport::TestCase | @@ -21,23 +21,23 @@ class DatesHelperTest < ActiveSupport::TestCase | ||
21 | should 'generate period with two dates' do | 21 | should 'generate period with two dates' do |
22 | date1 = mock | 22 | date1 = mock |
23 | date1.stubs(:year).returns('A') | 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 | date2 = mock | 25 | date2 = mock |
26 | date2.stubs(:year).returns('B') | 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 | expects(:_).with('from %{date1} to %{date2}').returns('from %{date1} to %{date2}') | 28 | expects(:_).with('from %{date1} to %{date2}').returns('from %{date1} to %{date2}') |
29 | assert_equal 'from XXX to YYY', show_period(date1, date2) | 29 | assert_equal 'from XXX to YYY', show_period(date1, date2) |
30 | end | 30 | end |
31 | 31 | ||
32 | should 'generate period with in two diferent years' do | 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 | end | 36 | end |
37 | 37 | ||
38 | should 'generate period with in two diferent months of the same year' do | 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 | assert_equal 'from February 1 to March 1, 2013', show_period(date1, date2) | 41 | assert_equal 'from February 1 to March 1, 2013', show_period(date1, date2) |
42 | end | 42 | end |
43 | 43 | ||
@@ -49,13 +49,13 @@ class DatesHelperTest < ActiveSupport::TestCase | @@ -49,13 +49,13 @@ class DatesHelperTest < ActiveSupport::TestCase | ||
49 | 49 | ||
50 | should 'generate period with two equal dates' do | 50 | should 'generate period with two equal dates' do |
51 | date1 = mock | 51 | date1 = mock |
52 | - expects(:show_date).with(date1, anything).returns('XXX') | 52 | + expects(:show_time).with(date1, anything).returns('XXX') |
53 | assert_equal 'XXX', show_period(date1, date1) | 53 | assert_equal 'XXX', show_period(date1, date1) |
54 | end | 54 | end |
55 | 55 | ||
56 | should 'generate period with one date only' do | 56 | should 'generate period with one date only' do |
57 | date1 = mock | 57 | date1 = mock |
58 | - expects(:show_date).with(date1, anything).returns('XXX') | 58 | + expects(:show_time).with(date1, anything).returns('XXX') |
59 | assert_equal 'XXX', show_period(date1) | 59 | assert_equal 'XXX', show_period(date1) |
60 | end | 60 | end |
61 | 61 | ||
@@ -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 |
@@ -118,16 +118,16 @@ class DatesHelperTest < ActiveSupport::TestCase | @@ -118,16 +118,16 @@ class DatesHelperTest < ActiveSupport::TestCase | ||
118 | end | 118 | end |
119 | 119 | ||
120 | should 'format time' do | 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 | end | 122 | end |
123 | 123 | ||
124 | should 'format time with 2 digits minutes' do | 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 | end | 126 | end |
127 | 127 | ||
128 | should 'translate time' do | 128 | should 'translate time' do |
129 | time = Time.parse('25 May 2009, 12:47') | 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 | end | 131 | end |
132 | 132 | ||
133 | should 'handle nil time' do | 133 | should 'handle nil time' do |
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,33 @@ class EventTest < ActiveSupport::TestCase | @@ -84,32 +72,33 @@ 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 | + 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 | display = instance_eval(&event.to_html) | 102 | display = instance_eval(&event.to_html) |
114 | 103 | ||
115 | assert_tag_in_string display, :content => Regexp.new("January 1, 2008") | 104 | assert_tag_in_string display, :content => Regexp.new("January 1, 2008") |
@@ -148,7 +137,7 @@ class EventTest < ActiveSupport::TestCase | @@ -148,7 +137,7 @@ class EventTest < ActiveSupport::TestCase | ||
148 | profile = create_user('testuser').person | 137 | profile = create_user('testuser').person |
149 | event = create(Event, :profile => profile, :name => 'test', | 138 | event = create(Event, :profile => profile, :name => 'test', |
150 | :body => '<p>first paragraph </p><p>second paragraph </p>', | 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 | assert_match '<p>first paragraph </p>', event.first_paragraph | 142 | assert_match '<p>first paragraph </p>', event.first_paragraph |
154 | end | 143 | end |
@@ -161,7 +150,7 @@ class EventTest < ActiveSupport::TestCase | @@ -161,7 +150,7 @@ class EventTest < ActiveSupport::TestCase | ||
161 | 150 | ||
162 | should 'filter HTML in body' do | 151 | should 'filter HTML in body' do |
163 | profile = create_user('testuser').person | 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 | assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)' | 155 | assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)' |
167 | assert_no_tag_in_string e.body, :tag => 'script' | 156 | assert_no_tag_in_string e.body, :tag => 'script' |
@@ -169,7 +158,7 @@ class EventTest < ActiveSupport::TestCase | @@ -169,7 +158,7 @@ class EventTest < ActiveSupport::TestCase | ||
169 | 158 | ||
170 | should 'filter HTML in name' do | 159 | should 'filter HTML in name' do |
171 | profile = create_user('testuser').person | 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 | assert_tag_in_string e.name, :tag => 'p', :content => 'a paragraph (valid)' | 163 | assert_tag_in_string e.name, :tag => 'p', :content => 'a paragraph (valid)' |
175 | assert_no_tag_in_string e.name, :tag => 'script' | 164 | assert_no_tag_in_string e.name, :tag => 'script' |
@@ -184,8 +173,8 @@ class EventTest < ActiveSupport::TestCase | @@ -184,8 +173,8 @@ class EventTest < ActiveSupport::TestCase | ||
184 | 173 | ||
185 | should 'list all events' do | 174 | should 'list all events' do |
186 | profile = fast_create(Profile) | 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 | profile.events << [event1, event2] | 178 | profile.events << [event1, event2] |
190 | assert_includes profile.events, event1 | 179 | assert_includes profile.events, event1 |
191 | assert_includes profile.events, event2 | 180 | assert_includes profile.events, event2 |
@@ -194,7 +183,7 @@ class EventTest < ActiveSupport::TestCase | @@ -194,7 +183,7 @@ class EventTest < ActiveSupport::TestCase | ||
194 | should 'list events by day' do | 183 | should 'list events by day' do |
195 | profile = fast_create(Profile) | 184 | profile = fast_create(Profile) |
196 | 185 | ||
197 | - today = Date.today | 186 | + today = DateTime.now |
198 | yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day) | 187 | yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day) |
199 | today_event = build(Event, :name => 'Ze Birthday', :start_date => today) | 188 | today_event = build(Event, :name => 'Ze Birthday', :start_date => today) |
200 | tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day) | 189 | tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day) |
@@ -207,7 +196,7 @@ class EventTest < ActiveSupport::TestCase | @@ -207,7 +196,7 @@ class EventTest < ActiveSupport::TestCase | ||
207 | should 'list events by month' do | 196 | should 'list events by month' do |
208 | profile = fast_create(Profile) | 197 | profile = fast_create(Profile) |
209 | 198 | ||
210 | - today = Date.new(2013, 10, 6) | 199 | + today = DateTime.new(2013, 10, 6) |
211 | 200 | ||
212 | last_month_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.month) | 201 | last_month_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.month) |
213 | 202 | ||
@@ -230,7 +219,7 @@ class EventTest < ActiveSupport::TestCase | @@ -230,7 +219,7 @@ class EventTest < ActiveSupport::TestCase | ||
230 | should 'event by month ordered by start date'do | 219 | should 'event by month ordered by start date'do |
231 | profile = fast_create(Profile) | 220 | profile = fast_create(Profile) |
232 | 221 | ||
233 | - today = Date.new(2013, 10, 6) | 222 | + today = DateTime.new(2013, 10, 6) |
234 | 223 | ||
235 | event_1 = Event.new(:name => 'Maria Birthday', :start_date => today + 1.day) | 224 | 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) | 225 | event_2 = Event.new(:name => 'Joana Birthday', :start_date => today - 1.day) |
@@ -248,7 +237,7 @@ class EventTest < ActiveSupport::TestCase | @@ -248,7 +237,7 @@ class EventTest < ActiveSupport::TestCase | ||
248 | should 'list events in a range' do | 237 | should 'list events in a range' do |
249 | profile = fast_create(Profile) | 238 | profile = fast_create(Profile) |
250 | 239 | ||
251 | - today = Date.today | 240 | + today = DateTime.now |
252 | event_in_range = build(Event, :name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 241 | 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) | 242 | event_in_day = build(Event, :name => 'Ze Birthday', :start_date => today) |
254 | 243 | ||
@@ -262,7 +251,7 @@ class EventTest < ActiveSupport::TestCase | @@ -262,7 +251,7 @@ class EventTest < ActiveSupport::TestCase | ||
262 | should 'not list events out of range' do | 251 | should 'not list events out of range' do |
263 | profile = fast_create(Profile) | 252 | profile = fast_create(Profile) |
264 | 253 | ||
265 | - today = Date.today | 254 | + today = DateTime.now |
266 | event_in_range1 = build(Event, :name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 255 | 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) | 256 | 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) | 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 < ActiveSupport::TestCase | @@ -1563,8 +1563,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
1563 | 1563 | ||
1564 | should 'list all events' do | 1564 | should 'list all events' do |
1565 | profile = fast_create(Profile) | 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 | profile.events << [event1, event2] | 1568 | profile.events << [event1, event2] |
1569 | assert_includes profile.events, event1 | 1569 | assert_includes profile.events, event1 |
1570 | assert_includes profile.events, event2 | 1570 | assert_includes profile.events, event2 |
@@ -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) |
@@ -1586,7 +1586,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1586,7 +1586,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1586 | should 'list events by month' do | 1586 | should 'list events by month' do |
1587 | profile = fast_create(Profile) | 1587 | profile = fast_create(Profile) |
1588 | 1588 | ||
1589 | - today = Date.new(2014, 03, 2) | 1589 | + today = DateTime.new(2014, 03, 2) |
1590 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) | 1590 | yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) |
1591 | today_event = Event.new(:name => 'Ze Birthday', :start_date => today) | 1591 | today_event = Event.new(:name => 'Ze Birthday', :start_date => today) |
1592 | tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day) | 1592 | 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 | ||
@@ -1613,7 +1613,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1613,7 +1613,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1613 | should 'not list events out of range' do | 1613 | should 'not list events out of range' do |
1614 | profile = fast_create(Profile) | 1614 | profile = fast_create(Profile) |
1615 | 1615 | ||
1616 | - today = Date.today | 1616 | + today = DateTime.now |
1617 | event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) | 1617 | event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) |
1618 | event_in_range2 = Event.new(:name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day) | 1618 | event_in_range2 = Event.new(:name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day) |
1619 | event_out_of_range = Event.new(:name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day) | 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 < ActiveSupport::TestCase | @@ -1627,9 +1627,9 @@ class ProfileTest < ActiveSupport::TestCase | ||
1627 | 1627 | ||
1628 | should 'sort events by date' do | 1628 | should 'sort events by date' do |
1629 | profile = fast_create(Profile) | 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 | profile.events << [event1, event2, event3] | 1633 | profile.events << [event1, event2, event3] |
1634 | assert_equal [event2, event1, event3], profile.events | 1634 | assert_equal [event2, event1, event3], profile.events |
1635 | end | 1635 | end |