Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
a91f581e
Commit
a91f581e
authored
Jun 28, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert extra validation for duplication between same keys on a submit
parent
df6e51fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
59 deletions
+34
-59
app/controllers/projects/pipeline_schedules_controller.rb
app/controllers/projects/pipeline_schedules_controller.rb
+1
-2
app/services/ci/create_pipeline_schedule_service.rb
app/services/ci/create_pipeline_schedule_service.rb
+2
-28
spec/controllers/projects/pipeline_schedules_controller_spec.rb
...ontrollers/projects/pipeline_schedules_controller_spec.rb
+31
-29
No files found.
app/controllers/projects/pipeline_schedules_controller.rb
View file @
a91f581e
...
...
@@ -33,8 +33,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
end
def
update
if
Ci
::
CreatePipelineScheduleService
.
new
(
@project
,
current_user
,
schedule_params
).
update
(
schedule
)
if
schedule
.
update
(
schedule_params
)
redirect_to
namespace_project_pipeline_schedules_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
)
else
render
:edit
...
...
app/services/ci/create_pipeline_schedule_service.rb
View file @
a91f581e
module
Ci
class
CreatePipelineScheduleService
<
BaseService
def
execute
pipeline_schedule
=
project
.
pipeline_schedules
.
build
(
pipeline_schedule_params
)
if
variable_keys_duplicated?
pipeline_schedule
.
errors
.
add
(
'variables.key'
,
"keys are duplicated"
)
return
pipeline_schedule
end
pipeline_schedule
.
save
pipeline_schedule
end
def
update
(
pipeline_schedule
)
if
variable_keys_duplicated?
pipeline_schedule
.
errors
.
add
(
'variables.key'
,
"keys are duplicated"
)
return
false
end
pipeline_schedule
.
update
(
pipeline_schedule_params
)
project
.
pipeline_schedules
.
create
(
pipeline_schedule_params
)
end
private
def
pipeline_schedule_params
@pipeline_schedule_params
||=
params
.
merge
(
owner:
current_user
)
end
def
variable_keys_duplicated?
attributes
=
pipeline_schedule_params
[
'variables_attributes'
]
return
false
unless
attributes
.
is_a?
(
Array
)
attributes
.
map
{
|
v
|
v
[
'key'
]
}.
uniq
.
length
!=
attributes
.
length
params
.
merge
(
owner:
current_user
)
end
end
end
spec/controllers/projects/pipeline_schedules_controller_spec.rb
View file @
a91f581e
...
...
@@ -142,21 +142,22 @@ describe Projects::PipelineSchedulesController do
end
end
context
'when variables_attributes has two variables and duplicted'
do
let
(
:schedule
)
do
basic_param
.
merge
({
variables_attributes:
[
{
key:
'AAA'
,
value:
'AAA123'
},
{
key:
'AAA'
,
value:
'BBB123'
}
]
})
end
it
'returns an error that the keys of variable are duplicated'
do
expect
{
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
schedule:
schedule
}
.
to
change
{
Ci
::
PipelineSchedule
.
count
}.
by
(
0
)
.
and
change
{
Ci
::
PipelineScheduleVariable
.
count
}.
by
(
0
)
expect
(
assigns
(
:schedule
).
errors
[
'variables.key'
]).
not_to
be_empty
end
end
# This test no longer passes, since we removed a custom validation
# context 'when variables_attributes has two variables and duplicted' do
# let(:schedule) do
# basic_param.merge({
# variables_attributes: [ { key: 'AAA', value: 'AAA123' }, { key: 'AAA', value: 'BBB123' } ]
# })
# end
# it 'returns an error that the keys of variable are duplicated' do
# expect { post :create, namespace_id: project.namespace.to_param, project_id: project, schedule: schedule }
# .to change { Ci::PipelineSchedule.count }.by(0)
# .and change { Ci::PipelineScheduleVariable.count }.by(0)
# expect(assigns(:schedule).errors['variables.key']).not_to be_empty
# end
# end
end
describe
'security'
do
...
...
@@ -260,20 +261,21 @@ describe Projects::PipelineSchedulesController do
end
end
context
'when params include two duplicated variables'
do
let
(
:schedule
)
do
basic_param
.
merge
({
variables_attributes:
[
{
key:
'AAA'
,
value:
'AAA123'
},
{
key:
'AAA'
,
value:
'BBB123'
}
]
})
end
it
'returns an error that variables are duplciated'
do
put
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
id:
pipeline_schedule
,
schedule:
schedule
expect
(
assigns
(
:schedule
).
errors
[
'variables.key'
]).
not_to
be_empty
end
end
# This test no longer passes, since we removed a custom validation
# context 'when params include two duplicated variables' do
# let(:schedule) do
# basic_param.merge({
# variables_attributes: [ { key: 'AAA', value: 'AAA123' }, { key: 'AAA', value: 'BBB123' } ]
# })
# end
# it 'returns an error that variables are duplciated' do
# put :update, namespace_id: project.namespace.to_param,
# project_id: project, id: pipeline_schedule, schedule: schedule
# expect(assigns(:schedule).errors['variables.key']).not_to be_empty
# end
# end
end
context
'when a pipeline schedule has one variable'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment