From 1ae00382cd0d75ac83d245c2cf28131824f4ad6d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 29 Sep 2017 00:37:59 +0300 Subject: [PATCH] Add ident equality #569 --- app/models/contact/ident.rb | 10 ++++++++++ spec/models/contact/ident_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/models/contact/ident.rb b/app/models/contact/ident.rb index 3891b3ed8..d531b833c 100644 --- a/app/models/contact/ident.rb +++ b/app/models/contact/ident.rb @@ -55,6 +55,16 @@ class Contact::Ident Country.new(country_code) end + def ==(other_ident) + if other_ident.is_a?(self.class) + (code == other_ident.code) && + (type == other_ident.type) && + (country_code == other_ident.country_code) + else + false + end + end + private # https://github.com/rails/rails/issues/1513 diff --git a/spec/models/contact/ident_spec.rb b/spec/models/contact/ident_spec.rb index 5ef0875c9..d26f76d0f 100644 --- a/spec/models/contact/ident_spec.rb +++ b/spec/models/contact/ident_spec.rb @@ -204,4 +204,24 @@ RSpec.describe Contact::Ident, db: false do expect(ident.country).to eq(Country.new('US')) end end + + describe '#==' do + let(:ident) { described_class.new(code: 'test', type: 'test', country_code: 'US') } + + context 'when code, type and country code are the same' do + let(:another_ident) { described_class.new(code: 'test', type: 'test', country_code: 'US') } + + it 'returns true' do + expect(ident).to eq(another_ident) + end + end + + context 'when code, type and country code are not the same' do + let(:another_ident) { described_class.new(code: 'another-test', type: 'test', country_code: 'US') } + + it 'returns false' do + expect(ident).to_not eq(another_ident) + end + end + end end