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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:09:07+00:00 2026-06-10T17:09:07+00:00

I have such controller : class StatsController < ApplicationController def users_in_system @users = User.all

  • 0

I have such controller:

class StatsController < ApplicationController
  def users_in_system
    @users = User.all
  end
end

Routes:

  scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
    devise_for :users, :skip => [:registrations]                                          
    as :user do
      get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'    
      put 'users' => 'devise/registrations#update', :as => 'user_registration'            
      get '/users/sign_out' => 'devise/sessions#destroy'                                  
    end

    match '/users_list', :to => 'stats#users_in_system'
    match '/about', :to => 'pages#about'
    root :to => 'pages#home'
  end

  match '*path', to: redirect("/#{I18n.default_locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }
  match '', to: redirect("/#{I18n.default_locale}")

Rake routes:

      new_user_session GET    /:locale/users/sign_in(.:format)       devise/sessions#new {:locale=>/en|ru/}
          user_session POST   /:locale/users/sign_in(.:format)       devise/sessions#create {:locale=>/en|ru/}
  destroy_user_session DELETE /:locale/users/sign_out(.:format)      devise/sessions#destroy {:locale=>/en|ru/}
         user_password POST   /:locale/users/password(.:format)      devise/passwords#create {:locale=>/en|ru/}
     new_user_password GET    /:locale/users/password/new(.:format)  devise/passwords#new {:locale=>/en|ru/}
    edit_user_password GET    /:locale/users/password/edit(.:format) devise/passwords#edit {:locale=>/en|ru/}
                       PUT    /:locale/users/password(.:format)      devise/passwords#update {:locale=>/en|ru/}
edit_user_registration GET    /:locale/users/edit(.:format)          devise/registrations#edit {:locale=>/en|ru/}
     user_registration PUT    /:locale/users(.:format)               devise/registrations#update {:locale=>/en|ru/}
        users_sign_out GET    /:locale/users/sign_out(.:format)      devise/sessions#destroy {:locale=>/en|ru/}
            users_list        /:locale/users_list(.:format)          stats#users_in_system {:locale=>/en|ru/}
                 about        /:locale/about(.:format)               pages#about {:locale=>/en|ru/}
                  root        /:locale(.:format)                     pages#home {:locale=>/en|ru/}
                              /*path(.:format)                       :controller#:action
                              /                                      :controller#:action

And i want to write test for controller. So i try that spec:

require 'spec_helper'

describe StatsController do
  render_views

  before(:each){ @user = FactoryGirl.create( :user ) }

  describe "GET 'users_in_system'" do
    describe "for non-signed users" do
      it "should deny access" do
        get :users_in_system
        #...
      end
    end
  end
end

And it fails:

1) StatsController GET 'users_in_system' for non-signed users should deny access
     Failure/Error: get :users_in_system
     ActionController::RoutingError:
       No route matches {:controller=>"stats", :action=>"users_in_system"}
     # ./spec/controllers/stats_controller_spec.rb:11:in `block (4 levels) in <top (required)>'

In browser this page opens and everything works. How can rspec generate such error?!

UPD1: I suppose that, probably, i18n integration in routes breaks my tests.

UPD2:

My application.rb:

require File.expand_path('../boot', __FILE__)
require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module MyApp
  class Application < Rails::Application
    config.i18n.default_locale = :ru
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.active_support.escape_html_entities_in_json = true
    config.active_record.whitelist_attributes = true
    config.assets.enabled = true
    config.assets.version = '1.0'
  end
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-10T17:09:09+00:00Added an answer on June 10, 2026 at 5:09 pm

    I suspect the problem is that I18n.default_locale is not being properly set in rspec, which breaks your routing.

    The first thing I’d suggest is to see if I18n.default_locale is actually being set in your test.

    A few questions to get started:

    • If you change get :users_in_system to get :users_in_system, :locale => :en does the test pass?
    • Try replacing I18n.default_locale in routes.rb by its explicit value, say :en, and see if that changes anything.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom user like such: class PersonsController < UsersController end However, after
Given I have a controller class as such: public class ResourceController : AuthorizedController {
I have the Following ActionResult in a Controller. it returns a row of data(such
I have got this controller: class Start extends CI_Controller{ var $base; var $css; function
The goal is to have a singleton data controller class called FetchData.h/.m that pulls
I'm using devise gem and showing user's objects on registrations/edit view. I have such
I have a Controller class and a Monitor worker thread. The controller thread looks
I would really appreciate some help on this. I have relationships such as: class
I have such terrible models: class ParentalRelation < ActiveRecord::Base belongs_to :parent belongs_to :student belongs_to
I have classes such as AccountsController, ProductsController etc that all inherit from BaseController. Unity

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.