Skip to content

Instantly share code, notes, and snippets.

Created September 29, 2017 06:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Fun recursive function to test if things like copying deep data structures work correctly. Done with @boconnell at @remix.
def identity_of_model(model, global_excluded=['id', 'created_at', 'updated_at', 'deleted_at'])
excluded_columns = + global_excluded
identity = model.attributes.except(*excluded_columns)
model.class.reflect_on_all_associations(:has_many).sort_by(&:name).each do |ref|
identity[] = model.send(
model.class.reflect_on_all_associations(:has_and_belongs_to_many).sort_by(&:name).each do |ref|
identity["#{}_counts"] = model.send(
identity_of_model(Map.first) == identity_of_model(copy(Map.first))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment