spec/functional/dirty_spec.rb in mongo_mapper-0.15.1 vs spec/functional/dirty_spec.rb in mongo_mapper-0.15.2
- old
+ new
@@ -278,9 +278,30 @@
doc = @document.create(:a => "b")
@document.find(doc.id).previous_changes.should be_blank
end
end
+ context "Document having Array key with typecast option" do
+ before do
+ @author_id = BSON::ObjectId.new
+ @doc = Doc('Book') { key :author_ids, Array, typecast: "ObjectId" }
+ @doc.plugin MongoMapper::Plugins::Dirty
+ @book = @doc.create!(author_ids: [@author_id])
+ end
+
+ context "changed" do
+ it "should be empty if assigned the same array" do
+ @book.author_ids = [@author_id]
+ @book.changed.should be_empty
+ end
+
+ it "should be empty if assigned the same but before-typecasted array" do
+ @book.author_ids = [@author_id.to_s]
+ @book.changed.should be_empty
+ end
+ end
+ end
+
context "Embedded documents" do
before do
@edoc = EDoc('Duck') { key :name, String }
@edoc.plugin MongoMapper::Plugins::Dirty
@document = Doc('Long') { key :name, String }