Commit e7c31078 authored by Alex Kalderimis's avatar Alex Kalderimis

Ensure correct model equality semantics

They need to behave with data-object semantics
parent 15a86e9d
......@@ -34,6 +34,14 @@ module DesignManagement
"#{design.id}.#{version.id}"
end
def ==(other)
return false unless other.is_a?(self.class)
other.id == id
end
alias_method :eql?, :==
def self.lazy_find(id)
BatchLoader.for(id).batch do |ids, callback|
find(ids).each do |record|
......
......@@ -18,6 +18,35 @@ describe DesignManagement::DesignAtVersion do
end
end
describe '#==' do
it 'has structural semantics' do
design = create(:design, issue: issue)
version = create(:design_version, designs: [design], issue: issue)
this = create(:design_at_version, design: design, version: version)
other = create(:design_at_version, design: design, version: version)
expect(this).to eq(other)
end
it 'does not admit false positives' do
design = create(:design, issue: issue)
version_a = create(:design_version, designs: [design])
version_b = create(:design_version, designs: [design])
this = create(:design_at_version, design: design, version: version_a)
other = create(:design_at_version, design: design, version: version_b)
expect(this).not_to eq(other)
end
it 'rejects objects with the same id and the wrong class' do
dav = create(:design_at_version)
expect(dav).not_to eq(OpenStruct.new(id: dav.id))
end
end
describe 'status methods' do
let!(:design_a) { create(:design, issue: issue) }
let!(:design_b) { create(:design, issue: issue) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment