Skip to content

Commit

Permalink
Verify if is an Address object before compare.
Browse files Browse the repository at this point in the history
  • Loading branch information
prodis committed Nov 10, 2015
1 parent a0bdddf commit 3b9a4ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/correios/cep/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Address
element :complemento2, as: :complement2

def ==(other)
return false unless other.is_a?(self.class)

instance_variables.each do |attr|
return false unless self.instance_variable_get(attr) == other.instance_variable_get(attr)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/correios/cep/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@

it { should be false }
end

context 'when compares with other kind of object' do
subject do
address = described_class.new
address == :address
end

it { should be false }
end
end

describe '#has_content?' do
Expand Down

0 comments on commit 3b9a4ae

Please sign in to comment.