mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
parent
c733c0910d
commit
ecc68f083d
3 changed files with 67 additions and 25 deletions
|
@ -1,18 +1,34 @@
|
||||||
module Concerns::Contact::Identical
|
module Concerns::Contact::Identical
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
ATTRIBUTE_FILTER = %w[
|
IDENTIFIABLE_ATTRIBUTES = %w[
|
||||||
name
|
name
|
||||||
|
email
|
||||||
|
phone
|
||||||
|
fax
|
||||||
ident
|
ident
|
||||||
ident_type
|
ident_type
|
||||||
ident_country_code
|
ident_country_code
|
||||||
phone
|
org_name
|
||||||
email
|
|
||||||
]
|
]
|
||||||
private_constant :ATTRIBUTE_FILTER
|
private_constant :IDENTIFIABLE_ATTRIBUTES
|
||||||
|
|
||||||
def identical(registrar)
|
def identical(registrar)
|
||||||
self.class.where(attributes.slice(*ATTRIBUTE_FILTER)).where(registrar: registrar)
|
self.class.where(identifiable_hash)
|
||||||
|
.where(["statuses = ?::character varying[]", "{#{read_attribute(:statuses).join(',')}}"])
|
||||||
|
.where(registrar: registrar)
|
||||||
.where.not(id: id).take
|
.where.not(id: id).take
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def identifiable_hash
|
||||||
|
attributes = IDENTIFIABLE_ATTRIBUTES
|
||||||
|
|
||||||
|
if self.class.address_processing?
|
||||||
|
attributes += self.class.address_attribute_names
|
||||||
|
end
|
||||||
|
|
||||||
|
slice(*attributes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
17
test/fixtures/contacts.yml
vendored
17
test/fixtures/contacts.yml
vendored
|
@ -9,16 +9,22 @@ john:
|
||||||
code: john-001
|
code: john-001
|
||||||
auth_info: cacb5b
|
auth_info: cacb5b
|
||||||
|
|
||||||
william:
|
william: &william
|
||||||
name: William
|
name: William
|
||||||
email: william@inbox.test
|
email: william@inbox.test
|
||||||
phone: '+555.555'
|
phone: '+555.555'
|
||||||
|
fax: +555.555
|
||||||
ident: 1234
|
ident: 1234
|
||||||
ident_type: priv
|
ident_type: priv
|
||||||
ident_country_code: US
|
ident_country_code: US
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
code: william-001
|
code: william-001
|
||||||
auth_info: 6573d0
|
auth_info: 6573d0
|
||||||
|
street: Main Street
|
||||||
|
zip: 12345
|
||||||
|
city: New York
|
||||||
|
state: New York
|
||||||
|
country_code: US
|
||||||
statuses:
|
statuses:
|
||||||
- ok
|
- ok
|
||||||
|
|
||||||
|
@ -56,17 +62,10 @@ jack:
|
||||||
auth_info: e2c440
|
auth_info: e2c440
|
||||||
|
|
||||||
identical_to_william:
|
identical_to_william:
|
||||||
name: William
|
<<: *william
|
||||||
email: william@inbox.test
|
|
||||||
phone: '+555.555'
|
|
||||||
ident: 1234
|
|
||||||
ident_type: priv
|
|
||||||
ident_country_code: US
|
|
||||||
registrar: goodnames
|
registrar: goodnames
|
||||||
code: william-002
|
code: william-002
|
||||||
auth_info: 5ab865
|
auth_info: 5ab865
|
||||||
statuses:
|
|
||||||
- ok
|
|
||||||
|
|
||||||
invalid:
|
invalid:
|
||||||
name: any
|
name: any
|
||||||
|
|
|
@ -1,30 +1,57 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ContactIdenticalTest < ActiveSupport::TestCase
|
class ContactIdenticalTest < ActiveSupport::TestCase
|
||||||
|
REGULAR_FILTER_ATTRIBUTES = %i[
|
||||||
|
name
|
||||||
|
email
|
||||||
|
phone
|
||||||
|
fax
|
||||||
|
ident
|
||||||
|
ident_type
|
||||||
|
ident_country_code
|
||||||
|
org_name
|
||||||
|
]
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@contact = contacts(:william)
|
@contact = contacts(:william)
|
||||||
@identical = contacts(:identical_to_william)
|
@identical = contacts(:identical_to_william)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_identical
|
def test_returns_identical
|
||||||
assert_equal @identical, @contact.identical(@identical.registrar)
|
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_not_identical
|
def test_does_not_return_non_identical
|
||||||
filter_attributes = %i[
|
REGULAR_FILTER_ATTRIBUTES.each do |attribute|
|
||||||
name
|
previous_value = @identical.public_send(attribute)
|
||||||
ident
|
@identical.update_attribute(attribute, 'other')
|
||||||
ident_type
|
assert_nil @contact.identical(@identical.registrar)
|
||||||
ident_country_code
|
@identical.update_attribute(attribute, previous_value)
|
||||||
phone
|
end
|
||||||
email
|
|
||||||
]
|
|
||||||
|
|
||||||
filter_attributes.each do |attribute|
|
@identical.update!({ statuses: %w[ok linked] })
|
||||||
|
assert_nil @contact.identical(@identical.registrar)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_takes_address_into_account_when_processing_enabled
|
||||||
|
Setting.address_processing = true
|
||||||
|
|
||||||
|
Contact.address_attribute_names.each do |attribute|
|
||||||
previous_value = @identical.public_send(attribute)
|
previous_value = @identical.public_send(attribute)
|
||||||
@identical.update_attribute(attribute, 'other')
|
@identical.update_attribute(attribute, 'other')
|
||||||
assert_nil @contact.identical(@identical.registrar)
|
assert_nil @contact.identical(@identical.registrar)
|
||||||
@identical.update_attribute(attribute, previous_value)
|
@identical.update_attribute(attribute, previous_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ignores_address_when_processing_disabled
|
||||||
|
Setting.address_processing = false
|
||||||
|
|
||||||
|
Contact.address_attribute_names.each do |attribute|
|
||||||
|
previous_value = @identical.public_send(attribute)
|
||||||
|
@identical.update_attribute(attribute, 'other')
|
||||||
|
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||||
|
@identical.update_attribute(attribute, previous_value)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue