Permalink
Browse files

Add spec for Virtus::ValueObject::Equalizer#<<

  • Loading branch information...
1 parent 9cc4918 commit b06a3b6cafea9d0b2c73e85b4bb2b5cc6016e945 @solnic committed Mar 19, 2012
Showing with 59 additions and 2 deletions.
  1. +1 −0 lib/virtus/value_object/equalizer.rb
  2. +58 −2 spec/unit/virtus/value_object/equalizer/append_spec.rb
View
1 lib/virtus/value_object/equalizer.rb
@@ -122,3 +122,4 @@ def compile_keys(separator = ' ', &block)
end # class Equalizer
end # module ValueObject
end # module Virtus
+
View
60 spec/unit/virtus/value_object/equalizer/append_spec.rb
@@ -1,5 +1,61 @@
require 'spec_helper'
-describe Virtus::ValueObject::Equalizer, '#append' do
- it 'should have spec'
+describe Virtus::ValueObject::Equalizer, '#<<' do
+ let(:equalizer) { described_class.new(:user, [ :first_name ]) }
+
+ let(:klass) do
+ klass = Class.new { attr_accessor :first_name, :last_name }
+ klass.send(:include, equalizer)
+ end
+
+ let(:user_one) { klass.new }
+ let(:user_two) { klass.new }
+
+ let(:first_name) { 'john' }
+ let(:last_name) { 'doe' }
+
+ before do
+ equalizer << :last_name
+
+ user_one.first_name = first_name
+ user_one.last_name = last_name
+
+ user_two.first_name = first_name
+ user_two.last_name = last_name
+ end
+
+ describe "#eql?" do
+ subject { user_one.eql?(user_two) }
+
+ context 'when key values match' do
+ it { should be(true) }
+ end
+
+ context 'when key values match' do
+ before { user_two.last_name = 'other' }
+
+ it { should be(false) }
+ end
+ end
+
+ describe "#==?" do
+ subject { user_one == user_two }
+
+ context 'when key values match' do
+ it { should be(true) }
+ end
+
+ context 'when key values match' do
+ before { user_two.last_name = 'other' }
+
+ it { should be(false) }
+ end
+ end
+
+ describe "#hash" do
+ subject { user_one.hash }
+
+ it { should be(klass.hash ^ first_name.hash ^ last_name.hash) }
+ end
end
+

0 comments on commit b06a3b6

Please sign in to comment.