Skip to content

Instantly share code, notes, and snippets.

@camwest
Created November 9, 2011 19:46
Show Gist options
  • Save camwest/1352715 to your computer and use it in GitHub Desktop.
Save camwest/1352715 to your computer and use it in GitHub Desktop.
def merge(user1, user2, preferred_email)
raise "Email cannot be the same" if (user1 == user2)
u = User.unscoped.find_by_email(user1)
u2 = User.unscoped.find_by_email(user2)
raise "User1 not found" if u.nil?
raise "User2 not found" if u2.nil?
if u.alternate_ids.empty?
primary = u2
victim = u
else
primary = u
victim = u2
end
primary.takeover!(victim)
primary.update_attribute(:email, preferred_email)
primary.employments.collect { |emp| emp.allstate_network_ids.collect(&:network_id) }.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment