Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to use FactoryGirl with Rails 3.1 attr_accessible ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Man Vuong Ha Thanh  
View profile  
 More options Sep 28 2012, 8:06 am
From: Man Vuong Ha Thanh <thanhman...@gmail.com>
Date: Fri, 28 Sep 2012 05:06:23 -0700 (PDT)
Local: Fri, Sep 28 2012 8:06 am
Subject: How to use FactoryGirl with Rails 3.1 attr_accessible ?

I have a model like this:

class Customer < ActiveRecord::Base
  attr_accessible :name
  attr_accessible :name, :credit_rating, :as => :admin

end

To set the credit_rating attribute we must do:

c = Customer.create!({
      :name => "Customer",
      :credit_rating => 2.5
    }, :as => :admin)

How can we define this in Factory?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Clayton  
View profile  
 More options Sep 28 2012, 8:15 am
From: Josh Clayton <jclay...@thoughtbot.com>
Date: Fri, 28 Sep 2012 05:15:51 -0700 (PDT)
Local: Fri, Sep 28 2012 8:15 am
Subject: Re: How to use FactoryGirl with Rails 3.1 attr_accessible ?

FactoryGirl assigns each attribute directly, which bypasses
attr_accessible. The article
here: https://github.com/thoughtbot/factory_girl/wiki/How-factory_girl-inte...
explains how FactoryGirl and ActiveRecord interact more explicitly, but
declaring the factory as

factory :customer do
  name 'My wonderful customer'
  credit_rating 2.5
end

should be fine.

Best of luck!

On Friday, September 28, 2012 8:06:23 AM UTC-4, Man Vuong Ha Thanh wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »