mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Validate and enforce AdjustmentMetadata associations
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AdjustmentMetadata < ApplicationRecord
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :adjustment, class_name: 'Spree::Adjustment'
|
||||
belongs_to :enterprise
|
||||
end
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RequireAdjustmentAndEnterpriseOnAdjustmentMetadata < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :adjustment_metadata, :adjustment_id, false
|
||||
change_column_null :adjustment_metadata, :enterprise_id, false
|
||||
end
|
||||
end
|
||||
@@ -44,8 +44,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_22_120633) do
|
||||
end
|
||||
|
||||
create_table "adjustment_metadata", id: :serial, force: :cascade do |t|
|
||||
t.integer "adjustment_id"
|
||||
t.integer "enterprise_id"
|
||||
t.integer "adjustment_id", null: false
|
||||
t.integer "enterprise_id", null: false
|
||||
t.string "fee_name", limit: 255
|
||||
t.string "fee_type", limit: 255
|
||||
t.string "enterprise_role", limit: 255
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe AdjustmentMetadata do
|
||||
it { is_expected.to belong_to(:adjustment).required }
|
||||
it { is_expected.to belong_to(:enterprise).required }
|
||||
|
||||
it "is valid when built from factory" do
|
||||
adjustment_metadata = build(:adjustment_metadata)
|
||||
expect(adjustment_metadata).to be_valid
|
||||
|
||||
Reference in New Issue
Block a user