mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 05:05:45 +02:00
Fix tests
This commit is contained in:
parent
7b258f8e79
commit
e1d2fb45d5
2 changed files with 23 additions and 5 deletions
|
@ -2,7 +2,6 @@ class RegistrantUser < User
|
||||||
attr_accessor :idc_data
|
attr_accessor :idc_data
|
||||||
|
|
||||||
devise :trackable, :timeoutable
|
devise :trackable, :timeoutable
|
||||||
after_save :update_related_contacts
|
|
||||||
|
|
||||||
def ability
|
def ability
|
||||||
@ability ||= Ability.new(self)
|
@ability ||= Ability.new(self)
|
||||||
|
@ -56,8 +55,7 @@ class RegistrantUser < User
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_related_contacts
|
def update_related_contacts
|
||||||
cc, idcode = registrant_ident.split('-')
|
contacts = Contact.where(ident: ident, country_code: country_code)
|
||||||
contacts = Contact.where(ident: idcode, country_code: cc)
|
|
||||||
.where('UPPER(name) != UPPER(?)', username)
|
.where('UPPER(name) != UPPER(?)', username)
|
||||||
|
|
||||||
contacts.each { |c| c.update(name: username) }
|
contacts.each { |c| c.update(name: username) }
|
||||||
|
@ -100,6 +98,7 @@ class RegistrantUser < User
|
||||||
user.username = "#{user_data[:first_name]} #{user_data[:last_name]}"
|
user.username = "#{user_data[:first_name]} #{user_data[:last_name]}"
|
||||||
user.save
|
user.save
|
||||||
|
|
||||||
|
user.update_related_contacts
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase
|
||||||
assert_equal('JOHN SMITH', user.username)
|
assert_equal('JOHN SMITH', user.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_or_create_by_api_data_creates_a_user_after_upcasing_input
|
def test_find_or_create_by_api_data_creates_a_user_with_original_name
|
||||||
user_data = {
|
user_data = {
|
||||||
ident: '37710100070',
|
ident: '37710100070',
|
||||||
first_name: 'John',
|
first_name: 'John',
|
||||||
|
@ -24,6 +24,25 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase
|
||||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||||
|
|
||||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||||
assert_equal('JOHN SMITH', user.username)
|
assert_equal('John Smith', user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_updates_related_contacts_name_if_differs_from_e_identity
|
||||||
|
contact = contacts(:john)
|
||||||
|
contact.update(ident: '39708290276', ident_country_code: 'EE')
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
ident: '39708290276',
|
||||||
|
first_name: 'John',
|
||||||
|
last_name: 'Doe'
|
||||||
|
}
|
||||||
|
|
||||||
|
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||||
|
|
||||||
|
user = User.find_by(registrant_ident: 'EE-39708290276')
|
||||||
|
assert_equal('John Doe', user.username)
|
||||||
|
|
||||||
|
contact.reload
|
||||||
|
assert_equal user.username, contact.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue