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
e5338263
Commit
e5338263
authored
Jul 03, 2018
by
Reuben Pereira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move common tests from user and project reference filter specs to a shared example
parent
4fb46624
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
143 deletions
+89
-143
spec/lib/banzai/filter/project_reference_filter_spec.rb
spec/lib/banzai/filter/project_reference_filter_spec.rb
+4
-70
spec/lib/banzai/filter/user_reference_filter_spec.rb
spec/lib/banzai/filter/user_reference_filter_spec.rb
+12
-73
spec/support/banzai/reference_filter_shared_examples.rb
spec/support/banzai/reference_filter_shared_examples.rb
+73
-0
No files found.
spec/lib/banzai/filter/project_reference_filter_spec.rb
View file @
e5338263
...
...
@@ -12,8 +12,12 @@ describe Banzai::Filter::ProjectReferenceFilter do
end
let
(
:project
)
{
create
(
:project
,
:public
)
}
subject
{
project
}
let
(
:subject_name
)
{
"project"
}
let
(
:reference
)
{
get_reference
(
project
)
}
it_behaves_like
'user reference or project reference'
it
'ignores invalid projects'
do
exp
=
act
=
"Hey
#{
invalidate_reference
(
reference
)
}
"
...
...
@@ -32,81 +36,11 @@ describe Banzai::Filter::ProjectReferenceFilter do
end
end
context
'mentioning a project'
do
it_behaves_like
'a reference containing an element node'
it
'links to a Project'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
project_url
(
project
)
end
it
'links to a Project with a period'
do
project
=
create
(
:project
,
name:
'alphA.Beta'
)
doc
=
reference_filter
(
"Hey
#{
get_reference
(
project
)
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'links to a Project with an underscore'
do
project
=
create
(
:project
,
name:
'ping_pong_king'
)
doc
=
reference_filter
(
"Hey
#{
get_reference
(
project
)
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'links to a Project with different case-sensitivity'
do
project
=
create
(
:project
,
name:
'RescueRanger'
)
reference
=
get_reference
(
project
)
doc
=
reference_filter
(
"Hey
#{
reference
.
upcase
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
text
).
to
eq
(
reference
)
end
it
'includes a data-project attribute'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project'
)
expect
(
link
.
attr
(
'data-project'
)).
to
eq
project
.
id
.
to_s
end
end
it
'includes default classes'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
eq
'gfm gfm-project has-tooltip'
end
it
'supports an :only_path context'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
project_path
(
project
)
end
context
'referencing a project in a link href'
do
let
(
:reference
)
{
%Q{<a href="
#{
get_reference
(
project
)
}
">Project</a>}
}
it
'links to a Project'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
project_url
(
project
)
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Mention me (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r{
\(
<a.+>Project</a>
\.\)
}
)
end
it
'includes a data-project attribute'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project'
)
expect
(
link
.
attr
(
'data-project'
)).
to
eq
project
.
id
.
to_s
end
end
context
'in group context'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
...
...
spec/lib/banzai/filter/user_reference_filter_spec.rb
View file @
e5338263
...
...
@@ -3,9 +3,17 @@ require 'spec_helper'
describe
Banzai
::
Filter
::
UserReferenceFilter
do
include
FilterSpecHelper
def
get_reference
(
user
)
user
.
to_reference
end
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:reference
)
{
user
.
to_reference
}
subject
{
user
}
let
(
:subject_name
)
{
"user"
}
let
(
:reference
)
{
get_reference
(
user
)
}
it_behaves_like
'user reference or project reference'
it
'requires project context'
do
expect
{
described_class
.
call
(
''
)
}.
to
raise_error
(
ArgumentError
,
/:project/
)
...
...
@@ -66,45 +74,6 @@ describe Banzai::Filter::UserReferenceFilter do
end
end
context
'mentioning a user'
do
it_behaves_like
'a reference containing an element node'
it
'links to a User'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
user_url
(
user
)
end
it
'links to a User with a period'
do
user
=
create
(
:user
,
name:
'alphA.Beta'
)
doc
=
reference_filter
(
"Hey
#{
user
.
to_reference
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'links to a User with an underscore'
do
user
=
create
(
:user
,
name:
'ping_pong_king'
)
doc
=
reference_filter
(
"Hey
#{
user
.
to_reference
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'links to a User with different case-sensitivity'
do
user
=
create
(
:user
,
username:
'RescueRanger'
)
doc
=
reference_filter
(
"Hey
#{
user
.
to_reference
.
upcase
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
text
).
to
eq
(
user
.
to_reference
)
end
it
'includes a data-user attribute'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-user'
)
expect
(
link
.
attr
(
'data-user'
)).
to
eq
user
.
namespace
.
owner_id
.
to_s
end
end
context
'mentioning a group'
do
it_behaves_like
'a reference containing an element node'
...
...
@@ -154,36 +123,6 @@ describe Banzai::Filter::UserReferenceFilter do
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
eq
'gfm gfm-project_member has-tooltip'
end
it
'supports an :only_path context'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
user_path
(
user
)
end
context
'referencing a user in a link href'
do
let
(
:reference
)
{
%Q{<a href="
#{
user
.
to_reference
}
">User</a>}
}
it
'links to a User'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
user_url
(
user
)
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Mention me (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r{
\(
<a.+>User</a>
\.\)
}
)
end
it
'includes a data-user attribute'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-user'
)
expect
(
link
.
attr
(
'data-user'
)).
to
eq
user
.
namespace
.
owner_id
.
to_s
end
end
context
'when a project is not specified'
do
let
(
:project
)
{
nil
}
...
...
@@ -227,7 +166,7 @@ describe Banzai::Filter::UserReferenceFilter do
end
it
'supports mentioning a single user'
do
reference
=
g
roup_member
.
to_reference
reference
=
g
et_reference
(
group_member
)
doc
=
reference_filter
(
"Hey
#{
reference
}
"
,
context
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
user_url
(
group_member
)
...
...
@@ -243,7 +182,7 @@ describe Banzai::Filter::UserReferenceFilter do
describe
'#namespaces'
do
it
'returns a Hash containing all Namespaces'
do
document
=
Nokogiri
::
HTML
.
fragment
(
"<p>
#{
user
.
to_reference
}
</p>"
)
document
=
Nokogiri
::
HTML
.
fragment
(
"<p>
#{
get_reference
(
user
)
}
</p>"
)
filter
=
described_class
.
new
(
document
,
project:
project
)
ns
=
user
.
namespace
...
...
@@ -253,7 +192,7 @@ describe Banzai::Filter::UserReferenceFilter do
describe
'#usernames'
do
it
'returns the usernames mentioned in a document'
do
document
=
Nokogiri
::
HTML
.
fragment
(
"<p>
#{
user
.
to_reference
}
</p>"
)
document
=
Nokogiri
::
HTML
.
fragment
(
"<p>
#{
get_reference
(
user
)
}
</p>"
)
filter
=
described_class
.
new
(
document
,
project:
project
)
expect
(
filter
.
usernames
).
to
eq
([
user
.
username
])
...
...
spec/support/banzai/reference_filter_shared_examples.rb
View file @
e5338263
...
...
@@ -11,3 +11,76 @@ shared_examples 'a reference containing an element node' do
expect
(
doc
.
children
.
first
.
inner_html
).
to
eq
(
inner_html
)
end
end
# Requires a reference, subject and subject_name:
# subject { create(:user) }
# let(:reference) { subject.to_reference }
# let(:subject_name) { 'user' }
shared_examples
'user reference or project reference'
do
shared_examples
'it contains a data- attribute'
do
it
'includes a data- attribute'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
"data-
#{
subject_name
}
"
)
expect
(
link
.
attr
(
"data-
#{
subject_name
}
"
)).
to
eq
subject
.
id
.
to_s
end
end
context
'mentioning a resource'
do
it_behaves_like
'a reference containing an element node'
it_behaves_like
'it contains a data- attribute'
it
"links to a resource"
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
send
(
"
#{
subject_name
}
_url"
,
subject
)
end
it
'links to a resource with a period'
do
subject
=
create
(
subject_name
.
to_sym
,
name:
'alphA.Beta'
)
doc
=
reference_filter
(
"Hey
#{
get_reference
(
subject
)
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'links to a resource with an underscore'
do
subject
=
create
(
subject_name
.
to_sym
,
name:
'ping_pong_king'
)
doc
=
reference_filter
(
"Hey
#{
get_reference
(
subject
)
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'links to a resource with different case-sensitivity'
do
subject
=
create
(
subject_name
.
to_sym
,
name:
'RescueRanger'
)
reference
=
get_reference
(
subject
)
doc
=
reference_filter
(
"Hey
#{
reference
.
upcase
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
text
).
to
eq
(
reference
)
end
end
it
'supports an :only_path context'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
send
"
#{
subject_name
}
_path"
,
subject
end
context
'referencing a resource in a link href'
do
let
(
:reference
)
{
%Q{<a href="
#{
get_reference
(
subject
)
}
">Some text</a>}
}
it_behaves_like
'it contains a data- attribute'
it
'links to the resource'
do
doc
=
reference_filter
(
"Hey
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
send
"
#{
subject_name
}
_url"
,
subject
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Mention me (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r{
\(
<a.+>Some text</a>
\.\)
}
)
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