Skip to content

Instantly share code, notes, and snippets.

@shwoodard
Created December 8, 2009 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shwoodard/251480 to your computer and use it in GitHub Desktop.
Save shwoodard/251480 to your computer and use it in GitHub Desktop.
def email
@emails = []
ContactImport.transaction do
emailed_association_requests.to_send.each do |ear|
if existing_user = User.find_by_email(ear.email)
ear.destroy
BusinessAssociation.new(:business => user.business, :other_business => existing_user.business).save!
else
ear.email!
end
end
end
end
it 'should destroy the ear if the user is already a vbn member' do
ci = Factory.create(:valid_contact_import)
ear = Factory.create(:valid_emailed_association_request)
user = Factory.create(:valid_user)
ci.user = user
ci.emailed_association_requests << ear
User.stubs(:find_by_email).returns(Factory.build(:valid_user))
ba = Factory.build(:valid_business_association)
ba.stubs(:save!)
BusinessAssociation.stubs(:new).returns(ba)
ear.expects(:destroy)
ci.email
end
it 'should email the ear if the user is not already a vbn member' do
ci = Factory.create(:valid_contact_import)
ear = Factory.create(:valid_emailed_association_request)
ci.emailed_association_requests << ear
User.stubs(:find_by_email).returns(nil)
ear.expects(:email!)
ci.email
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment