Skip to content

Commit

Permalink
Add a basic notion of Blacklight::Document equality
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Aug 3, 2017
1 parent 3aa180a commit eae5950
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/concerns/blacklight/document/active_model_shim.rb
Expand Up @@ -31,6 +31,13 @@ def id
self[self.class.unique_key]
end

def ==(other)
super ||
(other.instance_of?(self.class) &&
id &&
other.id == id)
end

def _read_attribute(attr)
self[attr]
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/blacklight/document/active_model_shim_spec.rb
Expand Up @@ -30,4 +30,14 @@ def documents
expect(MockDocument.find(1).id).to be 1
end
end

describe "#==" do
it 'is equal for the same id' do
expect(MockDocument.new(id: 1) == MockDocument.new(id: 1)).to eq true
end

it 'is not equal if the ids differ' do
expect(MockDocument.new(id: 1) == MockDocument.new(id: 2)).to eq false
end
end
end

0 comments on commit eae5950

Please sign in to comment.