From 13b2f37884ff5db5c31eb98cc8afda84411aac7e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 16 Jun 2023 15:54:43 +1000 Subject: [PATCH] Require EnterpriseFee.belongs_to by default --- app/models/enterprise_fee.rb | 4 +++- .../20230616055032_require_enterprise_on_enterprise_fee.rb | 7 +++++++ db/schema.rb | 2 +- spec/models/enterprise_fee_spec.rb | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20230616055032_require_enterprise_on_enterprise_fee.rb diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 598035abed..5abaf2bcb6 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -3,10 +3,12 @@ class EnterpriseFee < ApplicationRecord include CalculatedAdjustments + self.belongs_to_required_by_default = true + acts_as_paranoid belongs_to :enterprise - belongs_to :tax_category, class_name: 'Spree::TaxCategory' + belongs_to :tax_category, optional: true, class_name: 'Spree::TaxCategory' has_many :coordinator_fees, dependent: :destroy has_many :order_cycles, through: :coordinator_fees diff --git a/db/migrate/20230616055032_require_enterprise_on_enterprise_fee.rb b/db/migrate/20230616055032_require_enterprise_on_enterprise_fee.rb new file mode 100644 index 0000000000..4a22cc4c9e --- /dev/null +++ b/db/migrate/20230616055032_require_enterprise_on_enterprise_fee.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class RequireEnterpriseOnEnterpriseFee < ActiveRecord::Migration[7.0] + def change + change_column_null :enterprise_fees, :enterprise_id, false + end +end diff --git a/db/schema.rb b/db/schema.rb index c58419991e..17d9f51edb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -121,7 +121,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_09_201542) do end create_table "enterprise_fees", id: :serial, force: :cascade do |t| - t.integer "enterprise_id" + t.integer "enterprise_id", null: false t.string "fee_type", limit: 255 t.string "name", limit: 255 t.datetime "created_at", precision: nil, null: false diff --git a/spec/models/enterprise_fee_spec.rb b/spec/models/enterprise_fee_spec.rb index ab6f5eda53..cfbd5a9fee 100644 --- a/spec/models/enterprise_fee_spec.rb +++ b/spec/models/enterprise_fee_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe EnterpriseFee do describe "associations" do - it { is_expected.to belong_to(:enterprise) } + it { is_expected.to belong_to(:enterprise).required } end describe "validations" do