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

Comments

Projects
None yet
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

This comment has been minimized.

Show comment
Hide comment
@dchelimsky

dchelimsky Sep 6, 2011

Member

Is this only when it's an association?

Member

dchelimsky commented Sep 6, 2011

Is this only when it's an association?

@cbron

This comment has been minimized.

Show comment
Hide comment
@cbron

cbron Sep 6, 2011

yup, it works fine outside of associations.

cbron commented Sep 6, 2011

yup, it works fine outside of associations.

@dchelimsky

This comment has been minimized.

Show comment
Hide comment
@dchelimsky

dchelimsky Sep 6, 2011

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.

Member

dchelimsky commented Sep 6, 2011

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

This comment has been minimized.

Show comment
Hide comment
@mrnbrkt

mrnbrkt 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?

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

This comment has been minimized.

Show comment
Hide comment
@dchelimsky

dchelimsky Sep 27, 2011

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.

Member

dchelimsky commented Sep 27, 2011

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