mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
When deleting enterprise relationships, delete dependent permissions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class EnterpriseRelationship < ActiveRecord::Base
|
||||
belongs_to :parent, class_name: 'Enterprise', touch: true
|
||||
belongs_to :child, class_name: 'Enterprise', touch: true
|
||||
has_many :permissions, class_name: 'EnterpriseRelationshipPermission'
|
||||
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
|
||||
|
||||
validates_presence_of :parent_id, :child_id
|
||||
validates_uniqueness_of :child_id, scope: :parent_id, message: "^That relationship is already established."
|
||||
|
||||
@@ -69,14 +69,13 @@ feature %q{
|
||||
end.to change(EnterpriseRelationship, :count).by(0)
|
||||
end
|
||||
|
||||
|
||||
scenario "deleting a relationship" do
|
||||
e1 = create(:enterprise, name: 'One')
|
||||
e2 = create(:enterprise, name: 'Two')
|
||||
er = create(:enterprise_relationship, parent: e1, child: e2)
|
||||
er = create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:add_to_order_cycle])
|
||||
|
||||
visit admin_enterprise_relationships_path
|
||||
page.should have_relationship e1, e2
|
||||
page.should have_relationship e1, e2, ['to add to order cycle']
|
||||
|
||||
first("a.delete-enterprise-relationship").click
|
||||
|
||||
|
||||
Reference in New Issue
Block a user