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
Tatuya Kamada
gitlab-ce
Commits
c14ac835
Commit
c14ac835
authored
Aug 03, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that we have only one list per label per board
parent
c08a14c3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
0 deletions
+23
-0
app/models/list.rb
app/models/list.rb
+1
-0
db/migrate/20160803161903_add_unique_index_to_lists_label_id.rb
...rate/20160803161903_add_unique_index_to_lists_label_id.rb
+15
-0
db/schema.rb
db/schema.rb
+1
-0
spec/models/list_spec.rb
spec/models/list_spec.rb
+6
-0
No files found.
app/models/list.rb
View file @
c14ac835
...
@@ -6,6 +6,7 @@ class List < ActiveRecord::Base
...
@@ -6,6 +6,7 @@ class List < ActiveRecord::Base
validates
:board
,
:list_type
,
presence:
true
validates
:board
,
:list_type
,
presence:
true
validates
:label
,
:position
,
presence:
true
,
if: :label?
validates
:label
,
:position
,
presence:
true
,
if: :label?
validates
:label_id
,
uniqueness:
{
scope: :board_id
},
if: :label?
validates
:position
,
numericality:
{
only_integer:
true
,
greater_than_or_equal_to:
0
},
if: :label?
validates
:position
,
numericality:
{
only_integer:
true
,
greater_than_or_equal_to:
0
},
if: :label?
delegate
:name
,
to: :label
,
allow_nil:
true
,
prefix:
true
delegate
:name
,
to: :label
,
allow_nil:
true
,
prefix:
true
...
...
db/migrate/20160803161903_add_unique_index_to_lists_label_id.rb
0 → 100644
View file @
c14ac835
class
AddUniqueIndexToListsLabelId
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:lists
,
[
:board_id
,
:label_id
],
unique:
true
end
def
down
remove_index
:lists
,
column:
[
:board_id
,
:label_id
]
if
index_exists?
(
:lists
,
[
:board_id
,
:label_id
],
unique:
true
)
end
end
db/schema.rb
View file @
c14ac835
...
@@ -550,6 +550,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do
...
@@ -550,6 +550,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
end
add_index
"lists"
,
[
"board_id"
,
"label_id"
],
name:
"index_lists_on_board_id_and_label_id"
,
unique:
true
,
using: :btree
add_index
"lists"
,
[
"board_id"
],
name:
"index_lists_on_board_id"
,
using: :btree
add_index
"lists"
,
[
"board_id"
],
name:
"index_lists_on_board_id"
,
using: :btree
add_index
"lists"
,
[
"label_id"
],
name:
"index_lists_on_label_id"
,
using: :btree
add_index
"lists"
,
[
"label_id"
],
name:
"index_lists_on_label_id"
,
using: :btree
...
...
spec/models/list_spec.rb
View file @
c14ac835
...
@@ -17,6 +17,12 @@ describe List do
...
@@ -17,6 +17,12 @@ describe List do
it
{
is_expected
.
to
validate_presence_of
(
:position
)
}
it
{
is_expected
.
to
validate_presence_of
(
:position
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:position
).
only_integer
.
is_greater_than_or_equal_to
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:position
).
only_integer
.
is_greater_than_or_equal_to
(
0
)
}
it
'validates uniqueness of label scoped to board_id'
do
create
(
:list
)
expect
(
subject
).
to
validate_uniqueness_of
(
:label_id
).
scoped_to
(
:board_id
)
end
context
'when list_type is set to backlog'
do
context
'when list_type is set to backlog'
do
subject
{
described_class
.
new
(
list_type: :backlog
)
}
subject
{
described_class
.
new
(
list_type: :backlog
)
}
...
...
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