Skip to content

Commit d646cfc

Browse files
Added blank check in representers for build task attributes. (#2753)
1 parent 75ab962 commit d646cfc

File tree

12 files changed

+250
-40
lines changed

12 files changed

+250
-40
lines changed

server/webapp/WEB-INF/rails.new/app/presenters/api_v1/config/tasks/ant_task_representer.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2015 ThoughtWorks, Inc.
2+
# Copyright 2016 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,13 +23,12 @@ class AntTaskRepresenter < ApiV1::Config::Tasks::BaseTaskRepresenter
2323
'workingDirectory' => 'working_directory',
2424
'buildFile' => 'build_file',
2525
'onCancelConfig' => 'on_cancel',
26-
'runIf' => 'run_if',
27-
'nantPath' => 'nant_path'
26+
'runIf' => 'run_if'
2827
}
2928

30-
property :working_directory
31-
property :build_file
32-
property :target
29+
property :working_directory, skip_parse: SkipParseOnBlank
30+
property :build_file, skip_parse: SkipParseOnBlank
31+
property :target, skip_parse: SkipParseOnBlank
3332

3433
end
3534
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v1/config/tasks/nant_task_representer.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2015 ThoughtWorks, Inc.
2+
# Copyright 2016 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -27,10 +27,10 @@ class NantTaskRepresenter < ApiV1::Config::Tasks::BaseTaskRepresenter
2727
'nantPath' => 'nant_path'
2828
}
2929

30-
property :working_directory
31-
property :build_file
32-
property :target
33-
property :nant_path
30+
property :working_directory, skip_parse: SkipParseOnBlank
31+
property :build_file, skip_parse: SkipParseOnBlank
32+
property :target, skip_parse: SkipParseOnBlank
33+
property :nant_path, skip_parse: SkipParseOnBlank
3434

3535

3636
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v1/config/tasks/rake_task_representer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2015 ThoughtWorks, Inc.
2+
# Copyright 2016 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -26,9 +26,9 @@ class RakeTaskRepresenter < ApiV1::Config::Tasks::BaseTaskRepresenter
2626
'runIf' => 'run_if'
2727
}
2828

29-
property :working_directory
30-
property :build_file
31-
property :target
29+
property :working_directory, skip_parse: SkipParseOnBlank
30+
property :build_file, skip_parse: SkipParseOnBlank
31+
property :target, skip_parse: SkipParseOnBlank
3232

3333
end
3434
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v2/config/tasks/ant_task_representer.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ class AntTaskRepresenter < ApiV2::Config::Tasks::BaseTaskRepresenter
2323
'workingDirectory' => 'working_directory',
2424
'buildFile' => 'build_file',
2525
'onCancelConfig' => 'on_cancel',
26-
'runIf' => 'run_if',
27-
'nantPath' => 'nant_path'
26+
'runIf' => 'run_if'
2827
}
2928

30-
property :working_directory
31-
property :build_file
32-
property :target
29+
property :working_directory, skip_parse: SkipParseOnBlank
30+
property :build_file, skip_parse: SkipParseOnBlank
31+
property :target, skip_parse: SkipParseOnBlank
3332

3433
end
3534
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v2/config/tasks/nant_task_representer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class NantTaskRepresenter < ApiV2::Config::Tasks::BaseTaskRepresenter
2727
'nantPath' => 'nant_path'
2828
}
2929

30-
property :working_directory
31-
property :build_file
32-
property :target
33-
property :nant_path
30+
property :working_directory, skip_parse: SkipParseOnBlank
31+
property :build_file, skip_parse: SkipParseOnBlank
32+
property :target, skip_parse: SkipParseOnBlank
33+
property :nant_path, skip_parse: SkipParseOnBlank
3434

3535

3636
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v2/config/tasks/rake_task_representer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class RakeTaskRepresenter < ApiV2::Config::Tasks::BaseTaskRepresenter
2626
'runIf' => 'run_if'
2727
}
2828

29-
property :working_directory
30-
property :build_file
31-
property :target
29+
property :working_directory, skip_parse: SkipParseOnBlank
30+
property :build_file, skip_parse: SkipParseOnBlank
31+
property :target, skip_parse: SkipParseOnBlank
3232

3333
end
3434
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v3/config/tasks/ant_task_representer.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ class AntTaskRepresenter < ApiV3::Config::Tasks::BaseTaskRepresenter
2323
'workingDirectory' => 'working_directory',
2424
'buildFile' => 'build_file',
2525
'onCancelConfig' => 'on_cancel',
26-
'runIf' => 'run_if',
27-
'nantPath' => 'nant_path'
26+
'runIf' => 'run_if'
2827
}
2928

30-
property :working_directory
31-
property :build_file
32-
property :target
29+
property :working_directory, skip_parse: SkipParseOnBlank
30+
property :build_file, skip_parse: SkipParseOnBlank
31+
property :target, skip_parse: SkipParseOnBlank
3332

3433
end
3534
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v3/config/tasks/nant_task_representer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class NantTaskRepresenter < ApiV3::Config::Tasks::BaseTaskRepresenter
2727
'nantPath' => 'nant_path'
2828
}
2929

30-
property :working_directory
31-
property :build_file
32-
property :target
33-
property :nant_path
30+
property :working_directory, skip_parse: SkipParseOnBlank
31+
property :build_file, skip_parse: SkipParseOnBlank
32+
property :target, skip_parse: SkipParseOnBlank
33+
property :nant_path, skip_parse: SkipParseOnBlank
3434

3535

3636
end

server/webapp/WEB-INF/rails.new/app/presenters/api_v3/config/tasks/rake_task_representer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class RakeTaskRepresenter < ApiV3::Config::Tasks::BaseTaskRepresenter
2626
'runIf' => 'run_if'
2727
}
2828

29-
property :working_directory
30-
property :build_file
31-
property :target
29+
property :working_directory, skip_parse: SkipParseOnBlank
30+
property :build_file, skip_parse: SkipParseOnBlank
31+
property :target, skip_parse: SkipParseOnBlank
3232

3333
end
3434
end

server/webapp/WEB-INF/rails.new/spec/presenters/api_v1/config/task_representer_spec.rb

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2015 ThoughtWorks, Inc.
2+
# Copyright 2016 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -161,6 +161,17 @@ def task_hash
161161
}
162162
end
163163

164+
def default_task_hash
165+
{
166+
type: 'ant',
167+
attributes: {
168+
working_directory: '',
169+
build_file: '',
170+
target: ' '
171+
}
172+
}
173+
end
174+
164175
it 'should represent errors' do
165176
task = AntTask.new()
166177
task.setWorkingDirectory("../outside")
@@ -178,6 +189,18 @@ def task_hash
178189
expect(errors_hash[:errors].keys.size).to eq(task.errors.size)
179190
end
180191

192+
it 'should represent the ant task attributes as null if blank' do
193+
task = AntTask.new
194+
ApiV1::Config::Tasks::TaskRepresenter.new(task).from_hash(default_task_hash)
195+
actual_json = ApiV1::Config::Tasks::TaskRepresenter.new(task).to_hash(url_builder: UrlBuilder.new)
196+
expect(task.getTarget).to eq(nil)
197+
expect(task.getBuildFile).to eq(nil)
198+
expect(task.workingDirectory).to eq(nil)
199+
expect(actual_json).to eq({ type: 'ant',
200+
attributes: {run_if: [], on_cancel: nil, working_directory: nil, build_file: nil, target: nil}
201+
})
202+
end
203+
181204
def errors_hash
182205
{
183206
type: 'ant',
@@ -214,6 +237,18 @@ def task_hash
214237
}
215238
end
216239

240+
def default_task_hash
241+
{
242+
type: 'nant',
243+
attributes: {
244+
working_directory: '',
245+
build_file: '',
246+
target: ' ',
247+
nant_path: ''
248+
}
249+
}
250+
end
251+
217252
it 'should represent errors' do
218253
task = NantTask.new()
219254
task.setWorkingDirectory("../outside")
@@ -231,6 +266,18 @@ def task_hash
231266
expect(errors_hash[:errors].keys.size).to eq(task.errors.size)
232267
end
233268

269+
it 'should represent the nant task attributes as null if blank' do
270+
task = NantTask.new
271+
ApiV1::Config::Tasks::TaskRepresenter.new(task).from_hash(default_task_hash)
272+
actual_json = ApiV1::Config::Tasks::TaskRepresenter.new(task).to_hash(url_builder: UrlBuilder.new)
273+
expect(task.getTarget).to eq(nil)
274+
expect(task.getBuildFile).to eq(nil)
275+
expect(task.workingDirectory).to eq(nil)
276+
expect(actual_json).to eq({ type: 'nant',
277+
attributes: {run_if: [], on_cancel: nil, working_directory: nil, build_file: nil, target: nil, nant_path: nil}
278+
})
279+
end
280+
234281
def errors_hash
235282
{
236283
type: 'nant',
@@ -266,6 +313,18 @@ def task_hash
266313
}
267314
end
268315

316+
def default_task_hash
317+
{
318+
type: 'rake',
319+
attributes: {
320+
working_directory: '',
321+
build_file: '',
322+
target: ' ',
323+
nant_path: ''
324+
}
325+
}
326+
end
327+
269328
it 'should represent errors' do
270329
task = RakeTask.new()
271330
task.setWorkingDirectory("../outside")
@@ -283,6 +342,18 @@ def task_hash
283342
expect(errors_hash[:errors].keys.size).to eq(task.errors.size)
284343
end
285344

345+
it 'should represent the rake task attributes as null if not provided' do
346+
task = RakeTask.new
347+
ApiV1::Config::Tasks::TaskRepresenter.new(task).from_hash(default_task_hash)
348+
actual_json = ApiV1::Config::Tasks::TaskRepresenter.new(task).to_hash(url_builder: UrlBuilder.new)
349+
expect(task.getTarget).to eq(nil)
350+
expect(task.getBuildFile).to eq(nil)
351+
expect(task.workingDirectory).to eq(nil)
352+
expect(actual_json).to eq({type: 'rake',
353+
attributes: {run_if: [], on_cancel: nil, working_directory: nil, build_file: nil, target: nil}
354+
})
355+
end
356+
286357
def errors_hash
287358
{
288359
type: 'rake',

0 commit comments

Comments
 (0)