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
611912fe
Commit
611912fe
authored
Dec 07, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store the demodulized reference filter name in data attribute
parent
d611a387
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
18 deletions
+18
-18
lib/gitlab/markdown/filter/reference_gatherer_filter.rb
lib/gitlab/markdown/filter/reference_gatherer_filter.rb
+1
-1
lib/gitlab/markdown/reference_filter.rb
lib/gitlab/markdown/reference_filter.rb
+3
-3
spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb
spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb
+7
-7
spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb
.../gitlab/markdown/filter/reference_gatherer_filter_spec.rb
+7
-7
No files found.
lib/gitlab/markdown/filter/reference_gatherer_filter.rb
View file @
611912fe
...
@@ -31,7 +31,7 @@ module Gitlab
...
@@ -31,7 +31,7 @@ module Gitlab
return
unless
node
.
has_attribute?
(
'data-reference-filter'
)
return
unless
node
.
has_attribute?
(
'data-reference-filter'
)
reference_type
=
node
.
attr
(
'data-reference-filter'
)
reference_type
=
node
.
attr
(
'data-reference-filter'
)
reference_filter
=
reference_type
.
constantize
reference_filter
=
Gitlab
::
Markdown
.
const_get
(
reference_type
)
return
if
context
[
:reference_filter
]
&&
reference_filter
!=
context
[
:reference_filter
]
return
if
context
[
:reference_filter
]
&&
reference_filter
!=
context
[
:reference_filter
]
...
...
lib/gitlab/markdown/reference_filter.rb
View file @
611912fe
...
@@ -57,14 +57,14 @@ module Gitlab
...
@@ -57,14 +57,14 @@ module Gitlab
# Examples:
# Examples:
#
#
# data_attribute(project: 1, issue: 2)
# data_attribute(project: 1, issue: 2)
# # => "data-reference-filter=\"
Gitlab::Markdown::
SomeReferenceFilter\" data-project=\"1\" data-issue=\"2\""
# # => "data-reference-filter=\"SomeReferenceFilter\" data-project=\"1\" data-issue=\"2\""
#
#
# data_attribute(project: 3, merge_request: 4)
# data_attribute(project: 3, merge_request: 4)
# # => "data-reference-filter=\"
Gitlab::Markdown::
SomeReferenceFilter\" data-project=\"3\" data-merge-request=\"4\""
# # => "data-reference-filter=\"SomeReferenceFilter\" data-project=\"3\" data-merge-request=\"4\""
#
#
# Returns a String
# Returns a String
def
data_attribute
(
attributes
=
{})
def
data_attribute
(
attributes
=
{})
attributes
[
:reference_filter
]
=
self
.
class
.
name
attributes
[
:reference_filter
]
=
self
.
class
.
name
.
demodulize
attributes
.
map
{
|
key
,
value
|
%Q(data-
#{
key
.
to_s
.
dasherize
}
="
#{
value
}
")
}.
join
(
" "
)
attributes
.
map
{
|
key
,
value
|
%Q(data-
#{
key
.
to_s
.
dasherize
}
="
#{
value
}
")
}.
join
(
" "
)
end
end
...
...
spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb
View file @
611912fe
...
@@ -20,7 +20,7 @@ describe Gitlab::Markdown::RedactorFilter do
...
@@ -20,7 +20,7 @@ describe Gitlab::Markdown::RedactorFilter do
user
=
create
(
:user
)
user
=
create
(
:user
)
project
=
create
(
:empty_project
)
project
=
create
(
:empty_project
)
link
=
reference_link
(
project:
project
.
id
,
reference_filter:
Gitlab
::
Markdown
::
ReferenceFilter
.
name
)
link
=
reference_link
(
project:
project
.
id
,
reference_filter:
'ReferenceFilter'
)
doc
=
filter
(
link
,
current_user:
user
)
doc
=
filter
(
link
,
current_user:
user
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
0
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
0
...
@@ -31,14 +31,14 @@ describe Gitlab::Markdown::RedactorFilter do
...
@@ -31,14 +31,14 @@ describe Gitlab::Markdown::RedactorFilter do
project
=
create
(
:empty_project
)
project
=
create
(
:empty_project
)
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
link
=
reference_link
(
project:
project
.
id
,
reference_filter:
Gitlab
::
Markdown
::
ReferenceFilter
.
name
)
link
=
reference_link
(
project:
project
.
id
,
reference_filter:
'ReferenceFilter'
)
doc
=
filter
(
link
,
current_user:
user
)
doc
=
filter
(
link
,
current_user:
user
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
end
it
'handles invalid Project references'
do
it
'handles invalid Project references'
do
link
=
reference_link
(
project:
12345
,
reference_filter:
Gitlab
::
Markdown
::
ReferenceFilter
.
name
)
link
=
reference_link
(
project:
12345
,
reference_filter:
'ReferenceFilter'
)
expect
{
filter
(
link
)
}.
not_to
raise_error
expect
{
filter
(
link
)
}.
not_to
raise_error
end
end
...
@@ -51,7 +51,7 @@ describe Gitlab::Markdown::RedactorFilter do
...
@@ -51,7 +51,7 @@ describe Gitlab::Markdown::RedactorFilter do
user
=
create
(
:user
)
user
=
create
(
:user
)
group
=
create
(
:group
)
group
=
create
(
:group
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
'UserReferenceFilter'
)
doc
=
filter
(
link
,
current_user:
user
)
doc
=
filter
(
link
,
current_user:
user
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
0
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
0
...
@@ -62,14 +62,14 @@ describe Gitlab::Markdown::RedactorFilter do
...
@@ -62,14 +62,14 @@ describe Gitlab::Markdown::RedactorFilter do
group
=
create
(
:group
)
group
=
create
(
:group
)
group
.
add_developer
(
user
)
group
.
add_developer
(
user
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
'UserReferenceFilter'
)
doc
=
filter
(
link
,
current_user:
user
)
doc
=
filter
(
link
,
current_user:
user
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
end
it
'handles invalid Group references'
do
it
'handles invalid Group references'
do
link
=
reference_link
(
group:
12345
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
group:
12345
,
reference_filter:
'UserReferenceFilter'
)
expect
{
filter
(
link
)
}.
not_to
raise_error
expect
{
filter
(
link
)
}.
not_to
raise_error
end
end
...
@@ -79,7 +79,7 @@ describe Gitlab::Markdown::RedactorFilter do
...
@@ -79,7 +79,7 @@ describe Gitlab::Markdown::RedactorFilter do
it
'allows any User reference'
do
it
'allows any User reference'
do
user
=
create
(
:user
)
user
=
create
(
:user
)
link
=
reference_link
(
user:
user
.
id
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
user:
user
.
id
,
reference_filter:
'UserReferenceFilter'
)
doc
=
filter
(
link
)
doc
=
filter
(
link
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
...
...
spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb
View file @
611912fe
...
@@ -16,7 +16,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
...
@@ -16,7 +16,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
project
=
create
(
:empty_project
)
project
=
create
(
:empty_project
)
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
link
=
reference_link
(
project:
project
.
id
,
issue:
issue
.
id
,
reference_filter:
Gitlab
::
Markdown
::
IssueReferenceFilter
.
name
)
link
=
reference_link
(
project:
project
.
id
,
issue:
issue
.
id
,
reference_filter:
'IssueReferenceFilter'
)
result
=
pipeline_result
(
link
,
current_user:
user
)
result
=
pipeline_result
(
link
,
current_user:
user
)
expect
(
result
[
:references
][
:issue
]).
to
be_empty
expect
(
result
[
:references
][
:issue
]).
to
be_empty
...
@@ -28,14 +28,14 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
...
@@ -28,14 +28,14 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
link
=
reference_link
(
project:
project
.
id
,
issue:
issue
.
id
,
reference_filter:
Gitlab
::
Markdown
::
IssueReferenceFilter
.
name
)
link
=
reference_link
(
project:
project
.
id
,
issue:
issue
.
id
,
reference_filter:
'IssueReferenceFilter'
)
result
=
pipeline_result
(
link
,
current_user:
user
)
result
=
pipeline_result
(
link
,
current_user:
user
)
expect
(
result
[
:references
][
:issue
]).
to
eq
([
issue
])
expect
(
result
[
:references
][
:issue
]).
to
eq
([
issue
])
end
end
it
'handles invalid Project references'
do
it
'handles invalid Project references'
do
link
=
reference_link
(
project:
12345
,
issue:
12345
,
reference_filter:
Gitlab
::
Markdown
::
IssueReferenceFilter
.
name
)
link
=
reference_link
(
project:
12345
,
issue:
12345
,
reference_filter:
'IssueReferenceFilter'
)
expect
{
pipeline_result
(
link
)
}.
not_to
raise_error
expect
{
pipeline_result
(
link
)
}.
not_to
raise_error
end
end
...
@@ -49,7 +49,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
...
@@ -49,7 +49,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
user
=
create
(
:user
)
user
=
create
(
:user
)
group
=
create
(
:group
)
group
=
create
(
:group
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
'UserReferenceFilter'
)
result
=
pipeline_result
(
link
,
current_user:
user
)
result
=
pipeline_result
(
link
,
current_user:
user
)
expect
(
result
[
:references
][
:user
]).
to
be_empty
expect
(
result
[
:references
][
:user
]).
to
be_empty
...
@@ -60,14 +60,14 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
...
@@ -60,14 +60,14 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
group
=
create
(
:group
)
group
=
create
(
:group
)
group
.
add_developer
(
user
)
group
.
add_developer
(
user
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
group:
group
.
id
,
reference_filter:
'UserReferenceFilter'
)
result
=
pipeline_result
(
link
,
current_user:
user
)
result
=
pipeline_result
(
link
,
current_user:
user
)
expect
(
result
[
:references
][
:user
]).
to
eq
([
user
])
expect
(
result
[
:references
][
:user
]).
to
eq
([
user
])
end
end
it
'handles invalid Group references'
do
it
'handles invalid Group references'
do
link
=
reference_link
(
group:
12345
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
group:
12345
,
reference_filter:
'UserReferenceFilter'
)
expect
{
pipeline_result
(
link
)
}.
not_to
raise_error
expect
{
pipeline_result
(
link
)
}.
not_to
raise_error
end
end
...
@@ -77,7 +77,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
...
@@ -77,7 +77,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
it
'allows any User reference'
do
it
'allows any User reference'
do
user
=
create
(
:user
)
user
=
create
(
:user
)
link
=
reference_link
(
user:
user
.
id
,
reference_filter:
Gitlab
::
Markdown
::
UserReferenceFilter
.
name
)
link
=
reference_link
(
user:
user
.
id
,
reference_filter:
'UserReferenceFilter'
)
result
=
pipeline_result
(
link
)
result
=
pipeline_result
(
link
)
expect
(
result
[
:references
][
:user
]).
to
eq
([
user
])
expect
(
result
[
:references
][
:user
]).
to
eq
([
user
])
...
...
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