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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:47:28+00:00 2026-06-11T08:47:28+00:00

I’m new to RSpec, and trying to write a simple test that shows Devise

  • 0

I’m new to RSpec, and trying to write a simple test that shows Devise is working. I’ve picked a random page and want to write a test that shows that a non logged-in user is re-redirected to /users/sign_in.

describe OrgsController do

  describe "GET index when not logged in" do
    it "redirects to new_user_session_path" do
      user = FactoryGirl.create(:user)
      user.confirm!
      sign_in user
      sign_out user
      get :index
      response.should redirect_to new_user_session_path
    end
  end

  before(:each) do
    user = FactoryGirl.create(:user)
    user.confirm!
    sign_in user
  end

  # remaining specs

end

I get "Expected response to be a redirect to <http://test.host/users/sign_in?locale=en> but was a redirect to <http://test.host/users/sign_in>."

I have implemented i18n, and have in my Application Controller:

before_filter :set_i18n_locale_from_params

What is the best way to get this working in terms of:

  • Getting the routes to match?
  • The hackishness of signing a user in and out again to get round the effects of the before(:each) block?
  • The overall approach?
  • 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-11T08:47:30+00:00Added an answer on June 11, 2026 at 8:47 am

    The problem of getting controller tests/specs to properly set the locale is a longstanding one, see: How to set locale default_url_options for functional tests (Rails)

    From what you’ve written, it looks like get :index is not setting the locale by default, because default_url_options will not work from controller tests/specs. Try one of the solutions mentioned in the link above to get the routes to match. See also this discussion on github: https://github.com/rspec/rspec-rails/issues/255

    For what it’s worth, this is the patch I currently use in specs/tests to get the locale to be automatically passed to routes from the current locale:

    class ActionDispatch::Routing::RouteSet
      def url_for_with_locale_fix(options)
        url_for_without_locale_fix(options.merge(:locale => I18n.locale))
      end
    
      alias_method_chain :url_for, :locale_fix
    end
    

    Regarding the hackishness of the before(:each) block setup you have, I’d really suggest separating the cases using context blocks, with one context without the before filter logging the user in, and another with the before block logging the user in. The setup you have right now is really confusing for someone trying to see what’s going on.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.