I am working on a Ruby script to address users accidentally deleted from the app, which clones a User record and the UserGroups right before deletion.
I'm looping through both objects, and now trying to figure how to assert that the attributes match.
I tried
assert_equal archived_user_groups, deleted_user_groups
but that is asserting the objects not the attributes, so it fails.
I am trying to loop through the array and check that attributes (user_id, group_id) are the same for every object at the same index (0, 1, 2, ...). Is each_with_index
suitable for this, and how would it be implemented?
archived_user_groups_test.rb:
def test_user_with_user_groups
user = users(:employee_bb)
deleted_user_groups = user.user_groups.sort_by{ |u| [u.user_id, u.group_id] }
user.archive!
archived_user_groups = ArchivedUserGroup.where(user_id: user.id).sort_by{ |u| [u.user_id, u.group_id] }
deleted_user_groups.each do |ug|
archived_user_groups.find do |attribute_names, attribute_values|
assert_equal archived_user_groups, deleted_user_groups
end
end
end