Sha256: d690a873906bc28408bc3dce248b8205b4d5dae8a03f256ee1c11283905c0c65

Contents?: true

Size: 924 Bytes

Versions: 4

Compression:

Stored size: 924 Bytes

Contents

# Stores the fact that a user has invited one of her friends to attend a conference.
# origin: M
class Invitation < ActiveRecord::Base

  belongs_to :recipient, :class_name => 'User'
  belongs_to :sender, :class_name => 'User'
  belongs_to :conference

  validates_presence_of :conference_id, :recipient_id, :sender_id

  validate :recipient_must_be_a_friend

  named_scope :for_recipient, lambda { |recipient| { :conditions => { :recipient_id => recipient.id }}}
  named_scope :include_everything, :include => [:recipient, :sender, :conference]

  def accept!
    conference.attend!(recipient)
    destroy
  end

  def dismiss!
    destroy
  end

  private

  def recipient_must_be_a_friend
    if sender && recipient && !sender.friends.include?(recipient)
      errors.add(:recipient_id, 'is not a confirmed contact of the invitation sender')
    end
    true
  end

  def self.import(path)
    YAML.load(path)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serum-rails-0.2.1 spec/test_apps/rails-2-3/app/models/invitation.rb
serum-rails-0.2.0 spec/test_apps/rails-2-3/app/models/invitation.rb
serum-rails-0.1.1 spec/test_app/app/models/invitation.rb
serum-rails-0.1.0 spec/test_app/app/models/invitation.rb