Skip to content

Commit 29ec3db

Browse files
committed
Fix issue #48 by adding a proper hierarchy model hash implementation.
1 parent 36c646e commit 29ec3db

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/closure_tree/acts_as_tree.rb

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def ==(comparison_object)
4040
self.attributes == comparison_object.attributes
4141
end
4242
alias :eql? :==
43+
def hash
44+
attributes.hash
45+
end
4346
RUBY
4447

4548
self.hierarchy_class.table_name = hierarchy_table_name

spec/tag_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ def nuke_db
130130
TagHierarchy.find_all_by_ancestor_id(@root.id).should == root_hiers
131131
TagHierarchy.find_all_by_descendant_id(@root.id).should == root_hiers
132132
end
133+
134+
it "should have different hash codes for each hierarchy model" do
135+
hashes = TagHierarchy.all.map(&:hash)
136+
hashes.should =~ hashes.uniq
137+
end
138+
139+
it "should return the same hash code for equal hierarchy models" do
140+
TagHierarchy.first.hash.should == TagHierarchy.first.hash
141+
end
133142
end
134143

135144
it "performs as the readme says it does" do

0 commit comments

Comments
 (0)