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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:27:14+00:00 2026-06-02T04:27:14+00:00

I made it up to Chapter 9 of the Ruby on Rails tutorial, and

  • 0

I made it up to Chapter 9 of the Ruby on Rails tutorial, and added functionality of my own to lock a user when they first sign up, such that an admin has to go in and approve (“unlock”) their id before a new user has access to the site. I added a :locked boolean attribute that works just like the :admin attribute of the User object. I have that all working now, but I’m having trouble writing a simple test for it. I added the following test to user_pages_spec.rb, just under the hierarchy “pagination” – “as an admin user”:

describe "as an admin user to unlock new users" do
    let(:admin) { FactoryGirl.create(:admin) }
    let(:locked_user) { FactoryGirl.create(:locked) }
    before do
      sign_in admin
      visit users_path
    end

    it { should have_link('unlock', href: user_path(locked_user)) }
    it { should_not have_link('unlock', href: user_path(admin)) }
end

and to support the creation of a “locked” user, added this to factories.rb:

factory :locked do
    locked true
end

I can confirm manually through Firefox that the unlocking link shows up, but I’m still getting the following failure:

  1) User pages index pagination as an admin user to unlock new users 
     Failure/Error: it { should have_link('unlock', href: user_path(locked_user)) }
       expected link "unlock" to return something
     # ./spec/requests/user_pages_spec.rb:64:in `block (5 levels) in <top (required)>'

I’m interested in knowing a) why this fails :), but also b) how to go about debugging a problem like this. How do I tell what the test is actually “seeing”? I tried rails-pry with a different problem as suggested by another stackoverflow user, but in this case I’ve found it of limited use.

Any ideas or suggestions would be much appreciated. Thanks in advance!

-Matt

  • 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-02T04:27:17+00:00Added an answer on June 2, 2026 at 4:27 am

    You are supposed to write the test first 😉

    Using your test as a start, I have been working through the process. I have gotten to the point of getting the same error as you. Using the pry-rails gem and putting binding.pry in the test:

    it { binding.pry ; should have_link('unlock', href: user_path(locked_user)) }
    

    (After messing around a lot) I copy and paste from the test to the command prompt:

    should have_link('unlock', href: user_path(locked_user))
    

    and get the error. Changing it to:

    should have_link('unlock', href: user_path(User.first))
    

    works. Entering locked_user at the prompt shows me the user record. Next I entered page.body and it shows me my locked user doesn’t even show up on the page. (Confirmed by entering User.count and found it to be 33 so it was on page 2.) You may not have this problem depending on how deeply embedded your test is the specs. I realized I had embedded it inside another spec accidentally. When I moved it out (User.count == 2), it still didn’t work. My locked_user still wasn’t on the page. User.all didn’t include the user either. Hartl mentions in chapter 10,

    This uses the let! (read “let bang”) method in place of let; the reason is that let variables are lazy, meaning that they only spring into existence when referenced.

    Changed the let to let! and it worked. (User.count == 3, including the locked_user this time.) Here is the test block.

    describe "as an admin user" do
      let(:admin) { FactoryGirl.create(:admin) }
      before do
        sign_in admin
        visit users_path
      end
    
    ...
    
      describe "other users should have an unlock link" do  ## changed the description
        let!(:locked_user) { FactoryGirl.create(:locked) }
        before { visit users_path }
    
        it { should have_link('unlock', href: user_path(locked_user)) }
      end
    end
    

    My code doesn’t unlock anything yet (I’ll need another test for that…) but the link shows up when it should. 🙂

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

Sidebar

Related Questions

I am working through chapter 1 of the Ruby on Rails 3 Tutorial I
I made a custom control that is basically a multiline TextBox that allows input,
I`v made my webpart that works well (I can add it to page and
I made a custom DatePicker that extends the android DatePicker UI component. I needed
I made this app that takes time entries from fogbugz and posts them to
I made a function that overwrite the the :hover of some elements on a
I made a game in VB .Net that uses tcp and sends messages back
So I'm going through the first chapter of How To Design Programs 2nd Edition.
I am doing a homework assignment that reads in a book. First, a line
I'm a Delphi, Ruby, and Javascript programmer that is finally learning C - starting

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.