Hi!

I'm using Rspec and factory_girl. In my products model I have a method that
creates permalinks simply by overriding to_param, like this:

def create_permalink
self.permalink = "#{self.name} #{self.brand.name}".parameterize
end

My product factory looks like this:

Factory.define :product do |p|
p.sequence(:name) { |n| 'Product Name #{n}'}
p.gender 'Man'
p.sequence(:price) { |n| 123.00 + n }
p.product_url 'http://www.example.com/prod-url'
p.association :reseller
p.association :subcategory
end


Then when I try to use the factory in Rspec, like this:

Factory.create(:product)

I get the following error:

Failure/Error: Factory.create(:product)
NoMethodError: undefined method `name' for nil:NilClass


Why is that?

Regards
Linus

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Z84Fe91Ica4J.
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

  • Dave Aronson at Jan 1, 2012 at 4:45 pm

    On Thu, Dec 29, 2011 at 05:28, Linus Pettersson wrote:

    def create_permalink
    self.permalink = "#{self.name} #{self.brand.name}".parameterize
    end ...
    Failure/Error: Factory.create(:product)
    NoMethodError: undefined method `name' for nil:NilClass

    Why is that?
    My guess would be that you're not setting self.brand. I don't see
    anything in the Factory setting it.

    -Dave

    --
    Dave Aronson, President, Dave Aronson Software Engineering and Training
    Ruby on Rails Freelancing (Northern Virginia, Washington DC, or Remote)
    DaveAronson.com, Codosaur.us, Dare2XL.com, & RecruitingRants.com (NEW!)
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (me)

    --
    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.
  • Linus Pettersson at Jan 2, 2012 at 10:04 am
    Of course... Thank you! Sometimes when you've looked for too long on the
    code you get blind :)

    Regards
    Linus

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/AfHG7WIXgmkJ.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 29, '11 at 10:28a
activeJan 2, '12 at 10:04a
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Linus Pettersson: 2 posts Dave Aronson: 1 post

People

Translate

site design / logo © 2021 Grokbase