double verification when deleting a site (safer)

did committed Dec 04, 2015
commit e827221d0adbdff113162263bccb30a8a94a66fd
Showing 3 changed files with 9 additions and 3 deletions
Gemfile +1 -1
@@ @@ -14,7 +14,7 @@ gem 'therubyracer'
# Local development
# gem 'locomotivecms_coal', path: '../gems/coal', require: false
- # gem 'locomotivecms_steam', path: '../gems/steam', require: false
+ gem 'locomotivecms_steam', path: '../gems/steam', require: false
# gem 'locomotivecms_common', path: '../in_progress/common', require: false
group :development, :test do
locomotive/wagon/commands/delete_command.rb b/lib/locomotive/wagon/commands/delete_command.rb +6 -2
@@ @@ -36,8 +36,12 @@ module Locomotive::Wagon
private
def delete_site
- client.current_site.destroy.tap do |response|
- shell.say "The site specified in your #{env} environment has been deleted.", :green
+ if shell.ask('Please, type the handle of your site') == client.options[:handle]
+ client.current_site.destroy.tap do |response|
+ shell.say "The remote site specified in your #{env} environment has been deleted.", :green
+ end
+ else
+ shell.say 'The delete operation has been cancelled', :red
end
end
spec/integration/commands/delete_command_spec.rb +2 -0
@@ @@ -29,6 +29,8 @@ describe Locomotive::Wagon::DeleteCommand do
let(:client_api) { Locomotive::Coal::Client.new(api_uri, api_credentials, handle: 'short-lived') }
let(:_client_api) { Locomotive::Coal::Client.new(api_uri, api_credentials) }
+ before { allow(shell).to receive(:ask).and_return 'short-lived' }
+
before { _client_api.sites.create(name: 'ShortLived', handle: 'short-lived') }
subject { described_class.delete(env, path, 'site', nil, shell) }