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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:14:35+00:00 2026-06-03T12:14:35+00:00

I am currently following Michael Hartl’s tutorial on RoR and am trying to get

  • 0

I am currently following Michael Hartl’s tutorial on RoR and am trying to get to grips more with Rspec testing. I am able to follow the majority of what is going on however I am a bit confused as to what and how the :authenticate method functions:

it { should respond_to(:authenticate) }

And how it relates to the following section of code:

    describe "return value of authenticate" do
  before { @user.save }
    let(:found_user) { User.find_by_email(@user.email) }

  describe "with valid password" do
    it { should == found_user.authenticate(@user.password) }
  end

  describe "with invalid password" do
    let(:user_for_invalid_password) { found_user.authenticate("invalid") }

    it { should_not == user_for_invalid_password }
    specify { user_for_invalid_password.should be_false }
  end
end

I understand the assignment a variable using let and the corresponding block, but I am struggling to understand what is happening when the authenticate method is called, what is it authenticating against in the initial line? Is it authenticating against the user.rb model that requires an email be present and that it matches a particular regex, or is it something else. I have included the user.rb code for clarity:

class User < ActiveRecord::Base
  attr_accessible :email, :name, :password, :password_confirmation
  has_secure_password

  before_save { |user| user.email = email.downcase }

  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, length: { minimum: 6 }
  validates :password_confirmation, presence: true

end

Any help much appreciated.

  • 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-03T12:14:41+00:00Added an answer on June 3, 2026 at 12:14 pm

    Without line numbers I might be misunderstanding which line you are referring to but here goes. The very first line of code you quote with the ‘respond_to’ method is merely asking the object whether it’s interface handles whatever you are asking it to respond to. I think there is a bit missing – it should be: obj.should respond_to(:somemethod) It just checks that the object has a method with that name – so a fairly basic test.

    Your question about what is going on when you call the authenticate method might be explained by the fact that you can’t see the authenticate method in user.rb. In the older versions of the Hartl tutorial there is an authenticate method (I still have it on my machine 🙂

    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
    

    Looking at the way it is called in your code clearly it is implemented slightly differently off in a helper method or something… see the call to ‘has_secure_password’ in your model? That’s a helper method where :authenticate lives.

    Check the source code/documentation for more details.

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

Sidebar

Related Questions

I am following Michael Hartl's RoR tutorial, and it is covering the basics of
I'm currently following the third tutorial listed here: here where I'm trying to compile
I am following the Ruby on Rails tutorial by Michael Hartl http://ruby.railstutorial.org/ I installed
I am new to RoR3 am following along with the RoR3 Michael Hartl Tutorial.
I was following Michael Hartl's tutorial to build a sign up form with login.
I'm a Rails beginner and currently reading Michael Hartl's Rails 3 Tutorial and have
I'm currently following a tutorial in a book, and it instructs to create a
I'am currently following a tutorial ( http://kristantohans.wordpress.com/2010/03/01/new-to-jasperreport-build-your-first-impressive-application-part-2/ ) and he use a java db
I'm currently following the Shovell tutorial in the Simply Rails 2 book. On page
I am currently following the Ruby on Rails Tutorial and have run into a

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.