Commit a8fd5395008cab3076c455838a746177b4f11daa
1 parent
4a051199
Exists in
master
and in
6 other branches
fixing event plugin tests
Showing
4 changed files
with
15 additions
and
13 deletions
Show diff stats
app/models/event.rb
... | ... | @@ -114,7 +114,7 @@ class Event < Article |
114 | 114 | end |
115 | 115 | |
116 | 116 | def duration |
117 | - ((self.end_date || self.start_date) - self.start_date).to_i | |
117 | + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) | |
118 | 118 | end |
119 | 119 | |
120 | 120 | alias_method :article_lead, :lead | ... | ... |
plugins/event/lib/event_plugin/event_block.rb
... | ... | @@ -30,13 +30,13 @@ class EventPlugin::EventBlock < Block |
30 | 30 | events = user.nil? ? events.public : events.display_filter(user,nil) |
31 | 31 | |
32 | 32 | if future_only |
33 | - events = events.where('start_date >= ?', Date.today) | |
33 | + events = events.where('start_date >= ?', DateTime.now.beginning_of_day) | |
34 | 34 | end |
35 | 35 | |
36 | 36 | if date_distance_limit > 0 |
37 | 37 | events = events.by_range([ |
38 | - Date.today - date_distance_limit, | |
39 | - Date.today + date_distance_limit | |
38 | + DateTime.now.beginning_of_day - date_distance_limit, | |
39 | + DateTime.now.beginning_of_day + date_distance_limit | |
40 | 40 | ]) |
41 | 41 | end |
42 | 42 | ... | ... |
plugins/event/test/functional/event_block_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | |
3 | + | |
3 | 4 | # Re-raise errors caught by the controller. |
4 | 5 | class HomeController |
5 | - #append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
6 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
6 | 7 | def rescue_action(e) |
7 | 8 | raise e |
8 | 9 | end |
... | ... | @@ -15,7 +16,7 @@ class HomeControllerTest < ActionController::TestCase |
15 | 16 | @env.enable_plugin('EventPlugin') |
16 | 17 | |
17 | 18 | @p1 = fast_create(Person, :environment_id => @env.id) |
18 | - @e1a = fast_create(Event, :name=>'Event p1 A', :profile_id=>@p1.id) | |
19 | + @e1a = Event.create!(:name=>'Event p1 A', :profile =>@p1) | |
19 | 20 | |
20 | 21 | box = Box.create!(:owner => @env) |
21 | 22 | @block = EventPlugin::EventBlock.create!(:box => box) |
... | ... | @@ -27,6 +28,7 @@ class HomeControllerTest < ActionController::TestCase |
27 | 28 | |
28 | 29 | should 'see events microdata sturcture' do |
29 | 30 | get :index |
31 | +#raise response.body.inspect | |
30 | 32 | assert_select '.event-plugin_event-block ul.events' |
31 | 33 | assert_select ev |
32 | 34 | assert_select ev + 'a[itemprop="url"]' |
... | ... | @@ -41,15 +43,15 @@ class HomeControllerTest < ActionController::TestCase |
41 | 43 | |
42 | 44 | should 'see event duration' do |
43 | 45 | @e1a.slug = 'event1a' |
44 | - @e1a.start_date = Date.today | |
45 | - @e1a.end_date = Date.today + 1.day | |
46 | + @e1a.start_date = DateTime.now | |
47 | + @e1a.end_date = DateTime.now + 1.day | |
46 | 48 | @e1a.save! |
47 | 49 | get :index |
48 | 50 | assert_select ev + 'time.duration[itemprop="endDate"]', /1 day/ |
49 | 51 | |
50 | 52 | @e1a.slug = 'event1a' |
51 | - @e1a.start_date = Date.today | |
52 | - @e1a.end_date = Date.today + 2.day | |
53 | + @e1a.start_date = DateTime.now | |
54 | + @e1a.end_date = DateTime.now + 2.day | |
53 | 55 | @e1a.save! |
54 | 56 | get :index |
55 | 57 | assert_select ev + 'time.duration[itemprop="endDate"]', /2 days/ |
... | ... | @@ -60,8 +62,8 @@ class HomeControllerTest < ActionController::TestCase |
60 | 62 | assert_select ev + 'time.duration[itemprop="endDate"]', false |
61 | 63 | |
62 | 64 | @e1a.slug = 'event1a' |
63 | - @e1a.start_date = Date.today | |
64 | - @e1a.end_date = Date.today | |
65 | + @e1a.start_date = DateTime.now | |
66 | + @e1a.end_date = DateTime.now | |
65 | 67 | @e1a.save! |
66 | 68 | get :index |
67 | 69 | assert_select ev + 'time.duration[itemprop="endDate"]', false | ... | ... |
plugins/event/views/blocks/event.html.erb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | <ul class="events"> |
4 | 4 | <% block.events(user).map do |event| %> |
5 | - <% days_left = ( event.start_date - Date.today ).round %> | |
5 | + <% days_left = ( (event.start_date - DateTime.now)/60/60/24 ).round %> | |
6 | 6 | <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Event" class="event"> |
7 | 7 | <%= render( |
8 | 8 | :file => 'event_plugin/event_block_item', | ... | ... |