Reuse identical contacts

#746
This commit is contained in:
Artur Beljajev 2018-03-05 10:59:14 +02:00
parent 84bc0f8914
commit 53a34ee2d6
9 changed files with 94 additions and 12 deletions

View file

@ -0,0 +1,30 @@
require 'test_helper'
class ContactIdenticalTest < ActiveSupport::TestCase
def setup
@contact = contacts(:william)
@identical = contacts(:identical_to_william)
end
def test_identical
assert_equal @identical, @contact.identical(@identical.registrar)
end
def test_not_identical
filter_attributes = %i[
name
ident
ident_type
ident_country_code
phone
email
]
filter_attributes.each do |attribute|
previous_value = @identical.public_send(attribute)
@identical.update_attribute(attribute, 'other')
assert_nil @contact.identical(@identical.registrar)
@identical.update_attribute(attribute, previous_value)
end
end
end

View file

@ -35,18 +35,23 @@ class ContactTransferTest < ActiveSupport::TestCase
end
def test_keeps_original_contact_untouched
original_hash = @contact.to_json
original_hash = @contact.attributes
@contact.transfer(@new_registrar)
@contact.reload
assert_equal original_hash, @contact.to_json
assert_equal original_hash, @contact.attributes
end
def test_creates_new_contact
assert_difference 'Contact.count' do
assert_difference -> { @new_registrar.contacts.count } do
@contact.transfer(@new_registrar)
end
end
def test_reuses_identical_contact
identical = contacts(:identical_to_william)
assert_equal identical, contacts(:william).transfer(@new_registrar)
end
def test_bypasses_validation
@contact = contacts(:invalid)