summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-02 13:27:53 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-06-02 13:27:53 -0400
commit79c4e3899fa7697afdefb13d64c4add08ca84aac (patch)
tree86c31089d42859765b9b63acecba3b233fa5a0f1 /spec/support
parent442a0663da437abcdec7fbd86967b6d8980d4090 (diff)
downloadgitlab-ce-79c4e3899fa7697afdefb13d64c4add08ca84aac.tar.gz
Rename ReferenceFilterSpecHelper to FilterSpecHelper
And make it more generalized for all filter specs.
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/filter_spec_helper.rb (renamed from spec/support/reference_filter_spec_helper.rb)75
1 files changed, 41 insertions, 34 deletions
diff --git a/spec/support/reference_filter_spec_helper.rb b/spec/support/filter_spec_helper.rb
index afbea55ab99..755964e9a3d 100644
--- a/spec/support/reference_filter_spec_helper.rb
+++ b/spec/support/filter_spec_helper.rb
@@ -1,46 +1,23 @@
-# Common methods and setup for Gitlab::Markdown reference filter specs
+# Helper methods for Gitlab::Markdown filter specs
#
# Must be included into specs manually
-module ReferenceFilterSpecHelper
+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