Admin can delete enterprise relationships

This commit is contained in:
Rohan Mitchell
2014-05-16 14:44:01 +10:00
parent aa965e3752
commit 5d0680234d
6 changed files with 36 additions and 7 deletions

View File

@@ -4,8 +4,12 @@ Admin.controller "AdminEnterpriseRelationshipsCtrl", ($scope, $http, EnterpriseR
$scope.create = ->
$http.post('/admin/enterprise_relationships', {enterprise_relationship: {parent_id: $scope.parent_id, child_id: $scope.child_id}}).success (data, status) =>
$scope.EnterpriseRelationships.enterprise_relationships.unshift({parent_name: data.parent_name, child_name: data.child_name})
$scope.EnterpriseRelationships.enterprise_relationships.unshift(data)
$scope.errors = ""
.error (response, status) =>
$scope.errors = response.errors
$scope.delete = (enterprise_relationship) ->
if confirm("Are you sure?")
$scope.EnterpriseRelationships.delete enterprise_relationship

View File

@@ -1,4 +1,9 @@
Admin.factory 'EnterpriseRelationships', (enterprise_relationships) ->
Admin.factory 'EnterpriseRelationships', ($http, enterprise_relationships) ->
new class EnterpriseRelationships
constructor: ->
@enterprise_relationships = enterprise_relationships
delete: (er) ->
ers = @enterprise_relationships
$http.delete('/admin/enterprise_relationships/' + er.id).success (data) ->
ers.splice ers.indexOf(er), 1

View File

@@ -14,5 +14,11 @@ module Admin
render status: 400, json: {errors: @enterprise_relationship.errors.full_messages.join(', ')}
end
end
def destroy
@enterprise_relationship = EnterpriseRelationship.find params[:id]
@enterprise_relationship.destroy
render nothing: true
end
end
end

View File

@@ -27,3 +27,5 @@
%tr{"ng-repeat" => "enterprise_relationship in EnterpriseRelationships.enterprise_relationships"}
%td {{ enterprise_relationship.parent_name }}
%td {{ enterprise_relationship.child_name }}
%td.actions
%a.delete-enterprise-relationship.icon-trash.no-text{'ng-click' => 'delete(enterprise_relationship)'}

View File

@@ -1,6 +1,6 @@
object @enterprise_relationship
attributes :parent_id, :child_id
attributes :id, :parent_id, :child_id
node :parent_name do |enterprise_relationship|
enterprise_relationship.parent.name

View File

@@ -22,8 +22,8 @@ feature %q{
# Then I should see the relationships
within('table#enterprise-relationships') do
page.should have_table_row [e1.name, e2.name]
page.should have_table_row [e3.name, e4.name]
page.should have_table_row [e1.name, e2.name, '']
page.should have_table_row [e3.name, e4.name, '']
end
end
@@ -37,7 +37,7 @@ feature %q{
select 'Two', from: 'enterprise_relationship_child_name'
click_button 'Create'
page.should have_table_row [e1.name, e2.name]
page.should have_table_row [e1.name, e2.name, '']
EnterpriseRelationship.where(parent_id: e1, child_id: e2).should be_present
end
@@ -60,5 +60,17 @@ feature %q{
end
scenario "deleting a relationship"
scenario "deleting a relationship" do
e1 = create(:enterprise, name: 'One')
e2 = create(:enterprise, name: 'Two')
er = create(:enterprise_relationship, parent: e1, child: e2)
visit admin_enterprise_relationships_path
page.should have_table_row [e1.name, e2.name, '']
first("a.delete-enterprise-relationship").click
page.should_not have_table_row [e1.name, e2.name, '']
EnterpriseRelationship.where(id: er.id).should be_empty
end
end