Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab FOSS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab FOSS
Commits
621f9307
Commit
621f9307
authored
7 years ago
by
Shinya Maeda
Browse files
Options
Downloads
Patches
Plain Diff
Implement uniqueness_of_in_memory_validator
parent
ff7529b3
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/ci/pipeline_schedule.rb
+5
-0
5 additions, 0 deletions
app/models/ci/pipeline_schedule.rb
spec/controllers/projects/pipeline_schedules_controller_spec.rb
+30
-37
30 additions, 37 deletions
...ontrollers/projects/pipeline_schedules_controller_spec.rb
with
35 additions
and
37 deletions
app/models/ci/pipeline_schedule.rb
+
5
−
0
View file @
621f9307
...
...
@@ -15,6 +15,11 @@ class PipelineSchedule < ActiveRecord::Base
validates
:cron_timezone
,
cron_timezone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
validates
:description
,
presence:
true
validates
:variables
,
uniqueness_of_in_memory:
{
:collection
=>
:variables
,
:attrs
=>
[
:pipeline_schedule_id
,
:key
],
:message
=>
[
'variables.key'
,
'keys are duplicated'
]
}
before_save
:set_next_run_at
...
...
This diff is collapsed.
Click to expand it.
spec/controllers/projects/pipeline_schedules_controller_spec.rb
+
30
−
37
View file @
621f9307
...
...
@@ -150,22 +150,21 @@ def visit_pipelines_schedules
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 { go }
# .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
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
{
go
}
.
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
...
...
@@ -194,7 +193,6 @@ def go
before
do
project
.
add_developer
(
user
)
sign_in
(
user
)
end
...
...
@@ -210,7 +208,6 @@ def go
go
pipeline_schedule
.
reload
expect
(
response
).
to
have_http_status
(
:found
)
expect
(
pipeline_schedule
.
description
).
to
eq
(
'updated_desc'
)
expect
(
pipeline_schedule
.
cron
).
to
eq
(
'0 1 * * *'
)
...
...
@@ -232,7 +229,6 @@ def go
expect
{
go
}.
to
change
{
Ci
::
PipelineScheduleVariable
.
count
}.
by
(
1
)
pipeline_schedule
.
reload
expect
(
response
).
to
have_http_status
(
:found
)
expect
(
pipeline_schedule
.
variables
.
last
.
key
).
to
eq
(
'AAA'
)
expect
(
pipeline_schedule
.
variables
.
last
.
value
).
to
eq
(
'AAA123'
)
...
...
@@ -250,7 +246,6 @@ def go
expect
{
go
}.
to
change
{
Ci
::
PipelineScheduleVariable
.
count
}.
by
(
2
)
pipeline_schedule
.
reload
expect
(
response
).
to
have_http_status
(
:found
)
expect
(
pipeline_schedule
.
variables
.
first
.
key
).
to
eq
(
'AAA'
)
expect
(
pipeline_schedule
.
variables
.
first
.
value
).
to
eq
(
'AAA123'
)
...
...
@@ -259,21 +254,20 @@ def go
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
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
...
...
@@ -293,7 +287,6 @@ def go
go
pipeline_schedule
.
reload
expect
(
response
).
to
have_http_status
(
:found
)
expect
(
pipeline_schedule
.
description
).
to
eq
(
'updated_desc'
)
expect
(
pipeline_schedule
.
cron
).
to
eq
(
'0 1 * * *'
)
...
...
@@ -316,6 +309,7 @@ def go
it
'adds the new variable'
do
expect
{
go
}.
to
change
{
Ci
::
PipelineScheduleVariable
.
count
}.
by
(
1
)
pipeline_schedule
.
reload
expect
(
pipeline_schedule
.
variables
.
last
.
key
).
to
eq
(
'AAA'
)
end
end
...
...
@@ -331,7 +325,6 @@ def go
expect
{
go
}.
not_to
change
{
Ci
::
PipelineScheduleVariable
.
count
}
pipeline_schedule_variable
.
reload
expect
(
pipeline_schedule_variable
.
value
).
to
eq
(
'new_value'
)
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment