When deleting enterprise relationships, delete dependent permissions

This commit is contained in:
Rohan Mitchell
2014-09-10 14:49:15 +10:00
parent c297b7014a
commit 32a2e793ad
2 changed files with 3 additions and 4 deletions

View File

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

View File

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