diff options
Diffstat (limited to 'spec/support/filter_spec_helper.rb')
-rw-r--r-- | spec/support/filter_spec_helper.rb | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/spec/support/filter_spec_helper.rb b/spec/support/filter_spec_helper.rb index 97e5c270a59..d6e03cbef3d 100644 --- a/spec/support/filter_spec_helper.rb +++ b/spec/support/filter_spec_helper.rb @@ -1,4 +1,4 @@ -# Helper methods for Gitlab::Markdown filter specs +# Helper methods for Banzai filter specs # # Must be included into specs manually module FilterSpecHelper @@ -10,36 +10,49 @@ module FilterSpecHelper # if none is provided. # # html - HTML String to pass to the filter's `call` method. - # contexts - Hash context for the filter. (default: {project: project}) + # context - Hash context for the filter. (default: {project: project}) # # Returns a Nokogiri::XML::DocumentFragment - def filter(html, contexts = {}) + def filter(html, context = {}) if defined?(project) - contexts.reverse_merge!(project: project) + context.reverse_merge!(project: project) end - described_class.call(html, contexts) + described_class.call(html, context) end # Run text through HTML::Pipeline with the current filter and return the # result Hash # # body - String text to run through the pipeline - # contexts - Hash context for the filter. (default: {project: project}) + # context - Hash context for the filter. (default: {project: project}) # # Returns the Hash - def pipeline_result(body, contexts = {}) - contexts.reverse_merge!(project: project) if defined?(project) + def pipeline_result(body, context = {}) + context.reverse_merge!(project: project) if defined?(project) - pipeline = HTML::Pipeline.new([described_class], contexts) + pipeline = HTML::Pipeline.new([described_class], context) pipeline.call(body) end - def reference_pipeline_result(body, contexts = {}) - contexts.reverse_merge!(project: project) if defined?(project) + def reference_pipeline(context = {}) + context.reverse_merge!(project: project) if defined?(project) - pipeline = HTML::Pipeline.new([described_class, Gitlab::Markdown::ReferenceGathererFilter], contexts) - pipeline.call(body) + filters = [ + Banzai::Filter::AutolinkFilter, + described_class, + Banzai::Filter::ReferenceGathererFilter + ] + + HTML::Pipeline.new(filters, context) + end + + def reference_pipeline_result(body, context = {}) + reference_pipeline(context).call(body) + end + + def reference_filter(html, context = {}) + reference_pipeline(context).to_document(html) end # Modify a String reference to make it invalid |