diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb index dba99cc7b3..ff2c1fe3fa 100644 --- a/app/models/enterprise_relationship.rb +++ b/app/models/enterprise_relationship.rb @@ -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." diff --git a/spec/features/admin/enterprise_relationships_spec.rb b/spec/features/admin/enterprise_relationships_spec.rb index 007f663db0..bfc624bce5 100644 --- a/spec/features/admin/enterprise_relationships_spec.rb +++ b/spec/features/admin/enterprise_relationships_spec.rb @@ -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