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'
...
@@ -2,11 +2,9 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
AutolinkFilter
do
describe
AutolinkFilter
do
let
(
:link
)
{
'http://about.gitlab.com/'
}
include
FilterSpecHelper
def
filter
(
html
,
options
=
{})
let
(
:link
)
{
'http://about.gitlab.com/'
}
described_class
.
call
(
html
,
options
)
end
it
'does nothing when :autolink is false'
do
it
'does nothing when :autolink is false'
do
exp
=
act
=
link
exp
=
act
=
link
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
79c4e389
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
CommitRangeReferenceFilter
do
describe
CommitRangeReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit1
)
{
project
.
commit
}
let
(
:commit1
)
{
project
.
commit
}
...
...
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
View file @
79c4e389
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
CommitReferenceFilter
do
describe
CommitReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit
)
{
project
.
commit
}
let
(
:commit
)
{
project
.
commit
}
...
...
spec/lib/gitlab/markdown/emoji_filter_spec.rb
View file @
79c4e389
...
@@ -2,9 +2,7 @@ require 'spec_helper'
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
EmojiFilter
do
describe
EmojiFilter
do
def
filter
(
html
,
contexts
=
{})
include
FilterSpecHelper
described_class
.
call
(
html
,
contexts
)
end
before
do
before
do
ActionController
::
Base
.
asset_host
=
'https://foo.com'
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'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
ExternalIssueReferenceFilter
do
describe
ExternalIssueReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
def
helper
def
helper
IssuesHelper
IssuesHelper
...
...
spec/lib/gitlab/markdown/external_link_filter_spec.rb
View file @
79c4e389
...
@@ -2,9 +2,7 @@ require 'spec_helper'
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
ExternalLinkFilter
do
describe
ExternalLinkFilter
do
def
filter
(
html
,
options
=
{})
include
FilterSpecHelper
described_class
.
call
(
html
,
options
)
end
it
'ignores elements without an href attribute'
do
it
'ignores elements without an href attribute'
do
exp
=
act
=
%q(<a id="ignored">Ignore Me</a>)
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'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
IssueReferenceFilter
do
describe
IssueReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
def
helper
def
helper
IssuesHelper
IssuesHelper
...
...
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
View file @
79c4e389
...
@@ -3,7 +3,7 @@ require 'html/pipeline'
...
@@ -3,7 +3,7 @@ require 'html/pipeline'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
LabelReferenceFilter
do
describe
LabelReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:label
)
{
create
(
:label
,
project:
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'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
MergeRequestReferenceFilter
do
describe
MergeRequestReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:merge
)
{
create
(
:merge_request
,
source_project:
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'
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
SanitizationFilter
do
describe
SanitizationFilter
do
def
filter
(
html
,
options
=
{})
include
FilterSpecHelper
described_class
.
call
(
html
,
options
)
end
describe
'default whitelist'
do
describe
'default whitelist'
do
it
'sanitizes tags that are not whitelisted'
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'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
SnippetReferenceFilter
do
describe
SnippetReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
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'
...
@@ -4,9 +4,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
TableOfContentsFilter
do
describe
TableOfContentsFilter
do
def
filter
(
html
,
options
=
{})
include
FilterSpecHelper
described_class
.
call
(
html
,
options
)
end
def
header
(
level
,
text
)
def
header
(
level
,
text
)
"<h
#{
level
}
>
#{
text
}
</h
#{
level
}
>
\n
"
"<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'
...
@@ -2,9 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
TaskListFilter
do
describe
TaskListFilter
do
def
filter
(
html
,
options
=
{})
include
FilterSpecHelper
described_class
.
call
(
html
,
options
)
end
it
'does not apply `task-list` class to non-task lists'
do
it
'does not apply `task-list` class to non-task lists'
do
exp
=
act
=
%(<ul><li>Item</li></ul>)
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'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
module
Gitlab::Markdown
module
Gitlab::Markdown
describe
UserReferenceFilter
do
describe
UserReferenceFilter
do
include
Reference
FilterSpecHelper
include
FilterSpecHelper
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
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
# Must be included into specs manually
module
Reference
FilterSpecHelper
module
FilterSpecHelper
extend
ActiveSupport
::
Concern
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
# Perform `call` on the described class
#
#
# Automatically passes the current `project` value
to the context if none is
# Automatically passes the current `project` value
, if defined, to the context
# provided.
#
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})
# 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
=
{})
def
filter
(
html
,
contexts
=
{})
contexts
.
reverse_merge!
(
project:
project
)
if
defined?
(
project
)
contexts
.
reverse_merge!
(
project:
project
)
end
described_class
.
call
(
html
,
contexts
)
described_class
.
call
(
html
,
contexts
)
end
end
...
@@ -50,7 +27,7 @@ module ReferenceFilterSpecHelper
...
@@ -50,7 +27,7 @@ module ReferenceFilterSpecHelper
# body - String text to run through the pipeline
# body - String text to run through the pipeline
# contexts - Hash context for the filter. (default: {project: project})
# contexts - Hash context for the filter. (default: {project: project})
#
#
# Returns the Hash
of the pipeline result
# Returns the Hash
def
pipeline_result
(
body
,
contexts
=
{})
def
pipeline_result
(
body
,
contexts
=
{})
contexts
.
reverse_merge!
(
project:
project
)
contexts
.
reverse_merge!
(
project:
project
)
...
@@ -58,13 +35,43 @@ module ReferenceFilterSpecHelper
...
@@ -58,13 +35,43 @@ module ReferenceFilterSpecHelper
pipeline
.
call
(
body
)
pipeline
.
call
(
body
)
end
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!
def
allow_cross_reference!
allow_any_instance_of
(
described_class
).
allow_any_instance_of
(
described_class
).
to
receive
(
:user_can_reference_project?
).
and_return
(
true
)
to
receive
(
:user_can_reference_project?
).
and_return
(
true
)
end
end
# Stub CrossProjectReference#user_can_reference_project? to return false for
# the current test
def
disallow_cross_reference!
def
disallow_cross_reference!
allow_any_instance_of
(
described_class
).
allow_any_instance_of
(
described_class
).
to
receive
(
:user_can_reference_project?
).
and_return
(
false
)
to
receive
(
:user_can_reference_project?
).
and_return
(
false
)
end
end
# Shortcut to Rails' auto-generated routes helpers, to avoid including the
# module
def
urls
Rails
.
application
.
routes
.
url_helpers
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