mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
Solve both sides of the missing fields bug, not only one
This commit is contained in:
parent
cec05c3943
commit
a82db7a67a
7 changed files with 21 additions and 11 deletions
|
@ -1,10 +1,15 @@
|
|||
module ObjectVersionsHelper
|
||||
def attach_existing_fields(version, new_object)
|
||||
version.object_changes.to_h.each do |k, v|
|
||||
method_name = "#{k}=".to_sym
|
||||
version.object_changes.to_h.each do |key, value|
|
||||
method_name = "#{key}=".to_sym
|
||||
if new_object.respond_to?(method_name)
|
||||
new_object.public_send(method_name, v.last)
|
||||
new_object.public_send(method_name, value.last)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def only_present_fields(version, model)
|
||||
field_names = model.column_names
|
||||
version.object.to_h.select { |key, _value| field_names.include?(key) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,7 +57,8 @@
|
|||
%tbody
|
||||
- @versions.each do |version|
|
||||
- if version
|
||||
- contact = Contact.new(version.object.to_h)
|
||||
- attributes = only_present_fields(version, Contact)
|
||||
- contact = Contact.new(attributes)
|
||||
- attach_existing_fields(version, contact)
|
||||
|
||||
%tr
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
- contact = Contact.new(@version.object.to_h)
|
||||
- attributes = only_present_fields(@version, Contact)
|
||||
- contact = Contact.new(attributes)
|
||||
- attach_existing_fields(@version, contact)
|
||||
= render 'shared/title', name: contact.name
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@
|
|||
%tbody
|
||||
- @versions.each do |version|
|
||||
- if version
|
||||
- domain = Domain.new(version.object.to_h)
|
||||
- attributes = only_present_fields(version, Domain)
|
||||
- domain = Domain.new(attributes)
|
||||
- attach_existing_fields(version, domain)
|
||||
|
||||
%tr
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
- domain = Domain.new(@version.object.to_h)
|
||||
- present_fields = only_present_fields(@version, Domain)
|
||||
- domain = Domain.new(present_fields)
|
||||
- attach_existing_fields(@version, domain)
|
||||
|
||||
- if @version
|
||||
|
|
|
@ -27,7 +27,7 @@ class ContactVersionsTest < ActionDispatch::IntegrationTest
|
|||
INSERT INTO log_contacts (item_type, item_id, event, whodunnit, object,
|
||||
object_changes, created_at, session, children, ident_updated_at, uuid)
|
||||
VALUES ('Contact', 75, 'update', '1-AdminUser',
|
||||
'{"id": 75, "code": "test_code", "auth_info": "8b4d462aa04194ca78840a", "registrar_id": 75}',
|
||||
'{"id": 75, "code": "test_code", "auth_info": "8b4d462aa04194ca78840a", "registrar_id": 75, "old_field": "value"}',
|
||||
'{"other_made_up_field": "value"}',
|
||||
'2018-04-23 15:50:48.113491', '2018-04-23 12:44:56',
|
||||
'{"legal_documents":[null]}', null, null
|
||||
|
|
|
@ -32,8 +32,8 @@ class DomainVersionsTest < ActionDispatch::IntegrationTest
|
|||
object_changes, created_at, nameserver_ids, tech_contact_ids,
|
||||
admin_contact_ids, session, children)
|
||||
VALUES ('Domain', 54, 'update', '1-AdminUser',
|
||||
'{"id": 54, "registrar_id": 54, "valid_to": "2018-07-23T12:14:05.583+03:00", "registrant_id": 54, "transfer_code": "transfer_code"}',
|
||||
'{"valid_from": "2017-07-23T12:14:05.583+03:00", "foo": "bar", "other_made_up_field": "value"}',
|
||||
'{"id": 54, "registrar_id": 54, "valid_to": "2018-07-23T12:14:05.583+03:00", "registrant_id": 54, "transfer_code": "transfer_code", "valid_from": "2017-07-23T12:14:05.583+03:00"}',
|
||||
'{"foo": "bar", "other_made_up_field": "value"}',
|
||||
'2018-04-23 15:50:48.113491', '{}', '{}', '{}', '2018-04-23 12:44:56',
|
||||
'{"null_fracdmin_contacts":[108],"tech_contacts":[109],"nameservers":[],"dnskeys":[],"legal_documents":[null],"registrant":[1]}'
|
||||
)
|
||||
|
@ -50,6 +50,7 @@ class DomainVersionsTest < ActionDispatch::IntegrationTest
|
|||
|
||||
def test_removed_fields_are_not_causing_errors_in_index_view
|
||||
visit admin_domain_versions_path
|
||||
|
||||
assert_text 'test_registrar'
|
||||
assert_text 'test_registrar update 23.04.18, 18:50'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue