diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d9ba1e933..a86f2f506 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,7 +10,6 @@ class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller? before_filter :set_locale before_filter :set_current_organization - after_filter :store_location rescue_from MissingTOSAcceptance, OutadedTOSAcceptance do redirect_to terms_path @@ -21,7 +20,11 @@ class ApplicationController < ActionController::Base helper_method :current_organization, :admin?, :superadmin? - protected + def switch_lang + redirect_to :back + end + + private def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:username]) @@ -35,17 +38,6 @@ def set_current_organization end end - def store_location - # store last url - this is needed for post-login redirect to whatever the - # user last visited. - return unless request.get? - paths = ["/", "/users/sign_in", "/users/sign_up", "/users/password/new", - "/users/password/edit", "/users/confirmation", "/users/sign_out"] - if !paths.include?(request.path) && !request.xhr? - session[:previous_url] = request.fullpath - end - end - def after_sign_in_path_for(user) if user.members.present? users_path @@ -54,8 +46,6 @@ def after_sign_in_path_for(user) end end - private - def check_for_terms_acceptance! if user_signed_in? accepted = current_user.terms_accepted_at diff --git a/app/controllers/global_controller.rb b/app/controllers/global_controller.rb deleted file mode 100644 index 386ce1a48..000000000 --- a/app/controllers/global_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class GlobalController < ApplicationController - def switch_lang - redirect_to :back - end -end diff --git a/config/routes.rb b/config/routes.rb index ead5c2497..f28c54013 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ ActiveAdmin.routes(self) - get "global/switch_lang", as: :switch_lang + get :switch_lang, to: 'application#switch_lang' get "/pages/:page" => "pages#show", as: :page diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb new file mode 100644 index 000000000..58f34db3a --- /dev/null +++ b/spec/controllers/application_controller_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +RSpec.describe ApplicationController do + describe '#switch_lang' do + let(:original_locale) { I18n.locale } + + before do + request.env["HTTP_REFERER"] = root_path + end + + after do + I18n.locale = original_locale + end + + it 'switches locale to passed language via params' do + new_locale = (I18n.available_locales - [original_locale]).sample + + expect do + get :switch_lang, locale: new_locale + end.to change(I18n, :locale).from(original_locale).to(new_locale) + + expect(response).to redirect_to(root_path) + end + end +end