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
19142f40
Commit
19142f40
authored
May 10, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify Note model specs
parent
b94c6d9f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
215 deletions
+36
-215
spec/factories/notes.rb
spec/factories/notes.rb
+2
-2
spec/models/note_spec.rb
spec/models/note_spec.rb
+34
-213
No files found.
spec/factories/notes.rb
View file @
19142f40
...
@@ -34,7 +34,7 @@ FactoryGirl.define do
...
@@ -34,7 +34,7 @@ FactoryGirl.define do
factory
:system_note
,
traits:
[
:system
]
factory
:system_note
,
traits:
[
:system
]
trait
:on_commit
do
trait
:on_commit
do
project
factory: :project
project
commit_id
RepoHelpers
.
sample_commit
.
id
commit_id
RepoHelpers
.
sample_commit
.
id
noteable_type
"Commit"
noteable_type
"Commit"
end
end
...
@@ -44,7 +44,7 @@ FactoryGirl.define do
...
@@ -44,7 +44,7 @@ FactoryGirl.define do
end
end
trait
:on_merge_request
do
trait
:on_merge_request
do
project
factory: :project
project
noteable_id
1
noteable_id
1
noteable_type
"MergeRequest"
noteable_type
"MergeRequest"
end
end
...
...
spec/models/note_spec.rb
View file @
19142f40
...
@@ -20,20 +20,44 @@
...
@@ -20,20 +20,44 @@
require
'spec_helper'
require
'spec_helper'
describe
Note
do
describe
Note
do
describe
"Associations"
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:noteable
)
}
it
{
is_expected
.
to
belong_to
(
:noteable
)
}
it
{
is_expected
.
to
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
is_expected
.
to
belong_to
(
:author
).
class_name
(
'User'
)
}
end
end
describe
"Mass assignment"
do
describe
'validation'
do
end
describe
"Validation"
do
it
{
is_expected
.
to
validate_presence_of
(
:note
)
}
it
{
is_expected
.
to
validate_presence_of
(
:note
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
end
end
describe
'#votable?'
do
it
'is true for issue notes'
do
note
=
build
(
:note_on_issue
)
expect
(
note
).
to
be_votable
end
it
'is true for merge request notes'
do
note
=
build
(
:note_on_merge_request
)
expect
(
note
).
to
be_votable
end
it
'is false for merge request diff notes'
do
note
=
build
(
:note_on_merge_request_diff
)
expect
(
note
).
not_to
be_votable
end
it
'is false for commit notes'
do
note
=
build
(
:note_on_commit
)
expect
(
note
).
not_to
be_votable
end
it
'is false for commit diff notes'
do
note
=
build
(
:note_on_commit_diff
)
expect
(
note
).
not_to
be_votable
end
end
describe
'voting score'
do
describe
'voting score'
do
it
'recognizes a neutral note'
do
it
'recognizes a neutral note'
do
note
=
build
(
:votable_note
,
note:
'This is not a +1 note'
)
note
=
build
(
:votable_note
,
note:
'This is not a +1 note'
)
...
@@ -78,8 +102,6 @@ describe Note do
...
@@ -78,8 +102,6 @@ describe Note do
end
end
end
end
let
(
:project
)
{
create
(
:project
)
}
describe
"Commit notes"
do
describe
"Commit notes"
do
let!
(
:note
)
{
create
(
:note_on_commit
,
note:
"+1 from me"
)
}
let!
(
:note
)
{
create
(
:note_on_commit
,
note:
"+1 from me"
)
}
let!
(
:commit
)
{
note
.
noteable
}
let!
(
:commit
)
{
note
.
noteable
}
...
@@ -98,10 +120,6 @@ describe Note do
...
@@ -98,10 +120,6 @@ describe Note do
it
"should be recognized by #for_commit?"
do
it
"should be recognized by #for_commit?"
do
expect
(
note
).
to
be_for_commit
expect
(
note
).
to
be_for_commit
end
end
it
"should not be votable"
do
expect
(
note
).
not_to
be_votable
end
end
end
describe
"Commit diff line notes"
do
describe
"Commit diff line notes"
do
...
@@ -126,205 +144,7 @@ describe Note do
...
@@ -126,205 +144,7 @@ describe Note do
end
end
end
end
describe
"Issue notes"
do
describe
'authorization'
do
let!
(
:note
)
{
create
(
:note_on_issue
,
note:
"+1 from me"
)
}
it
"should not be votable"
do
expect
(
note
).
to
be_votable
end
end
describe
"Merge request notes"
do
let!
(
:note
)
{
create
(
:note_on_merge_request
,
note:
"+1 from me"
)
}
it
"should be votable"
do
expect
(
note
).
to
be_votable
end
end
describe
"Merge request diff line notes"
do
let!
(
:note
)
{
create
(
:note_on_merge_request_diff
,
note:
"+1 from me"
)
}
it
"should not be votable"
do
expect
(
note
).
not_to
be_votable
end
end
describe
'#create_cross_reference_note'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:author
)
{
create
(
:user
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:mergereq
)
{
create
(
:merge_request
,
:simple
,
target_project:
project
,
source_project:
project
)
}
let
(
:commit
)
{
project
.
commit
}
# Test all of {issue, merge request, commit} in both the referenced and referencing
# roles, to ensure that the correct information can be inferred from any argument.
context
'issue from a merge request'
do
subject
{
Note
.
create_cross_reference_note
(
issue
,
mergereq
,
author
)
}
it
{
is_expected
.
to
be_valid
}
describe
'#noteable'
do
subject
{
super
().
noteable
}
it
{
is_expected
.
to
eq
(
issue
)
}
end
describe
'#project'
do
subject
{
super
().
project
}
it
{
is_expected
.
to
eq
(
issue
.
project
)
}
end
describe
'#author'
do
subject
{
super
().
author
}
it
{
is_expected
.
to
eq
(
author
)
}
end
describe
'#note'
do
subject
{
super
().
note
}
it
{
is_expected
.
to
eq
(
"mentioned in merge request !
#{
mergereq
.
iid
}
"
)
}
end
end
context
'issue from a commit'
do
subject
{
Note
.
create_cross_reference_note
(
issue
,
commit
,
author
)
}
it
{
is_expected
.
to
be_valid
}
describe
'#noteable'
do
subject
{
super
().
noteable
}
it
{
is_expected
.
to
eq
(
issue
)
}
end
describe
'#note'
do
subject
{
super
().
note
}
it
{
is_expected
.
to
eq
(
"mentioned in commit
#{
commit
.
sha
}
"
)
}
end
end
context
'merge request from an issue'
do
subject
{
Note
.
create_cross_reference_note
(
mergereq
,
issue
,
author
)
}
it
{
is_expected
.
to
be_valid
}
describe
'#noteable'
do
subject
{
super
().
noteable
}
it
{
is_expected
.
to
eq
(
mergereq
)
}
end
describe
'#project'
do
subject
{
super
().
project
}
it
{
is_expected
.
to
eq
(
mergereq
.
project
)
}
end
describe
'#note'
do
subject
{
super
().
note
}
it
{
is_expected
.
to
eq
(
"mentioned in issue #
#{
issue
.
iid
}
"
)
}
end
end
context
'commit from a merge request'
do
subject
{
Note
.
create_cross_reference_note
(
commit
,
mergereq
,
author
)
}
it
{
is_expected
.
to
be_valid
}
describe
'#noteable'
do
subject
{
super
().
noteable
}
it
{
is_expected
.
to
eq
(
commit
)
}
end
describe
'#project'
do
subject
{
super
().
project
}
it
{
is_expected
.
to
eq
(
project
)
}
end
describe
'#note'
do
subject
{
super
().
note
}
it
{
is_expected
.
to
eq
(
"mentioned in merge request !
#{
mergereq
.
iid
}
"
)
}
end
end
context
'commit contained in a merge request'
do
subject
{
Note
.
create_cross_reference_note
(
mergereq
.
commits
.
first
,
mergereq
,
author
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'commit from issue'
do
subject
{
Note
.
create_cross_reference_note
(
commit
,
issue
,
author
)
}
it
{
is_expected
.
to
be_valid
}
describe
'#noteable_type'
do
subject
{
super
().
noteable_type
}
it
{
is_expected
.
to
eq
(
"Commit"
)
}
end
describe
'#noteable_id'
do
subject
{
super
().
noteable_id
}
it
{
is_expected
.
to
be_nil
}
end
describe
'#commit_id'
do
subject
{
super
().
commit_id
}
it
{
is_expected
.
to
eq
(
commit
.
id
)
}
end
describe
'#note'
do
subject
{
super
().
note
}
it
{
is_expected
.
to
eq
(
"mentioned in issue #
#{
issue
.
iid
}
"
)
}
end
end
context
'commit from commit'
do
let
(
:parent_commit
)
{
commit
.
parents
.
first
}
subject
{
Note
.
create_cross_reference_note
(
commit
,
parent_commit
,
author
)
}
it
{
is_expected
.
to
be_valid
}
describe
'#noteable_type'
do
subject
{
super
().
noteable_type
}
it
{
is_expected
.
to
eq
(
"Commit"
)
}
end
describe
'#noteable_id'
do
subject
{
super
().
noteable_id
}
it
{
is_expected
.
to
be_nil
}
end
describe
'#commit_id'
do
subject
{
super
().
commit_id
}
it
{
is_expected
.
to
eq
(
commit
.
id
)
}
end
describe
'#note'
do
subject
{
super
().
note
}
it
{
is_expected
.
to
eq
(
"mentioned in commit
#{
parent_commit
.
id
}
"
)
}
end
end
end
describe
'#system?'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:other
)
{
create
(
:issue
,
project:
project
)
}
let
(
:author
)
{
create
(
:user
)
}
let
(
:assignee
)
{
create
(
:user
)
}
let
(
:label
)
{
create
(
:label
)
}
let
(
:milestone
)
{
create
(
:milestone
)
}
it
'should recognize user-supplied notes as non-system'
do
@note
=
create
(
:note_on_issue
)
expect
(
@note
).
not_to
be_system
end
it
'should identify cross-reference notes as system notes'
do
@note
=
Note
.
create_cross_reference_note
(
issue
,
other
,
author
)
expect
(
@note
).
to
be_system
end
end
describe
:authorization
do
before
do
before
do
@p1
=
create
(
:project
)
@p1
=
create
(
:project
)
@p2
=
create
(
:project
)
@p2
=
create
(
:project
)
...
@@ -335,7 +155,7 @@ describe Note do
...
@@ -335,7 +155,7 @@ describe Note do
@abilities
<<
Ability
@abilities
<<
Ability
end
end
describe
:read
do
describe
'read'
do
before
do
before
do
@p1
.
project_members
.
create
(
user:
@u2
,
access_level:
ProjectMember
::
GUEST
)
@p1
.
project_members
.
create
(
user:
@u2
,
access_level:
ProjectMember
::
GUEST
)
@p2
.
project_members
.
create
(
user:
@u3
,
access_level:
ProjectMember
::
GUEST
)
@p2
.
project_members
.
create
(
user:
@u3
,
access_level:
ProjectMember
::
GUEST
)
...
@@ -346,7 +166,7 @@ describe Note do
...
@@ -346,7 +166,7 @@ describe Note do
it
{
expect
(
@abilities
.
allowed?
(
@u3
,
:read_note
,
@p1
)).
to
be_falsey
}
it
{
expect
(
@abilities
.
allowed?
(
@u3
,
:read_note
,
@p1
)).
to
be_falsey
}
end
end
describe
:write
do
describe
'write'
do
before
do
before
do
@p1
.
project_members
.
create
(
user:
@u2
,
access_level:
ProjectMember
::
DEVELOPER
)
@p1
.
project_members
.
create
(
user:
@u2
,
access_level:
ProjectMember
::
DEVELOPER
)
@p2
.
project_members
.
create
(
user:
@u3
,
access_level:
ProjectMember
::
DEVELOPER
)
@p2
.
project_members
.
create
(
user:
@u3
,
access_level:
ProjectMember
::
DEVELOPER
)
...
@@ -357,7 +177,7 @@ describe Note do
...
@@ -357,7 +177,7 @@ describe Note do
it
{
expect
(
@abilities
.
allowed?
(
@u3
,
:write_note
,
@p1
)).
to
be_falsey
}
it
{
expect
(
@abilities
.
allowed?
(
@u3
,
:write_note
,
@p1
)).
to
be_falsey
}
end
end
describe
:admin
do
describe
'admin'
do
before
do
before
do
@p1
.
project_members
.
create
(
user:
@u1
,
access_level:
ProjectMember
::
REPORTER
)
@p1
.
project_members
.
create
(
user:
@u1
,
access_level:
ProjectMember
::
REPORTER
)
@p1
.
project_members
.
create
(
user:
@u2
,
access_level:
ProjectMember
::
MASTER
)
@p1
.
project_members
.
create
(
user:
@u2
,
access_level:
ProjectMember
::
MASTER
)
...
@@ -373,6 +193,7 @@ describe Note do
...
@@ -373,6 +193,7 @@ describe Note do
it_behaves_like
'an editable mentionable'
do
it_behaves_like
'an editable mentionable'
do
subject
{
create
:note
,
noteable:
issue
,
project:
project
}
subject
{
create
:note
,
noteable:
issue
,
project:
project
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
let
(
:backref_text
)
{
issue
.
gfm_reference
}
let
(
:backref_text
)
{
issue
.
gfm_reference
}
let
(
:set_mentionable_text
)
{
->
(
txt
)
{
subject
.
note
=
txt
}
}
let
(
:set_mentionable_text
)
{
->
(
txt
)
{
subject
.
note
=
txt
}
}
...
...
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