Skip to content
Browse files

Added boolean method to check if attachment has been assigned (has id).

  • Loading branch information...
1 parent 065f5f1 commit 5e28b96be1db3b46dc019517053fcd31f8d613b5 @jnunemaker jnunemaker committed Mar 29, 2010
Showing with 13 additions and 0 deletions.
  1. +4 −0 lib/joint.rb
  2. +9 −0 test/test_joint.rb
View
4 lib/joint.rb
@@ -27,6 +27,10 @@ def #{name}
@#{name} ||= AttachmentProxy.new(self, :#{name})
end
+ def #{name}?
+ self.send(:#{name}_id?)
+ end
+
def #{name}=(file)
self["#{name}_id"] = Mongo::ObjectID.new
self["#{name}_size"] = File.size(file)
View
9 test/test_joint.rb
@@ -79,13 +79,22 @@ def teardown
@doc.pdf.read.should == @pdf_contents
@doc.image.read.should == @image_contents
end
+
+ should "know that attachment exists" do
+ @doc.image?.should be(true)
+ @doc.pdf?.should be(true)
+ end
end
context "Retrieving attachment that does not exist" do
setup do
@doc = Foo.create
end
+ should "know that the attachment is not present" do
+ @doc.image?.should be(false)
+ end
+
should "raise Mongo::GridError" do
assert_raises(Mongo::GridError) { @doc.image.read }
end

0 comments on commit 5e28b96

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