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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:08:41+00:00 2026-06-18T07:08:41+00:00

I’m up to the Chapter 9 Exercises in Hartl’s Rails Tutorial. I’ve been trying

  • 0

I’m up to the Chapter 9 Exercises in Hartl’s Rails Tutorial. I’ve been trying for ages but can’t crack question 6:

Signed-in users have no reason to access the new and create actions in the Users controller. Arrange for such users to be redirected to the root URL if they do try to hit those pages.

First, where should I put these tests? At the moment I’m trying in user_pages_spec.rb but I’m unsure if that’s right. And then where should I put the logic itself?

Second, is this what my test should look like:

  describe "after signing-in" do
    before { sign_in(user) }
    describe "creating a new user" do
      before { put new_user_path }
      specify { response.should redirect_to(root_url) }
    end
  end

At the moment when I do the above, RSpec tells me

Expected response to be a redirect to  but was a redirect to http://www.example.com/signin. 

But when I test it in my browser, visiting http://localhost:3000/users/new with a signed-in user, there is no redirect at all (which makes more sense to me because I haven’t coded one).

I’ve even downloaded Hartl’s code from github but I can’t see where / if he has included this functionality.

Edit:
I’ve got both

 describe "creating a new user" do
   before { visit new_user_path }
   it { should_not have_selector 'title', text: full_title('Sign Up') }
 end

And

 describe "creating a new user" do
   before { get new_user_path } # note the use of GET here not PUT
   specify { response.should redirect_to(root_url) }
 end

to work properly. Thanks to @Peter de Ridder for help

  • 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-18T07:08:42+00:00Added an answer on June 18, 2026 at 7:08 am

    I’m not really sure why you have a put request when calling new_user_path.

    describe "after signing-in" do
      let(:user) { FactoryGirl.create(:user) }
      before { sign_in user }
    
     describe "creating a new user" do
       before { get new_user_path }
       specify { response.should redirect_to(root_url) }
     end
    end
    

    Now the test should work as supposed. You still have to write the code to actually do the redirecting. But hey, that’s the whole challenge. Personally I would check if a user is signed in/present. If so, new and create actions should no longer be accessible.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I upgraded downgraded to rails 2.3.17 due to the security bugs, but now I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.