mongoid/mongoid — pull request #1449 by jasonsydes (2011-11-24 23:26:07+00:00)
Title: some specs to examine replacement on has_one relations 

Hi @durran. Thanks for your fix for #1442! I was trying to fix it myself, but got stuck.

The reason I got stuck was because I noticed that the code was probably going to result in this behavior:

```ruby
a = A.create!
b1 = a.build_b
b2 = a.create_b
```

The code above, I believe, results in b1 being saved when it's a dependent: :nullify relation with the current version of Mongoid.

So, in any case, this isn't really a real pull request. Feel free to discard some/all of it. What is included in this commit are some specs that test all of the has_one replacement cases -- I'm pretty sure it tackles all of them in the correct way, but you probably want to review them to make sure.

From what it looks like, the only spec in the submitted commit that fails is the following one (which is what is described in the code block above):

```
Failures:

1) Mongoid::Relations::Referenced::One#= when the relation is polymorphic when replacing an existing unpersisted (dependent: :nullify) relation with a new one created via the parent leaves the old child unpersisted
Failure/Error: cat.persisted?.should be_false
expected true to be false
# ./spec/functional/mongoid/relations/referenced/one_spec.rb:431:in `block (6 levels) in '

Finished in 23.98 seconds
137 examples, 1 failure
```

Should I create a new issue for this?

And thanks again for the fix you provided. It does work! And thanks again for some great code!