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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:10:26+00:00 2026-06-07T18:10:26+00:00

I am a complete newby at RoR and I am working through the Hartl

  • 0

I am a complete newby at RoR and I am working through the Hartl rails tutorial (http://ruby.railstutorial.org/). I am stuck on the tests for section 10.1.4 I keep on getting the following errors:

Failures:

1) User micropost associations should destroy associated microposts
Failure/Error: FactoryGirl.create(:micropost, user: @user, created_at: 1.day.ago)
NoMethodError:
undefined method content=' for #<User:0x007fce7c86b1e8>
# ./spec/models/user_spec.rb:147:in
block (3 levels) in ‘

2) User micropost associations should have the right microposts in the right order
Failure/Error: FactoryGirl.create(:micropost, user: @user, created_at: 1.day.ago)
NoMethodError:
undefined method content=' for #<User:0x007fce7cbd6288>
# ./spec/models/user_spec.rb:147:in
block (3 levels) in ‘

Since I am such a newbie my debugging capabilities are rather limited. I am sure this is not a huge issue so I would appreciate any help that I can get, here is the code I have:

USER_SPEC.RB

    require 'spec_helper'

    describe User do

      # Before means this code will run before every test is performed  
      before do
        @user = User.new(name: "Example User", email: "user@example.com",
                         password: "foobar", password_confirmation: "foobar")
      end

      subject { @user }

      it { should respond_to(:admin) }
      it { should respond_to(:authenticate) }
      it { should respond_to(:name) }
      it { should respond_to(:email) }
      it { should respond_to(:password_digest) }
      it { should respond_to(:password) }
      it { should respond_to(:password_confirmation) }
      it { should respond_to(:microposts) } 

      it { should be_valid }
      it { should_not be_admin }

      .
      .
      .
      .

      describe "micropost associations" do

        before { @user.save }
        let!(:older_micropost) do
          FactoryGirl.create(:micropost, user: @user, created_at: 1.day.ago)
        end
        let!(:newer_micropost) do
          FactoryGirl.create(:micropost, user: @user, created_at: 1.hour.ago)
        end

        it "should destroy associated microposts" do
          microposts = @user.microposts
          @user.destroy
          microposts.each do |micropost|
            Micropost.find_by_id(micropost.id).should be_nil
          end
        end

        it "should have the right microposts in the right order" do
          @user.microposts.should == [newer_micropost, older_micropost]
        end
      end
    end

USER.RB

    class User < ActiveRecord::Base
      attr_accessible :name, :email, :password, :password_confirmation
      has_secure_password
      has_many :microposts, dependent: :destroy

      before_save { self.email.downcase! }
      before_save :create_remember_token

      validates :name, presence: true, length: { maximum: 50 }

      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
      validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
                uniqueness: { case_sensitive: false }

      validates :password, presence: true, length: { minimum: 6 }
      validates :password_confirmation, presence: true

      private

        def create_remember_token
          self.remember_token = SecureRandom.urlsafe_base64
        end

    end

MICROPOST_SPEC.RB

    require 'spec_helper'

    describe Micropost do

      let(:user) { FactoryGirl.create(:user) }
      before { @micropost = user.microposts.build(content: "Lorem ipsum") }

      subject { @micropost }

      it { should respond_to(:content) }
      it { should respond_to(:user_id) }
      it { should respond_to(:user) }
      its(:user) { should == user }

      it { should be_valid }

      describe "when user_id is not present" do
        before { @micropost.user_id = nil }
        it { should_not be_valid }
      end

      describe "accessible attributes" do
        it "should not allow access to user_id" do
          expect do
            Micropost.new(user_id: user.id)
          end.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
        end    
      end
    end

MICROPOST.RB

    class Micropost < ActiveRecord::Base
      attr_accessible :content
      belongs_to :user

      validates :user_id, presence: true
      default_scope order: 'microposts.created_at DESC'
    end

FACTORIES.RB

    FactoryGirl.define do
      factory :user do
        sequence(:name)  { |n| "Person #{n}" }
        sequence(:email) { |n| "person_#{n}@example.com"}   
        password "foobar"
        password_confirmation "foobar"

        factory :admin do
          admin true
        end
      end

      factory :micropost do
        content "Lorem ipsum"
        user
      end
    end

AND LASTLY MY GEMFILE:

    source 'https://rubygems.org'

    gem 'rails', '3.2.5'
    gem 'jquery-rails', '2.0.0'
    gem 'bootstrap-sass', '2.0.0'
    gem 'bcrypt-ruby', '3.0.1'
    gem 'faker', '1.0.1'
    gem 'will_paginate', '3.0.3'
    gem 'bootstrap-will_paginate', '0.0.6'
    gem 'hirb'

    group :development, :test do
      gem 'sqlite3', '1.3.5'
      gem 'rspec-rails', '2.10.0'
      gem 'guard-rspec', '0.5.5'
    end

    # Gems used only for assets and not required
    # in production environments by default.
    group :assets do
      gem 'sass-rails',   '3.2.4'
      gem 'coffee-rails', '3.2.2'
      gem 'uglifier', '1.2.3'
    end

    group :test do
      gem 'capybara', '1.1.2'
      gem 'factory_girl_rails', '1.4.0'
      gem 'cucumber-rails', '1.2.1', :require => false
      gem 'database_cleaner', '0.7.0'
      gem 'guard-spork', '0.3.2'  
      gem 'spork', '0.9.0'
      gem 'launchy', '2.1.0'
      gem 'rb-fsevent', '0.9.1', :require => false
      gem 'growl', '1.0.3'
    end

    group :production do
      gem 'pg', '0.12.2'
    end

Thank you for any help I an get on this.

  • 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-07T18:10:27+00:00Added an answer on June 7, 2026 at 6:10 pm

    Since you added the :micropost factory to spec/factories.rb in section 10.1.4, your additions to that file will be reflected once you restart Spork.

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

Sidebar

Related Questions

Complete new person to Ruby and Rails here... Have tried some tutorials in the
While I'm not a complete Ruby/Rails newb, I'm still pretty green and I'm trying
I am a complete Ruby newby and am playing around with rspec I am
Newb RoR developer here, standing at the finish line of my first paying Rails
I'm a complete newb to Django working on a sample app. It appears that
Complete newby question - I've looked everywhere (as I'm not a .NET dev finding
Howdy, Now I'm a complete newby to .Net and the likes of VB (I'm
This is a complete newb question but I'm trying to run through the Lift-in-Action
I'm currently working on a site that has a hidden section (schedule, rates). When
I keep having problems with programs in Python (I'm a complete newb) where it

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.