locomotivecms_wagon 2.0.0.rc4 → 2.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../integration_helper'
3
+ require 'locomotive/wagon/commands/authenticate_command'
4
+ require 'locomotive/wagon/commands/delete_command'
5
+ require 'thor'
6
+
7
+ describe Locomotive::Wagon::DeleteCommand do
8
+
9
+ before { VCR.insert_cassette 'delete', record: :new_episodes, match_requests_on: [:method, :uri, :body] }
10
+ after { VCR.eject_cassette }
11
+
12
+ let(:env) { 'production' }
13
+ let(:path) { default_site_path }
14
+ let(:shell) { Thor::Shell::Color.new }
15
+ let(:options) { { data: true, verbose: true } }
16
+ let(:api_uri) { 'http://www.example.com:3000' }
17
+ let(:api_credentials) { { email: TEST_API_EMAIL, api_key: TEST_API_KEY } }
18
+ let(:client_api) { Locomotive::Coal::Client.new(api_uri, api_credentials, handle: 'www') }
19
+
20
+ before do
21
+ allow_any_instance_of(described_class).to receive(:read_deploy_settings).and_return({})
22
+ allow_any_instance_of(described_class).to receive(:api_site_client)
23
+ .and_return(client_api)
24
+
25
+ end
26
+
27
+ describe 'delete the current site' do
28
+
29
+ let(:client_api) { Locomotive::Coal::Client.new(api_uri, api_credentials, handle: 'short-lived') }
30
+ let(:_client_api) { Locomotive::Coal::Client.new(api_uri, api_credentials) }
31
+
32
+ before { allow(shell).to receive(:ask).and_return 'short-lived' }
33
+
34
+ before { _client_api.sites.create(name: 'ShortLived', handle: 'short-lived') }
35
+
36
+ subject { described_class.delete(env, path, 'site', nil, shell) }
37
+
38
+ it { is_expected.to be_a(Locomotive::Coal::Resource) }
39
+
40
+ end
41
+
42
+ context 'resource exists' do
43
+
44
+ let(:resource_id) { nil }
45
+
46
+ subject { described_class.delete(env, path, resource_type, resource_id, shell) }
47
+
48
+ describe 'delete page resource' do
49
+
50
+ let(:resource_type) { 'page' }
51
+ let(:resource_id) { 'hello-world' }
52
+
53
+ before { client_api.pages.create(title: 'Hello world', slug: 'hello-world', parent: 'index', template: 'Hello world!') }
54
+ it { is_expected.to be_a(Locomotive::Coal::Resource) }
55
+
56
+ end
57
+
58
+ describe 'delete content type resource' do
59
+
60
+ let(:resource_type) { 'content_type' }
61
+ let(:resource_id) { 'fake_messages' }
62
+
63
+ before { client_api.content_types.create(name: 'FakeMessages', slug: 'fake-messages', fields: [{ label: 'E-mail', name: 'email', type: 'string' }]) }
64
+ it { is_expected.to be_a(Locomotive::Coal::Resource) }
65
+
66
+ describe 'all of them' do
67
+
68
+ let(:resource_type) { 'content_types' }
69
+
70
+ before { client_api.content_types.create(name: 'FakeMessages', slug: 'fake-messages-2', fields: [{ label: 'E-mail', name: 'email', type: 'string' }]) }
71
+ it { expect(subject['deletions']).to be >= 1 }
72
+
73
+ end
74
+
75
+ end
76
+
77
+ describe 'delete snippet resource' do
78
+
79
+ let(:resource_type) { 'snippet' }
80
+ let(:resource_id) { 'analytics' }
81
+
82
+ before { client_api.snippets.create(name: 'Analytics', slug: 'analytics', template: 'Analytics') }
83
+ it { is_expected.to be_a(Locomotive::Coal::Resource) }
84
+
85
+ describe 'all of them' do
86
+
87
+ let(:resource_type) { 'snippets' }
88
+
89
+ before { client_api.snippets.create(name: 'Analytics', slug: 'analytics_2', template: 'Analytics') }
90
+ it { expect(subject['deletions']).to be >= 1 }
91
+
92
+ end
93
+
94
+ end
95
+
96
+ describe 'delete all theme asset resources' do
97
+
98
+ let(:resource_type) { 'theme_assets' }
99
+
100
+ before {
101
+ client_api.theme_assets.create(source: Locomotive::Coal::UploadIO.new(File.join(default_site_path, 'icon.png')))
102
+ client_api.theme_assets.create(source: Locomotive::Coal::UploadIO.new(File.join(default_site_path, 'public', 'samples', 'photo.jpg')))
103
+ }
104
+
105
+ it { expect(subject['deletions']).to be >= 2 }
106
+
107
+ end
108
+
109
+ describe 'delete translation resource' do
110
+
111
+ let(:resource_type) { 'translation' }
112
+ let(:resource_id) { 'hello_world' }
113
+
114
+ before { client_api.translations.create(key: 'hello_world', values: { fr: 'Bonjour le monde' }) }
115
+ it { is_expected.to be_a(Locomotive::Coal::Resource) }
116
+
117
+ describe 'all of them' do
118
+
119
+ let(:resource_type) { 'translations' }
120
+
121
+ before { client_api.translations.create(key: 'hello_world_2', values: { fr: 'Bonjour le monde' }) }
122
+ it { expect(subject['deletions']).to be >= 1 }
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+
130
+ context 'resource does not exist' do
131
+ describe '.delete' do
132
+ [ ['page', 'bogus_id'],
133
+ ['content_type', 'bogus_id'],
134
+ ['snippet', 'bogus_id'],
135
+ ['translation', 'bogus_id']
136
+ ].each do |resource, id|
137
+ describe resource do
138
+ it 'raises an exception' do
139
+ expect { described_class.delete(env, path, resource, id) }
140
+ .to raise_error(Locomotive::Coal::UnknownResourceError)
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+
148
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_wagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc4
4
+ version: 2.0.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-22 00:00:00.000000000 Z
12
+ date: 2015-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -101,28 +101,28 @@ dependencies:
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 1.0.0.rc2
104
+ version: 1.0.0.rc3
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 1.0.0.rc2
111
+ version: 1.0.0.rc3
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: locomotivecms_steam
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: 1.0.0.rc6
118
+ version: 1.0.0.rc7
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: 1.0.0.rc6
125
+ version: 1.0.0.rc7
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: listen
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -452,7 +452,7 @@ files:
452
452
  - lib/locomotive/wagon/commands/concerns/netrc_concern.rb
453
453
  - lib/locomotive/wagon/commands/concerns/spinner_concern.rb
454
454
  - lib/locomotive/wagon/commands/concerns/steam_concern.rb
455
- - lib/locomotive/wagon/commands/destroy_command.rb
455
+ - lib/locomotive/wagon/commands/delete_command.rb
456
456
  - lib/locomotive/wagon/commands/generate_command.rb
457
457
  - lib/locomotive/wagon/commands/init_command.rb
458
458
  - lib/locomotive/wagon/commands/loggers/base_logger.rb
@@ -533,6 +533,7 @@ files:
533
533
  - spec/fixtures/blog/data/comments.yml
534
534
  - spec/fixtures/blog/data/posts.yml
535
535
  - spec/fixtures/cassettes/authenticate.yml
536
+ - spec/fixtures/cassettes/delete.yml
536
537
  - spec/fixtures/cassettes/push.yml
537
538
  - spec/fixtures/default/README
538
539
  - spec/fixtures/default/app/content_types/bands.yml
@@ -605,6 +606,7 @@ files:
605
606
  - spec/integration/cassettes/staging.yml
606
607
  - spec/integration/cli_spec.rb
607
608
  - spec/integration/commands/authenticate_command_spec.rb
609
+ - spec/integration/commands/delete_command_spec.rb
608
610
  - spec/integration/commands/push_command_spec.rb
609
611
  - spec/integration/generators/page_spec.rb
610
612
  - spec/integration/generators/relationship_spec.rb
@@ -661,6 +663,7 @@ test_files:
661
663
  - spec/fixtures/blog/data/comments.yml
662
664
  - spec/fixtures/blog/data/posts.yml
663
665
  - spec/fixtures/cassettes/authenticate.yml
666
+ - spec/fixtures/cassettes/delete.yml
664
667
  - spec/fixtures/cassettes/push.yml
665
668
  - spec/fixtures/default/README
666
669
  - spec/fixtures/default/app/content_types/bands.yml
@@ -733,6 +736,7 @@ test_files:
733
736
  - spec/integration/cassettes/staging.yml
734
737
  - spec/integration/cli_spec.rb
735
738
  - spec/integration/commands/authenticate_command_spec.rb
739
+ - spec/integration/commands/delete_command_spec.rb
736
740
  - spec/integration/commands/push_command_spec.rb
737
741
  - spec/integration/generators/page_spec.rb
738
742
  - spec/integration/generators/relationship_spec.rb
@@ -1,29 +0,0 @@
1
- require_relative 'concerns/api_concern'
2
- require_relative 'concerns/deploy_file_concern'
3
-
4
- module Locomotive::Wagon
5
-
6
- class DestroyCommand < Struct.new(:env, :path, :options)
7
-
8
- include ApiConcern
9
- include DeployFileConcern
10
-
11
- def self.destroy(env, path, options)
12
- self.new(env, path, options).destroy
13
- end
14
-
15
- def destroy
16
- api_client = api_site_client(connection_information)
17
-
18
- api_client.current_site.destroy
19
- end
20
-
21
- private
22
-
23
- def connection_information
24
- read_deploy_settings(self.env, self.path)
25
- end
26
-
27
- end
28
-
29
- end