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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:05:58+00:00 2026-05-26T05:05:58+00:00

Good day! I’m practising materials from Ruby on Rails Tutorial by Michael Hartle. Below

  • 0

Good day! I’m practising materials from “Ruby on Rails Tutorial” by Michael Hartle.
Below is the failure message I received, even though the “expected” and “got” seems to match. Would you please give me some suggestion to see how I should approach this issue?
Thank you so much!
enter image description here

Below is the implementation code:

class User < ActiveRecord::Base
  attr_accessor :password
  attr_accessible :name, :emp_id, :dept_id, :password, :password_confirmation 
  validates :emp_id, :presence => true
  validates :name, :presence => true,
               :length => { :maximum => 50 }
  validates :password, :presence => true,
            :confirmation => true,
            :length => { :within => 6..40 }
  before_save :encrypt_password
  def has_password?(submitted_password)
    encrypted_password == encrypt(submitted_password)
  end
  def self.authenticate(emp_id, submitted_password)
    user = find_by_emp_id(emp_id)
    return nil if user.nil?
    return user if user.has_password?(submitted_password)
  end
  private 
    def encrypt_password
      self.salt = make_salt if new_record?
      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

Below is the SPEC code:

require 'spec_helper'
describe User do
  before(:each) do
    @attr = {:name=>"Example", :dept_id=>01, :emp_id=>10, :password=>"pwdabcd", :password_confirmation => "pwdabcd" }
  end
  .
  .
  .   
  describe "password encryption" do
    before(:each) do
      @user = User.create!(@attr)
    end
    .
    .
    . 
    describe "authenticate method" do
      it "should return the user on emp_id password match" do
        matching_user = User.authenticate(@attr[:emp_id], @attr[:password])
        matching_user.should == @user
      end
    end
  end
end

Thank you so much for your kind assistance.
Have a nice day!

  • 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-26T05:05:58+00:00Added an answer on May 26, 2026 at 5:05 am

    Kevin – when you see a failure message like that, the representation of the object (#<User ...>) is up to the object, so it’s possible that it doesn’t show you everything that is being compared by ==. My guess is it has something to do with :password_confirmation, but I’m not certain. It doesn’t look like the implementation is using it yet, so try removing password_confirmation from @attr in the spec, and from the attr_accessible declaration, and see if it passes.

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

Sidebar

Related Questions

Good day, I receive data from a communication channel and display it. Parallel, I
Good day, I have a question here. I am trying to fetch image from
Good day! I've recently switched from IIS 6.0 to IIS 7.x and I'm in
Good day dear colleagues, I decided to move some projects from MySQL to MongoDB
Good day, We just converted our web application .NET 1.1 to .NET 2.0. We
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good day, In visual studio 2005, when I drop a webcontrol in the designer,
Good Day All we are trying to do is inside a trigger make sure
Good day. I have little usage of Flash CS4, however i have to build
Good day everyone, I am building a page in ASP.NET, and using Master Pages

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.