Add contact disclosable attributes

Closes #992
This commit is contained in:
Artur Beljajev 2018-11-08 17:55:58 +02:00
parent 59db269240
commit d695d95ad7
15 changed files with 184 additions and 30 deletions

View file

@ -0,0 +1,39 @@
require 'test_helper'
class ContactDisclosableTest < ActiveSupport::TestCase
setup do
@contact = contacts(:john)
@original_disclosable_attributes = Contact.disclosable_attributes
end
teardown do
Contact.disclosable_attributes = @original_disclosable_attributes
end
def test_no_disclosed_attributes_by_default
assert_empty Contact.new.disclosed_attributes
end
def test_disclosable_attributes
assert_equal %w[name email], Contact.disclosable_attributes
end
def test_valid_without_disclosed_attributes
@contact.disclosed_attributes = []
assert @contact.valid?
end
def test_invalid_when_attribute_is_not_disclosable
Contact.disclosable_attributes = %w[some disclosable]
@contact.disclosed_attributes = %w[some undisclosable]
assert @contact.invalid?
assert_includes @contact.errors.get(:disclosed_attributes), 'contain unsupported attribute(s)'
end
def test_valid_when_attribute_is_disclosable
Contact.disclosable_attributes = %w[some disclosable]
@contact.disclosed_attributes = %w[disclosable]
assert @contact.valid?
end
end

View file

@ -6,7 +6,7 @@ class ContactTest < ActiveSupport::TestCase
end
def test_valid_fixture
assert @contact.valid?
assert @contact.valid?, proc { @contact.errors.full_messages }
end
def test_invalid_without_email
@ -48,4 +48,4 @@ class ContactTest < ActiveSupport::TestCase
assert_equal 'EE', @contact.country_code
assert_equal address, @contact.address
end
end
end

View file

@ -39,12 +39,13 @@ class WhoisRecordTest < ActiveSupport::TestCase
end
def test_generates_json_with_registrant
registrant = contacts(:john).becomes(Registrant)
registrant.update!(name: 'John', kind: 'priv', email: 'john@shop.test',
updated_at: Time.zone.parse('2010-07-05'))
contact = contacts(:john)
contact.update!(name: 'John', kind: 'priv', email: 'john@shop.test',
updated_at: Time.zone.parse('2010-07-05'),
disclosed_attributes: %w[name])
domain = domains(:shop)
domain.update!(registrant: registrant)
domain.update!(registrant: contact.becomes(Registrant))
whois_record = whois_records(:shop)
whois_record.update!(json: {})
@ -54,12 +55,14 @@ class WhoisRecordTest < ActiveSupport::TestCase
assert_equal 'priv', generated_json[:registrant_kind]
assert_equal 'john@shop.test', generated_json[:email]
assert_equal '2010-07-05T00:00:00+03:00', generated_json[:registrant_changed]
assert_equal %w[name], generated_json[:registrant_disclosed_attributes]
end
def test_generates_json_with_admin_contacts
contact = contacts(:john)
contact.update!(name: 'John', email: 'john@shop.test',
updated_at: Time.zone.parse('2010-07-05'))
updated_at: Time.zone.parse('2010-07-05'),
disclosed_attributes: %w[name])
domain = domains(:shop)
domain.admin_contacts = [contact]
@ -71,12 +74,14 @@ class WhoisRecordTest < ActiveSupport::TestCase
assert_equal 'John', admin_contact_json[:name]
assert_equal 'john@shop.test', admin_contact_json[:email]
assert_equal '2010-07-05T00:00:00+03:00', admin_contact_json[:changed]
assert_equal %w[name], admin_contact_json[:disclosed_attributes]
end
def test_generates_json_with_tech_contacts
contact = contacts(:john)
contact.update!(name: 'John', email: 'john@shop.test',
updated_at: Time.zone.parse('2010-07-05'))
updated_at: Time.zone.parse('2010-07-05'),
disclosed_attributes: %w[name])
domain = domains(:shop)
domain.tech_contacts = [contact]
@ -88,5 +93,6 @@ class WhoisRecordTest < ActiveSupport::TestCase
assert_equal 'John', tech_contact_json[:name]
assert_equal 'john@shop.test', tech_contact_json[:email]
assert_equal '2010-07-05T00:00:00+03:00', tech_contact_json[:changed]
assert_equal %w[name], tech_contact_json[:disclosed_attributes]
end
end