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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:58:25+00:00 2026-06-16T01:58:25+00:00

I have a simple CRUD app with some basic validations for a Commodity model.

  • 0

I have a simple CRUD app with some basic validations for a Commodity model. The tests for those pass. OK, now I need to test against having no spaces, or more than one word for its name. I tested the below in console and it seemed to work so reading up on the rails guides on validations I wrote a custom validation below. Unfortunately running my tests, all fail now because it cannot create a commodity because it fails due to the custom validation I wrote. I’ve tried many different combinations of incorprating the validator starting with Railscasts #211 by combining it into the validates call. It’s probably something simple but if I yank out the call to the validator then the other basic tests pass. The error is: Validation failed: Name must be a single word (ActiveRecord::RecordInvalid)

 require_relative 'commodity_name_validator'
 class Commodity < ActiveRecord::Base
   attr_accessible :description, :name
   has_many :prices
   before_save { |commodity| commodity.name.capitalize! }
   validates :name, presence: true, length: { minimum: 4 }
   validate :commodity_name_validations
 end

 class CommodityNameValidator < ActiveModel::Validator
   def validate(record)
     if record.name.split(" ").length <= 1
       record.errors[:base] << "Name must be a single word"
     end
   end
 end

thnx, sam

  • 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-06-16T01:58:26+00:00Added an answer on June 16, 2026 at 1:58 am

    It appears this ‘stomp’ is due to cucumber throwing errors earlier when it encounters a basic error in this case. Thanks to @jorendorff pointing out that replacing my <= 1 to != 1 made this test pass and those previous to pass as well. I don’t know if it’s ruby’s reflection or what that causes previous passing tests to error out, I’m speaking out of ignorance. I just know that cucumber, at least, will throw errors that mislead to the real cause.

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

Sidebar

Related Questions

I'm making a simple CRUD app with ASP MVC and I want to have
I have some problem with IoC - Unity. I made a simple web app.
I have a simple Restlet service hosted on AppEngine. This performs basic CRUD operations
I have a very simple CRUD functional test suite for each and every controller
I am building a simple CRUD app (not using the CRUD module). My model
I have a simple Rails 3.1 CRUD app built using Oracle running on JRuby.
I have a simple Crud application where there is one filed called Category. During
I have written a simple CRUD form which has one select list. However the
I have simple win service, that executes few tasks periodically. How should I pass
I'm writing a very simple CRUD app that takes user stories and stores them

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.