pgit 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.agignore +3 -0
- data/.travis.yml +1 -0
- data/README.markdown +32 -9
- data/Rakefile +12 -0
- data/bin/pgit +167 -25
- data/lib/pgit.rb +40 -10
- data/lib/pgit/bilateral/handle_back.rb +22 -0
- data/lib/pgit/bilateral/handle_choose_story.rb +31 -0
- data/lib/pgit/bilateral/story.rb +44 -0
- data/lib/pgit/command.rb +83 -0
- data/lib/pgit/command/add.rb +36 -0
- data/lib/pgit/command/application.rb +21 -0
- data/lib/pgit/command/edit.rb +36 -0
- data/lib/pgit/command/remove.rb +36 -0
- data/lib/pgit/command/run.rb +32 -0
- data/lib/pgit/command/show.rb +53 -0
- data/lib/pgit/configuration.rb +27 -3
- data/lib/pgit/current_project.rb +9 -45
- data/lib/pgit/current_project/validator.rb +2 -1
- data/lib/pgit/error/external.rb +11 -0
- data/lib/pgit/error/user.rb +12 -0
- data/lib/pgit/helpers/heredoc.rb +17 -0
- data/lib/pgit/helpers/query_methods.rb +63 -0
- data/lib/pgit/helpers/string_extensions.rb +29 -0
- data/lib/pgit/installer/bash_auto_completion.rb +57 -0
- data/lib/pgit/pivotal/collection_request.rb +21 -0
- data/lib/pgit/pivotal/individual_request.rb +47 -0
- data/lib/pgit/pivotal/iteration.rb +6 -0
- data/lib/pgit/pivotal/iterations.rb +15 -0
- data/lib/pgit/pivotal/project.rb +6 -0
- data/lib/pgit/pivotal/projects.rb +20 -0
- data/lib/pgit/pivotal/query.rb +8 -0
- data/lib/pgit/pivotal/request.rb +33 -0
- data/lib/pgit/pivotal/request/query.rb +25 -0
- data/lib/pgit/pivotal/story.rb +38 -0
- data/lib/pgit/pivotal_request_validator.rb +1 -1
- data/lib/pgit/project.rb +78 -0
- data/lib/pgit/project/add.rb +28 -0
- data/lib/pgit/project/application.rb +21 -0
- data/lib/pgit/project/interactive_adder.rb +41 -0
- data/lib/pgit/project/remove.rb +41 -0
- data/lib/pgit/project/reuse_api_token_adder.rb +48 -0
- data/lib/pgit/response_handler.rb +16 -0
- data/lib/pgit/root.rb +5 -0
- data/lib/pgit/status.rb +16 -0
- data/lib/pgit/story_branch/application.rb +3 -3
- data/lib/pgit/{name_parser.rb → story_branch/name_parser.rb} +0 -0
- data/lib/pgit/story_branch/story_id_parser.rb +11 -0
- data/lib/pgit/validators/project_validator.rb +20 -0
- data/lib/pgit/version.rb +1 -1
- data/lib/pivotal +0 -0
- data/pgit.gemspec +5 -0
- data/spec/fixtures/iterations +1 -0
- data/spec/pgit/bilateral/handle_back_spec.rb +29 -0
- data/spec/pgit/bilateral/handle_choose_story_spec.rb +17 -0
- data/spec/pgit/bilateral/story_spec.rb +178 -0
- data/spec/pgit/command/add_spec.rb +68 -0
- data/spec/pgit/command/application_spec.rb +110 -0
- data/spec/pgit/command/edit_spec.rb +61 -0
- data/spec/pgit/command/remove_spec.rb +76 -0
- data/spec/pgit/command/run_spec.rb +49 -0
- data/spec/pgit/command/show_spec.rb +95 -0
- data/spec/pgit/command_spec.rb +299 -0
- data/spec/pgit/configuration_spec.rb +121 -18
- data/spec/pgit/current_project/validator_spec.rb +2 -1
- data/spec/pgit/current_project_spec.rb +20 -71
- data/spec/pgit/{external_error_spec.rb → error/external_spec.rb} +3 -3
- data/spec/pgit/error/user_spec.rb +17 -0
- data/spec/pgit/helpers/heredoc_spec.rb +33 -0
- data/spec/pgit/helpers/query_methods_spec.rb +24 -0
- data/spec/pgit/helpers/string_extensions_spec.rb +49 -0
- data/spec/pgit/installer/bash_auto_completion_spec.rb +134 -0
- data/spec/pgit/pivotal/individual_request_spec.rb +32 -0
- data/spec/pgit/pivotal/iteration_spec.rb +19 -0
- data/spec/pgit/pivotal/iterations_spec.rb +37 -0
- data/spec/pgit/pivotal/project_spec.rb +9 -0
- data/spec/pgit/pivotal/projects_spec.rb +48 -0
- data/spec/pgit/pivotal/request/query_spec.rb +24 -0
- data/spec/pgit/pivotal/story_spec.rb +113 -0
- data/spec/pgit/pivotal_request_validator_spec.rb +3 -3
- data/spec/pgit/project/add_spec.rb +52 -0
- data/spec/pgit/project/application_spec.rb +69 -0
- data/spec/pgit/project/interactive_adder_spec.rb +45 -0
- data/spec/pgit/project/remove_spec.rb +86 -0
- data/spec/pgit/project/reuse_api_token_adder_spec.rb +41 -0
- data/spec/pgit/project_spec.rb +513 -0
- data/spec/pgit/status_spec.rb +40 -0
- data/spec/pgit/story_branch/application_spec.rb +5 -8
- data/spec/pgit/story_branch/name_parser_spec.rb +3 -3
- data/spec/pgit/story_branch/story_id_parser_spec.rb +17 -0
- data/spec/pgit/validators/project_validator_spec.rb +39 -0
- metadata +146 -21
- data/lib/pgit/configuration/layout_error.rb +0 -9
- data/lib/pgit/configuration/missing_attributes_error.rb +0 -10
- data/lib/pgit/configuration/not_found_error.rb +0 -10
- data/lib/pgit/configuration/project_missing_error.rb +0 -10
- data/lib/pgit/configuration/validator.rb +0 -41
- data/lib/pgit/current_project/no_paths_match_working_dir_error.rb +0 -10
- data/lib/pgit/external_error.rb +0 -9
- data/lib/pgit/installer/configuration.rb +0 -34
- data/lib/pgit/story.rb +0 -44
- data/spec/pgit/configuration/missing_attributes_error_spec.rb +0 -30
- data/spec/pgit/configuration/not_found_error_spec.rb +0 -17
- data/spec/pgit/configuration/project_missing_error_spec.rb +0 -30
- data/spec/pgit/configuration/validator_spec.rb +0 -79
- data/spec/pgit/current_project/no_paths_match_working_dir_error_spec.rb +0 -17
- data/spec/pgit/installer/configuration_spec.rb +0 -162
- data/spec/pgit/story_spec.rb +0 -35
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Project::ReuseApiTokenAdder' do
|
4
|
+
describe '#execute' do
|
5
|
+
describe 'there is already a project in the configuration file' do
|
6
|
+
it 'asks the right questions and the responses can be queried properly' do
|
7
|
+
api_token = 'someapitoken123'
|
8
|
+
path = 'some/path'
|
9
|
+
project_in_config = instance_double('PGit::Project',
|
10
|
+
api_token: api_token,
|
11
|
+
path: path)
|
12
|
+
projects = [project_in_config]
|
13
|
+
project = instance_double('PGit::Project')
|
14
|
+
allow(project).to receive(:api_token=).with(api_token)
|
15
|
+
|
16
|
+
question1 = instance_double('Interactive::Question', :question= => nil,
|
17
|
+
:options= => nil)
|
18
|
+
question2 = instance_double('Interactive::Question', :question= => nil,
|
19
|
+
:options= => nil)
|
20
|
+
reuse_response = double('response', yes?: true)
|
21
|
+
which_response = double('response', whole_number?: true, to_i: 0)
|
22
|
+
story_1 = double('OpenStruct', api_token: api_token, path: path)
|
23
|
+
allow(OpenStruct).to receive(:new).with(api_token: api_token, path: path).and_return(story_1)
|
24
|
+
allow(Interactive::Question).to receive(:new).and_yield(question1).and_yield(question2).and_return(question1, question2)
|
25
|
+
allow(question1).to receive(:columns=).with [:index, :api_token, :path]
|
26
|
+
allow(question2).to receive(:columns=).with [:index, :api_token, :path]
|
27
|
+
allow(question1).to receive(:ask_and_wait_for_valid_response).and_yield(reuse_response)
|
28
|
+
allow(question2).to receive(:ask_and_wait_for_valid_response).and_yield(which_response)
|
29
|
+
|
30
|
+
adder = PGit::Project::ReuseApiTokenAdder.new(project, projects)
|
31
|
+
adder.execute!
|
32
|
+
|
33
|
+
expect(question1).to have_received(:question=).with "Do you want to reuse an api token?"
|
34
|
+
expect(question1).to have_received(:options=).with [:yes, :no]
|
35
|
+
expect(question2).to have_received(:question=).with "Which one?"
|
36
|
+
expect(question2).to have_received(:options=).with [[story_1], :cancel]
|
37
|
+
expect(question2).to have_received(:columns=).with [:index, :api_token, :path]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,513 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Project' do
|
4
|
+
describe 'kind' do
|
5
|
+
it 'should give "project"' do
|
6
|
+
p = PGit::Project.new
|
7
|
+
p.instance_variable_set("@kind", 'project')
|
8
|
+
|
9
|
+
expect(p.kind).to eq 'project'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#given_api_token?' do
|
14
|
+
it 'should return false if no api_token given' do
|
15
|
+
p = PGit::Project.new
|
16
|
+
expect(p).not_to be_given_api_token
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return true if api_token is given' do
|
20
|
+
proj = PGit::Project.new do |p|
|
21
|
+
p.api_token = 'someapitoken'
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(proj).to be_given_api_token
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#given_id?' do
|
29
|
+
it 'should return false if no api_token given' do
|
30
|
+
p = PGit::Project.new
|
31
|
+
expect(p).not_to be_given_id
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return true if api_token is given' do
|
35
|
+
proj = PGit::Project.new do |p|
|
36
|
+
p.id = 'someid'
|
37
|
+
end
|
38
|
+
expect(proj).to be_given_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#commands=' do
|
43
|
+
it 'sets the commands' do
|
44
|
+
command = instance_double('PGit::Command')
|
45
|
+
command_name = 'command_name'
|
46
|
+
command_steps = ['subcommand1', 'subcommand2']
|
47
|
+
new_command = instance_double('PGit::Command', name: command_name,
|
48
|
+
steps: command_steps)
|
49
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
50
|
+
"id" => 12345,
|
51
|
+
"api_token" => "astoeuh",
|
52
|
+
"commands" => [{'command_name' => command_steps }] }
|
53
|
+
allow(PGit::Command).to receive(:new).and_return(command)
|
54
|
+
configuration = instance_double('PGit::Configuration')
|
55
|
+
proj = PGit::Project.new(configuration, project_hash)
|
56
|
+
proj.commands = [new_command]
|
57
|
+
|
58
|
+
expect(proj.commands.first).to eq new_command
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#commands' do
|
63
|
+
it 'returns the commands if they exist' do
|
64
|
+
command = instance_double('PGit::Command')
|
65
|
+
command_name = 'command_name'
|
66
|
+
command_steps = ['subcommand1', 'subcommand2']
|
67
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
68
|
+
"id" => 12345,
|
69
|
+
"api_token" => "astoeuh",
|
70
|
+
"commands" => [{'command_name' => command_steps }] }
|
71
|
+
allow(PGit::Command).to receive(:new).and_return(command)
|
72
|
+
configuration = instance_double('PGit::Configuration')
|
73
|
+
proj = PGit::Project.new(configuration, project_hash)
|
74
|
+
|
75
|
+
expect(proj.commands.first).to eq command
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns empty array if there are no commands' do
|
79
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
80
|
+
"id" => 12345,
|
81
|
+
"api_token" => "astoeuh",
|
82
|
+
"commands" => [] }
|
83
|
+
configuration = instance_double('PGit::Configuration')
|
84
|
+
proj = PGit::Project.new(configuration, project_hash)
|
85
|
+
|
86
|
+
expect(proj.commands).to eq []
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#path' do
|
91
|
+
it 'returns the path' do
|
92
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
93
|
+
"id" => 12345,
|
94
|
+
"api_token" => "astoeuh",
|
95
|
+
"commands" => [] }
|
96
|
+
configuration = instance_double('PGit::Configuration')
|
97
|
+
proj = PGit::Project.new(configuration, project_hash)
|
98
|
+
expect(proj.path).to eq project_hash.fetch('path')
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'defaults to :no_path_given' do
|
102
|
+
configuration = instance_double('PGit::Configuration')
|
103
|
+
api_token = 's3cret'
|
104
|
+
id = 12345
|
105
|
+
proj = PGit::Project.new(configuration) do |p|
|
106
|
+
p.api_token = api_token
|
107
|
+
p.id = id
|
108
|
+
end
|
109
|
+
|
110
|
+
expect(proj.path).to eq :no_path_given
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#sublink' do
|
115
|
+
it 'returns the sublink' do
|
116
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
117
|
+
"id" => 12345,
|
118
|
+
"api_token" => "astoeuh",
|
119
|
+
"commands" => [] }
|
120
|
+
configuration = instance_double('PGit::Configuration')
|
121
|
+
proj = PGit::Project.new(configuration, project_hash)
|
122
|
+
|
123
|
+
expect(proj.sublink).to eq "projects/#{proj.id}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#api_token' do
|
128
|
+
it 'returns the api_token' do
|
129
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
130
|
+
"id" => 12345,
|
131
|
+
"api_token" => "astoeuh",
|
132
|
+
"commands" => [] }
|
133
|
+
configuration = instance_double('PGit::Configuration')
|
134
|
+
proj = PGit::Project.new(configuration, project_hash)
|
135
|
+
expect(proj.api_token).to eq project_hash.fetch('api_token')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#id' do
|
140
|
+
it 'returns the id' do
|
141
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
142
|
+
"id" => 12345,
|
143
|
+
"api_token" => "astoeuh",
|
144
|
+
"commands" => [] }
|
145
|
+
configuration = instance_double('PGit::Configuration')
|
146
|
+
proj = PGit::Project.new(configuration, project_hash)
|
147
|
+
expect(proj.id).to eq project_hash.fetch('id')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#has_path?(path)' do
|
152
|
+
it 'returns true if the paths are the same' do
|
153
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
154
|
+
"id" => 12345,
|
155
|
+
"api_token" => "astoeuh",
|
156
|
+
"commands" => [] }
|
157
|
+
configuration = instance_double('PGit::Configuration')
|
158
|
+
proj = PGit::Project.new(configuration, project_hash)
|
159
|
+
|
160
|
+
expect(proj).to be_has_path(project_hash.fetch('path'))
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'returns false if the paths are not the same' do
|
164
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
165
|
+
"id" => 12345,
|
166
|
+
"api_token" => "astoeuh",
|
167
|
+
"commands" => [] }
|
168
|
+
configuration = instance_double('PGit::Configuration')
|
169
|
+
proj = PGit::Project.new(configuration, project_hash)
|
170
|
+
|
171
|
+
expect(proj).not_to be_has_path('some/other/path')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe '#has_api_token?(api_token)' do
|
176
|
+
it 'returns true if the api_tokens are the same' do
|
177
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
178
|
+
"id" => 12345,
|
179
|
+
"api_token" => "astoeuh",
|
180
|
+
"commands" => [] }
|
181
|
+
configuration = instance_double('PGit::Configuration')
|
182
|
+
proj = PGit::Project.new(configuration, project_hash)
|
183
|
+
|
184
|
+
expect(proj).to be_has_api_token(project_hash.fetch('api_token'))
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'returns false if the api_tokens are not the same' do
|
188
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
189
|
+
"id" => 12345,
|
190
|
+
"api_token" => "astoeuh",
|
191
|
+
"commands" => [] }
|
192
|
+
configuration = instance_double('PGit::Configuration')
|
193
|
+
proj = PGit::Project.new(configuration, project_hash)
|
194
|
+
|
195
|
+
expect(proj).not_to be_has_api_token('some/other/api_token')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe '#has_id?(id)' do
|
200
|
+
it 'returns true if the ids are the same' do
|
201
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
202
|
+
"id" => 12345,
|
203
|
+
"api_token" => "astoeuh",
|
204
|
+
"commands" => [] }
|
205
|
+
configuration = instance_double('PGit::Configuration')
|
206
|
+
proj = PGit::Project.new(configuration, project_hash)
|
207
|
+
|
208
|
+
expect(proj).to be_has_id(project_hash.fetch('id'))
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'returns false if the ids are not the same' do
|
212
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
213
|
+
"id" => 12345,
|
214
|
+
"api_token" => "astoeuh",
|
215
|
+
"commands" => [] }
|
216
|
+
configuration = instance_double('PGit::Configuration')
|
217
|
+
proj = PGit::Project.new(configuration, project_hash)
|
218
|
+
|
219
|
+
expect(proj).not_to be_has_id(54321)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe 'instatiating with a block' do
|
224
|
+
it 'sets the api_token, path, id based on the block' do
|
225
|
+
path = '/some/path'
|
226
|
+
api_token = 's3cret'
|
227
|
+
id = 12345
|
228
|
+
commands = []
|
229
|
+
configuration = instance_double('PGit::Configuration')
|
230
|
+
|
231
|
+
proj = PGit::Project.new(configuration) do |p|
|
232
|
+
p.path = path
|
233
|
+
p.api_token = api_token
|
234
|
+
p.id = id
|
235
|
+
p.commands = commands
|
236
|
+
end
|
237
|
+
|
238
|
+
expect(proj.path).to eq path
|
239
|
+
expect(proj.api_token).to eq api_token
|
240
|
+
expect(proj.id).to eq id
|
241
|
+
expect(proj.commands).to eq commands
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#to_hash' do
|
246
|
+
it 'returns the hash version' do
|
247
|
+
command = "command1"
|
248
|
+
steps = ["step1", "step2"]
|
249
|
+
command_hash = { command => steps }
|
250
|
+
project_hash = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
251
|
+
"id" => 12345,
|
252
|
+
"api_token" => "astoeuh",
|
253
|
+
"commands" => [
|
254
|
+
command_hash
|
255
|
+
]
|
256
|
+
}
|
257
|
+
fake_command = instance_double('PGit::Command', to_hash: command_hash)
|
258
|
+
configuration = instance_double('PGit::Configuration')
|
259
|
+
proj = PGit::Project.new(configuration, project_hash)
|
260
|
+
|
261
|
+
expect(proj.to_hash).to eq project_hash
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '#save!' do
|
266
|
+
it 'saves the project if does not exist' do
|
267
|
+
projects = []
|
268
|
+
configuration = instance_double('PGit::Configuration',
|
269
|
+
projects: projects,
|
270
|
+
"projects=".to_sym => :success,
|
271
|
+
save!: :successful_save)
|
272
|
+
command = "command1"
|
273
|
+
steps = ["step1", "step2"]
|
274
|
+
command_hash = { command => steps }
|
275
|
+
new_project = instance_double('PGit::Project',
|
276
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
277
|
+
'id'=> 54321,
|
278
|
+
'api_token'=> 'astoeuh',
|
279
|
+
'commands'=> [command_hash])
|
280
|
+
|
281
|
+
new_projs = [new_project]
|
282
|
+
allow(configuration).to receive(:projects=).with(new_projs)
|
283
|
+
|
284
|
+
proj = PGit::Project.new(configuration) do |p|
|
285
|
+
p.path = new_project.path
|
286
|
+
p.api_token = new_project.api_token
|
287
|
+
p.id = 54321
|
288
|
+
end
|
289
|
+
|
290
|
+
allow(proj).to receive(:valid?).and_return(true)
|
291
|
+
proj.save!
|
292
|
+
|
293
|
+
expect(configuration).to have_received(:save!)
|
294
|
+
expect(configuration.projects.first.path).to eq proj.path
|
295
|
+
expect(configuration.projects.first.id).to eq 54321
|
296
|
+
expect(configuration.projects.size).to eq 1
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'replaces the old copy of the project' do
|
300
|
+
command = "command1"
|
301
|
+
steps = ["step1", "step2"]
|
302
|
+
command_hash = { command => steps }
|
303
|
+
old_project = instance_double('PGit::Project',
|
304
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
305
|
+
'id'=> 12345,
|
306
|
+
'api_token'=> 'astoeuh',
|
307
|
+
'commands'=> [command_hash])
|
308
|
+
new_project = instance_double('PGit::Project',
|
309
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
310
|
+
'id'=> 54321,
|
311
|
+
'api_token'=> 'astoeuh',
|
312
|
+
'commands'=> [command_hash])
|
313
|
+
|
314
|
+
projects = [old_project]
|
315
|
+
|
316
|
+
class SomeConfig
|
317
|
+
def initialize(fake_proj)
|
318
|
+
@projs = [] << fake_proj
|
319
|
+
end
|
320
|
+
|
321
|
+
def projects
|
322
|
+
@projs
|
323
|
+
end
|
324
|
+
|
325
|
+
def projects=(projArr)
|
326
|
+
@projs = projArr
|
327
|
+
end
|
328
|
+
|
329
|
+
def save!
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
configuration = SomeConfig.new(old_project)
|
334
|
+
allow(configuration).to receive(:save!)
|
335
|
+
|
336
|
+
proj = PGit::Project.new(configuration) do |p|
|
337
|
+
p.path = old_project.path
|
338
|
+
p.api_token = old_project.api_token
|
339
|
+
p.id = 54321
|
340
|
+
end
|
341
|
+
|
342
|
+
allow(proj).to receive(:valid?).and_return(true)
|
343
|
+
proj.save!
|
344
|
+
|
345
|
+
expect(configuration).to have_received(:save!)
|
346
|
+
expect(configuration.projects.first.path).to eq proj.path
|
347
|
+
expect(configuration.projects.first.id).to eq 54321
|
348
|
+
expect(configuration.projects.size).to eq 1
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'raises an error if id does not exist' do
|
352
|
+
command = "command1"
|
353
|
+
steps = ["step1", "step2"]
|
354
|
+
command_hash = { command => steps }
|
355
|
+
old_project = instance_double('PGit::Project',
|
356
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
357
|
+
'id'=> 12345,
|
358
|
+
'api_token'=> 'astoeuh',
|
359
|
+
'commands'=> [command_hash])
|
360
|
+
new_project = instance_double('PGit::Project',
|
361
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
362
|
+
'id'=> 54321,
|
363
|
+
'api_token'=> 'astoeuh',
|
364
|
+
'commands'=> [command_hash])
|
365
|
+
|
366
|
+
projects = [old_project]
|
367
|
+
configuration = instance_double('PGit::Configuration',
|
368
|
+
projects: projects,
|
369
|
+
"projects=".to_sym => :success,
|
370
|
+
save!: :successful_save)
|
371
|
+
|
372
|
+
new_projs = [new_project]
|
373
|
+
allow(configuration).to receive(:projects=).with(new_projs)
|
374
|
+
|
375
|
+
proj = PGit::Project.new(configuration) do |p|
|
376
|
+
p.path = old_project.path
|
377
|
+
p.api_token = old_project.api_token
|
378
|
+
end
|
379
|
+
|
380
|
+
expect{proj.save!}.to raise_error(PGit::Error::User, 'no_id_given')
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'raises an error if api_token does not exist' do
|
384
|
+
command = "command1"
|
385
|
+
steps = ["step1", "step2"]
|
386
|
+
command_hash = { command => steps }
|
387
|
+
old_project = instance_double('PGit::Project',
|
388
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
389
|
+
'id'=> 12345,
|
390
|
+
'api_token'=> 'astoeuh',
|
391
|
+
'commands'=> [command_hash])
|
392
|
+
new_project = instance_double('PGit::Project',
|
393
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
394
|
+
'id'=> 54321,
|
395
|
+
'api_token'=> 'astoeuh',
|
396
|
+
'commands'=> [command_hash])
|
397
|
+
|
398
|
+
projects = [old_project]
|
399
|
+
configuration = instance_double('PGit::Configuration',
|
400
|
+
projects: projects,
|
401
|
+
"projects=".to_sym => :success,
|
402
|
+
save!: :successful_save)
|
403
|
+
|
404
|
+
new_projs = [new_project]
|
405
|
+
allow(configuration).to receive(:projects=).with(new_projs)
|
406
|
+
|
407
|
+
proj = PGit::Project.new(configuration) do |p|
|
408
|
+
p.path = old_project.path
|
409
|
+
p.id = old_project.id
|
410
|
+
end
|
411
|
+
|
412
|
+
expect{proj.save!}.to raise_error(PGit::Error::User, 'no_api_token_given')
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'raises an error if path does not exist' do
|
416
|
+
command = "command1"
|
417
|
+
steps = ["step1", "step2"]
|
418
|
+
command_hash = { command => steps }
|
419
|
+
old_project = instance_double('PGit::Project',
|
420
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
421
|
+
'id'=> 12345,
|
422
|
+
'api_token'=> 'astoeuh',
|
423
|
+
'commands'=> [command_hash])
|
424
|
+
new_project = instance_double('PGit::Project',
|
425
|
+
'path'=>"/Therapy-Exercises-Online/some_other_project",
|
426
|
+
'id'=> 54321,
|
427
|
+
'api_token'=> 'astoeuh',
|
428
|
+
'commands'=> [command_hash])
|
429
|
+
|
430
|
+
projects = [old_project]
|
431
|
+
configuration = instance_double('PGit::Configuration',
|
432
|
+
projects: projects,
|
433
|
+
"projects=".to_sym => :success,
|
434
|
+
save!: :successful_save)
|
435
|
+
|
436
|
+
new_projs = [new_project]
|
437
|
+
allow(configuration).to receive(:projects=).with(new_projs)
|
438
|
+
|
439
|
+
proj = PGit::Project.new(configuration) do |p|
|
440
|
+
p.id = old_project.id
|
441
|
+
p.api_token = old_project.api_token
|
442
|
+
end
|
443
|
+
|
444
|
+
expect{proj.save!}.to raise_error(PGit::Error::User, 'no_path_given')
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
describe '#remove!' do
|
449
|
+
it 'removes the project' do
|
450
|
+
matching_path = "/Therapy-Exercises-Online/some_other_project"
|
451
|
+
project_hash = { "path" => matching_path,
|
452
|
+
"id" => 12345,
|
453
|
+
"api_token" => "astoeuh",
|
454
|
+
"commands" => [] }
|
455
|
+
project = instance_double('PGit::Project', path: matching_path)
|
456
|
+
|
457
|
+
class SomeConfig
|
458
|
+
def initialize(fake_proj)
|
459
|
+
@projs = [] << fake_proj
|
460
|
+
end
|
461
|
+
|
462
|
+
def projects
|
463
|
+
@projs
|
464
|
+
end
|
465
|
+
|
466
|
+
def projects=(projArr)
|
467
|
+
@projs = projArr
|
468
|
+
end
|
469
|
+
|
470
|
+
def save!
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
configuration = SomeConfig.new(project)
|
475
|
+
allow(configuration).to receive(:save!)
|
476
|
+
proj = PGit::Project.new(configuration, project_hash)
|
477
|
+
|
478
|
+
proj.remove!
|
479
|
+
|
480
|
+
expect(configuration.projects.size).to eq 0
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
describe '#exists?' do
|
485
|
+
it 'returns true if it is already in the configuration' do
|
486
|
+
matching_path = "/Therapy-Exercises-Online/some_other_project"
|
487
|
+
project = instance_double('PGit::Project', path: matching_path)
|
488
|
+
projects = [project]
|
489
|
+
configuration = instance_double('PGit::Configuration',
|
490
|
+
projects: projects,
|
491
|
+
save!: true)
|
492
|
+
proj = PGit::Project.new(configuration) do |p|
|
493
|
+
p.path = matching_path
|
494
|
+
end
|
495
|
+
|
496
|
+
expect(proj).to be_exists
|
497
|
+
end
|
498
|
+
|
499
|
+
it 'returns false if it is not in the configuration' do
|
500
|
+
matching_path = "/Therapy-Exercises-Online/some_other_project"
|
501
|
+
project = instance_double('PGit::Project', path: matching_path)
|
502
|
+
projects = [project]
|
503
|
+
configuration = instance_double('PGit::Configuration',
|
504
|
+
projects: projects,
|
505
|
+
save!: true)
|
506
|
+
proj = PGit::Project.new(configuration) do |p|
|
507
|
+
p.path = '/some/non-matching/path'
|
508
|
+
end
|
509
|
+
|
510
|
+
expect(proj).not_to be_exists
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|