Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value objects do not have equality when using Virtus.value_object #313

Closed
wants to merge 1 commit into from

Conversation

betamatt
Copy link

Given:

class Value
  include Virtus.value_object
  attribute :number, Integer
end

We expect: Value.new(:number => 7) == Value.new(:number => 7)

This behavior works as expected when using the deprecated include Virtus::ValueObject but is not preserved with the newer include. The equality behavior seems to be provided by ValueObject::ClassMethods which does not get extended when a value object class is constructed using the builder.

I took a quick crack at correcting the issue but I'm pretty sure I'm going down the wrong path. Including the class methods fixes equality but seems to introduce conflicting ideas about how to set options on attributes. Can you provide some guidance?

Extend value object classes with ValueObject::ClassMethods which adds an
equalizer to the class. The existing integration test for value objects using
the deprecated `include ValueObject` is updated to use the new include.
@solnic
Copy link
Owner

solnic commented Feb 25, 2015

You need to wrap attribute definitions in a values do .. end block. That's horrible I have to admit so it's going away in Virtus 2.0. Sorry about that.

@solnic solnic closed this Feb 25, 2015
@betamatt
Copy link
Author

Oof. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants