Commit 9705e4a
Changed files (5)
app
assets
javascripts
controllers
templates
controllers
config
spec
controllers
app/assets/javascripts/controllers/environment.js.coffee
@@ -1,1 +1,5 @@
-App.EnvironmentController = Ember.ObjectController.extend()
+App.EnvironmentController = Ember.ObjectController.extend
+ actions:
+ deleteEnvironment: ->
+ @get('model').destroyRecord().then =>
+ @transitionToRoute('service.environments')
app/assets/javascripts/templates/environment.hbs
@@ -1,2 +1,3 @@
-<h4>details</h4>
+<h4>details for {{name}}</h4>
+<a href="#" {{action "deleteEnvironment"}}>delete</a>
<p>API Key: {{apiKey}}</p>
app/controllers/environments_controller.rb
@@ -12,6 +12,11 @@ class EnvironmentsController < ApplicationController
@environment = service.environments.create!(environment_params)
end
+ def destroy
+ Environment.find(params[:id]).destroy
+ render json: {}
+ end
+
private
def environment_params
config/routes.rb
@@ -2,7 +2,7 @@ Erkell::Application.routes.draw do
resources :sessions, only: [:new, :create, :destroy]
resources :videos, only: [:index, :create, :update, :destroy]
resources :services, only: [:index, :create]
- resources :environments, only: [:index, :show, :create]
+ resources :environments, only: [:index, :show, :create, :destroy]
get 'dashboard', to: 'dashboard#index'
root 'dashboard#index'
spec/controllers/environments_controller_spec.rb
@@ -37,4 +37,13 @@ describe EnvironmentsController do
expect(Environment.last.name).to eql('development')
end
end
+
+ describe "#destroy" do
+ let(:environment) { create(:environment) }
+
+ it 'deletes the environment' do
+ xhr :delete, :destroy, id: environment.id
+ expect(Environment.count).to eql(0)
+ end
+ end
end