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
|
module ObjectVersionsHelper
|
||||||
def attach_existing_fields(version, new_object)
|
def attach_existing_fields(version, new_object)
|
||||||
version.object_changes.to_h.each do |k, v|
|
version.object_changes.to_h.each do |key, value|
|
||||||
method_name = "#{k}=".to_sym
|
method_name = "#{key}=".to_sym
|
||||||
if new_object.respond_to?(method_name)
|
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
|
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
|
end
|
||||||
|
|
|
@ -57,8 +57,9 @@
|
||||||
%tbody
|
%tbody
|
||||||
- @versions.each do |version|
|
- @versions.each do |version|
|
||||||
- if version
|
- if version
|
||||||
- contact = Contact.new(version.object.to_h)
|
- attributes = only_present_fields(version, Contact)
|
||||||
- attach_existing_fields(version, contact)
|
- contact = Contact.new(attributes)
|
||||||
|
- attach_existing_fields(version, contact)
|
||||||
|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(contact.name, admin_contact_version_path(version.id))
|
%td= link_to(contact.name, admin_contact_version_path(version.id))
|
||||||
|
|
|
@ -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)
|
- attach_existing_fields(@version, contact)
|
||||||
= render 'shared/title', name: contact.name
|
= render 'shared/title', name: contact.name
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@
|
||||||
%tbody
|
%tbody
|
||||||
- @versions.each do |version|
|
- @versions.each do |version|
|
||||||
- if 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)
|
- attach_existing_fields(version, domain)
|
||||||
|
|
||||||
%tr
|
%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)
|
- attach_existing_fields(@version, domain)
|
||||||
|
|
||||||
- if @version
|
- if @version
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ContactVersionsTest < ActionDispatch::IntegrationTest
|
||||||
INSERT INTO log_contacts (item_type, item_id, event, whodunnit, object,
|
INSERT INTO log_contacts (item_type, item_id, event, whodunnit, object,
|
||||||
object_changes, created_at, session, children, ident_updated_at, uuid)
|
object_changes, created_at, session, children, ident_updated_at, uuid)
|
||||||
VALUES ('Contact', 75, 'update', '1-AdminUser',
|
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"}',
|
'{"other_made_up_field": "value"}',
|
||||||
'2018-04-23 15:50:48.113491', '2018-04-23 12:44:56',
|
'2018-04-23 15:50:48.113491', '2018-04-23 12:44:56',
|
||||||
'{"legal_documents":[null]}', null, null
|
'{"legal_documents":[null]}', null, null
|
||||||
|
|
|
@ -32,8 +32,8 @@ class DomainVersionsTest < ActionDispatch::IntegrationTest
|
||||||
object_changes, created_at, nameserver_ids, tech_contact_ids,
|
object_changes, created_at, nameserver_ids, tech_contact_ids,
|
||||||
admin_contact_ids, session, children)
|
admin_contact_ids, session, children)
|
||||||
VALUES ('Domain', 54, 'update', '1-AdminUser',
|
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"}',
|
'{"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"}',
|
||||||
'{"valid_from": "2017-07-23T12:14:05.583+03:00", "foo": "bar", "other_made_up_field": "value"}',
|
'{"foo": "bar", "other_made_up_field": "value"}',
|
||||||
'2018-04-23 15:50:48.113491', '{}', '{}', '{}', '2018-04-23 12:44:56',
|
'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]}'
|
'{"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
|
def test_removed_fields_are_not_causing_errors_in_index_view
|
||||||
visit admin_domain_versions_path
|
visit admin_domain_versions_path
|
||||||
|
|
||||||
assert_text 'test_registrar'
|
assert_text 'test_registrar'
|
||||||
assert_text 'test_registrar update 23.04.18, 18:50'
|
assert_text 'test_registrar update 23.04.18, 18:50'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue