From 9175504bc189f3b7f621dd3f6b4fa6d141d48462 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 6 Aug 2020 11:00:49 +0100 Subject: [PATCH 1/8] Bring taxon, taxonomy and classification from spree_core --- app/models/spree/classification.rb | 7 +++ app/models/spree/taxon.rb | 73 ++++++++++++++++++++++++++++++ app/models/spree/taxonomy.rb | 22 +++++++++ spec/models/spree/taxon_spec.rb | 49 ++++++++++++++++++++ spec/models/spree/taxonomy_spec.rb | 18 ++++++++ 5 files changed, 169 insertions(+) create mode 100644 app/models/spree/classification.rb create mode 100644 app/models/spree/taxon.rb create mode 100644 app/models/spree/taxonomy.rb create mode 100644 spec/models/spree/taxonomy_spec.rb diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb new file mode 100644 index 0000000000..7f7b1579ec --- /dev/null +++ b/app/models/spree/classification.rb @@ -0,0 +1,7 @@ +module Spree + class Classification < ActiveRecord::Base + self.table_name = 'spree_products_taxons' + belongs_to :product, class_name: "Spree::Product" + belongs_to :taxon, class_name: "Spree::Taxon" + end +end diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb new file mode 100644 index 0000000000..2d9cbb4a4d --- /dev/null +++ b/app/models/spree/taxon.rb @@ -0,0 +1,73 @@ +module Spree + class Taxon < ActiveRecord::Base + acts_as_nested_set dependent: :destroy + + belongs_to :taxonomy, class_name: 'Spree::Taxonomy', :touch => true + has_many :classifications, dependent: :delete_all + has_many :products, through: :classifications + + before_create :set_permalink + + validates :name, presence: true + + has_attached_file :icon, + styles: { mini: '32x32>', normal: '128x128>' }, + default_style: :mini, + url: '/spree/taxons/:id/:style/:basename.:extension', + path: ':rails_root/public/spree/taxons/:id/:style/:basename.:extension', + default_url: '/assets/default_taxon.png' + + include Spree::Core::S3Support + supports_s3 :icon + + include Spree::Core::ProductFilters # for detailed defs of filters + + # indicate which filters should be used for a taxon + # this method should be customized to your own site + def applicable_filters + fs = [] + # fs << ProductFilters.taxons_below(self) + ## unless it's a root taxon? left open for demo purposes + + fs << Spree::Core::ProductFilters.price_filter if Spree::Core::ProductFilters.respond_to?(:price_filter) + fs << Spree::Core::ProductFilters.brand_filter if Spree::Core::ProductFilters.respond_to?(:brand_filter) + fs + end + + # Return meta_title if set otherwise generates from root name and/or taxon name + def seo_title + if meta_title + meta_title + else + root? ? name : "#{root.name} - #{name}" + end + end + + # Creates permalink based on Stringex's .to_url method + def set_permalink + if parent.present? + self.permalink = [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last)].join('/') + else + self.permalink = name.to_url if permalink.blank? + end + end + + # For #2759 + def to_param + permalink + end + + def active_products + scope = products.active + scope + end + + def pretty_name + ancestor_chain = self.ancestors.inject("") do |name, ancestor| + name += "#{ancestor.name} -> " + end + ancestor_chain + "#{name}" + end + + end +end diff --git a/app/models/spree/taxonomy.rb b/app/models/spree/taxonomy.rb new file mode 100644 index 0000000000..c5b4a5e965 --- /dev/null +++ b/app/models/spree/taxonomy.rb @@ -0,0 +1,22 @@ +module Spree + class Taxonomy < ActiveRecord::Base + validates :name, presence: true + + has_many :taxons + has_one :root, -> { where parent_id: nil }, class_name: "Spree::Taxon", dependent: :destroy + + after_save :set_name + + default_scope -> { order("#{self.table_name}.position") } + + private + def set_name + if root + root.update_column(:name, name) + else + self.root = Taxon.create!(taxonomy_id: id, name: name) + end + end + + end +end diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb index 54a0069da9..9055b94aea 100644 --- a/spec/models/spree/taxon_spec.rb +++ b/spec/models/spree/taxon_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' module Spree describe Taxon do + let(:taxon) { Spree::Taxon.new(:name => "Ruby on Rails") } + let(:e) { create(:supplier_enterprise) } let!(:t1) { create(:taxon) } let!(:t2) { create(:taxon) } @@ -46,5 +48,52 @@ module Spree end.to change { taxon2.reload.updated_at } end end + + context "set_permalink" do + it "should set permalink correctly when no parent present" do + taxon.set_permalink + taxon.permalink.should == "ruby-on-rails" + end + + it "should support Chinese characters" do + taxon.name = "你好" + taxon.set_permalink + taxon.permalink.should == 'ni-hao' + end + + context "with parent taxon" do + before do + taxon.stub :parent_id => 123 + taxon.stub :parent => mock_model(Spree::Taxon, :permalink => "brands") + end + + it "should set permalink correctly when taxon has parent" do + taxon.set_permalink + taxon.permalink.should == "brands/ruby-on-rails" + end + + it "should set permalink correctly with existing permalink present" do + taxon.permalink = "b/rubyonrails" + taxon.set_permalink + taxon.permalink.should == "brands/rubyonrails" + end + + it "should support Chinese characters" do + taxon.name = "我" + taxon.set_permalink + taxon.permalink.should == "brands/wo" + end + end + end + + # Regression test for Spree #2620 + context "creating a child node using first_or_create" do + let(:taxonomy) { create(:taxonomy) } + + it "does not error out" do + pending "breaks in Rails 4 with postgres, see https://github.com/rails/rails/issues/10995" + expect { taxonomy.root.children.where(:name => "Some name").first_or_create }.not_to raise_error + end + end end end diff --git a/spec/models/spree/taxonomy_spec.rb b/spec/models/spree/taxonomy_spec.rb new file mode 100644 index 0000000000..f825f49764 --- /dev/null +++ b/spec/models/spree/taxonomy_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Spree::Taxonomy do + context "#destroy" do + before do + @taxonomy = create(:taxonomy) + @root_taxon = @taxonomy.root + @child_taxon = create(:taxon, :taxonomy_id => @taxonomy.id, :parent => @root_taxon) + end + + it "should destroy all associated taxons" do + @taxonomy.destroy + expect{ Spree::Taxon.find(@root_taxon.id) }.to raise_error(ActiveRecord::RecordNotFound) + expect{ Spree::Taxon.find(@child_taxon.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + end +end + From 49060892e835e9dc2f16cae4361ba0ada7743601 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 6 Aug 2020 11:03:51 +0100 Subject: [PATCH 2/8] Merge decorators into original files from spree_core --- app/models/spree/classification.rb | 15 +++++- app/models/spree/classification_decorator.rb | 15 ------ app/models/spree/taxon.rb | 49 ++++++++++++++++---- app/models/spree/taxon_decorator.rb | 47 ------------------- 4 files changed, 52 insertions(+), 74 deletions(-) delete mode 100644 app/models/spree/classification_decorator.rb delete mode 100644 app/models/spree/taxon_decorator.rb diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb index 7f7b1579ec..3cad99c8e1 100644 --- a/app/models/spree/classification.rb +++ b/app/models/spree/classification.rb @@ -1,7 +1,18 @@ module Spree class Classification < ActiveRecord::Base self.table_name = 'spree_products_taxons' - belongs_to :product, class_name: "Spree::Product" - belongs_to :taxon, class_name: "Spree::Taxon" + belongs_to :product, class_name: "Spree::Product", touch: true + belongs_to :taxon, class_name: "Spree::Taxon", touch: true + + before_destroy :dont_destroy_if_primary_taxon + + private + + def dont_destroy_if_primary_taxon + if product.primary_taxon == taxon + errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name) + false + end + end end end diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb deleted file mode 100644 index 20608bad94..0000000000 --- a/app/models/spree/classification_decorator.rb +++ /dev/null @@ -1,15 +0,0 @@ -Spree::Classification.class_eval do - belongs_to :product, class_name: "Spree::Product", touch: true - belongs_to :taxon, class_name: "Spree::Taxon", touch: true - - before_destroy :dont_destroy_if_primary_taxon - - private - - def dont_destroy_if_primary_taxon - if product.primary_taxon == taxon - errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name) - false - end - end -end diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index 2d9cbb4a4d..b1adbd61d4 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -3,7 +3,7 @@ module Spree acts_as_nested_set dependent: :destroy belongs_to :taxonomy, class_name: 'Spree::Taxonomy', :touch => true - has_many :classifications, dependent: :delete_all + has_many :classifications, dependent: :destroy has_many :products, through: :classifications before_create :set_permalink @@ -22,16 +22,9 @@ module Spree include Spree::Core::ProductFilters # for detailed defs of filters - # indicate which filters should be used for a taxon - # this method should be customized to your own site + # Indicate which filters should be used for this taxon def applicable_filters - fs = [] - # fs << ProductFilters.taxons_below(self) - ## unless it's a root taxon? left open for demo purposes - - fs << Spree::Core::ProductFilters.price_filter if Spree::Core::ProductFilters.respond_to?(:price_filter) - fs << Spree::Core::ProductFilters.brand_filter if Spree::Core::ProductFilters.respond_to?(:brand_filter) - fs + [] end # Return meta_title if set otherwise generates from root name and/or taxon name @@ -69,5 +62,41 @@ module Spree ancestor_chain + "#{name}" end + # Find all the taxons of supplied products for each enterprise, indexed by enterprise. + # Format: {enterprise_id => [taxon_id, ...]} + def self.supplied_taxons + taxons = {} + + Spree::Taxon. + joins(products: :supplier). + select('spree_taxons.*, enterprises.id AS enterprise_id'). + each do |t| + taxons[t.enterprise_id.to_i] ||= Set.new + taxons[t.enterprise_id.to_i] << t.id + end + + taxons + end + + # Find all the taxons of distributed products for each enterprise, indexed by enterprise. + # May return :all taxons (distributed in open and closed order cycles), + # or :current taxons (distributed in an open order cycle). + # + # Format: {enterprise_id => [taxon_id, ...]} + def self.distributed_taxons(which_taxons = :all) + ents_and_vars = ExchangeVariant.joins(exchange: :order_cycle).merge(Exchange.outgoing) + .select("DISTINCT variant_id, receiver_id AS enterprise_id") + + ents_and_vars = ents_and_vars.merge(OrderCycle.active) if which_taxons == :current + + taxons = Spree::Taxon + .select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id").joins(products: :variants_including_master) + .joins("INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars ON spree_variants.id = ents_and_vars.variant_id") + + taxons.each_with_object({}) do |t, ts| + ts[t.enterprise_id.to_i] ||= Set.new + ts[t.enterprise_id.to_i] << t.id + end + end end end diff --git a/app/models/spree/taxon_decorator.rb b/app/models/spree/taxon_decorator.rb deleted file mode 100644 index f2c6f1e20a..0000000000 --- a/app/models/spree/taxon_decorator.rb +++ /dev/null @@ -1,47 +0,0 @@ -Spree::Taxon.class_eval do - has_many :classifications, dependent: :destroy - - # Indicate which filters should be used for this taxon - def applicable_filters - fs = [] - # fs << Spree::ProductFilters.distributor_filter if Spree::ProductFilters.respond_to? :distributor_filter - fs - end - - # Find all the taxons of supplied products for each enterprise, indexed by enterprise. - # Format: {enterprise_id => [taxon_id, ...]} - def self.supplied_taxons - taxons = {} - - Spree::Taxon. - joins(products: :supplier). - select('spree_taxons.*, enterprises.id AS enterprise_id'). - each do |t| - taxons[t.enterprise_id.to_i] ||= Set.new - taxons[t.enterprise_id.to_i] << t.id - end - - taxons - end - - # Find all the taxons of distributed products for each enterprise, indexed by enterprise. - # May return :all taxons (distributed in open and closed order cycles), - # or :current taxons (distributed in an open order cycle). - # - # Format: {enterprise_id => [taxon_id, ...]} - def self.distributed_taxons(which_taxons = :all) - ents_and_vars = ExchangeVariant.joins(exchange: :order_cycle).merge(Exchange.outgoing) - .select("DISTINCT variant_id, receiver_id AS enterprise_id") - - ents_and_vars = ents_and_vars.merge(OrderCycle.active) if which_taxons == :current - - taxons = Spree::Taxon - .select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id").joins(products: :variants_including_master) - .joins("INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars ON spree_variants.id = ents_and_vars.variant_id") - - taxons.each_with_object({}) do |t, ts| - ts[t.enterprise_id.to_i] ||= Set.new - ts[t.enterprise_id.to_i] << t.id - end - end -end From a1b64fe27b135ff91119fc877b08a51fd88fec2b Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 6 Aug 2020 11:06:03 +0100 Subject: [PATCH 3/8] Rubocop auto-correct --- app/models/spree/classification.rb | 2 ++ app/models/spree/taxon.rb | 20 +++++++++++--------- app/models/spree/taxonomy.rb | 18 ++++++++++-------- spec/models/spree/taxon_spec.rb | 10 ++++++---- spec/models/spree/taxonomy_spec.rb | 9 +++++---- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb index 3cad99c8e1..1a2b15ca6d 100644 --- a/app/models/spree/classification.rb +++ b/app/models/spree/classification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class Classification < ActiveRecord::Base self.table_name = 'spree_products_taxons' diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index b1adbd61d4..7fb566f39e 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module Spree class Taxon < ActiveRecord::Base acts_as_nested_set dependent: :destroy - belongs_to :taxonomy, class_name: 'Spree::Taxonomy', :touch => true + belongs_to :taxonomy, class_name: 'Spree::Taxonomy', touch: true has_many :classifications, dependent: :destroy has_many :products, through: :classifications @@ -11,16 +13,16 @@ module Spree validates :name, presence: true has_attached_file :icon, - styles: { mini: '32x32>', normal: '128x128>' }, - default_style: :mini, - url: '/spree/taxons/:id/:style/:basename.:extension', - path: ':rails_root/public/spree/taxons/:id/:style/:basename.:extension', - default_url: '/assets/default_taxon.png' + styles: { mini: '32x32>', normal: '128x128>' }, + default_style: :mini, + url: '/spree/taxons/:id/:style/:basename.:extension', + path: ':rails_root/public/spree/taxons/:id/:style/:basename.:extension', + default_url: '/assets/default_taxon.png' include Spree::Core::S3Support supports_s3 :icon - include Spree::Core::ProductFilters # for detailed defs of filters + include Spree::Core::ProductFilters # for detailed defs of filters # Indicate which filters should be used for this taxon def applicable_filters @@ -56,10 +58,10 @@ module Spree end def pretty_name - ancestor_chain = self.ancestors.inject("") do |name, ancestor| + ancestor_chain = ancestors.inject("") do |name, ancestor| name += "#{ancestor.name} -> " end - ancestor_chain + "#{name}" + ancestor_chain + name.to_s end # Find all the taxons of supplied products for each enterprise, indexed by enterprise. diff --git a/app/models/spree/taxonomy.rb b/app/models/spree/taxonomy.rb index c5b4a5e965..2934281b4d 100644 --- a/app/models/spree/taxonomy.rb +++ b/app/models/spree/taxonomy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class Taxonomy < ActiveRecord::Base validates :name, presence: true @@ -7,16 +9,16 @@ module Spree after_save :set_name - default_scope -> { order("#{self.table_name}.position") } + default_scope -> { order("#{table_name}.position") } private - def set_name - if root - root.update_column(:name, name) - else - self.root = Taxon.create!(taxonomy_id: id, name: name) - end - end + def set_name + if root + root.update_column(:name, name) + else + self.root = Taxon.create!(taxonomy_id: id, name: name) + end + end end end diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb index 9055b94aea..bf1dbe6e1c 100644 --- a/spec/models/spree/taxon_spec.rb +++ b/spec/models/spree/taxon_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' module Spree describe Taxon do - let(:taxon) { Spree::Taxon.new(:name => "Ruby on Rails") } + let(:taxon) { Spree::Taxon.new(name: "Ruby on Rails") } let(:e) { create(:supplier_enterprise) } let!(:t1) { create(:taxon) } @@ -63,8 +65,8 @@ module Spree context "with parent taxon" do before do - taxon.stub :parent_id => 123 - taxon.stub :parent => mock_model(Spree::Taxon, :permalink => "brands") + taxon.stub parent_id: 123 + taxon.stub parent: mock_model(Spree::Taxon, permalink: "brands") end it "should set permalink correctly when taxon has parent" do @@ -92,7 +94,7 @@ module Spree it "does not error out" do pending "breaks in Rails 4 with postgres, see https://github.com/rails/rails/issues/10995" - expect { taxonomy.root.children.where(:name => "Some name").first_or_create }.not_to raise_error + expect { taxonomy.root.children.where(name: "Some name").first_or_create }.not_to raise_error end end end diff --git a/spec/models/spree/taxonomy_spec.rb b/spec/models/spree/taxonomy_spec.rb index f825f49764..2ead3dcc0e 100644 --- a/spec/models/spree/taxonomy_spec.rb +++ b/spec/models/spree/taxonomy_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'spec_helper' describe Spree::Taxonomy do context "#destroy" do before do - @taxonomy = create(:taxonomy) - @root_taxon = @taxonomy.root - @child_taxon = create(:taxon, :taxonomy_id => @taxonomy.id, :parent => @root_taxon) + @taxonomy = create(:taxonomy) + @root_taxon = @taxonomy.root + @child_taxon = create(:taxon, taxonomy_id: @taxonomy.id, parent: @root_taxon) end it "should destroy all associated taxons" do @@ -15,4 +17,3 @@ describe Spree::Taxonomy do end end end - From 57e74a4980b53591db2cde2cd303b60c14b4033a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 6 Aug 2020 11:12:49 +0100 Subject: [PATCH 4/8] Fix rubocop issues --- app/models/spree/classification.rb | 9 +++++---- app/models/spree/taxon.rb | 14 +++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb index 1a2b15ca6d..0b668a068b 100644 --- a/app/models/spree/classification.rb +++ b/app/models/spree/classification.rb @@ -11,10 +11,11 @@ module Spree private def dont_destroy_if_primary_taxon - if product.primary_taxon == taxon - errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name) - false - end + return unless product.primary_taxon == taxon + + errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, + product: product.name) + false end end end diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index 7fb566f39e..cb148d8146 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -41,9 +41,9 @@ module Spree # Creates permalink based on Stringex's .to_url method def set_permalink if parent.present? - self.permalink = [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last)].join('/') - else - self.permalink = name.to_url if permalink.blank? + self.permalink = [parent.permalink, permalink_end].join('/') + elsif permalink.blank? + self.permalink = name.to_url end end @@ -100,5 +100,13 @@ module Spree ts[t.enterprise_id.to_i] << t.id end end + + private + + def permalink_end + return name.to_url if permalink.blank? + + permalink.split('/').last + end end end From c35b330d25cfc062115d26dbd29a2d73ff6cda55 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 6 Aug 2020 11:15:22 +0100 Subject: [PATCH 5/8] Fix taxon_spec --- spec/models/spree/taxon_spec.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb index bf1dbe6e1c..135b512cd3 100644 --- a/spec/models/spree/taxon_spec.rb +++ b/spec/models/spree/taxon_spec.rb @@ -54,36 +54,36 @@ module Spree context "set_permalink" do it "should set permalink correctly when no parent present" do taxon.set_permalink - taxon.permalink.should == "ruby-on-rails" + expect(taxon.permalink).to eq "ruby-on-rails" end it "should support Chinese characters" do taxon.name = "你好" taxon.set_permalink - taxon.permalink.should == 'ni-hao' + expect(taxon.permalink).to eq 'ni-hao' end context "with parent taxon" do before do taxon.stub parent_id: 123 - taxon.stub parent: mock_model(Spree::Taxon, permalink: "brands") + taxon.stub parent: build(:taxon, permalink: "brands") end it "should set permalink correctly when taxon has parent" do taxon.set_permalink - taxon.permalink.should == "brands/ruby-on-rails" + expect(taxon.permalink).to eq "brands/ruby-on-rails" end it "should set permalink correctly with existing permalink present" do taxon.permalink = "b/rubyonrails" taxon.set_permalink - taxon.permalink.should == "brands/rubyonrails" + expect(taxon.permalink).to eq "brands/rubyonrails" end it "should support Chinese characters" do taxon.name = "我" taxon.set_permalink - taxon.permalink.should == "brands/wo" + expect(taxon.permalink).to eq "brands/wo" end end end @@ -93,7 +93,6 @@ module Spree let(:taxonomy) { create(:taxonomy) } it "does not error out" do - pending "breaks in Rails 4 with postgres, see https://github.com/rails/rails/issues/10995" expect { taxonomy.root.children.where(name: "Some name").first_or_create }.not_to raise_error end end From fcbb88324425e48094a3abb5e95489a40738ea3f Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 6 Aug 2020 11:16:21 +0100 Subject: [PATCH 6/8] Transpec taxon_spec --- spec/models/spree/taxon_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb index 135b512cd3..e6d55b4b23 100644 --- a/spec/models/spree/taxon_spec.rb +++ b/spec/models/spree/taxon_spec.rb @@ -65,8 +65,8 @@ module Spree context "with parent taxon" do before do - taxon.stub parent_id: 123 - taxon.stub parent: build(:taxon, permalink: "brands") + allow(taxon).to receive_messages parent_id: 123 + allow(taxon).to receive_messages parent: build(:taxon, permalink: "brands") end it "should set permalink correctly when taxon has parent" do From 4183dda27e505086e2c965752cd18f4802c2d305 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 1 Sep 2020 10:24:58 +0100 Subject: [PATCH 7/8] Fix long line --- app/models/spree/taxon.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index cb148d8146..b8263f4dba 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -92,8 +92,11 @@ module Spree ents_and_vars = ents_and_vars.merge(OrderCycle.active) if which_taxons == :current taxons = Spree::Taxon - .select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id").joins(products: :variants_including_master) - .joins("INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars ON spree_variants.id = ents_and_vars.variant_id") + .select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id") + .joins(products: :variants_including_master) + .joins(" + INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars + ON spree_variants.id = ents_and_vars.variant_id") taxons.each_with_object({}) do |t, ts| ts[t.enterprise_id.to_i] ||= Set.new From 5521b4bb04cf480d4ce0fb880be52015e3b28ebb Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 5 Sep 2020 15:00:20 +0100 Subject: [PATCH 8/8] Remove unused product filters --- app/models/spree/taxon.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index b8263f4dba..4e29c068ce 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -22,8 +22,6 @@ module Spree include Spree::Core::S3Support supports_s3 :icon - include Spree::Core::ProductFilters # for detailed defs of filters - # Indicate which filters should be used for this taxon def applicable_filters []