Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6558069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:09:15+00:00 2026-05-25T13:09:15+00:00

user_type is a column in user model and it has to be :presence =>

  • 0

user_type is a column in user model and it has to be :presence => true. It rejects in rspec when passing a nil to user_type. However the factory_girl can store a nil user_type into the field with sqlite3.

Running rails 3.1.0. rspec 2.6.0 and factory_girl 2.1.0

//user model:

  validates :user_type,  :presence => true  

//Factory girl definition:

Factory.define :user do |user|

  user.name                  "Test User"
  user.email                 "test@test.com"
  user.password              "password1"
  user.password_confirmation "password1"
  user.status                "active"
  user.user_type             "employee"

end

Factory.define :user_level do |level|

  level.role                 "sales"
  level.position             "member"
  level.team                 1
  level.association          :user
end

//rspec case: passed

  it "should reject user type nil" do
    user = Factory.build(:user, :user_type => nil)
    user.should_not be_valid  
  end

  it "should take user type 'employee'" do
    user = Factory.build(:user, :user_type => 'employee')
    user.errors[:user_type].should be_empty
    user.should be_valid
  end

Any thoughts? thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:09:15+00:00Added an answer on May 25, 2026 at 1:09 pm

    As Michael Hartl pointed out in his excellent Rails tutorial, Factory Girl bypasses attr_accessible in the model. For instance, you can overwrite the “magic” columns using Factory Girl. Perhaps this applies to validations as well?

    It seems like it would be better in this case to actually create your user with User.new, since you are testing the process of creation and validation itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Schema: class Checkpoint(db.Model): id = db.Column(db.Integer, primary_key=True) creator = db.Column(db.Integer, db.ForeignKey('user.id')) name =
I have a textfield where the user can type what ever he want into
I have an HTML form where the user can type in any number:5, 8,
I have three models: User Award Trophy The associations are: User has many awards
My model contains an enum, which are mapped by JPA to an int column
I have recently added a new column (age) to a database table (user). I
i have wpf application, a game of sudoku. I have a model and user
how can i massage attributes at the model level before active record converts them
I have a table that has a column that contains links. Each cell in
I have a user model that has_one profile, and the profile belongs to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.