Skip to content
Browse files

Events are no longer global

  • Loading branch information...
1 parent 07013a3 commit c4ede48cd5caaf0beb1be59e4688e317108bcb7f Jeff Saracco committed
Showing with 14 additions and 10 deletions.
  1. +2 −2 app/controllers/items_controller.rb
  2. +5 −2 app/models/item.rb
  3. +2 −2 app/models/post.rb
  4. +5 −4 spec/models/item_spec.rb
View
4 app/controllers/items_controller.rb
@@ -19,7 +19,7 @@ def new
def index
@standup = Standup.find_by_id(params[:standup_id])
- events = @standup.items.events_on_or_after(Date.today)
+ events = Item.events_on_or_after(Date.today, @standup)
@items = @standup.items.orphans.merge(events)
end
@@ -45,7 +45,7 @@ def update
end
def presentation
- events = @standup.items.events_on_or_after(Date.today)
+ events = Item.events_on_or_after(Date.today, @standup)
@items = @standup.items.orphans.merge(events)
render layout: 'deck'
end
View
7 app/models/item.rb
@@ -19,8 +19,11 @@ def self.orphans
where(post_id: nil).where("kind != 'Event'").order("created_at ASC").group_by(&:kind)
end
- def self.events_on_or_after(date)
- where(kind: "Event").where("date >= ?", date).order("date").group_by(&:kind)
+ def self.events_on_or_after(date, standup)
+ where(kind: "Event").
+ where("standup_id = #{standup.id} OR standup_id IS NULL").
+ where("date >= ?", date).
+ order("date").group_by(&:kind)
end
def self.for_post(standup)
View
4 app/models/post.rb
@@ -37,12 +37,12 @@ def title_for_blog
def items_by_type
sorted_by_type(items).
- merge(Item.events_on_or_after(Date.today))
+ merge(Item.events_on_or_after(Date.today, standup))
end
def public_items_by_type
sorted_by_type(public_items).
- merge(Item.public.events_on_or_after(Date.today))
+ merge(Item.public.events_on_or_after(Date.today, standup))
end
def deliver_email
View
9 spec/models/item_spec.rb
@@ -47,12 +47,13 @@
end
describe ".events_on_or_after" do
- subject { Item.events_on_or_after(date)['Event'] }
+ subject { Item.events_on_or_after(date, standup)['Event'] }
+ let(:standup) { create(:standup) }
let(:date) { Date.parse('1/1/1970') }
- let!(:event_before_date) { create(:item, date: (date - 1.day), kind: 'Event') }
- let!(:event_after_date) { create(:item, date: (date + 1.day), kind: 'Event') }
- let!(:event_on_date) { create(:item, date: (date), kind: 'Event') }
+ let!(:event_before_date) { create(:item, date: (date - 1.day), kind: 'Event', standup: standup) }
+ let!(:event_after_date) { create(:item, date: (date + 1.day), kind: 'Event', standup: standup) }
+ let!(:event_on_date) { create(:item, date: (date), kind: 'Event', standup: standup) }
it { should_not include event_before_date }
it { should include event_on_date }

0 comments on commit c4ede48

Please sign in to comment.
Something went wrong with that request. Please try again.