From 2e0e6a8635f6a5f3cd4a650954d8df43c7634496 Mon Sep 17 00:00:00 2001 From: Bas Vodde Date: Wed, 30 Apr 2014 21:41:16 +0800 Subject: [PATCH] Equal operator for SubjectData --- lib/highrise/subject_data.rb | 4 ++++ spec/highrise/subject_data_spec.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/highrise/subject_data.rb b/lib/highrise/subject_data.rb index 5ea9d24..b09d638 100644 --- a/lib/highrise/subject_data.rb +++ b/lib/highrise/subject_data.rb @@ -1,4 +1,8 @@ module Highrise class SubjectData < Base + def==other + attributes["value"] == other.attributes["value"] && + attributes["subject_field_label"] == other.attributes["subject_field_label"] + end end end \ No newline at end of file diff --git a/spec/highrise/subject_data_spec.rb b/spec/highrise/subject_data_spec.rb index 78c3d6b..4391e73 100644 --- a/spec/highrise/subject_data_spec.rb +++ b/spec/highrise/subject_data_spec.rb @@ -2,4 +2,23 @@ describe Highrise::SubjectData do it { should be_a_kind_of Highrise::Base } + + it "Two different subject datas with different values are not equal" do + martini = Highrise::SubjectData.new({:id => 1, :value => "Martini", :subject_field_id => 3, :subject_field_label => "Cocktail"}) + sling = Highrise::SubjectData.new({:id => 2, :value => "Singapore Sling", :subject_field_id => 4, :subject_field_label => "Cocktail"}) + martini.should_not==sling + end + + it "Two different subject datas with different labels are not equal" do + martini = Highrise::SubjectData.new({:id => 1, :value => "Martini", :subject_field_id => 3, :subject_field_label => "Cocktail"}) + sling = Highrise::SubjectData.new({:id => 2, :value => "Martini", :subject_field_id => 4, :subject_field_label => "Vermouth Brands"}) + martini.should_not==sling + end + + it "Two the same subject datas are equal" do + martini = Highrise::SubjectData.new({:id => 1, :value => "Martini", :subject_field_id => 3, :subject_field_label => "Cocktail"}) + another_martini = Highrise::SubjectData.new({:id => 2, :value => "Martini", :subject_field_id => 4, :subject_field_label => "Cocktail"}) + martini.should==another_martini + end + end \ No newline at end of file