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

  • Home
  • SEARCH
  • 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 6474889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:38:25+00:00 2026-05-25T06:38:25+00:00

I have built a simple rails app with three classes that inherit from ActiveRecord

  • 0

I have built a simple rails app with three classes that inherit from ActiveRecord so far. I am a little bit ahead on my test driven development as I’ve already written the classes I need to test. Thus far the tests that I’ve written have all gone well. Objects are being created, attributes are responding, validations are all in place.

The problem begins when I invoke the “!” on my create methods, since now the objects are being passed all the way along to the database. Instead of my normal validations intercepting the invalid inputs it seems the database is being given a chance to respond to the stimulus.

Thus far the error which I’ve received when running my tests is:

ActiveRecord::RecordInvalid:
Validation failed: Shop is too long (maximum is 11 characters)

I’m glad that I am getting this error but would like to know how to plan for it better in my tests. The code that generates the above error is:

  it "should not a accept a department with a shopify shop_id that's over 11 chars" do
    long_id = "9" * 12
    long_id_department = Department.create!(@attr.merge(:id => [long_id, ""]))
    long_id_department.should_not be_valid
  end

I presume that this line in particular should assume some other form: long_id_department.should_not be_valid

Hoping you all could shed some light on what that form should be.

  • 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-25T06:38:26+00:00Added an answer on May 25, 2026 at 6:38 am

    The shoulda gem makes testing your validations a piece of cake. The more recent shoulda releases are built as an add-on to RSpec.

    The documentation for the specific type of validation you’re attempting is here.

    You’ll end up with test code that looks like this.

    describe Department do
      it { should ensure_length_of(:id).is_at_most(11) }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, and thanks for looking. I have built the simple D2D app from
We have already built a rails app that has several users and an image
I have a simple Video model in my rails app that has_many comments. I
I've built a Rails app that's pretty simple... you send a request to a
I have built a very simple blog application using Ruby on Rails. New to
I have built a simple C#.Net app on a M/C with only .Net FX
I have a simple web app built in asp.net webforms c# where and how
I have made a simple Rails application that allows people to comment on posts.
I have a really simple Rails application that allows users to register their attendance
I have built a simple word addin that interacts with a company intranet. For

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.