Skip to content

Commit

Permalink
Fixed condition string in Page.find so that events were found properl…
Browse files Browse the repository at this point in the history
…y in their month

Fixed nil error when no event_datetime_end was specified
Updated TODO
  • Loading branch information
mghaught committed Oct 6, 2008
1 parent f30003b commit 652c676
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion TODO
@@ -1,5 +1,4 @@
--Next Release-- --Next Release--
Fix bug on page_event tab when no end date is set
Make event fields be hidden (in popup) unless set or they click the add date icon Make event fields be hidden (in popup) unless set or they click the add date icon
Add the default time to event in calendar picker, default to top of the hour Add the default time to event in calendar picker, default to top of the hour
Have the end_date default to X time after start date (1 hour) Have the end_date default to X time after start date (1 hour)
Expand Down
2 changes: 1 addition & 1 deletion app/views/page_events/index.rhtml
Expand Up @@ -48,7 +48,7 @@ span.event_date {
<td><%= event.status.name %></td> <td><%= event.status.name %></td>
<td> <td>
<%= event.event_datetime_start.strftime("%m/%d/%Y %I:%M %p") %> <%= event.event_datetime_start.strftime("%m/%d/%Y %I:%M %p") %>
<%- if event.event_datetime_end > event.event_datetime_start -%> <%- if event.event_datetime_end && event.event_datetime_end > event.event_datetime_start -%>
&ndash;<%= event.event_datetime_end.strftime("%m/%d/%Y %I:%M %p") %> &ndash;<%= event.event_datetime_end.strftime("%m/%d/%Y %I:%M %p") %>
<%- end -%> <%- end -%>
</td> </td>
Expand Down
7 changes: 5 additions & 2 deletions lib/page_event/page_extensions.rb
Expand Up @@ -7,7 +7,8 @@ def self.included(base)
module ClassMethods module ClassMethods
def events_by_month(date = Time.now, status = nil) def events_by_month(date = Time.now, status = nil)
month_start = date.at_beginning_of_month month_start = date.at_beginning_of_month
condition_str = "event_datetime_start >= :month_start OR event_datetime_end < :month_end" condition_str = "(event_datetime_start >= :month_start AND event_datetime_start < :month_end)"
condition_str << " OR (event_datetime_end >= :month_start AND event_datetime_end < :month_end)"
condition_str << " AND status_id = #{status}" if status condition_str << " AND status_id = #{status}" if status


Page.find(:all,:conditions => [condition_str, Page.find(:all,:conditions => [condition_str,
Expand All @@ -19,7 +20,9 @@ def events_by_month(date = Time.now, status = nil)


def event_count_by_month(date = Time.now) def event_count_by_month(date = Time.now)
month_start = date.at_beginning_of_month month_start = date.at_beginning_of_month
Page.count(:conditions => ["event_datetime_start >= :month_start OR event_datetime_end < :month_end", condition_str = "(event_datetime_start >= :month_start AND event_datetime_start < :month_end)"
condition_str << " OR (event_datetime_end >= :month_start AND event_datetime_end < :month_end)"
Page.count(:conditions => [condition_str,
{ {
:month_start => month_start, :month_start => month_start,
:month_end => month_start.next_month :month_end => month_start.next_month
Expand Down
6 changes: 3 additions & 3 deletions spec/models/page_extensions_spec.rb
Expand Up @@ -26,7 +26,7 @@
describe "#upcoming_events" do describe "#upcoming_events" do


before(:each) do before(:each) do
create_page "Another event", :event_datetime => (Time.now.at_beginning_of_month.next_month - 4.minutes).to_s(:db) create_page "Another event", :event_datetime_start => (Time.now.at_beginning_of_month.next_month - 4.minutes).to_s(:db)
end end


it "should return the pages for the next 3 upcoming events" do it "should return the pages for the next 3 upcoming events" do
Expand All @@ -40,8 +40,8 @@
describe "with more upcoming events" do describe "with more upcoming events" do


before(:each) do before(:each) do
create_page "Yet another event", :event_datetime => (Time.now.at_beginning_of_month.next_month - 3.minutes).to_s(:db) create_page "Yet another event", :event_datetime_start => (Time.now.at_beginning_of_month.next_month - 3.minutes).to_s(:db)
create_page "Final event", :event_datetime => (Time.now.at_beginning_of_month.next_month - 1.minutes).to_s(:db) create_page "Final event", :event_datetime_start => (Time.now.at_beginning_of_month.next_month - 1.minutes).to_s(:db)
end end


it "should return only return 3 events, even if there are more" do it "should return only return 3 events, even if there are more" do
Expand Down
11 changes: 7 additions & 4 deletions spec/scenarios/pages_scenario.rb
Expand Up @@ -6,12 +6,15 @@ def load
create_page "Home", :slug => "/", :parent_id => nil, create_page "Home", :slug => "/", :parent_id => nil,
:published_at => 2.months.ago.to_s(:db), :published_at => 2.months.ago.to_s(:db),
:body => "Hello world!", :body => "Hello world!",
:event_datetime => 5.minutes.from_now.to_s(:db) :event_datetime_start => 5.minutes.from_now.to_s(:db),
:event_datetime_end => 125.minutes.from_now.to_s(:db)



create_page "No Event" create_page "No Event"
create_page "CMonth First", :event_datetime => Time.now.at_beginning_of_month.to_s(:db) create_page "CMonth First", :event_datetime_start => Time.now.at_beginning_of_month.to_s(:db),
create_page "CMonth Last", :event_datetime => (Time.now.at_beginning_of_month.next_month - 2.minutes).to_s(:db) :event_datetime_end => (Time.now.at_beginning_of_month + 2.hours).to_s(:db)
create_page "Last Month", :event_datetime => (Time.now.at_beginning_of_month.last_month).to_s(:db) create_page "CMonth Last", :event_datetime_start => (Time.now.at_beginning_of_month.next_month - 2.minutes).to_s(:db)
create_page "Last Month", :event_datetime_start => (Time.now.at_beginning_of_month.last_month).to_s(:db)




end end
Expand Down

0 comments on commit 652c676

Please sign in to comment.