test/unit/test_ar_side.rb in bigamy-0.2.0 vs test/unit/test_ar_side.rb in bigamy-0.2.1
- old
+ new
@@ -99,10 +99,20 @@
setup do
@user.save! && @u1.save! && @u2.save!
@user.docs = [@u1, @u2]
end
+ should "clear on nil assignment" do
+ @user.docs = nil
+ assert_equal [], Doc.find_by_user_id(@user.id)
+ end
+
+ should "clear on nil assignment" do
+ @user.docs = nil
+ assert_equal [], Doc.find_all_by_user_id(@user.id)
+ end
+
should "assign user_id on docs" do
assert Doc.find(@u1.id, @u2.id).all? {|x| x.user_id == @user.id}
end
should "retrieve targets" do
@@ -133,21 +143,31 @@
assert_raises(Bigamy::NewRecordAssignment) do
@user.doc = @doc
end
end
- context "with a saved doc" do
- setup { @doc.save! }
-
- should "save user" do
+ context "with a saved doc and user" do
+ setup do
+ @doc.save!
@user.doc = @doc
@user.save!
+ end
+ should "save user" do
assert !@user.doc_id.nil?
assert_equal @user.doc_id, @doc.id
assert_equal 1, Doc.count
assert_equal 1, User.count
end
+
+ should "clear relationship on nil assignment" do
+ @user.doc = nil
+ @user.save!
+
+ u = User.find(@user.id)
+ assert_equal nil, u.doc_id
+ end
+
end
end
end
end