From e039aabeeffc3c7cce6f6808915d5875fb33a9c0 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Wed, 17 Aug 2011 11:00:14 -0700 Subject: [PATCH] senders must now own aspects --- app/models/invitation.rb | 9 +++++++++ spec/models/invitation_spec.rb | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 553a4d54b..a60e3c0fe 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -17,6 +17,7 @@ class Invitation < ActiveRecord::Base validate :ensure_not_inviting_self, :on => :create validate :valid_identifier? + validate :sender_owns_aspect? validates_uniqueness_of :sender_id, :scope => [:identifier, :service], :unless => :admin? after_create :queue_send! #TODO make this after_commit :queue_saved!, :on => :create @@ -121,6 +122,14 @@ class Invitation < ActiveRecord::Base end end + # @note Validation + def sender_owns_aspect? + unless(self.sender && (self.sender_id == self.aspect.user_id)) + errors[:base] << 'You do not own that aspect' + end + end + + # @note Validation def valid_identifier? return false unless self.identifier diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 30b081737..54f1800db 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -24,7 +24,8 @@ describe Invitation do end it 'ensures the sender is placing the recipient into one of his aspects' do - pending + @invitation.aspect = Factory(:aspect) + @invitation.should_not be_valid end end @@ -35,6 +36,7 @@ describe Invitation do end + describe 'the invite process' do before do end @@ -61,13 +63,17 @@ describe Invitation do invite.send! }.should_not change(User, :count) end - it 'is able to resend an invite' do - end it 'handles the case when that user has an invite but not a user' do + pending end it 'handles the case where that user has an invite but has not yet accepted' do + pending + end + + it 'generate the invitation token and pass it to the user' do + end end