From dc31acfca1f0161c25da7eb977078d1a5b1de468 Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Sun, 16 Aug 2015 16:56:08 +0900 Subject: [PATCH 1/4] Add the router name and Rename the resource name to the plural --- backend/config/routes.rb | 2 +- frontend/config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/config/routes.rb b/backend/config/routes.rb index d0f00799..07b0b792 100644 --- a/backend/config/routes.rb +++ b/backend/config/routes.rb @@ -54,7 +54,7 @@ resource :store, controller: :store, only: [:show, :edit, :update] - devise_for :user, path: :user, class_name: Comable::User.name, module: :devise, controllers: { + devise_for :users, path: :user, class_name: Comable::User.name, module: :devise, router_name: :comable, controllers: { sessions: 'comable/admin/user_sessions' } diff --git a/frontend/config/routes.rb b/frontend/config/routes.rb index b00d9244..506d9fc4 100644 --- a/frontend/config/routes.rb +++ b/frontend/config/routes.rb @@ -23,7 +23,7 @@ resources :pages, only: [:show] - devise_for :user, path: :member, class_name: Comable::User.name, module: :devise + devise_for :users, path: :member, class_name: Comable::User.name, module: :devise, router_name: :comable resource :user, path: :member do member do From 8c619f9c402a825e06baf867f61b89a1df8dde2b Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Sun, 16 Aug 2015 17:10:09 +0900 Subject: [PATCH 2/4] Change the redirect path for devise --- .../app/helpers/comable/application_helper.rb | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/app/helpers/comable/application_helper.rb b/core/app/helpers/comable/application_helper.rb index 1faa90a9..51949abe 100644 --- a/core/app/helpers/comable/application_helper.rb +++ b/core/app/helpers/comable/application_helper.rb @@ -61,24 +61,33 @@ def liquid_assigns private - def after_sign_in_path_for(_resource) - session.delete(:user_return_to) || comable.root_path + def comable_root_path + case resource_name + when :admin_user + comable.admin_root_path + else + comable.root_path + end end - def after_sign_out_path_for(_resource) - session.delete(:user_return_to) || comable.root_path + def after_sign_in_path_for(_resource_or_scope) + session.delete(:user_return_to) || comable_root_path + end + + def after_sign_out_path_for(_scope) + session.delete(:user_return_to) || comable_root_path end def after_sign_up_path_for(resource) - signed_in_root_path(resource) || comable.root_path + signed_in_root_path(resource) || comable_root_path end def after_update_path_for(resource) - signed_in_root_path(resource) || comable.root_path + signed_in_root_path(resource) || comable_root_path end def after_resetting_password_path_for(resource) - signed_in_root_path(resource) || comable.root_path + signed_in_root_path(resource) || comable_root_path end end end From 409da3cb7b79808ec9a3f3f5e01106ab6e82ec09 Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Mon, 17 Aug 2015 20:25:57 +0900 Subject: [PATCH 3/4] Add the test for `#comable_root_path` --- .../helpers/comable/application_helper_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/spec/helpers/comable/application_helper_spec.rb b/core/spec/helpers/comable/application_helper_spec.rb index 77cedc63..a3c4a9a6 100644 --- a/core/spec/helpers/comable/application_helper_spec.rb +++ b/core/spec/helpers/comable/application_helper_spec.rb @@ -46,4 +46,20 @@ expect(subject.liquid_assigns.keys).to include(*%w( current_store current_comable_user current_order current_trackers form_authenticity_token )) end end + + describe '#comable_root_path' do + subject { helper.clone } + + before { def subject.resource_name; end } + + it 'returns the root path for the customer in frontend' do + allow(subject).to receive(:resource_name).and_return(:user) + expect(subject.send(:comable_root_path)).to eq(comable.root_path) + end + + it 'returns the root path for the admin user in backend' do + allow(subject).to receive(:resource_name).and_return(:admin_user) + expect(subject.send(:comable_root_path)).to eq(comable.admin_root_path) + end + end end From 86fa9762806aacc18e09d7762f245b2208c7fdfa Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Sun, 23 Aug 2015 15:48:40 +0900 Subject: [PATCH 4/4] Fix the problem A few methods doesn't works without backend or frontend gem. --- .../app/controllers/comable/application_controller.rb | 4 ++++ core/app/helpers/comable/application_helper.rb | 6 ++++-- core/spec/helpers/comable/application_helper_spec.rb | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 core/app/controllers/comable/application_controller.rb diff --git a/core/app/controllers/comable/application_controller.rb b/core/app/controllers/comable/application_controller.rb new file mode 100644 index 00000000..dbde3d8c --- /dev/null +++ b/core/app/controllers/comable/application_controller.rb @@ -0,0 +1,4 @@ +module Comable + class ApplicationController < ActionController::Base + end +end diff --git a/core/app/helpers/comable/application_helper.rb b/core/app/helpers/comable/application_helper.rb index 51949abe..69e4617f 100644 --- a/core/app/helpers/comable/application_helper.rb +++ b/core/app/helpers/comable/application_helper.rb @@ -5,7 +5,9 @@ def current_store end def current_comable_user - resource = current_admin_user || current_user || Comable::User.new + resource = current_admin_user if defined? Comable::Backend + resource ||= current_user if defined? Comable::Frontend + resource ||= Comable::User.new resource.with_cookies(cookies) end @@ -66,7 +68,7 @@ def comable_root_path when :admin_user comable.admin_root_path else - comable.root_path + defined?(Comable::Frontend) ? comable.root_path : '/' end end diff --git a/core/spec/helpers/comable/application_helper_spec.rb b/core/spec/helpers/comable/application_helper_spec.rb index a3c4a9a6..70a160f0 100644 --- a/core/spec/helpers/comable/application_helper_spec.rb +++ b/core/spec/helpers/comable/application_helper_spec.rb @@ -52,6 +52,17 @@ before { def subject.resource_name; end } + it 'returns the root path for the customer in main_app' do + frontend = Comable::Frontend + begin + Comable.send(:remove_const, :Frontend) + allow(subject).to receive(:resource_name).and_return(:user) + expect(subject.send(:comable_root_path)).to eq('/') + ensure + Comable.const_set(:Frontend, frontend) + end + end + it 'returns the root path for the customer in frontend' do allow(subject).to receive(:resource_name).and_return(:user) expect(subject.send(:comable_root_path)).to eq(comable.root_path)