Permalink
Browse files

add spec for nested attribute

  • Loading branch information...
1 parent bd16024 commit 2ddedb13191076707edceeaa948534cbfc22d954 @aklaiber aklaiber committed with rmm5t Mar 19, 2013
Showing with 25 additions and 0 deletions.
  1. +25 −0 spec/mongoid_spec.rb
View
@@ -666,6 +666,31 @@ def filename
include_examples "double embedded documents"
end
end
+
+ describe 'with embedded documents and nested attributes' do
+ before do
+ @embedded_doc_class = define_mongo_class('MongoLocation') do
+ include Mongoid::Document
+ mount_uploader :image, @uploader
+ embedded_in :mongo_user
+ end
+
+ @class.class_eval do
+ embeds_many :mongo_locations
+ accepts_nested_attributes_for :mongo_locations
+ end
+
+ @doc = @class.new(mongo_locations_attributes: [{image: stub_file("old.jpeg")}])
+ @doc.save.should be_true
+ @embedded_doc = @doc.mongo_locations.first
+ end
+
+ it "should set the image on a save" do
+ @doc.reload
+ @doc.mongo_locations.first.image.path.should match(/old\.jpeg$/)
+ @embedded_doc.image.path.should match(/old\.jpeg$/)
+ end
+ end
end
describe '#mount_uploader removing old files with versions' do

0 comments on commit 2ddedb1

Please sign in to comment.