Skip to content

Commit

Permalink
Merge pull request #34 from tvdeyen/alchemy-master-fixes
Browse files Browse the repository at this point in the history
Alchemy master fixes
  • Loading branch information
tvdeyen authored Mar 11, 2019
2 parents f5294fc + 4b3b419 commit 9558ee3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Engine < ::Rails::Engine
if Alchemy.user_class_name == 'Alchemy::User'
require 'alchemy/solidus/alchemy_user_extension'
Alchemy::User.include Alchemy::Solidus::AlchemyUserExtension
require 'alchemy/solidus/spree_admin_unauthorized_redirect'
end

if SolidusSupport.solidus_gem_version < Gem::Version.new('2.5')
Expand Down
9 changes: 9 additions & 0 deletions lib/alchemy/solidus/spree_admin_unauthorized_redirect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Spree::Admin::BaseController.unauthorized_redirect = -> do
if try_spree_current_user
flash[:error] = I18n.t('spree.authorization_failure')
redirect_to spree.root_path
else
store_location
redirect_to alchemy.login_path
end
end
8 changes: 7 additions & 1 deletion lib/generators/alchemy/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class InstallGenerator < Rails::Generators::Base
class_option :auto_accept, default: false, type: :boolean,
desc: 'Set true if run from a automated script (ie. on a CI)'

source_root File.expand_path('templates', __dir__)

def run_alchemy_installer
unless options[:skip_alchemy_installer]
arguments = options[:auto_accept] ? ['--skip-demo-files', '--force'] : []
Expand All @@ -43,14 +45,18 @@ def run_spree_custom_user_generator
if Kernel.const_defined?('Alchemy::Devise') && !options[:skip_spree_custom_user_generator]
arguments = options[:auto_accept] ? ['Alchemy::User', '--force'] : ['Alchemy::User']
Spree::CustomUserGenerator.start(arguments)
gsub_file 'lib/spree/authentication_helpers.rb', /main_app\./, 'alchemy.'
gsub_file 'lib/spree/authentication_helpers.rb', /main_app\./, 'Alchemy.'
if SolidusSupport.solidus_gem_version < Gem::Version.new('2.5.0')
gsub_file 'config/initializers/spree.rb', /Spree\.user_class.?=.?.+$/, 'Spree.user_class = "Alchemy::User"'
end
rake 'db:migrate'
end
end

def copy_alchemy_initializer
template "alchemy.rb.tt", "config/initializers/alchemy.rb"
end

def inject_admin_tab
inject_into_file 'config/initializers/spree.rb', {after: "Spree::Backend::Config.configure do |config|\n"} do
<<~ADMIN_TAB
Expand Down
42 changes: 42 additions & 0 deletions lib/generators/alchemy/solidus/install/templates/alchemy.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Alchemy::Modules.register_module({
engine_name: 'spree',
name: 'solidus',
navigation: {
controller: 'spree/admin/orders',
action: 'index',
name: 'Store',
image: 'alchemy/solidus/alchemy_module_icon.png',
data: { turbolinks: false },
sub_navigation: [
{
controller: 'spree/admin/orders',
action: 'index',
name: 'Orders'
},
{
controller: 'spree/admin/products',
action: 'index',
name: 'Products'
},
{
controller: 'spree/admin/promotions',
action: 'index',
name: 'Promotions'
},
{
controller: 'spree/admin/stock_items',
action: 'index',
name: 'Stock'
<%- if defined?(Spree::Auth::Engine) -%>
},
{
controller: 'spree/admin/users',
action: 'index',
name: 'Users'
}
<%- else -%>
}
<%- end -%>
]
}
})
9 changes: 8 additions & 1 deletion spec/features/alchemy/alchemy_admin_integrations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'alchemy/version'
require 'rails_helper'
begin
require 'factory_girl'
Expand All @@ -6,6 +7,12 @@
require 'spree/testing_support/factories/address_factory'

RSpec.feature "Admin Integration", type: :feature do
it 'gets redirected to login if accessing admin' do
visit '/admin'

expect(page).to have_field 'user_login'
end

it 'it is possible to login and visit Alchemy admin' do
login!
visit '/admin/dashboard'
Expand All @@ -28,6 +35,6 @@ def login!
expect(page).to have_field 'user_login'
fill_in 'user_login', with: 'admin'
fill_in 'user_password', with: 'test1234'
click_button 'login'
click_button Alchemy.version > '4.1.0' ? 'Login' : 'login'
end
end

0 comments on commit 9558ee3

Please sign in to comment.