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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:56:47+00:00 2026-06-12T05:56:47+00:00

I worked through all of Michael Hartl’s Ruby on Rails Tutorial with all the

  • 0

I worked through all of Michael Hartl’s Ruby on Rails Tutorial with all the tests passing. Now that I’m going back and making changes to the site to suit my own needs, it’s not as cut and dry as “the tests in this section aren’t passing.” I’ve created a new “Charity” object that is strongly based on Hartl’s “Micropost” object. The only difference is that instead of having “content” the object has a :name, :description and :summary.

This is the code for the test that is failing, (specifically “it { should be_valid }”) which is located in /charity_spec.rb:

require 'spec_helper'

    describe Charity do

      let(:user) { FactoryGirl.create(:user) }
      before { @charity = user.charities.build(summary: "Lorem ipsum") }

      subject { @charity }

      it { should respond_to(:name) }
      it { should respond_to(:user_id) }
      it { should respond_to(:summary) }
      it { should respond_to(:description) }
      it { should respond_to(:user) }
      its(:user) { should == user }
      it { should be_valid }
      ...

The test actually passes at first, but once I add the validations to the charity.rb file, they return;

 Failures:
   1) Charity
      Failure/Error: it { should be_valid }
         expected valid? to return, true, got false
         ...

Here’s the charity.rb:

class Charity < ActiveRecord::Base
  attr_accessible :name, :description, :summary
  belongs_to :user

  validates :name, presence: true, length: { maximum: 40 }
  validates :summary, presence: true
  validates :description, presence: true
  validates :user_id, presence: true

  default_scope order: 'charities.created_at DESC'
end

I’m sure it’s something stupid, but my understanding of everything is so weak I can’t figure out what I’m doing wrong, my feeling is that it’s something wrong with my factory, but I really don’t know.

Here’s my charity factory located in the factories.rb:

factory :charity do
    name "Lorem ipsum"
    summary "Lorem ipsum"
    description "Lorem ipsum"
    user
end

When I remove the :name, :summary, and :description validations from charity.rb, the test passes. For good measure, here’s the beginning of my user.rb:

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation 
  has_secure_password
  has_many :charities
  has_many :microposts, dependent: :destroy
  • 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-12T05:56:48+00:00Added an answer on June 12, 2026 at 5:56 am

    Use your factory to have a proper charity:

    before { @charity = user.charities.build(FactoryGirl.attributes_for(:charity)) }
    

    It failed because you validate presence of attributes which were not set like name

    If you need more background on FactoryGirl, their documentation is really good.

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

Sidebar

Related Questions

I am following the Ruby on Rails tutorial by Michael Hartl http://ruby.railstutorial.org/ I installed
Hi I worked through Michael Hartl's RAILSTUTORIAL book and I have a question about
I want to iterate through all 5 character combinations of 0-9, a-z. I worked
I've worked myself through the rapidXML sources and managed to read some values. Now
I had some code that ran commands through Runtime.getRuntime.exec(String) , and it worked on
I have an Java applet that loads native code through JNI. Everything worked just
All right, after having worked through Cocoa Dev Central's Build a Core Data Application
new to IOS OpenGL programming. I have worked through a few tutorials that talk
I just worked through a book on WCF and was surprised that it didn't
I worked through the Fluent NHibernate tutorial at http://wiki.fluentnhibernate.org/Getting_started and the project compiles fine.

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.