BigW Consortium Gitlab

Commit 611912fe by Robert Speicher

Store the demodulized reference filter name in data attribute

parent d611a387
......@@ -31,7 +31,7 @@ module Gitlab
return unless node.has_attribute?('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]
......
......@@ -57,14 +57,14 @@ module Gitlab
# Examples:
#
# 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-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
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(" ")
end
......
......@@ -20,7 +20,7 @@ describe Gitlab::Markdown::RedactorFilter do
user = create(:user)
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)
expect(doc.css('a').length).to eq 0
......@@ -31,14 +31,14 @@ describe Gitlab::Markdown::RedactorFilter do
project = create(:empty_project)
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)
expect(doc.css('a').length).to eq 1
end
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
end
......@@ -51,7 +51,7 @@ describe Gitlab::Markdown::RedactorFilter do
user = create(:user)
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)
expect(doc.css('a').length).to eq 0
......@@ -62,14 +62,14 @@ describe Gitlab::Markdown::RedactorFilter do
group = create(:group)
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)
expect(doc.css('a').length).to eq 1
end
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
end
......@@ -79,7 +79,7 @@ describe Gitlab::Markdown::RedactorFilter do
it 'allows any User reference' do
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)
expect(doc.css('a').length).to eq 1
......
......@@ -16,7 +16,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
project = create(:empty_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)
expect(result[:references][:issue]).to be_empty
......@@ -28,14 +28,14 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
issue = create(:issue, project: project)
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)
expect(result[:references][:issue]).to eq([issue])
end
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
end
......@@ -49,7 +49,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
user = create(:user)
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)
expect(result[:references][:user]).to be_empty
......@@ -60,14 +60,14 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
group = create(:group)
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)
expect(result[:references][:user]).to eq([user])
end
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
end
......@@ -77,7 +77,7 @@ describe Gitlab::Markdown::ReferenceGathererFilter do
it 'allows any User reference' do
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)
expect(result[:references][:user]).to eq([user])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment