Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/requisite/api_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def to_json(show_nil: false)
to_hash(show_nil: show_nil).to_json
end

def ==(other)
other.class == self.class && other.to_hash == self.to_hash
end

private

def parse_typed_hash(name, hash)
Expand Down
24 changes: 24 additions & 0 deletions test/requisite/api_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,30 @@ def response.b; 2; end
response.to_hash.must_equal(:num => 12)
end

describe '#==' do
let(:response_1) do
DummyApiModel.serialized_attributes { attribute :a }
DummyApiModel.new(a: 'A')
end

it 'is true with the same object' do
response_2 = response_1
assert_equal response_1, response_2
end

it 'is true with an equal object' do
DummyApiModel.serialized_attributes { attribute :a }
response_2 = DummyApiModel.new(a: 'A')
assert_equal response_1, response_2
end

it 'is false with an unequal object' do
DummyApiModel.serialized_attributes { attribute :a }
response_2 = DummyApiModel.new(a: 'B')
refute_equal response_1, response_2
end
end

describe 'with nested structures' do

describe 'with typed arrays' do
Expand Down