Browse files

Added equality.

  • Loading branch information...
1 parent c3f589b commit 019a0f9c0a515b60e1d5458577c28b0c783a2865 @jnunemaker committed Dec 28, 2010
Showing with 34 additions and 0 deletions.
  1. +6 −0 lib/scam.rb
  2. +28 −0 spec/scam_spec.rb
View
6 lib/scam.rb
@@ -39,4 +39,10 @@ def instances
def initialize(attrs={})
attrs.each { |key, value| send("#{key}=", value) }
end
+
+ def eql?(other)
+ other.class == self.class && other.id == id
+ end
+
+ alias == eql?
end
View
28 spec/scam_spec.rb
@@ -124,4 +124,32 @@
FeedTemplate.should include(@template)
end
end
+
+ describe "#eql?" do
+ it "returns true if same class and id" do
+ FeedTemplate.new(:id => 1).should eql(FeedTemplate.new(:id => 1))
+ end
+
+ it "returns false if different class" do
+ FeedTemplate.new(:id => 1).should_not eql(Class.new.new)
+ end
+
+ it "returns false if different id" do
+ FeedTemplate.new(:id => 1).should_not eql(FeedTemplate.new(:id => 2))
+ end
+ end
+
+ describe "#==" do
+ it "returns true if same class and id" do
+ FeedTemplate.new(:id => 1).should == FeedTemplate.new(:id => 1)
+ end
+
+ it "returns false if different class" do
+ FeedTemplate.new(:id => 1).should_not == Class.new.new
+ end
+
+ it "returns false if different id" do
+ FeedTemplate.new(:id => 1).should_not == FeedTemplate.new(:id => 2)
+ end
+ end
end

0 comments on commit 019a0f9

Please sign in to comment.