Permalink
Browse files

Err, fixing stupid code written in haste

  • Loading branch information...
1 parent eff9988 commit 67d9966a26057b7d61a5e357e7c38462a4ab44e7 @karmi committed May 1, 2009
Showing with 5 additions and 10 deletions.
  1. +4 −7 app/controllers/application_controller.rb
  2. +1 −3 test/functional/home_controller_test.rb
@@ -14,7 +14,7 @@ def set_locale
end
def available_locales
- I18n.available_locales
+ I18n.available_locales.map(&:to_s).sort
end
def current_locale?(l)
@@ -29,8 +29,7 @@ def current_page_path(options={})
# Get locale from request parameters
def extract_locale_from_params
- return nil unless params[:locale]
- (available_locales.include? params[:locale].to_sym) ? params[:locale] : nil
+ (available_locales.include? params[:locale].to_s) ? params[:locale] : nil
end
# Get locale code from request top-level domain (like http://application.it:3000)
@@ -41,8 +40,7 @@ def extract_locale_from_params
# in your /etc/hosts file to try this out locally
def extract_locale_from_tld
parsed_locale = request.host.split('.').last
- return nil unless parsed_locale
- (available_locales.include? parsed_locale.to_sym) ? parsed_locale : nil
+ (available_locales.include? parsed_locale.to_s) ? parsed_locale : nil
end
# Get locale code from request subdomain (like http://it.application.local:3000)
@@ -51,8 +49,7 @@ def extract_locale_from_tld
# in your /etc/hosts file to try this out locally
def extract_locale_from_subdomain
parsed_locale = request.subdomains.first
- return nil unless parsed_locale
- (available_locales.include? parsed_locale.to_sym) ? parsed_locale : nil
+ (available_locales.include? parsed_locale.to_s) ? parsed_locale : nil
end
end
@@ -6,9 +6,7 @@ class HomeControllerTest < ActionController::TestCase
def test_should_return_available_locales
assert_nothing_raised { @controller.available_locales }
assert @controller.available_locales.is_a? Array
- assert @controller.available_locales.include?(:cz)
- assert @controller.available_locales.include?(:de)
- assert @controller.available_locales.include?(:en)
+ assert_equal ["cz", "de", "en"], @controller.available_locales
end
def test_should_render_proper_en_us_locale_by_default

0 comments on commit 67d9966

Please sign in to comment.