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
Léo-Paul Géneau
gitlab-ce
Commits
79c4e389
Commit
79c4e389
authored
Jun 02, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ReferenceFilterSpecHelper to FilterSpecHelper
And make it more generalized for all filter specs.
parent
442a0663
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
56 additions
and
61 deletions
+56
-61
spec/lib/gitlab/markdown/autolink_filter_spec.rb
spec/lib/gitlab/markdown/autolink_filter_spec.rb
+2
-4
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/emoji_filter_spec.rb
spec/lib/gitlab/markdown/emoji_filter_spec.rb
+1
-3
spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb
...b/gitlab/markdown/external_issue_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/external_link_filter_spec.rb
spec/lib/gitlab/markdown/external_link_filter_spec.rb
+1
-3
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
...ib/gitlab/markdown/merge_request_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/sanitization_filter_spec.rb
spec/lib/gitlab/markdown/sanitization_filter_spec.rb
+1
-3
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+1
-1
spec/lib/gitlab/markdown/table_of_contents_filter_spec.rb
spec/lib/gitlab/markdown/table_of_contents_filter_spec.rb
+1
-3
spec/lib/gitlab/markdown/task_list_filter_spec.rb
spec/lib/gitlab/markdown/task_list_filter_spec.rb
+1
-3
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
+1
-1
spec/support/filter_spec_helper.rb
spec/support/filter_spec_helper.rb
+41
-34
No files found.
spec/lib/gitlab/markdown/autolink_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,11 +2,9 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
AutolinkFilter
do
let
(
:link
)
{
'http://about.gitlab.com/'
}
include
FilterSpecHelper
def
filter
(
html
,
options
=
{})
described_class
.
call
(
html
,
options
)
end
let
(
:link
)
{
'http://about.gitlab.com/'
}
it
'does nothing when :autolink is false'
do
exp
=
act
=
link
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
CommitRangeReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit1
)
{
project
.
commit
}
...
...
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
CommitReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit
)
{
project
.
commit
}
...
...
spec/lib/gitlab/markdown/emoji_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
EmojiFilter
do
def
filter
(
html
,
contexts
=
{})
described_class
.
call
(
html
,
contexts
)
end
include
FilterSpecHelper
before
do
ActionController
::
Base
.
asset_host
=
'https://foo.com'
...
...
spec/lib/gitlab/markdown/external_issue_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
ExternalIssueReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
def
helper
IssuesHelper
...
...
spec/lib/gitlab/markdown/external_link_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
ExternalLinkFilter
do
def
filter
(
html
,
options
=
{})
described_class
.
call
(
html
,
options
)
end
include
FilterSpecHelper
it
'ignores elements without an href attribute'
do
exp
=
act
=
%q(<a id="ignored">Ignore Me</a>)
...
...
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
IssueReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
def
helper
IssuesHelper
...
...
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -3,7 +3,7 @@ require 'html/pipeline'
module
Gitlab::Markdown
describe
LabelReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
)
}
...
...
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
MergeRequestReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
)
}
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
project
)
}
...
...
spec/lib/gitlab/markdown/sanitization_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
SanitizationFilter
do
def
filter
(
html
,
options
=
{})
described_class
.
call
(
html
,
options
)
end
include
FilterSpecHelper
describe
'default whitelist'
do
it
'sanitizes tags that are not whitelisted'
do
...
...
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
SnippetReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
...
...
spec/lib/gitlab/markdown/table_of_contents_filter_spec.rb
View file @
79c4e389
...
...
@@ -4,9 +4,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
TableOfContentsFilter
do
def
filter
(
html
,
options
=
{})
described_class
.
call
(
html
,
options
)
end
include
FilterSpecHelper
def
header
(
level
,
text
)
"<h
#{
level
}
>
#{
text
}
</h
#{
level
}
>
\n
"
...
...
spec/lib/gitlab/markdown/task_list_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
TaskListFilter
do
def
filter
(
html
,
options
=
{})
described_class
.
call
(
html
,
options
)
end
include
FilterSpecHelper
it
'does not apply `task-list` class to non-task lists'
do
exp
=
act
=
%(<ul><li>Item</li></ul>)
...
...
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
View file @
79c4e389
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
describe
UserReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
spec/support/
reference_
filter_spec_helper.rb
→
spec/support/filter_spec_helper.rb
View file @
79c4e389
#
Common methods and setup for Gitlab::Markdown reference
filter specs
#
Helper methods for Gitlab::Markdown
filter specs
#
# Must be included into specs manually
module
Reference
FilterSpecHelper
module
FilterSpecHelper
extend
ActiveSupport
::
Concern
# Shortcut to Rails' auto-generated routes helpers, to avoid including the
# module
def
urls
Rails
.
application
.
routes
.
url_helpers
end
# Modify a String reference to make it invalid
#
# Commit SHAs get reversed, IDs get incremented by 1, all other Strings get
# their word characters reversed.
#
# reference - String reference to modify
#
# Returns a String
def
invalidate_reference
(
reference
)
if
reference
=~
/\A(.+)?.\d+\z/
# Integer-based reference with optional project prefix
reference
.
gsub
(
/\d+\z/
)
{
|
i
|
i
.
to_i
+
1
}
elsif
reference
=~
/\A(.+@)?(\h{6,40}\z)/
# SHA-based reference with optional prefix
reference
.
gsub
(
/\h{6,40}\z/
)
{
|
v
|
v
.
reverse
}
else
reference
.
gsub
(
/\w+\z/
)
{
|
v
|
v
.
reverse
}
end
end
# Perform `call` on the described class
#
# Automatically passes the current `project` value
to the context if none is
# provided.
# Automatically passes the current `project` value
, if defined, to the context
#
if none is
provided.
#
# html -
String text
to pass to the filter's `call` method.
# html -
HTML String
to pass to the filter's `call` method.
# contexts - Hash context for the filter. (default: {project: project})
#
# Returns
the String text returned by the filter's `call` method.
# Returns
a Nokogiri::XML::DocumentFragment
def
filter
(
html
,
contexts
=
{})
contexts
.
reverse_merge!
(
project:
project
)
if
defined?
(
project
)
contexts
.
reverse_merge!
(
project:
project
)
end
described_class
.
call
(
html
,
contexts
)
end
...
...
@@ -50,7 +27,7 @@ module ReferenceFilterSpecHelper
# body - String text to run through the pipeline
# contexts - Hash context for the filter. (default: {project: project})
#
# Returns the Hash
of the pipeline result
# Returns the Hash
def
pipeline_result
(
body
,
contexts
=
{})
contexts
.
reverse_merge!
(
project:
project
)
...
...
@@ -58,13 +35,43 @@ module ReferenceFilterSpecHelper
pipeline
.
call
(
body
)
end
# Modify a String reference to make it invalid
#
# Commit SHAs get reversed, IDs get incremented by 1, all other Strings get
# their word characters reversed.
#
# reference - String reference to modify
#
# Returns a String
def
invalidate_reference
(
reference
)
if
reference
=~
/\A(.+)?.\d+\z/
# Integer-based reference with optional project prefix
reference
.
gsub
(
/\d+\z/
)
{
|
i
|
i
.
to_i
+
1
}
elsif
reference
=~
/\A(.+@)?(\h{6,40}\z)/
# SHA-based reference with optional prefix
reference
.
gsub
(
/\h{6,40}\z/
)
{
|
v
|
v
.
reverse
}
else
reference
.
gsub
(
/\w+\z/
)
{
|
v
|
v
.
reverse
}
end
end
# Stub CrossProjectReference#user_can_reference_project? to return true for
# the current test
def
allow_cross_reference!
allow_any_instance_of
(
described_class
).
to
receive
(
:user_can_reference_project?
).
and_return
(
true
)
end
# Stub CrossProjectReference#user_can_reference_project? to return false for
# the current test
def
disallow_cross_reference!
allow_any_instance_of
(
described_class
).
to
receive
(
:user_can_reference_project?
).
and_return
(
false
)
end
# Shortcut to Rails' auto-generated routes helpers, to avoid including the
# module
def
urls
Rails
.
application
.
routes
.
url_helpers
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