From 1126f28d020ff5397f24e0f583b4ab3ab404ad65 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 30 Nov 2018 03:01:27 +0500 Subject: [PATCH] Add UsersHelper --- app/helpers/users_helper.rb | 33 ++++++++++++++++++++++++++ app/views/users/shared/_links.html.erb | 12 +++++----- spec/helpers/users_helper_spec.rb | 7 ++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 app/helpers/users_helper.rb create mode 100644 spec/helpers/users_helper_spec.rb diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..f1c1ff8 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module UsersHelper + def display_sign_in_link? + controller_name != 'sessions' + end + + def display_sign_up_link? + devise_mapping.registerable? && + controller_name != 'registrations' + end + + def display_password_reset_link? + devise_mapping.recoverable? && + controller_name != 'passwords' && + controller_name != 'registrations' + end + + def display_email_confirmation_link? + devise_mapping.confirmable? && + controller_name != 'confirmations' + end + + def display_unlock_link? + devise_mapping.lockable? && + resource_class.unlock_strategy_enabled?(:email) && + controller_name != 'unlocks' + end + + def display_omniauth_links? + devise_mapping.omniauthable? + end +end diff --git a/app/views/users/shared/_links.html.erb b/app/views/users/shared/_links.html.erb index 0ecf846..f7ac612 100644 --- a/app/views/users/shared/_links.html.erb +++ b/app/views/users/shared/_links.html.erb @@ -1,29 +1,29 @@ -<%- if controller_name != 'sessions' %> +<%- if display_sign_in_link? %> <%= link_to translate('.sign_in'), new_session_path(resource_name) %>
<% end -%> -<%- if devise_mapping.registerable? && controller_name != 'registrations' %> +<%- if display_sign_up_link? %> <%= link_to translate('.sign_up'), new_registration_path(resource_name) %>
<% end -%> -<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> +<%- if display_password_reset_link? %> <%= link_to translate('.forgot_your_password'), new_password_path(resource_name) %>
<% end -%> -<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> +<%- if display_email_confirmation_link? %> <%= link_to translate('.didn_t_receive_confirmation_instructions'), new_confirmation_path(resource_name) %>
<% end -%> -<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> +<%- if display_unlock_link? %> <%= link_to translate('.didn_t_receive_unlock_instructions'), new_unlock_path(resource_name) %>
<% end -%> -<%- if devise_mapping.omniauthable? %> +<%- if display_omniauth_links? %> <%- resource_class.omniauth_providers.each do |provider| %> <%= link_to translate('.sign_in_with_provider', provider: OmniAuth::Utils.camelize(provider)), omniauth_authorize_path(resource_name, provider) %>
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb new file mode 100644 index 0000000..baa2bc5 --- /dev/null +++ b/spec/helpers/users_helper_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe UsersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end