From 18fb1cfa746912956e16037af04fa59829a4446d Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 11 Mar 2026 10:44:15 +1100 Subject: [PATCH] Rename variant 'owner' to 'hub' As discussed by team, and using same nomenclature as VariantOverride. --- app/models/spree/variant.rb | 8 ++++---- app/views/admin/products_v3/_variant_row.html.haml | 2 +- config/locales/en.yml | 2 +- db/migrate/20260225022934_add_hub_to_spree_variants.rb | 7 +++++++ db/migrate/20260225022934_add_owner_to_spree_variants.rb | 7 ------- db/schema.rb | 6 +++--- spec/models/spree/variant_spec.rb | 4 ++-- spec/requests/admin/products_v3_spec.rb | 2 +- spec/system/admin/products_v3/index_spec.rb | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 db/migrate/20260225022934_add_hub_to_spree_variants.rb delete mode 100644 db/migrate/20260225022934_add_owner_to_spree_variants.rb diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index a57a873d0c..13d556b377 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -40,7 +40,7 @@ module Spree belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true - belongs_to :owner, class_name: 'Enterprise', optional: true + belongs_to :hub, class_name: 'Enterprise', optional: true delegate :name, :name=, :description, :description=, :meta_keywords, to: :product @@ -275,8 +275,8 @@ module Spree # Clone this variant, retaining a 'source' link to it def create_linked_variant(user) - # Owner is my enterprise which has permission to create variants sourced from that supplier - owner_id = EnterpriseRelationship.permitted_by(supplier).permitting(user.enterprises) + # Hub owner is my enterprise which has permission to create variant sourced from that supplier + hub_id = EnterpriseRelationship.permitted_by(supplier).permitting(user.enterprises) .with_permission(:create_linked_variants) .pick(:child_id) @@ -284,7 +284,7 @@ module Spree variant.price = price variant.source_variants = [self] variant.stock_items << Spree::StockItem.new(variant:) - variant.owner_id = owner_id + variant.hub_id = hub_id variant.on_demand = on_demand variant.on_hand = on_hand variant.save! diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 3982046e27..f5aee06bf7 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -4,7 +4,7 @@ %td.col-image -# empty - variant.source_variants.each do |source_variant| - = content_tag(:span, "🔗", title: t('admin.products_page.variant_row.sourced_from', source_name: source_variant.name, source_id: source_variant.id, owner_name: variant.owner&.name)) + = content_tag(:span, "🔗", title: t('admin.products_page.variant_row.sourced_from', source_name: source_variant.name, source_id: source_variant.id, hub_name: variant.hub&.name)) %td.col-name.field.naked_inputs = f.hidden_field :id = f.text_field :display_name, 'aria-label': t('admin.products_page.columns.name'), placeholder: variant.product.name diff --git a/config/locales/en.yml b/config/locales/en.yml index d7adcc8183..2b8134bc77 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -721,7 +721,7 @@ en: image: edit: Edit variant_row: - sourced_from: "Sourced from: %{source_name} (%{source_id}); Owned by: %{owner_name}" + sourced_from: "Sourced from: %{source_name} (%{source_id}); Hub: %{hub_name}" product_preview: product_preview: Product preview shop_tab: Shop diff --git a/db/migrate/20260225022934_add_hub_to_spree_variants.rb b/db/migrate/20260225022934_add_hub_to_spree_variants.rb new file mode 100644 index 0000000000..bcfed767b8 --- /dev/null +++ b/db/migrate/20260225022934_add_hub_to_spree_variants.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddHubToSpreeVariants < ActiveRecord::Migration[7.1] + def change + add_reference :spree_variants, :hub, foreign_key: { to_table: :enterprises } + end +end diff --git a/db/migrate/20260225022934_add_owner_to_spree_variants.rb b/db/migrate/20260225022934_add_owner_to_spree_variants.rb deleted file mode 100644 index 89928af714..0000000000 --- a/db/migrate/20260225022934_add_owner_to_spree_variants.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class AddOwnerToSpreeVariants < ActiveRecord::Migration[7.1] - def change - add_reference :spree_variants, :owner, foreign_key: { to_table: :enterprises } - end -end diff --git a/db/schema.rb b/db/schema.rb index cf235ead0d..1c77a7ca8d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1009,8 +1009,8 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do t.bigint "supplier_id" t.float "variant_unit_scale" t.string "variant_unit_name", limit: 255 - t.bigint "owner_id" - t.index ["owner_id"], name: "index_spree_variants_on_owner_id" + t.bigint "hub_id" + t.index ["hub_id"], name: "index_spree_variants_on_hub_id" t.index ["primary_taxon_id"], name: "index_spree_variants_on_primary_taxon_id" t.index ["product_id"], name: "index_variants_on_product_id" t.index ["shipping_category_id"], name: "index_spree_variants_on_shipping_category_id" @@ -1271,7 +1271,7 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do add_foreign_key "spree_tax_rates", "spree_zones", column: "zone_id", name: "spree_tax_rates_zone_id_fk" add_foreign_key "spree_users", "spree_addresses", column: "bill_address_id", name: "spree_users_bill_address_id_fk" add_foreign_key "spree_users", "spree_addresses", column: "ship_address_id", name: "spree_users_ship_address_id_fk" - add_foreign_key "spree_variants", "enterprises", column: "owner_id" + add_foreign_key "spree_variants", "enterprises", column: "hub_id" add_foreign_key "spree_variants", "enterprises", column: "supplier_id" add_foreign_key "spree_variants", "spree_products", column: "product_id", name: "spree_variants_product_id_fk" add_foreign_key "spree_variants", "spree_shipping_categories", column: "shipping_category_id" diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 1b0bb47acc..085be8a04b 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Spree::Variant do it { is_expected.to have_many :semantic_links } it { is_expected.to belong_to(:product).required } it { is_expected.to belong_to(:supplier).required } - it { is_expected.to belong_to(:owner).optional } + it { is_expected.to belong_to(:hub).optional } it { is_expected.to have_many(:inventory_units) } it { is_expected.to have_many(:line_items) } it { is_expected.to have_many(:stock_items) } @@ -1024,7 +1024,7 @@ RSpec.describe Spree::Variant do linked_variant = variant.create_linked_variant(user) expect(linked_variant.source_variants).to eq [variant] - expect(linked_variant.owner).to eq enterprise + expect(linked_variant.hub).to eq enterprise expect(linked_variant.price).to eq 10.95 expect(linked_variant.on_demand).to eq false expect(linked_variant.on_hand).to eq 5 diff --git a/spec/requests/admin/products_v3_spec.rb b/spec/requests/admin/products_v3_spec.rb index de4418458c..1f0773753a 100644 --- a/spec/requests/admin/products_v3_spec.rb +++ b/spec/requests/admin/products_v3_spec.rb @@ -121,7 +121,7 @@ RSpec.describe "Admin::ProductsV3" do # The new variant is owned by my enterprise that has permission, not the other one new_variant = variant.product.variants.order(:id).last - expect(new_variant.owner).to eq enterprise + expect(new_variant.hub).to eq enterprise end end end diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index 83fddcf354..d943e5a1d3 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -147,7 +147,7 @@ RSpec.describe 'As an enterprise user, I can browse my products' do let!(:v3_source) { p3.variants.first } let!(:v3_sourced) { create(:variant, display_name: "Variant3-sourced", product: p3, supplier: source_producer, - owner: producer) + hub: producer) } let!(:enterprise_relationship) { # Other producer grants me access to manage their variant @@ -163,7 +163,7 @@ RSpec.describe 'As an enterprise user, I can browse my products' do it "shows sourced variant with indicator" do within row_containing_name("Variant3-sourced") do expect(page).to have_selector 'span[title*="Sourced from: "]' - expect(page).to have_selector 'span[title*="Owned by: My Enterprise"]' + expect(page).to have_selector 'span[title*="Hub: My Enterprise"]' end end end