contentful_bootstrap 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Contentful::Bootstrap::Commands::CreateSpace do
4
4
  let(:path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'contentfulrc.ini')) }
5
5
  let(:token) { Contentful::Bootstrap::Token.new path }
6
- subject { Contentful::Bootstrap::Commands::CreateSpace.new token, 'foo', 'bar', 'baz', false, false }
6
+ subject { described_class.new token, 'foo', template: 'bar', json_template: 'baz', trigger_oauth: false, quiet: true }
7
7
  let(:space_double) { SpaceDouble.new }
8
8
 
9
9
  before do
@@ -22,7 +22,7 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
22
22
  end
23
23
 
24
24
  it 'does not create template when template_name is nil' do
25
- create_space_command = described_class.new(token, 'foo', nil, 'baz', false, false)
25
+ create_space_command = described_class.new(token, 'foo', json_template: 'baz', trigger_oauth: false, quiet: true)
26
26
 
27
27
  expect(create_space_command.template_name).to eq nil
28
28
 
@@ -35,7 +35,7 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
35
35
  end
36
36
 
37
37
  it 'does not create json template when json_template is nil' do
38
- create_space_command = described_class.new(token, 'foo', 'bar', nil, false, false)
38
+ create_space_command = described_class.new(token, 'foo', template: 'bar', trigger_oauth: false, quiet: true)
39
39
 
40
40
  expect(create_space_command.json_template).to eq nil
41
41
 
@@ -63,10 +63,10 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
63
63
  it 'Importing asset array values does not work #22' do
64
64
  json_path = File.expand_path(File.join('spec', 'fixtures', 'json_fixtures', 'issue_22.json'))
65
65
 
66
- allow_any_instance_of(described_class).to receive(:gets).and_return('y')
67
- allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:gets).and_return('n')
66
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('y')
67
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('n')
68
68
 
69
- command = described_class.new(token, 'issue_22', nil, json_path, false)
69
+ command = described_class.new(token, 'issue_22', json_template: json_path, quiet: true)
70
70
 
71
71
  vcr('issue_22') {
72
72
  command.run
@@ -76,10 +76,10 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
76
76
  it 'assets can be created with any content type #39' do
77
77
  json_path = File.expand_path(File.join('spec', 'fixtures', 'json_fixtures', 'asset_no_transform.json'))
78
78
 
79
- allow_any_instance_of(described_class).to receive(:gets).and_return('y')
80
- allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:gets).and_return('n')
79
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('y')
80
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('n')
81
81
 
82
- command = described_class.new(token, 'asset_no_transform', nil, json_path, false)
82
+ command = described_class.new(token, 'asset_no_transform', json_template: json_path, mark_processed: false, quiet: true)
83
83
 
84
84
  vcr('asset_no_transform') {
85
85
  command.run
@@ -89,12 +89,12 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
89
89
 
90
90
  describe 'integration' do
91
91
  before do
92
- allow_any_instance_of(described_class).to receive(:gets).and_return('y')
93
- allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:gets).and_return('n')
92
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('y')
93
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('n')
94
94
  end
95
95
 
96
96
  it 'create space' do
97
- command = described_class.new token, 'some_space'
97
+ command = described_class.new token, 'some_space', quiet: true
98
98
 
99
99
  vcr('create_space') {
100
100
  command.run
@@ -102,7 +102,7 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
102
102
  end
103
103
 
104
104
  it 'create space with blog template' do
105
- command = described_class.new token, 'blog_space', 'blog'
105
+ command = described_class.new token, 'blog_space', template: 'blog', quiet: true
106
106
 
107
107
  vcr('create_space_with_blog_template') {
108
108
  command.run
@@ -110,7 +110,7 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
110
110
  end
111
111
 
112
112
  it 'create space with gallery template' do
113
- command = described_class.new token, 'gallery_space', 'gallery'
113
+ command = described_class.new token, 'gallery_space', template: 'gallery', quiet: true
114
114
 
115
115
  vcr('create_space_with_gallery_template') {
116
116
  command.run
@@ -118,7 +118,7 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
118
118
  end
119
119
 
120
120
  it 'create space with catalogue template' do
121
- command = described_class.new token, 'catalogue_space', 'catalogue'
121
+ command = described_class.new token, 'catalogue_space', template: 'catalogue', quiet: true
122
122
 
123
123
  vcr('create_space_with_catalogue_template') {
124
124
  command.run
@@ -131,7 +131,7 @@ describe Contentful::Bootstrap::Commands::CreateSpace do
131
131
 
132
132
  it 'create space with json template with no ids' do
133
133
  json_path = File.expand_path(File.join('spec', 'fixtures', 'json_fixtures', 'no_ids.json'))
134
- command = described_class.new token, 'no_ids_space', nil, json_path
134
+ command = described_class.new token, 'no_ids_space', json_template: json_path, quiet: true
135
135
 
136
136
  vcr('no_ids') {
137
137
  command.run
@@ -18,7 +18,7 @@ end
18
18
  describe Contentful::Bootstrap::Commands::GenerateToken do
19
19
  let(:path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'contentfulrc.ini')) }
20
20
  let(:token) { Contentful::Bootstrap::Token.new path }
21
- subject { Contentful::Bootstrap::Commands::GenerateToken.new token, 'foo', 'bar', false }
21
+ subject { described_class.new token, 'foo', token_name: 'bar', trigger_oauth: false, quiet: true }
22
22
  let(:space_double) { SpaceDouble.new }
23
23
 
24
24
  describe 'instance methods' do
@@ -28,45 +28,42 @@ describe Contentful::Bootstrap::Commands::GenerateToken do
28
28
 
29
29
  describe '#run' do
30
30
  it 'fetches space from api if space is a string' do
31
- allow(subject).to receive(:gets) { 'n' }
32
- allow_any_instance_of(Contentful::Management::Request).to receive(:post) { ResponseDouble.new }
33
- expect(Contentful::Management::Space).to receive(:find).with('foo') { space_double }
31
+ allow(Contentful::Bootstrap::Support).to receive(:gets) { 'n' }
32
+ expect_any_instance_of(Contentful::Management::ClientSpaceMethodsFactory).to receive(:find).with('foo') { space_double }
34
33
 
35
34
  subject.run
36
35
  end
37
36
 
38
37
  it 'uses space if space is not a string' do
39
- allow(subject).to receive(:gets) { 'n' }
40
- allow_any_instance_of(Contentful::Management::Request).to receive(:post) { ResponseDouble.new }
41
- expect(Contentful::Management::Space).not_to receive(:find).with('foo') { space_double }
42
-
43
- subject.instance_variable_set(:@actual_space, space_double)
38
+ allow(Contentful::Bootstrap::Support).to receive(:gets) { 'n' }
39
+ expect_any_instance_of(Contentful::Management::ClientSpaceMethodsFactory).not_to receive(:find).with('foo') { space_double }
40
+ subject.instance_variable_set(:@space, space_double)
44
41
 
45
42
  subject.run
46
43
  end
47
44
 
48
45
  it 'returns access token' do
49
- allow(subject).to receive(:gets) { 'n' }
50
- allow_any_instance_of(Contentful::Management::Request).to receive(:post) { ResponseDouble.new }
51
- allow(Contentful::Management::Space).to receive(:find).with('foo') { space_double }
46
+ allow(Contentful::Bootstrap::Support).to receive(:gets) { 'n' }
47
+ allow_any_instance_of(Contentful::Management::ClientSpaceMethodsFactory).to receive(:find).with('foo') { space_double }
48
+ expect(space_double).to receive(:api_keys).and_call_original
52
49
 
53
- expect(subject.run).to eq 'foo'
50
+ expect(subject.run).to eq 'random_api_key'
54
51
  end
55
52
 
56
53
  it 'fails if API returns an error' do
57
- allow(subject).to receive(:gets) { 'n' }
58
- allow_any_instance_of(Contentful::Management::Request).to receive(:post) { ErrorDouble.new }
59
- allow(Contentful::Management::Space).to receive(:find).with('foo') { space_double }
54
+ allow(Contentful::Bootstrap::Support).to receive(:gets) { 'n' }
55
+ allow_any_instance_of(Contentful::Management::ClientSpaceMethodsFactory).to receive(:find).with('foo') { space_double }
56
+ expect(space_double).to receive(:api_keys).and_raise(ErrorDouble.new)
60
57
 
61
58
  expect { subject.run }.to raise_error ErrorDouble
62
59
  end
63
60
 
64
61
  it 'token gets written if user input is other than no' do
65
- allow(subject).to receive(:gets) { 'y' }
66
- allow_any_instance_of(Contentful::Management::Request).to receive(:post) { ResponseDouble.new }
67
- allow(Contentful::Management::Space).to receive(:find).with('foo') { space_double }
62
+ allow(Contentful::Bootstrap::Support).to receive(:gets) { 'y' }
63
+ allow_any_instance_of(Contentful::Management::ClientSpaceMethodsFactory).to receive(:find).with('foo') { space_double }
64
+ expect(space_double).to receive(:api_keys).and_call_original
68
65
 
69
- expect(token).to receive(:write_access_token).with('foobar', 'foo')
66
+ expect(token).to receive(:write_access_token).with('foobar', 'random_api_key')
70
67
  expect(token).to receive(:write_space_id).with('foobar', 'foobar')
71
68
 
72
69
  subject.run
@@ -82,11 +79,11 @@ describe Contentful::Bootstrap::Commands::GenerateToken do
82
79
 
83
80
  describe 'integration' do
84
81
  before do
85
- allow_any_instance_of(subject.class).to receive(:gets).and_return('n')
82
+ allow(Contentful::Bootstrap::Support).to receive(:gets).and_return('n')
86
83
  end
87
84
 
88
85
  it 'generates a token for a given space' do
89
- command = subject.class.new token, 'zred3m25k5em', 'foo'
86
+ command = described_class.new token, 'zred3m25k5em', token_name: 'foo', quiet: true
90
87
 
91
88
  vcr('generate_token') {
92
89
  command.run
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Contentful::Bootstrap::Commands::UpdateSpace do
4
4
  let(:path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'contentfulrc.ini')) }
5
5
  let(:token) { Contentful::Bootstrap::Token.new path }
6
- subject { Contentful::Bootstrap::Commands::UpdateSpace.new token, 'foo', 'bar', false, false }
6
+ subject { described_class.new token, 'foo', json_template: 'bar', mark_processed: false, trigger_oauth: false, quiet: true }
7
7
  let(:space_double) { SpaceDouble.new }
8
8
 
9
9
  before do
@@ -20,15 +20,15 @@ describe Contentful::Bootstrap::Commands::UpdateSpace do
20
20
  end
21
21
 
22
22
  it 'exits if JSON not sent' do
23
- update_space_command = described_class.new(token, 'foo', nil, false)
23
+ update_space_command = described_class.new(token, 'foo', mark_processed: false, quiet: true)
24
24
 
25
25
  expect { update_space_command.run }.to raise_error SystemExit
26
26
  end
27
27
 
28
28
  it 'exits if space is not found' do
29
- update_space_command = described_class.new(token, 'foo', 'bar', false)
29
+ update_space_command = described_class.new(token, 'foo', json_template: 'bar', quiet: true)
30
30
 
31
- expect(::Contentful::Management::Space).to receive(:find).with('foo').and_raise(::Contentful::Management::NotFound.new(ErrorRequestDouble.new))
31
+ expect_any_instance_of(::Contentful::Management::ClientSpaceMethodsFactory).to receive(:find).with('foo').and_raise(::Contentful::Management::NotFound.new(ErrorRequestDouble.new))
32
32
 
33
33
  expect { update_space_command.run }.to raise_error SystemExit
34
34
  end
@@ -42,7 +42,7 @@ describe Contentful::Bootstrap::Commands::UpdateSpace do
42
42
  describe 'runs JSON Template without already processed elements' do
43
43
  [true, false].each do |mark_processed|
44
44
  context "mark_processed is #{mark_processed}" do
45
- subject { described_class.new token, 'foo', 'bar', mark_processed, false }
45
+ subject { described_class.new token, 'foo', json_template: 'bar', mark_processed: mark_processed, trigger_oauth: false, quiet: true}
46
46
 
47
47
  it "calls JsonTemplate with mark_processed as #{mark_processed}" do
48
48
  allow(::File).to receive(:exist?) { true }
@@ -61,7 +61,7 @@ describe Contentful::Bootstrap::Commands::UpdateSpace do
61
61
  end
62
62
 
63
63
  context 'with skip_content_types set to true' do
64
- subject { described_class.new token, 'foo', 'bar', false, false, true }
64
+ subject { described_class.new token, 'foo', json_template: 'bar', trigger_oauth: false, skip_content_types: true, quiet: true }
65
65
 
66
66
  it 'calls JsonTemplate with skip_content_types' do
67
67
  allow(::File).to receive(:exist?) { true }
@@ -1,14 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class Double
4
- include Contentful::Bootstrap::Support
5
-
6
4
  def write
7
5
  $stderr.write('foo\n')
8
6
  end
9
7
 
10
8
  def muted_write
11
- silence_stderr do
9
+ Contentful::Bootstrap::Support.silence_stderr do
12
10
  write
13
11
  end
14
12
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Contentful::Bootstrap::Templates::Base do
4
4
  let(:space) { Contentful::Management::Space.new }
5
- subject { described_class.new(space) }
5
+ subject { described_class.new(space, true) }
6
6
 
7
7
  describe 'instance methods' do
8
8
  it '#content_types' do
@@ -33,7 +33,7 @@ describe Contentful::Bootstrap::Templates::Base do
33
33
  end
34
34
 
35
35
  context 'with skip_content_types set to true' do
36
- subject { described_class.new(space, true) }
36
+ subject { described_class.new(space, true, true) }
37
37
 
38
38
  it 'doesnt call create_content_type if skip_content_types is sent' do
39
39
  expect(subject).to receive(:create_entries)
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Contentful::Bootstrap::Templates::JsonTemplate do
4
4
  let(:space) { Contentful::Management::Space.new }
5
5
  let(:path) { json_path('simple') }
6
- subject { described_class.new space, path }
6
+ subject { described_class.new space, path, false, true, true }
7
7
 
8
8
  before do
9
9
  allow(::File).to receive(:write)
@@ -35,7 +35,7 @@ describe Contentful::Bootstrap::Templates::JsonTemplate do
35
35
  end
36
36
 
37
37
  it 'uses display_field if not' do
38
- subject = described_class.new(space, File.expand_path(File.join('spec', 'fixtures', 'json_fixtures', 'display_field.json')))
38
+ subject = described_class.new(space, File.expand_path(File.join('spec', 'fixtures', 'json_fixtures', 'display_field.json')), false, true, true)
39
39
 
40
40
  expect(subject.content_types.first['displayField']).to eq 'name'
41
41
  end
@@ -91,6 +91,7 @@ describe Contentful::Bootstrap::Templates::JsonTemplate do
91
91
 
92
92
  describe 'issues' do
93
93
  let(:link_entry_path) { json_path('links') }
94
+ let(:object_entry_path) { json_path('object') }
94
95
 
95
96
  it 'links are not properly getting processed - #33' do
96
97
  subject = described_class.new space, link_entry_path
@@ -102,6 +103,20 @@ describe Contentful::Bootstrap::Templates::JsonTemplate do
102
103
  }
103
104
  )
104
105
  end
106
+
107
+ it 'allows templates with object fields to work - #51' do
108
+ subject = described_class.new space, object_entry_path
109
+ expect(subject.entries['test'].first).to eq(
110
+ {
111
+ "id" => "foo",
112
+ "name" => "test",
113
+ "object" => {
114
+ "foo" => "bar",
115
+ "baz" => "qux"
116
+ }
117
+ }
118
+ )
119
+ end
105
120
  end
106
121
 
107
122
  describe 'bootstrap processed' do
@@ -171,7 +186,7 @@ describe Contentful::Bootstrap::Templates::JsonTemplate do
171
186
 
172
187
  describe 'skip_content_types' do
173
188
  context 'with skip_content_types set to true' do
174
- subject { described_class.new(space, path, false, false, true) }
189
+ subject { described_class.new(space, path, false, false, true, true) }
175
190
 
176
191
  it 'skips content type creation' do
177
192
  ['assets', 'entries'].each do |n|
@@ -187,7 +202,7 @@ describe Contentful::Bootstrap::Templates::JsonTemplate do
187
202
  end
188
203
 
189
204
  context 'with skip_content_types set to false' do
190
- subject { described_class.new(space, path, false, false, false) }
205
+ subject { described_class.new(space, path, false, false, true, false) }
191
206
 
192
207
  it 'doesnt skip content type creation' do
193
208
  ['assets', 'entries', 'content_types'].each do |n|
@@ -0,0 +1,38 @@
1
+ {
2
+ "version": 3,
3
+ "contentTypes": [
4
+ {
5
+ "id": "test",
6
+ "name": "Test",
7
+ "displayField": "name",
8
+ "fields": [
9
+ {
10
+ "id": "name",
11
+ "name": "Name",
12
+ "type": "Symbol"
13
+ },
14
+ {
15
+ "id": "object",
16
+ "name": "Object",
17
+ "type": "Object"
18
+ }
19
+ ]
20
+ }
21
+ ],
22
+ "assets": [],
23
+ "entries": {
24
+ "test": [
25
+ {
26
+ "sys": { "id": "foo" },
27
+ "fields": {
28
+ "name": "test",
29
+ "object": {
30
+ "foo": "bar",
31
+ "baz": "qux"
32
+ }
33
+ }
34
+ }
35
+ ]
36
+ }
37
+ }
38
+
data/spec/spec_helper.rb CHANGED
@@ -36,6 +36,22 @@ def ini(ini_file)
36
36
  file
37
37
  end
38
38
 
39
+ class ApiKeyDouble
40
+ attr_reader :name, :description, :access_token
41
+
42
+ def initialize(name, description)
43
+ @name = name
44
+ @description = description
45
+ @access_token = 'random_api_key'
46
+ end
47
+ end
48
+
49
+ class ApiKeysHandlerDouble
50
+ def create(options)
51
+ ApiKeyDouble.new(options[:name], options[:description])
52
+ end
53
+ end
54
+
39
55
  class SpaceDouble
40
56
  def id
41
57
  'foobar'
@@ -44,6 +60,10 @@ class SpaceDouble
44
60
  def name
45
61
  'foobar'
46
62
  end
63
+
64
+ def api_keys
65
+ ApiKeysHandlerDouble.new
66
+ end
47
67
  end
48
68
 
49
69
  class ServerDouble
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Litvak Bruno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-22 00:00:00.000000000 Z
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,28 +170,34 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.9'
173
+ version: '1.0'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0.9'
180
+ version: '1.0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: contentful
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - "~>"
185
+ - - ">"
186
186
  - !ruby/object:Gem::Version
187
- version: '0.7'
187
+ version: '0'
188
+ - - "<"
189
+ - !ruby/object:Gem::Version
190
+ version: '3'
188
191
  type: :runtime
189
192
  prerelease: false
190
193
  version_requirements: !ruby/object:Gem::Requirement
191
194
  requirements:
192
- - - "~>"
195
+ - - ">"
193
196
  - !ruby/object:Gem::Version
194
- version: '0.7'
197
+ version: '0'
198
+ - - "<"
199
+ - !ruby/object:Gem::Version
200
+ version: '3'
195
201
  - !ruby/object:Gem::Dependency
196
202
  name: inifile
197
203
  requirement: !ruby/object:Gem::Requirement
@@ -285,6 +291,7 @@ files:
285
291
  - spec/fixtures/json_fixtures/links.json
286
292
  - spec/fixtures/json_fixtures/low.json
287
293
  - spec/fixtures/json_fixtures/no_ids.json
294
+ - spec/fixtures/json_fixtures/object.json
288
295
  - spec/fixtures/json_fixtures/ok_version.json
289
296
  - spec/fixtures/json_fixtures/processed.json
290
297
  - spec/fixtures/json_fixtures/simple.json
@@ -321,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
328
  version: '0'
322
329
  requirements: []
323
330
  rubyforge_project:
324
- rubygems_version: 2.5.1
331
+ rubygems_version: 2.6.10
325
332
  signing_key:
326
333
  specification_version: 4
327
334
  summary: Contentful CLI tool for getting started with Contentful
@@ -358,6 +365,7 @@ test_files:
358
365
  - spec/fixtures/json_fixtures/links.json
359
366
  - spec/fixtures/json_fixtures/low.json
360
367
  - spec/fixtures/json_fixtures/no_ids.json
368
+ - spec/fixtures/json_fixtures/object.json
361
369
  - spec/fixtures/json_fixtures/ok_version.json
362
370
  - spec/fixtures/json_fixtures/processed.json
363
371
  - spec/fixtures/json_fixtures/simple.json