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
d52237a6
Commit
d52237a6
authored
Apr 27, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve uniqueness validation error message
parent
3fdccc12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
app/models/related_issue.rb
app/models/related_issue.rb
+2
-1
spec/models/related_issue_spec.rb
spec/models/related_issue_spec.rb
+15
-1
spec/services/related_issues/create_service_spec.rb
spec/services/related_issues/create_service_spec.rb
+1
-1
No files found.
app/models/related_issue.rb
View file @
d52237a6
...
...
@@ -2,6 +2,7 @@ class RelatedIssue < ActiveRecord::Base
belongs_to
:issue
belongs_to
:related_issue
,
class_name:
'Issue'
validates
:issue
,
presence:
true
,
uniqueness:
{
scope: :related_issue_id
}
validates
:issue
,
presence:
true
validates
:related_issue
,
presence:
true
validates
:issue
,
uniqueness:
{
scope: :related_issue_id
,
message:
'is already related'
}
end
spec/models/related_issue_spec.rb
View file @
d52237a6
...
...
@@ -11,6 +11,20 @@ describe RelatedIssue do
it
{
is_expected
.
to
validate_presence_of
(
:issue
)
}
it
{
is_expected
.
to
validate_presence_of
(
:related_issue
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:issue
).
scoped_to
(
:related_issue_id
)
}
it
do
is_expected
.
to
validate_uniqueness_of
(
:issue
)
.
scoped_to
(
:related_issue_id
)
.
with_message
(
/already related/
)
end
context
'self relation'
do
it
'invalidates object'
do
issue
=
create
:issue
related_issue
=
build
:related_issue
,
issue:
issue
,
related_issue:
issue
expect
(
related_issue
).
to
be_invalid
expect
(
related_issue
.
errors
[
:issue
]).
to
include
(
"cannot be related to itself"
)
end
end
end
end
spec/services/related_issues/create_service_spec.rb
View file @
d52237a6
...
...
@@ -136,7 +136,7 @@ describe RelatedIssues::CreateService, service: true do
end
it
'returns error'
do
is_expected
.
to
eq
(
message:
"Validation failed: Issue
has already been taken
"
,
status: :error
,
http_status:
401
)
is_expected
.
to
eq
(
message:
"Validation failed: Issue
is already related
"
,
status: :error
,
http_status:
401
)
end
it
'no relation is created'
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