Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- "3.3"
- "3.4"
alchemy:
- "8.0-stable"
- "main"
solidus:
- "v4.5"
- "v4.6"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ log/*.log
pkg/
/spec/dummy/
!/spec/dummy/app/models/spree/user.rb
!/spec/dummy/Gemfile
Gemfile.lock
.ruby-version
.claude/
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gem "solidus_core", github: "solidusio/solidus", branch: solidus_branch
gem "solidus_backend", github: "solidusio/solidus", branch: solidus_branch
gem "solidus_frontend", github: "solidusio/solidus_frontend", branch: "main"

alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "8.0-stable")
alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "main")
gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: alchemy_branch
gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: alchemy_branch

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ To use Solidus Auth Devise, instruct Alchemy to use the `Spree::User` class:

```ruby
# config/initializers/alchemy.rb
Alchemy.user_class_name = 'Spree::User'
Alchemy.current_user_method = :spree_current_user
Alchemy.config.user_class = 'Spree::User'
Alchemy.config.current_user_method = :spree_current_user
```

If you put Spree in it's own routing namespace (see below) you will want to
let Alchemy know these paths:

```ruby
# config/initializers/alchemy.rb
Alchemy.login_path = '/store/login'
Alchemy.logout_path = '/store/logout'
Alchemy.config.login_path = '/store/login'
Alchemy.config.logout_path = '/store/logout'
```

#### 2. Option: Use [Alchemy Devise](https://github.com/AlchemyCMS/alchemy-devise)
Expand Down Expand Up @@ -161,15 +161,15 @@ and tell Solidus about Alchemy's path helpers:
# lib/spree/authentication_helpers.rb
...
def spree_login_path
Alchemy.login_path
Alchemy.config.login_path
end

def spree_signup_path
Alchemy.signup_path
Alchemy.config.signup_path
end

def spree_logout_path
Alchemy.logout_path
Alchemy.config.logout_path
end
...
```
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ task default: %i[test_setup spec]

desc "Setup test app"
task :test_setup do
solidus_branch = ENV.fetch("SOLIDUS_BRANCH", "v4.4")
solidus_branch = ENV.fetch("SOLIDUS_BRANCH", "v4.6")
solidus_install_options = "--payment-method=none --frontend=none --authentication=none"
if ["v4.5", "v4.6", "main"].include?(solidus_branch)
solidus_install_options += " --admin-preview=false"
end
ENV["SKIP_SOLIDUS_BOLT"] = "1" # solidus_frontend defaults to installing solidus_bolt if auto-accept is used
Dir.chdir("spec/dummy") do
system <<~SETUP
bin/rake db:environment:set db:drop && \
Expand Down
2 changes: 1 addition & 1 deletion alchemy-solidus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Alchemy::Solidus::VERSION

gem.add_dependency("alchemy_cms", [">= 8.0.0.b", "< 9"])
gem.add_dependency("alchemy_cms", [">= 8.1.0.a", "< 9"])
gem.add_dependency("solidus_api", [">= 4.0.0", "< 5"])
gem.add_dependency("solidus_core", [">= 4.0.0", "< 5"])
gem.add_dependency("solidus_backend", [">= 4.0.0", "< 5"])
Expand Down
23 changes: 23 additions & 0 deletions app/components/alchemy/ingredients/spree_product_editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Alchemy
module Ingredients
class SpreeProductEditor < BaseEditor
delegate :product, to: :ingredient

def input_field
render Alchemy::Admin::ProductSelect.new(api_key, product:, query_params:) do
text_field_tag form_field_name(:product_id),
product&.id,
id: form_field_id(:product_id),
class: "full_width"
end
end

private

def api_key = helpers.current_alchemy_user&.spree_api_key
def query_params = settings[:query_params]
end
end
end
23 changes: 23 additions & 0 deletions app/components/alchemy/ingredients/spree_taxon_editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Alchemy
module Ingredients
class SpreeTaxonEditor < BaseEditor
delegate :taxon, to: :ingredient

def input_field
render Alchemy::Admin::TaxonSelect.new(api_key, taxon:, query_params:) do
text_field_tag form_field_name(:taxon_id),
taxon&.id,
id: form_field_id(:taxon_id),
class: "full_width"
end
end

private

def api_key = helpers.current_alchemy_user&.spree_api_key
def query_params = settings[:query_params]
end
end
end
23 changes: 23 additions & 0 deletions app/components/alchemy/ingredients/spree_variant_editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Alchemy
module Ingredients
class SpreeVariantEditor < BaseEditor
delegate :variant, to: :ingredient

def input_field
render Alchemy::Admin::VariantSelect.new(api_key, variant:, query_params:) do
text_field_tag form_field_name(:variant_id),
variant&.id,
id: form_field_id(:variant_id),
class: "full_width"
end
end

private

def api_key = helpers.current_alchemy_user&.spree_api_key
def query_params = settings[:query_params]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Alchemy
module Solidus
module ApplicationControllerPatch
def spree_current_user
if Alchemy.user_class_name == "::Alchemy::User"
if Alchemy.config.user_class_name == "::Alchemy::User"
current_user
else
super
Expand Down
17 changes: 0 additions & 17 deletions app/views/alchemy/ingredients/_spree_product_editor.html.erb

This file was deleted.

4 changes: 0 additions & 4 deletions app/views/alchemy/ingredients/_spree_product_view.html.erb

This file was deleted.

17 changes: 0 additions & 17 deletions app/views/alchemy/ingredients/_spree_taxon_editor.html.erb

This file was deleted.

4 changes: 0 additions & 4 deletions app/views/alchemy/ingredients/_spree_taxon_view.html.erb

This file was deleted.

36 changes: 0 additions & 36 deletions app/views/alchemy/ingredients/_spree_variant_editor.html.erb

This file was deleted.

4 changes: 0 additions & 4 deletions app/views/alchemy/ingredients/_spree_variant_view.html.erb

This file was deleted.

13 changes: 5 additions & 8 deletions config/initializers/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
controller: "/spree/admin/orders",
action: "index",
name: "Store",
icon: (Alchemy.gem_version >= Gem::Version.new("7.4.0.a")) ? "shopping-cart" : "shopping-cart-line",
icon: "shopping-cart",
data: {turbolinks: false, turbo: false},
sub_navigation: [
{
Expand Down Expand Up @@ -35,13 +35,10 @@
name: "Users"
}
)
Alchemy.user_class_name = "Spree::User"
Alchemy.current_user_method = :spree_current_user

if Alchemy.respond_to?(:logout_method)
Rails.application.config.after_initialize do
Alchemy.logout_method = Devise.sign_out_via
end
Alchemy.config.user_class = "Spree::User"
Alchemy.config.current_user_method = :spree_current_user
Rails.application.config.after_initialize do
Alchemy.logout_method = Devise.sign_out_via.to_s
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Engine < ::Rails::Engine
end

config.to_prepare do
Alchemy.register_ability ::Spree::Ability
Alchemy.config.abilities.add("Spree::Ability")
::Spree::Ability.register_ability ::Alchemy::Permissions

if SolidusSupport.frontend_available?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module Alchemy
module Solidus
module SpreeAdminBaseControllerPatch
def self.prepended(base)
if Alchemy.user_class_name == "::Alchemy::User"
if Alchemy.config.user_class_name == "::Alchemy::User"
base.unauthorized_redirect = -> do
if spree_current_user
flash[:error] = I18n.t("spree.authorization_failure")
redirect_to spree.root_path
else
store_location
redirect_to Alchemy.login_path
redirect_to Alchemy.config.login_path
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,29 @@

require "rails_helper"

RSpec.describe "alchemy/ingredients/_spree_product_editor" do
RSpec.describe Alchemy::Ingredients::SpreeProductEditor, type: :component do
let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat") }
let(:element_editor) { Alchemy::ElementEditor.new(element) }
let(:ingredient) { Alchemy::Ingredients::SpreeProduct.new(element: element, role: "product") }
let(:ingredient_editor) { described_class.new(ingredient) }
let(:ingredient) { Alchemy::Ingredients::SpreeProduct.new(id: 1234, element: element, role: "product") }

before do
allow(element).to receive(:definition) do
Alchemy::ElementDefinition.new(
name: "all_you_can_eat",
ingredients: [
{role: "product",
type: "SpreeProduct"},
{role: "variant",
type: "SpreeVariant"},
{role: "taxon",
type: "SpreeTaxon"}
type: "SpreeProduct"}
]
)
end

allow(element_editor).to receive(:ingredients) { [Alchemy::IngredientEditor.new(ingredient)] }
view.class.send(:include, Alchemy::Admin::IngredientsHelper)
view.class.define_method(:current_alchemy_user) { nil } # trick rspec-mocks to allow this method to be stubbed
allow(view).to receive(:current_alchemy_user) { build_stubbed(:alchemy_admin_user) }
vc_test_view_context.class.include Alchemy::Admin::BaseHelper
vc_test_view_context.class.define_method(:current_alchemy_user) { nil } # trick rspec-mocks to allow this method to be stubbed
allow(vc_test_view_context).to receive(:current_alchemy_user) { build_stubbed(:alchemy_admin_user) }
end

subject do
render element_editor
rendered
render_inline ingredient_editor
page
end

it_behaves_like "an alchemy ingredient editor"
Expand Down
Loading