Created
December 8, 2009 07:07
-
-
Save shwoodard/251480 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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