From 434f9600b71360700675160a7ff2ef3841cdf1bc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 27 Jul 2021 15:02:45 +0200 Subject: [PATCH] Enterprise fee must be linked with an enterprise Add 2 validation / errorproof options: - Add rails validation on `enterprise_id` on enterprise_fee model - Do not add a blank option on the select: ie. user can select a blank enterprise in the form Update tests as well --- app/models/enterprise_fee.rb | 1 + app/views/admin/enterprise_fees/index.html.haml | 2 +- spec/features/admin/enterprise_fees_spec.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 9ceed01020..bac889327b 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -21,6 +21,7 @@ class EnterpriseFee < ApplicationRecord validates :fee_type, inclusion: { in: FEE_TYPES } validates :name, presence: true + validates :enterprise_id, presence: true before_save :ensure_valid_tax_category_settings diff --git a/app/views/admin/enterprise_fees/index.html.haml b/app/views/admin/enterprise_fees/index.html.haml index 2f061bb57d..7ca885dad2 100644 --- a/app/views/admin/enterprise_fees/index.html.haml +++ b/app/views/admin/enterprise_fees/index.html.haml @@ -29,7 +29,7 @@ %tr{ ng: { repeat: 'enterprise_fee in enterprise_fees | filter:query' } } %td = f.ng_hidden_field :id - %ofn-select{ :id => angular_id(:enterprise_id), data: 'enterprises', include_blank: true, ng: { model: 'enterprise_fee.enterprise_id' } } + %ofn-select{ :id => angular_id(:enterprise_id), data: 'enterprises', ng: { model: 'enterprise_fee.enterprise_id' } } %input{ type: "hidden", name: angular_name(:enterprise_id), ng: { value: "enterprise_fee.enterprise_id" } } %td= f.ng_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type' %td= f.ng_text_field :name, { placeholder: t('.name_placeholder') } diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb index 455d653018..66a93d6f9e 100644 --- a/spec/features/admin/enterprise_fees_spec.rb +++ b/spec/features/admin/enterprise_fees_spec.rb @@ -181,7 +181,7 @@ feature ' click_link "Manage Enterprise Fees" expect(page).to have_select('sets_enterprise_fee_set_collection_attributes_0_enterprise_id', selected: 'Second Distributor', - options: ['', 'First Distributor', 'Second Distributor']) + options: ['First Distributor', 'Second Distributor']) end end end