Skip to content

Small controllers refactor #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/global_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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