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

  • Home
  • SEARCH
  • 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 8649631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:36:32+00:00 2026-06-12T13:36:32+00:00

I am working with Michael Hartl’s tutorial. When I run test I get this

  • 0

I am working with Michael Hartl’s tutorial. When I run test I get this error:

 1) Authentication authorization for non-signed-in users when attempting to visit a   
protected page as non-admin user submitting a DELETE request to the Users#destroy action
Failure/Error: specify { response.should redirect_to(root_path) } 
Expected response to be a redirect to <http://www.example.com/> but
was a redirect to <http://www.example.com/users>
# ./spec/requests/authentication_pages_spec.rb:81:in `block (7 levels)
in <top required)>'

Here is my authentication_pages_spec.rb. Code might be slightly diffrent than showed in tutorial examples. Those changes were necessary to pass recent tests. Up to this moment everything worked perfect.

require 'spec_helper'

describe "Authentication" do
  let(:user) { FactoryGirl.create(:user) } 
    subject { page }

  describe "signin page" do
    before { visit signin_path }

    it { should have_selector('h1', text: 'Sign in') }
    it { should have_selector('title', text: 'Sign in') }
  end

  describe "signin" do

    before { visit signin_path } 

    describe "with invalid information" do
      before { click_button "Sign in" }

      it { should have_selector('title', text: 'Sign in') }
      it { should have_selector('div.alert.alert-error', text: 'Invalid') }

      describe "after visiting another page" do
          before { click_link "Home"}
          it { should have_selector('div.alert.alert-error') }
      end
    end

      describe "with valid information" do     
      let(:user) { FactoryGirl.create(:user) } 
      before do
        fill_in "Email",    with: user.email
        fill_in "Password", with: user.password
        click_button "Sign in"
      end

      it { should have_selector('title',    text: user.name) }

      it { should have_link('Users',        href: users_path) }
      it { should have_link('Profile',      href: user_path(user)) }
      it { should have_link('Settings',     href: edit_user_path(user)) }
      it { should have_link('Sign out',     href: signout_path) }

      it { should_not have_link('Sign in',  href: signin_path) } 

      describe "followed by signout" do
        before { click_link "Sign out" }
        it { should have_link('Sign in') }
      end
    end
  end

  describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "when attempting to visit a protected page" do
        before do
          visit edit_user_path(user)
          fill_in "Email",    with: user.email
          fill_in "Password", with: user.password
          click_button "Sign in"
        end

        describe "after signing in" do

          it "should render the desired protected page" do
            page.should have_selector('title', text: 'Edit user')
          end          
       end
        describe "as non-admin user" do
          let(:user)  { FactoryGirl.create(:user) }
          let(:non_admin) { FactoryGirl.create(:user) }

          before { sign_in non_admin }

          describe "submitting a DELETE request to the Users#destroy action" do
            before { delete user_path(user) }
            specify { response.should redirect_to(root_path) }
          end
        end        
      end
    end

    describe "in the Users controller" do

      describe "visiting the edit page" do
        before { visit edit_user_path(user) }
        it { should have_selector('title', text: "Sign in") }
      end

      describe "submitting to the update action" do
        before { put user_path(user) }
        specify { response.should redirect_to(signin_path) }
      end

      describe "visiting the user index" do
        before {visit users_path }
        it { should have_selector('title', text: 'Sign in') }
      end
    end


     describe "as wrong user" do
       let(:user) { FactoryGirl.create(:user) }
       let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
       before { sign_in user }

       describe "visiting User#edit page" do
         before { visit edit_user_path(wrong_user) }
         it { should_not have_selector('title', text: full_title('Edit user')) }
       end

       describe "submitting a PUT request to the User#update action" do
         before { put user_path(wrong_user) }
         specify { response.should redirect_to(root_path) } 
       end
    end    
  end
end

Anybody got idea? Thanks for help & intrest!

  • 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-12T13:36:34+00:00Added an answer on June 12, 2026 at 1:36 pm

    In your users_controller#destroy you have redirect to users_path instead of root_path(which you’re expecting). Can you show your #destroy action?

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

Sidebar

Related Questions

I'm working on chapter 11 of Michael Hartl's RailsTutorial and I got this error
I am currently working through Michael Hartl's Rails Tutorial while experimenting with some other
I'm a newbie working through Michael Hartl's Tuby on Rails Tutorial and I have
Working with H2 I get this error when I try to write a row
I am working through the Ruby on Rails Tutorial by Michael Hartl and I
I am working through Michael Hartl's Ruby on Rails Tutorial Chapter 5 exercises and
I am working on Michael Hartl Rails tutorial (currently chapter 7). When I try
I am working on Michael Hartl's tutorial (chapter 6). When I try to create
I'am working with Michael Hartl Tutorial. In chapter 7 I've found problem that I
I am working through Michael Hartl's Ruby on Rails tutorial, and I am doing

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.