mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Require EnterpriseRelationshipPermission.belongs_to by default
I had to change some specs to keep them simple but I don't think anything is broken. In one case, it would have needed a lot more setup to make the spec work. But in production, the permissions are never used with ModelSet, for example.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class EnterpriseRelationshipPermission < ApplicationRecord
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :enterprise_relationship
|
||||
default_scope { order('name') }
|
||||
before_destroy :destroy_related_exchanges
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class RequireEnterpriseRelationshipOnEnterpriseRelationshipPermission < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :enterprise_relationship_permissions, :enterprise_relationship_id, false
|
||||
end
|
||||
end
|
||||
@@ -161,7 +161,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_09_201542) do
|
||||
end
|
||||
|
||||
create_table "enterprise_relationship_permissions", id: :serial, force: :cascade do |t|
|
||||
t.integer "enterprise_relationship_id"
|
||||
t.integer "enterprise_relationship_id", null: false
|
||||
t.string "name", limit: 255, null: false
|
||||
t.index ["enterprise_relationship_id"], name: "index_erp_on_erid"
|
||||
end
|
||||
|
||||
@@ -817,7 +817,7 @@ describe Enterprise do
|
||||
it "should return only parent producers" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
expect(Enterprise.parents_of_one_union_others(supplier, nil)).to include(distributor)
|
||||
@@ -827,7 +827,7 @@ describe Enterprise do
|
||||
another_enterprise = create(:enterprise)
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
expect(
|
||||
@@ -838,7 +838,7 @@ describe Enterprise do
|
||||
it "does not find child in the relationship" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
expect(Enterprise.parents_of_one_union_others(distributor, nil)).not_to include(supplier)
|
||||
@@ -862,7 +862,7 @@ describe Enterprise do
|
||||
it "finds parent in the relationship" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
product = create(:product)
|
||||
order_cycle = create(
|
||||
:simple_order_cycle,
|
||||
@@ -878,7 +878,7 @@ describe Enterprise do
|
||||
it "does not find child in the relationship" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
product = create(:product)
|
||||
@@ -896,7 +896,7 @@ describe Enterprise do
|
||||
supplier = create(:supplier_enterprise)
|
||||
sender = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor, child: supplier,
|
||||
permissions: [permission])
|
||||
product = create(:product)
|
||||
|
||||
@@ -5,16 +5,16 @@ require 'spec_helper'
|
||||
describe Sets::ModelSet do
|
||||
describe "updating" do
|
||||
it "creates new models" do
|
||||
attrs = { collection_attributes: { '1' => { name: 's1' },
|
||||
'2' => { name: 's2' } } }
|
||||
attrs = { collection_attributes: { '1' => { name: "Fantasia", iso_name: "FAN" },
|
||||
'2' => { name: "Utopia", iso_name: "UTO" } } }
|
||||
|
||||
ms = Sets::ModelSet.new(EnterpriseRelationshipPermission,
|
||||
EnterpriseRelationshipPermission.all,
|
||||
ms = Sets::ModelSet.new(Spree::Country,
|
||||
Spree::Country.all,
|
||||
attrs)
|
||||
|
||||
expect { ms.save }.to change(EnterpriseRelationshipPermission, :count).by(2)
|
||||
expect { ms.save }.to change(Spree::Country, :count).by(2)
|
||||
|
||||
expect(EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count).to eq(2)
|
||||
expect(Spree::Country.where(name: ["Fantasia", "Utopia"]).count).to eq(2)
|
||||
end
|
||||
|
||||
it "updates existing models" do
|
||||
|
||||
Reference in New Issue
Block a user