diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8705065..3a05401 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,9 +11,9 @@ jobs: ruby-version: - "3.0" - "3.1" + - "3.2" alchemy: - - "6.0" - - "6.1" + - "7.0.0-a" solidus: - "3.2" - "3.3" @@ -21,15 +21,17 @@ jobs: ALCHEMY_VERSION: ${{ matrix.alchemy }} SOLIDUS_VERSION: ${{ matrix.solidus }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Set up Node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: 14 + - name: Prepare tests + run: bundle exec rake test_setup - name: Run tests - run: bundle exec rake + run: bundle exec rspec diff --git a/Gemfile b/Gemfile index 2c6f8d4..59588cf 100644 --- a/Gemfile +++ b/Gemfile @@ -5,16 +5,16 @@ gem "solidus_core", "~> #{solidus_version}.0" gem "solidus_frontend", "~> #{solidus_version}.0" gem "solidus_backend", "~> #{solidus_version}.0" -alchemy_version = ENV.fetch("ALCHEMY_VERSION", "6.1") -gem "alchemy_cms", "~> #{alchemy_version}.0" -gem "alchemy-devise", "~> #{alchemy_version}.0" +gem "alchemy_cms", "~> 7.0.0-a" +gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: "main" # Specify your gem's dependencies in alchemy-solidus.gemspec gemspec gem "sqlite3" gem "pry-rails" -gem "sprockets", "< 4" +gem "sprockets", "~> 4.0" +gem "jsbundling-rails", "~> 1.1" gem "rails", "~> 6.1.0" gem "listen" gem "puma" diff --git a/Rakefile b/Rakefile index 79d20cd..2cae576 100644 --- a/Rakefile +++ b/Rakefile @@ -27,8 +27,10 @@ task :test_setup do bin/rails g gutentag:migration_versions && \ bin/rails g solidus:install --force --auto-accept --no-seed --no-sample #{solidus_install_options} && \ bin/rails g solidus_frontend:install --force --auto-accept && \ + bin/rails javascript:install:esbuild && \ bin/rails g alchemy:solidus:install --auto-accept --force && \ - bin/rake db:test:prepare + bin/rake db:test:prepare && \ + bin/rails javascript:build SETUP exit($?.exitstatus) unless $?.success? end diff --git a/alchemy-solidus.gemspec b/alchemy-solidus.gemspec index 055c41f..f86a846 100644 --- a/alchemy-solidus.gemspec +++ b/alchemy-solidus.gemspec @@ -13,13 +13,13 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.version = Alchemy::Solidus::VERSION - gem.add_dependency("alchemy_cms", [">= 6.0.0", "< 7"]) + gem.add_dependency("alchemy_cms", [">= 7.0.0.a", "< 8"]) gem.add_dependency("solidus_core", [">= 3.0.0", "< 4.0"]) gem.add_dependency("solidus_backend", [">= 3.0.0", "< 4.0"]) gem.add_dependency("solidus_support", [">= 0.1.1"]) gem.add_dependency("deface", ["~> 1.0"]) - gem.add_development_dependency("rspec-rails", ["~> 5.0"]) + gem.add_development_dependency("rspec-rails", ["~> 6.0"]) gem.add_development_dependency("shoulda-matchers", ["~> 4.0"]) gem.add_development_dependency("capybara", ["~> 2.15"]) gem.add_development_dependency("capybara-screenshot", ["~> 1.0"]) diff --git a/app/models/alchemy/essence_spree_product.rb b/app/models/alchemy/essence_spree_product.rb deleted file mode 100644 index f8d2243..0000000 --- a/app/models/alchemy/essence_spree_product.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Alchemy - class EssenceSpreeProduct < ActiveRecord::Base - PRODUCT_ID = /\A\d+\z/ - - belongs_to :product, - class_name: "Spree::Product", - optional: true, - foreign_key: "spree_product_id" - - acts_as_essence(ingredient_column: :product) - - def ingredient=(product_or_id) - case product_or_id - when PRODUCT_ID, "" - self.spree_product_id = product_or_id - when Spree::Product - self.product = product_or_id - else - super - end - end - - def preview_text(_maxlength) - return unless product - product.name - end - end -end diff --git a/app/models/alchemy/essence_spree_taxon.rb b/app/models/alchemy/essence_spree_taxon.rb deleted file mode 100644 index 59e89da..0000000 --- a/app/models/alchemy/essence_spree_taxon.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Alchemy - class EssenceSpreeTaxon < ActiveRecord::Base - TAXON_ID = /\A\d+\z/ - - belongs_to :taxon, - class_name: "Spree::Taxon", - optional: true, - foreign_key: "taxon_id" - - acts_as_essence(ingredient_column: :taxon) - - def ingredient=(taxon_or_id) - case taxon_or_id - when TAXON_ID, "" - self.taxon_id = taxon_or_id - when Spree::Taxon - self.taxon = taxon_or_id - else - super - end - end - - def preview_text(_maxlength) - return unless taxon - taxon.name - end - end -end diff --git a/app/models/alchemy/essence_spree_variant.rb b/app/models/alchemy/essence_spree_variant.rb deleted file mode 100644 index fb5eceb..0000000 --- a/app/models/alchemy/essence_spree_variant.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Alchemy - class EssenceSpreeVariant < ActiveRecord::Base - VARIANT_ID = /\A\d+\z/ - - belongs_to :variant, - class_name: "Spree::Variant", - optional: true - - acts_as_essence(ingredient_column: :variant) - - def ingredient=(variant_or_id) - case variant_or_id - when VARIANT_ID, "" - self.variant_id = variant_or_id - when Spree::Variant - self.variant = variant_or_id - else - super - end - end - - def preview_text(_maxlength) - return unless variant - variant.descriptive_name - end - end -end diff --git a/app/views/alchemy/essences/_essence_spree_product_editor.html.erb b/app/views/alchemy/essences/_essence_spree_product_editor.html.erb deleted file mode 100644 index 91997c2..0000000 --- a/app/views/alchemy/essences/_essence_spree_product_editor.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<% content ||= local_assigns[:content] || local_assigns[:essence_spree_product_editor] %> - -
- <%= content_label(content) %> - <%= text_field_tag( - content.form_field_name, - content.essence.spree_product_id, - id: content.form_field_id, - class: 'alchemy_selectbox full_width' - ) %> -
- - diff --git a/app/views/alchemy/essences/_essence_spree_product_view.html.erb b/app/views/alchemy/essences/_essence_spree_product_view.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/alchemy/essences/_essence_spree_taxon_editor.html.erb b/app/views/alchemy/essences/_essence_spree_taxon_editor.html.erb deleted file mode 100644 index af7fede..0000000 --- a/app/views/alchemy/essences/_essence_spree_taxon_editor.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<% content ||= local_assigns[:content] || local_assigns[:essence_spree_taxon_editor] %> - -
- <%= content_label(content) %> - <%= text_field_tag( - content.form_field_name, - content.essence.taxon_id, - id: content.form_field_id, - class: 'alchemy_selectbox full_width' - ) %> -
- - diff --git a/app/views/alchemy/essences/_essence_spree_taxon_view.html.erb b/app/views/alchemy/essences/_essence_spree_taxon_view.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/alchemy/essences/_essence_spree_variant_editor.html.erb b/app/views/alchemy/essences/_essence_spree_variant_editor.html.erb deleted file mode 100644 index 637b64a..0000000 --- a/app/views/alchemy/essences/_essence_spree_variant_editor.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<% content ||= local_assigns[:content] || local_assigns[:essence_spree_variant_editor] %> - -
- <%= content_label(content) %> - <%= text_field_tag( - content.form_field_name, - content.essence.variant_id, - id: content.form_field_id, - class: 'alchemy_selectbox full_width' - ) %> -
- - diff --git a/app/views/alchemy/essences/_essence_spree_variant_view.html.erb b/app/views/alchemy/essences/_essence_spree_variant_view.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js index 0cf91f4..338a0e8 100644 --- a/spec/dummy/app/assets/config/manifest.js +++ b/spec/dummy/app/assets/config/manifest.js @@ -1,5 +1,3 @@ - //= link_tree ../images -//= link_directory ../javascripts .js //= link_directory ../stylesheets .css -//= link rails5_engine_manifest.js +//= link_tree ../builds diff --git a/spec/dummy/app/views/alchemy/elements/_all_you_can_eat.html.erb b/spec/dummy/app/views/alchemy/elements/_all_you_can_eat.html.erb new file mode 100644 index 0000000..265d7e8 --- /dev/null +++ b/spec/dummy/app/views/alchemy/elements/_all_you_can_eat.html.erb @@ -0,0 +1,13 @@ +<%- cache(all_you_can_eat) do -%> + <%= element_view_for(all_you_can_eat) do |el| -%> +
+ <%= el.render(:product) %> +
+
+ <%= el.render(:variant) %> +
+
+ <%= el.render(:taxon) %> +
+ <%- end -%> +<%- end -%> diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb index a6eb017..7e744bd 100644 --- a/spec/dummy/app/views/layouts/application.html.erb +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -5,7 +5,7 @@ <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all' %> - <%= javascript_include_tag 'application' %> + <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> diff --git a/spec/dummy/config/alchemy/elements.yml b/spec/dummy/config/alchemy/elements.yml new file mode 100644 index 0000000..d46a117 --- /dev/null +++ b/spec/dummy/config/alchemy/elements.yml @@ -0,0 +1,4 @@ +# == In this configuration, you set up Alchemy's element layouts. +# +# For further information please see http://guides.alchemy-cms.com/stable/elements.html + diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb index e69de29..d553068 100644 --- a/spec/dummy/db/seeds.rb +++ b/spec/dummy/db/seeds.rb @@ -0,0 +1,4 @@ + +Spree::Core::Engine.load_seed if defined?(Spree::Core) +Spree::Auth::Engine.load_seed if defined?(Spree::Auth) +Alchemy::Seeder.seed! diff --git a/spec/dummy/package.json b/spec/dummy/package.json new file mode 100644 index 0000000..a7f9caf --- /dev/null +++ b/spec/dummy/package.json @@ -0,0 +1,11 @@ +{ + "name": "app", + "private": "true", + "dependencies": { + "@alchemy_cms/admin": "~7.0.0-a", + "esbuild": "^0.17.14" + }, + "scripts": { + "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets" + } +} diff --git a/spec/features/alchemy/alchemy_admin_integrations_spec.rb b/spec/features/alchemy/alchemy_admin_integrations_spec.rb index cee021f..e274f28 100644 --- a/spec/features/alchemy/alchemy_admin_integrations_spec.rb +++ b/spec/features/alchemy/alchemy_admin_integrations_spec.rb @@ -1,6 +1,5 @@ require "alchemy/version" require "rails_helper" -require "alchemy/devise/test_support/factories" RSpec.feature "Admin Integration", type: :feature do let!(:user) do diff --git a/spec/models/alchemy/essence_spree_product_spec.rb b/spec/models/alchemy/essence_spree_product_spec.rb deleted file mode 100644 index f60ac1e..0000000 --- a/spec/models/alchemy/essence_spree_product_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" -require "alchemy/test_support/essence_shared_examples" - -require_dependency "alchemy/site" - -RSpec.describe Alchemy::EssenceSpreeProduct, type: :model do - let(:product) { build_stubbed(:product) } - let(:essence) { described_class.new(product: product) } - - it_behaves_like "an essence" do - let(:ingredient_value) { product } - end - - describe "ingredient=" do - context "when String value is empty" do - let(:value) { "" } - - before do - essence.ingredient = value - end - - it "sets spree_product_id to nil" do - expect(essence.spree_product_id).to eq(nil) - end - end - - context "when String value is only a number" do - let(:value) { "101" } - - before do - essence.ingredient = value - end - - it "sets spree_product_id with that id" do - expect(essence.spree_product_id).to eq(101) - end - end - - context "when value is an Spree Variant" do - let(:value) { product } - - before do - essence.ingredient = value - end - - it "sets product to that product" do - expect(essence.product).to eq(product) - end - end - - context "when value is not only a number" do - let(:value) { "product1" } - - it do - expect { - essence.ingredient = value - }.to raise_error(ActiveRecord::AssociationTypeMismatch) - end - end - end - - describe "#preview_text" do - subject { essence.preview_text(nil) } - - it "returns the products name" do - is_expected.to eq(product.name) - end - end -end diff --git a/spec/models/alchemy/essence_spree_taxon_spec.rb b/spec/models/alchemy/essence_spree_taxon_spec.rb deleted file mode 100644 index 3b7f463..0000000 --- a/spec/models/alchemy/essence_spree_taxon_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" -require "alchemy/test_support/essence_shared_examples" - -require_dependency "alchemy/site" - -RSpec.describe Alchemy::EssenceSpreeTaxon, type: :model do - let(:taxon) { build_stubbed(:taxon) } - let(:essence) { described_class.new(taxon: taxon) } - - it_behaves_like "an essence" do - let(:ingredient_value) { taxon } - end - - describe "ingredient=" do - context "when String is empty" do - let(:value) { "" } - - before do - essence.ingredient = value - end - - it "sets taxon_id to nil" do - expect(essence.taxon_id).to eq(nil) - end - end - - context "when String value is only a number" do - let(:value) { "101" } - - before do - essence.ingredient = value - end - - it "sets taxon_id with that id" do - expect(essence.taxon_id).to eq(101) - end - end - - context "when value is an Spree Variant" do - let(:value) { taxon } - - before do - essence.ingredient = value - end - - it "sets taxon to that taxon" do - expect(essence.taxon).to eq(taxon) - end - end - - context "when value is not only a number" do - let(:value) { "taxon1" } - - it do - expect { - essence.ingredient = value - }.to raise_error(ActiveRecord::AssociationTypeMismatch) - end - end - end - - describe "#preview_text" do - subject { essence.preview_text(nil) } - - it "returns the taxons name" do - is_expected.to eq(taxon.name) - end - end -end diff --git a/spec/models/alchemy/essence_spree_variant_spec.rb b/spec/models/alchemy/essence_spree_variant_spec.rb deleted file mode 100644 index 8627faf..0000000 --- a/spec/models/alchemy/essence_spree_variant_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" -require "alchemy/test_support/essence_shared_examples" - -require_dependency "alchemy/site" - -RSpec.describe Alchemy::EssenceSpreeVariant, type: :model do - let(:variant) { build(:variant) } - let(:essence) { described_class.new(variant: variant) } - - it_behaves_like "an essence" do - let(:ingredient_value) { variant } - end - - describe "ingredient=" do - context "when String value is empty" do - let(:value) { "" } - - before do - essence.ingredient = value - end - - it "sets variant_id to nil" do - expect(essence.variant_id).to eq(nil) - end - end - - context "when String value is only a number" do - let(:value) { "101" } - - before do - essence.ingredient = value - end - - it "sets variant_id with that id" do - expect(essence.variant_id).to eq(101) - end - end - - context "when value is an Spree Variant" do - let(:value) { variant } - - before do - essence.ingredient = value - end - - it "sets variant to that variant" do - expect(essence.variant).to eq(variant) - end - end - - context "when value is not only a number" do - let(:value) { "variant1" } - - it do - expect { - essence.ingredient = value - }.to raise_error(ActiveRecord::AssociationTypeMismatch) - end - end - end - - describe "#preview_text" do - subject { essence.preview_text(nil) } - - it "returns the variants name" do - is_expected.to eq(variant.descriptive_name) - end - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3450f5c..a58b055 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -46,6 +46,9 @@ FactoryBot.definition_file_paths.append(Alchemy::TestSupport.factories_path) FactoryBot.reload +require "alchemy/devise/test_support/factories" +require "alchemy/test_support/shared_ingredient_editor_examples" + RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/views/alchemy/essences/essence_spree_product_editor_spec.rb b/spec/views/alchemy/essences/essence_spree_product_editor_spec.rb deleted file mode 100644 index 5419416..0000000 --- a/spec/views/alchemy/essences/essence_spree_product_editor_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "alchemy/essences/_essence_spree_product_editor" do - let(:content) do - content = Alchemy::Content.new(essence: essence) - if Alchemy.gem_version >= Gem::Version.new("4.9") - Alchemy::ContentEditor.new(content) - else - content - end - end - - let(:essence) { Alchemy::EssenceSpreeProduct.new } - - before do - view.class.send(:include, Alchemy::Admin::ElementsHelper) - expect(view).to receive(:content_label) { content.name } - end - - context "with local named content" do - subject do - render "alchemy/essences/essence_spree_product_editor", - content: content, - spree: double(api_products_path: "/api/products"), - current_alchemy_user: double(spree_api_key: "123") - rendered - end - - it "renders a product input" do - is_expected.to have_css("input.alchemy_selectbox.full_width") - end - - context "with a product related to essence" do - let(:product) { Spree::Product.new(id: 1) } - let(:essence) { Alchemy::EssenceSpreeProduct.new(spree_product_id: product.id) } - - it "sets product id as value" do - is_expected.to have_css('input.alchemy_selectbox[value="1"]') - end - end - end - - context "with local named essence_spree_product_editor" do - subject do - render "alchemy/essences/essence_spree_product_editor", - essence_spree_product_editor: content, - spree: double(api_products_path: "/api/products"), - current_alchemy_user: double(spree_api_key: "123") - rendered - end - - it "renders a product input" do - is_expected.to have_css("input.alchemy_selectbox.full_width") - end - - context "with a product related to essence" do - let(:product) { Spree::Product.new(id: 1) } - let(:essence) { Alchemy::EssenceSpreeProduct.new(spree_product_id: product.id) } - - it "sets product id as value" do - is_expected.to have_css('input.alchemy_selectbox[value="1"]') - end - end - end -end diff --git a/spec/views/alchemy/essences/essence_spree_taxon_editor_spec.rb b/spec/views/alchemy/essences/essence_spree_taxon_editor_spec.rb deleted file mode 100644 index 3c9cc67..0000000 --- a/spec/views/alchemy/essences/essence_spree_taxon_editor_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "alchemy/essences/_essence_spree_taxon_editor" do - let(:content) do - content = Alchemy::Content.new(essence: essence) - if Alchemy.gem_version >= Gem::Version.new("4.9") - Alchemy::ContentEditor.new(content) - else - content - end - end - let(:essence) { Alchemy::EssenceSpreeTaxon.new } - - before do - view.class.send(:include, Alchemy::Admin::ElementsHelper) - allow(view).to receive(:content_label) { content.name } - end - - context "with local named content" do - subject do - render "alchemy/essences/essence_spree_taxon_editor", - content: content, - spree: double(api_taxons_path: "/api/taxons"), - current_alchemy_user: double(spree_api_key: "123") - rendered - end - - it "renders a taxon input" do - is_expected.to have_css("input.alchemy_selectbox.full_width") - end - - context "with a taxon related to essence" do - let(:taxon) { Spree::Taxon.new(id: 1) } - let(:essence) { Alchemy::EssenceSpreeTaxon.new(taxon_id: taxon.id) } - - it "sets taxon id as value" do - is_expected.to have_css('input.alchemy_selectbox[value="1"]') - end - end - end - - context "with local named essence_spree_taxon_editor" do - subject do - render "alchemy/essences/essence_spree_taxon_editor", - essence_spree_taxon_editor: content, - spree: double(api_taxons_path: "/api/taxons"), - current_alchemy_user: double(spree_api_key: "123") - rendered - end - - it "renders a taxon input" do - is_expected.to have_css("input.alchemy_selectbox.full_width") - end - - context "with a taxon related to essence" do - let(:taxon) { Spree::Taxon.new(id: 1) } - let(:essence) { Alchemy::EssenceSpreeTaxon.new(taxon_id: taxon.id) } - - it "sets taxon id as value" do - is_expected.to have_css('input.alchemy_selectbox[value="1"]') - end - end - end -end diff --git a/spec/views/alchemy/essences/essence_spree_variant_editor_spec.rb b/spec/views/alchemy/essences/essence_spree_variant_editor_spec.rb deleted file mode 100644 index 5e42b14..0000000 --- a/spec/views/alchemy/essences/essence_spree_variant_editor_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "alchemy/essences/_essence_spree_variant_editor" do - let(:content) do - content = Alchemy::Content.new(essence: essence) - if Alchemy.gem_version >= Gem::Version.new("4.9") - Alchemy::ContentEditor.new(content) - else - content - end - end - let(:essence) { Alchemy::EssenceSpreeVariant.new } - - before do - view.class.send(:include, Alchemy::Admin::ElementsHelper) - allow(view).to receive(:content_label) { content.name } - end - - context "with local named content" do - subject do - render "alchemy/essences/essence_spree_variant_editor", - content: content, - spree: double(api_variants_path: "/api/variants"), - current_alchemy_user: double(spree_api_key: "123") - rendered - end - - it "renders a variant input" do - is_expected.to have_css("input.alchemy_selectbox.full_width") - end - - context "with a variant related to essence" do - let(:product) { Spree::Product.new(name: "Chocolate") } - let(:variant) { Spree::Variant.new(id: 1, product: product) } - let(:essence) { Alchemy::EssenceSpreeVariant.new(variant_id: variant.id) } - - it "sets variant id as value" do - is_expected.to have_css('input.alchemy_selectbox[value="1"]') - end - end - end - - context "with local named essence_spree_variant_editor" do - subject do - render "alchemy/essences/essence_spree_variant_editor", - essence_spree_variant_editor: content, - spree: double(api_variants_path: "/api/variants"), - current_alchemy_user: double(spree_api_key: "123") - rendered - end - - it "renders a variant input" do - is_expected.to have_css("input.alchemy_selectbox.full_width") - end - - context "with a variant related to essence" do - let(:product) { Spree::Product.new(name: "Chocolate") } - let(:variant) { Spree::Variant.new(id: 1, product: product) } - let(:essence) { Alchemy::EssenceSpreeVariant.new(variant_id: variant.id) } - - it "sets variant id as value" do - is_expected.to have_css('input.alchemy_selectbox[value="1"]') - end - end - end -end diff --git a/spec/views/alchemy/ingredients/spree_product_editor_spec.rb b/spec/views/alchemy/ingredients/spree_product_editor_spec.rb new file mode 100644 index 0000000..0f93cc4 --- /dev/null +++ b/spec/views/alchemy/ingredients/spree_product_editor_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "alchemy/ingredients/_spree_product_editor" 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") } + + before do + allow(element).to receive(:definition) do + { + name: "all_you_can_eat", + ingredients: [ + { role: "product", + type: "SpreeProduct" }, + { role: "variant", + type: "SpreeVariant" }, + { role: "taxon", + type: "SpreeTaxon" }, + ], + } + 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) } + end + + subject do + render element_editor + rendered + end + + it_behaves_like "an alchemy ingredient editor" + + it "renders a product input" do + is_expected.to have_css("input.alchemy_selectbox.full_width") + end + + context "with a product related to ingredient" do + let(:product) { Spree::Product.new(id: 1) } + + let(:ingredient) do + Alchemy::Ingredients::SpreeProduct.new(element: element, role: "product", product: product) + end + + it "sets product id as value" do + is_expected.to have_css('input.alchemy_selectbox[value="1"]') + end + end +end diff --git a/spec/views/alchemy/ingredients/spree_taxon_editor_spec.rb b/spec/views/alchemy/ingredients/spree_taxon_editor_spec.rb new file mode 100644 index 0000000..a657dbd --- /dev/null +++ b/spec/views/alchemy/ingredients/spree_taxon_editor_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "alchemy/ingredients/_spree_taxon_editor" do + let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat") } + let(:element_editor) { Alchemy::ElementEditor.new(element) } + let(:ingredient) { Alchemy::Ingredients::SpreeTaxon.new(element: element, role: "taxon") } + + before do + allow(element).to receive(:definition) do + { + name: "all_you_can_eat", + ingredients: [ + { role: "product", + type: "SpreeProduct" }, + { role: "variant", + type: "SpreeVariant" }, + { role: "taxon", + type: "SpreeTaxon" }, + ], + } + 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) } + end + + subject do + render element_editor + rendered + end + + it_behaves_like "an alchemy ingredient editor" + + it "renders a taxon input" do + is_expected.to have_css("input.alchemy_selectbox.full_width") + end + + context "with a taxon related to ingredient" do + let(:taxon) { Spree::Taxon.new(id: 1) } + + let(:ingredient) do + Alchemy::Ingredients::SpreeTaxon.new(element: element, role: "taxon", taxon: taxon) + end + + it "sets taxon id as value" do + is_expected.to have_css('input.alchemy_selectbox[value="1"]') + end + end +end diff --git a/spec/views/alchemy/ingredients/spree_variant_editor_spec.rb b/spec/views/alchemy/ingredients/spree_variant_editor_spec.rb new file mode 100644 index 0000000..b634cfd --- /dev/null +++ b/spec/views/alchemy/ingredients/spree_variant_editor_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "alchemy/ingredients/_spree_variant_editor" do + let(:element) { build_stubbed(:alchemy_element, name: "all_you_can_eat") } + let(:element_editor) { Alchemy::ElementEditor.new(element) } + let(:ingredient) { Alchemy::Ingredients::SpreeVariant.new(element: element, role: "variant") } + + before do + allow(element).to receive(:definition) do + { + name: "all_you_can_eat", + ingredients: [ + { role: "product", + type: "SpreeProduct" }, + { role: "variant", + type: "SpreeVariant" }, + { role: "taxon", + type: "SpreeTaxon" }, + ], + } + 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) } + end + + subject do + render element_editor + rendered + end + + it_behaves_like "an alchemy ingredient editor" + + it "renders a variant input" do + is_expected.to have_css("input.alchemy_selectbox.full_width") + end + + context "with a variant related to ingredient" do + let(:variant) { Spree::Variant.new(id: 1, product: Spree::Product.new) } + + let(:ingredient) do + Alchemy::Ingredients::SpreeVariant.new(element: element, role: "variant", variant: variant) + end + + it "sets variant id as value" do + is_expected.to have_css('input.alchemy_selectbox[value="1"]') + end + end +end