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
1
Merge Requests
1
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
nexedi
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
...
@@ -33,8 +33,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
end
end
def
update
def
update
if
Ci
::
CreatePipelineScheduleService
if
schedule
.
update
(
schedule_params
)
.
new
(
@project
,
current_user
,
schedule_params
).
update
(
schedule
)
redirect_to
namespace_project_pipeline_schedules_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
)
redirect_to
namespace_project_pipeline_schedules_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
)
else
else
render
:edit
render
:edit
...
...
app/services/ci/create_pipeline_schedule_service.rb
View file @
a91f581e
module
Ci
module
Ci
class
CreatePipelineScheduleService
<
BaseService
class
CreatePipelineScheduleService
<
BaseService
def
execute
def
execute
pipeline_schedule
=
project
.
pipeline_schedules
.
build
(
pipeline_schedule_params
)
project
.
pipeline_schedules
.
create
(
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
)
end
end
private
private
def
pipeline_schedule_params
def
pipeline_schedule_params
@pipeline_schedule_params
||=
params
.
merge
(
owner:
current_user
)
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
end
end
end
end
end
end
spec/controllers/projects/pipeline_schedules_controller_spec.rb
View file @
a91f581e
...
@@ -142,21 +142,22 @@ describe Projects::PipelineSchedulesController do
...
@@ -142,21 +142,22 @@ describe Projects::PipelineSchedulesController do
end
end
end
end
context
'when variables_attributes has two variables and duplicted'
do
# This test no longer passes, since we removed a custom validation
let
(
:schedule
)
do
# context 'when variables_attributes has two variables and duplicted' do
basic_param
.
merge
({
# let(:schedule) do
variables_attributes:
[
{
key:
'AAA'
,
value:
'AAA123'
},
{
key:
'AAA'
,
value:
'BBB123'
}
]
# basic_param.merge({
})
# variables_attributes: [ { key: 'AAA', value: 'AAA123' }, { key: 'AAA', value: 'BBB123' } ]
end
# })
# 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
}
# it 'returns an error that the keys of variable are duplicated' do
.
to
change
{
Ci
::
PipelineSchedule
.
count
}.
by
(
0
)
# expect { post :create, namespace_id: project.namespace.to_param, project_id: project, schedule: schedule }
.
and
change
{
Ci
::
PipelineScheduleVariable
.
count
}.
by
(
0
)
# .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
# expect(assigns(:schedule).errors['variables.key']).not_to be_empty
end
# end
# end
end
end
describe
'security'
do
describe
'security'
do
...
@@ -260,20 +261,21 @@ describe Projects::PipelineSchedulesController do
...
@@ -260,20 +261,21 @@ describe Projects::PipelineSchedulesController do
end
end
end
end
context
'when params include two duplicated variables'
do
# This test no longer passes, since we removed a custom validation
let
(
:schedule
)
do
# context 'when params include two duplicated variables' do
basic_param
.
merge
({
# let(:schedule) do
variables_attributes:
[
{
key:
'AAA'
,
value:
'AAA123'
},
{
key:
'AAA'
,
value:
'BBB123'
}
]
# basic_param.merge({
})
# variables_attributes: [ { key: 'AAA', value: 'AAA123' }, { key: 'AAA', value: 'BBB123' } ]
end
# })
# end
it
'returns an error that variables are duplciated'
do
put
:update
,
namespace_id:
project
.
namespace
.
to_param
,
# it 'returns an error that variables are duplciated' do
project_id:
project
,
id:
pipeline_schedule
,
schedule:
schedule
# 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
# expect(assigns(:schedule).errors['variables.key']).not_to be_empty
end
# end
# end
end
end
context
'when a pipeline schedule has one variable'
do
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