Permalink
Browse files

some small refactoring and tests

  • Loading branch information...
1 parent 8b6fd02 commit b45a3f40c05b3e46609b2b9f7af559c3daed043d @maxwell maxwell committed Apr 15, 2012
Showing with 26 additions and 9 deletions.
  1. +9 −9 app/controllers/application_controller.rb
  2. +17 −0 spec/controllers/application_controller_spec.rb
@@ -66,15 +66,15 @@ def set_git_header
end
def set_locale
- if user_signed_in?
- I18n.locale = current_user.language
- else
- locale = request.preferred_language_from AVAILABLE_LANGUAGE_CODES
- locale ||= request.compatible_language_from AVAILABLE_LANGUAGE_CODES
- locale ||= DEFAULT_LANGUAGE
- I18n.locale = locale
- I18n.locale = params[:lang] if params[:lang].present? && AVAILABLE_LANGUAGE_CODES.include? params[:lang]
- end
+ #this could be a LocaleFinder object, or maybe an upstream helper method
+ I18n.locale = if user_signed_in?
+ current_user.language
+ else
+ locale = AVAILABLE_LANGUAGE_CODES.find{|x| x == params[:lang]}
+ locale ||= request.preferred_language_from(AVAILABLE_LANGUAGE_CODES)
+ locale ||= request.compatible_language_from(AVAILABLE_LANGUAGE_CODES)
+ locale ||= DEFAULT_LANGUAGE
+ end
end
def redirect_unless_admin
@@ -45,4 +45,21 @@ def index
# end
#end
end
+
+ describe "#set_locale" do
+ it 'defaults to the default language' do
+ get :index
+ I18n.locale.should == DEFAULT_LANGUAGE.to_sym
+ end
+
+ it 'prefers a param passed to the page' do
+ get :index, :lang => 'es'
+ I18n.locale.should == 'es'.to_sym
+ end
+
+ it 'defaults to the current users language'
+
+ it 'if no one is signed in, it tries to infer it from the request'
+
+ end
end

0 comments on commit b45a3f4

Please sign in to comment.