Last active
January 3, 2016 11:59
-
-
Save lunks/8459469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Attendee < ActiveRecord::Base | |
devise :invitable, :rememberable, :trackable, :omniauthable, | |
:registerable, :database_authenticatable, :recoverable | |
has_many :reservations, through: :invites | |
has_many :invites, foreign_key: :guest_id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PeopleRelatedAssociations | |
def add_guest_associations | |
self.class_eval do | |
has_many :checked_in_attendees, through: :reservations, source: :attendee | |
end | |
end | |
end | |
class AttendeeStats | |
attr_reader :attendee | |
def initialize(attendee) | |
@attendee = attendee | |
@attendee.extend(PeopleRelatedAssociations).add_guest_associations | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe AttendeeStats do | |
let!(:attendee_stats) { AttendeeStats.new(attendee) } | |
let!(:attendee) { create(:attendee) } | |
it "extends attendee with guest associations" do | |
attendee_stats.attendee.checked_in_attendees.should == [] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) AttendeeStats#people_brought_count extends attendee with guest associations | |
Failure/Error: attendee_stats.attendee.checked_in_attendees.should == [] | |
NoMethodError: | |
undefined method `association_class' for nil:NilClass | |
# /Users/lunks/.rvm/gems/ruby-1.9.3-p448@wego/gems/activerecord-3.2.13/lib/active_record/associations.rb:160:in `association' | |
# /Users/lunks/.rvm/gems/ruby-1.9.3-p448@wego/gems/activerecord-3.2.13/lib/active_record/associations/builder/association.rb:44:in `block in define_readers' | |
# ./spec/services/attendee_stats_spec.rb:6:in `block (3 levels) in <top (required)>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment