Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed condition string in Page.find so that events were found properl…

…y in their month

Fixed nil error when no event_datetime_end was specified
Updated TODO
  • Loading branch information...
commit 652c6761b1c23b739238e44541fc925dbbc60ced 1 parent f30003b
@mghaught authored
View
1  TODO
@@ -1,5 +1,4 @@
--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
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)
View
2  app/views/page_events/index.rhtml
@@ -48,7 +48,7 @@ span.event_date {
<td><%= event.status.name %></td>
<td>
<%= 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") %>
<%- end -%>
</td>
View
7 lib/page_event/page_extensions.rb
@@ -7,7 +7,8 @@ def self.included(base)
module ClassMethods
def events_by_month(date = Time.now, status = nil)
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
Page.find(:all,:conditions => [condition_str,
@@ -19,7 +20,9 @@ def events_by_month(date = Time.now, status = nil)
def event_count_by_month(date = Time.now)
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_end => month_start.next_month
View
6 spec/models/page_extensions_spec.rb
@@ -26,7 +26,7 @@
describe "#upcoming_events" 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
it "should return the pages for the next 3 upcoming events" do
@@ -40,8 +40,8 @@
describe "with more upcoming events" 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 "Final event", :event_datetime => (Time.now.at_beginning_of_month.next_month - 1.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_start => (Time.now.at_beginning_of_month.next_month - 1.minutes).to_s(:db)
end
it "should return only return 3 events, even if there are more" do
View
11 spec/scenarios/pages_scenario.rb
@@ -6,12 +6,15 @@ def load
create_page "Home", :slug => "/", :parent_id => nil,
:published_at => 2.months.ago.to_s(:db),
: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 "CMonth First", :event_datetime => 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)
- create_page "Last Month", :event_datetime => (Time.now.at_beginning_of_month.last_month).to_s(:db)
+ create_page "CMonth First", :event_datetime_start => Time.now.at_beginning_of_month.to_s(:db),
+ :event_datetime_end => (Time.now.at_beginning_of_month + 2.hours).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
Please sign in to comment.
Something went wrong with that request. Please try again.