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 6904519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:04:17+00:00 2026-05-27T08:04:17+00:00

There is field name active in customer table. It validates as below in customer.rb:

  • 0

There is field name active in customer table. It validates as below in customer.rb:

validates :active, :presence => true

Here is the rspec code to test a field short_name:

it "should be OK with duplicate short_name in different active status" do
  customer = Factory(:customer, :active => false, :short_name => "test user")
  customer1 = Factory.build(:customer, :active => true, :short_name => "Test user")
  customer1.should be_valid           
end

Validation for short_name is:

  validates :short_name, :presence => true, :uniqueness => { :scope => :active }

The above code causes the error:

  1) Customer data integrity should be OK with duplicate short_name in different active status
     Failure/Error: customer = Factory(:customer, :active => false, :short_name => "test user")
     ActiveRecord::RecordInvalid:
       Validation failed: Active can't be blank
     # ./spec/models/customer_spec.rb:62:in `block (3 levels) in <top (required)>'

It seems that the false value assigned to field active was considered to be blank or nil by rspec and failed the data validation check. Tried to use 0 for false and it causes the same error. The rspec case passes if removing the validation for field active.

  • 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-27T08:04:18+00:00Added an answer on May 27, 2026 at 8:04 am

    This is not a rspec issue, it’s related to Rails’ validation. I suppose your active field is a boolean and, to quote the validates_presence_of documentation:

    If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true

    So simply change your validator to something like the following (assuming you want the “sexy” syntax) and it should work:

    validates :active, :inclusion => [true, false]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any possibility of changing the MySQL DB table's field name or adding
in an sql table there's an id, first name and last name field. i'd
Is there a way to get a specific field name from a template with
Consider i have a registartion table and there is field prefLocationId and it contains
I have one label field and three buttons with the name of red, yellow,
I have a database table (named Topics) which includes these fields : topicId name
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
Is there a field or anyway to retreave the smtp server of a user
Say I have a table with a field called ordernum that denotes the order
Is there a way with MySQL (5.0 specifically) to have an auto_increment field who's

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.