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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:43:40+00:00 2026-05-30T19:43:40+00:00

I have this test from michael hartl book describe follower/following counts do let(:user) {

  • 0

I have this test from michael hartl book

describe "follower/following counts" do
  let(:user) { FactoryGirl.create(:user) }
  let(:other_user) { FactoryGirl.create(:user) }

  before do 
    sign_in(user)
    visit root_path
    user.follow!(other_user) 
  end
  it { should have_link('0 following', href: following_user_path(user)) }
  it { should have_link('1 follower', href: followers_user_path(user)) }
end

the problem is that this always fails

it { should have_link('1 follower', href: followers_user_path(user)) }

but when i change it to

it { should have_link('0 follower', href: followers_user_path(user)) }

the test passes. Here is my model code:

User.rb

has_many :relationships, foreign_key: "follower_id", dependent: :destroy
has_many :reverse_relationships, foreign_key: "followed_id", class_name:  "Relationship", dependent: :destroy
has_many :followed_users, through: :relationships, source: :followed
has_many :followers, through: :reverse_relationships, source: :follower

def follow!(other_user)
  relationships.create!(followed_id: other_user.id)
end

Relationship.rb

attr_accessible :followed_id
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
validates :follower_id, presence: true
validates :followed_id, presence: true

Routes.rb

resources :users do
  member do
    get :following, :followers
  end
end
resources :relationships, only: [:create, :destroy]
  • 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-30T19:43:41+00:00Added an answer on May 30, 2026 at 7:43 pm

    You need to visit the page after you’ve followed the user:

    before do 
      sign_in(user)
      user.follow!(other_user) 
      visit root_path
    end
    

    else the page will have been rendered before the user was followed, and thus says “0 followers”.

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

Sidebar

Related Questions

Following on from this question...I'm trying to unit test the following scenario: I have
I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
This is from Michael Hartl's book, section 8.4. RSpec is testing a successful signup
I am following the tutorial from Michael Hartl . I tried the first test
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
In this test Core Data project, I have a one to many relationship from
I have a file, which I read from test . This file is UTF-8.
I have this test page I am working from: http://www.problemio.com/test.php The problem happens when
So i have this test Activity with 3 elements: TextView, EditText, Button. When user
I have this test slider http://jsfiddle.net/dUyLY/2/ In Chrome it works nice, but in firefox

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.