From e6069e06a9350fc9a5cc99ec87e8ed74ec1fbb42 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 22 Dec 2016 16:34:29 +0200 Subject: [PATCH] Introduce kind and reg_no contact's attributes #266 --- app/models/contact.rb | 6 ++++++ spec/factories/contact.rb | 9 +++++++++ spec/models/contact_spec.rb | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/app/models/contact.rb b/app/models/contact.rb index b50428bb1..99139e898 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -15,6 +15,7 @@ class Contact < ActiveRecord::Base has_paper_trail class_name: "ContactVersion", meta: { children: :children_log } attr_accessor :legal_document_id + alias_attribute :kind, :ident_type accepts_nested_attributes_for :legal_documents @@ -583,4 +584,9 @@ class Contact < ActiveRecord::Base self[attr_name.to_sym] = nil end end + + def reg_no + return if priv? + ident + end end diff --git a/spec/factories/contact.rb b/spec/factories/contact.rb index 5218da399..7122babd5 100644 --- a/spec/factories/contact.rb +++ b/spec/factories/contact.rb @@ -12,5 +12,14 @@ FactoryGirl.define do ident_type 'priv' ident_country_code 'EE' registrar + + factory :contact_private_entity do + ident_type 'priv' + end + + factory :contact_legal_entity do + ident_type 'org' + ident '12345678' # valid reg no for .ee + end end end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 3952a1d0e..df4d8cfd3 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -361,6 +361,8 @@ describe Contact, '.destroy_orphans' do end RSpec.describe Contact, db: false do + it { is_expected.to alias_attribute(:kind, :ident_type) } + describe '::names' do before :example do expect(described_class).to receive(:pluck).with(:name).and_return('names') @@ -463,4 +465,20 @@ RSpec.describe Contact, db: false do expect(address_removed).to be_truthy end end + + describe '#reg_no' do + subject(:reg_no) { contact.reg_no } + + context 'when contact is legal entity' do + let(:contact) { FactoryGirl.build_stubbed(:contact_legal_entity, ident: '1234') } + + specify { expect(reg_no).to eq('1234') } + end + + context 'when contact is private entity' do + let(:contact) { FactoryGirl.build_stubbed(:contact_private_entity, ident: '1234') } + + specify { expect(reg_no).to be_nil } + end + end end