Skip to content

Commit

Permalink
added version controll on ==
Browse files Browse the repository at this point in the history
  • Loading branch information
hallgren committed Oct 12, 2015
1 parent f40b2b8 commit 6807491
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/sandthorn/event_sourced_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def save
end

def ==(other)
other.respond_to?(:id) && id == other.id
return false unless other.respond_to?(:current_event_version) && current_event_version == other.current_event_version
return false unless other.respond_to?(:id) && id == other.id
return true
end

def trace args
Expand Down
18 changes: 18 additions & 0 deletions spec/event_sourced_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ class DirtyClassChild < DirtyClass
it "should have originating_version == 1 post save" do
expect(dirty_obejct.save.originating_version).to eql 1
end

end

context ".==" do
before do
dirty_obejct.save
end

it "should be the same object with ==" do
reloaded_dirty_object = DirtyClass.find dirty_obejct.aggregate_id
expect(reloaded_dirty_object == dirty_obejct).to be_truthy
end

it "should not be the same object if one mutated" do
reloaded_dirty_object = DirtyClass.find dirty_obejct.aggregate_id
dirty_obejct.change_name("new name")
expect(dirty_obejct == reloaded_dirty_object).to be_falsy
end
end

context "find" do
Expand Down

0 comments on commit 6807491

Please sign in to comment.