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
Jérome Perrin
gitlab-ce
Commits
6568b4a9
Commit
6568b4a9
authored
Mar 13, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add shared specs for AtomicInternalId concern.
parent
d374d0be
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
2 deletions
+46
-2
app/models/concerns/atomic_internal_id.rb
app/models/concerns/atomic_internal_id.rb
+1
-1
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+7
-1
spec/support/shared_examples/models/atomic_internal_id_spec.rb
...support/shared_examples/models/atomic_internal_id_spec.rb
+38
-0
No files found.
app/models/concerns/atomic_internal_id.rb
View file @
6568b4a9
...
...
@@ -26,7 +26,7 @@ module AtomicInternalId
included
do
class
<<
self
def
has_internal_id
(
on
,
scope
:,
usage:
nil
,
init:
nil
)
# rubocop:disable Naming/PredicateName
def
has_internal_id
(
on
,
scope
:,
usage:
nil
,
init
:)
# rubocop:disable Naming/PredicateName
before_validation
(
on: :create
)
do
if
self
.
public_send
(
on
).
blank?
# rubocop:disable GitlabSecurity/PublicSend
...
...
spec/models/issue_spec.rb
View file @
6568b4a9
...
...
@@ -9,11 +9,17 @@ describe Issue do
describe
'modules'
do
subject
{
described_class
}
it
{
is_expected
.
to
include_module
(
InternalId
)
}
it
{
is_expected
.
to
include_module
(
Issuable
)
}
it
{
is_expected
.
to
include_module
(
Referable
)
}
it
{
is_expected
.
to
include_module
(
Sortable
)
}
it
{
is_expected
.
to
include_module
(
Taskable
)
}
it_behaves_like
'AtomicInternalId'
do
let
(
:internal_id_attribute
)
{
:iid
}
let
(
:instance
)
{
build
(
:issue
)
}
let
(
:scope_attrs
)
{
{
project:
instance
.
project
}
}
let
(
:usage
)
{
:issues
}
end
end
subject
{
create
(
:issue
)
}
...
...
spec/support/shared_examples/models/atomic_internal_id_spec.rb
0 → 100644
View file @
6568b4a9
require
'spec_helper'
shared_examples_for
'AtomicInternalId'
do
describe
'.has_internal_id'
do
describe
'Module inclusion'
do
subject
{
described_class
}
it
{
is_expected
.
to
include_module
(
AtomicInternalId
)
}
end
describe
'Validation'
do
subject
{
instance
}
before
do
allow
(
InternalId
).
to
receive
(
:generate_next
).
and_return
(
nil
)
end
it
{
is_expected
.
to
validate_presence_of
(
internal_id_attribute
)
}
it
{
is_expected
.
to
validate_numericality_of
(
internal_id_attribute
)
}
end
describe
'internal id generation'
do
subject
{
instance
.
save!
}
it
'calls InternalId.generate_next and sets internal id attribute'
do
iid
=
rand
(
1
..
1000
)
expect
(
InternalId
).
to
receive
(
:generate_next
).
with
(
instance
,
scope_attrs
,
usage
,
any_args
).
and_return
(
iid
)
subject
expect
(
instance
.
public_send
(
internal_id_attribute
)).
to
eq
(
iid
)
# rubocop:disable GitlabSecurity/PublicSend
end
it
'does not overwrite an existing internal id'
do
instance
.
public_send
(
"
#{
internal_id_attribute
}
="
,
4711
)
# rubocop:disable GitlabSecurity/PublicSend
expect
{
subject
}.
not_to
change
{
instance
.
public_send
(
internal_id_attribute
)
}
# rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
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