Prevent creating a linked variant from a linked variant

It's just too confusing.
This commit is contained in:
David Cook
2026-03-31 14:34:17 +11:00
parent 5beed6f028
commit ccc38367f3
2 changed files with 13 additions and 3 deletions

View File

@@ -92,7 +92,7 @@
- if variant.persisted?
= link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(variant.product, variant)
- if allowed_source_producers.include?(variant.supplier)
- if variant.source_variants.empty? && allowed_source_producers.include?(variant.supplier)
= link_to t('admin.products_page.actions.create_linked_variant'), admin_create_linked_variant_path(variant_id: variant.id, product_index:), 'data-turbo-method': :post
- if variant.product.variants.size > 1

View File

@@ -285,8 +285,9 @@ RSpec.describe 'As an enterprise user, I can perform actions on the products scr
end
describe "Create linked variant" do
let!(:variant) {
create(:variant, display_name: "My box", supplier: producer)
let!(:variant) { create(:variant, display_name: "My box", supplier: producer) }
let!(:linked_variant) {
variant.create_linked_variant(user).tap{ |v| v.update! display_name: "My linked variant" }
}
let!(:other_producer) { create(:supplier_enterprise) }
let!(:other_variant) {
@@ -312,6 +313,15 @@ RSpec.describe 'As an enterprise user, I can perform actions on the products scr
expect(page).to have_link "Create linked variant"
end
close_action_menu
# Check my own linked variant
within row_containing_name("My linked variant") do
page.find(".vertical-ellipsis-menu").click
expect(page).not_to have_link "Create linked variant"
end
close_action_menu
# Create linked variant sourced from my friend
within row_containing_name("My friends box") do