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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:21:24+00:00 2026-06-17T07:21:24+00:00

I am new to programming, this is my first application. While creating an application

  • 0

I am new to programming, this is my first application.
While creating an application in Rails, i have two models. User&list,nested.

resources :users do
  resources :lists
end

These are the following routes i obtain with this setting:

user_lists GET    /users/:user_id/lists(.:format)             lists#index
           POST   /users/:user_id/lists(.:format)             lists#create
new_user_list GET    /users/:user_id/lists/new(.:format)      lists#new
edit_user_list GET    /users/:user_id/lists/:id/edit(.:format)lists#edit
user_list GET    /users/:user_id/lists/:id(.:format)          lists#show
           PUT    /users/:user_id/lists/:id(.:format)         lists#update
           DELETE /users/:user_id/lists/:id(.:format)         lists#destroy

With regards i have created the views with the following links.

<div class="stats">
  <a href="<%= user_lists_path(current_user) %>">
    <%= pluralize(current_user.lists.count, 'List') %>
  </a>
</div>

<div class="list">
  <%= link_to 'Create List', new_user_list_path(current_user) %>
</div>

These work as expected, however when i use the same url helpers in testing i get an error.

describe "List create page" do 
  let(:user) { FactoryGirl.create(:user) }
  before do  
    user.save
    visit new_user_list_path(user)
  end
  it { should have_selector('title', text: 'SocialTask | List') }
  it { should have_selector('h1', text: 'Create list') }

  describe "invalid list creation" do 
    before { click_button 'Create list' } 
    it { should have_content('Error in creating list') }
  end
 end

This causes the tests to have an error.

Failure/Error: visit new_user_list_path(user)
 NoMethodError:
   undefined method `lists' for nil:NilClass

I have tried playing around with the url that did not work.
I tried updating rspec/capybara that did not work either.
I have also checked the inclusion of

config.include Rails.application.routes.url_helpers

in the spec helper.

How do i get the helpers to work? Or am i missing some minor detail?
Thanks in advance.

Helper Methods.

module SessionsHelper

def sign_in(user)
  cookies.permanent[:remember_token] = user.remember_token
  self.current_user = user 
end

def current_user=(user)
  @current_user = user 
end

def current_user 
  @current_user ||= User.find_by_remember_token(cookies[:remember_token])
end

def signed_in?
  !current_user.nil?
end

def sign_out
  self.current_user = nil 
  cookies.delete(:remember_token)
end

def current_user?(user)
  current_user == user
end
end

The rspec helper to sign in.
support/utilities.rb

include ApplicationHelper
 def sign_in(user)
  visit signin_path
  fill_in "Email", with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in"
  cookies[:remember_token] = user.remember_token
 end
  • 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-17T07:21:25+00:00Added an answer on June 17, 2026 at 7:21 am

    Without seeing the stack trace, I think your problem is in the view on this line:

    <%= pluralize(current_user.lists.count, 'List') %>
    

    It seems like current_user is nil. Normally you should define some kind of helper method in your RSpec suite to simulate a user logging in. That way, current_user will return the user that you stub out in the test.

    Here’s an example:

    # spec/support/session_helper.rb
    module SessionHelper
      def login(username = 'admin')
        request.session[:user_id] = User.find_by_username(username).id
      end
    end
    

    Yours will differ depending on how you authenticate your users. For example, Devise publishes its own set of test helpers, so you can simply include its helpers directly:

    # spec/support/devise.rb
    RSpec.configure do |config|
      config.include Devise::TestHelpers, :type => :controller
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to web-application programming with Java. I have two questions. First: I
First, I am new to programming and this is my first major assignment in
i am new kernel programming.i have been trying to load this driver program for
Totally new to programming so kindly excuse the silly question. I have this URL
First off I'm new at programming. I'm creating an app with one navigation bar
I am new to Parallel Programming and infact this is the first time I
(Here's my requisite line about being new to ruby/rails and programming in general; first
I am new to WP7 programming and I have been following this tutorial http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx
I am new to Android programming. I am creating a very simple application in
I'm new to programming. I have a form application that launches a thread. Form

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.