mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Rubocop auto-correct
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class Classification < ActiveRecord::Base
|
||||
self.table_name = 'spree_products_taxons'
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user