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
Boxiang Sun
gitlab-ce
Commits
79570ce2
Commit
79570ce2
authored
Feb 05, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix validation of duplicate new variables
parent
f7ed0964
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
0 deletions
+25
-0
app/models/group.rb
app/models/group.rb
+1
-0
app/models/project.rb
app/models/project.rb
+1
-0
spec/support/shared_examples/controllers/variables_shared_examples.rb
.../shared_examples/controllers/variables_shared_examples.rb
+23
-0
No files found.
app/models/group.rb
View file @
79570ce2
...
@@ -36,6 +36,7 @@ class Group < Namespace
...
@@ -36,6 +36,7 @@ class Group < Namespace
validate
:visibility_level_allowed_by_projects
validate
:visibility_level_allowed_by_projects
validate
:visibility_level_allowed_by_sub_groups
validate
:visibility_level_allowed_by_sub_groups
validate
:visibility_level_allowed_by_parent
validate
:visibility_level_allowed_by_parent
validates
:variables
,
variable_duplicates:
true
validates
:two_factor_grace_period
,
presence:
true
,
numericality:
{
greater_than_or_equal_to:
0
}
validates
:two_factor_grace_period
,
presence:
true
,
numericality:
{
greater_than_or_equal_to:
0
}
...
...
app/models/project.rb
View file @
79570ce2
...
@@ -261,6 +261,7 @@ class Project < ActiveRecord::Base
...
@@ -261,6 +261,7 @@ class Project < ActiveRecord::Base
validates
:repository_storage
,
validates
:repository_storage
,
presence:
true
,
presence:
true
,
inclusion:
{
in:
->
(
_object
)
{
Gitlab
.
config
.
repositories
.
storages
.
keys
}
}
inclusion:
{
in:
->
(
_object
)
{
Gitlab
.
config
.
repositories
.
storages
.
keys
}
}
validates
:variables
,
variable_duplicates:
true
has_many
:uploads
,
as: :model
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:uploads
,
as: :model
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
spec/support/shared_examples/controllers/variables_shared_examples.rb
View file @
79570ce2
...
@@ -48,6 +48,29 @@ shared_examples 'PATCH #update updates variables' do
...
@@ -48,6 +48,29 @@ shared_examples 'PATCH #update updates variables' do
end
end
end
end
context
'with duplicate new variable parameters'
do
let
(
:variables_attributes
)
do
[
new_variable_attributes
,
new_variable_attributes
.
merge
(
value:
'other_value'
)
]
end
it
'does not update the existing variable'
do
expect
{
subject
}.
not_to
change
{
variable
.
reload
.
value
}
end
it
'does not create the new variable'
do
expect
{
subject
}.
not_to
change
{
owner
.
variables
.
count
}
end
it
'returns a bad request response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with valid new variable parameters'
do
context
'with valid new variable parameters'
do
let
(
:variables_attributes
)
do
let
(
:variables_attributes
)
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