Skip to content

Can't use mock_model on a model that hasn't been implemented yet in 3.1 #435

Closed
cbron opened this Issue Sep 6, 2011 · 5 comments

3 participants

@cbron
cbron commented Sep 6, 2011

When mocking out models that don't exist in Rails 3.1 like this:
Message.rb

belongs_to :recipient, :class_name => "User"

Message_spec.rb

@message = Message.new(:title => "title", :text => "foo", :recipient => mock_model("User"))

When I run tests i get this:

 NoMethodError:
      undefined method `primary_key' for User:Class

Of course its fixed by creating the user model.

@dchelimsky
RSpec member

Is this only when it's an association?

@cbron
cbron commented Sep 6, 2011

yup, it works fine outside of associations.

@dchelimsky
RSpec member

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.

@dchelimsky dchelimsky closed this in cf3f04c Sep 6, 2011
@mrnbrkt
mrnbrkt commented Sep 27, 2011

Pardon me for asking, but if mock_model is becoming obsolete and has to be phased out, what are the recommended alternatives?

@dchelimsky
RSpec member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.