Skip to content
Browse files

Respect models that are marked as safe.

  • Loading branch information...
1 parent f7b9214 commit 9fbda218d425f1f3ba0b40d16002db71d6a360f7 @hardbap hardbap committed Apr 15, 2011
Showing with 23 additions and 0 deletions.
  1. +5 −0 lib/joint.rb
  2. +18 −0 test/test_joint.rb
View
5 lib/joint.rb
@@ -76,6 +76,7 @@ def save_attachments
:_id => send(name).id,
:filename => send(name).name,
:content_type => send(name).type,
+ :safe => send(name).safe?
})
end
assigned_attachments.clear
@@ -112,6 +113,10 @@ def type
@instance.send("#{@name}_type")
end
+ def safe?
+ @instance.send(:class).safe?
+ end
+
def grid_io
@grid_io ||= @instance.grid.get(id)
end
View
18 test/test_joint.rb
@@ -9,6 +9,10 @@ class Asset
attachment :file
end
+class SafeAsset < Asset
+ safe
+end
+
class BaseModel
include MongoMapper::Document
plugin Joint
@@ -83,6 +87,20 @@ def teardown
BaseModel.joint_collection_name.should == 'base_attachments'
end
+ should "respect the model's safe option setting" do
+ unsafe_doc = Asset.new(:image => @image, :file => @file)
+ rewind_files
+ Mongo::Grid.any_instance.expects(:put).twice.with(anything, has_entries(:safe => false))
+
+ unsafe_doc.save
+
+ safe_doc = SafeAsset.new(:image => @image, :file => @file)
+ rewind_files
+ Mongo::Grid.any_instance.expects(:put).twice.with(anything, has_entries(:safe => true))
+
+ safe_doc.save
+ end
+
context "with inheritance" do
should "add attachment to attachment_names" do
BaseModel.attachment_names.should == Set.new([:file])

0 comments on commit 9fbda21

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