mongoid/mongoid — Issue #1510: to_param error with stub_model
Author: tiagogodinho
Created: 2011-12-20 02:23:48+00:00
State: open

When I use Rails scaffold with Mongoid **2.4.0** the tests don't pass.

`spec/views/posts/index.html.erb_spec.rb`

```ruby
assign(:posts, [
stub_model(Post,
:title => "Title",
:text => "MyText"
),
stub_model(Post,
:title => "Title",
:text => "MyText"
)
])
```
`app/views/posts/index.html.erb`

```erb
<%= link_to 'Show', post %> // Error nil.join
```

When I call `to_param` return an error. I debug and discover that Mongoid override `to_key` method.

On Rails `to_key` return the id if post.persisted? returns true. In Mongoid 2.4 `to_key` call `new_record?` and don't work with stub_model.