Skip to content

Commit

Permalink
Adding activity when person attends event. Improved Specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Dias committed Sep 10, 2008
1 parent 683c071 commit 9773da8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/helpers/activities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def feed_message(activity)
%(#{person_link(person)}'s description has changed.)
when "Event"
%(#{person_link(person)} has created a new event: #{event_link(activity.item.title, activity.item)}.)
when "EventAttendee"
event = activity.item.event
%(#{person_link(person)} is attending #{someones(event.person, person)} event:
#{event_link(event.title, event)}.)
else
raise "Invalid activity type #{activity_type(activity).inspect}"
end
Expand Down Expand Up @@ -95,6 +99,9 @@ def minifeed_message(activity)
%(#{person_link(person)}'s description has changed.)
when "Event"
%(#{person_link(person)}'s has created a new #{event_link("event", activity.item)}.)
when "EventAttendee"
event = activity.item.event
%(#{person_link(person)} is attending #{someones(event.person, person)} #{event_link("event", event)}.)
else
raise "Invalid activity type #{activity_type(activity).inspect}"
end
Expand Down Expand Up @@ -126,7 +133,9 @@ def feed_icon(activity)
when "Person"
"edit.gif"
when "Event"
"event.gif"
"time.gif"
when "EventAttendee"
"check.gif"
else
raise "Invalid activity type #{activity_type(activity).inspect}"
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/event_attendee.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
class EventAttendee < ActiveRecord::Base
include ActivityLogger

belongs_to :person
belongs_to :event, :counter_cache => true
validates_uniqueness_of :person_id, :scope => :event_id

after_create :log_activity

def log_activity
add_activities(:item => self, :person => self.person)
end

end
29 changes: 29 additions & 0 deletions spec/models/event_attendee_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe EventAttendee do
before(:each) do
@person = people(:aaron)
@event = events(:public)
@event_attendee = EventAttendee.new(:event => @event,
:person => @person)
end

it 'should be valid' do
@event.should be_valid
end

describe "event_attendee activity associations" do
before(:each) do
@event_attendee.save!
@activity = Activity.find_by_item_id(@event_attendee)
end

it "should have an activity" do
@activity.should_not be_nil
end

it "should add an activity to the attendee" do
@event_attendee.person.recent_activity.should contain(@activity)
end
end
end
15 changes: 15 additions & 0 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@
end
end

describe 'event activity association' do
before(:each) do
@event = Event.create!(@valid_attributes)
@activity = Activity.find_by_item_id(@event)
end

it "should have an activity" do
@activity.should_not be_nil
end

it "should add an activity to the creator" do
@event.person.recent_activity.should contain(@activity)
end
end

end

0 comments on commit 9773da8

Please sign in to comment.