contentful_bootstrap 1.6.0 → 2.0.2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -0
- data/.rubocop_todo.yml +123 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +1 -0
- data/Guardfile +5 -0
- data/README.md +40 -14
- data/Rakefile +7 -0
- data/bin/contentful_bootstrap +33 -22
- data/contentful_bootstrap.gemspec +7 -0
- data/lib/contentful/bootstrap.rb +7 -5
- data/lib/contentful/bootstrap/command_runner.rb +45 -0
- data/lib/contentful/bootstrap/commands.rb +3 -168
- data/lib/contentful/bootstrap/commands/base.rb +66 -0
- data/lib/contentful/bootstrap/commands/create_space.rb +111 -0
- data/lib/contentful/bootstrap/commands/generate_json.rb +41 -0
- data/lib/contentful/bootstrap/commands/generate_token.rb +52 -0
- data/lib/contentful/bootstrap/constants.rb +2 -2
- data/lib/contentful/bootstrap/generator.rb +94 -0
- data/lib/contentful/bootstrap/server.rb +25 -17
- data/lib/contentful/bootstrap/support.rb +3 -2
- data/lib/contentful/bootstrap/templates.rb +4 -4
- data/lib/contentful/bootstrap/templates/base.rb +51 -30
- data/lib/contentful/bootstrap/templates/blog.rb +33 -33
- data/lib/contentful/bootstrap/templates/catalogue.rb +103 -103
- data/lib/contentful/bootstrap/templates/gallery.rb +55 -56
- data/lib/contentful/bootstrap/templates/json_template.rb +22 -16
- data/lib/contentful/bootstrap/templates/links.rb +2 -2
- data/lib/contentful/bootstrap/templates/links/asset.rb +2 -2
- data/lib/contentful/bootstrap/templates/links/base.rb +3 -3
- data/lib/contentful/bootstrap/templates/links/entry.rb +2 -2
- data/lib/contentful/bootstrap/token.rb +32 -31
- data/lib/contentful/bootstrap/version.rb +1 -1
- data/spec/contentful/bootstrap/command_runner_spec.rb +111 -0
- data/spec/contentful/bootstrap/commands/base_spec.rb +102 -0
- data/spec/contentful/bootstrap/commands/create_space_spec.rb +72 -0
- data/spec/contentful/bootstrap/commands/generate_json_spec.rb +64 -0
- data/spec/contentful/bootstrap/commands/generate_token_spec.rb +82 -0
- data/spec/contentful/bootstrap/generator_spec.rb +15 -0
- data/spec/contentful/bootstrap/server_spec.rb +154 -0
- data/spec/contentful/bootstrap/support_spec.rb +27 -0
- data/spec/contentful/bootstrap/templates/base_spec.rb +34 -0
- data/spec/contentful/bootstrap/templates/blog_spec.rb +32 -0
- data/spec/contentful/bootstrap/templates/catalogue_spec.rb +40 -0
- data/spec/contentful/bootstrap/templates/gallery_spec.rb +40 -0
- data/spec/contentful/bootstrap/templates/json_template_spec.rb +52 -0
- data/spec/contentful/bootstrap/templates/links/asset_spec.rb +23 -0
- data/spec/contentful/bootstrap/templates/links/base_spec.rb +31 -0
- data/spec/contentful/bootstrap/templates/links/entry_spec.rb +23 -0
- data/spec/contentful/bootstrap/token_spec.rb +143 -0
- data/spec/fixtures/ini_fixtures/contentfulrc.ini +2 -0
- data/spec/fixtures/ini_fixtures/no_global.ini +2 -0
- data/spec/fixtures/ini_fixtures/no_token.ini +1 -0
- data/spec/fixtures/ini_fixtures/sections.ini +5 -0
- data/spec/fixtures/json_fixtures/issue_22.json +77 -0
- data/spec/fixtures/json_fixtures/simple.json +34 -0
- data/spec/fixtures/json_fixtures/wl1z0pal05vy.json +437 -0
- data/spec/fixtures/vcr_fixtures/generate_json.yml +384 -0
- data/spec/fixtures/vcr_fixtures/issue_22.yml +2488 -0
- data/spec/spec_helper.rb +51 -0
- metadata +167 -4
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'contentful/bootstrap/templates/links/entry'
|
2
|
+
require 'contentful/bootstrap/templates/links/asset'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'contentful/management'
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Bootstrap
|
@@ -11,7 +11,7 @@ module Contentful
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def link_type
|
14
|
-
self.class.name.split(
|
14
|
+
self.class.name.split('::').last
|
15
15
|
end
|
16
16
|
|
17
17
|
def type
|
@@ -25,7 +25,7 @@ module Contentful
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def management_class
|
28
|
-
|
28
|
+
fail 'must implement'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,62 +1,63 @@
|
|
1
|
-
require
|
1
|
+
require 'inifile'
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Bootstrap
|
5
5
|
class Token
|
6
|
-
CONFIG_ENV =
|
7
|
-
DEFAULT_SECTION =
|
8
|
-
DEFAULT_PATH =
|
9
|
-
MANAGEMENT_TOKEN =
|
10
|
-
DELIVERY_TOKEN =
|
11
|
-
SPACE_ID =
|
6
|
+
CONFIG_ENV = 'CONTENTFUL_ENV'.freeze
|
7
|
+
DEFAULT_SECTION = 'global'.freeze
|
8
|
+
DEFAULT_PATH = '.contentfulrc'.freeze
|
9
|
+
MANAGEMENT_TOKEN = 'CONTENTFUL_MANAGEMENT_ACCESS_TOKEN'.freeze
|
10
|
+
DELIVERY_TOKEN = 'CONTENTFUL_DELIVERY_ACCESS_TOKEN'.freeze
|
11
|
+
SPACE_ID = 'SPACE_ID'.freeze
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
attr_reader :config_path
|
14
|
+
|
15
|
+
def initialize(config_path = '')
|
16
|
+
@config_path = config_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other_token)
|
20
|
+
return false unless other_token.is_a?(Contentful::Bootstrap::Token)
|
21
|
+
other_token.config_path == @config_path
|
15
22
|
end
|
16
23
|
|
17
|
-
def
|
18
|
-
return false unless File.
|
19
|
-
config_file[config_section].
|
24
|
+
def present?
|
25
|
+
return false unless ::File.exist? filename
|
26
|
+
config_file[config_section].key? MANAGEMENT_TOKEN
|
20
27
|
end
|
21
28
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
fail "Token not found"
|
27
|
-
end
|
29
|
+
def read
|
30
|
+
config_file[config_section].fetch(MANAGEMENT_TOKEN)
|
31
|
+
rescue KeyError
|
32
|
+
raise 'Token not found'
|
28
33
|
end
|
29
34
|
|
30
|
-
def
|
35
|
+
def write(value, section = nil, key = MANAGEMENT_TOKEN)
|
31
36
|
file = config_file
|
32
37
|
file[section || config_section][key] = value
|
33
38
|
file.save
|
34
39
|
end
|
35
40
|
|
36
|
-
def
|
41
|
+
def write_access_token(space_name, token)
|
37
42
|
write(token, space_name, DELIVERY_TOKEN)
|
38
43
|
end
|
39
44
|
|
40
|
-
def
|
45
|
+
def write_space_id(space_name, space_id)
|
41
46
|
write(space_id, space_name, SPACE_ID)
|
42
47
|
end
|
43
48
|
|
44
|
-
def
|
45
|
-
return config_path
|
46
|
-
File.join(ENV['HOME'], DEFAULT_PATH)
|
49
|
+
def filename
|
50
|
+
return config_path unless config_path.empty?
|
51
|
+
::File.join(ENV['HOME'], DEFAULT_PATH)
|
47
52
|
end
|
48
53
|
|
49
|
-
def
|
54
|
+
def config_section
|
50
55
|
return ENV[CONFIG_ENV] if config_file.has_section? ENV[CONFIG_ENV]
|
51
56
|
DEFAULT_SECTION
|
52
57
|
end
|
53
58
|
|
54
|
-
def
|
55
|
-
File.exist?(filename) ? IniFile.load(filename) : IniFile.new(filename: filename)
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.config_path
|
59
|
-
@@config_path ||= ""
|
59
|
+
def config_file
|
60
|
+
@file ||= ::File.exist?(filename) ? IniFile.load(filename) : IniFile.new(filename: filename)
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contentful::Bootstrap::CommandRunner do
|
4
|
+
let(:path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'contentfulrc.ini')) }
|
5
|
+
subject { Contentful::Bootstrap::CommandRunner.new(path) }
|
6
|
+
|
7
|
+
describe 'instance methods' do
|
8
|
+
before do
|
9
|
+
end
|
10
|
+
describe '#create_space' do
|
11
|
+
before do
|
12
|
+
allow_any_instance_of(Contentful::Bootstrap::Commands::CreateSpace).to receive(:run)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'default values' do
|
16
|
+
expect(Contentful::Bootstrap::Commands::CreateSpace).to receive(:new).with(
|
17
|
+
subject.token, 'foo', nil, nil, true
|
18
|
+
).and_call_original
|
19
|
+
|
20
|
+
subject.create_space('foo')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'with options' do
|
24
|
+
expect(Contentful::Bootstrap::Commands::CreateSpace).to receive(:new).with(
|
25
|
+
subject.token, 'foo', 'bar', 'baz', false
|
26
|
+
).and_call_original
|
27
|
+
|
28
|
+
subject.create_space('foo', template: 'bar', json_template: 'baz', trigger_oauth: false)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'runs command' do
|
32
|
+
expect_any_instance_of(Contentful::Bootstrap::Commands::CreateSpace).to receive(:run)
|
33
|
+
|
34
|
+
subject.create_space('foo', template: 'bar', json_template: 'baz', trigger_oauth: false)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#generate_token' do
|
39
|
+
before do
|
40
|
+
allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:run)
|
41
|
+
allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:fetch_space)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'default values' do
|
45
|
+
expect(Contentful::Bootstrap::Commands::GenerateToken).to receive(:new).with(
|
46
|
+
subject.token, 'foo', 'Bootstrap Token', true
|
47
|
+
).and_call_original
|
48
|
+
|
49
|
+
subject.generate_token('foo')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'with options' do
|
53
|
+
expect(Contentful::Bootstrap::Commands::GenerateToken).to receive(:new).with(
|
54
|
+
subject.token, 'foo', 'bar', false
|
55
|
+
).and_call_original
|
56
|
+
|
57
|
+
subject.generate_token('foo', name: 'bar', trigger_oauth: false)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'runs command' do
|
61
|
+
expect_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:run)
|
62
|
+
|
63
|
+
subject.generate_token('foo', name: 'bar', trigger_oauth: false)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#generate_json' do
|
68
|
+
it 'requires access token to run' do
|
69
|
+
expect {
|
70
|
+
subject.generate_json('foo')
|
71
|
+
}.to raise_error('Access Token required')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'default values' do
|
75
|
+
allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateJson).to receive(:run)
|
76
|
+
|
77
|
+
expect(Contentful::Bootstrap::Commands::GenerateJson).to receive(:new).with(
|
78
|
+
'foo', 'bar', nil
|
79
|
+
).and_call_original
|
80
|
+
|
81
|
+
subject.generate_json('foo', access_token: 'bar')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'with options' do
|
85
|
+
allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateJson).to receive(:run)
|
86
|
+
|
87
|
+
expect(Contentful::Bootstrap::Commands::GenerateJson).to receive(:new).with(
|
88
|
+
'foo', 'bar', 'baz'
|
89
|
+
).and_call_original
|
90
|
+
|
91
|
+
subject.generate_json('foo', access_token: 'bar', filename: 'baz')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'runs command' do
|
95
|
+
expect_any_instance_of(Contentful::Bootstrap::Commands::GenerateJson).to receive(:run)
|
96
|
+
|
97
|
+
subject.generate_json('foo', access_token: 'bar', filename: 'baz')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'attributes' do
|
103
|
+
it ':config_path' do
|
104
|
+
expect(subject.config_path).to eq path
|
105
|
+
end
|
106
|
+
|
107
|
+
it ':token' do
|
108
|
+
expect(subject.token == Contentful::Bootstrap::Token.new(path)).to be_truthy
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'net/http'
|
3
|
+
require 'contentful/bootstrap/commands/base'
|
4
|
+
|
5
|
+
describe Contentful::Bootstrap::Commands::Base do
|
6
|
+
let(:path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'contentfulrc.ini')) }
|
7
|
+
let(:no_token_path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'no_token.ini')) }
|
8
|
+
let(:token) { Contentful::Bootstrap::Token.new path }
|
9
|
+
let(:non_management_token) { Contentful::Bootstrap::Token.new no_token_path }
|
10
|
+
subject { Contentful::Bootstrap::Commands::Base.new token, 'foo', false }
|
11
|
+
|
12
|
+
describe 'abstract methods' do
|
13
|
+
it '#run' do
|
14
|
+
expect { subject.run }.to raise_error 'must implement'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'initialize' do
|
19
|
+
describe 'configuration' do
|
20
|
+
it 'runs configuration when trigger_oauth is true' do
|
21
|
+
expect_any_instance_of(subject.class).to receive(:configuration)
|
22
|
+
subject.class.new(token, 'foo')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'doesnt run configuration when trigger_oauth is false' do
|
26
|
+
expect_any_instance_of(subject.class).not_to receive(:configuration)
|
27
|
+
subject.class.new(token, 'foo', false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'management_client_init' do
|
32
|
+
it 'runs management_client_init when trigger_oauth is true' do
|
33
|
+
expect_any_instance_of(subject.class).to receive(:management_client_init)
|
34
|
+
subject.class.new(token, 'foo')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'doesnt run management_client_init when trigger_oauth is false' do
|
38
|
+
expect_any_instance_of(subject.class).not_to receive(:management_client_init)
|
39
|
+
subject.class.new(token, 'foo', false)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'instance methods' do
|
45
|
+
it '#management_client_init' do
|
46
|
+
allow_any_instance_of(subject.class).to receive(:configuration)
|
47
|
+
expect(Contentful::Management::Client).to receive(:new).with(token.read, raise_errors: true)
|
48
|
+
|
49
|
+
subject.class.new(token, 'foo')
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#configuration' do
|
53
|
+
before do
|
54
|
+
allow_any_instance_of(subject.class).to receive(:management_client_init)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'passes if token is found' do
|
58
|
+
expect { subject.class.new(token, 'foo') }.to output("OAuth token found, moving on!\n").to_stdout
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'token not found' do
|
62
|
+
it 'exits if answer is no' do
|
63
|
+
expect_any_instance_of(subject.class).to receive(:gets) { "n\n" }
|
64
|
+
expect { subject.class.new(non_management_token, 'foo') }.to raise_error SystemExit
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'runs token_server if other answer' do
|
68
|
+
expect_any_instance_of(subject.class).to receive(:gets) { "y\n" }
|
69
|
+
expect_any_instance_of(subject.class).to receive(:token_server)
|
70
|
+
|
71
|
+
subject.class.new(non_management_token, 'foo')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it '#token_server' do
|
77
|
+
allow_any_instance_of(subject.class).to receive(:management_client_init)
|
78
|
+
|
79
|
+
expect_any_instance_of(subject.class).to receive(:gets) { "y\n" }
|
80
|
+
expect_any_instance_of(Contentful::Bootstrap::Server).to receive(:start) {}
|
81
|
+
expect_any_instance_of(Contentful::Bootstrap::Server).to receive(:running?) { true }
|
82
|
+
expect(Net::HTTP).to receive(:get).with(URI('http://localhost:5123')) {}
|
83
|
+
expect(non_management_token).to receive(:present?).and_return(false, true)
|
84
|
+
expect_any_instance_of(Contentful::Bootstrap::Server).to receive(:stop) {}
|
85
|
+
|
86
|
+
subject.class.new(non_management_token, 'foo')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'attributes' do
|
91
|
+
it ':space' do
|
92
|
+
expect(subject.space).to eq 'foo'
|
93
|
+
end
|
94
|
+
|
95
|
+
it ':token' do
|
96
|
+
expect(subject.token == Contentful::Bootstrap::Token.new(path)).to be_truthy
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#initialize' do
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contentful::Bootstrap::Commands::CreateSpace do
|
4
|
+
let(:path) { File.expand_path(File.join('spec', 'fixtures', 'ini_fixtures', 'contentfulrc.ini')) }
|
5
|
+
let(:token) { Contentful::Bootstrap::Token.new path }
|
6
|
+
subject { Contentful::Bootstrap::Commands::CreateSpace.new token, 'foo', 'bar', 'baz', false }
|
7
|
+
let(:space_double) { SpaceDouble.new }
|
8
|
+
|
9
|
+
describe 'instance methods' do
|
10
|
+
describe '#run' do
|
11
|
+
it 'with all non nil attributes' do
|
12
|
+
expect(subject).to receive(:fetch_space) { space_double }
|
13
|
+
expect(subject).to receive(:create_template).with(space_double)
|
14
|
+
expect(subject).to receive(:create_json_template).with(space_double)
|
15
|
+
expect(subject).to receive(:generate_token).with(space_double)
|
16
|
+
|
17
|
+
subject.run
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not create template when template_name is nil' do
|
21
|
+
create_space_command = subject.class.new(token, 'foo', nil, 'baz', false)
|
22
|
+
|
23
|
+
expect(create_space_command.template_name).to eq nil
|
24
|
+
|
25
|
+
expect(create_space_command).to receive(:fetch_space) { space_double }
|
26
|
+
expect(create_space_command).not_to receive(:create_template).with(space_double)
|
27
|
+
expect(create_space_command).to receive(:create_json_template).with(space_double)
|
28
|
+
expect(create_space_command).to receive(:generate_token).with(space_double)
|
29
|
+
|
30
|
+
create_space_command.run
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not create json template when json_template is nil' do
|
34
|
+
create_space_command = subject.class.new(token, 'foo', 'bar', nil, false)
|
35
|
+
|
36
|
+
expect(create_space_command.json_template).to eq nil
|
37
|
+
|
38
|
+
expect(create_space_command).to receive(:fetch_space) { space_double }
|
39
|
+
expect(create_space_command).to receive(:create_template).with(space_double)
|
40
|
+
expect(create_space_command).not_to receive(:create_json_template).with(space_double)
|
41
|
+
expect(create_space_command).to receive(:generate_token).with(space_double)
|
42
|
+
|
43
|
+
create_space_command.run
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'attributes' do
|
49
|
+
it ':template_name' do
|
50
|
+
expect(subject.template_name).to eq 'bar'
|
51
|
+
end
|
52
|
+
|
53
|
+
it ':json_template' do
|
54
|
+
expect(subject.json_template).to eq 'baz'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'issues' do
|
59
|
+
it 'Importing asset array values does not work #22' do
|
60
|
+
json_path = File.expand_path(File.join('spec', 'fixtures', 'json_fixtures', 'issue_22.json'))
|
61
|
+
|
62
|
+
allow_any_instance_of(subject.class).to receive(:gets).and_return('y')
|
63
|
+
allow_any_instance_of(Contentful::Bootstrap::Commands::GenerateToken).to receive(:gets).and_return('n')
|
64
|
+
|
65
|
+
command = subject.class.new(token, 'issue_22', nil, json_path)
|
66
|
+
|
67
|
+
vcr('issue_22') {
|
68
|
+
command.run
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contentful::Bootstrap::Commands::GenerateJson do
|
4
|
+
subject { Contentful::Bootstrap::Commands::GenerateJson.new('foo', 'bar') }
|
5
|
+
|
6
|
+
describe 'instance methods' do
|
7
|
+
describe '#run' do
|
8
|
+
it 'exits if access_token is nil' do
|
9
|
+
subject.instance_variable_set(:@access_token, nil)
|
10
|
+
|
11
|
+
expect { subject.run }.to raise_error SystemExit
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'calls generator' do
|
15
|
+
allow(subject).to receive(:write).with('json')
|
16
|
+
|
17
|
+
expect_any_instance_of(Contentful::Bootstrap::Generator).to receive(:generate_json) { 'json' }
|
18
|
+
|
19
|
+
subject.run
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'writes json' do
|
23
|
+
vcr('generate_json') {
|
24
|
+
subject.instance_variable_set(:@space_id, 'wl1z0pal05vy')
|
25
|
+
subject.instance_variable_set(:@access_token, '48d7db7d4cd9d09df573c251d456f4acc72141b92f36e57f8684b36cf5cfff6e')
|
26
|
+
|
27
|
+
json_fixture('wl1z0pal05vy') { |json|
|
28
|
+
expect(subject).to receive(:write).with(JSON.pretty_generate(json))
|
29
|
+
}
|
30
|
+
|
31
|
+
subject.run
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#write' do
|
37
|
+
it 'outputs json to stoud if no filename provided' do
|
38
|
+
expect { subject.write('json') }.to output("json\n").to_stdout
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'writes to file if filename provided' do
|
42
|
+
subject.instance_variable_set(:@filename, 'foo')
|
43
|
+
|
44
|
+
expect(::File).to receive(:write).with('foo', 'json')
|
45
|
+
|
46
|
+
expect { subject.write('json') }.to output("Saving JSON template to 'foo'\n").to_stdout
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'attributes' do
|
52
|
+
it ':space_id' do
|
53
|
+
expect(subject.space_id).to eq 'foo'
|
54
|
+
end
|
55
|
+
|
56
|
+
it ':access_token' do
|
57
|
+
expect(subject.access_token).to eq 'bar'
|
58
|
+
end
|
59
|
+
|
60
|
+
it ':filename' do
|
61
|
+
expect(subject.filename).to eq nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|