Skip to content

Commit

Permalink
Merge 48e36ec into 8718828
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Cake committed Aug 28, 2015
2 parents 8718828 + 48e36ec commit 5150c85
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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'
}

Expand Down
4 changes: 4 additions & 0 deletions core/app/controllers/comable/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Comable
class ApplicationController < ActionController::Base
end
end
27 changes: 19 additions & 8 deletions core/app/helpers/comable/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -65,24 +67,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
defined?(Comable::Frontend) ? 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
27 changes: 27 additions & 0 deletions core/spec/helpers/comable/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,31 @@
expect(subject.current_navigations).to eq(Comable::Navigation.all)
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 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)
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
2 changes: 1 addition & 1 deletion frontend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5150c85

Please sign in to comment.