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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:49:07+00:00 2026-05-16T17:49:07+00:00

Through rspec (I’m using rspec-1.3.0, rspec-rails-1.3.2 gems) generator ( ruby script/generate rspec_model suggestion section_id:integer

  • 0

Through rspec (I’m using rspec-1.3.0, rspec-rails-1.3.2 gems) generator (ruby script/generate rspec_model suggestion section_id:integer user_id:integer subject:string content:text state:string type:string) I created model and model spec and run rake db:migrate and rake:test:prepare

After that I started to work on my model spec:

require 'spec_helper'

describe Suggestion do
  before(:each) do
    @valid_attributes = {
      :section_id => 1,
      :user_id => 1,
      :subject => 'Inappropriate title',
      :content => 'The title of this section is inappropriate.',
      :state => 'new',
      :type => 'flag'
    }
  end

  it "should create a new instance given valid attributes" do
    Suggestion.create!(@valid_attributes)
  end

  it "should reject empty section_id attribute" do 
    empty_section_id_suggestion = Suggestion.new(@valid_attributes.merge(:section_id => ""))
    empty_section_id_suggestion.should_not be_valid
  end

  ...

Apart from 1st "should create a new instance given valid attributes" test I created 6 tests, basically each testing attribute of suggestion model for being empty – almost exactly same as "should reject empty section_id attribute" example.

When I run tests I get 6 failed tests, which is fine. First test "should create a new instance given valid attributes" passes.

Now when I go the the suggestion model and add validates_presence_of :all I get following error message related to 1st test:

ActiveRecord::RecordInvalid in 'Suggestion should create a new instance given valid attributes'
Validation failed: All can't be blank
./spec/models/suggestion_spec.rb:16:

When I try to run tests in isolation (validates_presence_of :attribute) all tests are passing, only with :type attribute I get again similar error message:

ActiveRecord::RecordInvalid in 'Suggestion should create a new instance given valid attributes'
Validation failed: Type can't be blank
./spec/models/suggestion_spec.rb:16:

I haven’t encountered this problem before (have multiple similar models and their specs passing properly). It looks like it has problem with the :type attribute (it says it can’t be empty), even I’m passing value to it through @valid_attributes. I tried to Google search but didn’t find similar problem/solution.

Here is the test for :type attribute

it "should reject empty type attribute" do 
        empty_type_suggestion = Suggestion.new(@valid_attributes.merge(:type => ""))
        empty_type_suggestion.should_not be_valid
  end

Please check it out and let me know what I’m doing wrong here.

Thanks a lot for help

Peter

  • 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-16T17:49:07+00:00Added an answer on May 16, 2026 at 5:49 pm

    in your model you cant just say validate :all because :all isnt a column name.

    class Suggestion < AR::Base
      validates_pressence_of :subject, :content
    end
    

    there would be no reason to validate the presence of id columns but i guess you can if you want.

    api documentation:
    http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates_presence_of

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

Sidebar

Related Questions

I'm having a frustrating time with Rspec while working through the Ruby on Rails
So I'm using rspec to test my code as I'm going through the Rails
I'm going through a tutorial that has suggested using rspec , but I have
I'm working through the Ruby on Rails 3 Tutorial: Learn Rails by Example by
I have a Page scaffold that I created through rails generate scaffold. I ran
I'm working through the Ruby on Rails Tutorial and I'm getting stuck on the
I've been working through the Ruby on Rails Tutorial. I've run into a problem
While using RSpec (2.10.0), machinist (2.0), rspec-rails (2.10.1) and rails (2.3.6) I am having
I am testing a controller in rails using rspec. The response body is just
I'm trying to walk through Hartl's Ruby on Rails tutorial whilst upgrading his examples

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.