When mocking out models that don't exist in Rails 3.1 like this:
belongs_to :recipient, :class_name => "User"
@message = Message.new(:title => "title", :text => "foo", :recipient => mock_model("User"))
When I run tests i get this:
undefined method `primary_key' for User:Class
Of course its fixed by creating the user model.
Is this only when it's an association?
yup, it works fine outside of associations.
Looks like ActiveRecord 3.1 increased the number of non-ActiveModel methods it calls on associations. I'm going to go ahead and patch this, but this suggests to me we should phase mock_model out.
Define primary_key method on class generated by mock_model("WithAStri…
- Closes #435.
Pardon me for asking, but if mock_model is becoming obsolete and has to be phased out, what are the recommended alternatives?
It's not a given at this point, so I wouldn't worry about it. If/when it happens there will be plenty of warning and recommendations.