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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:19:45+00:00 2026-05-29T05:19:45+00:00

I’ve got a problem with my controller tests for my Courses Controller. It seems

  • 0

I’ve got a problem with my controller tests for my Courses Controller. It seems that devise is not signing in my user correctly. All the generated controller tests for this controller only are failing.

I create my user in users.rb using Factory-girl as per below…

FactoryGirl.define do
  factory :user do 
    sequence :email do |n| 
      "test#{n}@email.com"
    end
    password "password"
    password_confirmation "password"
  end
end

Then in my courses_controller_spec.rb I simulate the login as per below..

require 'spec_helper'
describe CoursesController do
  include Devise::TestHelpers

  before(:each) do
    #@request.env["devise.mapping"] = Devise.mappings[:user]
    user = Factory.create(:user)
    user.toggle!(:admin)
    sign_in user
  end

  describe "DELETE destroy" do
    it "redirects to the courses list" do
      course = Factory.create(:course)
      delete :destroy, {:id => course.to_param}, valid_session
      response.should redirect_to(courses_url)
    end
  end

And I get the output…

Failure/Error: response.should redirect_to(courses_url)
Expected response to be a redirect to <http://test.host/courses> but was a redirect to <http://test.host/users/sign_in>

Please note I’ve also used the following in my spec_helper.rb

config.include Devise::TestHelpers, :type => :controller

And I’ve tried it as per https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-%28and-rspec%29

In my request specs I can create the user and login using the below which works fine but I’d like to get all the controller tests working also

fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"

Any help here would be much appreciated.

  • 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-29T05:19:45+00:00Added an answer on May 29, 2026 at 5:19 am

    I just figured this out myself. Remove the valid_session from your delete call. That seems to overwrite the session defined using the devise test helpers.

    Everything else seems correct. Keep all the devise setup code and just change the delete line in your spec to:

    delete :destroy, {:id => course.to_param}
    

    I also kept in the following line in my before( :each ) block, which you commented out. Not sure what it does yet:

    @request.env["devise.mapping"] = Devise.mappings[:user]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

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.