From 4ddde3f311858a1747d5393326e9f414bdfe2247 Mon Sep 17 00:00:00 2001 From: DrumsnChocolate Date: Sun, 19 Jan 2025 14:21:41 +0100 Subject: [PATCH 1/5] make product names mutable again --- app/models/product.rb | 9 --------- app/views/price_lists/index.html.erb | 6 +++--- spec/models/product_spec.rb | 6 ------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index 8082251ac..4ad7b4a1d 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -6,7 +6,6 @@ class Product < ApplicationRecord has_many :price_lists, through: :product_prices, dependent: :restrict_with_error validates :name, :category, presence: true - validate :name_readonly accepts_nested_attributes_for :product_prices, allow_destroy: true @@ -17,12 +16,4 @@ def requires_age def t_category I18n.t category end - - private - - def name_readonly - return if new_record? - - errors.add(:name, 'is readonly') if name_changed? - end end diff --git a/app/views/price_lists/index.html.erb b/app/views/price_lists/index.html.erb index 2998d0dba..8a0da018b 100644 --- a/app/views/price_lists/index.html.erb +++ b/app/views/price_lists/index.html.erb @@ -25,11 +25,11 @@
<% end %> - + @@ -60,7 +60,7 @@
- +
diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index e8d5c8fb2..b4adc3787 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -17,12 +17,6 @@ it { expect(product).not_to be_valid } end - - context 'when updating the name' do - subject(:product) { create(:product) } - - it { expect(product.update(name: 'new_name')).to be false } - end end describe '#requires_age' do From e128b4596646ea49448498fd91d695ffab760c34 Mon Sep 17 00:00:00 2001 From: lodewiges <131907615+lodewiges@users.noreply.github.com> Date: Mon, 27 Oct 2025 00:25:36 +0100 Subject: [PATCH 2/5] Add context for updating product name in specs --- spec/models/product_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index b4adc3787..a260ec951 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -19,6 +19,12 @@ end end + context 'when updating the name' do + subject(:product) { create(:product) } + + it { expect(product.update(name: 'new_name')).to be true } + end + describe '#requires_age' do context 'when with requires age category' do subject(:product) { create(:product, category: %w[beer craft_beer distilled whiskey wine tobacco].sample) } From 7361f96e42f0c0f6764bee1e57e7d0621dab7756 Mon Sep 17 00:00:00 2001 From: lodewiges <131907615+lodewiges@users.noreply.github.com> Date: Mon, 27 Oct 2025 00:26:35 +0100 Subject: [PATCH 3/5] Fix indentation and formatting in product_spec.rb --- spec/models/product_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index a260ec951..df5dd88d4 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -17,13 +17,13 @@ it { expect(product).not_to be_valid } end - end - context 'when updating the name' do + context 'when updating the name' do subject(:product) { create(:product) } it { expect(product.update(name: 'new_name')).to be true } end + end describe '#requires_age' do context 'when with requires age category' do From 290612a81c364da6acfad7be465f2b8241235da2 Mon Sep 17 00:00:00 2001 From: Lodewiges Date: Mon, 27 Oct 2025 00:51:24 +0100 Subject: [PATCH 4/5] add warning when changing product name --- app/javascript/packs/price_lists.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/javascript/packs/price_lists.js b/app/javascript/packs/price_lists.js index 7585ec79d..54c5f9c8d 100644 --- a/app/javascript/packs/price_lists.js +++ b/app/javascript/packs/price_lists.js @@ -55,6 +55,11 @@ document.addEventListener('turbolinks:load', () => { }, saveProduct: function(product) { + if (product.id && product._beforeEditingCache.name !== product.name) { + if (!confirm("Weet je zeker dat je de productnaam wilt wijzigen? Pas hier mee op want dit kan problemen geven in bestaande orders. Als je twijfelt, maak dan een nieuw product aan in plaats van het bestaande te hernoemen.")) { + return; + } + } const sanitizedProduct = this.sanitizeProductInput(product); if (sanitizedProduct.id) { // Existing product this.$http.put(`/products/${sanitizedProduct.id}.json`, { product: sanitizedProduct }).then( (response) => { From eca3e5b6187edf4c5fb4c497c004012014960041 Mon Sep 17 00:00:00 2001 From: Lodewiges Date: Mon, 27 Oct 2025 00:58:43 +0100 Subject: [PATCH 5/5] Fix lintS --- app/javascript/packs/price_lists.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/packs/price_lists.js b/app/javascript/packs/price_lists.js index 54c5f9c8d..2b9bd3dbd 100644 --- a/app/javascript/packs/price_lists.js +++ b/app/javascript/packs/price_lists.js @@ -56,7 +56,7 @@ document.addEventListener('turbolinks:load', () => { saveProduct: function(product) { if (product.id && product._beforeEditingCache.name !== product.name) { - if (!confirm("Weet je zeker dat je de productnaam wilt wijzigen? Pas hier mee op want dit kan problemen geven in bestaande orders. Als je twijfelt, maak dan een nieuw product aan in plaats van het bestaande te hernoemen.")) { + if (!confirm('Weet je zeker dat je de productnaam wilt wijzigen? Pas hier mee op want dit kan problemen geven in bestaande orders. Als je twijfelt, maak dan een nieuw product aan in plaats van het bestaande te hernoemen.')) { return; } }