Hi everyone,

I have the following classes:

class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :timeoutable,
:recoverable, :rememberable, :trackable, :validatable

has_many :comments, :dependent => destroy
...
end

class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :commentable, :polymorphic => true
...
end

In rails console, I can successfully create a new comment via user:
@attr = { :title => "Something", :content => "Something else" }
@user.comments.create!(@attr) # this command runs successfully
However, when I try to do the same thing in RSpec, I get the following
error:

Failure/Error: @user.comments.create!(@attr)
NoMethodError:
undefined method `comments' for #<User:0x00000004867000>

Has anyone seen this before? Could it have anything to do with the
combination of RSpec and Devise?

Thanks in advance,

Mike

I'm using Rails 3.1.0, Ruby 1.9.2p290, and RSpec 2.6.4.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 4, '12 at 5:09a
activeFeb 4, '12 at 5:09a
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Mike Kim: 1 post

People

Translate

site design / logo © 2021 Grokbase