From 9ddfb1584b0eca79370d1fa21cfcde9f89da5376 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 15 Aug 2014 16:05:09 +1000 Subject: [PATCH] Admin can delete enterprise roles --- .../admin/enterprise_roles_controller.rb | 6 ++++++ spec/features/admin/enterprise_roles_spec.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/controllers/admin/enterprise_roles_controller.rb b/app/controllers/admin/enterprise_roles_controller.rb index 9ce3eafcab..8ffc2bad01 100644 --- a/app/controllers/admin/enterprise_roles_controller.rb +++ b/app/controllers/admin/enterprise_roles_controller.rb @@ -16,5 +16,11 @@ module Admin render status: 400, json: {errors: @enterprise_role.errors.full_messages.join(', ')} end end + + def destroy + @enterprise_role = EnterpriseRole.find params[:id] + @enterprise_role.destroy + render nothing: true + end end end diff --git a/spec/features/admin/enterprise_roles_spec.rb b/spec/features/admin/enterprise_roles_spec.rb index c36810e72a..0e44c9cfe3 100644 --- a/spec/features/admin/enterprise_roles_spec.rb +++ b/spec/features/admin/enterprise_roles_spec.rb @@ -62,6 +62,20 @@ feature %q{ page.should have_content "That role is already present." end.to change(EnterpriseRole, :count).by(0) end + + scenario "deleting a relationship" do + u = create(:user, email: 'u@example.com') + e = create(:enterprise, name: 'One') + er = create(:enterprise_role, user: u, enterprise: e) + + visit admin_enterprise_roles_path + page.should have_relationship u, e + + first("a.delete-enterprise-role").click + + page.should_not have_relationship u, e + EnterpriseRole.where(id: er.id).should be_empty + end end