Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-06-18 12:17:31 UTC using RuboCop version 1.76.0.
# on 2025-06-18 13:16:56 UTC using RuboCop version 1.76.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -332,7 +332,7 @@ Rails/FilePath:
- 'core/lib/spree/testing_support/dummy_app.rb'
- 'sample/lib/spree/sample.rb'

# Offense count: 59
# Offense count: 57
# Configuration parameters: Include.
# Include: **/app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/spree/api/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ module Spree::Api
required_attributes = json_response["required_attributes"]
expect(required_attributes).to include("name")
expect(required_attributes).to include("price")
expect(required_attributes).to include("shipping_category_id")
expect(required_attributes).to include("shipping_category")
end

it_behaves_like "modifying product actions are restricted"
Expand Down Expand Up @@ -348,7 +348,7 @@ module Spree::Api
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]
expect(errors.keys).to include("name", "price", "shipping_category_id")
expect(errors.keys).to include("name", "price", "shipping_category")
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
# Regression test for https://github.com/spree/spree/issues/942
context "errors when no shipping methods are available" do
before do
Spree::ShippingMethod.delete_all
Spree::ShippingMethod.update_all(available_to_all: false, available_to_users: false)
end

specify do
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def build_option_type_with_values(name, values)
fill_in "product_sku", with: "B100"
fill_in "product_price", with: "100"
click_button "Create"
expect(page).to have_content("Shipping category can't be blank")
expect(page).to have_content("Shipping Category must exist")
end

context "using a locale with a different decimal format " do
Expand Down
3 changes: 1 addition & 2 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Product < Spree::Base
has_many :taxons, through: :classifications, before_remove: :remove_taxon

belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products, optional: true
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products
belongs_to :primary_taxon, class_name: 'Spree::Taxon', optional: true

has_one :master,
Expand Down Expand Up @@ -122,7 +122,6 @@ def find_or_build_master
validates :meta_title, length: { maximum: 255 }
validates :name, presence: true
validates :price, presence: true, if: proc { Spree::Config[:require_master_price] }
validates :shipping_category_id, presence: true
validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }

attr_accessor :option_values_hash
Expand Down
4 changes: 2 additions & 2 deletions core/app/models/spree/shipping_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class ShippingCategory < Spree::Base
self.allowed_ransackable_attributes = %w[name]

validates :name, presence: true
has_many :products, inverse_of: :shipping_category
has_many :shipping_method_categories, inverse_of: :shipping_category
has_many :products, inverse_of: :shipping_category, dependent: :restrict_with_error
has_many :shipping_method_categories, inverse_of: :shipping_category, dependent: :destroy
has_many :shipping_methods, through: :shipping_method_categories
end
end
4 changes: 2 additions & 2 deletions core/app/models/spree/shipping_method_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class ShippingMethodCategory < Spree::Base
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', optional: true
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :shipping_method_categories, optional: true
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :shipping_method_categories
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AddShippingCategoryForeignKeys < ActiveRecord::Migration[7.0]
def change
add_foreign_key :spree_products, :spree_shipping_categories, column: :shipping_category_id, null: false
add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, null: false
add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, null: false
end
end
Loading