Skip to content
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

Update dependencies to Solidus 2.0 and Alchemy 4.0 #15

Closed
wants to merge 9 commits into from
Closed
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
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
Gemfile.lock
/spec/dummy/
Gemfile.lock
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ gemspec

gem 'sqlite3'
gem 'alchemy-devise'
gem 'pry-rails'
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ Install the gem with:
$ bundle install
```

## Automated setup

We ship a Rails generator that helps you to install this gem into your existing Rails app.

```
$ bin/rails g alchemy:solidus:install
```

There are several options available, please check them by:

```
$ bin/rails g alchemy:solidus:install --help
```

## Manual setup

### Authentication system installation

Both Alchemy and Solidus come without an authentication system in place. You will need to choose an authentication system yourself. There are 3 available options. Whichever you choose, you need to instruct Solidus & Alchemy about your choice of authentication system.
Expand Down
34 changes: 19 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ begin
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
Bundler::GemHelper.install_tasks

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'AlchemySolidus'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

Bundler::GemHelper.install_tasks
task default: [:test_setup, :spec]

require 'active_support/core_ext/string'

desc 'Setup test app'
task :test_setup do
Dir.chdir('spec/dummy') do
system <<-SETUP.strip_heredoc
export RAILS_ENV=test && \
bin/rake db:drop db:create && \
bin/rails g spree:install --force --quiet --auto-accept --no-seed --no-sample && \
bin/rails g alchemy:solidus:install --auto-accept
SETUP
end
end
11 changes: 9 additions & 2 deletions alchemy-solidus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Alchemy::Solidus::VERSION

gem.add_dependency('alchemy_cms', ['~> 3.2'])
gem.add_dependency('solidus', ['~> 1.0'])
gem.add_dependency('alchemy_cms', ['>= 4.0.0.beta', '< 5.0'])
gem.add_dependency('solidus_core', ['~> 2.0'])
gem.add_dependency('solidus_backend', ['~> 2.0'])
gem.add_dependency('deface', ['~> 1.0'])

gem.add_development_dependency('rspec-rails', ['~> 3.7'])
gem.add_development_dependency('capybara', ['~> 2.15'])
gem.add_development_dependency('capybara-screenshot', ['~> 1.0'])
gem.add_development_dependency('factory_bot', ['~> 4.8'])
gem.add_development_dependency('ffaker', ['~> 2.7'])
end
14 changes: 14 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/alchemy/solidus/engine', __FILE__)
APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
require 'rails/engine/commands'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateAlchemyEssenceSpreeProducts < ActiveRecord::Migration
class CreateAlchemyEssenceSpreeProducts < ActiveRecord::Migration[4.2]
def change
create_table 'alchemy_essence_spree_products' do |t|
t.integer :spree_product_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateAlchemyEssenceSpreeTaxons < ActiveRecord::Migration
class CreateAlchemyEssenceSpreeTaxons < ActiveRecord::Migration[4.2]
def change
create_table :alchemy_essence_spree_taxons do |t|
t.references :taxon
Expand Down
2 changes: 0 additions & 2 deletions lib/alchemy-solidus.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
require "alchemy_cms"
require "solidus"
require "alchemy/solidus/engine"
20 changes: 14 additions & 6 deletions lib/alchemy/solidus/alchemy_user_extension.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
module Alchemy::SpreeUserExtension
def spree_roles
if admin?
::Spree::Role.where(name: 'admin')
else
::Spree::Role.none
module Alchemy
module Solidus
module AlchemyUserExtension
def self.included(klass)
klass.include Spree::UserMethods
end

def spree_roles
if admin?
::Spree::Role.where(name: 'admin')
else
::Spree::Role.none
end
end
end
end
end
15 changes: 13 additions & 2 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'alchemy/solidus/alchemy_user_extension'
require 'alchemy/solidus/spree_user_extension'
require 'alchemy_cms'
require 'solidus_core'
require 'solidus_backend'

module Alchemy
module Solidus
Expand All @@ -15,8 +18,16 @@ class Engine < ::Rails::Engine
config.to_prepare do
Alchemy.register_ability ::Spree::Ability
::Spree::Ability.register_ability ::Alchemy::Permissions
Spree::User.include Spree::AlchemyUserExtension if Alchemy.user_class_name == 'Spree::User'
Alchemy::User.include Alchemy::SpreeUserExtension if Alchemy.user_class_name == 'Alchemy::User'

if Alchemy.user_class_name == 'Spree::User'
require 'alchemy/solidus/spree_user_extension'
Spree::User.include Alchemy::Solidus::SpreeUserExtension
end

if Alchemy.user_class_name == 'Alchemy::User'
require 'alchemy/solidus/alchemy_user_extension'
Alchemy::User.include Alchemy::Solidus::AlchemyUserExtension
end
end
end
end
Expand Down
16 changes: 10 additions & 6 deletions lib/alchemy/solidus/spree_user_extension.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module Spree::AlchemyUserExtension
def alchemy_roles
if has_spree_role?(:admin)
%w(admin)
else
[]
module Alchemy
module Solidus
module SpreeUserExtension
def alchemy_roles
if has_spree_role?(:admin)
%w(admin)
else
[]
end
end
end
end
end
69 changes: 69 additions & 0 deletions lib/generators/alchemy/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'rails/generators'
require 'rails/generators/alchemy/install/install_generator'
require 'generators/spree/custom_user/custom_user_generator'

begin
require 'generators/alchemy/devise/install/install_generator'
rescue
end

module Alchemy
module Solidus
class InstallGenerator < Rails::Generators::Base
SPREE_MOUNT_REGEXP = /mount\sSpree::Core::Engine.*$/
desc "Installs Alchemy Solidus into your App."

class_option :skip_alchemy_installer, default: false, type: :boolean,
desc: "Set true if you don't want to run the Alchemy installer"
class_option :skip_alchemy_devise_installer, default: false, type: :boolean,
desc: "Set true if you don't want to run the Alchemy Devise installer. NOTE: Automatically skipped if Alchemy::Devise is not available."
class_option :skip_spree_custom_user_generator, default: false, type: :boolean,
desc: "Set true if you don't want to run the Solidus custom user generator. NOTE: Automatically skipped if Alchemy::Devise is not available."
class_option :auto_accept, default: false, type: :boolean,
desc: 'Set true if run from a automated script (ie. on a CI)'

def run_alchemy_installer
unless options[:skip_alchemy_installer]
arguments = options[:auto_accept] ? ['--skip-demo-files', '--force'] : []
Alchemy::Generators::InstallGenerator.start(arguments)
end
end

def run_alchemy_devise_installer
if Kernel.const_defined?('Alchemy::Devise') && !options[:skip_alchemy_devise_installer]
arguments = options[:auto_accept] ? ['--force'] : []
Alchemy::Devise::Generators::InstallGenerator.start(arguments)
end
end

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)
spree_initializer_file = Rails.root.join('config', 'initializers', 'spree.rb')
file_action = File.exist?(spree_initializer_file) ? :append_file : :create_file
public_send(file_action, spree_initializer_file) do
%{\nSpree.user_class = "Alchemy::User"\n}
end
rake 'db:migrate'
end
end

def inject_routes
routes_file_path = Rails.root.join('config', 'routes.rb')
mountpoint = '/'
unless options[:auto_accept]
mountpoint = ask("\nAt which path do you want to mount AlchemyCMS at?", default: mountpoint)
end
if File.read(routes_file_path).match SPREE_MOUNT_REGEXP
sentinel = SPREE_MOUNT_REGEXP
else
sentinel = "Rails.application.routes.draw do\n"
end
inject_into_file routes_file_path, {after: sentinel} do
"\n mount Alchemy::Engine, at: '/#{mountpoint.chomp('/')}'\n"
end
end
end
end
end
6 changes: 6 additions & 0 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
5 changes: 5 additions & 0 deletions spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link rails5_engine_manifest.js
Empty file.
13 changes: 13 additions & 0 deletions spec/dummy/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
15 changes: 15 additions & 0 deletions spec/dummy/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
3 changes: 3 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
Empty file.
2 changes: 2 additions & 0 deletions spec/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
3 changes: 3 additions & 0 deletions spec/dummy/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file.
14 changes: 14 additions & 0 deletions spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= csrf_meta_tags %>

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
</head>

<body>
<%= yield %>
</body>
</html>
3 changes: 3 additions & 0 deletions spec/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions spec/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions spec/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
38 changes: 38 additions & 0 deletions spec/dummy/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

# Install JavaScript dependencies if using Yarn
# system('bin/yarn')


# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end

puts "\n== Preparing database =="
system! 'bin/rails db:setup'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
Loading