Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created December 8, 2009 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floehopper/251547 to your computer and use it in GitHub Desktop.
Save floehopper/251547 to your computer and use it in GitHub Desktop.
it 'should destroy the ear if the user is already a 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 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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment