zenflow 0.8.11 → 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.markdown +8 -0
- data/VERSION.yml +1 -1
- data/lib/zenflow.rb +1 -1
- data/lib/zenflow/cli.rb +6 -31
- data/lib/zenflow/commands/admin.rb +88 -0
- data/lib/zenflow/helpers/github.rb +96 -53
- data/lib/zenflow/helpers/repo.rb +0 -9
- data/spec/zenflow/{helpers/cli_spec.rb → cli_spec.rb} +20 -93
- data/spec/zenflow/commands/admin_spec.rb +202 -0
- data/spec/zenflow/helpers/github_spec.rb +332 -112
- data/spec/zenflow/helpers/repo_spec.rb +0 -56
- metadata +5 -5
- data/lib/zenflow/commands/hubs.rb +0 -124
- data/spec/zenflow/commands/hubs_spec.rb +0 -372
@@ -19,88 +19,6 @@ describe Zenflow::CLI do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "#set_up_github" do
|
23
|
-
context "when a github user is already saved" do
|
24
|
-
before do
|
25
|
-
Zenflow::Github.should_receive(:user).and_return('user')
|
26
|
-
end
|
27
|
-
|
28
|
-
context "and the user decides to set a new one" do
|
29
|
-
before do
|
30
|
-
Zenflow.should_receive(:Ask).and_return('n')
|
31
|
-
end
|
32
|
-
|
33
|
-
it "authorizes with Github" do
|
34
|
-
Zenflow::Github.should_receive(:set_user)
|
35
|
-
subject.set_up_github
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "and the user decides not to set a new one" do
|
40
|
-
before do
|
41
|
-
Zenflow.should_receive(:Ask).and_return('y')
|
42
|
-
end
|
43
|
-
|
44
|
-
it "does not authorize with Github" do
|
45
|
-
Zenflow::Github.should_not_receive(:set_user)
|
46
|
-
subject.set_up_github
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when a zenflow_token is not already saved" do
|
52
|
-
before do
|
53
|
-
Zenflow::Github.should_receive(:user).and_return(nil)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "authorizes with Github" do
|
57
|
-
Zenflow::Github.should_receive(:set_user)
|
58
|
-
subject.set_up_github
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#authorize_github" do
|
64
|
-
context "when a zenflow_token is already saved" do
|
65
|
-
before do
|
66
|
-
Zenflow::Github.should_receive(:zenflow_token).and_return('super secret token')
|
67
|
-
end
|
68
|
-
|
69
|
-
context "and the user decides to set a new one" do
|
70
|
-
before do
|
71
|
-
Zenflow.should_receive(:Ask).and_return('y')
|
72
|
-
end
|
73
|
-
|
74
|
-
it "authorizes with Github" do
|
75
|
-
Zenflow::Github.should_receive(:authorize)
|
76
|
-
subject.authorize_github
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "and the user decides not to set a new one" do
|
81
|
-
before do
|
82
|
-
Zenflow.should_receive(:Ask).and_return('n')
|
83
|
-
end
|
84
|
-
|
85
|
-
it "does not authorize with Github" do
|
86
|
-
Zenflow::Github.should_not_receive(:authorize)
|
87
|
-
subject.authorize_github
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when a zenflow_token is not already saved" do
|
93
|
-
before do
|
94
|
-
Zenflow::Github.should_receive(:zenflow_token).and_return(nil)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "authorizes with Github" do
|
98
|
-
Zenflow::Github.should_receive(:authorize)
|
99
|
-
subject.authorize_github
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
22
|
describe "#already_configured" do
|
105
23
|
let(:question) {['There is an existing config file. Overwrite it?', {:options => ["y", "N"], :default => "n"}]}
|
106
24
|
before do
|
@@ -272,17 +190,26 @@ describe Zenflow::CLI do
|
|
272
190
|
end
|
273
191
|
|
274
192
|
describe "#init" do
|
193
|
+
let(:current){Zenflow::Github.new('current')}
|
194
|
+
|
195
|
+
before do
|
196
|
+
stub_const("Zenflow::Github::CURRENT", current)
|
197
|
+
end
|
198
|
+
|
275
199
|
context "when in a project that doesn't belong to the default hub" do
|
200
|
+
before do
|
201
|
+
current.should_receive(:is_default_hub?).and_return(false)
|
202
|
+
end
|
203
|
+
|
276
204
|
context "when zenflow has not been configured" do
|
277
205
|
before do
|
278
206
|
Zenflow::Config.should_receive(:configured?).and_return(false)
|
279
|
-
Zenflow::Repo.should_receive(:is_default_hub?).and_return(false)
|
280
207
|
end
|
281
208
|
|
282
209
|
it 'configures zenflow' do
|
283
210
|
subject.should_not_receive(:already_configured)
|
284
|
-
|
285
|
-
|
211
|
+
current.should_receive(:config)
|
212
|
+
current.should_receive(:authorize)
|
286
213
|
subject.should_receive(:configure_project)
|
287
214
|
subject.should_receive(:configure_branches)
|
288
215
|
subject.should_receive(:configure_merge_strategy)
|
@@ -298,13 +225,13 @@ describe Zenflow::CLI do
|
|
298
225
|
context "when zenflow has not been configured" do
|
299
226
|
before do
|
300
227
|
Zenflow::Config.should_receive(:configured?).and_return(false)
|
301
|
-
|
228
|
+
current.should_receive(:is_default_hub?).and_return(true)
|
302
229
|
end
|
303
230
|
|
304
231
|
it 'configures zenflow' do
|
305
232
|
subject.should_not_receive(:already_configured)
|
306
|
-
|
307
|
-
|
233
|
+
current.should_receive(:set_user)
|
234
|
+
current.should_receive(:authorize)
|
308
235
|
subject.should_receive(:configure_project)
|
309
236
|
subject.should_receive(:configure_branches)
|
310
237
|
subject.should_receive(:configure_merge_strategy)
|
@@ -323,13 +250,13 @@ describe Zenflow::CLI do
|
|
323
250
|
|
324
251
|
context 'and it is forced to initialize' do
|
325
252
|
before do
|
326
|
-
|
253
|
+
current.should_receive(:is_default_hub?).and_return(true)
|
327
254
|
end
|
328
255
|
|
329
256
|
it 'configures zenflow' do
|
330
257
|
subject.should_not_receive(:already_configured)
|
331
|
-
|
332
|
-
|
258
|
+
current.should_receive(:set_user)
|
259
|
+
current.should_receive(:authorize)
|
333
260
|
subject.should_receive(:configure_project)
|
334
261
|
subject.should_receive(:configure_branches)
|
335
262
|
subject.should_receive(:configure_merge_strategy)
|
@@ -350,8 +277,8 @@ describe Zenflow::CLI do
|
|
350
277
|
|
351
278
|
it 'calls already_configured' do
|
352
279
|
subject.should_receive(:already_configured).and_call_original
|
353
|
-
|
354
|
-
|
280
|
+
current.should_not_receive(:set_user)
|
281
|
+
current.should_not_receive(:authorize)
|
355
282
|
subject.should_not_receive(:configure_branches)
|
356
283
|
subject.should_not_receive(:configure_merge_strategy)
|
357
284
|
subject.should_not_receive(:configure_remotes)
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zenflow::Admin do
|
4
|
+
let(:admin) { Zenflow::Admin.new }
|
5
|
+
|
6
|
+
describe '.list' do
|
7
|
+
it 'lists recognized hubs in git config' do
|
8
|
+
Zenflow::Shell.should_receive(:run).with("git config --get-regexp zenflow\.hub\..*", silent: true).and_return(
|
9
|
+
<<EOS
|
10
|
+
zenflow.hub.hub.1.api.base.url api_base_url
|
11
|
+
zenflow.hub.yet.another.hub.github.user github_user
|
12
|
+
zenflow.hub.hub.1.token token
|
13
|
+
zenflow.hub.my-hub.token token
|
14
|
+
zenflow.hub.one.more.hub.user.agent.base user_agent_base
|
15
|
+
zenflow.hub.bad.token.hub.goobers user_agent_base
|
16
|
+
EOS
|
17
|
+
)
|
18
|
+
Zenflow.should_receive(:Log).with("Recogized hubs")
|
19
|
+
Terminal::Table.should_receive(:new).with(
|
20
|
+
headings: ["Hub"],
|
21
|
+
rows: [
|
22
|
+
["github.com [default] [current]"],
|
23
|
+
["hub.1"],
|
24
|
+
["my-hub"],
|
25
|
+
["one.more.hub"],
|
26
|
+
["yet.another.hub"]
|
27
|
+
]
|
28
|
+
).and_return("log-data")
|
29
|
+
Zenflow.should_receive(:Log).with("log-data", indent: false, arrows: false, color: false)
|
30
|
+
admin.list
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.current' do
|
35
|
+
it 'logs the hubs of the current project' do
|
36
|
+
Zenflow.should_receive(:Log).with("This project's hub is github.com [default] [current]")
|
37
|
+
admin.current
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.describe' do
|
42
|
+
it 'displays config parameters for the hub' do
|
43
|
+
hub = Zenflow::Github.new('my-hub')
|
44
|
+
admin.should_receive(:resolve_hub).with('my-hub').and_return(hub)
|
45
|
+
admin.should_receive(:hub_label).with('my-hub').and_return('my-hub')
|
46
|
+
Zenflow.should_receive(:Log).with("Configuration details for hub my-hub")
|
47
|
+
hub.should_receive(:describe).and_return([
|
48
|
+
["Parameter 1", "Github Config Key 1", "Github Conifg Value 1", "Value 1"],
|
49
|
+
["Parameter 2", "Github Config Key 2", "Github Conifg Value 2", "Value 2"],
|
50
|
+
["Parameter 3", "Github Config Key 3", "Github Conifg Value 3", "Value 3"]
|
51
|
+
])
|
52
|
+
Terminal::Table.should_receive(:new).with(
|
53
|
+
headings: ["Parameter", "Github Config Key", "Github Config Value", "Value (with system defaults)"],
|
54
|
+
rows: [
|
55
|
+
["Parameter 1", "Github Config Key 1", "Github Conifg Value 1", "Value 1"],
|
56
|
+
["Parameter 2", "Github Config Key 2", "Github Conifg Value 2", "Value 2"],
|
57
|
+
["Parameter 3", "Github Config Key 3", "Github Conifg Value 3", "Value 3"]
|
58
|
+
]
|
59
|
+
).and_return("log-data")
|
60
|
+
Zenflow.should_receive(:Log).with("log-data", {:indent=>false, :arrows=>false, :color=>false})
|
61
|
+
admin.describe('my-hub')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '.config' do
|
66
|
+
context 'when called with a hub parameter' do
|
67
|
+
it 'calls the individual parameter config methods' do
|
68
|
+
myhub = Zenflow::Github.new('my-hub')
|
69
|
+
Zenflow::Github.should_receive(:new).with('my-hub').and_return(myhub)
|
70
|
+
admin.should_receive(:hub_label).with('my-hub').and_return('my-hub')
|
71
|
+
Zenflow.should_receive(:Log).with("Configuring my-hub")
|
72
|
+
myhub.should_receive(:config)
|
73
|
+
admin.config('my-hub')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when called with no hub parameter' do
|
78
|
+
it 'calls the individual parameter config methods' do
|
79
|
+
admin.should_receive(:hub_label).with('github.com').and_return('github.com')
|
80
|
+
Zenflow.should_receive(:Log).with("Configuring github.com")
|
81
|
+
Zenflow::Github::CURRENT.should_receive(:config)
|
82
|
+
admin.config
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.authorize' do
|
88
|
+
context 'when called with a hub parameter' do
|
89
|
+
it 'call the hubs authorize method' do
|
90
|
+
myhub = Zenflow::Github.new('my-hub')
|
91
|
+
Zenflow::Github.should_receive(:new).with('my-hub').and_return(myhub)
|
92
|
+
admin.should_receive(:hub_label).with('my-hub').and_return('my-hub')
|
93
|
+
Zenflow.should_receive(:Log).with("Authorizing my-hub")
|
94
|
+
myhub.should_receive(:authorize)
|
95
|
+
admin.authorize('my-hub')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when called with no hub parameter' do
|
100
|
+
it 'call the current hubs authorize method' do
|
101
|
+
admin.should_receive(:hub_label).with('github.com').and_return('github.com')
|
102
|
+
Zenflow.should_receive(:Log).with("Authorizing github.com")
|
103
|
+
Zenflow::Github::CURRENT.should_receive(:authorize)
|
104
|
+
admin.authorize
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.resolve_hub' do
|
110
|
+
context 'hub is not nil' do
|
111
|
+
it 'resolves to the supplied hub' do
|
112
|
+
expect(admin.resolve_hub('my-hub').hub).to eq('my-hub')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'hub is nil' do
|
117
|
+
it 'resolves to the CURRENT hub' do
|
118
|
+
expect(admin.resolve_hub).to eq(Zenflow::Github::CURRENT)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.hub_label' do
|
124
|
+
context 'hub is default hub' do
|
125
|
+
context 'hub is current hub' do
|
126
|
+
before(:each){
|
127
|
+
stub_const("Zenflow::Github::CURRENT", Zenflow::Github.new(Zenflow::Github::DEFAULT_HUB))
|
128
|
+
}
|
129
|
+
|
130
|
+
it 'returns the expected label' do
|
131
|
+
expect(admin.hub_label(Zenflow::Github::DEFAULT_HUB)).to eq("#{Zenflow::Github::DEFAULT_HUB} [default] [current]")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'hub is not current hub' do
|
136
|
+
before(:each){
|
137
|
+
stub_const("Zenflow::Github::CURRENT", Zenflow::Github.new('current-hub'))
|
138
|
+
}
|
139
|
+
|
140
|
+
it 'returns the expected label' do
|
141
|
+
expect(admin.hub_label(Zenflow::Github::DEFAULT_HUB)).to eq("#{Zenflow::Github::DEFAULT_HUB} [default]")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'hub is not default hub' do
|
147
|
+
before(:each){
|
148
|
+
stub_const("Zenflow::Github::CURRENT", Zenflow::Github.new('current-hub'))
|
149
|
+
}
|
150
|
+
|
151
|
+
context 'hub is current hub' do
|
152
|
+
it 'returns the expected label' do
|
153
|
+
expect(admin.hub_label('current-hub')).to eq('current-hub [current]')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'hub is not current hub' do
|
158
|
+
it 'returns the expected label' do
|
159
|
+
expect(admin.hub_label('not-current-hub')).to eq('not-current-hub')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '.default_hub_tag' do
|
166
|
+
context 'hub is default hub' do
|
167
|
+
it 'returns the expected tag' do
|
168
|
+
expect(admin.default_hub_tag(Zenflow::Github::DEFAULT_HUB)).to eq(' [default]')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'hub is not default hub' do
|
173
|
+
it 'returns the expected tag' do
|
174
|
+
expect(admin.default_hub_tag('not-default-hub')).to eq('')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '.current_hub_tag' do
|
180
|
+
before(:each){
|
181
|
+
stub_const("Zenflow::Github::CURRENT", Zenflow::Github.new('current-hub'))
|
182
|
+
}
|
183
|
+
|
184
|
+
context 'hub is current hub' do
|
185
|
+
it 'returns the expected tag' do
|
186
|
+
expect(admin.current_hub_tag('current-hub')).to eq(' [current]')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'hub is not current hub' do
|
191
|
+
it 'returns the expected tag' do
|
192
|
+
expect(admin.current_hub_tag('not-current-hub')).to eq('')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '.config_key_regex' do
|
198
|
+
it 'returns the expected regex' do
|
199
|
+
expect(admin.config_keys_regex).to eq('(?:api\\.base\\.url|github\\.user|token|user\\.agent\\.base)')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -3,260 +3,469 @@ require 'spec_helper'
|
|
3
3
|
describe Zenflow::Github do
|
4
4
|
describe '.api_base_url' do
|
5
5
|
context 'when the value is present' do
|
6
|
+
let(:hub) { Zenflow::Github.new('test-hub') }
|
7
|
+
|
6
8
|
before(:each){
|
7
|
-
|
9
|
+
hub.should_receive(:get_config).with('api.base.url').and_return("api-base-url")
|
8
10
|
}
|
9
11
|
|
10
|
-
context 'and
|
12
|
+
context 'and use_default_when_value_is_nil is not specified' do
|
13
|
+
it 'returns the expected value' do
|
14
|
+
expect(hub.api_base_url).to eq("api-base-url")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'and use_default_when_value_is_nil is true' do
|
11
19
|
it 'returns the expected value' do
|
12
|
-
expect(
|
20
|
+
expect(hub.api_base_url(true)).to eq("api-base-url")
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
16
|
-
context 'and
|
24
|
+
context 'and use_default_when_value_is_nil is false' do
|
17
25
|
it 'returns the expected value' do
|
18
|
-
expect(
|
26
|
+
expect(hub.api_base_url(false)).to eq("api-base-url")
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
23
31
|
context 'when the value is absent' do
|
32
|
+
let(:hub) { Zenflow::Github.new('test-hub') }
|
33
|
+
|
24
34
|
before(:each){
|
25
|
-
|
35
|
+
hub.should_receive(:get_config).with('api.base.url').and_return(nil)
|
26
36
|
}
|
27
37
|
|
28
|
-
context 'and
|
38
|
+
context 'and use_default_when_value_is_nil is not specified' do
|
39
|
+
it 'returns the expected value' do
|
40
|
+
expect(hub.api_base_url).to eq("https://api.github.com")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'and use_default_when_value_is_nil is true' do
|
29
45
|
it 'returns the expected value' do
|
30
|
-
expect(
|
46
|
+
expect(hub.api_base_url(true)).to eq("https://api.github.com")
|
31
47
|
end
|
32
48
|
end
|
33
49
|
|
34
|
-
context 'and
|
50
|
+
context 'and use_default_when_value_is_nil is false' do
|
35
51
|
it 'returns the expected value' do
|
36
|
-
expect(
|
52
|
+
expect(hub.api_base_url(false)).to eq(nil)
|
37
53
|
end
|
38
54
|
end
|
39
55
|
end
|
40
56
|
end
|
41
57
|
|
42
58
|
describe '.set_api_base_url' do
|
43
|
-
let(:api_base_url){'api-base-url'}
|
44
59
|
|
45
60
|
it 'asks for the API base URL and sets it to zenflow.api.base.url' do
|
46
|
-
|
47
|
-
|
48
|
-
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '.set_api_base_url' do
|
65
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
66
|
+
let(:api_base_url){'api-base-url'}
|
67
|
+
|
68
|
+
context 'when a github api base url is already saved' do
|
69
|
+
before do
|
70
|
+
hub.should_receive(:api_base_url).twice.and_return(api_base_url)
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'and the user decides to set a new one' do
|
74
|
+
before do
|
75
|
+
Zenflow.should_receive(:Ask).and_return('n')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'asks for an api base url' do
|
79
|
+
Zenflow.should_receive(:Ask).and_return(api_base_url)
|
80
|
+
hub.should_receive(:set_config).with('api.base.url', api_base_url)
|
81
|
+
hub.set_api_base_url
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'and the user decides not to set a new one' do
|
86
|
+
before do
|
87
|
+
Zenflow.should_receive(:Ask).and_return('y')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'does not ask for an api base url' do
|
91
|
+
Zenflow.should_not_receive(:Ask)
|
92
|
+
hub.should_not_receive(:set_config)
|
93
|
+
hub.set_api_base_url
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when an api base url is not already saved' do
|
99
|
+
before do
|
100
|
+
hub.should_receive(:api_base_url).and_return(nil)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'asks for an api base url' do
|
104
|
+
Zenflow.should_receive(:Ask).and_return(api_base_url)
|
105
|
+
hub.should_receive(:set_config).with('api.base.url', api_base_url)
|
106
|
+
hub.set_api_base_url
|
107
|
+
end
|
49
108
|
end
|
50
109
|
end
|
51
110
|
|
52
111
|
describe '.user' do
|
112
|
+
let(:hub){Zenflow::Github.new('hub')}
|
53
113
|
let(:user){'github-user'}
|
54
114
|
|
55
115
|
before(:each){
|
56
|
-
|
116
|
+
hub.should_receive(:get_config).with('github.user').and_return(user)
|
57
117
|
}
|
58
118
|
|
59
119
|
it "returns the user" do
|
60
|
-
expect(
|
120
|
+
expect(hub.user).to eq(user)
|
61
121
|
end
|
62
122
|
end
|
63
123
|
|
64
124
|
describe '.set_user' do
|
125
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
65
126
|
let(:user){'github-user'}
|
66
127
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
128
|
+
context 'when a github user is already saved' do
|
129
|
+
before do
|
130
|
+
hub.should_receive(:user).twice.and_return(user)
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'and the user decides to set a new one' do
|
134
|
+
before do
|
135
|
+
Zenflow.should_receive(:Ask).and_return('n')
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'asks for a user' do
|
139
|
+
Zenflow.should_receive(:Ask).and_return(user)
|
140
|
+
hub.should_receive(:set_config).with('github.user', user)
|
141
|
+
hub.set_user
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'and the user decides not to set a new one' do
|
146
|
+
before do
|
147
|
+
Zenflow.should_receive(:Ask).and_return('y')
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'does not ask for a user' do
|
151
|
+
Zenflow.should_not_receive(:Ask)
|
152
|
+
hub.should_not_receive(:set_config)
|
153
|
+
hub.set_user
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'when a user is not already saved' do
|
159
|
+
before do
|
160
|
+
hub.should_receive(:user).and_return(nil)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'asks for a user' do
|
164
|
+
Zenflow.should_receive(:Ask).and_return(user)
|
165
|
+
hub.should_receive(:set_config).with('github.user', user)
|
166
|
+
hub.set_user
|
167
|
+
end
|
71
168
|
end
|
72
169
|
end
|
73
170
|
|
74
171
|
describe '.authorize' do
|
75
|
-
|
172
|
+
let(:hub){Zenflow::Github.new('my-hub')}
|
173
|
+
|
174
|
+
context 'when a zenflow_token is already saved' do
|
76
175
|
before do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
176
|
+
hub.should_receive(:zenflow_token).and_return('super secret token')
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'and the user decides to set a new one' do
|
180
|
+
before do
|
181
|
+
Zenflow.should_receive(:Ask).with("You already have a token from GitHub. Do you want to set a new one?", :options => ["y", "N"], :default => "n").and_return('y')
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'and authorization succeeds' do
|
185
|
+
before do
|
186
|
+
Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.")
|
187
|
+
hub.should_receive(:user).twice.and_return('adamkittelson')
|
188
|
+
hub.should_receive(:api_base_url).and_return('https://api.base.url')
|
189
|
+
Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}')
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'authorizes with Github' do
|
193
|
+
hub.should_receive(:set_config).with('token', "super secure token")
|
194
|
+
Zenflow.should_receive("Log").with("Authorized!")
|
195
|
+
hub.authorize
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'and authorization fails' do
|
200
|
+
before do
|
201
|
+
Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.")
|
202
|
+
hub.should_receive(:user).twice.and_return('adamkittelson')
|
203
|
+
hub.should_receive(:api_base_url).and_return('https://api.base.url')
|
204
|
+
Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}')
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'authorizes with Github' do
|
208
|
+
Zenflow.should_receive("Log").with("Something went wrong. Error from GitHub was: failed to authorize, bummer")
|
209
|
+
hub.authorize
|
210
|
+
end
|
211
|
+
end
|
81
212
|
end
|
82
213
|
|
83
|
-
|
84
|
-
|
85
|
-
|
214
|
+
context 'and the user decides not to set a new one' do
|
215
|
+
before do
|
216
|
+
Zenflow.should_receive(:Ask).and_return('n')
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'does not authorize with Github' do
|
220
|
+
hub.authorize
|
221
|
+
end
|
86
222
|
end
|
87
223
|
end
|
88
224
|
|
89
|
-
context
|
225
|
+
context 'when a zenflow_token is not already saved' do
|
90
226
|
before do
|
91
|
-
|
92
|
-
Zenflow::Github.should_receive(:user).twice.and_return('adamkittelson')
|
93
|
-
Zenflow::Github.should_receive(:api_base_url).and_return('https://api.base.url')
|
94
|
-
Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}')
|
227
|
+
hub.should_receive(:zenflow_token).and_return(nil)
|
95
228
|
end
|
96
229
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
230
|
+
context 'and authorization succeeds' do
|
231
|
+
before do
|
232
|
+
Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.")
|
233
|
+
hub.should_receive(:user).twice.and_return('adamkittelson')
|
234
|
+
hub.should_receive(:api_base_url).and_return('https://api.base.url')
|
235
|
+
Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}')
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'authorizes with Github' do
|
239
|
+
hub.should_receive(:set_config).with('token', "super secure token")
|
240
|
+
Zenflow.should_receive("Log").with("Authorized!")
|
241
|
+
hub.authorize
|
242
|
+
end
|
101
243
|
end
|
102
|
-
end
|
103
244
|
|
245
|
+
context 'and authorization fails' do
|
246
|
+
before do
|
247
|
+
Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.")
|
248
|
+
hub.should_receive(:user).twice.and_return('adamkittelson')
|
249
|
+
hub.should_receive(:api_base_url).and_return('https://api.base.url')
|
250
|
+
Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}')
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'does not authorize with Github' do
|
254
|
+
Zenflow.should_receive("Log").with("Something went wrong. Error from GitHub was: failed to authorize, bummer")
|
255
|
+
hub.authorize
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
104
259
|
end
|
105
260
|
|
106
261
|
describe '.user_agent_base' do
|
262
|
+
let(:hub){Zenflow::Github.new('hub')}
|
263
|
+
|
107
264
|
context 'when the value is present' do
|
108
265
|
before(:each){
|
109
|
-
|
266
|
+
hub.should_receive(:get_config).with('user.agent.base').and_return("user-agent-base")
|
110
267
|
}
|
111
268
|
|
112
|
-
context 'and
|
269
|
+
context 'and use_default_when_value_is_nil is not specified' do
|
113
270
|
it 'returns the expected value' do
|
114
|
-
expect(
|
271
|
+
expect(hub.user_agent_base).to eq("user-agent-base")
|
115
272
|
end
|
116
273
|
end
|
117
274
|
|
118
|
-
context 'and
|
275
|
+
context 'and use_default_when_value_is_nil is true' do
|
119
276
|
it 'returns the expected value' do
|
120
|
-
expect(
|
277
|
+
expect(hub.user_agent_base(true)).to eq("user-agent-base")
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'and use_default_when_value_is_nil is false' do
|
282
|
+
it 'returns the expected value' do
|
283
|
+
expect(hub.user_agent_base(false)).to eq("user-agent-base")
|
121
284
|
end
|
122
285
|
end
|
123
286
|
end
|
124
287
|
|
125
288
|
context 'when the value is absent' do
|
126
289
|
before(:each){
|
127
|
-
|
290
|
+
hub.should_receive(:get_config).with('user.agent.base').and_return(nil)
|
128
291
|
}
|
129
292
|
|
130
|
-
context 'and
|
293
|
+
context 'and use_default_when_value_is_nil is not specified' do
|
294
|
+
it 'returns the expected value' do
|
295
|
+
expect(hub.user_agent_base).to eq("Zencoder")
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'and use_default_when_value_is_nil is true' do
|
131
300
|
it 'returns the expected value' do
|
132
|
-
expect(
|
301
|
+
expect(hub.user_agent_base(true)).to eq("Zencoder")
|
133
302
|
end
|
134
303
|
end
|
135
304
|
|
136
|
-
context 'and
|
305
|
+
context 'and use_default_when_value_is_nil is false' do
|
137
306
|
it 'returns the expected value' do
|
138
|
-
expect(
|
307
|
+
expect(hub.user_agent_base(false)).to eq(nil)
|
139
308
|
end
|
140
309
|
end
|
141
310
|
end
|
142
311
|
end
|
143
312
|
|
144
313
|
describe '.set_user_agent_base' do
|
314
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
145
315
|
let(:user_agent_base){'user-agent-base'}
|
146
316
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
152
|
-
end
|
317
|
+
context 'when a github user agent base is already saved' do
|
318
|
+
before do
|
319
|
+
hub.should_receive(:user_agent_base).twice.and_return(user_agent_base)
|
320
|
+
end
|
153
321
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
159
|
-
end
|
322
|
+
context 'and the user decides to set a new one' do
|
323
|
+
before do
|
324
|
+
Zenflow.should_receive(:Ask).and_return('n')
|
325
|
+
end
|
160
326
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
327
|
+
it 'asks for a user agent base' do
|
328
|
+
Zenflow.should_receive(:Ask).and_return(user_agent_base)
|
329
|
+
hub.should_receive(:set_config).with('user.agent.base', user_agent_base)
|
330
|
+
hub.set_user_agent_base
|
331
|
+
end
|
332
|
+
end
|
166
333
|
|
167
|
-
|
168
|
-
|
169
|
-
|
334
|
+
context 'and the user decides not to set a new one' do
|
335
|
+
before do
|
336
|
+
Zenflow.should_receive(:Ask).and_return('y')
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'does not ask for a user agent base' do
|
340
|
+
Zenflow.should_not_receive(:Ask)
|
341
|
+
hub.should_not_receive(:set_config)
|
342
|
+
hub.set_user_agent_base
|
343
|
+
end
|
170
344
|
end
|
345
|
+
end
|
171
346
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
347
|
+
context 'when a user agent base is not already saved' do
|
348
|
+
before do
|
349
|
+
hub.should_receive(:user_agent_base).and_return(nil)
|
350
|
+
end
|
176
351
|
|
177
|
-
|
178
|
-
|
179
|
-
|
352
|
+
it 'asks for a user agent base' do
|
353
|
+
Zenflow.should_receive(:Ask).and_return(user_agent_base)
|
354
|
+
hub.should_receive(:set_config).with('user.agent.base', user_agent_base)
|
355
|
+
hub.set_user_agent_base
|
180
356
|
end
|
181
357
|
end
|
182
358
|
end
|
183
359
|
|
184
|
-
describe '.
|
360
|
+
describe '.current' do
|
361
|
+
context 'when the current repo is nil' do
|
362
|
+
before(:each){
|
363
|
+
Zenflow::Repo.should_receive(:hub).and_return(nil)
|
364
|
+
}
|
365
|
+
|
366
|
+
it 'returns the default hub' do
|
367
|
+
expect(Zenflow::Github.current.hub).to eq 'github.com'
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context 'when the current repo is not nil' do
|
372
|
+
before(:each){
|
373
|
+
Zenflow::Repo.should_receive(:hub).and_return('current.repo.hub')
|
374
|
+
}
|
375
|
+
|
376
|
+
it 'returns the current repo\'s hub' do
|
377
|
+
expect(Zenflow::Github.current.hub).to eq 'current.repo.hub'
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
describe '.parameter_key_for_hub' do
|
383
|
+
|
185
384
|
context 'when hub is the default hub' do
|
385
|
+
let(:hub){Zenflow::Github.new('github.com')}
|
386
|
+
|
186
387
|
context 'and key is the api url base key' do
|
187
388
|
it 'prepends \'zenflow\' as a prefix' do
|
188
|
-
expect(
|
389
|
+
expect(hub.parameter_key_for_hub('api.base.url')).to eq("zenflow.api.base.url")
|
189
390
|
end
|
190
391
|
end
|
191
392
|
|
192
393
|
context 'and key is the user key' do
|
193
394
|
it 'does not prepend a prefix' do
|
194
|
-
expect(
|
395
|
+
expect(hub.parameter_key_for_hub('github.user')).to eq('github.user')
|
195
396
|
end
|
196
397
|
end
|
197
398
|
|
198
399
|
context 'and key is the zenflow token key' do
|
199
400
|
it 'prepends \'zenflow\' as a prefix' do
|
200
|
-
expect(
|
401
|
+
expect(hub.parameter_key_for_hub('token')).to eq("zenflow.token")
|
201
402
|
end
|
202
403
|
end
|
203
404
|
|
204
405
|
context 'and key is the user agent base key' do
|
205
406
|
it 'prepends \'zenflow\' as a prefix' do
|
206
|
-
expect(
|
407
|
+
expect(hub.parameter_key_for_hub('user.agent.base')).to eq("zenflow.user.agent.base")
|
207
408
|
end
|
208
409
|
end
|
209
410
|
end
|
210
411
|
|
211
412
|
context 'hub is not the default hub' do
|
413
|
+
let(:hub){Zenflow::Github.new('my-hub')}
|
414
|
+
|
212
415
|
context 'and key is the api url base key' do
|
213
416
|
it 'prepends a hub-specific prefix' do
|
214
|
-
expect(
|
417
|
+
expect(hub.parameter_key_for_hub('api.base.url')).to eq("zenflow.hub.my-hub.api.base.url")
|
215
418
|
end
|
216
419
|
end
|
217
420
|
|
218
421
|
context 'and key is the user key' do
|
219
422
|
it 'prepends a hub-specific prefix' do
|
220
|
-
expect(
|
423
|
+
expect(hub.parameter_key_for_hub('github.user')).to eq("zenflow.hub.my-hub.github.user")
|
221
424
|
end
|
222
425
|
end
|
223
426
|
|
224
427
|
context 'and key is the zenflow token key' do
|
225
428
|
it 'prepends a hub-specific prefix' do
|
226
|
-
expect(
|
429
|
+
expect(hub.parameter_key_for_hub('token')).to eq("zenflow.hub.my-hub.token")
|
227
430
|
end
|
228
431
|
end
|
229
432
|
|
230
433
|
context 'and key is the user agent base key' do
|
231
434
|
it 'prepends a hub-specific prefix' do
|
232
|
-
expect(
|
435
|
+
expect(hub.parameter_key_for_hub('user.agent.base')).to eq("zenflow.hub.my-hub.user.agent.base")
|
233
436
|
end
|
234
437
|
end
|
235
438
|
end
|
236
439
|
end
|
237
440
|
|
238
|
-
describe '.
|
441
|
+
describe '.get_config' do
|
442
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
443
|
+
|
239
444
|
it 'gets the correct global config parameter' do
|
240
|
-
|
241
|
-
|
445
|
+
hub.should_receive(:get_global_config).with("zenflow.hub.test-hub.test-key")
|
446
|
+
hub.get_config('test-key')
|
242
447
|
end
|
243
448
|
end
|
244
449
|
|
245
|
-
describe '.
|
450
|
+
describe '.set_config' do
|
451
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
452
|
+
|
246
453
|
it 'sets the correct global config parameter' do
|
247
|
-
|
248
|
-
|
454
|
+
hub.should_receive(:set_global_config).with("zenflow.hub.test-hub.test-key", "test-value")
|
455
|
+
hub.set_config('test-key', 'test-value')
|
249
456
|
end
|
250
457
|
end
|
251
458
|
|
252
459
|
describe '.get_global_config' do
|
460
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
461
|
+
|
253
462
|
context 'when value is present' do
|
254
463
|
before(:each){
|
255
464
|
Zenflow::Shell.should_receive(:run).with('git config --get key', silent: true).and_return('value')
|
256
465
|
}
|
257
466
|
|
258
467
|
it 'returns the value' do
|
259
|
-
expect(
|
468
|
+
expect(hub.get_global_config('key')).to eq('value')
|
260
469
|
end
|
261
470
|
end
|
262
471
|
|
@@ -266,18 +475,20 @@ describe Zenflow::Github do
|
|
266
475
|
}
|
267
476
|
|
268
477
|
it 'returns nil' do
|
269
|
-
expect(
|
478
|
+
expect(hub.get_global_config('key')).to eq(nil)
|
270
479
|
end
|
271
480
|
end
|
272
481
|
end
|
273
482
|
|
274
483
|
describe '.set_global_config' do
|
484
|
+
let(:hub){Zenflow::Github.new('test-hub')}
|
485
|
+
|
275
486
|
before(:each){
|
276
487
|
Zenflow::Shell.should_receive(:run).with('git config --global key value', silent: true)
|
277
488
|
}
|
278
489
|
|
279
490
|
it 'sets the value' do
|
280
|
-
|
491
|
+
hub.set_global_config('key', 'value')
|
281
492
|
end
|
282
493
|
end
|
283
494
|
|
@@ -292,24 +503,29 @@ describe Zenflow::Github do
|
|
292
503
|
end
|
293
504
|
end
|
294
505
|
|
295
|
-
describe '.
|
506
|
+
describe '.describe_parameter' do
|
507
|
+
let(:hub){Zenflow::Github.new('my-hub')}
|
508
|
+
|
296
509
|
it 'returns the expected array' do
|
297
|
-
|
298
|
-
|
510
|
+
hub.should_receive(:get_config).with('key').and_return('config-value')
|
511
|
+
|
512
|
+
expect(hub.describe_parameter('name', 'key', 'value')).to eq(
|
299
513
|
['name', 'zenflow.hub.my-hub.key', 'config-value', 'value']
|
300
514
|
)
|
301
515
|
end
|
302
516
|
end
|
303
517
|
|
304
|
-
describe '.
|
518
|
+
describe '.describe' do
|
305
519
|
context 'all parameters configured' do
|
520
|
+
let(:hub){Zenflow::Github.new('my-hub')}
|
521
|
+
|
306
522
|
it 'returns the expected data' do
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
523
|
+
hub.should_receive(:get_config).twice.with('api.base.url').and_return('api-base-url-config-value')
|
524
|
+
hub.should_receive(:get_config).twice.with('github.user').and_return('github-user-config-value')
|
525
|
+
hub.should_receive(:get_config).twice.with('token').and_return('token-config-value')
|
526
|
+
hub.should_receive(:get_config).twice.with('user.agent.base').and_return('user-agent-base-config-value')
|
311
527
|
|
312
|
-
expect(
|
528
|
+
expect(hub.describe).to eq([
|
313
529
|
['API Base URL', 'zenflow.hub.my-hub.api.base.url', 'api-base-url-config-value', 'api-base-url-config-value'],
|
314
530
|
['User', 'zenflow.hub.my-hub.github.user', 'github-user-config-value', 'github-user-config-value'],
|
315
531
|
['Token', 'zenflow.hub.my-hub.token', 'token-config-value', 'token-config-value'],
|
@@ -319,13 +535,15 @@ describe Zenflow::Github do
|
|
319
535
|
end
|
320
536
|
|
321
537
|
context 'no parameters configured' do
|
538
|
+
let(:hub){Zenflow::Github.new('my-hub')}
|
539
|
+
|
322
540
|
it 'returns the expected data' do
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
541
|
+
hub.should_receive(:get_config).twice.with('api.base.url').and_return(nil)
|
542
|
+
hub.should_receive(:get_config).twice.with('github.user').and_return(nil)
|
543
|
+
hub.should_receive(:get_config).twice.with('token').and_return(nil)
|
544
|
+
hub.should_receive(:get_config).twice.with('user.agent.base').and_return(nil)
|
327
545
|
|
328
|
-
expect(
|
546
|
+
expect(hub.describe).to eq([
|
329
547
|
['API Base URL', 'zenflow.hub.my-hub.api.base.url', nil, 'https://api.github.com'],
|
330
548
|
['User', 'zenflow.hub.my-hub.github.user', nil, nil],
|
331
549
|
['Token', 'zenflow.hub.my-hub.token', nil, nil],
|
@@ -335,13 +553,15 @@ describe Zenflow::Github do
|
|
335
553
|
end
|
336
554
|
|
337
555
|
context 'hub is default' do
|
556
|
+
let(:hub){Zenflow::Github.new(Zenflow::Github::DEFAULT_HUB)}
|
557
|
+
|
338
558
|
it 'returns the expected data' do
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
559
|
+
hub.should_receive(:get_config).twice.with('api.base.url').and_return(nil)
|
560
|
+
hub.should_receive(:get_config).twice.with('github.user').and_return(nil)
|
561
|
+
hub.should_receive(:get_config).twice.with('token').and_return(nil)
|
562
|
+
hub.should_receive(:get_config).twice.with('user.agent.base').and_return(nil)
|
343
563
|
|
344
|
-
expect(
|
564
|
+
expect(hub.describe).to eq([
|
345
565
|
['API Base URL', 'zenflow.api.base.url', nil, 'https://api.github.com'],
|
346
566
|
['User', 'github.user', nil, nil],
|
347
567
|
['Token', 'zenflow.token', nil, nil],
|