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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:44:39+00:00 2026-05-30T10:44:39+00:00

I’ve been following the Rails Tutorial 3 successfully until I got to chapter 7

  • 0

I’ve been following the Rails Tutorial 3 successfully until I got to chapter 7 and implemented the user model, now my rspec keeps failing.

Here’s my user.rb file output

class User < ActiveRecord::Base
attr_accessible :name, :email

email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

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

validates :email,    :presence   => true,
                     :format     => { :with => email_regex },
                     :uniqueness => { :case_sensitive => false }

validates :password, :presence => true,
                     :confirmation => true,
                     :length => { :within => 6..40 }

before_save :encrypt_password

# Return tue if the user's password matches the submitted password.
    def has_password?(submitted_password)
        encrypted_password == encrypt(submitted_password)
    end

    def self.authenticate(email, submitted_password)
        user = find_by_email(email)
        return nil  if user.nil?
        return user if user.has_password?(submitted_password)
    end

private

def encrypt_password
  self.salt = make_salt unless has_password?(password)
  self.encrypted_password = encrypt(password)
end

def encrypt(string)
  secure_hash("#{salt}--#{string}")
end

def make_salt
  secure_hash("#{Time.now.utc}--#{password}")
end

def secure_hash(string)
  Digest::SHA2.hexdigest(string)
end
end

Here’s my users_spec.rb

require 'spec_helper'

describe User do

  before(:each) do
  @attr = { 
  :name => "Example User",
  :email => "user@example.com",
  :password => "foobar",
  :password_confirmation => "foobar"
    }
  end

  it "should create a new instance given a valid attribute" do
    User.create!(@attr)
  end

  it "should require a name" do
    no_name_user = User.new(@attr.merge(:name => ""))
    no_name_user.should_not be_valid
  end

  it "should require an email address" do
    no_email_user = User.new(@attr.merge(:email => ""))
    no_email_user.should_not be_valid
  end

  it "should reject names that are too long" do
    long_name = "a" * 51
    long_name_user = User.new(@attr.merge(:name => long_name))
    long_name_user.should_not be_valid
  end

  it "should accept valid email addresses" do
    addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
    addresses.each do |address|
      valid_email_user = User.new(@attr.merge(:email => address))
      valid_email_user.should be_valid
    end
  end

  it "should reject invalid email addresses" do
    addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
    addresses.each do |address|
      invalid_email_user = User.new(@attr.merge(:email => address))
      invalid_email_user.should_not be_valid
    end
   end

  it "should reject duplicate email addresses" do
    User.create!(@attr)
    user_with_duplicate_email = User.new(@attr)
    user_with_duplicate_email.should_not be_valid
  end

  it "should reject email addresses identical up to case" do
    upcased_email = @attr[:email].upcase
    User.create!(@attr.merge(:email => upcased_email))
    user_with_duplicate_email = User.new(@attr)
    user_with_duplicate_email.should_not be_valid
  end

  describe "passwords" do

before(:each) do
      @user = User.create!(@attr)
    end

    it "should have a password attribute" do
      @user.should respond_to(:password)
    end

it "should have a password confirmation attribute" do
  @user.should respond_to(:password_confirmation)
end
  end

      describe "password validations" do

    it "should require a password" do
      User.new(@attr.merge(:password => "", :password_confirmation => "")).
        should_not be_valid
    end

    it "should require a matching password confirmation" do
      User.new(@attr.merge(:password_confirmation => "invalid")).
        should_not be_valid
    end

    it "should reject short passwords" do
      short = "a" * 5
      hash = @attr.merge(:password => short, :password_confirmation => short)
      User.new(hash).should_not be_valid
    end

    it "should reject long passwords" do
      long = "a" * 41
      hash = @attr.merge(:password => long, :password_confirmation => long)
      User.new(hash).should_not be_valid
    end
  end
end

Finally here’s the output of my rspec

