Skip to content
Browse files

Made the S3::Object#== method more robust so comparing an instance of…

… S3::Object to nil (s3obj == nil) doesn't throw a NoMethodError anymore.
  • Loading branch information...
1 parent eff6553 commit 946e97e66a4b13d8a931bfcfe13643132927696a @fjoachim fjoachim committed with Jakub Kuźma Sep 4, 2010
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/s3/object.rb
  2. +6 −0 test/object_test.rb
View
2 lib/s3/object.rb
@@ -17,7 +17,7 @@ class Object
# of the objects are the same, and both have the same buckets (see
# Bucket equality)
def ==(other)
- self.key == other.key and self.bucket == other.bucket
+ other.equal?(self) || (other.instance_of?(self.class) && self.key == other.key && self.bucket == other.bucket)
end
# Returns full key of the object: e.g. <tt>bucket-name/object/key.ext</tt>
View
6 test/object_test.rb
@@ -40,6 +40,12 @@ def setup
S3::Object.send(:new, nil, :key => "/images/pictures/test images/Lena not full.png")
end
end
+
+ test "==" do
+ expected = false
+ actual = @object_lena == nil
+ assert_equal(expected, actual)
+ end
test "full key" do
expected = "images/Lena.png"

0 comments on commit 946e97e

Please sign in to comment.
Something went wrong with that request. Please try again.