Require EnterpriseFee.belongs_to by default

This commit is contained in:
Maikel Linke
2023-06-16 15:54:43 +10:00
parent 87ccfc94ef
commit 13b2f37884
4 changed files with 12 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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