Failures:

  1) UsersController GET 'show' should be successfull
 Failure/Error: @user = Factory(:user)
 ArgumentError:
   Factory not registered: user
 # ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

  2) UsersController GET 'show' should find the right user
 Failure/Error: @user = Factory(:user)
 ArgumentError:
   Factory not registered: user
 # ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

  3) User should create a new instance given a valid attribute
 Failure/Error: User.create!(@attr)
 NoMethodError:
   undefined method `password' for #<User:0x007f9d3684e0b0>
 # ./spec/models/user_spec.rb:15:in `block (2 levels) in <top (required)>'

  4) User should require a name
 Failure/Error: no_name_user.should_not be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36eacf38>
 # ./spec/models/user_spec.rb:20:in `block (2 levels) in <top (required)>'

  5) User should require an email address
 Failure/Error: no_email_user.should_not be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36e45978>
 # ./spec/models/user_spec.rb:25:in `block (2 levels) in <top (required)>'

  6) User should reject names that are too long
 Failure/Error: long_name_user.should_not be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36e0b2a0>
 # ./spec/models/user_spec.rb:31:in `block (2 levels) in <top (required)>'

  7) User should accept valid email addresses
 Failure/Error: valid_email_user.should be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36da4c80>
 # ./spec/models/user_spec.rb:38:in `block (3 levels) in <top (required)>'
 # ./spec/models/user_spec.rb:36:in `each'
 # ./spec/models/user_spec.rb:36:in `block (2 levels) in <top (required)>'

  8) User should reject invalid email addresses
 Failure/Error: invalid_email_user.should_not be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36d870b8>
 # ./spec/models/user_spec.rb:46:in `block (3 levels) in <top (required)>'
 # ./spec/models/user_spec.rb:44:in `each'
 # ./spec/models/user_spec.rb:44:in `block (2 levels) in <top (required)>'

  9) User should reject duplicate email addresses
 Failure/Error: User.create!(@attr)
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36c6c890>
 # ./spec/models/user_spec.rb:51:in `block (2 levels) in <top (required)>'

  10) User should reject email addresses identical up to case
 Failure/Error: User.create!(@attr.merge(:email => upcased_email))
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36c4d878>
 # ./spec/models/user_spec.rb:58:in `block (2 levels) in <top (required)>'

  11) User passwords should have a password attribute
 Failure/Error: @user = User.create!(@attr)
 NoMethodError:
   undefined method `password' for #<User:0x007f9d36b3cda8>
 # ./spec/models/user_spec.rb:66:in `block (3 levels) in <top (required)>'

  12) User passwords should have a password confirmation attribute
 Failure/Error: @user = User.create!(@attr)
 NoMethodError:
   undefined method `password' for #<User:0x007f9d369c27c0>
 # ./spec/models/user_spec.rb:66:in `block (3 levels) in <top (required)>'

  13) User password validations should require a password
 Failure/Error: User.new(@attr.merge(:password => "", :password_confirmation => "")).
 NoMethodError:
   undefined method `password' for #<User:0x007f9d3699e5f0>
 # ./spec/models/user_spec.rb:81:in `block (3 levels) in <top (required)>'

  14) User password validations should require a matching password confirmation
 Failure/Error: User.new(@attr.merge(:password_confirmation => "invalid")).
 NoMethodError:
   undefined method `password' for #<User:0x007f9d3698e600>
 # ./spec/models/user_spec.rb:86:in `block (3 levels) in <top (required)>'

  15) User password validations should reject short passwords
 Failure/Error: User.new(hash).should_not be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d3697dda0>
 # ./spec/models/user_spec.rb:93:in `block (3 levels) in <top (required)>'

  16) User password validations should reject long passwords
 Failure/Error: User.new(hash).should_not be_valid
 NoMethodError:
   undefined method `password' for #<User:0x007f9d3696c5a0>
 # ./spec/models/user_spec.rb:99:in `block (3 levels) in <top (required)>'

Finished in 0.80301 seconds
35 examples, 16 failures, 2 pending

Failed examples:

rspec ./spec/controllers/users_controller_spec.rb:12 # UsersController GET 'show' should be successfull
rspec ./spec/controllers/users_controller_spec.rb:17 # UsersController GET 'show' should find the right user
rspec ./spec/models/user_spec.rb:14 # User should create a new instance given a valid attribute
rspec ./spec/models/user_spec.rb:18 # User should require a name
rspec ./spec/models/user_spec.rb:23 # User should require an email address
rspec ./spec/models/user_spec.rb:28 # User should reject names that are too long
rspec ./spec/models/user_spec.rb:34 # User should accept valid email addresses
rspec ./spec/models/user_spec.rb:42 # User should reject invalid email addresses
rspec ./spec/models/user_spec.rb:50 # User should reject duplicate email addresses
rspec ./spec/models/user_spec.rb:56 # User should reject email addresses identical up to case
rspec ./spec/models/user_spec.rb:69 # User passwords should have a password attribute
rspec ./spec/models/user_spec.rb:73 # User passwords should have a password confirmation attribute
rspec ./spec/models/user_spec.rb:80 # User password validations should require a password
rspec ./spec/models/user_spec.rb:85 # User password validations should require a matching password confirmation
rspec ./spec/models/user_spec.rb:90 # User password validations should reject short passwords
rspec ./spec/models/user_spec.rb:96 # User password validations should reject long passwords

Any ideas on what’s going on? I’ve been stuck on this for about a week now

  • 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-30T10:44:41+00:00Added an answer on May 30, 2026 at 10:44 am

    You don’t have accessible password or password_confirmation properties on your model. Change:

    attr_accessible :name, :email
    

    to:

    attr_accessible :name, :email, :password, :password_confirmation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but

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.