Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Setup proper test environment in page_builder gem, move more specs
Damian Legawiec4ab35ed636cd
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex d05cb00e40..92f76be52e 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -121,7 +121,7 @@ jobs:parallelism: 2environment:<<: *environment- PROJECTS: storefront+ PROJECTS: storefront,page_buildertest_other_postgres:<<: *testenvironment:@@ -152,7 +152,7 @@ jobs:parallelism: 2environment:<<: *mysql_environment- PROJECTS: storefront+ PROJECTS: storefront,page_buildertest_other_mysql:<<: *test_mysqlenvironment:diff --git a/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rbindex b32f7cdf01..33f958aa09 100644--- a/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/store_serializer_spec.rb@@ -50,8 +50,7 @@ describe Spree::Api::V2::Platform::StoreSerializer dofavicon_path: nil,storefront_custom_code_body_end: nil,storefront_custom_code_body_start: nil,- storefront_custom_code_head: nil,- page_links_count: store.page_links_count+ storefront_custom_code_head: nil},relationships: {default_country: {diff --git a/bin/build-ci.rb b/bin/build-ci.rbindex 996eeceac4..6128d256ce 100755--- a/bin/build-ci.rb+++ b/bin/build-ci.rb@@ -21,7 +21,7 @@ class Project@name = nameend- ALL = %w[emails api core sample admin storefront].freeze+ ALL = %w[emails api core sample admin storefront page_builder].freezeCORE_GEMS = %w[api core].freeze# Install subprojectdiff --git a/core/app/jobs/spree/products/touch_taxons_job.rb b/core/app/jobs/spree/products/touch_taxons_job.rbindex a318661b69..6762daf911 100644--- a/core/app/jobs/spree/products/touch_taxons_job.rb+++ b/core/app/jobs/spree/products/touch_taxons_job.rb@@ -6,7 +6,6 @@ module Spreedef perform(taxon_ids, taxonomy_ids)Spree::Taxon.where(id: taxon_ids).update_all(updated_at: Time.current)Spree::Taxonomy.where(id: taxonomy_ids).update_all(updated_at: Time.current)- Spree::Taxons::TouchFeaturedSections.call(taxon_ids: taxon_ids) if defined?(Spree::Taxons::TouchFeaturedSections)endendenddiff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rbindex 83b2d4894e..2b87f47840 100644--- a/core/app/models/spree/ability.rb+++ b/core/app/models/spree/ability.rb@@ -165,9 +165,9 @@ module Spreeendcan :accept, Spree::Invitation, invitee_id: [user.id, nil], invitee_type: user.class.name, status: 'pending'can :read, ::Spree::Policy- can :read, ::Spree::Page- can :read, ::Spree::Post- can :read, ::Spree::PostCategory+ can :read, ::Spree::Page if defined?(Spree::Page)+ can :read, ::Spree::Post if defined?(Spree::Post)+ can :read, ::Spree::PostCategory if defined?(Spree::PostCategory)enddef protect_admin_rolediff --git a/core/app/models/spree/policy.rb b/core/app/models/spree/policy.rbindex 4c21dfe4d7..7b45f48f3e 100644--- a/core/app/models/spree/policy.rb+++ b/core/app/models/spree/policy.rb@@ -2,7 +2,6 @@ module Spreeclass Policy < Spree.base_classextend FriendlyIdinclude Spree::TranslatableResource- include Spree::LinkableUNIQUENESS_SCOPE = %i[owner_id owner_type].freezediff --git a/core/app/models/spree/post.rb b/core/app/models/spree/post.rbindex 3615ca91a3..315210d4b9 100644--- a/core/app/models/spree/post.rb+++ b/core/app/models/spree/post.rb@@ -1,7 +1,6 @@module Spreeclass Post < Spree.base_classinclude Spree::SingleStoreResource- include Spree::Linkableinclude Spree::Metafieldsextend FriendlyIddiff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rbindex 4497622715..d8d03fb104 100644--- a/core/app/models/spree/product.rb+++ b/core/app/models/spree/product.rb@@ -30,7 +30,6 @@ module Spreeinclude Spree::MemoizedDatainclude Spree::Metafieldsinclude Spree::Metadata- include Spree::Linkableinclude Spree::Product::Webhooksinclude Spree::Product::Slugsif defined?(Spree::VendorConcern)diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rbindex 02b62d128b..35a6f0a31d 100644--- a/core/app/models/spree/taxon.rb+++ b/core/app/models/spree/taxon.rb@@ -19,7 +19,6 @@ module Spreeinclude Spree::Metafieldsinclude Spree::Metadatainclude Spree::MemoizedData- include Spree::Linkableif defined?(Spree::Webhooks::HasWebhooks)include Spree::Webhooks::HasWebhooksenddiff --git a/core/app/services/spree/taxons/remove_products.rb b/core/app/services/spree/taxons/remove_products.rbindex 2be051cc6b..8a05c0f477 100644--- a/core/app/services/spree/taxons/remove_products.rb+++ b/core/app/services/spree/taxons/remove_products.rb@@ -47,7 +47,7 @@ module Spreetaxon_ids = taxons.pluck(:id)Spree::Taxon.where(id: taxon_ids).touch_all- Spree::Taxons::TouchFeaturedSections.call(taxon_ids: taxon_ids)+ Spree::Taxons::TouchFeaturedSections.call(taxon_ids: taxon_ids) if defined?(Spree::Taxons::TouchFeaturedSections)success(true)enddiff --git a/core/spec/jobs/spree/products/touch_taxons_job_spec.rb b/core/spec/jobs/spree/products/touch_taxons_job_spec.rbindex 16a201567f..69f01f6125 100644--- a/core/spec/jobs/spree/products/touch_taxons_job_spec.rb+++ b/core/spec/jobs/spree/products/touch_taxons_job_spec.rb@@ -9,8 +9,6 @@ describe Spree::Products::TouchTaxonsJob, type: :job dolet!(:taxon_2) { create(:taxon, taxonomy: taxonomy) }let!(:other_taxon) { create(:taxon) }- let!(:featured_section) { create(:featured_taxon_page_section, preferred_taxon_id: taxon_1.id) }-let(:taxon_ids) { [taxon_1.id, taxon_2.id] }let(:taxonomy_ids) { [taxonomy.id] }@@ -22,10 +20,6 @@ describe Spree::Products::TouchTaxonsJob, type: :job doexpect { subject }.to change { Spree::Taxonomy.where(id: taxonomy_ids).pluck(:updated_at) }end- it 'touches featured sections for the specified taxons' do- expect { subject }.to change { Spree::PageSections::FeaturedTaxon.where(id: featured_section.id).pluck(:updated_at) }- end-it 'does not touch other taxons' doexpect { subject }.not_to change { other_taxon.reload.updated_at }enddiff --git a/core/spec/lib/spree/core_environment_spec.rb b/core/spec/lib/spree/core_environment_spec.rbindex 944d6f50bd..f43e3ec84f 100644--- a/core/spec/lib/spree/core_environment_spec.rb+++ b/core/spec/lib/spree/core_environment_spec.rb@@ -170,81 +170,4 @@ RSpec.describe 'Spree environment accessors' doSpree.promotions.rules.concat(original)endend-- describe 'Spree.page_builder' do- it 'provides access to page builder configuration' do- expect(Spree.page_builder).to be_a(Spree::PageBuilderConfig)- end-- it 'memoizes the page_builder instance' do- expect(Spree.page_builder).to be(Spree.page_builder)- end-- describe 'getter methods' do- it 'provides access to themes' do- expect(Spree.page_builder.themes).to eq(Rails.application.config.spree.themes)- expect(Spree.page_builder.themes).to be_an(Array)- end-- it 'provides access to theme_layout_sections' do- expect(Spree.page_builder.theme_layout_sections).to eq(Rails.application.config.spree.theme_layout_sections)- expect(Spree.page_builder.theme_layout_sections).to be_an(Array)- end-- it 'provides access to pages' do- expect(Spree.page_builder.pages).to eq(Rails.application.config.spree.pages)- expect(Spree.page_builder.pages).to be_an(Array)- end-- it 'provides access to page_sections' do- expect(Spree.page_builder.page_sections).to eq(Rails.application.config.spree.page_sections)- expect(Spree.page_builder.page_sections).to be_an(Array)- end-- it 'provides access to page_blocks' do- expect(Spree.page_builder.page_blocks).to eq(Rails.application.config.spree.page_blocks)- expect(Spree.page_builder.page_blocks).to be_an(Array)- end- end-- describe 'setter methods' do- it 'allows setting themes' do- original = Spree.page_builder.themes.dup- Spree.page_builder.themes = ['Custom::Theme']- expect(Spree.page_builder.themes).to eq(['Custom::Theme'])- expect(Rails.application.config.spree.themes).to eq(['Custom::Theme'])- # Restore original- Spree.page_builder.themes = original- end-- it 'allows setting pages' do- original = Spree.page_builder.pages.dup- Spree.page_builder.pages = ['Custom::Page']- expect(Spree.page_builder.pages).to eq(['Custom::Page'])- expect(Rails.application.config.spree.pages).to eq(['Custom::Page'])- # Restore original- Spree.page_builder.pages = original- end-- it 'allows setting page_sections' do- original = Spree.page_builder.page_sections.dup- Spree.page_builder.page_sections = ['Custom::Section']- expect(Spree.page_builder.page_sections).to eq(['Custom::Section'])- expect(Rails.application.config.spree.page_sections).to eq(['Custom::Section'])- # Restore original- Spree.page_builder.page_sections = original- end- end-- describe 'modifying values' do- it 'allows appending to themes' do- original = Spree.page_builder.themes.dup- Spree.page_builder.themes << 'Custom::NewTheme'- expect(Spree.page_builder.themes).to include('Custom::NewTheme')- # Restore original- Spree.page_builder.themes.clear- Spree.page_builder.themes.concat(original)- end- end- endenddiff --git a/core/spec/models/spree/policy_spec.rb b/core/spec/models/spree/policy_spec.rbindex 89f70a122f..5fcbb37e28 100644--- a/core/spec/models/spree/policy_spec.rb+++ b/core/spec/models/spree/policy_spec.rb@@ -23,18 +23,6 @@ RSpec.describe Spree::Policy, type: :model doendend- describe 'Callbacks' do- context 'after destroy destroys links in which policy is linked to' do- let!(:page_link) { create(:page_link, linkable: policy, parent: store) }-- it 'destroys links' do- expect(store.links).to include(page_link)- expect { policy.destroy }.to change(Spree::PageLink, :count).by(-1)- expect(store.links).not_to include(page_link)- end- end- end-describe 'friendly_id' doit 'generates friendly URLs from slug' dopolicy = create(:policy, slug: 'my-policy')diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rbindex 6006804a3e..16fa721601 100644--- a/core/spec/models/spree/store_spec.rb+++ b/core/spec/models/spree/store_spec.rb@@ -158,7 +158,7 @@ describe Spree::Store, type: :model, without_global_store: true dolet(:store) { build(:store) }it 'creates default policies' do- expect { store.save! }.to change(Spree::Policy, :count).by(4).and change(store.links, :count).by(4)+ expect { store.save! }.to change(Spree::Policy, :count).by(4)endendend@@ -213,15 +213,6 @@ describe Spree::Store, type: :model, without_global_store: true doendend- describe '#create_default_theme' do- let(:store) { build(:store) }-- it 'creates a default theme' do- expect(store).to receive(:create_default_theme)- store.save!- end- end-describe '#import_products_from_store' dolet(:store) { build(:store, import_products_from_store_id: other_store.id) }let(:other_store) { create(:store) }diff --git a/core/spec/models/spree/taxon_spec.rb b/core/spec/models/spree/taxon_spec.rbindex 6aad4dcf33..91154171b2 100644--- a/core/spec/models/spree/taxon_spec.rb+++ b/core/spec/models/spree/taxon_spec.rb@@ -160,16 +160,6 @@ describe Spree::Taxon, type: :model doendendend-- describe 'after_destroy :remove_all_featured_sections' do- let(:taxon) { create(:taxon) }- let!(:featured_section) { create(:featured_taxon_page_section, preferred_taxon_id: taxon.id) }-- it 'removes the associated featured section' do- expect { taxon.destroy! }.to change(Spree::PageSections::FeaturedTaxon, :count).from(3).to(2)- expect(featured_section.reload).to be_deleted- end- endendcontext 'when using another locale' do@@ -799,73 +789,4 @@ describe Spree::Taxon, type: :model doendendend-- describe '#featured?' do- subject { taxon.featured? }-- let(:taxon) { create(:taxon) }- let!(:featured_section) { create(:featured_taxon_page_section, preferred_taxon_id: featured_taxon.id) }-- context 'with a featured section' do- let(:featured_taxon) { taxon }-- it { is_expected.to be(true) }- end-- context 'with no featured section' do- let(:featured_taxon) { create(:taxon) }-- it { is_expected.to be(false) }- end- end-- describe '#page_builder_image' do- subject(:page_builder_image) { taxon.page_builder_image }-- let(:taxon) { build(:taxon, image: image, square_image: square_image) }-- context 'when image and square image are not attached' do- let(:image) { nil }- let(:square_image) { nil }-- it { is_expected.to_not be_attached }- end-- context 'when only image is attached' do- let(:image) { file_fixture('icon_256x256.png') }- let(:square_image) { nil }-- it { is_expected.to be_attached }- it { is_expected.to eq(taxon.image)}- end-- context 'when both image and square image are attached' do- let(:image) { file_fixture('icon_256x256.png') }- let(:square_image) { file_fixture('icon_256x256.png') }-- it { is_expected.to be_attached}- it { is_expected.to eq(taxon.square_image)}- end- end-- describe '#featured_sections' do- subject { taxon.featured_sections }-- let(:taxon) { create(:taxon) }-- let!(:featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: featured_taxon.id) }- let!(:other_featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: create(:taxon).id) }-- context 'with featured sections' do- let(:featured_taxon) { taxon }-- it { is_expected.to contain_exactly(*featured_sections) }- end-- context 'with no featured sections' do- let(:featured_taxon) { create(:taxon) }-- it { is_expected.to be_empty }- end- endenddiff --git a/core/spec/services/spree/products/auto_match_taxons_spec.rb b/core/spec/services/spree/products/auto_match_taxons_spec.rbindex 254b0873e8..ed035ab309 100644--- a/core/spec/services/spree/products/auto_match_taxons_spec.rb+++ b/core/spec/services/spree/products/auto_match_taxons_spec.rb@@ -46,21 +46,4 @@ RSpec.describe Spree::Products::AutoMatchTaxons doexpect(taxon.products.reload).not_to include(product)endend-- context 'for a featured taxon' do- let!(:taxon) { create(:automatic_taxon, taxonomy: store.taxonomies.first) }- let!(:featured_taxon) { Spree::PageSections::FeaturedTaxon.create!(pageable: Spree::Page.find_by(name: 'Homepage')) }-- before do- create(:tag_taxon_rule, taxon: taxon, value: 'cruelty-free')- product.tag_list.add('cruelty-free')- product.save-- featured_taxon.update!(preferred_taxon_id: taxon.id)- end-- it 'refreshes the featured taxon' do- expect { subject }.to change { featured_taxon.reload.updated_at }- end- endenddiff --git a/core/spec/services/spree/taxons/add_products_spec.rb b/core/spec/services/spree/taxons/add_products_spec.rbindex ab23d85df8..bf9b267953 100644--- a/core/spec/services/spree/taxons/add_products_spec.rb+++ b/core/spec/services/spree/taxons/add_products_spec.rb@@ -5,7 +5,6 @@ module Spreelet(:service) { described_class }let(:taxons) { create_list(:taxon, 2) }let(:products) { create_list(:product, 3) }- let!(:featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: taxons.first.id) }describe '#call' dosubject { service.call(taxons: taxons, products: products) }@@ -29,10 +28,6 @@ module Spreeexpect { subject }.to change { Spree::Taxon.where(id: taxons.pluck(:id)).pluck(:updated_at) }end- it 'touches all featured sections' do- expect { subject }.to change { Spree::PageSections::FeaturedTaxon.where(id: featured_sections.pluck(:id)).pluck(:updated_at) }- end-it 'returns a successful result' doexpect(subject.success?).to be trueexpect(subject.value).to eq truediff --git a/core/spec/services/spree/taxons/remove_products_spec.rb b/core/spec/services/spree/taxons/remove_products_spec.rbindex 1a049205ac..a51f393a74 100644--- a/core/spec/services/spree/taxons/remove_products_spec.rb+++ b/core/spec/services/spree/taxons/remove_products_spec.rb@@ -5,7 +5,6 @@ module Spreelet(:service) { described_class }let(:taxons) { create_list(:taxon, 2) }let(:products) { create_list(:product, 3) }- let!(:featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: taxons.first.id) }describe '#call' dosubject { service.call(taxons: taxons, products: products) }@@ -37,10 +36,6 @@ module Spreeexpect { subject }.to change { Spree::Taxon.where(id: taxons.pluck(:id)).pluck(:updated_at) }end- it 'touches all featured sections' do- expect { subject }.to change { Spree::PageSections::FeaturedTaxon.where(id: featured_sections.pluck(:id)).pluck(:updated_at) }- end-it 'returns a successful result' doexpect(subject.success?).to be trueexpect(subject.value).to eq truediff --git a/page_builder/Rakefile b/page_builder/Rakefileindex c4bf010ef5..66e5bfa328 100644--- a/page_builder/Rakefile+++ b/page_builder/Rakefile@@ -13,8 +13,6 @@ task :test_app doENV['LIB_NAME'] = 'spree/page_builder'Rake::Task['common:test_app'].execute(- user_class: 'User',- authentication: 'devise',install_storefront: 'false',install_admin: 'true')diff --git a/page_builder/app/jobs/spree/page_builder/products/touch_taxons_job_decorator.rb b/page_builder/app/jobs/spree/page_builder/products/touch_taxons_job_decorator.rbnew file mode 100644index 0000000000..3d5a32c89b--- /dev/null+++ b/page_builder/app/jobs/spree/page_builder/products/touch_taxons_job_decorator.rb@@ -0,0 +1,15 @@+module Spree+ module PageBuilder+ module Products+ module TouchTaxonsJobDecorator+ def perform(taxon_ids, taxonomy_ids)+ super(taxon_ids, taxonomy_ids)++ Spree::Taxons::TouchFeaturedSections.call(taxon_ids: taxon_ids)+ end+ end+ end+ end+end++Spree::Products::TouchTaxonsJob.prepend(Spree::PageBuilder::Products::TouchTaxonsJobDecorator)diff --git a/page_builder/app/models/spree/page_builder/policy_decorator.rb b/page_builder/app/models/spree/page_builder/policy_decorator.rbindex d46dd375df..0f89cf62e5 100644--- a/page_builder/app/models/spree/page_builder/policy_decorator.rb+++ b/page_builder/app/models/spree/page_builder/policy_decorator.rb@@ -1,6 +1,10 @@module Spreemodule PageBuildermodule PolicyDecorator+ def self.prepended(base)+ base.include Spree::Linkable+ end+def page_builder_urlreturn unless Spree::Core::Engine.routes.url_helpers.respond_to?(:policy_path)diff --git a/page_builder/app/models/spree/page_builder/post_decorator.rb b/page_builder/app/models/spree/page_builder/post_decorator.rbindex bdd1e2e46e..1a3eb860e7 100644--- a/page_builder/app/models/spree/page_builder/post_decorator.rb+++ b/page_builder/app/models/spree/page_builder/post_decorator.rb@@ -1,6 +1,10 @@module Spreemodule PageBuildermodule PostDecorator+ def self.prepended(base)+ base.include Spree::Linkable+ end+def page_builder_urlreturn unless Spree::Core::Engine.routes.url_helpers.respond_to?(:post_path)diff --git a/page_builder/app/models/spree/page_builder/product_decorator.rb b/page_builder/app/models/spree/page_builder/product_decorator.rbindex a445bbc5e3..15a564acc8 100644--- a/page_builder/app/models/spree/page_builder/product_decorator.rb+++ b/page_builder/app/models/spree/page_builder/product_decorator.rb@@ -1,6 +1,10 @@module Spreemodule PageBuildermodule ProductDecorator+ def self.prepended(base)+ base.include Spree::Linkable+ end+def page_builder_urlreturn unless Spree::Core::Engine.routes.url_helpers.respond_to?(:product_path)diff --git a/page_builder/app/models/spree/page_builder/taxon_decorator.rb b/page_builder/app/models/spree/page_builder/taxon_decorator.rbindex 4a2eabf985..55fd171e3e 100644--- a/page_builder/app/models/spree/page_builder/taxon_decorator.rb+++ b/page_builder/app/models/spree/page_builder/taxon_decorator.rb@@ -2,6 +2,8 @@ module Spreemodule PageBuildermodule TaxonDecoratordef self.prepended(base)+ base.include Spree::Linkable+base.class_eval doafter_commit :touch_featured_sections, on: [:update]after_touch :touch_featured_sectionsdiff --git a/page_builder/lib/spree/page_builder/testing_support/factories.rb b/page_builder/lib/spree/page_builder/testing_support/factories.rbnew file mode 100644index 0000000000..a36a5d0b8f--- /dev/null+++ b/page_builder/lib/spree/page_builder/testing_support/factories.rb@@ -0,0 +1,3 @@+Dir["#{File.dirname(__FILE__)}/factories/**"].each do |f|+ load File.expand_path(f)+enddiff --git a/page_builder/lib/spree/testing_support/factories/page_block_factory.rb b/page_builder/lib/spree/page_builder/testing_support/factories/page_block_factory.rbsimilarity index 100%rename from page_builder/lib/spree/testing_support/factories/page_block_factory.rbrename to page_builder/lib/spree/page_builder/testing_support/factories/page_block_factory.rbdiff --git a/page_builder/lib/spree/testing_support/factories/page_factory.rb b/page_builder/lib/spree/page_builder/testing_support/factories/page_factory.rbsimilarity index 100%rename from page_builder/lib/spree/testing_support/factories/page_factory.rbrename to page_builder/lib/spree/page_builder/testing_support/factories/page_factory.rbdiff --git a/page_builder/lib/spree/testing_support/factories/page_link_factory.rb b/page_builder/lib/spree/page_builder/testing_support/factories/page_link_factory.rbsimilarity index 100%rename from page_builder/lib/spree/testing_support/factories/page_link_factory.rbrename to page_builder/lib/spree/page_builder/testing_support/factories/page_link_factory.rbdiff --git a/page_builder/lib/spree/testing_support/factories/page_section_factory.rb b/page_builder/lib/spree/page_builder/testing_support/factories/page_section_factory.rbsimilarity index 100%rename from page_builder/lib/spree/testing_support/factories/page_section_factory.rbrename to page_builder/lib/spree/page_builder/testing_support/factories/page_section_factory.rbdiff --git a/page_builder/lib/spree/testing_support/factories/theme_factory.rb b/page_builder/lib/spree/page_builder/testing_support/factories/theme_factory.rbsimilarity index 100%rename from page_builder/lib/spree/testing_support/factories/theme_factory.rbrename to page_builder/lib/spree/page_builder/testing_support/factories/theme_factory.rbdiff --git a/page_builder/spec/fixtures/files/icon_256x256.gif b/page_builder/spec/fixtures/files/icon_256x256.gifnew file mode 100644index 0000000000..02130fcbfdBinary files /dev/null and b/page_builder/spec/fixtures/files/icon_256x256.gif differdiff --git a/page_builder/spec/fixtures/files/icon_256x256.png b/page_builder/spec/fixtures/files/icon_256x256.pngnew file mode 100644index 0000000000..2edee4a6a3Binary files /dev/null and b/page_builder/spec/fixtures/files/icon_256x256.png differdiff --git a/page_builder/spec/fixtures/files/icon_512x512.png b/page_builder/spec/fixtures/files/icon_512x512.pngnew file mode 100644index 0000000000..2d2f28266bBinary files /dev/null and b/page_builder/spec/fixtures/files/icon_512x512.png differdiff --git a/page_builder/spec/fixtures/files/img_256x128.png b/page_builder/spec/fixtures/files/img_256x128.pngnew file mode 100644index 0000000000..f0c4b9e137Binary files /dev/null and b/page_builder/spec/fixtures/files/img_256x128.png differdiff --git a/page_builder/spec/fixtures/files/logo.png b/page_builder/spec/fixtures/files/logo.pngnew file mode 100644index 0000000000..8d0d83f754Binary files /dev/null and b/page_builder/spec/fixtures/files/logo.png differdiff --git a/page_builder/spec/fixtures/thinking-cat.jpg b/page_builder/spec/fixtures/thinking-cat.jpgnew file mode 100644index 0000000000..7e8524d367Binary files /dev/null and b/page_builder/spec/fixtures/thinking-cat.jpg differdiff --git a/page_builder/spec/jobs/spree/page_builder/products/touch_taxons_job_decorator_spec.rb b/page_builder/spec/jobs/spree/page_builder/products/touch_taxons_job_decorator_spec.rbnew file mode 100644index 0000000000..4ad7f00acb--- /dev/null+++ b/page_builder/spec/jobs/spree/page_builder/products/touch_taxons_job_decorator_spec.rb@@ -0,0 +1,21 @@+require 'spec_helper'++describe Spree::Products::TouchTaxonsJob, type: :job do+ describe '#perform' do+ subject { described_class.perform_now(taxon_ids, taxonomy_ids) }++ let!(:taxonomy) { create(:taxonomy) }+ let!(:taxon_1) { create(:taxon, taxonomy: taxonomy) }+ let!(:taxon_2) { create(:taxon, taxonomy: taxonomy) }+ let!(:other_taxon) { create(:taxon) }++ let!(:featured_section) { create(:featured_taxon_page_section, preferred_taxon_id: taxon_1.id) }++ let(:taxon_ids) { [taxon_1.id, taxon_2.id] }+ let(:taxonomy_ids) { [taxonomy.id] }++ it 'touches featured sections for the specified taxons' do+ expect { subject }.to change { Spree::PageSections::FeaturedTaxon.where(id: featured_section.id).pluck(:updated_at) }+ end+ end+enddiff --git a/page_builder/spec/lib/spree/core_environment_spec.rb b/page_builder/spec/lib/spree/core_environment_spec.rbnew file mode 100644index 0000000000..a0f858df6b--- /dev/null+++ b/page_builder/spec/lib/spree/core_environment_spec.rb@@ -0,0 +1,80 @@+require 'spec_helper'++RSpec.describe 'Spree environment accessors' do+ describe 'Spree.page_builder' do+ it 'provides access to page builder configuration' do+ expect(Spree.page_builder).to be_a(Spree::PageBuilderConfig)+ end++ it 'memoizes the page_builder instance' do+ expect(Spree.page_builder).to be(Spree.page_builder)+ end++ describe 'getter methods' do+ it 'provides access to themes' do+ expect(Spree.page_builder.themes).to eq(Rails.application.config.spree.themes)+ expect(Spree.page_builder.themes).to be_an(Array)+ end++ it 'provides access to theme_layout_sections' do+ expect(Spree.page_builder.theme_layout_sections).to eq(Rails.application.config.spree.theme_layout_sections)+ expect(Spree.page_builder.theme_layout_sections).to be_an(Array)+ end++ it 'provides access to pages' do+ expect(Spree.page_builder.pages).to eq(Rails.application.config.spree.pages)+ expect(Spree.page_builder.pages).to be_an(Array)+ end++ it 'provides access to page_sections' do+ expect(Spree.page_builder.page_sections).to eq(Rails.application.config.spree.page_sections)+ expect(Spree.page_builder.page_sections).to be_an(Array)+ end++ it 'provides access to page_blocks' do+ expect(Spree.page_builder.page_blocks).to eq(Rails.application.config.spree.page_blocks)+ expect(Spree.page_builder.page_blocks).to be_an(Array)+ end+ end++ describe 'setter methods' do+ it 'allows setting themes' do+ original = Spree.page_builder.themes.dup+ Spree.page_builder.themes = ['Custom::Theme']+ expect(Spree.page_builder.themes).to eq(['Custom::Theme'])+ expect(Rails.application.config.spree.themes).to eq(['Custom::Theme'])+ # Restore original+ Spree.page_builder.themes = original+ end++ it 'allows setting pages' do+ original = Spree.page_builder.pages.dup+ Spree.page_builder.pages = ['Custom::Page']+ expect(Spree.page_builder.pages).to eq(['Custom::Page'])+ expect(Rails.application.config.spree.pages).to eq(['Custom::Page'])+ # Restore original+ Spree.page_builder.pages = original+ end++ it 'allows setting page_sections' do+ original = Spree.page_builder.page_sections.dup+ Spree.page_builder.page_sections = ['Custom::Section']+ expect(Spree.page_builder.page_sections).to eq(['Custom::Section'])+ expect(Rails.application.config.spree.page_sections).to eq(['Custom::Section'])+ # Restore original+ Spree.page_builder.page_sections = original+ end+ end++ describe 'modifying values' do+ it 'allows appending to themes' do+ original = Spree.page_builder.themes.dup+ Spree.page_builder.themes << 'Custom::NewTheme'+ expect(Spree.page_builder.themes).to include('Custom::NewTheme')+ # Restore original+ Spree.page_builder.themes.clear+ Spree.page_builder.themes.concat(original)+ end+ end+ end+enddiff --git a/page_builder/spec/models/spree/page_builder/policy_decorator_spec.rb b/page_builder/spec/models/spree/page_builder/policy_decorator_spec.rbnew file mode 100644index 0000000000..fddb554402--- /dev/null+++ b/page_builder/spec/models/spree/page_builder/policy_decorator_spec.rb@@ -0,0 +1,18 @@+require 'spec_helper'++RSpec.describe Spree::Policy, type: :model do+ let(:store) { Spree::Store.default }+ let(:policy) { create(:policy, owner: store) }++ describe 'Callbacks' do+ context 'after destroy destroys links in which policy is linked to' do+ let!(:page_link) { create(:page_link, linkable: policy, parent: store) }++ it 'destroys links' do+ expect(store.links).to include(page_link)+ expect { policy.destroy }.to change(Spree::PageLink, :count).by(-1)+ expect(store.links).not_to include(page_link)+ end+ end+ end+enddiff --git a/page_builder/spec/models/spree/page_builder/store_decorator_spec.rb b/page_builder/spec/models/spree/page_builder/store_decorator_spec.rbnew file mode 100644index 0000000000..d32566acfd--- /dev/null+++ b/page_builder/spec/models/spree/page_builder/store_decorator_spec.rb@@ -0,0 +1,29 @@+require 'spec_helper'++RSpec.describe Spree::Store, type: :model do+ describe 'Callbacks' do+ describe '#create_default_theme' do+ let(:store) { build(:store) }++ it 'creates a default theme' do\+ expect(store.default_theme).to be_nil+ expect(store.themes.count).to eq(0)+ store.save!+ expect(store.themes.count).to eq(1)+ expect(store.reload.default_theme).to be_present+ expect(store.default_theme.name).to eq(Spree.t(:default_theme_name))+ end+ end++ describe '#create_default_policies' do+ let(:store) { build(:store) }++ it 'creates links for default policies' do+ expect(store.links.count).to eq(0)+ store.save!+ expect(store.links.count).to eq(4)+ expect(store.links.map(&:linkable)).to match_array(store.policies)+ end+ end+ end+enddiff --git a/page_builder/spec/models/spree/page_builder/taxon_decorator_spec.rb b/page_builder/spec/models/spree/page_builder/taxon_decorator_spec.rbnew file mode 100644index 0000000000..8808cad13f--- /dev/null+++ b/page_builder/spec/models/spree/page_builder/taxon_decorator_spec.rb@@ -0,0 +1,84 @@+require 'spec_helper'++RSpec.describe Spree::Taxon, type: :model do+ describe 'Callbacks' do+ describe 'after_destroy :remove_all_featured_sections' do+ let(:taxon) { create(:taxon) }+ let!(:featured_section) { create(:featured_taxon_page_section, preferred_taxon_id: taxon.id) }++ it 'removes the associated featured section' do+ expect { taxon.destroy! }.to change(Spree::PageSections::FeaturedTaxon, :count).from(3).to(2)+ expect(featured_section.reload).to be_deleted+ end+ end+ end++ describe '#featured?' do+ subject { taxon.featured? }++ let(:taxon) { create(:taxon) }+ let!(:featured_section) { create(:featured_taxon_page_section, preferred_taxon_id: featured_taxon.id) }++ context 'with a featured section' do+ let(:featured_taxon) { taxon }++ it { is_expected.to be(true) }+ end++ context 'with no featured section' do+ let(:featured_taxon) { create(:taxon) }++ it { is_expected.to be(false) }+ end+ end++ describe '#page_builder_image' do+ subject(:page_builder_image) { taxon.page_builder_image }++ let(:taxon) { build(:taxon, image: image, square_image: square_image) }++ context 'when image and square image are not attached' do+ let(:image) { nil }+ let(:square_image) { nil }++ it { is_expected.to_not be_attached }+ end++ context 'when only image is attached' do+ let(:image) { file_fixture('icon_256x256.png') }+ let(:square_image) { nil }++ it { is_expected.to be_attached }+ it { is_expected.to eq(taxon.image)}+ end++ context 'when both image and square image are attached' do+ let(:image) { file_fixture('icon_256x256.png') }+ let(:square_image) { file_fixture('icon_256x256.png') }++ it { is_expected.to be_attached}+ it { is_expected.to eq(taxon.square_image)}+ end+ end++ describe '#featured_sections' do+ subject { taxon.featured_sections }++ let(:taxon) { create(:taxon) }++ let!(:featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: featured_taxon.id) }+ let!(:other_featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: create(:taxon).id) }++ context 'with featured sections' do+ let(:featured_taxon) { taxon }++ it { is_expected.to contain_exactly(*featured_sections) }+ end++ context 'with no featured sections' do+ let(:featured_taxon) { create(:taxon) }++ it { is_expected.to be_empty }+ end+ end+enddiff --git a/page_builder/spec/services/spree/products/auto_match_taxons_spec.rb b/page_builder/spec/services/spree/products/auto_match_taxons_spec.rbnew file mode 100644index 0000000000..b184930c49--- /dev/null+++ b/page_builder/spec/services/spree/products/auto_match_taxons_spec.rb@@ -0,0 +1,25 @@+require 'spec_helper'++RSpec.describe Spree::Products::AutoMatchTaxons do+ subject { described_class.call(product: product) }++ let(:store) { @default_store }+ let(:product) { create(:product, stores: [store]) }++ context 'for a featured taxon' do+ let!(:taxon) { create(:automatic_taxon, taxonomy: store.taxonomies.first) }+ let!(:featured_taxon) { Spree::PageSections::FeaturedTaxon.create!(pageable: Spree::Page.find_by(name: 'Homepage')) }++ before do+ create(:tag_taxon_rule, taxon: taxon, value: 'cruelty-free')+ product.tag_list.add('cruelty-free')+ product.save++ featured_taxon.update!(preferred_taxon_id: taxon.id)+ end++ it 'refreshes the featured taxon' do+ expect { subject }.to change { featured_taxon.reload.updated_at }+ end+ end+enddiff --git a/page_builder/spec/services/spree/taxons/add_products_spec.rb b/page_builder/spec/services/spree/taxons/add_products_spec.rbnew file mode 100644index 0000000000..78b64eda4c--- /dev/null+++ b/page_builder/spec/services/spree/taxons/add_products_spec.rb@@ -0,0 +1,18 @@+require 'spec_helper'++module Spree+ describe Taxons::AddProducts do+ let(:service) { described_class }+ let(:taxons) { create_list(:taxon, 2) }+ let(:products) { create_list(:product, 3) }+ let!(:featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: taxons.first.id) }++ describe '#call' do+ subject { service.call(taxons: taxons, products: products) }++ it 'touches all featured sections' do+ expect { subject }.to change { Spree::PageSections::FeaturedTaxon.where(id: featured_sections.pluck(:id)).pluck(:updated_at) }+ end+ end+ end+enddiff --git a/page_builder/spec/services/spree/taxons/remove_products_spec.rb b/page_builder/spec/services/spree/taxons/remove_products_spec.rbnew file mode 100644index 0000000000..da3fdd5560--- /dev/null+++ b/page_builder/spec/services/spree/taxons/remove_products_spec.rb@@ -0,0 +1,23 @@+require 'spec_helper'++module Spree+ describe Taxons::RemoveProducts do+ let(:service) { described_class }+ let(:taxons) { create_list(:taxon, 2) }+ let(:products) { create_list(:product, 3) }+ let!(:featured_sections) { create_list(:featured_taxon_page_section, 2, preferred_taxon_id: taxons.first.id) }++ describe '#call' do+ subject { service.call(taxons: taxons, products: products) }++ before do+ # Add products to taxons initially+ Spree::Taxons::AddProducts.call(taxons: taxons, products: products)+ end++ it 'touches all featured sections' do+ expect { subject }.to change { Spree::PageSections::FeaturedTaxon.where(id: featured_sections.pluck(:id)).pluck(:updated_at) }+ end+ end+ end+enddiff --git a/page_builder/spec/spec_helper.rb b/page_builder/spec/spec_helper.rbindex 8e649c310f..11382a027a 100644--- a/page_builder/spec/spec_helper.rb+++ b/page_builder/spec/spec_helper.rb@@ -37,7 +37,16 @@ require 'spree/testing_support/store'require 'spree/testing_support/controller_requests'require 'spree/testing_support/url_helpers'+require 'spree/page_builder/testing_support/factories'+RSpec.configure do |config|+ config.color = true+ config.default_formatter = 'doc'+ config.fail_fast = ENV['FAIL_FAST'] || false+ config.infer_spec_type_from_file_location!+ config.mock_with :rspec+ config.raise_errors_for_deprecations!+config.include FactoryBot::Syntax::Methodsconfig.use_transactional_fixtures = false@@ -54,15 +63,7 @@ RSpec.configure do |config|endconfig.include Spree::TestingSupport::Preferences- config.include Spree::TestingSupport::Storeconfig.include Spree::TestingSupport::UrlHelpersconfig.include Spree::TestingSupport::ControllerRequests, type: :controllerconfig.include Spree::TestingSupport::AuthorizationHelpers::Controller, type: :controller-- config.fail_fast = ENV['FAIL_FAST'] || false- config.order = :random- config.filter_run focus: true- config.run_all_when_everything_filtered = true-- config.example_status_persistence_file_path = './spec/examples.txt'enddiff --git a/storefront/Rakefile b/storefront/Rakefileindex b546e3604d..221cb495b1 100644--- a/storefront/Rakefile+++ b/storefront/Rakefile@@ -13,9 +13,10 @@ task :test_app doENV['LIB_NAME'] = 'spree/storefront'Rake::Task['common:test_app'].execute(- user_class: 'User',+ user_class: 'Spree::User',+ admin_user_class: 'Spree::AdminUser',authentication: 'devise',install_storefront: 'true',- install_admin: 'false'+ install_admin: 'true')enddiff --git a/storefront/spec/spec_helper.rb b/storefront/spec/spec_helper.rbindex f94787d47e..6c10c31d78 100644--- a/storefront/spec/spec_helper.rb+++ b/storefront/spec/spec_helper.rb@@ -49,6 +49,8 @@ require 'spree/testing_support/capybara_config'require 'spree/testing_support/rspec_retry_config'require 'spree/testing_support/image_helpers'+require 'spree/page_builder/testing_support/factories'+require 'spree/core/controller_helpers/strong_parameters'RSpec.configure do |config|