Skip to content

Commit

Permalink
Handle invalid locale
Browse files Browse the repository at this point in the history
So it wont 500 when passing a not valid locale as ?locale=foo
  • Loading branch information
arthurnn committed Jul 2, 2015
1 parent ae00cf5 commit 14bdd63
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -13,6 +13,8 @@ class ApplicationController < ActionController::Base

def set_locale
I18n.locale = params[:locale] || I18n.default_locale
rescue I18n::InvalidLocale
I18n.locale = I18n.default_locale
end

rescue_from(ActionController::ParameterMissing) do |e|
Expand Down
5 changes: 5 additions & 0 deletions test/functional/home_controller_test.rb
Expand Up @@ -35,4 +35,9 @@ class HomeControllerTest < ActionController::TestCase
get :index
end
end

should "use default locale on GET using invalid one" do
get :index, locale: 'foobar'
assert_equal I18n.locale, I18n.default_locale
end
end
2 changes: 0 additions & 2 deletions test/test_helper.rb
Expand Up @@ -12,8 +12,6 @@

require 'helpers/gem_helpers'

I18n.enforce_available_locales = false

RubygemFs.mock!

class MiniTest::Test
Expand Down

0 comments on commit 14bdd63

Please sign in to comment.