diff options
Diffstat (limited to 'spec/lib/banzai')
69 files changed, 2542 insertions, 2542 deletions
diff --git a/spec/lib/banzai/color_parser_spec.rb b/spec/lib/banzai/color_parser_spec.rb index af2a8f215c1..127560d9319 100644 --- a/spec/lib/banzai/color_parser_spec.rb +++ b/spec/lib/banzai/color_parser_spec.rb @@ -1,13 +1,13 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ColorParser do - describe '.parse' do - context 'HEX format' do + describe ".parse" do + context "HEX format" do [ - '#abc', '#ABC', - '#d2d2d2', '#D2D2D2', - '#123a', '#123A', - '#123456aa', '#123456AA' + "#abc", "#ABC", + "#d2d2d2", "#D2D2D2", + "#123a", "#123A", + "#123456aa", "#123456AA", ].each do |color| it "parses the valid hex color #{color}" do expect(subject.parse(color)).to eq(color) @@ -15,10 +15,10 @@ describe Banzai::ColorParser do end [ - '#', '#1', '#12', '#12g', '#12G', - '#12345', '#r2r2r2', '#R2R2R2', '#1234567', - '# 123', '# 1234', '# 123456', '# 12345678', - '#1 2 3', '#123 4', '#12 34 56', '#123456 78' + "#", "#1", "#12", "#12g", "#12G", + "#12345", "#r2r2r2", "#R2R2R2", "#1234567", + "# 123", "# 1234", "# 123456", "# 12345678", + "#1 2 3", "#123 4", "#12 34 56", "#123456 78", ].each do |color| it "does not parse the invalid hex color #{color}" do expect(subject.parse(color)).to be_nil @@ -26,15 +26,15 @@ describe Banzai::ColorParser do end end - context 'RGB format' do + context "RGB format" do [ - 'rgb(0,0,0)', 'rgb(255,255,255)', - 'rgb(0, 0, 0)', 'RGB(0,0,0)', - 'rgb(0,0,0,0)', 'rgb(0,0,0,0.0)', 'rgb(0,0,0,.0)', - 'rgb(0,0,0, 0)', 'rgb(0,0,0, 0.0)', 'rgb(0,0,0, .0)', - 'rgb(0,0,0,1)', 'rgb(0,0,0,1.0)', - 'rgba(0,0,0)', 'rgba(0,0,0,0)', 'RGBA(0,0,0)', - 'rgb(0%,0%,0%)', 'rgba(0%,0%,0%,0%)' + "rgb(0,0,0)", "rgb(255,255,255)", + "rgb(0, 0, 0)", "RGB(0,0,0)", + "rgb(0,0,0,0)", "rgb(0,0,0,0.0)", "rgb(0,0,0,.0)", + "rgb(0,0,0, 0)", "rgb(0,0,0, 0.0)", "rgb(0,0,0, .0)", + "rgb(0,0,0,1)", "rgb(0,0,0,1.0)", + "rgba(0,0,0)", "rgba(0,0,0,0)", "RGBA(0,0,0)", + "rgb(0%,0%,0%)", "rgba(0%,0%,0%,0%)", ].each do |color| it "parses the valid rgb color #{color}" do expect(subject.parse(color)).to eq(color) @@ -42,12 +42,12 @@ describe Banzai::ColorParser do end [ - 'FOOrgb(0,0,0)', 'rgb(0,0,0)BAR', - 'rgb(0,0,-1)', 'rgb(0,0,-0)', 'rgb(0,0,256)', - 'rgb(0,0,0,-0.1)', 'rgb(0,0,0,-0.0)', 'rgb(0,0,0,-.1)', - 'rgb(0,0,0,1.1)', 'rgb(0,0,0,2)', - 'rgba(0,0,0,)', 'rgba(0,0,0,0.)', 'rgba(0,0,0,1.)', - 'rgb(0,0,0%)', 'rgb(101%,0%,0%)' + "FOOrgb(0,0,0)", "rgb(0,0,0)BAR", + "rgb(0,0,-1)", "rgb(0,0,-0)", "rgb(0,0,256)", + "rgb(0,0,0,-0.1)", "rgb(0,0,0,-0.0)", "rgb(0,0,0,-.1)", + "rgb(0,0,0,1.1)", "rgb(0,0,0,2)", + "rgba(0,0,0,)", "rgba(0,0,0,0.)", "rgba(0,0,0,1.)", + "rgb(0,0,0%)", "rgb(101%,0%,0%)", ].each do |color| it "does not parse the invalid rgb color #{color}" do expect(subject.parse(color)).to be_nil @@ -55,18 +55,18 @@ describe Banzai::ColorParser do end end - context 'HSL format' do + context "HSL format" do [ - 'hsl(0,0%,0%)', 'hsl(0,100%,100%)', - 'hsl(540,0%,0%)', 'hsl(-720,0%,0%)', - 'hsl(0deg,0%,0%)', 'hsl(0DEG,0%,0%)', - 'hsl(0, 0%, 0%)', 'HSL(0,0%,0%)', - 'hsl(0,0%,0%,0)', 'hsl(0,0%,0%,0.0)', 'hsl(0,0%,0%,.0)', - 'hsl(0,0%,0%, 0)', 'hsl(0,0%,0%, 0.0)', 'hsl(0,0%,0%, .0)', - 'hsl(0,0%,0%,1)', 'hsl(0,0%,0%,1.0)', - 'hsla(0,0%,0%)', 'hsla(0,0%,0%,0)', 'HSLA(0,0%,0%)', - 'hsl(1rad,0%,0%)', 'hsl(1.1rad,0%,0%)', 'hsl(.1rad,0%,0%)', - 'hsl(-1rad,0%,0%)', 'hsl(1RAD,0%,0%)' + "hsl(0,0%,0%)", "hsl(0,100%,100%)", + "hsl(540,0%,0%)", "hsl(-720,0%,0%)", + "hsl(0deg,0%,0%)", "hsl(0DEG,0%,0%)", + "hsl(0, 0%, 0%)", "HSL(0,0%,0%)", + "hsl(0,0%,0%,0)", "hsl(0,0%,0%,0.0)", "hsl(0,0%,0%,.0)", + "hsl(0,0%,0%, 0)", "hsl(0,0%,0%, 0.0)", "hsl(0,0%,0%, .0)", + "hsl(0,0%,0%,1)", "hsl(0,0%,0%,1.0)", + "hsla(0,0%,0%)", "hsla(0,0%,0%,0)", "HSLA(0,0%,0%)", + "hsl(1rad,0%,0%)", "hsl(1.1rad,0%,0%)", "hsl(.1rad,0%,0%)", + "hsl(-1rad,0%,0%)", "hsl(1RAD,0%,0%)", ].each do |color| it "parses the valid hsl color #{color}" do expect(subject.parse(color)).to eq(color) @@ -74,12 +74,12 @@ describe Banzai::ColorParser do end [ - 'hsl(+0,0%,0%)', 'hsl(0,0,0%)', 'hsl(0,0%,0)', 'hsl(0 deg,0%,0%)', - 'hsl(0,-0%,0%)', 'hsl(0,101%,0%)', 'hsl(0,-1%,0%)', - 'hsl(0,0%,0%,-0.1)', 'hsl(0,0%,0%,-.1)', - 'hsl(0,0%,0%,1.1)', 'hsl(0,0%,0%,2)', - 'hsl(0,0%,0%,)', 'hsl(0,0%,0%,0.)', 'hsl(0,0%,0%,1.)', - 'hsl(deg,0%,0%)', 'hsl(rad,0%,0%)' + "hsl(+0,0%,0%)", "hsl(0,0,0%)", "hsl(0,0%,0)", "hsl(0 deg,0%,0%)", + "hsl(0,-0%,0%)", "hsl(0,101%,0%)", "hsl(0,-1%,0%)", + "hsl(0,0%,0%,-0.1)", "hsl(0,0%,0%,-.1)", + "hsl(0,0%,0%,1.1)", "hsl(0,0%,0%,2)", + "hsl(0,0%,0%,)", "hsl(0,0%,0%,0.)", "hsl(0,0%,0%,1.)", + "hsl(deg,0%,0%)", "hsl(rad,0%,0%)", ].each do |color| it "does not parse the invalid hsl color #{color}" do expect(subject.parse(color)).to be_nil diff --git a/spec/lib/banzai/commit_renderer_spec.rb b/spec/lib/banzai/commit_renderer_spec.rb index 1f53657c59c..9abfc660c31 100644 --- a/spec/lib/banzai/commit_renderer_spec.rb +++ b/spec/lib/banzai/commit_renderer_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::CommitRenderer do - describe '.render' do - it 'renders a commit description and title' do + describe ".render" do + it "renders a commit description and title" do user = build(:user) project = create(:project, :repository) diff --git a/spec/lib/banzai/cross_project_reference_spec.rb b/spec/lib/banzai/cross_project_reference_spec.rb index ba995e16be7..e4f9c5f748f 100644 --- a/spec/lib/banzai/cross_project_reference_spec.rb +++ b/spec/lib/banzai/cross_project_reference_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::CrossProjectReference do let(:including_class) { Class.new.include(described_class).new } @@ -8,41 +8,41 @@ describe Banzai::CrossProjectReference do allow(including_class).to receive(:parent_from_ref).and_call_original end - describe '#parent_from_ref' do - context 'when no project was referenced' do - it 'returns the project from context' do + describe "#parent_from_ref" do + context "when no project was referenced" do + it "returns the project from context" do project = double - allow(including_class).to receive(:context).and_return({ project: project }) + allow(including_class).to receive(:context).and_return({project: project}) expect(including_class.parent_from_ref(nil)).to eq project end end - context 'when no project was referenced in group context' do - it 'returns the group from context' do + context "when no project was referenced in group context" do + it "returns the group from context" do group = double - allow(including_class).to receive(:context).and_return({ group: group }) + allow(including_class).to receive(:context).and_return({group: group}) expect(including_class.parent_from_ref(nil)).to eq group end end - context 'when referenced project does not exist' do - it 'returns nil' do - expect(including_class.parent_from_ref('invalid/reference')).to be_nil + context "when referenced project does not exist" do + it "returns nil" do + expect(including_class.parent_from_ref("invalid/reference")).to be_nil end end - context 'when referenced project exists' do - it 'returns the referenced project' do - project2 = double('referenced project') + context "when referenced project exists" do + it "returns the referenced project" do + project2 = double("referenced project") expect(Project).to receive(:find_by_full_path) - .with('cross/reference').and_return(project2) + .with("cross/reference").and_return(project2) - expect(including_class.parent_from_ref('cross/reference')).to eq project2 + expect(including_class.parent_from_ref("cross/reference")).to eq project2 end end end diff --git a/spec/lib/banzai/filter/absolute_link_filter_spec.rb b/spec/lib/banzai/filter/absolute_link_filter_spec.rb index 50be551cd90..08d5d8a9244 100644 --- a/spec/lib/banzai/filter/absolute_link_filter_spec.rb +++ b/spec/lib/banzai/filter/absolute_link_filter_spec.rb @@ -1,58 +1,58 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::AbsoluteLinkFilter do def filter(doc, context = {}) described_class.call(doc, context) end - context 'with html links' do - context 'if only_path is false' do + context "with html links" do + context "if only_path is false" do let(:only_path_context) do - { only_path: false } + {only_path: false} end - let(:fake_url) { 'http://www.example.com' } + let(:fake_url) { "http://www.example.com" } before do allow(Gitlab.config.gitlab).to receive(:url).and_return(fake_url) end - context 'has the .gfm class' do - it 'converts a relative url into absolute' do - doc = filter(link('/foo', 'gfm'), only_path_context) - expect(doc.at_css('a')['href']).to eq "#{fake_url}/foo" + context "has the .gfm class" do + it "converts a relative url into absolute" do + doc = filter(link("/foo", "gfm"), only_path_context) + expect(doc.at_css("a")["href"]).to eq "#{fake_url}/foo" end - it 'does not change the url if it already absolute' do - doc = filter(link("#{fake_url}/foo", 'gfm'), only_path_context) - expect(doc.at_css('a')['href']).to eq "#{fake_url}/foo" + it "does not change the url if it already absolute" do + doc = filter(link("#{fake_url}/foo", "gfm"), only_path_context) + expect(doc.at_css("a")["href"]).to eq "#{fake_url}/foo" end - context 'if relative_url_root is set' do - it 'joins the url without doubling the path' do + context "if relative_url_root is set" do + it "joins the url without doubling the path" do allow(Gitlab.config.gitlab).to receive(:url).and_return("#{fake_url}/gitlab/") - doc = filter(link("/gitlab/foo", 'gfm'), only_path_context) - expect(doc.at_css('a')['href']).to eq "#{fake_url}/gitlab/foo" + doc = filter(link("/gitlab/foo", "gfm"), only_path_context) + expect(doc.at_css("a")["href"]).to eq "#{fake_url}/gitlab/foo" end end end - context 'has not the .gfm class' do - it 'does not convert a relative url into absolute' do - doc = filter(link('/foo'), only_path_context) - expect(doc.at_css('a')['href']).to eq '/foo' + context "has not the .gfm class" do + it "does not convert a relative url into absolute" do + doc = filter(link("/foo"), only_path_context) + expect(doc.at_css("a")["href"]).to eq "/foo" end end end - context 'if only_path is not false' do - it 'does not convert a relative url into absolute' do - expect(filter(link('/foo', 'gfm')).at_css('a')['href']).to eq '/foo' - expect(filter(link('/foo')).at_css('a')['href']).to eq '/foo' + context "if only_path is not false" do + it "does not convert a relative url into absolute" do + expect(filter(link("/foo", "gfm")).at_css("a")["href"]).to eq "/foo" + expect(filter(link("/foo")).at_css("a")["href"]).to eq "/foo" end end end - def link(path, css_class = '') + def link(path, css_class = "") %(<a class="#{css_class}" href="#{path}">example</a>) end end diff --git a/spec/lib/banzai/filter/abstract_reference_filter_spec.rb b/spec/lib/banzai/filter/abstract_reference_filter_spec.rb index 1e82d18d056..459818e6016 100644 --- a/spec/lib/banzai/filter/abstract_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/abstract_reference_filter_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::AbstractReferenceFilter do let(:project) { create(:project) } - describe '#references_per_parent' do - it 'returns a Hash containing references grouped per parent paths' do + describe "#references_per_parent" do + it "returns a Hash containing references grouped per parent paths" do doc = Nokogiri::HTML.fragment("#1 #{project.full_path}#2") filter = described_class.new(doc, project: project) @@ -18,44 +18,44 @@ describe Banzai::Filter::AbstractReferenceFilter do end end - describe '#parent_per_reference' do - it 'returns a Hash containing projects grouped per parent paths' do - doc = Nokogiri::HTML.fragment('') + describe "#parent_per_reference" do + it "returns a Hash containing projects grouped per parent paths" do + doc = Nokogiri::HTML.fragment("") filter = described_class.new(doc, project: project) expect(filter).to receive(:references_per_parent) - .and_return({ project.full_path => Set.new(%w[1]) }) + .and_return({project.full_path => Set.new(%w[1])}) expect(filter.parent_per_reference) - .to eq({ project.full_path => project }) + .to eq({project.full_path => project}) end end - describe '#find_for_paths' do - let(:doc) { Nokogiri::HTML.fragment('') } + describe "#find_for_paths" do + let(:doc) { Nokogiri::HTML.fragment("") } let(:filter) { described_class.new(doc, project: project) } - context 'with RequestStore disabled' do - it 'returns a list of Projects for a list of paths' do + context "with RequestStore disabled" do + it "returns a list of Projects for a list of paths" do expect(filter.find_for_paths([project.full_path])) .to eq([project]) end it "return an empty array for paths that don't exist" do - expect(filter.find_for_paths(['nonexistent/project'])) + expect(filter.find_for_paths(["nonexistent/project"])) .to eq([]) end end - context 'with RequestStore enabled', :request_store do - it 'returns a list of Projects for a list of paths' do + context "with RequestStore enabled", :request_store do + it "returns a list of Projects for a list of paths" do expect(filter.find_for_paths([project.full_path])) .to eq([project]) end context "when no project with that path exists" do it "returns no value" do - expect(filter.find_for_paths(['nonexistent/project'])) + expect(filter.find_for_paths(["nonexistent/project"])) .to eq([]) end @@ -63,19 +63,19 @@ describe Banzai::Filter::AbstractReferenceFilter do project_refs_cache = {} allow(filter).to receive(:refs_cache).and_return(project_refs_cache) - filter.find_for_paths(['nonexistent/project']) + filter.find_for_paths(["nonexistent/project"]) - expect(project_refs_cache).to eq({ 'nonexistent/project' => nil }) + expect(project_refs_cache).to eq({"nonexistent/project" => nil}) end - context 'when the project refs cache includes nil values' do + context "when the project refs cache includes nil values" do before do # adds { 'nonexistent/project' => nil } to cache - filter.from_ref_cached('nonexistent/project') + filter.from_ref_cached("nonexistent/project") end it "return an empty array for paths that don't exist" do - expect(filter.find_for_paths(['nonexistent/project'])) + expect(filter.find_for_paths(["nonexistent/project"])) .to eq([]) end end @@ -83,9 +83,9 @@ describe Banzai::Filter::AbstractReferenceFilter do end end - describe '#current_parent_path' do - it 'returns the path of the current parent' do - doc = Nokogiri::HTML.fragment('') + describe "#current_parent_path" do + it "returns the path of the current parent" do + doc = Nokogiri::HTML.fragment("") filter = described_class.new(doc, project: project) expect(filter.current_parent_path).to eq(project.full_path) diff --git a/spec/lib/banzai/filter/ascii_doc_post_processing_filter_spec.rb b/spec/lib/banzai/filter/ascii_doc_post_processing_filter_spec.rb index 34f1657b6d3..abf0e63d512 100644 --- a/spec/lib/banzai/filter/ascii_doc_post_processing_filter_spec.rb +++ b/spec/lib/banzai/filter/ascii_doc_post_processing_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::AsciiDocPostProcessingFilter do include FilterSpecHelper @@ -9,7 +9,7 @@ describe Banzai::Filter::AsciiDocPostProcessingFilter do end it "keeps content when no data-math-style found" do - result = filter('<pre>some code</pre><div data-math>and</div>').to_html - expect(result).to eq('<pre>some code</pre><div data-math>and</div>') + result = filter("<pre>some code</pre><div data-math>and</div>").to_html + expect(result).to eq("<pre>some code</pre><div data-math>and</div>") end end diff --git a/spec/lib/banzai/filter/autolink_filter_spec.rb b/spec/lib/banzai/filter/autolink_filter_spec.rb index 4972c4b4bd2..4b95e0839f2 100644 --- a/spec/lib/banzai/filter/autolink_filter_spec.rb +++ b/spec/lib/banzai/filter/autolink_filter_spec.rb @@ -1,141 +1,141 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::AutolinkFilter do include FilterSpecHelper - let(:link) { 'http://about.gitlab.com/' } + let(:link) { "http://about.gitlab.com/" } let(:quotes) { ['"', "'"] } - it 'does nothing when :autolink is false' do + it "does nothing when :autolink is false" do exp = act = link expect(filter(act, autolink: false).to_html).to eq exp end - it 'does nothing with non-link text' do - exp = act = 'This text contains no links to autolink' + it "does nothing with non-link text" do + exp = act = "This text contains no links to autolink" expect(filter(act).to_html).to eq exp end - context 'Various schemes' do - it 'autolinks http' do + context "Various schemes" do + it "autolinks http" do doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'autolinks https' do - link = 'https://google.com/' + it "autolinks https" do + link = "https://google.com/" doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'autolinks ftp' do - link = 'ftp://ftp.us.debian.org/debian/' + it "autolinks ftp" do + link = "ftp://ftp.us.debian.org/debian/" doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'autolinks short URLs' do - link = 'http://localhost:3000/' + it "autolinks short URLs" do + link = "http://localhost:3000/" doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'autolinks multiple URLs' do - link1 = 'http://localhost:3000/' - link2 = 'http://google.com/' + it "autolinks multiple URLs" do + link1 = "http://localhost:3000/" + link2 = "http://google.com/" doc = filter("See #{link1} and #{link2}") - found_links = doc.css('a') + found_links = doc.css("a") expect(found_links.size).to eq(2) expect(found_links[0].text).to eq(link1) - expect(found_links[0]['href']).to eq(link1) + expect(found_links[0]["href"]).to eq(link1) expect(found_links[1].text).to eq(link2) - expect(found_links[1]['href']).to eq(link2) + expect(found_links[1]["href"]).to eq(link2) end - it 'accepts link_attr options' do - doc = filter("See #{link}", link_attr: { class: 'custom' }) + it "accepts link_attr options" do + doc = filter("See #{link}", link_attr: {class: "custom"}) - expect(doc.at_css('a')['class']).to eq 'custom' + expect(doc.at_css("a")["class"]).to eq "custom" end - it 'autolinks smb' do - link = 'smb:///Volumes/shared/foo.pdf' + it "autolinks smb" do + link = "smb:///Volumes/shared/foo.pdf" doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'autolinks multiple occurrences of smb' do - link1 = 'smb:///Volumes/shared/foo.pdf' - link2 = 'smb:///Volumes/shared/bar.pdf' + it "autolinks multiple occurrences of smb" do + link1 = "smb:///Volumes/shared/foo.pdf" + link2 = "smb:///Volumes/shared/bar.pdf" doc = filter("See #{link1} and #{link2}") - found_links = doc.css('a') + found_links = doc.css("a") expect(found_links.size).to eq(2) expect(found_links[0].text).to eq(link1) - expect(found_links[0]['href']).to eq(link1) + expect(found_links[0]["href"]).to eq(link1) expect(found_links[1].text).to eq(link2) - expect(found_links[1]['href']).to eq(link2) + expect(found_links[1]["href"]).to eq(link2) end - it 'autolinks irc' do - link = 'irc://irc.freenode.net/git' + it "autolinks irc" do + link = "irc://irc.freenode.net/git" doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'autolinks rdar' do - link = 'rdar://localhost.com/blah' + it "autolinks rdar" do + link = "rdar://localhost.com/blah" doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq link - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a").text).to eq link + expect(doc.at_css("a")["href"]).to eq link end - it 'does not autolink javascript' do - link = 'javascript://alert(document.cookie);' + it "does not autolink javascript" do + link = "javascript://alert(document.cookie);" doc = filter("See #{link}") - expect(doc.at_css('a')).to be_nil + expect(doc.at_css("a")).to be_nil end - it 'does not autolink bad URLs' do - link = 'foo://23423:::asdf' + it "does not autolink bad URLs" do + link = "foo://23423:::asdf" doc = filter("See #{link}") expect(doc.to_s).to eq("See #{link}") end - it 'does not autolink bad URLs after we remove trailing punctuation' do - link = 'http://]' + it "does not autolink bad URLs after we remove trailing punctuation" do + link = "http://]" doc = filter("See #{link}") expect(doc.to_s).to eq("See #{link}") end - it 'does not include trailing punctuation' do - ['.', ', ok?', '...', '?', '!', ': is that ok?'].each do |trailing_punctuation| + it "does not include trailing punctuation" do + [".", ", ok?", "...", "?", "!", ": is that ok?"].each do |trailing_punctuation| doc = filter("See #{link}#{trailing_punctuation}") - expect(doc.at_css('a').text).to eq link + expect(doc.at_css("a").text).to eq link end end - it 'includes trailing punctuation when part of a balanced pair' do + it "includes trailing punctuation when part of a balanced pair" do described_class::PUNCTUATION_PAIRS.each do |close, open| next if open.in?(quotes) @@ -144,71 +144,71 @@ describe Banzai::Filter::AutolinkFilter do unbalanced_link = "#{link}#{close}" unbalanced_actual = filter("See #{unbalanced_link}...") - expect(balanced_actual.at_css('a').text).to eq(balanced_link) + expect(balanced_actual.at_css("a").text).to eq(balanced_link) expect(unescape(balanced_actual.to_html)).to eq(Rinku.auto_link("See #{balanced_link}...")) - expect(unbalanced_actual.at_css('a').text).to eq(link) + expect(unbalanced_actual.at_css("a").text).to eq(link) expect(unescape(unbalanced_actual.to_html)).to eq(Rinku.auto_link("See #{unbalanced_link}...")) end end - it 'removes trailing quotes' do + it "removes trailing quotes" do quotes.each do |quote| balanced_link = "#{link}#{quote}abc#{quote}" balanced_actual = filter("See #{balanced_link}...") unbalanced_link = "#{link}#{quote}" unbalanced_actual = filter("See #{unbalanced_link}...") - expect(balanced_actual.at_css('a').text).to eq(balanced_link[0...-1]) + expect(balanced_actual.at_css("a").text).to eq(balanced_link[0...-1]) expect(unescape(balanced_actual.to_html)).to eq(Rinku.auto_link("See #{balanced_link}...")) - expect(unbalanced_actual.at_css('a').text).to eq(link) + expect(unbalanced_actual.at_css("a").text).to eq(link) expect(unescape(unbalanced_actual.to_html)).to eq(Rinku.auto_link("See #{unbalanced_link}...")) end end - it 'removes one closing punctuation mark when the punctuation in the link is unbalanced' do + it "removes one closing punctuation mark when the punctuation in the link is unbalanced" do complicated_link = "(#{link}(a'b[c'd]))'" - expected_complicated_link = %Q{(<a href="#{link}(a'b[c'd]))">#{link}(a'b[c'd]))</a>'} + expected_complicated_link = %{(<a href="#{link}(a'b[c'd]))">#{link}(a'b[c'd]))</a>'} actual = unescape(filter(complicated_link).to_html) expect(actual).to eq(Rinku.auto_link(complicated_link)) expect(actual).to eq(expected_complicated_link) end - it 'does not double-encode HTML entities' do + it "does not double-encode HTML entities" do encoded_link = "#{link}?foo=bar&baz=quux" - expected_encoded_link = %Q{<a href="#{encoded_link}">#{encoded_link}</a>} + expected_encoded_link = %(<a href="#{encoded_link}">#{encoded_link}</a>) actual = unescape(filter(encoded_link).to_html) expect(actual).to eq(Rinku.auto_link(encoded_link)) expect(actual).to eq(expected_encoded_link) end - it 'does not include trailing HTML entities' do + it "does not include trailing HTML entities" do doc = filter("See <<<#{link}>>>") - expect(doc.at_css('a')['href']).to eq link + expect(doc.at_css("a")["href"]).to eq link expect(doc.text).to eq "See <<<#{link}>>>" end - it 'accepts link_attr options' do - doc = filter("See #{link}", link_attr: { class: 'custom' }) - expect(doc.at_css('a')['class']).to eq 'custom' + it "accepts link_attr options" do + doc = filter("See #{link}", link_attr: {class: "custom"}) + expect(doc.at_css("a")["class"]).to eq "custom" end - it 'escapes RTLO and other characters' do + it "escapes RTLO and other characters" do # rendered text looks like "http://example.com/evilexe.mp3" evil_link = "#{link}evil\u202E3pm.exe" - doc = filter("#{evil_link}") + doc = filter(evil_link.to_s) - expect(doc.at_css('a')['href']).to eq "http://about.gitlab.com/evil%E2%80%AE3pm.exe" + expect(doc.at_css("a")["href"]).to eq "http://about.gitlab.com/evil%E2%80%AE3pm.exe" end - it 'encodes international domains' do + it "encodes international domains" do link = "http://one😄two.com" expected = "http://one%F0%9F%98%84two.com" doc = filter(link) - expect(doc.at_css('a')['href']).to eq expected + expect(doc.at_css("a")["href"]).to eq expected end described_class::IGNORE_PARENTS.each do |elem| @@ -219,12 +219,12 @@ describe Banzai::Filter::AutolinkFilter do end end - context 'when the link is inside a tag' do + context "when the link is inside a tag" do %w[http rdar].each do |protocol| it "renders text after the link correctly for #{protocol}" do doc = filter(ERB::Util.html_escape_once("<#{protocol}://link><another>")) - expect(doc.children.last.text).to include('<another>') + expect(doc.children.last.text).to include("<another>") end end end diff --git a/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb b/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb index b645e49bd43..1a7e5cafd33 100644 --- a/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb +++ b/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb @@ -1,18 +1,18 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Filter::BlockquoteFenceFilter do include FilterSpecHelper - it 'converts blockquote fences to blockquote lines' do - content = File.read(Rails.root.join('spec/fixtures/blockquote_fence_before.md')) - expected = File.read(Rails.root.join('spec/fixtures/blockquote_fence_after.md')) + it "converts blockquote fences to blockquote lines" do + content = File.read(Rails.root.join("spec/fixtures/blockquote_fence_before.md")) + expected = File.read(Rails.root.join("spec/fixtures/blockquote_fence_after.md")) output = filter(content) expect(output).to eq(expected) end - it 'allows trailing whitespace on blockquote fence lines' do + it "allows trailing whitespace on blockquote fence lines" do expect(filter(">>> \ntest\n>>> ")).to eq("> test") end end diff --git a/spec/lib/banzai/filter/color_filter_spec.rb b/spec/lib/banzai/filter/color_filter_spec.rb index a098b037510..975dca0c94c 100644 --- a/spec/lib/banzai/filter/color_filter_spec.rb +++ b/spec/lib/banzai/filter/color_filter_spec.rb @@ -1,54 +1,54 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::ColorFilter, lib: true do include FilterSpecHelper - let(:color) { '#F00' } - let(:color_chip_selector) { 'code > span.gfm-color_chip > span' } + let(:color) { "#F00" } + let(:color_chip_selector) { "code > span.gfm-color_chip > span" } - ['#123', '#1234', '#123456', '#12345678', - 'rgb(0,0,0)', 'RGB(0, 0, 0)', 'rgba(0,0,0,1)', 'RGBA(0,0,0,0.7)', - 'hsl(270,30%,50%)', 'HSLA(270, 30%, 50%, .7)'].each do |color| + ["#123", "#1234", "#123456", "#12345678", + "rgb(0,0,0)", "RGB(0, 0, 0)", "rgba(0,0,0,1)", "RGBA(0,0,0,0.7)", + "hsl(270,30%,50%)", "HSLA(270, 30%, 50%, .7)",].each do |color| it "inserts color chip for supported color format #{color}" do content = code_tag(color) doc = filter(content) color_chip = doc.at_css(color_chip_selector) expect(color_chip.content).to be_empty - expect(color_chip.parent[:class]).to eq 'gfm-color_chip' + expect(color_chip.parent[:class]).to eq "gfm-color_chip" expect(color_chip[:style]).to eq "background-color: #{color};" end end - it 'ignores valid color code without backticks(code tags)' do + it "ignores valid color code without backticks(code tags)" do doc = filter(color) - expect(doc.css('span.gfm-color_chip').size).to be_zero + expect(doc.css("span.gfm-color_chip").size).to be_zero end - it 'ignores valid color code with prepended space' do - content = code_tag(' ' + color) + it "ignores valid color code with prepended space" do + content = code_tag(" " + color) doc = filter(content) expect(doc.css(color_chip_selector).size).to be_zero end - it 'ignores valid color code with appended space' do - content = code_tag(color + ' ') + it "ignores valid color code with appended space" do + content = code_tag(color + " ") doc = filter(content) expect(doc.css(color_chip_selector).size).to be_zero end - it 'ignores valid color code surrounded by spaces' do - content = code_tag(' ' + color + ' ') + it "ignores valid color code surrounded by spaces" do + content = code_tag(" " + color + " ") doc = filter(content) expect(doc.css(color_chip_selector).size).to be_zero end - it 'ignores invalid color code' do - invalid_color = '#BAR' + it "ignores invalid color code" do + invalid_color = "#BAR" content = code_tag(invalid_color) doc = filter(content) diff --git a/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb index 4daf6be1bb7..ad1f05ff2af 100644 --- a/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::CommitRangeReferenceFilter do include FilterSpecHelper @@ -10,53 +10,53 @@ describe Banzai::Filter::CommitRangeReferenceFilter do let(:range) { CommitRange.new("#{commit1.id}...#{commit2.id}", project) } let(:range2) { CommitRange.new("#{commit1.id}..#{commit2.id}", project) } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Commit Range #{range.to_reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - context 'internal reference' do + context "internal reference" do let(:reference) { range.to_reference } let(:reference2) { range2.to_reference } - it 'links to a valid two-dot reference' do + it "links to a valid two-dot reference" do doc = reference_filter("See #{reference2}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_compare_url(project, range2.to_param) end - it 'links to a valid three-dot reference' do + it "links to a valid three-dot reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_compare_url(project, range.to_param) end - it 'links to a valid short ID' do + it "links to a valid short ID" do reference = "#{commit1.short_id}...#{commit2.id}" reference2 = "#{commit1.id}...#{commit2.short_id}" - exp = commit1.short_id + '...' + commit2.short_id + exp = commit1.short_id + "..." + commit2.short_id - expect(reference_filter("See #{reference}").css('a').first.text).to eq exp - expect(reference_filter("See #{reference2}").css('a').first.text).to eq exp + expect(reference_filter("See #{reference}").css("a").first.text).to eq exp + expect(reference_filter("See #{reference2}").css("a").first.text).to eq exp end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("See (#{reference}.)") exp = Regexp.escape(range.reference_link_text) expect(doc.to_html).to match(%r{\(<a.+>#{exp}</a>\.\)}) end - it 'ignores invalid commit IDs' do + it "ignores invalid commit IDs" do exp = act = "See #{commit1.id.reverse}...#{commit2.id}" allow(project.repository).to receive(:commit).with(commit1.id.reverse) @@ -64,66 +64,66 @@ describe Banzai::Filter::CommitRangeReferenceFilter do expect(reference_filter(act).to_html).to eq exp end - it 'includes no title attribute' do + it "includes no title attribute" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('title')).to eq "" + expect(doc.css("a").first.attr("title")).to eq "" end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-commit_range has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-commit_range has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-commit-range attribute' do + it "includes a data-commit-range attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-commit-range') - expect(link.attr('data-commit-range')).to eq range.to_s + expect(link).to have_attribute("data-commit-range") + expect(link.attr("data-commit-range")).to eq range.to_s end - it 'supports an :only_path option' do + it "supports an :only_path option" do doc = reference_filter("See #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq urls.project_compare_url(project, from: commit1.id, to: commit2.id, only_path: true) end end - context 'cross-project / cross-namespace complete reference' do + context "cross-project / cross-namespace complete reference" do let(:project2) { create(:project, :public, :repository) } let(:reference) { "#{project2.full_path}@#{commit1.id}...#{commit2.id}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_compare_url(project2, range.to_param) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eql("#{project2.full_path}@#{commit1.short_id}...#{commit2.short_id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eql("Fixed (#{project2.full_path}@#{commit1.short_id}...#{commit2.short_id}.)") end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Fixed #{project2.full_path}@#{commit1.id.reverse}...#{commit2.id}" expect(reference_filter(act).to_html).to eq exp @@ -132,33 +132,33 @@ describe Banzai::Filter::CommitRangeReferenceFilter do end end - context 'cross-project / same-namespace complete reference' do + context "cross-project / same-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, :repository, namespace: namespace) } let(:project2) { create(:project, :public, :repository, path: "same-namespace", namespace: namespace) } let(:reference) { "#{project2.path}@#{commit1.id}...#{commit2.id}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_compare_url(project2, range.to_param) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eql("#{project2.path}@#{commit1.short_id}...#{commit2.short_id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eql("Fixed (#{project2.path}@#{commit1.short_id}...#{commit2.short_id}.)") end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Fixed #{project2.path}@#{commit1.id.reverse}...#{commit2.id}" expect(reference_filter(act).to_html).to eq exp @@ -167,33 +167,33 @@ describe Banzai::Filter::CommitRangeReferenceFilter do end end - context 'cross-project shorthand reference' do + context "cross-project shorthand reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, :repository, namespace: namespace) } let(:project2) { create(:project, :public, :repository, path: "same-namespace", namespace: namespace) } let(:reference) { "#{project2.path}@#{commit1.id}...#{commit2.id}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_compare_url(project2, range.to_param) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eql("#{project2.path}@#{commit1.short_id}...#{commit2.short_id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eql("Fixed (#{project2.path}@#{commit1.short_id}...#{commit2.short_id}.)") end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Fixed #{project2.path}@#{commit1.id.reverse}...#{commit2.id}" expect(reference_filter(act).to_html).to eq exp @@ -202,31 +202,31 @@ describe Banzai::Filter::CommitRangeReferenceFilter do end end - context 'cross-project URL reference' do + context "cross-project URL reference" do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:range) { CommitRange.new("#{commit1.id}...master", project) } - let(:reference) { urls.project_compare_url(project2, from: commit1.id, to: 'master') } + let(:reference) { urls.project_compare_url(project2, from: commit1.id, to: "master") } before do range.project = project2 end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq reference end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Fixed (#{reference}.)") exp = Regexp.escape(range.reference_link_text(project)) expect(doc.to_html).to match(%r{\(<a.+>#{exp}</a>\.\)}) end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Fixed #{project2.to_reference}@#{commit1.id.reverse}...#{commit2.id}" expect(reference_filter(act).to_html).to eq exp @@ -235,19 +235,19 @@ describe Banzai::Filter::CommitRangeReferenceFilter do end end - context 'group context' do - let(:context) { { project: nil, group: create(:group) } } + context "group context" do + let(:context) { {project: nil, group: create(:group)} } - it 'ignores internal references' do + it "ignores internal references" do exp = act = "See #{range.to_reference}" expect(reference_filter(act, context).to_html).to eq exp end - it 'links to a full-path reference' do + it "links to a full-path reference" do reference = "#{project.full_path}@#{commit1.short_id}...#{commit2.short_id}" - expect(reference_filter("See #{reference}", context).css('a').first.text).to eql(reference) + expect(reference_filter("See #{reference}", context).css("a").first.text).to eql(reference) end end end diff --git a/spec/lib/banzai/filter/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_reference_filter_spec.rb index d6c9e9e4b19..1e100665f7a 100644 --- a/spec/lib/banzai/filter/commit_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::CommitReferenceFilter do include FilterSpecHelper @@ -6,18 +6,18 @@ describe Banzai::Filter::CommitReferenceFilter do let(:project) { create(:project, :public, :repository) } let(:commit) { project.commit } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Commit #{commit.id}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - context 'internal reference' do + context "internal reference" do let(:reference) { commit.id } # Let's test a variety of commit SHA sizes just to be paranoid @@ -25,13 +25,13 @@ describe Banzai::Filter::CommitReferenceFilter do it "links to a valid reference of #{size} characters" do doc = reference_filter("See #{reference[0...size]}") - expect(doc.css('a').first.text).to eq commit.short_id - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.text).to eq commit.short_id + expect(doc.css("a").first.attr("href")) .to eq urls.project_commit_url(project, reference) end end - it 'always uses the short ID as the link text' do + it "always uses the short ID as the link text" do doc = reference_filter("See #{commit.id}") expect(doc.text).to eq "See #{commit.short_id}" @@ -39,57 +39,57 @@ describe Banzai::Filter::CommitReferenceFilter do expect(doc.text).to eq "See #{commit.short_id}" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("See (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{commit.short_id}</a>\.\)}) end - it 'ignores invalid commit IDs' do + it "ignores invalid commit IDs" do invalid = invalidate_reference(reference) exp = act = "See #{invalid}" expect(reference_filter(act).to_html).to eq exp end - it 'includes a title attribute' do + it "includes a title attribute" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('title')).to eq commit.title + expect(doc.css("a").first.attr("title")).to eq commit.title end - it 'escapes the title attribute' do - allow_any_instance_of(Commit).to receive(:title).and_return(%{"></a>whatever<a title="}) + it "escapes the title attribute" do + allow_any_instance_of(Commit).to receive(:title).and_return(%("></a>whatever<a title=")) doc = reference_filter("See #{reference}") expect(doc.text).to eq "See #{commit.short_id}" end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-commit has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-commit has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-commit attribute' do + it "includes a data-commit attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-commit') - expect(link.attr('data-commit')).to eq commit.id + expect(link).to have_attribute("data-commit") + expect(link.attr("data-commit")).to eq commit.id end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = reference_filter("See #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq urls.project_commit_url(project, reference, only_path: true) end @@ -97,161 +97,161 @@ describe Banzai::Filter::CommitReferenceFilter do let(:noteable) { create(:merge_request, target_project: project, source_project: project) } let(:commit) { noteable.commits.first } - it 'handles merge request contextual commit references' do + it "handles merge request contextual commit references" do url = urls.diffs_project_merge_request_url(project, noteable, commit_id: commit.id) doc = reference_filter("See #{reference}", noteable: noteable) - expect(doc.css('a').first[:href]).to eq(url) + expect(doc.css("a").first[:href]).to eq(url) end end end - context 'cross-project / cross-namespace complete reference' do + context "cross-project / cross-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:commit) { project2.commit } let(:reference) { "#{project2.full_path}@#{commit.short_id}" } - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text).to eql("#{project2.full_path}@#{commit.short_id}") + expect(doc.css("a").first.text).to eql("#{project2.full_path}@#{commit.short_id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text).to eql("See (#{project2.full_path}@#{commit.short_id}.)") end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Committed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project / same-namespace complete reference' do + context "cross-project / same-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, namespace: namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:commit) { project2.commit } let(:reference) { "#{project2.full_path}@#{commit.short_id}" } - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text).to eql("#{project2.path}@#{commit.short_id}") + expect(doc.css("a").first.text).to eql("#{project2.path}@#{commit.short_id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text).to eql("See (#{project2.path}@#{commit.short_id}.)") end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Committed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project shorthand reference' do + context "cross-project shorthand reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, namespace: namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:commit) { project2.commit } let(:reference) { "#{project2.full_path}@#{commit.short_id}" } - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text).to eql("#{project2.path}@#{commit.short_id}") + expect(doc.css("a").first.text).to eql("#{project2.path}@#{commit.short_id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text).to eql("See (#{project2.path}@#{commit.short_id}.)") end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do exp = act = "Committed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project URL reference' do + context "cross-project URL reference" do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:commit) { project2.commit } let(:reference) { urls.project_commit_url(project2, commit.id) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_commit_url(project2, commit.id) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{commit.reference_link_text(project)}</a>\.\)}) end - it 'ignores invalid commit IDs on the referenced project' do + it "ignores invalid commit IDs on the referenced project" do act = "Committed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to match(%r{<a.+>#{Regexp.escape(invalidate_reference(reference))}</a>}) end end - context 'URL reference for a commit patch' do + context "URL reference for a commit patch" do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:commit) { project2.commit } let(:link) { urls.project_commit_url(project2, commit.id) } - let(:extension) { '.patch' } + let(:extension) { ".patch" } let(:reference) { link + extension } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq reference end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See #{reference}") expect(doc.text).to eq("See #{commit.reference_link_text(project)} (patch)") end - it 'does not link to patch when extension match is after the path' do + it "does not link to patch when extension match is after the path" do invalidate_commit_reference = reference_filter("#{link}/builds.patch") doc = reference_filter("See (#{invalidate_commit_reference})") - expect(doc.css('a').first.attr('href')).to eq "#{link}/builds" + expect(doc.css("a").first.attr("href")).to eq "#{link}/builds" expect(doc.text).to eq("See (#{commit.reference_link_text(project)} (builds).patch)") end end - context 'group context' do - let(:context) { { project: nil, group: create(:group) } } + context "group context" do + let(:context) { {project: nil, group: create(:group)} } - it 'ignores internal references' do + it "ignores internal references" do exp = act = "See #{commit.id}" expect(reference_filter(act, context).to_html).to eq exp end - it 'links to a valid reference' do + it "links to a valid reference" do act = "See #{project.full_path}@#{commit.id}" - expect(reference_filter(act, context).css('a').first.text).to eql("#{project.full_path}@#{commit.short_id}") + expect(reference_filter(act, context).css("a").first.text).to eql("#{project.full_path}@#{commit.short_id}") end end end diff --git a/spec/lib/banzai/filter/commit_trailers_filter_spec.rb b/spec/lib/banzai/filter/commit_trailers_filter_spec.rb index 068cdc85a07..6c49825a949 100644 --- a/spec/lib/banzai/filter/commit_trailers_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_trailers_filter_spec.rb @@ -1,5 +1,5 @@ -require 'spec_helper' -require 'ffaker' +require "spec_helper" +require "ffaker" describe Banzai::Filter::CommitTrailersFilter do include FilterSpecHelper @@ -13,16 +13,16 @@ describe Banzai::Filter::CommitTrailersFilter do let(:commit_message) { trailer_line(trailer, user.name, user.email) } let(:commit_message_html) { commit_html(commit_message) } - context 'detects' do + context "detects" do let(:email) { FFaker::Internet.email } - it 'trailers in the form of *-by and replace users with links' do + it "trailers in the form of *-by and replace users with links" do doc = filter(commit_message_html) expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer) end - it 'trailers prefixed with whitespaces' do + it "trailers prefixed with whitespaces" do message_html = commit_html("\n\r #{commit_message}") doc = filter(message_html) @@ -30,7 +30,7 @@ describe Banzai::Filter::CommitTrailersFilter do expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer) end - it 'GitLab users via a secondary email' do + it "GitLab users via a secondary email" do _, message_html = build_commit_message( trailer: trailer, name: secondary_email.user.name, @@ -47,9 +47,9 @@ describe Banzai::Filter::CommitTrailersFilter do ) end - context 'non GitLab users' do - shared_examples 'mailto links' do - it 'replaces them with mailto links' do + context "non GitLab users" do + shared_examples "mailto links" do + it "replaces them with mailto links" do _, message_html = build_commit_message( trailer: trailer, name: FFaker::Name.name, @@ -62,24 +62,24 @@ describe Banzai::Filter::CommitTrailersFilter do end end - context 'when Gravatar is disabled' do + context "when Gravatar is disabled" do before do stub_application_setting(gravatar_enabled: false) end - it_behaves_like 'mailto links' + it_behaves_like "mailto links" end - context 'when Gravatar is enabled' do + context "when Gravatar is enabled" do before do stub_application_setting(gravatar_enabled: true) end - it_behaves_like 'mailto links' + it_behaves_like "mailto links" end end - it 'multiple trailers in the same message' do + it "multiple trailers in the same message" do different_trailer = "#{FFaker::Lorem.word}-by:" message = commit_html %( #{commit_message} @@ -92,11 +92,11 @@ describe Banzai::Filter::CommitTrailersFilter do expect_to_have_mailto_link_with_avatar(doc, email: email, trailer: different_trailer) end - context 'special names' do + context "special names" do where(:name) do [ - 'John S. Doe', - 'L33t H@x0r' + "John S. Doe", + "L33t H@x0r", ] end @@ -118,33 +118,33 @@ describe Banzai::Filter::CommitTrailersFilter do end context "ignores" do - it 'commit messages without trailers' do + it "commit messages without trailers" do exp = message = commit_html(FFaker::Lorem.sentence) doc = filter(message) expect(doc.to_html).to match Regexp.escape(exp) end - it 'trailers that are inline the commit message body' do + it "trailers that are inline the commit message body" do message = commit_html %( #{FFaker::Lorem.sentence} #{commit_message} #{FFaker::Lorem.sentence} ) doc = filter(message) - expect(doc.css('a').size).to eq 0 + expect(doc.css("a").size).to eq 0 end end context "structure" do - it 'preserves the commit trailer structure' do + it "preserves the commit trailer structure" do doc = filter(commit_message_html) expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer) expect(doc.text).to match Regexp.escape(commit_message) end - it 'preserves the original name used in the commit message' do + it "preserves the original name used in the commit message" do message, message_html = build_commit_message( trailer: trailer, name: FFaker::Name.name, @@ -157,7 +157,7 @@ describe Banzai::Filter::CommitTrailersFilter do expect(doc.text).to match Regexp.escape(message) end - it 'preserves the original email used in the commit message' do + it "preserves the original email used in the commit message" do message, message_html = build_commit_message( trailer: trailer, name: secondary_email.user.name, @@ -175,7 +175,7 @@ describe Banzai::Filter::CommitTrailersFilter do expect(doc.text).to match Regexp.escape(message) end - it 'only replaces trailer lines not the full commit message' do + it "only replaces trailer lines not the full commit message" do commit_body = FFaker::Lorem.paragraph message = commit_html %( #{commit_body} diff --git a/spec/lib/banzai/filter/emoji_filter_spec.rb b/spec/lib/banzai/filter/emoji_filter_spec.rb index 85a4619e33d..aa66d35db07 100644 --- a/spec/lib/banzai/filter/emoji_filter_spec.rb +++ b/spec/lib/banzai/filter/emoji_filter_spec.rb @@ -1,103 +1,103 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::EmojiFilter do include FilterSpecHelper - it 'replaces supported name emoji' do - doc = filter('<p>:heart:</p>') - expect(doc.css('gl-emoji').first.text).to eq '❤' + it "replaces supported name emoji" do + doc = filter("<p>:heart:</p>") + expect(doc.css("gl-emoji").first.text).to eq "❤" end - it 'replaces supported unicode emoji' do - doc = filter('<p>❤️</p>') - expect(doc.css('gl-emoji').first.text).to eq '❤' + it "replaces supported unicode emoji" do + doc = filter("<p>❤️</p>") + expect(doc.css("gl-emoji").first.text).to eq "❤" end - it 'ignores unsupported emoji' do - exp = act = '<p>:foo:</p>' + it "ignores unsupported emoji" do + exp = act = "<p>:foo:</p>" doc = filter(act) expect(doc.to_html).to match Regexp.escape(exp) end - it 'correctly encodes the URL' do - doc = filter('<p>:+1:</p>') - expect(doc.css('gl-emoji').first.text).to eq '👍' + it "correctly encodes the URL" do + doc = filter("<p>:+1:</p>") + expect(doc.css("gl-emoji").first.text).to eq "👍" end - it 'correctly encodes unicode to the URL' do - doc = filter('<p>👍</p>') - expect(doc.css('gl-emoji').first.text).to eq '👍' + it "correctly encodes unicode to the URL" do + doc = filter("<p>👍</p>") + expect(doc.css("gl-emoji").first.text).to eq "👍" end - it 'matches at the start of a string' do - doc = filter(':+1:') - expect(doc.css('gl-emoji').size).to eq 1 + it "matches at the start of a string" do + doc = filter(":+1:") + expect(doc.css("gl-emoji").size).to eq 1 end - it 'unicode matches at the start of a string' do + it "unicode matches at the start of a string" do doc = filter("'👍'") - expect(doc.css('gl-emoji').size).to eq 1 + expect(doc.css("gl-emoji").size).to eq 1 end - it 'matches at the end of a string' do - doc = filter('This gets a :-1:') - expect(doc.css('gl-emoji').size).to eq 1 + it "matches at the end of a string" do + doc = filter("This gets a :-1:") + expect(doc.css("gl-emoji").size).to eq 1 end - it 'unicode matches at the end of a string' do - doc = filter('This gets a 👍') - expect(doc.css('gl-emoji').size).to eq 1 + it "unicode matches at the end of a string" do + doc = filter("This gets a 👍") + expect(doc.css("gl-emoji").size).to eq 1 end - it 'matches with adjacent text' do - doc = filter('+1 (:+1:)') - expect(doc.css('gl-emoji').size).to eq 1 + it "matches with adjacent text" do + doc = filter("+1 (:+1:)") + expect(doc.css("gl-emoji").size).to eq 1 end - it 'unicode matches with adjacent text' do - doc = filter('+1 (👍)') - expect(doc.css('gl-emoji').size).to eq 1 + it "unicode matches with adjacent text" do + doc = filter("+1 (👍)") + expect(doc.css("gl-emoji").size).to eq 1 end - it 'does not match multiple emoji in a row' do - doc = filter(':see_no_evil::hear_no_evil::speak_no_evil:') - expect(doc.css('gl-emoji').size).to eq 0 + it "does not match multiple emoji in a row" do + doc = filter(":see_no_evil::hear_no_evil::speak_no_evil:") + expect(doc.css("gl-emoji").size).to eq 0 end - it 'unicode matches multiple emoji in a row' do + it "unicode matches multiple emoji in a row" do doc = filter("'🙈🙉🙊'") - expect(doc.css('gl-emoji').size).to eq 3 + expect(doc.css("gl-emoji").size).to eq 3 end - it 'mixed matches multiple emoji in a row' do + it "mixed matches multiple emoji in a row" do doc = filter("'🙈:see_no_evil:🙉:hear_no_evil:🙊:speak_no_evil:'") - expect(doc.css('gl-emoji').size).to eq 6 + expect(doc.css("gl-emoji").size).to eq 6 end - it 'does not match emoji in a string' do + it "does not match emoji in a string" do doc = filter("'2a00:a4c0:100::1'") - expect(doc.css('gl-emoji').size).to eq 0 + expect(doc.css("gl-emoji").size).to eq 0 end - it 'has a data-name attribute' do - doc = filter(':-1:') - expect(doc.css('gl-emoji').first.attr('data-name')).to eq 'thumbsdown' + it "has a data-name attribute" do + doc = filter(":-1:") + expect(doc.css("gl-emoji").first.attr("data-name")).to eq "thumbsdown" end - it 'has a data-unicode-version attribute' do - doc = filter(':-1:') - expect(doc.css('gl-emoji').first.attr('data-unicode-version')).to eq '6.0' + it "has a data-unicode-version attribute" do + doc = filter(":-1:") + expect(doc.css("gl-emoji").first.attr("data-unicode-version")).to eq "6.0" end - it 'keeps whitespace intact' do - doc = filter('This deserves a :+1:, big time.') + it "keeps whitespace intact" do + doc = filter("This deserves a :+1:, big time.") expect(doc.to_html).to match(/^This deserves a <gl-emoji.+>, big time\.\z/) end - it 'unicode keeps whitespace intact' do - doc = filter('This deserves a 🎱, big time.') + it "unicode keeps whitespace intact" do + doc = filter("This deserves a 🎱, big time.") expect(doc.to_html).to match(/^This deserves a <gl-emoji.+>, big time\.\z/) end diff --git a/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb index 43222ddb5e2..5db9aff0b40 100644 --- a/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::ExternalIssueReferenceFilter do include FilterSpecHelper @@ -8,13 +8,13 @@ describe Banzai::Filter::ExternalIssueReferenceFilter do end shared_examples_for "external issue tracker" do - it_behaves_like 'a reference containing an element node' + it_behaves_like "a reference containing an element node" - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Issue #{reference}</#{elem}>" @@ -22,79 +22,79 @@ describe Banzai::Filter::ExternalIssueReferenceFilter do end end - it 'ignores valid references when using default tracker' do + it "ignores valid references when using default tracker" do expect(project).to receive(:default_issues_tracker?).and_return(true) exp = act = "Issue #{reference}" expect(filter(act).to_html).to eq exp end - it 'links to a valid reference' do + it "links to a valid reference" do doc = filter("Issue #{reference}") - issue_id = doc.css('a').first.attr("data-external-issue") + issue_id = doc.css("a").first.attr("data-external-issue") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue_id, project) end - it 'links to the external tracker' do + it "links to the external tracker" do doc = filter("Issue #{reference}") - link = doc.css('a').first.attr('href') - issue_id = doc.css('a').first.attr("data-external-issue") + link = doc.css("a").first.attr("href") + issue_id = doc.css("a").first.attr("data-external-issue") expect(link).to eq(helper.url_for_issue(issue_id, project)) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = filter("Issue (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{reference}</a>\.\)}) end - it 'includes a title attribute' do + it "includes a title attribute" do doc = filter("Issue #{reference}") - expect(doc.css('a').first.attr('title')).to include("Issue in #{project.issues_tracker.title}") + expect(doc.css("a").first.attr("title")).to include("Issue in #{project.issues_tracker.title}") end - it 'escapes the title attribute' do + it "escapes the title attribute" do allow(project.external_issue_tracker).to receive(:title) - .and_return(%{"></a>whatever<a title="}) + .and_return(%("></a>whatever<a title=")) doc = filter("Issue #{reference}") expect(doc.text).to eq "Issue #{reference}" end - it 'includes default classes' do + it "includes default classes" do doc = filter("Issue #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = filter("Issue #{reference}", only_path: true) - link = doc.css('a').first.attr('href') - issue_id = doc.css('a').first["data-external-issue"] + link = doc.css("a").first.attr("href") + issue_id = doc.css("a").first["data-external-issue"] expect(link).to eq helper.url_for_issue(issue_id, project, only_path: true) end - context 'with RequestStore enabled', :request_store do + context "with RequestStore enabled", :request_store do let(:reference_filter) { HTML::Pipeline.new([described_class]) } - it 'queries the collection on the first call' do + it "queries the collection on the first call" do expect_any_instance_of(Project).to receive(:default_issues_tracker?).once.and_call_original expect_any_instance_of(Project).to receive(:external_issue_reference_pattern).once.and_call_original - not_cached = reference_filter.call("look for #{reference}", { project: project }) + not_cached = reference_filter.call("look for #{reference}", {project: project}) expect_any_instance_of(Project).not_to receive(:default_issues_tracker?) expect_any_instance_of(Project).not_to receive(:external_issue_reference_pattern) - cached = reference_filter.call("look for #{reference}", { project: project }) + cached = reference_filter.call("look for #{reference}", {project: project}) # Links must be the same - expect(cached[:output].css('a').first[:href]).to eq(not_cached[:output].css('a').first[:href]) + expect(cached[:output].css("a").first[:href]).to eq(not_cached[:output].css("a").first[:href]) end end end diff --git a/spec/lib/banzai/filter/external_link_filter_spec.rb b/spec/lib/banzai/filter/external_link_filter_spec.rb index 2acbe05f082..629f0f1973d 100644 --- a/spec/lib/banzai/filter/external_link_filter_spec.rb +++ b/spec/lib/banzai/filter/external_link_filter_spec.rb @@ -1,177 +1,177 @@ -require 'spec_helper' +require "spec_helper" -shared_examples 'an external link with rel attribute' do +shared_examples "an external link with rel attribute" do it 'adds rel="nofollow" to external links' do - expect(doc.at_css('a')).to have_attribute('rel') - expect(doc.at_css('a')['rel']).to include 'nofollow' + expect(doc.at_css("a")).to have_attribute("rel") + expect(doc.at_css("a")["rel"]).to include "nofollow" end it 'adds rel="noreferrer" to external links' do - expect(doc.at_css('a')).to have_attribute('rel') - expect(doc.at_css('a')['rel']).to include 'noreferrer' + expect(doc.at_css("a")).to have_attribute("rel") + expect(doc.at_css("a")["rel"]).to include "noreferrer" end it 'adds rel="noopener" to external links' do - expect(doc.at_css('a')).to have_attribute('rel') - expect(doc.at_css('a')['rel']).to include 'noopener' + expect(doc.at_css("a")).to have_attribute("rel") + expect(doc.at_css("a")["rel"]).to include "noopener" end end describe Banzai::Filter::ExternalLinkFilter do include FilterSpecHelper - it 'ignores elements without an href attribute' do - exp = act = %q(<a id="ignored">Ignore Me</a>) + it "ignores elements without an href attribute" do + exp = act = '<a id="ignored">Ignore Me</a>' expect(filter(act).to_html).to eq exp end - it 'ignores non-HTTP(S) links' do - exp = act = %q(<a href="irc://irc.freenode.net/gitlab">IRC</a>) + it "ignores non-HTTP(S) links" do + exp = act = '<a href="irc://irc.freenode.net/gitlab">IRC</a>' expect(filter(act).to_html).to eq exp end - it 'skips internal links' do + it "skips internal links" do internal = Gitlab.config.gitlab.url - exp = act = %Q(<a href="#{internal}/sign_in">Login</a>) + exp = act = %(<a href="#{internal}/sign_in">Login</a>) expect(filter(act).to_html).to eq exp end - context 'for root links on document' do - let(:doc) { filter %q(<a href="https://google.com/">Google</a>) } + context "for root links on document" do + let(:doc) { filter '<a href="https://google.com/">Google</a>' } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end - context 'for nested links on document' do - let(:doc) { filter %q(<p><a href="https://google.com/">Google</a></p>) } + context "for nested links on document" do + let(:doc) { filter '<p><a href="https://google.com/">Google</a></p>' } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end - context 'for invalid urls' do - it 'adds rel and target attributes to broken hrefs' do + context "for invalid urls" do + it "adds rel and target attributes to broken hrefs" do doc = filter %q(<p><a href="don't crash on broken urls">Google</a></p>) expected = %q(<p><a href="don't%20crash%20on%20broken%20urls" rel="nofollow noreferrer noopener" target="_blank">Google</a></p>) expect(doc.to_html).to eq(expected) end - it 'adds rel and target to improperly formatted mailtos' do - doc = filter %q(<p><a href="mailto://jblogs@example.com">Email</a></p>) - expected = %q(<p><a href="mailto://jblogs@example.com" rel="nofollow noreferrer noopener" target="_blank">Email</a></p>) + it "adds rel and target to improperly formatted mailtos" do + doc = filter '<p><a href="mailto://jblogs@example.com">Email</a></p>' + expected = '<p><a href="mailto://jblogs@example.com" rel="nofollow noreferrer noopener" target="_blank">Email</a></p>' expect(doc.to_html).to eq(expected) end - it 'adds rel and target to improperly formatted autolinks' do - doc = filter %q(<p><a href="mailto://jblogs@example.com">mailto://jblogs@example.com</a></p>) - expected = %q(<p><a href="mailto://jblogs@example.com" rel="nofollow noreferrer noopener" target="_blank">mailto://jblogs@example.com</a></p>) + it "adds rel and target to improperly formatted autolinks" do + doc = filter '<p><a href="mailto://jblogs@example.com">mailto://jblogs@example.com</a></p>' + expected = '<p><a href="mailto://jblogs@example.com" rel="nofollow noreferrer noopener" target="_blank">mailto://jblogs@example.com</a></p>' expect(doc.to_html).to eq(expected) end end - context 'for links with a username' do - context 'with a valid username' do - let(:doc) { filter %q(<a href="https://user@google.com/">Google</a>) } + context "for links with a username" do + context "with a valid username" do + let(:doc) { filter '<a href="https://user@google.com/">Google</a>' } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end - context 'with an impersonated username' do + context "with an impersonated username" do let(:internal) { Gitlab.config.gitlab.url } - let(:doc) { filter %Q(<a href="https://#{internal}@example.com" target="_blank">Reverse Tabnabbing</a>) } + let(:doc) { filter %(<a href="https://#{internal}@example.com" target="_blank">Reverse Tabnabbing</a>) } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end end - context 'for non-lowercase scheme links' do - context 'with http' do - let(:doc) { filter %q(<p><a href="httP://google.com/">Google</a></p>) } + context "for non-lowercase scheme links" do + context "with http" do + let(:doc) { filter '<p><a href="httP://google.com/">Google</a></p>' } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end - context 'with https' do - let(:doc) { filter %q(<p><a href="hTTpS://google.com/">Google</a></p>) } + context "with https" do + let(:doc) { filter '<p><a href="hTTpS://google.com/">Google</a></p>' } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end - it 'skips internal links' do + it "skips internal links" do internal_link = Gitlab.config.gitlab.url + "/sign_in" - url = internal_link.gsub(/\Ahttp/, 'HtTp') - act = %Q(<a href="#{url}">Login</a>) - exp = %Q(<a href="#{internal_link}">Login</a>) + url = internal_link.gsub(/\Ahttp/, "HtTp") + act = %(<a href="#{url}">Login</a>) + exp = %(<a href="#{internal_link}">Login</a>) expect(filter(act).to_html).to eq(exp) end - it 'skips relative links' do - exp = act = %q(<a href="http_spec/foo.rb">Relative URL</a>) + it "skips relative links" do + exp = act = '<a href="http_spec/foo.rb">Relative URL</a>' expect(filter(act).to_html).to eq(exp) end end - context 'for protocol-relative links' do - let(:doc) { filter %q(<p><a href="//google.com/">Google</a></p>) } + context "for protocol-relative links" do + let(:doc) { filter '<p><a href="//google.com/">Google</a></p>' } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" end - context 'links with RTLO character' do + context "links with RTLO character" do # In rendered text this looks like "http://example.com/evilexe.mp3" - let(:doc) { filter %Q(<a href="http://example.com/evil%E2%80%AE3pm.exe">http://example.com/evil\u202E3pm.exe</a>) } + let(:doc) { filter %(<a href="http://example.com/evil%E2%80%AE3pm.exe">http://example.com/evil\u202E3pm.exe</a>) } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" - it 'escapes RTLO in link text' do - expected = %q(http://example.com/evil%E2%80%AE3pm.exe</a>) + it "escapes RTLO in link text" do + expected = "http://example.com/evil%E2%80%AE3pm.exe</a>" expect(doc.to_html).to include(expected) end - it 'does not mangle the link text' do - doc = filter %Q(<a href="http://example.com">One<span>and</span>\u202Eexe.mp3</a>) + it "does not mangle the link text" do + doc = filter %(<a href="http://example.com">One<span>and</span>\u202Eexe.mp3</a>) - expect(doc.to_html).to include('One<span>and</span>%E2%80%AEexe.mp3</a>') + expect(doc.to_html).to include("One<span>and</span>%E2%80%AEexe.mp3</a>") end end - context 'for generated autolinks' do - context 'with an IDN character' do - let(:doc) { filter(%q(<a href="http://exa%F0%9F%98%84mple.com">http://exa😄mple.com</a>)) } - let(:doc_email) { filter(%q(<a href="http://exa%F0%9F%98%84mple.com">http://exa😄mple.com</a>), emailable_links: true) } + context "for generated autolinks" do + context "with an IDN character" do + let(:doc) { filter('<a href="http://exa%F0%9F%98%84mple.com">http://exa😄mple.com</a>') } + let(:doc_email) { filter('<a href="http://exa%F0%9F%98%84mple.com">http://exa😄mple.com</a>', emailable_links: true) } - it_behaves_like 'an external link with rel attribute' + it_behaves_like "an external link with rel attribute" - it 'does not change the link text' do - expect(doc.to_html).to include('http://exa😄mple.com</a>') + it "does not change the link text" do + expect(doc.to_html).to include("http://exa😄mple.com</a>") end - it 'uses punycode for emails' do - expect(doc_email.to_html).to include('http://xn--example-6p25f.com/</a>') + it "uses punycode for emails" do + expect(doc_email.to_html).to include("http://xn--example-6p25f.com/</a>") end end end - context 'for links that look malicious' do - context 'with an IDN character' do - let(:doc) { filter %q(<a href="http://exa%F0%9F%98%84mple.com">http://exa😄mple.com</a>) } + context "for links that look malicious" do + context "with an IDN character" do + let(:doc) { filter '<a href="http://exa%F0%9F%98%84mple.com">http://exa😄mple.com</a>' } - it 'adds a toolip with punycode' do - expect(doc.to_html).to include('http://exa😄mple.com</a>') + it "adds a toolip with punycode" do + expect(doc.to_html).to include("http://exa😄mple.com</a>") expect(doc.to_html).to include('class="has-tooltip"') expect(doc.to_html).to include('title="http://xn--example-6p25f.com/"') end end - context 'with RTLO character' do - let(:doc) { filter %q(<a href="http://example.com/evil%E2%80%AE3pm.exe">Evil Test</a>) } + context "with RTLO character" do + let(:doc) { filter '<a href="http://example.com/evil%E2%80%AE3pm.exe">Evil Test</a>' } - it 'adds a toolip with punycode' do - expect(doc.to_html).to include('Evil Test</a>') + it "adds a toolip with punycode" do + expect(doc.to_html).to include("Evil Test</a>") expect(doc.to_html).to include('class="has-tooltip"') expect(doc.to_html).to include('title="http://example.com/evil%E2%80%AE3pm.exe"') end diff --git a/spec/lib/banzai/filter/footnote_filter_spec.rb b/spec/lib/banzai/filter/footnote_filter_spec.rb index c6dcb4e46fd..f5c97a2980e 100644 --- a/spec/lib/banzai/filter/footnote_filter_spec.rb +++ b/spec/lib/banzai/filter/footnote_filter_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::FootnoteFilter do include FilterSpecHelper @@ -38,12 +38,12 @@ describe Banzai::Filter::FootnoteFilter do EOF end - context 'when footnotes exist' do + context "when footnotes exist" do let(:doc) { filter(footnote) } - let(:link_node) { doc.css('sup > a').first } - let(:identifier) { link_node[:id].delete_prefix('fnref1-') } + let(:link_node) { doc.css("sup > a").first } + let(:identifier) { link_node[:id].delete_prefix("fnref1-") } - it 'properly adds the necessary ids and classes' do + it "properly adds the necessary ids and classes" do expect(doc.to_html).to eq filtered_footnote end end diff --git a/spec/lib/banzai/filter/front_matter_filter_spec.rb b/spec/lib/banzai/filter/front_matter_filter_spec.rb index 3071dc7cf21..dbc31eb274b 100644 --- a/spec/lib/banzai/filter/front_matter_filter_spec.rb +++ b/spec/lib/banzai/filter/front_matter_filter_spec.rb @@ -1,9 +1,9 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Filter::FrontMatterFilter do include FilterSpecHelper - it 'allows for `encoding:` before the front matter' do + it "allows for `encoding:` before the front matter" do content = <<~MD # encoding: UTF-8 --- @@ -18,10 +18,10 @@ describe Banzai::Filter::FrontMatterFilter do output = filter(content) - expect(output).not_to match 'encoding' + expect(output).not_to match "encoding" end - it 'converts YAML front matter to a fenced code block' do + it "converts YAML front matter to a fenced code block" do content = <<~MD --- foo: :foo_symbol @@ -36,12 +36,12 @@ describe Banzai::Filter::FrontMatterFilter do output = filter(content) aggregate_failures do - expect(output).not_to include '---' + expect(output).not_to include "---" expect(output).to include "```yaml\nfoo: :foo_symbol\n" end end - it 'converts TOML frontmatter to a fenced code block' do + it "converts TOML frontmatter to a fenced code block" do content = <<~MD +++ foo = :foo_symbol @@ -56,12 +56,12 @@ describe Banzai::Filter::FrontMatterFilter do output = filter(content) aggregate_failures do - expect(output).not_to include '+++' + expect(output).not_to include "+++" expect(output).to include "```toml\nfoo = :foo_symbol\n" end end - it 'converts JSON front matter to a fenced code block' do + it "converts JSON front matter to a fenced code block" do content = <<~MD ;;; { @@ -78,12 +78,12 @@ describe Banzai::Filter::FrontMatterFilter do output = filter(content) aggregate_failures do - expect(output).not_to include ';;;' + expect(output).not_to include ";;;" expect(output).to include "```json\n{\n \"foo\": \":foo_symbol\",\n" end end - it 'converts arbitrary front matter to a fenced code block' do + it "converts arbitrary front matter to a fenced code block" do content = <<~MD ---arbitrary foo = :foo_symbol @@ -98,13 +98,13 @@ describe Banzai::Filter::FrontMatterFilter do output = filter(content) aggregate_failures do - expect(output).not_to include '---arbitrary' + expect(output).not_to include "---arbitrary" expect(output).to include "```arbitrary\nfoo = :foo_symbol\n" end end - context 'on content without front matter' do - it 'returns the content unmodified' do + context "on content without front matter" do + it "returns the content unmodified" do content = <<~MD # This is some Markdown @@ -115,8 +115,8 @@ describe Banzai::Filter::FrontMatterFilter do end end - context 'on front matter without content' do - it 'converts YAML front matter to a fenced code block' do + context "on front matter without content" do + it "converts YAML front matter to a fenced code block" do content = <<~MD --- foo: :foo_symbol diff --git a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb index 0e178b859c4..d800ea1b920 100644 --- a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb +++ b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::GollumTagsFilter do include FilterSpecHelper @@ -7,110 +7,110 @@ describe Banzai::Filter::GollumTagsFilter do let(:user) { double } let(:project_wiki) { ProjectWiki.new(project, user) } - describe 'validation' do - it 'ensure that a :project_wiki key exists in context' do + describe "validation" do + it "ensure that a :project_wiki key exists in context" do expect { filter("See [[images/image.jpg]]", {}) }.to raise_error ArgumentError, "Missing context keys for Banzai::Filter::GollumTagsFilter: :project_wiki" end end - context 'linking internal images' do - it 'creates img tag if image exists' do - gollum_file_double = double('Gollum::File', - mime_type: 'image/jpeg', - name: 'images/image.jpg', - path: 'images/image.jpg', - raw_data: '') + context "linking internal images" do + it "creates img tag if image exists" do + gollum_file_double = double("Gollum::File", + mime_type: "image/jpeg", + name: "images/image.jpg", + path: "images/image.jpg", + raw_data: "") wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double) - expect(project_wiki).to receive(:find_file).with('images/image.jpg').and_return(wiki_file) + expect(project_wiki).to receive(:find_file).with("images/image.jpg").and_return(wiki_file) - tag = '[[images/image.jpg]]' + tag = "[[images/image.jpg]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.at_css('img')['data-src']).to eq "#{project_wiki.wiki_base_path}/images/image.jpg" + expect(doc.at_css("img")["data-src"]).to eq "#{project_wiki.wiki_base_path}/images/image.jpg" end - it 'does not creates img tag if image does not exist' do - expect(project_wiki).to receive(:find_file).with('images/image.jpg').and_return(nil) + it "does not creates img tag if image does not exist" do + expect(project_wiki).to receive(:find_file).with("images/image.jpg").and_return(nil) - tag = '[[images/image.jpg]]' + tag = "[[images/image.jpg]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.css('img').size).to eq 0 + expect(doc.css("img").size).to eq 0 end end - context 'linking external images' do - it 'creates img tag for valid URL' do - tag = '[[http://example.com/image.jpg]]' + context "linking external images" do + it "creates img tag for valid URL" do + tag = "[[http://example.com/image.jpg]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.at_css('img')['data-src']).to eq "http://example.com/image.jpg" + expect(doc.at_css("img")["data-src"]).to eq "http://example.com/image.jpg" end - it 'does not creates img tag for invalid URL' do - tag = '[[http://example.com/image.pdf]]' + it "does not creates img tag for invalid URL" do + tag = "[[http://example.com/image.pdf]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.css('img').size).to eq 0 + expect(doc.css("img").size).to eq 0 end end - context 'linking external resources' do + context "linking external resources" do it "the created link's text will be equal to the resource's text" do - tag = '[[http://example.com]]' + tag = "[[http://example.com]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.at_css('a').text).to eq 'http://example.com' - expect(doc.at_css('a')['href']).to eq 'http://example.com' + expect(doc.at_css("a").text).to eq "http://example.com" + expect(doc.at_css("a")["href"]).to eq "http://example.com" end it "the created link's text will be link-text" do - tag = '[[link-text|http://example.com/pdfs/gollum.pdf]]' + tag = "[[link-text|http://example.com/pdfs/gollum.pdf]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.at_css('a').text).to eq 'link-text' - expect(doc.at_css('a')['href']).to eq 'http://example.com/pdfs/gollum.pdf' + expect(doc.at_css("a").text).to eq "link-text" + expect(doc.at_css("a")["href"]).to eq "http://example.com/pdfs/gollum.pdf" end end - context 'linking internal resources' do + context "linking internal resources" do it "the created link's text includes the resource's text and wiki base path" do - tag = '[[wiki-slug]]' + tag = "[[wiki-slug]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') + expected_path = ::File.join(project_wiki.wiki_base_path, "wiki-slug") - expect(doc.at_css('a').text).to eq 'wiki-slug' - expect(doc.at_css('a')['href']).to eq expected_path + expect(doc.at_css("a").text).to eq "wiki-slug" + expect(doc.at_css("a")["href"]).to eq expected_path end it "the created link's text will be link-text" do - tag = '[[link-text|wiki-slug]]' + tag = "[[link-text|wiki-slug]]" doc = filter("See #{tag}", project_wiki: project_wiki) - expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') + expected_path = ::File.join(project_wiki.wiki_base_path, "wiki-slug") - expect(doc.at_css('a').text).to eq 'link-text' - expect(doc.at_css('a')['href']).to eq expected_path + expect(doc.at_css("a").text).to eq "link-text" + expect(doc.at_css("a")["href"]).to eq expected_path end it "inside back ticks will be exempt from linkification" do - doc = filter('<code>[[link-in-backticks]]</code>', project_wiki: project_wiki) + doc = filter("<code>[[link-in-backticks]]</code>", project_wiki: project_wiki) - expect(doc.at_css('code').text).to eq '[[link-in-backticks]]' + expect(doc.at_css("code").text).to eq "[[link-in-backticks]]" end end - context 'table of contents' do - it 'replaces [[<em>TOC</em>]] with ToC result' do - doc = described_class.call("<p>[[<em>TOC</em>]]</p>", { project_wiki: project_wiki }, { toc: "FOO" }) + context "table of contents" do + it "replaces [[<em>TOC</em>]] with ToC result" do + doc = described_class.call("<p>[[<em>TOC</em>]]</p>", {project_wiki: project_wiki}, {toc: "FOO"}) expect(doc.to_html).to eq("FOO") end - it 'handles an empty ToC result' do + it "handles an empty ToC result" do input = "<p>[[<em>TOC</em>]]</p>" doc = described_class.call(input, project_wiki: project_wiki) - expect(doc.to_html).to eq '' + expect(doc.to_html).to eq "" end end end diff --git a/spec/lib/banzai/filter/html_entity_filter_spec.rb b/spec/lib/banzai/filter/html_entity_filter_spec.rb index 1d98fc0d5db..70d756a1afc 100644 --- a/spec/lib/banzai/filter/html_entity_filter_spec.rb +++ b/spec/lib/banzai/filter/html_entity_filter_spec.rb @@ -1,12 +1,12 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::HtmlEntityFilter do include FilterSpecHelper let(:unescaped) { 'foo <strike attr="foo">&&&</strike>' } - let(:escaped) { 'foo <strike attr="foo">&&amp;&</strike>' } + let(:escaped) { "foo <strike attr="foo">&&amp;&</strike>" } - it 'converts common entities to their HTML-escaped equivalents' do + it "converts common entities to their HTML-escaped equivalents" do output = filter(unescaped) expect(output).to eq(escaped) diff --git a/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb b/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb index d06c5535309..79c1d684f32 100644 --- a/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb +++ b/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::ImageLazyLoadFilter do include FilterSpecHelper @@ -11,23 +11,23 @@ describe Banzai::Filter::ImageLazyLoadFilter do %(<img src="#{path}" class="#{class_attr}"/>) end - it 'adds a class attribute' do - doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('img')['class']).to eq 'lazy' + it "adds a class attribute" do + doc = filter(image("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg")) + expect(doc.at_css("img")["class"]).to eq "lazy" end - it 'appends to the current class attribute' do - doc = filter(image_with_class('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg', 'test')) - expect(doc.at_css('img')['class']).to eq 'test lazy' + it "appends to the current class attribute" do + doc = filter(image_with_class("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg", "test")) + expect(doc.at_css("img")["class"]).to eq "test lazy" end - it 'transforms the image src to a data-src' do - doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('img')['data-src']).to eq '/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg' + it "transforms the image src to a data-src" do + doc = filter(image("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg")) + expect(doc.at_css("img")["data-src"]).to eq "/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" end - it 'works with external images' do - doc = filter(image('https://i.imgur.com/DfssX9C.jpg')) - expect(doc.at_css('img')['data-src']).to eq 'https://i.imgur.com/DfssX9C.jpg' + it "works with external images" do + doc = filter(image("https://i.imgur.com/DfssX9C.jpg")) + expect(doc.at_css("img")["data-src"]).to eq "https://i.imgur.com/DfssX9C.jpg" end end diff --git a/spec/lib/banzai/filter/image_link_filter_spec.rb b/spec/lib/banzai/filter/image_link_filter_spec.rb index c84b98eb225..705ec63b0fa 100644 --- a/spec/lib/banzai/filter/image_link_filter_spec.rb +++ b/spec/lib/banzai/filter/image_link_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::ImageLinkFilter do include FilterSpecHelper @@ -7,23 +7,23 @@ describe Banzai::Filter::ImageLinkFilter do %(<img src="#{path}" />) end - it 'wraps the image with a link to the image src' do - doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href'] + it "wraps the image with a link to the image src" do + doc = filter(image("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg")) + expect(doc.at_css("img")["src"]).to eq doc.at_css("a")["href"] end - it 'does not wrap a duplicate link' do - doc = filter(%Q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>)) + it "does not wrap a duplicate link" do + doc = filter(%(<a href="/whatever">#{image("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg")}</a>)) expect(doc.to_html).to match %r{^<a href="/whatever"><img[^>]*></a>$} end - it 'works with external images' do - doc = filter(image('https://i.imgur.com/DfssX9C.jpg')) - expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href'] + it "works with external images" do + doc = filter(image("https://i.imgur.com/DfssX9C.jpg")) + expect(doc.at_css("img")["src"]).to eq doc.at_css("a")["href"] end - it 'works with inline images' do - doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>)) + it "works with inline images" do + doc = filter(%(<p>test #{image("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg")} inline</p>)) expect(doc.to_html).to match %r{^<p>test <a[^>]*><img[^>]*></a> inline</p>$} end end diff --git a/spec/lib/banzai/filter/inline_diff_filter_spec.rb b/spec/lib/banzai/filter/inline_diff_filter_spec.rb index 63c4ab61b86..7e2bab37c0c 100644 --- a/spec/lib/banzai/filter/inline_diff_filter_spec.rb +++ b/spec/lib/banzai/filter/inline_diff_filter_spec.rb @@ -1,44 +1,44 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::InlineDiffFilter do include FilterSpecHelper - it 'adds inline diff span tags for deletions when using square brackets' do + it "adds inline diff span tags for deletions when using square brackets" do doc = "START [-something deleted-] END" expect(filter(doc).to_html).to eq('START <span class="idiff left right deletion">something deleted</span> END') end - it 'adds inline diff span tags for deletions when using curley braces' do + it "adds inline diff span tags for deletions when using curley braces" do doc = "START {-something deleted-} END" expect(filter(doc).to_html).to eq('START <span class="idiff left right deletion">something deleted</span> END') end - it 'does not add inline diff span tags when a closing tag is not provided' do + it "does not add inline diff span tags when a closing tag is not provided" do doc = "START [- END" expect(filter(doc).to_html).to eq(doc) end - it 'adds inline span tags for additions when using square brackets' do + it "adds inline span tags for additions when using square brackets" do doc = "START [+something added+] END" expect(filter(doc).to_html).to eq('START <span class="idiff left right addition">something added</span> END') end - it 'adds inline span tags for additions when using curley braces' do + it "adds inline span tags for additions when using curley braces" do doc = "START {+something added+} END" expect(filter(doc).to_html).to eq('START <span class="idiff left right addition">something added</span> END') end - it 'does not add inline diff span tags when a closing addition tag is not provided' do + it "does not add inline diff span tags when a closing addition tag is not provided" do doc = "START {+ END" expect(filter(doc).to_html).to eq(doc) end - it 'does not add inline diff span tags when the tags do not match' do + it "does not add inline diff span tags when the tags do not match" do examples = [ "{+ additions +]", "[+ additions +}", "{- delletions -]", - "[- delletions -}" + "[- delletions -}", ] examples.each do |doc| @@ -46,22 +46,22 @@ describe Banzai::Filter::InlineDiffFilter do end end - it 'prevents user-land html being injected' do + it "prevents user-land html being injected" do doc = "START {+<script>alert('I steal cookies')</script>+} END" expect(filter(doc).to_html).to eq("START <span class=\"idiff left right addition\"><script>alert('I steal cookies')</script></span> END") end - it 'preserves content inside pre tags' do + it "preserves content inside pre tags" do doc = "<pre>START {+something added+} END</pre>" expect(filter(doc).to_html).to eq(doc) end - it 'preserves content inside code tags' do + it "preserves content inside code tags" do doc = "<code>START {+something added+} END</code>" expect(filter(doc).to_html).to eq(doc) end - it 'preserves content inside tt tags' do + it "preserves content inside tt tags" do doc = "<tt>START {+something added+} END</tt>" expect(filter(doc).to_html).to eq(doc) end diff --git a/spec/lib/banzai/filter/issuable_state_filter_spec.rb b/spec/lib/banzai/filter/issuable_state_filter_spec.rb index a5373517ac8..bba19ebb451 100644 --- a/spec/lib/banzai/filter/issuable_state_filter_spec.rb +++ b/spec/lib/banzai/filter/issuable_state_filter_spec.rb @@ -1,18 +1,18 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::IssuableStateFilter do include ActionView::Helpers::UrlHelper include FilterSpecHelper let(:user) { create(:user) } - let(:context) { { current_user: user, issuable_state_filter_enabled: true } } + let(:context) { {current_user: user, issuable_state_filter_enabled: true} } let(:closed_issue) { create_issue(:closed) } let(:project) { create(:project, :public) } let(:group) { create(:group) } let(:other_project) { create(:project, :public) } def create_link(text, data) - link_to(text, '', class: 'gfm has-tooltip', data: data) + link_to(text, "", class: "gfm has-tooltip", data: data) end def create_issue(state) @@ -24,182 +24,182 @@ describe Banzai::Filter::IssuableStateFilter do source_project: project, target_project: project) end - it 'ignores non-GFM links' do + it "ignores non-GFM links" do html = %(See <a href="https://google.com/">Google</a>) doc = filter(html, current_user: user) - expect(doc.css('a').last.text).to eq('Google') + expect(doc.css("a").last.text).to eq("Google") end - it 'ignores non-issuable links' do - link = create_link('text', project: project, reference_type: 'issue') + it "ignores non-issuable links" do + link = create_link("text", project: project, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq('text') + expect(doc.css("a").last.text).to eq("text") end - it 'ignores issuable links with empty content' do - link = create_link('', issue: closed_issue.id, reference_type: 'issue') + it "ignores issuable links with empty content" do + link = create_link("", issue: closed_issue.id, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq('') + expect(doc.css("a").last.text).to eq("") end - it 'ignores issuable links with custom anchor' do - link = create_link('something', issue: closed_issue.id, reference_type: 'issue') + it "ignores issuable links with custom anchor" do + link = create_link("something", issue: closed_issue.id, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq('something') + expect(doc.css("a").last.text).to eq("something") end - it 'ignores issuable links to specific comments' do - link = create_link("#{closed_issue.to_reference} (comment 1)", issue: closed_issue.id, reference_type: 'issue') + it "ignores issuable links to specific comments" do + link = create_link("#{closed_issue.to_reference} (comment 1)", issue: closed_issue.id, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference} (comment 1)") + expect(doc.css("a").last.text).to eq("#{closed_issue.to_reference} (comment 1)") end - it 'ignores merge request links to diffs tab' do + it "ignores merge request links to diffs tab" do merge_request = create(:merge_request, :closed) link = create_link( "#{merge_request.to_reference} (diffs)", merge_request: merge_request.id, - reference_type: 'merge_request' + reference_type: "merge_request" ) doc = filter(link, context) - expect(doc.css('a').last.text).to eq("#{merge_request.to_reference} (diffs)") + expect(doc.css("a").last.text).to eq("#{merge_request.to_reference} (diffs)") end - it 'handles cross project references' do - link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: 'issue') + it "handles cross project references" do + link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: "issue") doc = filter(link, context.merge(project: other_project)) - expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference(other_project)} (closed)") + expect(doc.css("a").last.text).to eq("#{closed_issue.to_reference(other_project)} (closed)") end - it 'handles references from group scopes' do - link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: 'issue') + it "handles references from group scopes" do + link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: "issue") doc = filter(link, context.merge(project: nil, group: group)) - expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference(other_project)} (closed)") + expect(doc.css("a").last.text).to eq("#{closed_issue.to_reference(other_project)} (closed)") end - it 'skips cross project references if the user cannot read cross project' do + it "skips cross project references if the user cannot read cross project" do expect(Ability).to receive(:allowed?).with(user, :read_cross_project) { false } - link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: 'issue') + link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: "issue") doc = filter(link, context.merge(project: other_project)) - expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference(other_project)}") + expect(doc.css("a").last.text).to eq(closed_issue.to_reference(other_project).to_s) end - it 'does not append state when filter is not enabled' do - link = create_link('text', issue: closed_issue.id, reference_type: 'issue') - context = { current_user: user } + it "does not append state when filter is not enabled" do + link = create_link("text", issue: closed_issue.id, reference_type: "issue") + context = {current_user: user} doc = filter(link, context) - expect(doc.css('a').last.text).to eq('text') + expect(doc.css("a").last.text).to eq("text") end - context 'when project is in pending delete' do + context "when project is in pending delete" do before do project.update!(pending_delete: true) end - it 'does not append issue state' do - link = create_link('text', issue: closed_issue.id, reference_type: 'issue') + it "does not append issue state" do + link = create_link("text", issue: closed_issue.id, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq('text') + expect(doc.css("a").last.text).to eq("text") end end - context 'for issue references' do - it 'ignores open issue references' do + context "for issue references" do + it "ignores open issue references" do issue = create_issue(:opened) - link = create_link(issue.to_reference, issue: issue.id, reference_type: 'issue') + link = create_link(issue.to_reference, issue: issue.id, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq(issue.to_reference) + expect(doc.css("a").last.text).to eq(issue.to_reference) end - it 'appends state to closed issue references' do - link = create_link(closed_issue.to_reference, issue: closed_issue.id, reference_type: 'issue') + it "appends state to closed issue references" do + link = create_link(closed_issue.to_reference, issue: closed_issue.id, reference_type: "issue") doc = filter(link, context) - expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference} (closed)") + expect(doc.css("a").last.text).to eq("#{closed_issue.to_reference} (closed)") end end - context 'for merge request references' do - it 'ignores open merge request references' do + context "for merge request references" do + it "ignores open merge request references" do merge_request = create_merge_request(:opened) link = create_link( merge_request.to_reference, merge_request: merge_request.id, - reference_type: 'merge_request' + reference_type: "merge_request" ) doc = filter(link, context) - expect(doc.css('a').last.text).to eq(merge_request.to_reference) + expect(doc.css("a").last.text).to eq(merge_request.to_reference) end - it 'ignores reopened merge request references' do + it "ignores reopened merge request references" do merge_request = create_merge_request(:opened) link = create_link( merge_request.to_reference, merge_request: merge_request.id, - reference_type: 'merge_request' + reference_type: "merge_request" ) doc = filter(link, context) - expect(doc.css('a').last.text).to eq(merge_request.to_reference) + expect(doc.css("a").last.text).to eq(merge_request.to_reference) end - it 'ignores locked merge request references' do + it "ignores locked merge request references" do merge_request = create_merge_request(:locked) link = create_link( merge_request.to_reference, merge_request: merge_request.id, - reference_type: 'merge_request' + reference_type: "merge_request" ) doc = filter(link, context) - expect(doc.css('a').last.text).to eq(merge_request.to_reference) + expect(doc.css("a").last.text).to eq(merge_request.to_reference) end - it 'appends state to closed merge request references' do + it "appends state to closed merge request references" do merge_request = create_merge_request(:closed) link = create_link( merge_request.to_reference, merge_request: merge_request.id, - reference_type: 'merge_request' + reference_type: "merge_request" ) doc = filter(link, context) - expect(doc.css('a').last.text).to eq("#{merge_request.to_reference} (closed)") + expect(doc.css("a").last.text).to eq("#{merge_request.to_reference} (closed)") end - it 'appends state to merged merge request references' do + it "appends state to merged merge request references" do merge_request = create_merge_request(:merged) link = create_link( merge_request.to_reference, merge_request: merge_request.id, - reference_type: 'merge_request' + reference_type: "merge_request" ) doc = filter(link, context) - expect(doc.css('a').last.text).to eq("#{merge_request.to_reference} (merged)") + expect(doc.css("a").last.text).to eq("#{merge_request.to_reference} (merged)") end end end diff --git a/spec/lib/banzai/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb index 914c4e2d823..73beca3a8e4 100644 --- a/spec/lib/banzai/filter/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::IssueReferenceFilter do include FilterSpecHelper @@ -10,21 +10,21 @@ describe Banzai::Filter::IssueReferenceFilter do let(:project) { create(:project, :public) } let(:issue) { create(:issue, project: project) } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Issue #{issue.to_reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - describe 'performance' do + describe "performance" do let(:another_issue) { create(:issue, project: project) } - it 'does not have a N+1 query problem' do + it "does not have a N+1 query problem" do single_reference = "Issue #{issue.to_reference}" multiple_references = "Issues #{issue.to_reference} and #{another_issue.to_reference}" @@ -34,102 +34,102 @@ describe Banzai::Filter::IssueReferenceFilter do end end - context 'internal reference' do - it_behaves_like 'a reference containing an element node' + context "internal reference" do + it_behaves_like "a reference containing an element node" let(:reference) { "##{issue.iid}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("Fixed #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue.iid, project) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eql("Fixed (#{reference}.)") end - it 'ignores invalid issue IDs' do + it "ignores invalid issue IDs" do invalid = invalidate_reference(reference) exp = act = "Fixed #{invalid}" expect(reference_filter(act).to_html).to eq exp end - it 'includes a title attribute' do + it "includes a title attribute" do doc = reference_filter("Issue #{reference}") - expect(doc.css('a').first.attr('title')).to eq issue.title + expect(doc.css("a").first.attr("title")).to eq issue.title end - it 'escapes the title attribute' do - issue.update_attribute(:title, %{"></a>whatever<a title="}) + it "escapes the title attribute" do + issue.update_attribute(:title, %("></a>whatever<a title=")) doc = reference_filter("Issue #{reference}") expect(doc.text).to eq "Issue #{reference}" end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Issue #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Issue #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-issue attribute' do + it "includes a data-issue attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-issue') - expect(link.attr('data-issue')).to eq issue.id.to_s + expect(link).to have_attribute("data-issue") + expect(link.attr("data-issue")).to eq issue.id.to_s end - it 'includes a data-original attribute' do + it "includes a data-original attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-original') - expect(link.attr('data-original')).to eq reference + expect(link).to have_attribute("data-original") + expect(link.attr("data-original")).to eq reference end - it 'does not escape the data-original attribute' do - inner_html = 'element <code>node</code> inside' - doc = reference_filter(%{<a href="#{reference}">#{inner_html}</a>}) - expect(doc.children.first.attr('data-original')).to eq inner_html + it "does not escape the data-original attribute" do + inner_html = "element <code>node</code> inside" + doc = reference_filter(%(<a href="#{reference}">#{inner_html}</a>)) + expect(doc.children.first.attr("data-original")).to eq inner_html end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = reference_filter("Issue #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq helper.url_for_issue(issue.iid, project, only_path: true) end - it 'does not process links containing issue numbers followed by text' do + it "does not process links containing issue numbers followed by text" do href = "#{reference}st" doc = reference_filter("<a href='#{href}'></a>") - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") expect(link).to eq(href) end end - context 'cross-project / cross-namespace complete reference' do - it_behaves_like 'a reference containing an element node' + context "cross-project / cross-namespace complete reference" do + it_behaves_like "a reference containing an element node" let(:project2) { create(:project, :public) } let(:issue) { create(:issue, project: project2) } let(:reference) { "#{project2.full_path}##{issue.iid}" } - it 'ignores valid references when cross-reference project uses external tracker' do + it "ignores valid references when cross-reference project uses external tracker" do expect_any_instance_of(described_class).to receive(:find_object) .with(project2, issue.iid) .and_return(nil) @@ -138,40 +138,40 @@ describe Banzai::Filter::IssueReferenceFilter do expect(reference_filter(act).to_html).to eq exp end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue.iid, project2) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text).to eql("#{project2.full_path}##{issue.iid}") + expect(doc.css("a").first.text).to eql("#{project2.full_path}##{issue.iid}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eq("Fixed (#{project2.full_path}##{issue.iid}.)") end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end - it 'ignores invalid issue IDs on the referenced project' do + it "ignores invalid issue IDs on the referenced project" do exp = act = "Fixed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project / same-namespace complete reference' do - it_behaves_like 'a reference containing an element node' + context "cross-project / same-namespace complete reference" do + it_behaves_like "a reference containing an element node" let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } @@ -179,7 +179,7 @@ describe Banzai::Filter::IssueReferenceFilter do let(:issue) { create(:issue, project: project2) } let(:reference) { "#{project2.full_path}##{issue.iid}" } - it 'ignores valid references when cross-reference project uses external tracker' do + it "ignores valid references when cross-reference project uses external tracker" do expect_any_instance_of(described_class).to receive(:find_object) .with(project2, issue.iid) .and_return(nil) @@ -188,40 +188,40 @@ describe Banzai::Filter::IssueReferenceFilter do expect(reference_filter(act).to_html).to eq exp end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue.iid, project2) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text).to eql("#{project2.path}##{issue.iid}") + expect(doc.css("a").first.text).to eql("#{project2.path}##{issue.iid}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eq("Fixed (#{project2.path}##{issue.iid}.)") end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end - it 'ignores invalid issue IDs on the referenced project' do + it "ignores invalid issue IDs on the referenced project" do exp = act = "Fixed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project shorthand reference' do - it_behaves_like 'a reference containing an element node' + context "cross-project shorthand reference" do + it_behaves_like "a reference containing an element node" let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } @@ -229,7 +229,7 @@ describe Banzai::Filter::IssueReferenceFilter do let(:issue) { create(:issue, project: project2) } let(:reference) { "#{project2.path}##{issue.iid}" } - it 'ignores valid references when cross-reference project uses external tracker' do + it "ignores valid references when cross-reference project uses external tracker" do expect_any_instance_of(described_class).to receive(:find_object) .with(project2, issue.iid) .and_return(nil) @@ -238,136 +238,136 @@ describe Banzai::Filter::IssueReferenceFilter do expect(reference_filter(act).to_html).to eq exp end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue.iid, project2) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text).to eql("#{project2.path}##{issue.iid}") + expect(doc.css("a").first.text).to eql("#{project2.path}##{issue.iid}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.text).to eq("Fixed (#{project2.path}##{issue.iid}.)") end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end - it 'ignores invalid issue IDs on the referenced project' do + it "ignores invalid issue IDs on the referenced project" do exp = act = "Fixed #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project URL reference' do - it_behaves_like 'a reference containing an element node' + context "cross-project URL reference" do + it_behaves_like "a reference containing an element node" - let(:namespace) { create(:namespace, name: 'cross-reference') } + let(:namespace) { create(:namespace, name: "cross-reference") } let(:project2) { create(:project, :public, namespace: namespace) } let(:issue) { create(:issue, project: project2) } let(:reference) { helper.url_for_issue(issue.iid, project2) + "#note_123" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq reference end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Fixed (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(issue.to_reference(project))} \(comment 123\)</a>\.\)}) end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end end - context 'cross-project reference in link href' do - it_behaves_like 'a reference containing an element node' + context "cross-project reference in link href" do + it_behaves_like "a reference containing an element node" - let(:namespace) { create(:namespace, name: 'cross-reference') } + let(:namespace) { create(:namespace, name: "cross-reference") } let(:project2) { create(:project, :public, namespace: namespace) } let(:issue) { create(:issue, project: project2) } let(:reference) { issue.to_reference(project) } - let(:reference_link) { %{<a href="#{reference}">Reference</a>} } + let(:reference_link) { %(<a href="#{reference}">Reference</a>) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference_link}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue.iid, project2) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Fixed (#{reference_link}.)") expect(doc.to_html).to match(%r{\(<a.+>Reference</a>\.\)}) end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Fixed (#{reference_link}.)") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end end - context 'cross-project URL in link href' do - it_behaves_like 'a reference containing an element node' + context "cross-project URL in link href" do + it_behaves_like "a reference containing an element node" - let(:namespace) { create(:namespace, name: 'cross-reference') } + let(:namespace) { create(:namespace, name: "cross-reference") } let(:project2) { create(:project, :public, namespace: namespace) } let(:issue) { create(:issue, project: project2) } - let(:reference) { "#{helper.url_for_issue(issue.iid, project2) + "#note_123"}" } - let(:reference_link) { %{<a href="#{reference}">Reference</a>} } + let(:reference) { (helper.url_for_issue(issue.iid, project2) + "#note_123").to_s } + let(:reference_link) { %(<a href="#{reference}">Reference</a>) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference_link}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq helper.url_for_issue(issue.iid, project2) + "#note_123" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Fixed (#{reference_link}.)") expect(doc.to_html).to match(%r{\(<a.+>Reference</a>\.\)}) end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Fixed (#{reference_link}.)") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-issue has-tooltip" end end - context 'group context' do + context "group context" do let(:group) { create(:group) } - let(:context) { { project: nil, group: group } } + let(:context) { {project: nil, group: group} } - it 'ignores shorthanded issue reference' do + it "ignores shorthanded issue reference" do reference = "##{issue.iid}" text = "Fixed #{reference}" expect(reference_filter(text, context).to_html).to eq(text) end - it 'ignores valid references when cross-reference project uses external tracker' do + it "ignores valid references when cross-reference project uses external tracker" do expect_any_instance_of(described_class).to receive(:find_object) .with(project, issue.iid) .and_return(nil) @@ -378,91 +378,91 @@ describe Banzai::Filter::IssueReferenceFilter do expect(reference_filter(text, context).to_html).to eq(text) end - it 'links to a valid reference for complete cross-reference' do + it "links to a valid reference for complete cross-reference" do reference = "#{project.full_path}##{issue.iid}" doc = reference_filter("See #{reference}", context) - link = doc.css('a').first - expect(link.attr('href')).to eq(helper.url_for_issue(issue.iid, project)) + link = doc.css("a").first + expect(link.attr("href")).to eq(helper.url_for_issue(issue.iid, project)) expect(link.text).to include("#{project.full_path}##{issue.iid}") end - it 'ignores reference for shorthand cross-reference' do + it "ignores reference for shorthand cross-reference" do reference = "#{project.path}##{issue.iid}" text = "See #{reference}" expect(reference_filter(text, context).to_html).to eq(text) end - it 'links to a valid reference for url cross-reference' do + it "links to a valid reference for url cross-reference" do reference = helper.url_for_issue(issue.iid, project) + "#note_123" doc = reference_filter("See #{reference}", context) - link = doc.css('a').first - expect(link.attr('href')).to eq(helper.url_for_issue(issue.iid, project) + "#note_123") + link = doc.css("a").first + expect(link.attr("href")).to eq(helper.url_for_issue(issue.iid, project) + "#note_123") expect(link.text).to include("#{project.full_path}##{issue.iid}") end - it 'links to a valid reference for cross-reference in link href' do - reference = "#{helper.url_for_issue(issue.iid, project) + "#note_123"}" - reference_link = %{<a href="#{reference}">Reference</a>} + it "links to a valid reference for cross-reference in link href" do + reference = (helper.url_for_issue(issue.iid, project) + "#note_123").to_s + reference_link = %(<a href="#{reference}">Reference</a>) doc = reference_filter("See #{reference_link}", context) - link = doc.css('a').first - expect(link.attr('href')).to eq(helper.url_for_issue(issue.iid, project) + "#note_123") - expect(link.text).to include('Reference') + link = doc.css("a").first + expect(link.attr("href")).to eq(helper.url_for_issue(issue.iid, project) + "#note_123") + expect(link.text).to include("Reference") end - it 'links to a valid reference for issue reference in the link href' do + it "links to a valid reference for issue reference in the link href" do reference = issue.to_reference(group) - reference_link = %{<a href="#{reference}">Reference</a>} + reference_link = %(<a href="#{reference}">Reference</a>) doc = reference_filter("See #{reference_link}", context) - link = doc.css('a').first - expect(link.attr('href')).to eq(helper.url_for_issue(issue.iid, project)) - expect(link.text).to include('Reference') + link = doc.css("a").first + expect(link.attr("href")).to eq(helper.url_for_issue(issue.iid, project)) + expect(link.text).to include("Reference") end end - describe '#records_per_parent' do - context 'using an internal issue tracker' do - it 'returns a Hash containing the issues per project' do - doc = Nokogiri::HTML.fragment('') + describe "#records_per_parent" do + context "using an internal issue tracker" do + it "returns a Hash containing the issues per project" do + doc = Nokogiri::HTML.fragment("") filter = described_class.new(doc, project: project) expect(filter).to receive(:parent_per_reference) - .and_return({ project.full_path => project }) + .and_return({project.full_path => project}) expect(filter).to receive(:references_per_parent) - .and_return({ project.full_path => Set.new([issue.iid]) }) + .and_return({project.full_path => Set.new([issue.iid])}) expect(filter.records_per_parent) - .to eq({ project => { issue.iid => issue } }) + .to eq({project => {issue.iid => issue}}) end end end - describe '.references_in' do + describe ".references_in" do let(:merge_request) { create(:merge_request) } - it 'yields valid references' do - expect do |b| + it "yields valid references" do + expect { |b| described_class.references_in(issue.to_reference, &b) - end.to yield_with_args(issue.to_reference, issue.iid, nil, nil, MatchData) + }.to yield_with_args(issue.to_reference, issue.iid, nil, nil, MatchData) end it "doesn't yield invalid references" do - expect do |b| - described_class.references_in('#0', &b) - end.not_to yield_control + expect { |b| + described_class.references_in("#0", &b) + }.not_to yield_control end it "doesn't yield unsupported references" do - expect do |b| + expect { |b| described_class.references_in(merge_request.to_reference, &b) - end.not_to yield_control + }.not_to yield_control end end end diff --git a/spec/lib/banzai/filter/label_reference_filter_spec.rb b/spec/lib/banzai/filter/label_reference_filter_spec.rb index 108d7b43a26..642281d2f38 100644 --- a/spec/lib/banzai/filter/label_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb @@ -1,161 +1,161 @@ -require 'spec_helper' -require 'html/pipeline' +require "spec_helper" +require "html/pipeline" describe Banzai::Filter::LabelReferenceFilter do include FilterSpecHelper - let(:project) { create(:project, :public, name: 'sample-project') } + let(:project) { create(:project, :public, name: "sample-project") } let(:label) { create(:label, project: project) } let(:reference) { label.to_reference } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Label #{reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Label #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-label has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-label has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Label #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-label attribute' do + it "includes a data-label attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-label') - expect(link.attr('data-label')).to eq label.id.to_s + expect(link).to have_attribute("data-label") + expect(link.attr("data-label")).to eq label.id.to_s end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = reference_filter("Label #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq urls.project_issues_path(project, label_name: label.name) end - context 'project that does not exist referenced' do - let(:result) { reference_filter('aaa/bbb~ccc') } + context "project that does not exist referenced" do + let(:result) { reference_filter("aaa/bbb~ccc") } - it 'does not link reference' do - expect(result.to_html).to eq 'aaa/bbb~ccc' + it "does not link reference" do + expect(result.to_html).to eq "aaa/bbb~ccc" end end - describe 'label span element' do - it 'includes default classes' do + describe "label span element" do + it "includes default classes" do doc = reference_filter("Label #{reference}") - expect(doc.css('a span').first.attr('class')).to eq 'badge color-label has-tooltip' + expect(doc.css("a span").first.attr("class")).to eq "badge color-label has-tooltip" end - it 'includes a style attribute' do + it "includes a style attribute" do doc = reference_filter("Label #{reference}") - expect(doc.css('a span').first.attr('style')).to match(/\Abackground-color: #\h{6}; color: #\h{6}\z/) + expect(doc.css("a span").first.attr("style")).to match(/\Abackground-color: #\h{6}; color: #\h{6}\z/) end end - context 'Integer-based references' do - it 'links to a valid reference' do + context "Integer-based references" do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{label.name}</span></a>\.\)}) end - it 'ignores invalid label IDs' do + it "ignores invalid label IDs" do exp = act = "Label #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'String-based single-word references' do - let(:label) { create(:label, name: 'gfm', project: project) } + context "String-based single-word references" do + let(:label) { create(:label, name: "gfm", project: project) } let(:reference) { "#{Label.reference_prefix}#{label.name}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See gfm' + expect(doc.text).to eq "See gfm" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}).") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\)\.)) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{label.name}</span></a>\)\.}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do exp = act = "Label #{Label.reference_prefix}#{label.name.reverse}" expect(reference_filter(act).to_html).to eq exp end end - context 'String-based single-word references that begin with a digit' do - let(:label) { create(:label, name: '2fa', project: project) } + context "String-based single-word references that begin with a digit" do + let(:label) { create(:label, name: "2fa", project: project) } let(:reference) { "#{Label.reference_prefix}#{label.name}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See 2fa' + expect(doc.text).to eq "See 2fa" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}).") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\)\.)) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{label.name}</span></a>\)\.}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do exp = act = "Label #{Label.reference_prefix}#{label.id}#{label.name.reverse}" expect(reference_filter(act).to_html).to eq exp end end - context 'String-based single-word references with special characters' do - let(:label) { create(:label, name: '?g.fm&', project: project) } + context "String-based single-word references with special characters" do + let(:label) { create(:label, name: "?g.fm&", project: project) } let(:reference) { "#{Label.reference_prefix}#{label.name}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See ?g.fm&' + expect(doc.text).to eq "See ?g.fm&" end - it 'does not include trailing punctuation', :aggregate_failures do - ['.', ', ok?', '...', '?', '!', ': is that ok?'].each do |trailing_punctuation| + it "does not include trailing punctuation", :aggregate_failures do + [".", ", ok?", "...", "?", "!", ": is that ok?"].each do |trailing_punctuation| doc = filter("Label #{reference}#{trailing_punctuation}") - expect(doc.to_html).to match(%r(<a.+><span.+>\?g\.fm&</span></a>#{Regexp.escape(trailing_punctuation)})) + expect(doc.to_html).to match(%r{<a.+><span.+>\?g\.fm&</span></a>#{Regexp.escape(trailing_punctuation)}}) end end - it 'ignores invalid label names' do + it "ignores invalid label names" do act = "Label #{Label.reference_prefix}#{label.name.reverse}" exp = "Label #{Label.reference_prefix}&mf.g?" @@ -163,72 +163,72 @@ describe Banzai::Filter::LabelReferenceFilter do end end - context 'String-based multi-word references in quotes' do - let(:label) { create(:label, name: 'gfm references', project: project) } + context "String-based multi-word references in quotes" do + let(:label) { create(:label, name: "gfm references", project: project) } let(:reference) { label.to_reference(format: :name) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See gfm references' + expect(doc.text).to eq "See gfm references" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{label.name}</span></a>\.\)}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do exp = act = %(Label #{Label.reference_prefix}"#{label.name.reverse}") expect(reference_filter(act).to_html).to eq exp end end - context 'String-based multi-word references that begin with a digit' do - let(:label) { create(:label, name: '2 factor authentication', project: project) } + context "String-based multi-word references that begin with a digit" do + let(:label) { create(:label, name: "2 factor authentication", project: project) } let(:reference) { label.to_reference(format: :name) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See 2 factor authentication' + expect(doc.text).to eq "See 2 factor authentication" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{label.name}</span></a>\.\)}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do exp = act = "Label #{Label.reference_prefix}#{label.id}#{label.name.reverse}" expect(reference_filter(act).to_html).to eq exp end end - context 'String-based multi-word references with special characters in quotes' do - let(:label) { create(:label, name: 'g.fm & references?', project: project) } + context "String-based multi-word references with special characters in quotes" do + let(:label) { create(:label, name: "g.fm & references?", project: project) } let(:reference) { label.to_reference(format: :name) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See g.fm & references?' + expect(doc.text).to eq "See g.fm & references?" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+><span.+>g\.fm & references\?</span></a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+><span.+>g\.fm & references\?</span></a>\.\)}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do act = %(Label #{Label.reference_prefix}"#{label.name.reverse}") exp = %(Label #{Label.reference_prefix}"?secnerefer & mf.g\") @@ -236,148 +236,148 @@ describe Banzai::Filter::LabelReferenceFilter do end end - context 'References with html entities' do - let!(:label) { create(:label, name: '<html>', project: project) } + context "References with html entities" do + let!(:label) { create(:label, name: "<html>", project: project) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter('See ~"<html>"') - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) - expect(doc.text).to eq 'See <html>' + expect(doc.text).to eq "See <html>" end - it 'ignores invalid label names and escapes entities' do + it "ignores invalid label names and escapes entities" do act = %(Label #{Label.reference_prefix}"<non valid>") expect(reference_filter(act).to_html).to eq act end end - describe 'consecutive references' do - let(:bug) { create(:label, name: 'bug', project: project) } - let(:feature_proposal) { create(:label, name: 'feature proposal', project: project) } - let(:technical_debt) { create(:label, name: 'technical debt', project: project) } + describe "consecutive references" do + let(:bug) { create(:label, name: "bug", project: project) } + let(:feature_proposal) { create(:label, name: "feature proposal", project: project) } + let(:technical_debt) { create(:label, name: "technical debt", project: project) } let(:bug_reference) { "#{Label.reference_prefix}#{bug.name}" } let(:feature_proposal_reference) { feature_proposal.to_reference(format: :name) } let(:technical_debt_reference) { technical_debt.to_reference(format: :name) } - context 'separated with a comma' do + context "separated with a comma" do let(:references) { "#{bug_reference}, #{feature_proposal_reference}, #{technical_debt_reference}" } - it 'links to valid references' do + it "links to valid references" do doc = reference_filter("See #{references}") - expect(doc.css('a').map { |a| a.attr('href') }).to match_array([ + expect(doc.css("a").map { |a| a.attr("href") }).to match_array([ urls.project_issues_url(project, label_name: bug.name), urls.project_issues_url(project, label_name: feature_proposal.name), - urls.project_issues_url(project, label_name: technical_debt.name) + urls.project_issues_url(project, label_name: technical_debt.name), ]) - expect(doc.text).to eq 'See bug, feature proposal, technical debt' + expect(doc.text).to eq "See bug, feature proposal, technical debt" end end - context 'separated with a space' do + context "separated with a space" do let(:references) { "#{bug_reference} #{feature_proposal_reference} #{technical_debt_reference}" } - it 'links to valid references' do + it "links to valid references" do doc = reference_filter("See #{references}") - expect(doc.css('a').map { |a| a.attr('href') }).to match_array([ + expect(doc.css("a").map { |a| a.attr("href") }).to match_array([ urls.project_issues_url(project, label_name: bug.name), urls.project_issues_url(project, label_name: feature_proposal.name), - urls.project_issues_url(project, label_name: technical_debt.name) + urls.project_issues_url(project, label_name: technical_debt.name), ]) - expect(doc.text).to eq 'See bug feature proposal technical debt' + expect(doc.text).to eq "See bug feature proposal technical debt" end end end - describe 'edge cases' do - it 'gracefully handles non-references matching the pattern' do + describe "edge cases" do + it "gracefully handles non-references matching the pattern" do exp = act = '(format nil "~0f" 3.0) ; 3.0' expect(reference_filter(act).to_html).to eq exp end end - describe 'referencing a label in a link href' do - let(:reference) { %Q{<a href="#{label.to_reference}">Label</a>} } + describe "referencing a label in a link href" do + let(:reference) { %(<a href="#{label.to_reference}">Label</a>) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: label.name) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+>Label</a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+>Label</a>\.\)}) end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Label #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-label attribute' do + it "includes a data-label attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-label') - expect(link.attr('data-label')).to eq label.id.to_s + expect(link).to have_attribute("data-label") + expect(link.attr("data-label")).to eq label.id.to_s end end - describe 'group label references' do + describe "group label references" do let(:group) { create(:group) } let(:project) { create(:project, :public, namespace: group) } - let(:group_label) { create(:group_label, name: 'gfm references', group: group) } + let(:group_label) { create(:group_label, name: "gfm references", group: group) } - context 'without project reference' do + context "without project reference" do let(:reference) { group_label.to_reference(format: :name) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}", project: project) - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: group_label.name) - expect(doc.text).to eq 'See gfm references' + expect(doc.text).to eq "See gfm references" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{group_label.name}</span></a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{group_label.name}</span></a>\.\)}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do exp = act = %(Label #{Label.reference_prefix}"#{group_label.name.reverse}") expect(reference_filter(act).to_html).to eq exp end end - context 'with project reference' do + context "with project reference" do let(:reference) { "#{project.to_reference}#{group_label.to_reference(format: :name)}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}", project: project) - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_issues_url(project, label_name: group_label.name) expect(doc.text).to eq "See gfm references" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Label (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+><span.+>#{group_label.name}</span></a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+><span.+>#{group_label.name}</span></a>\.\)}) end - it 'ignores invalid label names' do + it "ignores invalid label names" do exp = act = %(Label #{project.to_reference}#{Label.reference_prefix}"#{group_label.name.reverse}") expect(reference_filter(act).to_html).to eq exp @@ -385,267 +385,267 @@ describe Banzai::Filter::LabelReferenceFilter do end end - describe 'cross-project / cross-namespace complete reference' do + describe "cross-project / cross-namespace complete reference" do let(:project2) { create(:project) } - let(:label) { create(:label, project: project2, color: '#00ff00') } + let(:label) { create(:label, project: project2, color: "#00ff00") } let(:reference) { "#{project2.full_path}~#{label.name}" } let!(:result) { reference_filter("See #{reference}") } - it 'links to a valid reference' do - expect(result.css('a').first.attr('href')) + it "links to a valid reference" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(project2, label_name: label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')).to match /background-color: #00ff00/ + it "has valid color" do + expect(result.css("a span").first.attr("style")).to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text).to eq "#{label.name} in #{project2.full_name}" + it "has valid link text" do + expect(result.css("a").first.text).to eq "#{label.name} in #{project2.full_name}" end - it 'has valid text' do + it "has valid text" do expect(result.text).to eq "See #{label.name} in #{project2.full_name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'cross-project / same-namespace complete reference' do + describe "cross-project / same-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, namespace: namespace) } let(:project2) { create(:project, namespace: namespace) } - let(:label) { create(:label, project: project2, color: '#00ff00') } + let(:label) { create(:label, project: project2, color: "#00ff00") } let(:reference) { "#{project2.full_path}~#{label.name}" } let!(:result) { reference_filter("See #{reference}") } - it 'links to a valid reference' do - expect(result.css('a').first.attr('href')) + it "links to a valid reference" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(project2, label_name: label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')).to match /background-color: #00ff00/ + it "has valid color" do + expect(result.css("a span").first.attr("style")).to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text).to eq "#{label.name} in #{project2.name}" + it "has valid link text" do + expect(result.css("a").first.text).to eq "#{label.name} in #{project2.name}" end - it 'has valid text' do + it "has valid text" do expect(result.text).to eq "See #{label.name} in #{project2.name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'cross-project shorthand reference' do + describe "cross-project shorthand reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, namespace: namespace) } let(:project2) { create(:project, namespace: namespace) } - let(:label) { create(:label, project: project2, color: '#00ff00') } + let(:label) { create(:label, project: project2, color: "#00ff00") } let(:reference) { "#{project2.path}~#{label.name}" } let!(:result) { reference_filter("See #{reference}") } - it 'links to a valid reference' do - expect(result.css('a').first.attr('href')) + it "links to a valid reference" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(project2, label_name: label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')) + it "has valid color" do + expect(result.css("a span").first.attr("style")) .to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text).to eq "#{label.name} in #{project2.name}" + it "has valid link text" do + expect(result.css("a").first.text).to eq "#{label.name} in #{project2.name}" end - it 'has valid text' do + it "has valid text" do expect(result.text).to eq "See #{label.name} in #{project2.name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'cross group label references' do + describe "cross group label references" do let(:group) { create(:group) } let(:project) { create(:project, :public, namespace: group) } let(:another_group) { create(:group) } let(:another_project) { create(:project, :public, namespace: another_group) } - let(:group_label) { create(:group_label, group: another_group, color: '#00ff00') } + let(:group_label) { create(:group_label, group: another_group, color: "#00ff00") } let(:reference) { "#{another_project.full_path}~#{group_label.name}" } let!(:result) { reference_filter("See #{reference}", project: project) } - it 'points to referenced project issues page' do - expect(result.css('a').first.attr('href')) + it "points to referenced project issues page" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(another_project, label_name: group_label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')) + it "has valid color" do + expect(result.css("a span").first.attr("style")) .to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text) + it "has valid link text" do + expect(result.css("a").first.text) .to eq "#{group_label.name} in #{another_project.full_name}" end - it 'has valid text' do + it "has valid text" do expect(result.text) .to eq "See #{group_label.name} in #{another_project.full_name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'cross-project / same-group_label complete reference' do + describe "cross-project / same-group_label complete reference" do let(:group) { create(:group) } let(:project) { create(:project, :public, namespace: group) } let(:another_project) { create(:project, :public, namespace: group) } - let(:group_label) { create(:group_label, group: group, color: '#00ff00') } + let(:group_label) { create(:group_label, group: group, color: "#00ff00") } let(:reference) { "#{another_project.full_path}~#{group_label.name}" } let!(:result) { reference_filter("See #{reference}", project: project) } - it 'points to referenced project issues page' do - expect(result.css('a').first.attr('href')) + it "points to referenced project issues page" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(another_project, label_name: group_label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')) + it "has valid color" do + expect(result.css("a span").first.attr("style")) .to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text) + it "has valid link text" do + expect(result.css("a").first.text) .to eq "#{group_label.name} in #{another_project.name}" end - it 'has valid text' do + it "has valid text" do expect(result.text) .to eq "See #{group_label.name} in #{another_project.name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'same project / same group_label complete reference' do + describe "same project / same group_label complete reference" do let(:group) { create(:group) } let(:project) { create(:project, :public, namespace: group) } - let(:group_label) { create(:group_label, group: group, color: '#00ff00') } + let(:group_label) { create(:group_label, group: group, color: "#00ff00") } let(:reference) { "#{project.full_path}~#{group_label.name}" } let!(:result) { reference_filter("See #{reference}", project: project) } - it 'points to referenced project issues page' do - expect(result.css('a').first.attr('href')) + it "points to referenced project issues page" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(project, label_name: group_label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')) + it "has valid color" do + expect(result.css("a span").first.attr("style")) .to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text).to eq group_label.name + it "has valid link text" do + expect(result.css("a").first.text).to eq group_label.name end - it 'has valid text' do + it "has valid text" do expect(result.text).to eq "See #{group_label.name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'same project / same group_label shorthand reference' do + describe "same project / same group_label shorthand reference" do let(:group) { create(:group) } let(:project) { create(:project, :public, namespace: group) } - let(:group_label) { create(:group_label, group: group, color: '#00ff00') } + let(:group_label) { create(:group_label, group: group, color: "#00ff00") } let(:reference) { "#{project.path}~#{group_label.name}" } let!(:result) { reference_filter("See #{reference}", project: project) } - it 'points to referenced project issues page' do - expect(result.css('a').first.attr('href')) + it "points to referenced project issues page" do + expect(result.css("a").first.attr("href")) .to eq urls.project_issues_url(project, label_name: group_label.name) end - it 'has valid color' do - expect(result.css('a span').first.attr('style')) + it "has valid color" do + expect(result.css("a span").first.attr("style")) .to match /background-color: #00ff00/ end - it 'has valid link text' do - expect(result.css('a').first.text).to eq group_label.name + it "has valid link text" do + expect(result.css("a").first.text).to eq group_label.name end - it 'has valid text' do + it "has valid text" do expect(result.text).to eq "See #{group_label.name}" end - it 'ignores invalid IDs on the referenced label' do + it "ignores invalid IDs on the referenced label" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - describe 'group context' do - it 'points to the page defined in label_url_method' do + describe "group context" do + it "points to the page defined in label_url_method" do group = create(:group) label = create(:group_label, group: group) reference = "~#{label.name}" - result = reference_filter("See #{reference}", { project: nil, group: group, label_url_method: :group_url } ) + result = reference_filter("See #{reference}", {project: nil, group: group, label_url_method: :group_url}) - expect(result.css('a').first.attr('href')).to eq(urls.group_url(group, label_name: label.name)) + expect(result.css("a").first.attr("href")).to eq(urls.group_url(group, label_name: label.name)) end - it 'finds labels also in ancestor groups' do + it "finds labels also in ancestor groups" do group = create(:group) label = create(:group_label, group: group) subgroup = create(:group, parent: group) reference = "~#{label.name}" - result = reference_filter("See #{reference}", { project: nil, group: subgroup, label_url_method: :group_url } ) + result = reference_filter("See #{reference}", {project: nil, group: subgroup, label_url_method: :group_url}) - expect(result.css('a').first.attr('href')).to eq(urls.group_url(subgroup, label_name: label.name)) + expect(result.css("a").first.attr("href")).to eq(urls.group_url(subgroup, label_name: label.name)) end - it 'points to referenced project issues page' do + it "points to referenced project issues page" do project = create(:project) label = create(:label, project: project) reference = "#{project.full_path}~#{label.name}" - result = reference_filter("See #{reference}", { project: nil, group: create(:group) } ) + result = reference_filter("See #{reference}", {project: nil, group: create(:group)}) - expect(result.css('a').first.attr('href')).to eq(urls.project_issues_url(project, label_name: label.name)) - expect(result.css('a').first.text).to eq "#{label.name} in #{project.full_name}" + expect(result.css("a").first.attr("href")).to eq(urls.project_issues_url(project, label_name: label.name)) + expect(result.css("a").first.text).to eq "#{label.name} in #{project.full_name}" end end end diff --git a/spec/lib/banzai/filter/markdown_filter_spec.rb b/spec/lib/banzai/filter/markdown_filter_spec.rb index 83fcda29680..f3fe1a07963 100644 --- a/spec/lib/banzai/filter/markdown_filter_spec.rb +++ b/spec/lib/banzai/filter/markdown_filter_spec.rb @@ -1,41 +1,41 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::MarkdownFilter do include FilterSpecHelper - describe 'markdown engine from context' do - it 'defaults to CommonMark' do - expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test') + describe "markdown engine from context" do + it "defaults to CommonMark" do + expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return("test") - filter('test') + filter("test") end - it 'uses CommonMark' do - expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test') + it "uses CommonMark" do + expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return("test") - filter('test', { markdown_engine: :common_mark }) + filter("test", {markdown_engine: :common_mark}) end end - describe 'code block' do - context 'using CommonMark' do + describe "code block" do + context "using CommonMark" do before do - stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark) + stub_const("Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE", :common_mark) end - it 'adds language to lang attribute when specified' do + it "adds language to lang attribute when specified" do result = filter("```html\nsome code\n```", no_sourcepos: true) expect(result).to start_with('<pre><code lang="html">') end - it 'does not add language to lang attribute when not specified' do + it "does not add language to lang attribute when not specified" do result = filter("```\nsome code\n```", no_sourcepos: true) - expect(result).to start_with('<pre><code>') + expect(result).to start_with("<pre><code>") end - it 'works with utf8 chars in language' do + it "works with utf8 chars in language" do result = filter("```日\nsome code\n```", no_sourcepos: true) expect(result).to start_with('<pre><code lang="日">') @@ -43,28 +43,28 @@ describe Banzai::Filter::MarkdownFilter do end end - describe 'source line position' do - context 'using CommonMark' do + describe "source line position" do + context "using CommonMark" do before do - stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark) + stub_const("Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE", :common_mark) end - it 'defaults to add data-sourcepos' do - result = filter('test') + it "defaults to add data-sourcepos" do + result = filter("test") expect(result).to eq '<p data-sourcepos="1:1-1:4">test</p>' end - it 'disables data-sourcepos' do - result = filter('test', no_sourcepos: true) + it "disables data-sourcepos" do + result = filter("test", no_sourcepos: true) - expect(result).to eq '<p>test</p>' + expect(result).to eq "<p>test</p>" end end end - describe 'footnotes in tables' do - it 'processes footnotes in table cells' do + describe "footnotes in tables" do + it "processes footnotes in table cells" do text = <<-MD.strip_heredoc | Column1 | | --------- | @@ -75,7 +75,7 @@ describe Banzai::Filter::MarkdownFilter do result = filter(text, no_sourcepos: true) - expect(result).to include('<td>foot <sup') + expect(result).to include("<td>foot <sup") expect(result).to include('<section class="footnotes">') end end diff --git a/spec/lib/banzai/filter/math_filter_spec.rb b/spec/lib/banzai/filter/math_filter_spec.rb index cade8cb409e..1cb732fad33 100644 --- a/spec/lib/banzai/filter/math_filter_spec.rb +++ b/spec/lib/banzai/filter/math_filter_spec.rb @@ -1,86 +1,86 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::MathFilter do include FilterSpecHelper - it 'leaves regular inline code unchanged' do + it "leaves regular inline code unchanged" do input = "<code>2+2</code>" doc = filter(input) expect(doc.to_s).to eq input end - it 'removes surrounding dollar signs and adds class code, math and js-render-math' do + it "removes surrounding dollar signs and adds class code, math and js-render-math" do doc = filter("$<code>2+2</code>$") expect(doc.to_s).to eq '<code class="code math js-render-math" data-math-style="inline">2+2</code>' end - it 'only removes surrounding dollar signs' do + it "only removes surrounding dollar signs" do doc = filter("test $<code>2+2</code>$ test") - before = doc.xpath('descendant-or-self::text()[1]').first - after = doc.xpath('descendant-or-self::text()[3]').first + before = doc.xpath("descendant-or-self::text()[1]").first + after = doc.xpath("descendant-or-self::text()[3]").first - expect(before.to_s).to eq 'test ' - expect(after.to_s).to eq ' test' + expect(before.to_s).to eq "test " + expect(after.to_s).to eq " test" end - it 'only removes surrounding single dollar sign' do + it "only removes surrounding single dollar sign" do doc = filter("test $$<code>2+2</code>$$ test") - before = doc.xpath('descendant-or-self::text()[1]').first - after = doc.xpath('descendant-or-self::text()[3]').first + before = doc.xpath("descendant-or-self::text()[1]").first + after = doc.xpath("descendant-or-self::text()[3]").first - expect(before.to_s).to eq 'test $' - expect(after.to_s).to eq '$ test' + expect(before.to_s).to eq "test $" + expect(after.to_s).to eq "$ test" end - it 'adds data-math-style inline attribute to inline math' do - doc = filter('$<code>2+2</code>$') - code = doc.xpath('descendant-or-self::code').first + it "adds data-math-style inline attribute to inline math" do + doc = filter("$<code>2+2</code>$") + code = doc.xpath("descendant-or-self::code").first - expect(code['data-math-style']).to eq 'inline' + expect(code["data-math-style"]).to eq "inline" end - it 'adds class code and math to inline math' do - doc = filter('$<code>2+2</code>$') - code = doc.xpath('descendant-or-self::code').first + it "adds class code and math to inline math" do + doc = filter("$<code>2+2</code>$") + code = doc.xpath("descendant-or-self::code").first expect(code[:class]).to include("code") expect(code[:class]).to include("math") end - it 'adds js-render-math class to inline math' do - doc = filter('$<code>2+2</code>$') - code = doc.xpath('descendant-or-self::code').first + it "adds js-render-math class to inline math" do + doc = filter("$<code>2+2</code>$") + code = doc.xpath("descendant-or-self::code").first expect(code[:class]).to include("js-render-math") end # Cases with faulty syntax. Should be a no-op - it 'ignores cases with missing dolar sign at the end' do + it "ignores cases with missing dolar sign at the end" do input = "test $<code>2+2</code> test" doc = filter(input) expect(doc.to_s).to eq input end - it 'ignores cases with missing dolar sign at the beginning' do + it "ignores cases with missing dolar sign at the beginning" do input = "test <code>2+2</code>$ test" doc = filter(input) expect(doc.to_s).to eq input end - it 'ignores dollar signs if it is not adjacent' do - input = '<p>We check strictly $<code>2+2</code> and <code>2+2</code>$ </p>' + it "ignores dollar signs if it is not adjacent" do + input = "<p>We check strictly $<code>2+2</code> and <code>2+2</code>$ </p>" doc = filter(input) expect(doc.to_s).to eq input end - it 'ignores dollar signs if they are inside another element' do - input = '<p>We check strictly <em>$</em><code>2+2</code><em>$</em></p>' + it "ignores dollar signs if they are inside another element" do + input = "<p>We check strictly <em>$</em><code>2+2</code><em>$</em></p>" doc = filter(input) expect(doc.to_s).to eq input @@ -88,40 +88,40 @@ describe Banzai::Filter::MathFilter do # Display math - it 'adds data-math-style display attribute to display math' do + it "adds data-math-style display attribute to display math" do doc = filter('<pre class="code highlight js-syntax-highlight math" v-pre="true"><code>2+2</code></pre>') - pre = doc.xpath('descendant-or-self::pre').first + pre = doc.xpath("descendant-or-self::pre").first - expect(pre['data-math-style']).to eq 'display' + expect(pre["data-math-style"]).to eq "display" end - it 'adds js-render-math class to display math' do + it "adds js-render-math class to display math" do doc = filter('<pre class="code highlight js-syntax-highlight math" v-pre="true"><code>2+2</code></pre>') - pre = doc.xpath('descendant-or-self::pre').first + pre = doc.xpath("descendant-or-self::pre").first expect(pre[:class]).to include("js-render-math") end - it 'ignores code blocks that are not math' do + it "ignores code blocks that are not math" do input = '<pre class="code highlight js-syntax-highlight plaintext" v-pre="true"><code>2+2</code></pre>' doc = filter(input) expect(doc.to_s).to eq input end - it 'requires the pre to contain both code and math' do + it "requires the pre to contain both code and math" do input = '<pre class="highlight js-syntax-highlight plaintext math" v-pre="true"><code>2+2</code></pre>' doc = filter(input) expect(doc.to_s).to eq input end - it 'dollar signs around to display math' do + it "dollar signs around to display math" do doc = filter('$<pre class="code highlight js-syntax-highlight math" v-pre="true"><code>2+2</code></pre>$') - before = doc.xpath('descendant-or-self::text()[1]').first - after = doc.xpath('descendant-or-self::text()[3]').first + before = doc.xpath("descendant-or-self::text()[1]").first + after = doc.xpath("descendant-or-self::text()[3]").first - expect(before.to_s).to eq '$' - expect(after.to_s).to eq '$' + expect(before.to_s).to eq "$" + expect(after.to_s).to eq "$" end end diff --git a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb index 55c41e55437..705220a7a82 100644 --- a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::MergeRequestReferenceFilter do include FilterSpecHelper @@ -6,21 +6,21 @@ describe Banzai::Filter::MergeRequestReferenceFilter do let(:project) { create(:project, :public) } let(:merge) { create(:merge_request, source_project: project) } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Merge #{merge.to_reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - describe 'performance' do - let(:another_merge) { create(:merge_request, source_project: project, source_branch: 'fix') } + describe "performance" do + let(:another_merge) { create(:merge_request, source_project: project, source_branch: "fix") } - it 'does not have a N+1 query problem' do + it "does not have a N+1 query problem" do single_reference = "Merge request #{merge.to_reference}" multiple_references = "Merge requests #{merge.to_reference} and #{another_merge.to_reference}" @@ -30,206 +30,206 @@ describe Banzai::Filter::MergeRequestReferenceFilter do end end - context 'internal reference' do + context "internal reference" do let(:reference) { merge.to_reference } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_merge_request_url(project, merge) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Merge (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(reference)}</a>\.\)}) end - it 'ignores invalid merge IDs' do + it "ignores invalid merge IDs" do exp = act = "Merge #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end - it 'ignores out-of-bounds merge request IDs on the referenced project' do + it "ignores out-of-bounds merge request IDs on the referenced project" do exp = act = "Merge !#{Gitlab::Database::MAX_INT_VALUE + 1}" expect(reference_filter(act).to_html).to eq exp end - it 'includes a title attribute' do + it "includes a title attribute" do doc = reference_filter("Merge #{reference}") - expect(doc.css('a').first.attr('title')).to eq merge.title + expect(doc.css("a").first.attr("title")).to eq merge.title end - it 'escapes the title attribute' do - merge.update_attribute(:title, %{"></a>whatever<a title="}) + it "escapes the title attribute" do + merge.update_attribute(:title, %("></a>whatever<a title=")) doc = reference_filter("Merge #{reference}") expect(doc.text).to eq "Merge #{reference}" end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Merge #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-merge_request has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-merge_request has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Merge #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-merge-request attribute' do + it "includes a data-merge-request attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-merge-request') - expect(link.attr('data-merge-request')).to eq merge.id.to_s + expect(link).to have_attribute("data-merge-request") + expect(link.attr("data-merge-request")).to eq merge.id.to_s end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = reference_filter("Merge #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq urls.project_merge_request_url(project, merge, only_path: true) end end - context 'cross-project / cross-namespace complete reference' do + context "cross-project / cross-namespace complete reference" do let(:project2) { create(:project, :public) } let(:merge) { create(:merge_request, source_project: project2) } let(:reference) { "#{project2.full_path}!#{merge.iid}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_merge_request_url(project2, merge) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Merge (#{reference}.)") - expect(doc.css('a').first.text).to eq(reference) + expect(doc.css("a").first.text).to eq(reference) end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Merge (#{reference}.)") expect(doc.text).to eq("Merge (#{reference}.)") end - it 'ignores invalid merge IDs on the referenced project' do + it "ignores invalid merge IDs on the referenced project" do exp = act = "Merge #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project / same-namespace complete reference' do + context "cross-project / same-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } let(:project2) { create(:project, :public, namespace: namespace) } let!(:merge) { create(:merge_request, source_project: project2) } let(:reference) { "#{project2.full_path}!#{merge.iid}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_merge_request_url(project2, merge) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Merge (#{reference}.)") - expect(doc.css('a').first.text).to eq("#{project2.path}!#{merge.iid}") + expect(doc.css("a").first.text).to eq("#{project2.path}!#{merge.iid}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Merge (#{reference}.)") expect(doc.text).to eq("Merge (#{project2.path}!#{merge.iid}.)") end - it 'ignores invalid merge IDs on the referenced project' do + it "ignores invalid merge IDs on the referenced project" do exp = act = "Merge #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project shorthand reference' do + context "cross-project shorthand reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } let(:project2) { create(:project, :public, namespace: namespace) } let!(:merge) { create(:merge_request, source_project: project2) } let(:reference) { "#{project2.path}!#{merge.iid}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_merge_request_url(project2, merge) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("Merge (#{reference}.)") - expect(doc.css('a').first.text).to eq("#{project2.path}!#{merge.iid}") + expect(doc.css("a").first.text).to eq("#{project2.path}!#{merge.iid}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("Merge (#{reference}.)") expect(doc.text).to eq("Merge (#{project2.path}!#{merge.iid}.)") end - it 'ignores invalid merge IDs on the referenced project' do + it "ignores invalid merge IDs on the referenced project" do exp = act = "Merge #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'URL reference for a commit' do + context "URL reference for a commit" do let(:mr) { create(:merge_request, :with_diffs) } let(:reference) do urls.project_merge_request_url(mr.project, mr) + "/diffs?commit_id=#{mr.diff_head_sha}" end let(:commit) { mr.commits.find { |commit| commit.sha == mr.diff_head_sha } } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq reference end - it 'commit ref tag is valid' do + it "commit ref tag is valid" do doc = reference_filter("See #{reference}") - commit_ref_tag = doc.css('a').first.css('span.gfm.gfm-commit') + commit_ref_tag = doc.css("a").first.css("span.gfm.gfm-commit") expect(commit_ref_tag.text).to eq(commit.short_id) end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See #{reference}") expect(doc.text).to eq("See #{mr.to_reference(full: true)} (#{commit.short_id})") end - it 'has valid title attribute' do + it "has valid title attribute" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('title')).to eq(commit.title) + expect(doc.css("a").first.attr("title")).to eq(commit.title) end - it 'ignores invalid commit short_ids on link text' do + it "ignores invalid commit short_ids on link text" do invalidate_commit_reference = urls.project_merge_request_url(mr.project, mr) + "/diffs?commit_id=12345678" doc = reference_filter("See #{invalidate_commit_reference}") @@ -238,32 +238,32 @@ describe Banzai::Filter::MergeRequestReferenceFilter do end end - context 'cross-project URL reference' do - let(:namespace) { create(:namespace, name: 'cross-reference') } + context "cross-project URL reference" do + let(:namespace) { create(:namespace, name: "cross-reference") } let(:project2) { create(:project, :public, namespace: namespace) } let(:merge) { create(:merge_request, source_project: project2, target_project: project2) } - let(:reference) { urls.project_merge_request_url(project2, merge) + '/diffs#note_123' } + let(:reference) { urls.project_merge_request_url(project2, merge) + "/diffs#note_123" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq reference end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Merge (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(merge.to_reference(project))} \(diffs, comment 123\)</a>\.\)}) end end - context 'group context' do - it 'links to a valid reference' do + context "group context" do + it "links to a valid reference" do reference = "#{project.full_path}!#{merge.iid}" - result = reference_filter("See #{reference}", { project: nil, group: create(:group) } ) + result = reference_filter("See #{reference}", {project: nil, group: create(:group)}) - expect(result.css('a').first.attr('href')).to eq(urls.project_merge_request_url(project, merge)) + expect(result.css("a").first.attr("href")).to eq(urls.project_merge_request_url(project, merge)) end end end diff --git a/spec/lib/banzai/filter/mermaid_filter_spec.rb b/spec/lib/banzai/filter/mermaid_filter_spec.rb index f6474c8936d..5e9e308f3b2 100644 --- a/spec/lib/banzai/filter/mermaid_filter_spec.rb +++ b/spec/lib/banzai/filter/mermaid_filter_spec.rb @@ -1,12 +1,12 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::MermaidFilter do include FilterSpecHelper - it 'adds `js-render-mermaid` class to the `code` tag' do + it "adds `js-render-mermaid` class to the `code` tag" do doc = filter("<pre class='code highlight js-syntax-highlight mermaid' lang='mermaid' v-pre='true'><code>graph TD;\n A-->B;\n</code></pre>") - result = doc.css('code').first + result = doc.css("code").first - expect(result[:class]).to include('js-render-mermaid') + expect(result[:class]).to include("js-render-mermaid") end end diff --git a/spec/lib/banzai/filter/milestone_reference_filter_spec.rb b/spec/lib/banzai/filter/milestone_reference_filter_spec.rb index 4c94e4fdae0..193dfc786db 100644 --- a/spec/lib/banzai/filter/milestone_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/milestone_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::MilestoneReferenceFilter do include FilterSpecHelper @@ -7,221 +7,221 @@ describe Banzai::Filter::MilestoneReferenceFilter do let(:group) { create(:group, :public, parent: parent_group) } let(:project) { create(:project, :public, group: group) } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - shared_examples 'reference parsing' do - %w(pre code a style).each do |elem| + shared_examples "reference parsing" do + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>milestone #{reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Milestone #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-milestone has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-milestone has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Milestone #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-milestone attribute' do + it "includes a data-milestone attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-milestone') - expect(link.attr('data-milestone')).to eq milestone.id.to_s + expect(link).to have_attribute("data-milestone") + expect(link.attr("data-milestone")).to eq milestone.id.to_s end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = reference_filter("Milestone #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq urls.milestone_path(milestone) end end - shared_examples 'Integer-based references' do - it 'links to a valid reference' do + shared_examples "Integer-based references" do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.milestone_url(milestone) + expect(doc.css("a").first.attr("href")).to eq urls.milestone_url(milestone) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Milestone (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+>#{milestone.reference_link_text}</a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+>#{milestone.reference_link_text}</a>\.\)}) end - it 'ignores invalid milestone IIDs' do + it "ignores invalid milestone IIDs" do exp = act = "Milestone #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - shared_examples 'String-based single-word references' do + shared_examples "String-based single-word references" do let(:reference) { "#{Milestone.reference_prefix}#{milestone.name}" } before do - milestone.update!(name: 'gfm') + milestone.update!(name: "gfm") end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.milestone_url(milestone) + expect(doc.css("a").first.attr("href")).to eq urls.milestone_url(milestone) expect(doc.text).to eq "See #{milestone.reference_link_text}" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Milestone (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+>#{milestone.reference_link_text}</a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+>#{milestone.reference_link_text}</a>\.\)}) end - it 'ignores invalid milestone names' do + it "ignores invalid milestone names" do exp = act = "Milestone #{Milestone.reference_prefix}#{milestone.name.reverse}" expect(reference_filter(act).to_html).to eq exp end end - shared_examples 'String-based multi-word references in quotes' do + shared_examples "String-based multi-word references in quotes" do let(:reference) { milestone.to_reference(format: :name) } before do - milestone.update!(name: 'gfm references') + milestone.update!(name: "gfm references") end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.milestone_url(milestone) + expect(doc.css("a").first.attr("href")).to eq urls.milestone_url(milestone) expect(doc.text).to eq "See #{milestone.reference_link_text}" end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Milestone (#{reference}.)") - expect(doc.to_html).to match(%r(\(<a.+>#{milestone.reference_link_text}</a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+>#{milestone.reference_link_text}</a>\.\)}) end - it 'ignores invalid milestone names' do + it "ignores invalid milestone names" do exp = act = %(Milestone #{Milestone.reference_prefix}"#{milestone.name.reverse}") expect(reference_filter(act).to_html).to eq exp end end - shared_examples 'referencing a milestone in a link href' do + shared_examples "referencing a milestone in a link href" do let(:unquoted_reference) { "#{Milestone.reference_prefix}#{milestone.name}" } - let(:link_reference) { %Q{<a href="#{unquoted_reference}">Milestone</a>} } + let(:link_reference) { %(<a href="#{unquoted_reference}">Milestone</a>) } before do - milestone.update!(name: 'gfm') + milestone.update!(name: "gfm") end - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{link_reference}") - expect(doc.css('a').first.attr('href')).to eq urls.milestone_url(milestone) + expect(doc.css("a").first.attr("href")).to eq urls.milestone_url(milestone) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Milestone (#{link_reference}.)") - expect(doc.to_html).to match(%r(\(<a.+>Milestone</a>\.\))) + expect(doc.to_html).to match(%r{\(<a.+>Milestone</a>\.\)}) end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Milestone #{link_reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-milestone attribute' do + it "includes a data-milestone attribute" do doc = reference_filter("See #{link_reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-milestone') - expect(link.attr('data-milestone')).to eq milestone.id.to_s + expect(link).to have_attribute("data-milestone") + expect(link.attr("data-milestone")).to eq milestone.id.to_s end end - shared_examples 'linking to a milestone as the entire link' do + shared_examples "linking to a milestone as the entire link" do let(:unquoted_reference) { "#{Milestone.reference_prefix}#{milestone.name}" } let(:link) { urls.milestone_url(milestone) } - let(:link_reference) { %Q{<a href="#{link}">#{link}</a>} } + let(:link_reference) { %(<a href="#{link}">#{link}</a>) } - it 'replaces the link text with the milestone reference' do + it "replaces the link text with the milestone reference" do doc = reference_filter("See #{link}") - expect(doc.css('a').first.text).to eq(unquoted_reference) + expect(doc.css("a").first.text).to eq(unquoted_reference) end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Milestone #{link_reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-milestone attribute' do + it "includes a data-milestone attribute" do doc = reference_filter("See #{link_reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-milestone') - expect(link.attr('data-milestone')).to eq milestone.id.to_s + expect(link).to have_attribute("data-milestone") + expect(link.attr("data-milestone")).to eq milestone.id.to_s end end - shared_examples 'cross-project / cross-namespace complete reference' do + shared_examples "cross-project / cross-namespace complete reference" do let(:namespace) { create(:namespace) } let(:another_project) { create(:project, :public, namespace: namespace) } let(:milestone) { create(:milestone, project: another_project) } let(:reference) { "#{another_project.full_path}%#{milestone.iid}" } let!(:result) { reference_filter("See #{reference}") } - it 'points to referenced project milestone page' do - expect(result.css('a').first.attr('href')).to eq urls + it "points to referenced project milestone page" do + expect(result.css("a").first.attr("href")).to eq urls .project_milestone_url(another_project, milestone) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eq("#{milestone.reference_link_text} in #{another_project.full_path}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text) .to eq("See (#{milestone.reference_link_text} in #{another_project.full_path}.)") end - it 'escapes the name attribute' do - allow_any_instance_of(Milestone).to receive(:title).and_return(%{"></a>whatever<a title="}) + it "escapes the name attribute" do + allow_any_instance_of(Milestone).to receive(:title).and_return(%("></a>whatever<a title=")) doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eq "#{milestone.reference_link_text} in #{another_project.full_path}" end end - shared_examples 'cross-project / same-namespace complete reference' do + shared_examples "cross-project / same-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } let(:another_project) { create(:project, :public, namespace: namespace) } @@ -229,36 +229,36 @@ describe Banzai::Filter::MilestoneReferenceFilter do let(:reference) { "#{another_project.full_path}%#{milestone.iid}" } let!(:result) { reference_filter("See #{reference}") } - it 'points to referenced project milestone page' do - expect(result.css('a').first.attr('href')).to eq urls + it "points to referenced project milestone page" do + expect(result.css("a").first.attr("href")).to eq urls .project_milestone_url(another_project, milestone) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eq("#{milestone.reference_link_text} in #{another_project.path}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text) .to eq("See (#{milestone.reference_link_text} in #{another_project.path}.)") end - it 'escapes the name attribute' do - allow_any_instance_of(Milestone).to receive(:title).and_return(%{"></a>whatever<a title="}) + it "escapes the name attribute" do + allow_any_instance_of(Milestone).to receive(:title).and_return(%("></a>whatever<a title=")) doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eq "#{milestone.reference_link_text} in #{another_project.path}" end end - shared_examples 'cross project shorthand reference' do + shared_examples "cross project shorthand reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } let(:another_project) { create(:project, :public, namespace: namespace) } @@ -266,71 +266,71 @@ describe Banzai::Filter::MilestoneReferenceFilter do let(:reference) { "#{another_project.path}%#{milestone.iid}" } let!(:result) { reference_filter("See #{reference}") } - it 'points to referenced project milestone page' do - expect(result.css('a').first.attr('href')).to eq urls + it "points to referenced project milestone page" do + expect(result.css("a").first.attr("href")).to eq urls .project_milestone_url(another_project, milestone) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eq("#{milestone.reference_link_text} in #{another_project.path}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text) .to eq("See (#{milestone.reference_link_text} in #{another_project.path}.)") end - it 'escapes the name attribute' do - allow_any_instance_of(Milestone).to receive(:title).and_return(%{"></a>whatever<a title="}) + it "escapes the name attribute" do + allow_any_instance_of(Milestone).to receive(:title).and_return(%("></a>whatever<a title=")) doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text) + expect(doc.css("a").first.text) .to eq "#{milestone.reference_link_text} in #{another_project.path}" end end - shared_context 'project milestones' do + shared_context "project milestones" do let(:reference) { milestone.to_reference(format: :iid) } - include_examples 'reference parsing' + include_examples "reference parsing" - it_behaves_like 'Integer-based references' - it_behaves_like 'String-based single-word references' - it_behaves_like 'String-based multi-word references in quotes' - it_behaves_like 'referencing a milestone in a link href' - it_behaves_like 'cross-project / cross-namespace complete reference' - it_behaves_like 'cross-project / same-namespace complete reference' - it_behaves_like 'cross project shorthand reference' + it_behaves_like "Integer-based references" + it_behaves_like "String-based single-word references" + it_behaves_like "String-based multi-word references in quotes" + it_behaves_like "referencing a milestone in a link href" + it_behaves_like "cross-project / cross-namespace complete reference" + it_behaves_like "cross-project / same-namespace complete reference" + it_behaves_like "cross project shorthand reference" end - shared_context 'group milestones' do + shared_context "group milestones" do let(:reference) { milestone.to_reference(format: :name) } - include_examples 'reference parsing' + include_examples "reference parsing" - it_behaves_like 'String-based single-word references' - it_behaves_like 'String-based multi-word references in quotes' - it_behaves_like 'referencing a milestone in a link href' + it_behaves_like "String-based single-word references" + it_behaves_like "String-based multi-word references in quotes" + it_behaves_like "referencing a milestone in a link href" - it 'does not support references by IID' do + it "does not support references by IID" do doc = reference_filter("See #{Milestone.reference_prefix}#{milestone.iid}") - expect(doc.css('a')).to be_empty + expect(doc.css("a")).to be_empty end - it 'does not support references by link' do + it "does not support references by link" do doc = reference_filter("See #{urls.milestone_url(milestone)}") - expect(doc.css('a').first.text).to eq(urls.milestone_url(milestone)) + expect(doc.css("a").first.text).to eq(urls.milestone_url(milestone)) end - it 'does not support cross-project references' do + it "does not support cross-project references" do another_group = create(:group) another_project = create(:project, :public, group: group) project_reference = another_project.to_reference(project) @@ -339,58 +339,58 @@ describe Banzai::Filter::MilestoneReferenceFilter do doc = reference_filter("See #{project_reference}#{reference}") - expect(doc.css('a')).to be_empty + expect(doc.css("a")).to be_empty end - it 'supports parent group references', :nested_groups do + it "supports parent group references", :nested_groups do milestone.update!(group: parent_group) doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text).to eq(milestone.reference_link_text) + expect(doc.css("a").first.text).to eq(milestone.reference_link_text) end end - context 'group context' do + context "group context" do let(:group) { create(:group) } - let(:context) { { project: nil, group: group } } + let(:context) { {project: nil, group: group} } - context 'when project milestone' do + context "when project milestone" do let(:milestone) { create(:milestone, project: project) } - it 'links to a valid reference' do + it "links to a valid reference" do reference = "#{project.full_path}%#{milestone.iid}" result = reference_filter("See #{reference}", context) - expect(result.css('a').first.attr('href')).to eq(urls.milestone_url(milestone)) + expect(result.css("a").first.attr("href")).to eq(urls.milestone_url(milestone)) end - it 'ignores internal references' do + it "ignores internal references" do exp = act = "See %#{milestone.iid}" expect(reference_filter(act, context).to_html).to eq exp end end - context 'when group milestone' do - let(:group_milestone) { create(:milestone, title: 'group_milestone', group: group) } + context "when group milestone" do + let(:group_milestone) { create(:milestone, title: "group_milestone", group: group) } - context 'for subgroups', :nested_groups do + context "for subgroups", :nested_groups do let(:sub_group) { create(:group, parent: group) } - let(:sub_group_milestone) { create(:milestone, title: 'sub_group_milestone', group: sub_group) } + let(:sub_group_milestone) { create(:milestone, title: "sub_group_milestone", group: sub_group) } - it 'links to a valid reference of subgroup and group milestones' do + it "links to a valid reference of subgroup and group milestones" do [group_milestone, sub_group_milestone].each do |milestone| reference = "%#{milestone.title}" - result = reference_filter("See #{reference}", { project: nil, group: sub_group }) + result = reference_filter("See #{reference}", {project: nil, group: sub_group}) - expect(result.css('a').first.attr('href')).to eq(urls.milestone_url(milestone)) + expect(result.css("a").first.attr("href")).to eq(urls.milestone_url(milestone)) end end end - it 'ignores internal references' do + it "ignores internal references" do exp = act = "See %#{group_milestone.iid}" expect(reference_filter(act, context).to_html).to eq exp @@ -398,31 +398,31 @@ describe Banzai::Filter::MilestoneReferenceFilter do end end - context 'when milestone is open' do - context 'project milestones' do + context "when milestone is open" do + context "project milestones" do let(:milestone) { create(:milestone, project: project) } - include_context 'project milestones' + include_context "project milestones" end - context 'group milestones' do + context "group milestones" do let(:milestone) { create(:milestone, group: group) } - include_context 'group milestones' + include_context "group milestones" end end - context 'when milestone is closed' do - context 'project milestones' do + context "when milestone is closed" do + context "project milestones" do let(:milestone) { create(:milestone, :closed, project: project) } - include_context 'project milestones' + include_context "project milestones" end - context 'group milestones' do + context "group milestones" do let(:milestone) { create(:milestone, :closed, group: group) } - include_context 'group milestones' + include_context "group milestones" end end end diff --git a/spec/lib/banzai/filter/plantuml_filter_spec.rb b/spec/lib/banzai/filter/plantuml_filter_spec.rb index 8235c411eb7..fe20661da97 100644 --- a/spec/lib/banzai/filter/plantuml_filter_spec.rb +++ b/spec/lib/banzai/filter/plantuml_filter_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::PlantumlFilter do include FilterSpecHelper - it 'should replace plantuml pre tag with img tag' do + it "should replace plantuml pre tag with img tag" do stub_application_setting(plantuml_enabled: true, plantuml_url: "http://localhost:8080") input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' output = '<div class="imageblock"><div class="content"><img class="plantuml" src="http://localhost:8080/png/U9npoazIqBLJ24uiIbImKl18pSd91m0rkGMq"></div></div>' @@ -12,7 +12,7 @@ describe Banzai::Filter::PlantumlFilter do expect(doc.to_s).to eq output end - it 'should not replace plantuml pre tag with img tag if disabled' do + it "should not replace plantuml pre tag with img tag if disabled" do stub_application_setting(plantuml_enabled: false) input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' output = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' @@ -21,7 +21,7 @@ describe Banzai::Filter::PlantumlFilter do expect(doc.to_s).to eq output end - it 'should not replace plantuml pre tag with img tag if url is invalid' do + it "should not replace plantuml pre tag with img tag if url is invalid" do stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid") input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> PlantUML Error: cannot connect to PlantUML server at "invalid"</pre></div></div>' diff --git a/spec/lib/banzai/filter/project_reference_filter_spec.rb b/spec/lib/banzai/filter/project_reference_filter_spec.rb index 69f9c1ae829..abd9b0c1a10 100644 --- a/spec/lib/banzai/filter/project_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/project_reference_filter_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::ProjectReferenceFilter do include FilterSpecHelper def invalidate_reference(reference) - "#{reference.reverse}" + reference.reverse.to_s end def get_reference(project) @@ -18,70 +18,70 @@ describe Banzai::Filter::ProjectReferenceFilter do let(:subject_name) { "project" } let(:reference) { get_reference(project) } - it_behaves_like 'user reference or project reference' + it_behaves_like "user reference or project reference" - it 'ignores invalid projects' do + it "ignores invalid projects" do exp = act = "Hey #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq(CGI.escapeHTML(exp)) end - it 'fails fast for long invalid string' do - expect do + it "fails fast for long invalid string" do + expect { Timeout.timeout(5.seconds) { reference_filter("A" * 50000).to_html } - end.not_to raise_error + }.not_to raise_error end - it 'allows references with text after the > character' do + it "allows references with text after the > character" do doc = reference_filter("Hey #{reference}foo") - expect(doc.css('a').first.attr('href')).to eq urls.project_url(subject) + expect(doc.css("a").first.attr("href")).to eq urls.project_url(subject) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Hey #{CGI.escapeHTML(reference)}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-project has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-project has-tooltip" end - context 'in group context' do + context "in group context" do let(:group) { create(:group) } let(:project) { create(:project, group: group) } let(:nested_group) { create(:group, :nested) } let(:nested_project) { create(:project, group: nested_group) } - it 'supports mentioning a project' do + it "supports mentioning a project" do reference = get_reference(project) doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.project_url(project) + expect(doc.css("a").first.attr("href")).to eq urls.project_url(project) end - it 'supports mentioning a project in a nested group' do + it "supports mentioning a project in a nested group" do reference = get_reference(nested_project) doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.project_url(nested_project) + expect(doc.css("a").first.attr("href")).to eq urls.project_url(nested_project) end end - describe '#projects_hash' do - it 'returns a Hash containing all Projects' do + describe "#projects_hash" do + it "returns a Hash containing all Projects" do document = Nokogiri::HTML.fragment("<p>#{get_reference(project)}</p>") filter = described_class.new(document, project: project) - expect(filter.projects_hash).to eq({ project.full_path => project }) + expect(filter.projects_hash).to eq({project.full_path => project}) end end - describe '#projects' do - it 'returns the projects mentioned in a document' do + describe "#projects" do + it "returns the projects mentioned in a document" do document = Nokogiri::HTML.fragment("<p>#{get_reference(project)}</p>") filter = described_class.new(document, project: project) diff --git a/spec/lib/banzai/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb index 919825a6102..634395167f5 100644 --- a/spec/lib/banzai/filter/redactor_filter_spec.rb +++ b/spec/lib/banzai/filter/redactor_filter_spec.rb @@ -1,31 +1,31 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::RedactorFilter do include ActionView::Helpers::UrlHelper include FilterSpecHelper - it 'ignores non-GFM links' do + it "ignores non-GFM links" do html = %(See <a href="https://google.com/">Google</a>) doc = filter(html, current_user: build(:user)) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end def reference_link(data) - link_to('text', '', class: 'gfm', data: data) + link_to("text", "", class: "gfm", data: data) end - it 'skips when the skip_redaction flag is set' do + it "skips when the skip_redaction flag is set" do user = create(:user) project = create(:project) - link = reference_link(project: project.id, reference_type: 'test') + link = reference_link(project: project.id, reference_type: "test") doc = filter(link, current_user: user, skip_redaction: true) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end - context 'with data-project' do + context "with data-project" do let(:parser_class) do Class.new(Banzai::ReferenceParser::BaseParser) do self.reference_type = :test @@ -34,171 +34,171 @@ describe Banzai::Filter::RedactorFilter do before do allow(Banzai::ReferenceParser).to receive(:[]) - .with('test') + .with("test") .and_return(parser_class) end - context 'valid projects' do + context "valid projects" do before do allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(true) end - it 'allows permitted Project references' do + it "allows permitted Project references" do user = create(:user) project = create(:project) project.add_maintainer(user) - link = reference_link(project: project.id, reference_type: 'test') + link = reference_link(project: project.id, reference_type: "test") doc = filter(link, current_user: user) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end end - context 'invalid projects' do + context "invalid projects" do before do allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(false) end - it 'removes unpermitted references' do + it "removes unpermitted references" do user = create(:user) project = create(:project) - link = reference_link(project: project.id, reference_type: 'test') + link = reference_link(project: project.id, reference_type: "test") doc = filter(link, current_user: user) - expect(doc.css('a').length).to eq 0 + expect(doc.css("a").length).to eq 0 end - it 'handles invalid references' do - link = reference_link(project: 12345, reference_type: 'test') + it "handles invalid references" do + link = reference_link(project: 12345, reference_type: "test") expect { filter(link) }.not_to raise_error end end end - context 'with data-issue' do - context 'for confidential issues' do - it 'removes references for non project members' do + context "with data-issue" do + context "for confidential issues" do + it "removes references for non project members" do non_member = create(:user) project = create(:project, :public) issue = create(:issue, :confidential, project: project) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: non_member) - expect(doc.css('a').length).to eq 0 + expect(doc.css("a").length).to eq 0 end - it 'removes references for project members with guest role' do + it "removes references for project members with guest role" do member = create(:user) project = create(:project, :public) project.add_guest(member) issue = create(:issue, :confidential, project: project) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: member) - expect(doc.css('a').length).to eq 0 + expect(doc.css("a").length).to eq 0 end - it 'allows references for author' do + it "allows references for author" do author = create(:user) project = create(:project, :public) issue = create(:issue, :confidential, project: project, author: author) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: author) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end - it 'allows references for assignee' do + it "allows references for assignee" do assignee = create(:user) project = create(:project, :public) issue = create(:issue, :confidential, project: project, assignees: [assignee]) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: assignee) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end - it 'allows references for project members' do + it "allows references for project members" do member = create(:user) project = create(:project, :public) project.add_developer(member) issue = create(:issue, :confidential, project: project) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: member) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end - it 'allows references for admin' do + it "allows references for admin" do admin = create(:admin) project = create(:project, :public) issue = create(:issue, :confidential, project: project) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: admin) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end end - it 'allows references for non confidential issues' do + it "allows references for non confidential issues" do user = create(:user) project = create(:project, :public) issue = create(:issue, project: project) - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') + link = reference_link(project: project.id, issue: issue.id, reference_type: "issue") doc = filter(link, current_user: user) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end end context "for user references" do - context 'with data-group' do - it 'removes unpermitted Group references' do + context "with data-group" do + it "removes unpermitted Group references" do user = create(:user) group = create(:group, :private) - link = reference_link(group: group.id, reference_type: 'user') + link = reference_link(group: group.id, reference_type: "user") doc = filter(link, current_user: user) - expect(doc.css('a').length).to eq 0 + expect(doc.css("a").length).to eq 0 end - it 'allows permitted Group references' do + it "allows permitted Group references" do user = create(:user) group = create(:group, :private) group.add_developer(user) - link = reference_link(group: group.id, reference_type: 'user') + link = reference_link(group: group.id, reference_type: "user") doc = filter(link, current_user: user) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end - it 'handles invalid Group references' do - link = reference_link(group: 12345, reference_type: 'user') + it "handles invalid Group references" do + link = reference_link(group: 12345, reference_type: "user") expect { filter(link) }.not_to raise_error end end - context 'with data-user' do - it 'allows any User reference' do + context "with data-user" do + it "allows any User reference" do user = create(:user) - link = reference_link(user: user.id, reference_type: 'user') + link = reference_link(user: user.id, reference_type: "user") doc = filter(link) - expect(doc.css('a').length).to eq 1 + expect(doc.css("a").length).to eq 1 end end end diff --git a/spec/lib/banzai/filter/reference_filter_spec.rb b/spec/lib/banzai/filter/reference_filter_spec.rb index f96b6c83b0a..942cb6d8a4d 100644 --- a/spec/lib/banzai/filter/reference_filter_spec.rb +++ b/spec/lib/banzai/filter/reference_filter_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::ReferenceFilter do let(:project) { build_stubbed(:project) } - describe '#each_node' do - it 'iterates over the nodes in a document' do + describe "#each_node" do + it "iterates over the nodes in a document" do document = Nokogiri::HTML.fragment('<a href="foo">foo</a>') filter = described_class.new(document, project: project) @@ -12,7 +12,7 @@ describe Banzai::Filter::ReferenceFilter do .to yield_with_args(an_instance_of(Nokogiri::XML::Element)) end - it 'returns an Enumerator when no block is given' do + it "returns an Enumerator when no block is given" do document = Nokogiri::HTML.fragment('<a href="foo">foo</a>') filter = described_class.new(document, project: project) @@ -26,16 +26,16 @@ describe Banzai::Filter::ReferenceFilter do expect { |b| filter.each_node(&b) }.not_to yield_control end - it 'skips text nodes in pre elements' do - document = Nokogiri::HTML.fragment('<pre>foo</pre>') + it "skips text nodes in pre elements" do + document = Nokogiri::HTML.fragment("<pre>foo</pre>") filter = described_class.new(document, project: project) expect { |b| filter.each_node(&b) }.not_to yield_control end end - describe '#nodes' do - it 'returns an Array of the HTML nodes' do + describe "#nodes" do + it "returns an Array of the HTML nodes" do document = Nokogiri::HTML.fragment('<a href="foo">foo</a>') filter = described_class.new(document, project: project) diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index dad0a5535c0..c8b50eb69a5 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -1,15 +1,15 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::RelativeLinkFilter do def filter(doc, contexts = {}) contexts.reverse_merge!({ - commit: commit, - project: project, - group: group, - project_wiki: project_wiki, - ref: ref, + commit: commit, + project: project, + group: group, + project_wiki: project_wiki, + ref: ref, requested_path: requested_path, - only_path: only_path + only_path: only_path, }) described_class.call(doc, contexts) @@ -34,377 +34,377 @@ describe Banzai::Filter::RelativeLinkFilter do let(:project) { create(:project, :repository) } let(:group) { nil } let(:project_path) { project.full_path } - let(:ref) { 'markdown' } + let(:ref) { "markdown" } let(:commit) { project.commit(ref) } let(:project_wiki) { nil } - let(:requested_path) { '/' } + let(:requested_path) { "/" } let(:only_path) { true } shared_examples :preserve_unchanged do - it 'does not modify any relative URL in anchor' do - doc = filter(link('README.md')) - expect(doc.at_css('a')['href']).to eq 'README.md' + it "does not modify any relative URL in anchor" do + doc = filter(link("README.md")) + expect(doc.at_css("a")["href"]).to eq "README.md" end - it 'does not modify any relative URL in image' do - doc = filter(image('files/images/logo-black.png')) - expect(doc.at_css('img')['src']).to eq 'files/images/logo-black.png' + it "does not modify any relative URL in image" do + doc = filter(image("files/images/logo-black.png")) + expect(doc.at_css("img")["src"]).to eq "files/images/logo-black.png" end - it 'does not modify any relative URL in video' do - doc = filter(video('files/videos/intro.mp4'), commit: project.commit('video'), ref: 'video') + it "does not modify any relative URL in video" do + doc = filter(video("files/videos/intro.mp4"), commit: project.commit("video"), ref: "video") - expect(doc.at_css('video')['src']).to eq 'files/videos/intro.mp4' + expect(doc.at_css("video")["src"]).to eq "files/videos/intro.mp4" end end - context 'with a project_wiki' do - let(:project_wiki) { double('ProjectWiki') } + context "with a project_wiki" do + let(:project_wiki) { double("ProjectWiki") } include_examples :preserve_unchanged end - context 'without a repository' do + context "without a repository" do let(:project) { create(:project) } include_examples :preserve_unchanged end - context 'with an empty repository' do + context "with an empty repository" do let(:project) { create(:project_empty_repo) } include_examples :preserve_unchanged end - it 'does not raise an exception on invalid URIs' do + it "does not raise an exception on invalid URIs" do act = link("://foo") expect { filter(act) }.not_to raise_error end - it 'does not raise an exception with a garbled path' do + it "does not raise an exception with a garbled path" do act = link("open(/var/tmp/):%20/location%0Afrom:%20/test") expect { filter(act) }.not_to raise_error end - it 'does not raise an exception with a space in the path' do + it "does not raise an exception with a space in the path" do act = link("/uploads/d18213acd3732630991986120e167e3d/Landscape_8.jpg \nBut here's some more unexpected text :smile:)") expect { filter(act) }.not_to raise_error end - it 'ignores ref if commit is passed' do - doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') ) - expect(doc.at_css('a')['href']) + it "ignores ref if commit is passed" do + doc = filter(link("non/existent.file"), commit: project.commit("empty-branch")) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/#{ref}/non/existent.file" # non-existent files have no leading blob/raw/tree end shared_examples :valid_repository do - it 'rebuilds absolute URL for a file in the repo' do - doc = filter(link('/doc/api/README.md')) - expect(doc.at_css('a')['href']) + it "rebuilds absolute URL for a file in the repo" do + doc = filter(link("/doc/api/README.md")) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end - it 'ignores absolute URLs with two leading slashes' do - doc = filter(link('//doc/api/README.md')) - expect(doc.at_css('a')['href']).to eq '//doc/api/README.md' + it "ignores absolute URLs with two leading slashes" do + doc = filter(link("//doc/api/README.md")) + expect(doc.at_css("a")["href"]).to eq "//doc/api/README.md" end - it 'rebuilds relative URL for a file in the repo' do - doc = filter(link('doc/api/README.md')) - expect(doc.at_css('a')['href']) + it "rebuilds relative URL for a file in the repo" do + doc = filter(link("doc/api/README.md")) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end - it 'rebuilds relative URL for a file in the repo with leading ./' do - doc = filter(link('./doc/api/README.md')) - expect(doc.at_css('a')['href']) + it "rebuilds relative URL for a file in the repo with leading ./" do + doc = filter(link("./doc/api/README.md")) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end - it 'rebuilds relative URL for a file in the repo up one directory' do - relative_link = link('../api/README.md') - doc = filter(relative_link, requested_path: 'doc/update/7.14-to-8.0.md') + it "rebuilds relative URL for a file in the repo up one directory" do + relative_link = link("../api/README.md") + doc = filter(relative_link, requested_path: "doc/update/7.14-to-8.0.md") - expect(doc.at_css('a')['href']) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end - it 'rebuilds relative URL for a file in the repo up multiple directories' do - relative_link = link('../../../api/README.md') - doc = filter(relative_link, requested_path: 'doc/foo/bar/baz/README.md') + it "rebuilds relative URL for a file in the repo up multiple directories" do + relative_link = link("../../../api/README.md") + doc = filter(relative_link, requested_path: "doc/foo/bar/baz/README.md") - expect(doc.at_css('a')['href']) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end - it 'rebuilds relative URL for a file in the repository root' do - relative_link = link('../README.md') - doc = filter(relative_link, requested_path: 'doc/some-file.md') + it "rebuilds relative URL for a file in the repository root" do + relative_link = link("../README.md") + doc = filter(relative_link, requested_path: "doc/some-file.md") - expect(doc.at_css('a')['href']) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/README.md" end - it 'rebuilds relative URL for a file in the repo with an anchor' do - doc = filter(link('README.md#section')) - expect(doc.at_css('a')['href']) + it "rebuilds relative URL for a file in the repo with an anchor" do + doc = filter(link("README.md#section")) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/blob/#{ref}/README.md#section" end - it 'rebuilds relative URL for a directory in the repo' do - doc = filter(link('doc/api/')) - expect(doc.at_css('a')['href']) + it "rebuilds relative URL for a directory in the repo" do + doc = filter(link("doc/api/")) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/tree/#{ref}/doc/api" end - it 'rebuilds relative URL for an image in the repo' do - doc = filter(image('files/images/logo-black.png')) + it "rebuilds relative URL for an image in the repo" do + doc = filter(image("files/images/logo-black.png")) - expect(doc.at_css('img')['src']) + expect(doc.at_css("img")["src"]) .to eq "/#{project_path}/raw/#{ref}/files/images/logo-black.png" end - it 'rebuilds relative URL for link to an image in the repo' do - doc = filter(link('files/images/logo-black.png')) + it "rebuilds relative URL for link to an image in the repo" do + doc = filter(link("files/images/logo-black.png")) - expect(doc.at_css('a')['href']) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/raw/#{ref}/files/images/logo-black.png" end - it 'rebuilds relative URL for a video in the repo' do - doc = filter(video('files/videos/intro.mp4'), commit: project.commit('video'), ref: 'video') + it "rebuilds relative URL for a video in the repo" do + doc = filter(video("files/videos/intro.mp4"), commit: project.commit("video"), ref: "video") - expect(doc.at_css('video')['src']) + expect(doc.at_css("video")["src"]) .to eq "/#{project_path}/raw/video/files/videos/intro.mp4" end - it 'does not modify relative URL with an anchor only' do - doc = filter(link('#section-1')) - expect(doc.at_css('a')['href']).to eq '#section-1' + it "does not modify relative URL with an anchor only" do + doc = filter(link("#section-1")) + expect(doc.at_css("a")["href"]).to eq "#section-1" end - it 'does not modify absolute URL' do - doc = filter(link('http://example.com')) - expect(doc.at_css('a')['href']).to eq 'http://example.com' + it "does not modify absolute URL" do + doc = filter(link("http://example.com")) + expect(doc.at_css("a")["href"]).to eq "http://example.com" end - it 'supports Unicode filenames' do - path = 'files/images/한글.png' + it "supports Unicode filenames" do + path = "files/images/한글.png" escaped = Addressable::URI.escape(path) # Stub this method so the file doesn't actually need to be in the repo allow_any_instance_of(described_class).to receive(:uri_type).and_return(:raw) doc = filter(image(escaped)) - expect(doc.at_css('img')['src']).to eq "/#{project_path}/raw/#{Addressable::URI.escape(ref)}/#{escaped}" + expect(doc.at_css("img")["src"]).to eq "/#{project_path}/raw/#{Addressable::URI.escape(ref)}/#{escaped}" end - context 'when requested path is a file in the repo' do - let(:requested_path) { 'doc/api/README.md' } - it 'rebuilds URL relative to the containing directory' do - doc = filter(link('users.md')) - expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/doc/api/users.md" + context "when requested path is a file in the repo" do + let(:requested_path) { "doc/api/README.md" } + it "rebuilds URL relative to the containing directory" do + doc = filter(link("users.md")) + expect(doc.at_css("a")["href"]).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/doc/api/users.md" end end - context 'when requested path is a directory in the repo' do - let(:requested_path) { 'doc/api/' } - it 'rebuilds URL relative to the directory' do - doc = filter(link('users.md')) - expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/doc/api/users.md" + context "when requested path is a directory in the repo" do + let(:requested_path) { "doc/api/" } + it "rebuilds URL relative to the directory" do + doc = filter(link("users.md")) + expect(doc.at_css("a")["href"]).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/doc/api/users.md" end end - context 'when ref name contains percent sign' do - let(:ref) { '100%branch' } - let(:commit) { project.commit('1b12f15a11fc6e62177bef08f47bc7b5ce50b141') } - let(:requested_path) { 'foo/bar/' } - it 'correctly escapes the ref' do - doc = filter(link('.gitkeep')) - expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/foo/bar/.gitkeep" + context "when ref name contains percent sign" do + let(:ref) { "100%branch" } + let(:commit) { project.commit("1b12f15a11fc6e62177bef08f47bc7b5ce50b141") } + let(:requested_path) { "foo/bar/" } + it "correctly escapes the ref" do + doc = filter(link(".gitkeep")) + expect(doc.at_css("a")["href"]).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/foo/bar/.gitkeep" end end - context 'when ref name contains special chars' do + context "when ref name contains special chars" do let(:ref) {'mark#\'@],+;-._/#@!$&()+down'} - it 'correctly escapes the ref' do + it "correctly escapes the ref" do # Addressable won't escape the '#', so we do this manually - ref_escaped = 'mark%23\'@%5D,+;-._/%23@!$&()+down' + ref_escaped = "mark%23'@%5D,+;-._/%23@!$&()+down" # Stub this method so the branch doesn't actually need to be in the repo allow_any_instance_of(described_class).to receive(:uri_type).and_return(:raw) - doc = filter(link('files/images/logo-black.png')) + doc = filter(link("files/images/logo-black.png")) - expect(doc.at_css('a')['href']) + expect(doc.at_css("a")["href"]) .to eq "/#{project_path}/raw/#{ref_escaped}/files/images/logo-black.png" end end - context 'when requested path is a directory with space in the repo' do - let(:ref) { 'master' } - let(:commit) { project.commit('38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e') } - let(:requested_path) { 'with space/' } - it 'does not escape the space twice' do - doc = filter(link('README.md')) - expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/with%20space/README.md" + context "when requested path is a directory with space in the repo" do + let(:ref) { "master" } + let(:commit) { project.commit("38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e") } + let(:requested_path) { "with space/" } + it "does not escape the space twice" do + doc = filter(link("README.md")) + expect(doc.at_css("a")["href"]).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/with%20space/README.md" end end end - context 'with a valid commit' do + context "with a valid commit" do include_examples :valid_repository end - context 'with a valid ref' do + context "with a valid ref" do let(:commit) { nil } # force filter to use ref instead of commit include_examples :valid_repository end - context 'with a /upload/ URL' do + context "with a /upload/ URL" do # not needed let(:commit) { nil } let(:ref) { nil } let(:requested_path) { nil } - let(:upload_path) { '/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg' } + let(:upload_path) { "/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" } let(:relative_path) { "/#{project.full_path}#{upload_path}" } - context 'to a project upload' do - context 'with an absolute URL' do + context "to a project upload" do + context "with an absolute URL" do let(:absolute_path) { Gitlab.config.gitlab.url + relative_path } let(:only_path) { false } - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(link(upload_path)) - expect(doc.at_css('a')['href']).to eq(absolute_path) + expect(doc.at_css("a")["href"]).to eq(absolute_path) end end - it 'rebuilds relative URL for a link' do + it "rebuilds relative URL for a link" do doc = filter(link(upload_path)) - expect(doc.at_css('a')['href']).to eq(relative_path) + expect(doc.at_css("a")["href"]).to eq(relative_path) doc = filter(nested(link(upload_path))) - expect(doc.at_css('a')['href']).to eq(relative_path) + expect(doc.at_css("a")["href"]).to eq(relative_path) end - it 'rebuilds relative URL for an image' do + it "rebuilds relative URL for an image" do doc = filter(image(upload_path)) - expect(doc.at_css('img')['src']).to eq(relative_path) + expect(doc.at_css("img")["src"]).to eq(relative_path) doc = filter(nested(image(upload_path))) - expect(doc.at_css('img')['src']).to eq(relative_path) + expect(doc.at_css("img")["src"]).to eq(relative_path) end - it 'does not modify absolute URL' do - doc = filter(link('http://example.com')) - expect(doc.at_css('a')['href']).to eq 'http://example.com' + it "does not modify absolute URL" do + doc = filter(link("http://example.com")) + expect(doc.at_css("a")["href"]).to eq "http://example.com" end - it 'supports unescaped Unicode filenames' do - path = '/uploads/한글.png' + it "supports unescaped Unicode filenames" do + path = "/uploads/한글.png" doc = filter(link(path)) - expect(doc.at_css('a')['href']).to eq("/#{project.full_path}/uploads/%ED%95%9C%EA%B8%80.png") + expect(doc.at_css("a")["href"]).to eq("/#{project.full_path}/uploads/%ED%95%9C%EA%B8%80.png") end - it 'supports escaped Unicode filenames' do - path = '/uploads/한글.png' + it "supports escaped Unicode filenames" do + path = "/uploads/한글.png" escaped = Addressable::URI.escape(path) doc = filter(image(escaped)) - expect(doc.at_css('img')['src']).to eq("/#{project.full_path}/uploads/%ED%95%9C%EA%B8%80.png") + expect(doc.at_css("img")["src"]).to eq("/#{project.full_path}/uploads/%ED%95%9C%EA%B8%80.png") end end - context 'to a group upload' do - let(:upload_link) { link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg') } + context "to a group upload" do + let(:upload_link) { link("/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg") } let(:group) { create(:group) } let(:project) { nil } let(:relative_path) { "/groups/#{group.full_path}/-/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" } - context 'with an absolute URL' do + context "with an absolute URL" do let(:absolute_path) { Gitlab.config.gitlab.url + relative_path } let(:only_path) { false } - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(upload_link) - expect(doc.at_css('a')['href']).to eq(absolute_path) + expect(doc.at_css("a")["href"]).to eq(absolute_path) end end - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(upload_link) - expect(doc.at_css('a')['href']).to eq(relative_path) + expect(doc.at_css("a")["href"]).to eq(relative_path) end - it 'rewrites the link correctly for subgroup' do + it "rewrites the link correctly for subgroup" do group.update!(parent: create(:group)) doc = filter(upload_link) - expect(doc.at_css('a')['href']).to eq(relative_path) + expect(doc.at_css("a")["href"]).to eq(relative_path) end - it 'does not modify absolute URL' do - doc = filter(link('http://example.com')) + it "does not modify absolute URL" do + doc = filter(link("http://example.com")) - expect(doc.at_css('a')['href']).to eq 'http://example.com' + expect(doc.at_css("a")["href"]).to eq "http://example.com" end end - context 'to a personal snippet' do + context "to a personal snippet" do let(:group) { nil } let(:project) { nil } - let(:relative_path) { '/uploads/-/system/personal_snippet/6/674e4f07fbf0a7736c3439212896e51a/example.tar.gz' } + let(:relative_path) { "/uploads/-/system/personal_snippet/6/674e4f07fbf0a7736c3439212896e51a/example.tar.gz" } - context 'with an absolute URL' do + context "with an absolute URL" do let(:absolute_path) { Gitlab.config.gitlab.url + relative_path } let(:only_path) { false } - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(link(relative_path)) - expect(doc.at_css('a')['href']).to eq(absolute_path) + expect(doc.at_css("a")["href"]).to eq(absolute_path) end end - context 'with a relative URL root' do - let(:gitlab_root) { '/gitlab' } + context "with a relative URL root" do + let(:gitlab_root) { "/gitlab" } let(:absolute_path) { Gitlab.config.gitlab.url + gitlab_root + relative_path } before do stub_config_setting(relative_url_root: gitlab_root) end - context 'with an absolute URL' do + context "with an absolute URL" do let(:only_path) { false } - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(link(relative_path)) - expect(doc.at_css('a')['href']).to eq(absolute_path) + expect(doc.at_css("a")["href"]).to eq(absolute_path) end end - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(link(relative_path)) - expect(doc.at_css('a')['href']).to eq(gitlab_root + relative_path) + expect(doc.at_css("a")["href"]).to eq(gitlab_root + relative_path) end end - it 'rewrites the link correctly' do + it "rewrites the link correctly" do doc = filter(link(relative_path)) - expect(doc.at_css('a')['href']).to eq(relative_path) + expect(doc.at_css("a")["href"]).to eq(relative_path) end - it 'does not modify absolute URL' do - doc = filter(link('http://example.com')) + it "does not modify absolute URL" do + doc = filter(link("http://example.com")) - expect(doc.at_css('a')['href']).to eq 'http://example.com' + expect(doc.at_css("a")["href"]).to eq "http://example.com" end end end diff --git a/spec/lib/banzai/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb index f2a5d7b2c9f..ddaa0c6446e 100644 --- a/spec/lib/banzai/filter/sanitization_filter_spec.rb +++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb @@ -1,52 +1,52 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::SanitizationFilter do include FilterSpecHelper - describe 'default whitelist' do - it 'sanitizes tags that are not whitelisted' do - act = %q{<textarea>no inputs</textarea> and <blink>no blinks</blink>} - exp = 'no inputs and no blinks' + describe "default whitelist" do + it "sanitizes tags that are not whitelisted" do + act = "<textarea>no inputs</textarea> and <blink>no blinks</blink>" + exp = "no inputs and no blinks" expect(filter(act).to_html).to eq exp end - it 'sanitizes tag attributes' do - act = %q{<a href="http://example.com/bar.html" onclick="bar">Text</a>} - exp = %q{<a href="http://example.com/bar.html">Text</a>} + it "sanitizes tag attributes" do + act = '<a href="http://example.com/bar.html" onclick="bar">Text</a>' + exp = '<a href="http://example.com/bar.html">Text</a>' expect(filter(act).to_html).to eq exp end - it 'sanitizes javascript in attributes' do + it "sanitizes javascript in attributes" do act = %q(<a href="javascript:alert('foo')">Text</a>) - exp = '<a>Text</a>' + exp = "<a>Text</a>" expect(filter(act).to_html).to eq exp end - it 'sanitizes mixed-cased javascript in attributes' do + it "sanitizes mixed-cased javascript in attributes" do act = %q(<a href="javaScript:alert('foo')">Text</a>) - exp = '<a>Text</a>' + exp = "<a>Text</a>" expect(filter(act).to_html).to eq exp end - it 'allows whitelisted HTML tags from the user' do + it "allows whitelisted HTML tags from the user" do exp = act = "<dl>\n<dt>Term</dt>\n<dd>Definition</dd>\n</dl>" expect(filter(act).to_html).to eq exp end - it 'sanitizes `class` attribute on any element' do - act = %q{<strong class="foo">Strong</strong>} - expect(filter(act).to_html).to eq %q{<strong>Strong</strong>} + it "sanitizes `class` attribute on any element" do + act = '<strong class="foo">Strong</strong>' + expect(filter(act).to_html).to eq "<strong>Strong</strong>" end - it 'sanitizes `id` attribute on any element' do - act = %q{<em id="foo">Emphasis</em>} - expect(filter(act).to_html).to eq %q{<em>Emphasis</em>} + it "sanitizes `id` attribute on any element" do + act = '<em id="foo">Emphasis</em>' + expect(filter(act).to_html).to eq "<em>Emphasis</em>" end end - describe 'custom whitelist' do - it 'customizes the whitelist only once' do - instance = described_class.new('Foo') + describe "custom whitelist" do + it "customizes the whitelist only once" do + instance = described_class.new("Foo") control_count = instance.whitelist[:transformers].size 3.times { instance.whitelist } @@ -54,9 +54,9 @@ describe Banzai::Filter::SanitizationFilter do expect(instance.whitelist[:transformers].size).to eq control_count end - it 'customizes the whitelist only once for different instances' do - instance1 = described_class.new('Foo1') - instance2 = described_class.new('Foo2') + it "customizes the whitelist only once for different instances" do + instance1 = described_class.new("Foo1") + instance2 = described_class.new("Foo2") control_count = instance1.whitelist[:transformers].size instance1.whitelist @@ -66,32 +66,32 @@ describe Banzai::Filter::SanitizationFilter do expect(instance2.whitelist[:transformers].size).to eq control_count end - it 'sanitizes `class` attribute from all elements' do - act = %q{<pre class="code highlight white c"><code><span class="k">def</span></code></pre>} - exp = %q{<pre><code><span class="k">def</span></code></pre>} + it "sanitizes `class` attribute from all elements" do + act = '<pre class="code highlight white c"><code><span class="k">def</span></code></pre>' + exp = '<pre><code><span class="k">def</span></code></pre>' expect(filter(act).to_html).to eq exp end - it 'sanitizes `class` attribute from non-highlight spans' do - act = %q{<span class="k">def</span>} - expect(filter(act).to_html).to eq %q{<span>def</span>} + it "sanitizes `class` attribute from non-highlight spans" do + act = '<span class="k">def</span>' + expect(filter(act).to_html).to eq "<span>def</span>" end - it 'allows `text-align` property in `style` attribute on table elements' do + it "allows `text-align` property in `style` attribute on table elements" do html = <<~HTML - <table> - <tr><th style="text-align: center">Head</th></tr> - <tr><td style="text-align: right">Body</th></tr> - </table> + <table> + <tr><th style="text-align: center">Head</th></tr> + <tr><td style="text-align: right">Body</th></tr> + </table> HTML doc = filter(html) - expect(doc.at_css('th')['style']).to eq 'text-align: center' - expect(doc.at_css('td')['style']).to eq 'text-align: right' + expect(doc.at_css("th")["style"]).to eq "text-align: center" + expect(doc.at_css("td")["style"]).to eq "text-align: right" end - it 'disallows other properties in `style` attribute on table elements' do + it "disallows other properties in `style` attribute on table elements" do html = <<~HTML <table> <tr><th style="text-align: foo">Head</th></tr> @@ -101,31 +101,31 @@ describe Banzai::Filter::SanitizationFilter do doc = filter(html) - expect(doc.at_css('th')['style']).to be_nil - expect(doc.at_css('td')['style']).to eq 'text-align: center' + expect(doc.at_css("th")["style"]).to be_nil + expect(doc.at_css("td")["style"]).to eq "text-align: center" end - it 'disallows `text-align` property in `style` attribute on other elements' do + it "disallows `text-align` property in `style` attribute on other elements" do html = <<~HTML <div style="text-align: center">Text</div> HTML doc = filter(html) - expect(doc.at_css('div')['style']).to be_nil + expect(doc.at_css("div")["style"]).to be_nil end - it 'allows `span` elements' do - exp = act = %q{<span>Hello</span>} + it "allows `span` elements" do + exp = act = "<span>Hello</span>" expect(filter(act).to_html).to eq exp end - it 'allows `abbr` elements' do - exp = act = %q{<abbr title="HyperText Markup Language">HTML</abbr>} + it "allows `abbr` elements" do + exp = act = '<abbr title="HyperText Markup Language">HTML</abbr>' expect(filter(act).to_html).to eq exp end - it 'disallows the `name` attribute globally, allows on `a`' do + it "disallows the `name` attribute globally, allows on `a`" do html = <<~HTML <img name="getElementById" src=""> <span name="foo" class="bar">Hi</span> @@ -134,22 +134,22 @@ describe Banzai::Filter::SanitizationFilter do doc = filter(html) - expect(doc.at_css('img')).not_to have_attribute('name') - expect(doc.at_css('span')).not_to have_attribute('name') - expect(doc.at_css('a')).to have_attribute('name') + expect(doc.at_css("img")).not_to have_attribute("name") + expect(doc.at_css("span")).not_to have_attribute("name") + expect(doc.at_css("a")).to have_attribute("name") end - it 'allows `summary` elements' do - exp = act = '<summary>summary line</summary>' + it "allows `summary` elements" do + exp = act = "<summary>summary line</summary>" expect(filter(act).to_html).to eq exp end - it 'allows `details` elements' do - exp = act = '<details>long text goes here</details>' + it "allows `details` elements" do + exp = act = "<details>long text goes here</details>" expect(filter(act).to_html).to eq exp end - it 'allows `data-math-style` attribute on `code` and `pre` elements' do + it "allows `data-math-style` attribute on `code` and `pre` elements" do html = <<-HTML <pre class="code" data-math-style="inline">something</pre> <code class="code" data-math-style="inline">something</code> @@ -165,94 +165,94 @@ describe Banzai::Filter::SanitizationFilter do expect(filter(html).to_html).to eq(output) end - it 'removes `rel` attribute from `a` elements' do - act = %q{<a href="#" rel="nofollow">Link</a>} - exp = %q{<a href="#">Link</a>} + it "removes `rel` attribute from `a` elements" do + act = '<a href="#" rel="nofollow">Link</a>' + exp = '<a href="#">Link</a>' expect(filter(act).to_html).to eq exp end # Adapted from the Sanitize test suite: http://git.io/vczrM protocols = { - 'protocol-based JS injection: simple, no spaces' => { - input: '<a href="javascript:alert(\'XSS\');">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: simple, no spaces" => { + input: '<a href="javascript:alert(\'XSS\');">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: simple, spaces before' => { - input: '<a href="javascript :alert(\'XSS\');">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: simple, spaces before" => { + input: '<a href="javascript :alert(\'XSS\');">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: simple, spaces after' => { - input: '<a href="javascript: alert(\'XSS\');">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: simple, spaces after" => { + input: '<a href="javascript: alert(\'XSS\');">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: simple, spaces before and after' => { - input: '<a href="javascript : alert(\'XSS\');">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: simple, spaces before and after" => { + input: '<a href="javascript : alert(\'XSS\');">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: preceding colon' => { - input: '<a href=":javascript:alert(\'XSS\');">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: preceding colon" => { + input: '<a href=":javascript:alert(\'XSS\');">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: UTF-8 encoding' => { - input: '<a href="javascript:">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: UTF-8 encoding" => { + input: '<a href="javascript:">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: long UTF-8 encoding' => { - input: '<a href="javascript:">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: long UTF-8 encoding" => { + input: '<a href="javascript:">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: long UTF-8 encoding without semicolons' => { - input: '<a href=javascript:alert('XSS')>foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: long UTF-8 encoding without semicolons" => { + input: "<a href=javascript:alert('XSS')>foo</a>", + output: "<a>foo</a>", }, - 'protocol-based JS injection: hex encoding' => { - input: '<a href="javascript:">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: hex encoding" => { + input: '<a href="javascript:">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: long hex encoding' => { - input: '<a href="javascript:">foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: long hex encoding" => { + input: '<a href="javascript:">foo</a>', + output: "<a>foo</a>", }, - 'protocol-based JS injection: hex encoding without semicolons' => { - input: '<a href=javascript:alert('XSS')>foo</a>', - output: '<a>foo</a>' + "protocol-based JS injection: hex encoding without semicolons" => { + input: "<a href=javascript:alert('XSS')>foo</a>", + output: "<a>foo</a>", }, - 'protocol-based JS injection: null char' => { - input: "<a href=java\0script:alert(\"XSS\")>foo</a>", - output: '<a href="java"></a>' + "protocol-based JS injection: null char" => { + input: "<a href=java\0script:alert(\"XSS\")>foo</a>", + output: '<a href="java"></a>', }, - 'protocol-based JS injection: invalid URL char' => { + "protocol-based JS injection: invalid URL char" => { input: '<img src=java\script:alert("XSS")>', - output: '<img>' + output: "<img>", }, - 'protocol-based JS injection: Unicode' => { - input: %Q(<a href="\u0001java\u0003script:alert('XSS')">foo</a>), - output: '<a>foo</a>' + "protocol-based JS injection: Unicode" => { + input: %(<a href="\u0001java\u0003script:alert('XSS')">foo</a>), + output: "<a>foo</a>", }, - 'protocol-based JS injection: spaces and entities' => { - input: '<a href="  javascript:alert(\'XSS\');">foo</a>', - output: '<a href="">foo</a>' + "protocol-based JS injection: spaces and entities" => { + input: '<a href="  javascript:alert(\'XSS\');">foo</a>', + output: '<a href="">foo</a>', }, - 'protocol whitespace' => { + "protocol whitespace" => { input: '<a href=" http://example.com/"></a>', - output: '<a href="http://example.com/"></a>' - } + output: '<a href="http://example.com/"></a>', + }, } protocols.each do |name, data| @@ -263,88 +263,88 @@ describe Banzai::Filter::SanitizationFilter do end end - it 'disallows data links' do + it "disallows data links" do input = '<a href="data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K">XSS</a>' output = filter(input) - expect(output.to_html).to eq '<a>XSS</a>' + expect(output.to_html).to eq "<a>XSS</a>" end - it 'disallows vbscript links' do + it "disallows vbscript links" do input = '<a href="vbscript:alert(document.domain)">XSS</a>' output = filter(input) - expect(output.to_html).to eq '<a>XSS</a>' + expect(output.to_html).to eq "<a>XSS</a>" end - it 'disallows invalid URIs' do - expect(Addressable::URI).to receive(:parse).with('foo://example.com') + it "disallows invalid URIs" do + expect(Addressable::URI).to receive(:parse).with("foo://example.com") .and_raise(Addressable::URI::InvalidURIError) input = '<a href="foo://example.com">Foo</a>' output = filter(input) - expect(output.to_html).to eq '<a>Foo</a>' + expect(output.to_html).to eq "<a>Foo</a>" end - it 'allows non-standard anchor schemes' do - exp = %q{<a href="irc://irc.freenode.net/git">IRC</a>} + it "allows non-standard anchor schemes" do + exp = '<a href="irc://irc.freenode.net/git">IRC</a>' act = filter(exp) expect(act.to_html).to eq exp end - it 'allows relative links' do - exp = %q{<a href="foo/bar.md">foo/bar.md</a>} + it "allows relative links" do + exp = '<a href="foo/bar.md">foo/bar.md</a>' act = filter(exp) expect(act.to_html).to eq exp end - it 'allows the `data-sourcepos` attribute globally' do - exp = %q{<p data-sourcepos="1:1-1:10">foo/bar.md</p>} + it "allows the `data-sourcepos` attribute globally" do + exp = '<p data-sourcepos="1:1-1:10">foo/bar.md</p>' act = filter(exp) expect(act.to_html).to eq exp end - describe 'footnotes' do - it 'allows correct footnote id property on links' do - exp = %q{<a href="#fn1" id="fnref1">foo/bar.md</a>} + describe "footnotes" do + it "allows correct footnote id property on links" do + exp = '<a href="#fn1" id="fnref1">foo/bar.md</a>' act = filter(exp) expect(act.to_html).to eq exp end - it 'allows correct footnote id property on li element' do - exp = %q{<ol><li id="fn1">footnote</li></ol>} + it "allows correct footnote id property on li element" do + exp = '<ol><li id="fn1">footnote</li></ol>' act = filter(exp) expect(act.to_html).to eq exp end - it 'removes invalid id for footnote links' do - exp = %q{<a href="#fn1">link</a>} + it "removes invalid id for footnote links" do + exp = '<a href="#fn1">link</a>' %w[fnrefx test xfnref1].each do |id| - act = filter(%Q{<a href="#fn1" id="#{id}">link</a>}) + act = filter(%(<a href="#fn1" id="#{id}">link</a>)) expect(act.to_html).to eq exp end end - it 'removes invalid id for footnote li' do - exp = %q{<ol><li>footnote</li></ol>} + it "removes invalid id for footnote li" do + exp = "<ol><li>footnote</li></ol>" %w[fnx test xfn1].each do |id| - act = filter(%Q{<ol><li id="#{id}">footnote</li></ol>}) + act = filter(%(<ol><li id="#{id}">footnote</li></ol>)) expect(act.to_html).to eq exp end end - it 'allows footnotes numbered higher than 9' do - exp = %q{<a href="#fn15" id="fnref15">link</a><ol><li id="fn15">footnote</li></ol>} + it "allows footnotes numbered higher than 9" do + exp = '<a href="#fn15" id="fnref15">link</a><ol><li id="fn15">footnote</li></ol>' act = filter(exp) expect(act.to_html).to eq exp diff --git a/spec/lib/banzai/filter/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb index 21cf092428d..86fec7a5efd 100644 --- a/spec/lib/banzai/filter/snippet_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::SnippetReferenceFilter do include FilterSpecHelper @@ -7,211 +7,211 @@ describe Banzai::Filter::SnippetReferenceFilter do let(:snippet) { create(:project_snippet, project: project) } let(:reference) { snippet.to_reference } - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Snippet #{reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - context 'internal reference' do - it 'links to a valid reference' do + context "internal reference" do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls + expect(doc.css("a").first.attr("href")).to eq urls .project_snippet_url(project, snippet) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Snippet (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(reference)}</a>\.\)}) end - it 'ignores invalid snippet IDs' do + it "ignores invalid snippet IDs" do exp = act = "Snippet #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end - it 'includes a title attribute' do + it "includes a title attribute" do doc = reference_filter("Snippet #{reference}") - expect(doc.css('a').first.attr('title')).to eq snippet.title + expect(doc.css("a").first.attr("title")).to eq snippet.title end - it 'escapes the title attribute' do - snippet.update_attribute(:title, %{"></a>whatever<a title="}) + it "escapes the title attribute" do + snippet.update_attribute(:title, %("></a>whatever<a title=")) doc = reference_filter("Snippet #{reference}") expect(doc.text).to eq "Snippet #{reference}" end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Snippet #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-snippet has-tooltip' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-snippet has-tooltip" end - it 'includes a data-project attribute' do + it "includes a data-project attribute" do doc = reference_filter("Snippet #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-project') - expect(link.attr('data-project')).to eq project.id.to_s + expect(link).to have_attribute("data-project") + expect(link.attr("data-project")).to eq project.id.to_s end - it 'includes a data-snippet attribute' do + it "includes a data-snippet attribute" do doc = reference_filter("See #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-snippet') - expect(link.attr('data-snippet')).to eq snippet.id.to_s + expect(link).to have_attribute("data-snippet") + expect(link.attr("data-snippet")).to eq snippet.id.to_s end - it 'supports an :only_path context' do + it "supports an :only_path context" do doc = reference_filter("Snippet #{reference}", only_path: true) - link = doc.css('a').first.attr('href') + link = doc.css("a").first.attr("href") - expect(link).not_to match %r(https?://) + expect(link).not_to match %r{https?://} expect(link).to eq urls.project_snippet_url(project, snippet, only_path: true) end end - context 'cross-project / cross-namespace complete reference' do + context "cross-project / cross-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, namespace: namespace) } let!(:snippet) { create(:project_snippet, project: project2) } let(:reference) { "#{project2.full_path}$#{snippet.id}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_snippet_url(project2, snippet) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text).to eql(reference) + expect(doc.css("a").first.text).to eql(reference) end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{reference}.)") expect(doc.text).to eql("See (#{reference}.)") end - it 'ignores invalid snippet IDs on the referenced project' do + it "ignores invalid snippet IDs on the referenced project" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project / same-namespace complete reference' do + context "cross-project / same-namespace complete reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } let(:project2) { create(:project, :public, namespace: namespace) } let!(:snippet) { create(:project_snippet, project: project2) } let(:reference) { "#{project2.full_path}$#{snippet.id}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_snippet_url(project2, snippet) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{project2.path}$#{snippet.id}.)") - expect(doc.css('a').first.text).to eql("#{project2.path}$#{snippet.id}") + expect(doc.css("a").first.text).to eql("#{project2.path}$#{snippet.id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{project2.path}$#{snippet.id}.)") expect(doc.text).to eql("See (#{project2.path}$#{snippet.id}.)") end - it 'ignores invalid snippet IDs on the referenced project' do + it "ignores invalid snippet IDs on the referenced project" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project shorthand reference' do + context "cross-project shorthand reference" do let(:namespace) { create(:namespace) } let(:project) { create(:project, :public, namespace: namespace) } let(:project2) { create(:project, :public, namespace: namespace) } let!(:snippet) { create(:project_snippet, project: project2) } let(:reference) { "#{project2.path}$#{snippet.id}" } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_snippet_url(project2, snippet) end - it 'link has valid text' do + it "link has valid text" do doc = reference_filter("See (#{project2.path}$#{snippet.id}.)") - expect(doc.css('a').first.text).to eql("#{project2.path}$#{snippet.id}") + expect(doc.css("a").first.text).to eql("#{project2.path}$#{snippet.id}") end - it 'has valid text' do + it "has valid text" do doc = reference_filter("See (#{project2.path}$#{snippet.id}.)") expect(doc.text).to eql("See (#{project2.path}$#{snippet.id}.)") end - it 'ignores invalid snippet IDs on the referenced project' do + it "ignores invalid snippet IDs on the referenced project" do exp = act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq exp end end - context 'cross-project URL reference' do - let(:namespace) { create(:namespace, name: 'cross-reference') } + context "cross-project URL reference" do + let(:namespace) { create(:namespace, name: "cross-reference") } let(:project2) { create(:project, :public, namespace: namespace) } let(:snippet) { create(:project_snippet, project: project2) } let(:reference) { urls.project_snippet_url(project2, snippet) } - it 'links to a valid reference' do + it "links to a valid reference" do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").first.attr("href")) .to eq urls.project_snippet_url(project2, snippet) end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("See (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{Regexp.escape(snippet.to_reference(project))}</a>\.\)}) end - it 'ignores invalid snippet IDs on the referenced project' do + it "ignores invalid snippet IDs on the referenced project" do act = "See #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to match(%r{<a.+>#{Regexp.escape(invalidate_reference(reference))}</a>}) end end - context 'group context' do - it 'links to a valid reference' do + context "group context" do + it "links to a valid reference" do reference = "#{project.full_path}$#{snippet.id}" - result = reference_filter("See #{reference}", { project: nil, group: create(:group) } ) + result = reference_filter("See #{reference}", {project: nil, group: create(:group)}) - expect(result.css('a').first.attr('href')).to eq(urls.project_snippet_url(project, snippet)) + expect(result.css("a").first.attr("href")).to eq(urls.project_snippet_url(project, snippet)) end - it 'ignores internal references' do + it "ignores internal references" do exp = act = "See $#{snippet.id}" expect(reference_filter(act, project: nil, group: create(:group)).to_html).to eq exp diff --git a/spec/lib/banzai/filter/spaced_link_filter_spec.rb b/spec/lib/banzai/filter/spaced_link_filter_spec.rb index 76d7644d76c..c81e5dd5360 100644 --- a/spec/lib/banzai/filter/spaced_link_filter_spec.rb +++ b/spec/lib/banzai/filter/spaced_link_filter_spec.rb @@ -1,84 +1,84 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::SpacedLinkFilter do include FilterSpecHelper - let(:link) { '[example](page slug)' } - let(:image) { '' } + let(:link) { "[example](page slug)" } + let(:image) { "" } - context 'when a link is detected' do - it 'converts slug with spaces to a link' do + context "when a link is detected" do + it "converts slug with spaces to a link" do doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq 'example' - expect(doc.at_css('a')['href']).to eq 'page%20slug' - expect(doc.at_css('a')['title']).to be_nil - expect(doc.at_css('p')).to be_nil + expect(doc.at_css("a").text).to eq "example" + expect(doc.at_css("a")["href"]).to eq "page%20slug" + expect(doc.at_css("a")["title"]).to be_nil + expect(doc.at_css("p")).to be_nil end - it 'converts slug with spaces and a title to a link' do + it "converts slug with spaces and a title to a link" do link = '[example](page slug "title")' doc = filter("See #{link}") - expect(doc.at_css('a').text).to eq 'example' - expect(doc.at_css('a')['href']).to eq 'page%20slug' - expect(doc.at_css('a')['title']).to eq 'title' - expect(doc.at_css('p')).to be_nil + expect(doc.at_css("a").text).to eq "example" + expect(doc.at_css("a")["href"]).to eq "page%20slug" + expect(doc.at_css("a")["title"]).to eq "title" + expect(doc.at_css("p")).to be_nil end - it 'does nothing with empty text' do - link = '[](page slug)' + it "does nothing with empty text" do + link = "[](page slug)" doc = filter("See #{link}") - expect(doc.at_css('a')).to be_nil + expect(doc.at_css("a")).to be_nil end - it 'does nothing with an empty slug' do - link = '[example]()' + it "does nothing with an empty slug" do + link = "[example]()" doc = filter("See #{link}") - expect(doc.at_css('a')).to be_nil + expect(doc.at_css("a")).to be_nil end end - context 'when an image is detected' do - it 'converts slug with spaces to an iamge' do + context "when an image is detected" do + it "converts slug with spaces to an iamge" do doc = filter("See #{image}") - expect(doc.at_css('img')['src']).to eq 'img%20test.jpg' - expect(doc.at_css('img')['alt']).to eq 'example' - expect(doc.at_css('p')).to be_nil + expect(doc.at_css("img")["src"]).to eq "img%20test.jpg" + expect(doc.at_css("img")["alt"]).to eq "example" + expect(doc.at_css("p")).to be_nil end - it 'converts slug with spaces and a title to an image' do + it "converts slug with spaces and a title to an image" do image = '' doc = filter("See #{image}") - expect(doc.at_css('img')['src']).to eq 'img%20test.jpg' - expect(doc.at_css('img')['alt']).to eq 'example' - expect(doc.at_css('img')['title']).to eq 'title' - expect(doc.at_css('p')).to be_nil + expect(doc.at_css("img")["src"]).to eq "img%20test.jpg" + expect(doc.at_css("img")["alt"]).to eq "example" + expect(doc.at_css("img")["title"]).to eq "title" + expect(doc.at_css("p")).to be_nil end end - it 'converts multiple URLs' do - link1 = '[first](slug one)' - link2 = '[second](http://example.com/slug two)' + it "converts multiple URLs" do + link1 = "[first](slug one)" + link2 = "[second](http://example.com/slug two)" doc = filter("See #{link1} and #{image} and #{link2}") - found_links = doc.css('a') + found_links = doc.css("a") expect(found_links.size).to eq(2) - expect(found_links[0].text).to eq 'first' - expect(found_links[0]['href']).to eq 'slug%20one' - expect(found_links[1].text).to eq 'second' - expect(found_links[1]['href']).to eq 'http://example.com/slug%20two' + expect(found_links[0].text).to eq "first" + expect(found_links[0]["href"]).to eq "slug%20one" + expect(found_links[1].text).to eq "second" + expect(found_links[1]["href"]).to eq "http://example.com/slug%20two" - found_images = doc.css('img') + found_images = doc.css("img") expect(found_images.size).to eq(1) - expect(found_images[0]['src']).to eq 'img%20test.jpg' - expect(found_images[0]['alt']).to eq 'example' + expect(found_images[0]["src"]).to eq "img%20test.jpg" + expect(found_images[0]["alt"]).to eq "example" end described_class::IGNORE_PARENTS.each do |elem| diff --git a/spec/lib/banzai/filter/suggestion_filter_spec.rb b/spec/lib/banzai/filter/suggestion_filter_spec.rb index b13c90b54bd..416171c0025 100644 --- a/spec/lib/banzai/filter/suggestion_filter_spec.rb +++ b/spec/lib/banzai/filter/suggestion_filter_spec.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::SuggestionFilter do include FilterSpecHelper let(:input) { "<pre class='code highlight js-syntax-highlight suggestion'><code>foo\n</code></pre>" } let(:default_context) do - { suggestions_filter_enabled: true } + {suggestions_filter_enabled: true} end - it 'includes `js-render-suggestion` class' do + it "includes `js-render-suggestion` class" do doc = filter(input, default_context) - result = doc.css('code').first + result = doc.css("code").first - expect(result[:class]).to include('js-render-suggestion') + expect(result[:class]).to include("js-render-suggestion") end - it 'includes no `js-render-suggestion` when filter is disabled' do + it "includes no `js-render-suggestion` when filter is disabled" do doc = filter(input) - result = doc.css('code').first + result = doc.css("code").first expect(result[:class]).to be_nil end diff --git a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index ef52c572898..c9d41c460c1 100644 --- a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::SyntaxHighlightFilter do include FilterSpecHelper @@ -16,7 +16,7 @@ describe Banzai::Filter::SyntaxHighlightFilter do context "when no language is specified" do it "highlights as plaintext" do - result = filter('<pre><code>def fun end</code></pre>') + result = filter("<pre><code>def fun end</code></pre>") expect(result.to_html).to eq('<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">def fun end</span></code></pre>') end @@ -45,12 +45,12 @@ describe Banzai::Filter::SyntaxHighlightFilter do end context "languages that should be passed through" do - %w(math mermaid plantuml).each do |lang| + %w[math mermaid plantuml].each do |lang| context "when #{lang} is specified" do it "highlights as plaintext but with the correct language attribute and class" do - result = filter(%{<pre><code lang="#{lang}">This is a test</code></pre>}) + result = filter(%(<pre><code lang="#{lang}">This is a test</code></pre>)) - expect(result.to_html).to eq(%{<pre class="code highlight js-syntax-highlight #{lang}" lang="#{lang}" v-pre="true"><code><span id="LC1" class="line" lang="#{lang}">This is a test</span></code></pre>}) + expect(result.to_html).to eq(%(<pre class="code highlight js-syntax-highlight #{lang}" lang="#{lang}" v-pre="true"><code><span id="LC1" class="line" lang="#{lang}">This is a test</span></code></pre>)) end include_examples "XSS prevention", lang @@ -78,9 +78,9 @@ describe Banzai::Filter::SyntaxHighlightFilter do end it "does not add highlighting classes" do - result = filter('<pre><code>This is a test</code></pre>') + result = filter("<pre><code>This is a test</code></pre>") - expect(result.to_html).to eq('<pre><code>This is a test</code></pre>') + expect(result.to_html).to eq("<pre><code>This is a test</code></pre>") end include_examples "XSS prevention", "ruby" diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb index 7213cd58ea7..2b20bb99dee 100644 --- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::TableOfContentsFilter do include FilterSpecHelper @@ -7,12 +7,12 @@ describe Banzai::Filter::TableOfContentsFilter do "<h#{level}>#{text}</h#{level}>\n" end - it 'does nothing when :no_header_anchors is truthy' do - exp = act = header(1, 'Header') + it "does nothing when :no_header_anchors is truthy" do + exp = act = header(1, "Header") expect(filter(act, no_header_anchors: 1).to_html).to eq exp end - it 'does nothing with empty headers' do + it "does nothing with empty headers" do exp = act = header(1, nil) expect(filter(act).to_html).to eq exp end @@ -22,105 +22,105 @@ describe Banzai::Filter::TableOfContentsFilter do html = header(i, "Header #{i}") doc = filter(html) - expect(doc.css("h#{i} a").first.attr('id')).to eq "user-content-header-#{i}" + expect(doc.css("h#{i} a").first.attr("id")).to eq "user-content-header-#{i}" end end - describe 'anchor tag' do - it 'has an `anchor` class' do - doc = filter(header(1, 'Header')) - expect(doc.css('h1 a').first.attr('class')).to eq 'anchor' + describe "anchor tag" do + it "has an `anchor` class" do + doc = filter(header(1, "Header")) + expect(doc.css("h1 a").first.attr("class")).to eq "anchor" end - it 'has a namespaced id' do - doc = filter(header(1, 'Header')) - expect(doc.css('h1 a').first.attr('id')).to eq 'user-content-header' + it "has a namespaced id" do + doc = filter(header(1, "Header")) + expect(doc.css("h1 a").first.attr("id")).to eq "user-content-header" end - it 'links to the non-namespaced id' do - doc = filter(header(1, 'Header')) - expect(doc.css('h1 a').first.attr('href')).to eq '#header' + it "links to the non-namespaced id" do + doc = filter(header(1, "Header")) + expect(doc.css("h1 a").first.attr("href")).to eq "#header" end - describe 'generated IDs' do - it 'translates spaces to dashes' do - doc = filter(header(1, 'This header has spaces in it')) - expect(doc.css('h1 a').first.attr('href')).to eq '#this-header-has-spaces-in-it' + describe "generated IDs" do + it "translates spaces to dashes" do + doc = filter(header(1, "This header has spaces in it")) + expect(doc.css("h1 a").first.attr("href")).to eq "#this-header-has-spaces-in-it" end - it 'squeezes multiple spaces and dashes' do - doc = filter(header(1, 'This---header is poorly-formatted')) - expect(doc.css('h1 a').first.attr('href')).to eq '#this-header-is-poorly-formatted' + it "squeezes multiple spaces and dashes" do + doc = filter(header(1, "This---header is poorly-formatted")) + expect(doc.css("h1 a").first.attr("href")).to eq "#this-header-is-poorly-formatted" end - it 'removes punctuation' do + it "removes punctuation" do doc = filter(header(1, "This, header! is, filled. with @ punctuation?")) - expect(doc.css('h1 a').first.attr('href')).to eq '#this-header-is-filled-with-punctuation' + expect(doc.css("h1 a").first.attr("href")).to eq "#this-header-is-filled-with-punctuation" end - it 'appends a unique number to duplicates' do - doc = filter(header(1, 'One') + header(2, 'One')) + it "appends a unique number to duplicates" do + doc = filter(header(1, "One") + header(2, "One")) - expect(doc.css('h1 a').first.attr('href')).to eq '#one' - expect(doc.css('h2 a').first.attr('href')).to eq '#one-1' + expect(doc.css("h1 a").first.attr("href")).to eq "#one" + expect(doc.css("h2 a").first.attr("href")).to eq "#one-1" end - it 'prepends a prefix to digits-only ids' do + it "prepends a prefix to digits-only ids" do doc = filter(header(1, "123") + header(2, "1.0")) - expect(doc.css('h1 a').first.attr('href')).to eq '#anchor-123' - expect(doc.css('h2 a').first.attr('href')).to eq '#anchor-10' + expect(doc.css("h1 a").first.attr("href")).to eq "#anchor-123" + expect(doc.css("h2 a").first.attr("href")).to eq "#anchor-10" end - it 'supports Unicode' do - doc = filter(header(1, '한글')) - expect(doc.css('h1 a').first.attr('id')).to eq 'user-content-한글' - expect(doc.css('h1 a').first.attr('href')).to eq '#한글' + it "supports Unicode" do + doc = filter(header(1, "한글")) + expect(doc.css("h1 a").first.attr("id")).to eq "user-content-한글" + expect(doc.css("h1 a").first.attr("href")).to eq "#한글" end end end - describe 'result' do + describe "result" do def result(html) HTML::Pipeline.new([described_class]).call(html) end - let(:results) { result(header(1, 'Header 1') + header(2, 'Header 2')) } + let(:results) { result(header(1, "Header 1") + header(2, "Header 2")) } let(:doc) { Nokogiri::XML::DocumentFragment.parse(results[:toc]) } - it 'is contained within a `ul` element' do - expect(doc.children.first.name).to eq 'ul' - expect(doc.children.first.attr('class')).to eq 'section-nav' + it "is contained within a `ul` element" do + expect(doc.children.first.name).to eq "ul" + expect(doc.children.first.attr("class")).to eq "section-nav" end - it 'contains an `li` element for each header' do - expect(doc.css('li').length).to eq 2 + it "contains an `li` element for each header" do + expect(doc.css("li").length).to eq 2 - links = doc.css('li a') + links = doc.css("li a") - expect(links.first.attr('href')).to eq '#header-1' - expect(links.first.text).to eq 'Header 1' - expect(links.last.attr('href')).to eq '#header-2' - expect(links.last.text).to eq 'Header 2' + expect(links.first.attr("href")).to eq "#header-1" + expect(links.first.text).to eq "Header 1" + expect(links.last.attr("href")).to eq "#header-2" + expect(links.last.text).to eq "Header 2" end - context 'table of contents nesting' do + context "table of contents nesting" do let(:results) do result( - header(1, 'Header 1') << - header(2, 'Header 1-1') << - header(3, 'Header 1-1-1') << - header(2, 'Header 1-2') << - header(1, 'Header 2') << - header(2, 'Header 2-1') + header(1, "Header 1") << + header(2, "Header 1-1") << + header(3, "Header 1-1-1") << + header(2, "Header 1-2") << + header(1, "Header 2") << + header(2, "Header 2-1") ) end - it 'keeps list levels regarding header levels' do - items = doc.css('li') + it "keeps list levels regarding header levels" do + items = doc.css("li") # Header 1 - expect(items[0].ancestors).to satisfy_none { |node| node.name == 'li' } + expect(items[0].ancestors).to satisfy_none { |node| node.name == "li" } # Header 1-1 expect(items[1].ancestors).to include(items[0]) @@ -133,18 +133,18 @@ describe Banzai::Filter::TableOfContentsFilter do expect(items[3].ancestors).not_to include(items[1]) # Header 2 - expect(items[4].ancestors).to satisfy_none { |node| node.name == 'li' } + expect(items[4].ancestors).to satisfy_none { |node| node.name == "li" } # Header 2-1 expect(items[5].ancestors).to include(items[4]) end end - context 'header text contains escaped content' do + context "header text contains escaped content" do let(:content) { '<img src="x" onerror="alert(42)">' } let(:results) { result(header(1, content)) } - it 'outputs escaped content' do + it "outputs escaped content" do expect(doc.inner_html).to include(content) end end diff --git a/spec/lib/banzai/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb index 1e8a44b4549..8a153fd16b3 100644 --- a/spec/lib/banzai/filter/user_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::UserReferenceFilter do include FilterSpecHelper @@ -13,141 +13,141 @@ describe Banzai::Filter::UserReferenceFilter do let(:subject_name) { "user" } let(:reference) { get_reference(user) } - it_behaves_like 'user reference or project reference' + it_behaves_like "user reference or project reference" - it 'requires project context' do - expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) + it "requires project context" do + expect { described_class.call("") }.to raise_error(ArgumentError, /:project/) end - it 'ignores invalid users' do + it "ignores invalid users" do exp = act = "Hey #{invalidate_reference(reference)}" expect(reference_filter(act).to_html).to eq(exp) end - it 'ignores references with text before the @ sign' do + it "ignores references with text before the @ sign" do exp = act = "Hey foo#{reference}" expect(reference_filter(act).to_html).to eq(exp) end - %w(pre code a style).each do |elem| + %w[pre code a style].each do |elem| it "ignores valid references contained inside '#{elem}' element" do exp = act = "<#{elem}>Hey #{reference}</#{elem}>" expect(reference_filter(act).to_html).to eq exp end end - context 'mentioning @all' do - it_behaves_like 'a reference containing an element node' + context "mentioning @all" do + it_behaves_like "a reference containing an element node" - let(:reference) { User.reference_prefix + 'all' } + let(:reference) { User.reference_prefix + "all" } before do project.add_developer(project.creator) end - it 'supports a special @all mention' do + it "supports a special @all mention" do project.add_developer(user) doc = reference_filter("Hey #{reference}", author: user) - expect(doc.css('a').length).to eq 1 - expect(doc.css('a').first.attr('href')) + expect(doc.css("a").length).to eq 1 + expect(doc.css("a").first.attr("href")) .to eq urls.project_url(project) end - it 'includes a data-author attribute when there is an author' do + it "includes a data-author attribute when there is an author" do project.add_developer(user) doc = reference_filter(reference, author: user) - expect(doc.css('a').first.attr('data-author')).to eq(user.id.to_s) + expect(doc.css("a").first.attr("data-author")).to eq(user.id.to_s) end - it 'does not include a data-author attribute when there is no author' do + it "does not include a data-author attribute when there is no author" do doc = reference_filter(reference) - expect(doc.css('a').first.has_attribute?('data-author')).to eq(false) + expect(doc.css("a").first.has_attribute?("data-author")).to eq(false) end - it 'ignores reference to all when the user is not a project member' do + it "ignores reference to all when the user is not a project member" do doc = reference_filter("Hey #{reference}", author: user) - expect(doc.css('a').length).to eq 0 + expect(doc.css("a").length).to eq 0 end end - context 'mentioning a group' do - it_behaves_like 'a reference containing an element node' + context "mentioning a group" do + it_behaves_like "a reference containing an element node" let(:group) { create(:group) } let(:reference) { group.to_reference } - it 'links to the Group' do + it "links to the Group" do doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.group_url(group) + expect(doc.css("a").first.attr("href")).to eq urls.group_url(group) end - it 'includes a data-group attribute' do + it "includes a data-group attribute" do doc = reference_filter("Hey #{reference}") - link = doc.css('a').first + link = doc.css("a").first - expect(link).to have_attribute('data-group') - expect(link.attr('data-group')).to eq group.id.to_s + expect(link).to have_attribute("data-group") + expect(link.attr("data-group")).to eq group.id.to_s end end - context 'mentioning a nested group' do - it_behaves_like 'a reference containing an element node' + context "mentioning a nested group" do + it_behaves_like "a reference containing an element node" let(:group) { create(:group, :nested) } let(:reference) { group.to_reference } - it 'links to the nested group' do + it "links to the nested group" do doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls.group_url(group) + expect(doc.css("a").first.attr("href")).to eq urls.group_url(group) end - it 'has the full group name as a title' do + it "has the full group name as a title" do doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('title')).to eq group.full_name + expect(doc.css("a").first.attr("title")).to eq group.full_name end end - it 'links with adjacent text' do + it "links with adjacent text" do doc = reference_filter("Mention me (#{reference}.)") expect(doc.to_html).to match(%r{\(<a.+>#{reference}</a>\.\)}) end - it 'includes default classes' do + it "includes default classes" do doc = reference_filter("Hey #{reference}") - expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-project_member' + expect(doc.css("a").first.attr("class")).to eq "gfm gfm-project_member" end - context 'when a project is not specified' do + context "when a project is not specified" do let(:project) { nil } - it 'does not link a User' do + it "does not link a User" do doc = reference_filter("Hey #{reference}") - expect(doc).not_to include('a') + expect(doc).not_to include("a") end - context 'when skip_project_check set to true' do - it 'links to a User' do + context "when skip_project_check set to true" do + it "links to a User" do doc = reference_filter("Hey #{reference}", skip_project_check: true) - expect(doc.css('a').first.attr('href')).to eq urls.user_url(user) + expect(doc.css("a").first.attr("href")).to eq urls.user_url(user) end - it 'does not link users using @all reference' do + it "does not link users using @all reference" do doc = reference_filter("Hey #{User.reference_prefix}all", skip_project_check: true) - expect(doc).not_to include('a') + expect(doc).not_to include("a") end end end - context 'in group context' do + context "in group context" do let(:group) { create(:group) } let(:group_member) { create(:user) } @@ -155,43 +155,43 @@ describe Banzai::Filter::UserReferenceFilter do group.add_developer(group_member) end - let(:context) { { author: group_member, project: nil, group: group } } + let(:context) { {author: group_member, project: nil, group: group} } - it 'supports a special @all mention' do - reference = User.reference_prefix + 'all' + it "supports a special @all mention" do + reference = User.reference_prefix + "all" doc = reference_filter("Hey #{reference}", context) - expect(doc.css('a').length).to eq(1) - expect(doc.css('a').first.attr('href')).to eq urls.group_url(group) + expect(doc.css("a").length).to eq(1) + expect(doc.css("a").first.attr("href")).to eq urls.group_url(group) end - it 'supports mentioning a single user' do + it "supports mentioning a single user" do reference = get_reference(group_member) doc = reference_filter("Hey #{reference}", context) - expect(doc.css('a').first.attr('href')).to eq urls.user_url(group_member) + expect(doc.css("a").first.attr("href")).to eq urls.user_url(group_member) end - it 'supports mentioning a group' do + it "supports mentioning a group" do reference = group.to_reference doc = reference_filter("Hey #{reference}", context) - expect(doc.css('a').first.attr('href')).to eq urls.user_url(group) + expect(doc.css("a").first.attr("href")).to eq urls.user_url(group) end end - describe '#namespaces' do - it 'returns a Hash containing all Namespaces' do + describe "#namespaces" do + it "returns a Hash containing all Namespaces" do document = Nokogiri::HTML.fragment("<p>#{get_reference(user)}</p>") filter = described_class.new(document, project: project) ns = user.namespace - expect(filter.namespaces).to eq({ ns.path => ns }) + expect(filter.namespaces).to eq({ns.path => ns}) end end - describe '#usernames' do - it 'returns the usernames mentioned in a document' do + describe "#usernames" do + it "returns the usernames mentioned in a document" do document = Nokogiri::HTML.fragment("<p>#{get_reference(user)}</p>") filter = described_class.new(document, project: project) diff --git a/spec/lib/banzai/filter/video_link_filter_spec.rb b/spec/lib/banzai/filter/video_link_filter_spec.rb index 81dda0687f3..f179ed265a2 100644 --- a/spec/lib/banzai/filter/video_link_filter_spec.rb +++ b/spec/lib/banzai/filter/video_link_filter_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::VideoLinkFilter do def filter(doc, contexts = {}) contexts.reverse_merge!({ - project: project + project: project, }) described_class.call(doc, contexts) @@ -15,36 +15,36 @@ describe Banzai::Filter::VideoLinkFilter do let(:project) { create(:project, :repository) } - context 'when the element src has a video extension' do + context "when the element src has a video extension" do UploaderHelper::VIDEO_EXT.each do |ext| it "replaces the image tag 'path/video.#{ext}' with a video tag" do container = filter(link_to_image("/path/video.#{ext}")).children.first - expect(container.name).to eq 'div' - expect(container['class']).to eq 'video-container' + expect(container.name).to eq "div" + expect(container["class"]).to eq "video-container" video, paragraph = container.children - expect(video.name).to eq 'video' - expect(video['src']).to eq "/path/video.#{ext}" + expect(video.name).to eq "video" + expect(video["src"]).to eq "/path/video.#{ext}" - expect(paragraph.name).to eq 'p' + expect(paragraph.name).to eq "p" link = paragraph.children.first - expect(link.name).to eq 'a' - expect(link['href']).to eq "/path/video.#{ext}" - expect(link['target']).to eq '_blank' + expect(link.name).to eq "a" + expect(link["href"]).to eq "/path/video.#{ext}" + expect(link["target"]).to eq "_blank" end end end - context 'when the element src is an image' do - it 'leaves the document unchanged' do - element = filter(link_to_image('/path/my_image.jpg')).children.first + context "when the element src is an image" do + it "leaves the document unchanged" do + element = filter(link_to_image("/path/my_image.jpg")).children.first - expect(element.name).to eq 'img' - expect(element['src']).to eq '/path/my_image.jpg' + expect(element.name).to eq "img" + expect(element["src"]).to eq "/path/my_image.jpg" end end end diff --git a/spec/lib/banzai/filter/wiki_link_filter_spec.rb b/spec/lib/banzai/filter/wiki_link_filter_spec.rb index b9059b85fdc..efae6f1d1f6 100644 --- a/spec/lib/banzai/filter/wiki_link_filter_spec.rb +++ b/spec/lib/banzai/filter/wiki_link_filter_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Filter::WikiLinkFilter do include FilterSpecHelper @@ -12,21 +12,21 @@ describe Banzai::Filter::WikiLinkFilter do it "doesn't rewrite absolute links" do filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0] - expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/') + expect(filtered_link.attribute("href").value).to eq("http://example.com:8000/") end it "doesn't rewrite links to project uploads" do filtered_link = filter("<a href='/uploads/a.test'>Link</a>", project_wiki: wiki).children[0] - expect(filtered_link.attribute('href').value).to eq('/uploads/a.test') + expect(filtered_link.attribute("href").value).to eq("/uploads/a.test") end describe "when links point to the #{Wikis::CreateAttachmentService::ATTACHMENT_PATH} folder" do context 'with an "a" html tag' do - it 'rewrites links' do + it "rewrites links" do filtered_link = filter("<a href='#{repository_upload_folder}/a.test'>Link</a>", project_wiki: wiki).children[0] - expect(filtered_link.attribute('href').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.test") + expect(filtered_link.attribute("href").value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.test") end end @@ -34,28 +34,28 @@ describe Banzai::Filter::WikiLinkFilter do let(:path) { "#{wiki.wiki_base_path}/#{repository_upload_folder}/a.jpg" } context 'inside an "a" html tag' do - it 'rewrites links' do + it "rewrites links" do filtered_elements = filter("<a href='#{repository_upload_folder}/a.jpg'><img src='#{repository_upload_folder}/a.jpg'>example</img></a>", project_wiki: wiki) - expect(filtered_elements.search('img').first.attribute('src').value).to eq(path) - expect(filtered_elements.search('a').first.attribute('href').value).to eq(path) + expect(filtered_elements.search("img").first.attribute("src").value).to eq(path) + expect(filtered_elements.search("a").first.attribute("href").value).to eq(path) end end context 'outside an "a" html tag' do - it 'rewrites links' do + it "rewrites links" do filtered_link = filter("<img src='#{repository_upload_folder}/a.jpg'>example</img>", project_wiki: wiki).children[0] - expect(filtered_link.attribute('src').value).to eq(path) + expect(filtered_link.attribute("src").value).to eq(path) end end end context 'with "video" html tag' do - it 'rewrites links' do + it "rewrites links" do filtered_link = filter("<video src='#{repository_upload_folder}/a.mp4'></video>", project_wiki: wiki).children[0] - expect(filtered_link.attribute('src').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.mp4") + expect(filtered_link.attribute("src").value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.mp4") end end end @@ -67,7 +67,7 @@ describe Banzai::Filter::WikiLinkFilter do it "doesn't rewrite invalid invalid_links like #{invalid_link}" do filtered_link = filter("<a href='#{invalid_link}'>Link</a>", project_wiki: wiki).children[0] - expect(filtered_link.attribute('href').value).to eq(invalid_link) + expect(filtered_link.attribute("href").value).to eq(invalid_link) end end end diff --git a/spec/lib/banzai/filter_array_spec.rb b/spec/lib/banzai/filter_array_spec.rb index ea84005e7f8..8d91af43837 100644 --- a/spec/lib/banzai/filter_array_spec.rb +++ b/spec/lib/banzai/filter_array_spec.rb @@ -1,39 +1,39 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::FilterArray do - describe '#insert_after' do - it 'inserts an element after a provided element' do - filters = described_class.new(%w(a b c)) + describe "#insert_after" do + it "inserts an element after a provided element" do + filters = described_class.new(%w[a b c]) - filters.insert_after('b', '1') + filters.insert_after("b", "1") - expect(filters).to eq %w(a b 1 c) + expect(filters).to eq %w[a b 1 c] end - it 'inserts an element at the end when the provided element does not exist' do - filters = described_class.new(%w(a b c)) + it "inserts an element at the end when the provided element does not exist" do + filters = described_class.new(%w[a b c]) - filters.insert_after('d', '1') + filters.insert_after("d", "1") - expect(filters).to eq %w(a b c 1) + expect(filters).to eq %w[a b c 1] end end - describe '#insert_before' do - it 'inserts an element before a provided element' do - filters = described_class.new(%w(a b c)) + describe "#insert_before" do + it "inserts an element before a provided element" do + filters = described_class.new(%w[a b c]) - filters.insert_before('b', '1') + filters.insert_before("b", "1") - expect(filters).to eq %w(a 1 b c) + expect(filters).to eq %w[a 1 b c] end - it 'inserts an element at the beginning when the provided element does not exist' do - filters = described_class.new(%w(a b c)) + it "inserts an element at the beginning when the provided element does not exist" do + filters = described_class.new(%w[a b c]) - filters.insert_before('d', '1') + filters.insert_before("d", "1") - expect(filters).to eq %w(1 a b c) + expect(filters).to eq %w[1 a b c] end end end diff --git a/spec/lib/banzai/issuable_extractor_spec.rb b/spec/lib/banzai/issuable_extractor_spec.rb index f42951d9781..8656fb9c76a 100644 --- a/spec/lib/banzai/issuable_extractor_spec.rb +++ b/spec/lib/banzai/issuable_extractor_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::IssuableExtractor do let(:project) { create(:project) } @@ -23,19 +23,19 @@ describe Banzai::IssuableExtractor do ).children[0] end - it 'returns instances of issuables for nodes with references' do + it "returns instances of issuables for nodes with references" do result = extractor.extract([issue_link, merge_request_link]) expect(result).to eq(issue_link => issue, merge_request_link => merge_request) end - describe 'caching', :request_store do - it 'saves records to cache' do + describe "caching", :request_store do + it "saves records to cache" do extractor.extract([issue_link, merge_request_link]) - second_call_queries = ActiveRecord::QueryRecorder.new do + second_call_queries = ActiveRecord::QueryRecorder.new { extractor.extract([issue_link, merge_request_link]) - end.count + }.count expect(second_call_queries).to eq 0 end diff --git a/spec/lib/banzai/object_renderer_spec.rb b/spec/lib/banzai/object_renderer_spec.rb index 3b52f6666d0..f44e1a5216c 100644 --- a/spec/lib/banzai/object_renderer_spec.rb +++ b/spec/lib/banzai/object_renderer_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ObjectRenderer do let(:project) { create(:project, :repository) } @@ -7,39 +7,39 @@ describe Banzai::ObjectRenderer do described_class.new( default_project: project, user: user, - redaction_context: { custom_value: 'value' } + redaction_context: {custom_value: "value"} ) end - let(:object) { Note.new(note: 'hello', note_html: '<p dir="auto">hello</p>', cached_markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION << 16) } + let(:object) { Note.new(note: "hello", note_html: '<p dir="auto">hello</p>', cached_markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION << 16) } - describe '#render' do - context 'with cache' do - it 'renders and redacts an Array of objects' do + describe "#render" do + context "with cache" do + it "renders and redacts an Array of objects" do renderer.render([object], :note) expect(object.redacted_note_html).to eq '<p dir="auto">hello</p>' expect(object.user_visible_reference_count).to eq 0 end - it 'calls Banzai::Redactor to perform redaction' do + it "calls Banzai::Redactor to perform redaction" do expect_any_instance_of(Banzai::Redactor).to receive(:redact).and_call_original renderer.render([object], :note) end - it 'retrieves field content using Banzai::Renderer.render_field' do + it "retrieves field content using Banzai::Renderer.render_field" do expect(Banzai::Renderer).to receive(:render_field).with(object, :note, {}).and_call_original renderer.render([object], :note) end - it 'passes context to PostProcessPipeline' do + it "passes context to PostProcessPipeline" do another_user = create(:user) another_project = create(:project) object = Note.new( - note: 'hello', - note_html: 'hello', + note: "hello", + note_html: "hello", author: another_user, project: another_project ) @@ -51,7 +51,7 @@ describe Banzai::ObjectRenderer do current_user: user, project: another_project, author: another_user, - custom_value: 'value' + custom_value: "value" ) ).and_call_original @@ -59,22 +59,22 @@ describe Banzai::ObjectRenderer do end end - context 'without cache' do + context "without cache" do let(:commit) { project.commit } - it 'renders and redacts an Array of objects' do + it "renders and redacts an Array of objects" do renderer.render([commit], :title) expect(commit.redacted_title_html).to eq("Merge branch 'branch-merged' into 'master'") end - it 'calls Banzai::Redactor to perform redaction' do + it "calls Banzai::Redactor to perform redaction" do expect_any_instance_of(Banzai::Redactor).to receive(:redact).and_call_original renderer.render([commit], :title) end - it 'retrieves field content using Banzai::Renderer.cacheless_render_field' do + it "retrieves field content using Banzai::Renderer.cacheless_render_field" do expect(Banzai::Renderer).to receive(:cacheless_render_field).with(commit, :title, {}).and_call_original renderer.render([commit], :title) diff --git a/spec/lib/banzai/pipeline/description_pipeline_spec.rb b/spec/lib/banzai/pipeline/description_pipeline_spec.rb index 77cb1954ea3..d0796152b5a 100644 --- a/spec/lib/banzai/pipeline/description_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/description_pipeline_spec.rb @@ -1,10 +1,10 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Pipeline::DescriptionPipeline do def parse(html) # When we pass HTML to Redcarpet, it gets wrapped in `p` tags... # ...except when we pass it pre-wrapped text. Rabble rabble. - unwrap = !html.start_with?('<p ') + unwrap = !html.start_with?("<p ") output = described_class.to_html(html, project: spy) @@ -17,21 +17,21 @@ describe Banzai::Pipeline::DescriptionPipeline do stub_commonmark_sourcepos_disabled end - it 'uses a limited whitelist' do - doc = parse('# Description') + it "uses a limited whitelist" do + doc = parse("# Description") - expect(doc.strip).to eq 'Description' + expect(doc.strip).to eq "Description" end - %w(pre code img ol ul li).each do |elem| + %w[pre code img ol ul li].each do |elem| it "removes '#{elem}' elements" do act = "<#{elem}>Description</#{elem}>" - expect(parse(act).strip).to eq 'Description' + expect(parse(act).strip).to eq "Description" end end - %w(b i strong em a ins del sup sub).each do |elem| + %w[b i strong em a ins del sup sub].each do |elem| it "still allows '#{elem}' elements" do exp = act = "<#{elem}>Description</#{elem}>" diff --git a/spec/lib/banzai/pipeline/email_pipeline_spec.rb b/spec/lib/banzai/pipeline/email_pipeline_spec.rb index b99161109eb..3a11e7cc7fb 100644 --- a/spec/lib/banzai/pipeline/email_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/email_pipeline_spec.rb @@ -1,17 +1,17 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Pipeline::EmailPipeline do - describe '.filters' do - it 'returns the expected type' do + describe ".filters" do + it "returns the expected type" do expect(described_class.filters).to be_kind_of(Banzai::FilterArray) end - it 'excludes ImageLazyLoadFilter' do + it "excludes ImageLazyLoadFilter" do expect(described_class.filters).not_to be_empty expect(described_class.filters).not_to include(Banzai::Filter::ImageLazyLoadFilter) end - it 'shows punycode for autolinks' do + it "shows punycode for autolinks" do examples = %W[ http://one😄two.com http://\u0261itlab.com @@ -19,9 +19,9 @@ describe Banzai::Pipeline::EmailPipeline do examples.each do |markdown| result = described_class.call(markdown, project: nil)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link.content).to include('http://xn--') + expect(link.content).to include("http://xn--") end end end diff --git a/spec/lib/banzai/pipeline/emoji_pipeline_spec.rb b/spec/lib/banzai/pipeline/emoji_pipeline_spec.rb index 744df3e0b96..f264e275390 100644 --- a/spec/lib/banzai/pipeline/emoji_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/emoji_pipeline_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::Pipeline::EmojiPipeline do def parse(text) described_class.to_html(text, {}) end - it 'replaces emoji' do - expected_result = "Hello world #{Gitlab::Emoji.gl_emoji_tag('100')}" + it "replaces emoji" do + expected_result = "Hello world #{Gitlab::Emoji.gl_emoji_tag("100")}" - expect(parse('Hello world :100:')).to eq(expected_result) + expect(parse("Hello world :100:")).to eq(expected_result) end - it 'filters out HTML tags' do - expected_result = "Hello <b>world</b> #{Gitlab::Emoji.gl_emoji_tag('100')}" + it "filters out HTML tags" do + expected_result = "Hello <b>world</b> #{Gitlab::Emoji.gl_emoji_tag("100")}" - expect(parse('Hello <b>world</b> :100:')).to eq(expected_result) + expect(parse("Hello <b>world</b> :100:")).to eq(expected_result) end end diff --git a/spec/lib/banzai/pipeline/full_pipeline_spec.rb b/spec/lib/banzai/pipeline/full_pipeline_spec.rb index 3d3aa64d630..4f814286754 100644 --- a/spec/lib/banzai/pipeline/full_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/full_pipeline_spec.rb @@ -1,32 +1,32 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Pipeline::FullPipeline do - describe 'References' do + describe "References" do let(:project) { create(:project, :public) } let(:issue) { create(:issue, project: project) } - it 'handles markdown inside a reference' do + it "handles markdown inside a reference" do markdown = "[some `code` inside](#{issue.to_reference})" result = described_class.call(markdown, project: project) - link_content = result[:output].css('a').inner_html - expect(link_content).to eq('some <code>code</code> inside') + link_content = result[:output].css("a").inner_html + expect(link_content).to eq("some <code>code</code> inside") end - it 'sanitizes reference HTML' do - link_label = '<script>bad things</script>' + it "sanitizes reference HTML" do + link_label = "<script>bad things</script>" markdown = "[#{link_label}](#{issue.to_reference})" result = described_class.to_html(markdown, project: project) expect(result).not_to include(link_label) end - it 'escapes the data-original attribute on a reference' do - markdown = %Q{[">bad things](#{issue.to_reference})} + it "escapes the data-original attribute on a reference" do + markdown = %{[">bad things](#{issue.to_reference})} result = described_class.to_html(markdown, project: project) - expect(result).to include(%{data-original='\">bad things'}) + expect(result).to include(%(data-original='\">bad things')) end end - describe 'footnotes' do + describe "footnotes" do let(:project) { create(:project, :public) } let(:html) { described_class.to_html(footnote_markdown, project: project) } let(:identifier) { html[/.*fnref1-(\d+).*/, 1] } @@ -53,15 +53,15 @@ describe Banzai::Pipeline::FullPipeline do EOF end - it 'properly adds the necessary ids and classes' do + it "properly adds the necessary ids and classes" do stub_commonmark_sourcepos_disabled expect(html.lines.map(&:strip).join("\n")).to eq filtered_footnote end end - describe 'links are detected as malicious' do - it 'has tooltips for malicious links' do + describe "links are detected as malicious" do + it "has tooltips for malicious links" do examples = %W[ http://example.com/evil\u202E3pm.exe [evilexe.mp3](http://example.com/evil\u202E3pm.exe) @@ -75,13 +75,13 @@ describe Banzai::Pipeline::FullPipeline do examples.each do |markdown| result = described_class.call(markdown, project: nil)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link[:class]).to include('has-tooltip') + expect(link[:class]).to include("has-tooltip") end end - it 'has no tooltips for safe links' do + it "has no tooltips for safe links" do examples = %w[ http://example.com [Safe-Test](http://example.com) @@ -91,7 +91,7 @@ describe Banzai::Pipeline::FullPipeline do examples.each do |markdown| result = described_class.call(markdown, project: nil)[:output] - link = result.css('a').first + link = result.css("a").first expect(link[:class]).to be_nil end diff --git a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb index 91b0499375d..8714f9d12c9 100644 --- a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb @@ -1,111 +1,111 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Pipeline::GfmPipeline do - describe 'integration between parsing regular and external issue references' do + describe "integration between parsing regular and external issue references" do let(:project) { create(:redmine_project, :public) } - context 'when internal issue tracker is enabled' do - context 'when shorthand pattern #ISSUE_ID is used' do - it 'links an internal issue if it exists' do + context "when internal issue tracker is enabled" do + context "when shorthand pattern #ISSUE_ID is used" do + it "links an internal issue if it exists" do issue = create(:issue, project: project) markdown = issue.to_reference(project, full: true) result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link['href']).to eq( + expect(link["href"]).to eq( Gitlab::Routing.url_helpers.project_issue_path(project, issue) ) end - it 'does not link any issue if it does not exist on GitLab' do - markdown = '#12' + it "does not link any issue if it does not exist on GitLab" do + markdown = "#12" result = described_class.call(markdown, project: project)[:output] - expect(result.css('a')).to be_empty + expect(result.css("a")).to be_empty end end - it 'allows to use long external reference syntax for Redmine' do - markdown = 'API_32-12' + it "allows to use long external reference syntax for Redmine" do + markdown = "API_32-12" result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + expect(link["href"]).to eq "http://redmine/projects/project_name_in_redmine/issues/12" end - it 'parses cross-project references to regular issues' do + it "parses cross-project references to regular issues" do other_project = create(:project, :public) issue = create(:issue, project: other_project) markdown = issue.to_reference(project, full: true) result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link['href']).to eq( + expect(link["href"]).to eq( Gitlab::Routing.url_helpers.project_issue_path(other_project, issue) ) end end - context 'when internal issue tracker is disabled' do + context "when internal issue tracker is disabled" do before do project.issues_enabled = false project.save! end - it 'allows to use shorthand external reference syntax for Redmine' do - markdown = '#12' + it "allows to use shorthand external reference syntax for Redmine" do + markdown = "#12" result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + expect(link["href"]).to eq "http://redmine/projects/project_name_in_redmine/issues/12" end - it 'allows to use long external reference syntax for Redmine' do - markdown = 'API_32-12' + it "allows to use long external reference syntax for Redmine" do + markdown = "API_32-12" result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + expect(link["href"]).to eq "http://redmine/projects/project_name_in_redmine/issues/12" end - it 'parses cross-project references to regular issues' do + it "parses cross-project references to regular issues" do other_project = create(:project, :public) issue = create(:issue, project: other_project) markdown = issue.to_reference(project, full: true) result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + link = result.css("a").first - expect(link['href']).to eq( + expect(link["href"]).to eq( Gitlab::Routing.url_helpers.project_issue_path(other_project, issue) ) end end end - describe 'markdown link or image urls having spaces' do + describe "markdown link or image urls having spaces" do let(:project) { create(:project, :public) } - it 'rewrites links with spaces in url' do + it "rewrites links with spaces in url" do markdown = "[Link to Page](page slug)" output = described_class.to_html(markdown, project: project) expect(output).to include("href=\"page%20slug\"") end - it 'rewrites images with spaces in url' do + it "rewrites images with spaces in url" do markdown = "" output = described_class.to_html(markdown, project: project) expect(output).to include("src=\"test%20image.png\"") end - it 'sanitizes the fixed link' do + it "sanitizes the fixed link" do markdown_xss = "[xss](javascript: alert%28document.domain%29)" output = described_class.to_html(markdown_xss, project: project) diff --git a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb index 64ca3ec345d..b0ee1bfc9e0 100644 --- a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb @@ -1,8 +1,8 @@ -require 'rails_helper' +require "rails_helper" describe Banzai::Pipeline::WikiPipeline do - describe 'TableOfContents' do - it 'replaces the tag with the TableOfContentsFilter result' do + describe "TableOfContents" do + it "replaces the tag with the TableOfContentsFilter result" do markdown = <<-MD.strip_heredoc [[_TOC_]] @@ -14,13 +14,13 @@ describe Banzai::Pipeline::WikiPipeline do result = described_class.call(markdown, project: spy, project_wiki: spy) aggregate_failures do - expect(result[:output].text).not_to include '[[' - expect(result[:output].text).not_to include 'TOC' + expect(result[:output].text).not_to include "[[" + expect(result[:output].text).not_to include "TOC" expect(result[:output].to_html).to include(result[:toc]) end end - it 'is case-sensitive' do + it "is case-sensitive" do markdown = <<-MD.strip_heredoc [[_toc_]] @@ -31,10 +31,10 @@ describe Banzai::Pipeline::WikiPipeline do output = described_class.to_html(markdown, project: spy, project_wiki: spy) - expect(output).to include('[[<em>toc</em>]]') + expect(output).to include("[[<em>toc</em>]]") end - it 'handles an empty pipeline result' do + it "handles an empty pipeline result" do # No Markdown headers in this doc, so `result[:toc]` will be empty markdown = <<-MD.strip_heredoc [[_TOC_]] @@ -45,8 +45,8 @@ describe Banzai::Pipeline::WikiPipeline do output = described_class.to_html(markdown, project: spy, project_wiki: spy) aggregate_failures do - expect(output).not_to include('<ul>') - expect(output).not_to include('[[<em>TOC</em>]]') + expect(output).not_to include("<ul>") + expect(output).not_to include("[[<em>TOC</em>]]") end end end @@ -55,10 +55,10 @@ describe Banzai::Pipeline::WikiPipeline do let(:namespace) { create(:namespace, name: "wiki_link_ns") } let(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) } let(:project_wiki) { ProjectWiki.new(project, double(:user)) } - let(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: 'nested/twice/start-page')) } + let(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: "nested/twice/start-page")) } - { "when GitLab is hosted at a root URL" => '/', - "when GitLab is hosted at a relative URL" => '/nested/relative/gitlab' }.each do |test_name, relative_url_root| + {"when GitLab is hosted at a root URL" => "/", + "when GitLab is hosted at a relative URL" => "/nested/relative/gitlab",}.each do |test_name, relative_url_root| context test_name do before do allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return(relative_url_root) @@ -114,14 +114,14 @@ describe Banzai::Pipeline::WikiPipeline do end describe "when creating non-hierarchical links" do - it 'rewrites non-file links to be at the scope of the wiki root' do + it "rewrites non-file links to be at the scope of the wiki root" do markdown = "[Link to Page](page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page\"") end - it 'rewrites non-file links (with spaces) to be at the scope of the wiki root' do + it "rewrites non-file links (with spaces) to be at the scope of the wiki root" do markdown = "[Link to Page](page slug)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) @@ -135,15 +135,15 @@ describe Banzai::Pipeline::WikiPipeline do expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page.md\"") end - it 'rewrites links with anchor' do - markdown = '[Link to Header](start-page#title)' + it "rewrites links with anchor" do + markdown = "[Link to Header](start-page#title)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start-page#title\"") end - it 'rewrites links (with spaces) with anchor' do - markdown = '[Link to Header](start page#title)' + it "rewrites links (with spaces) with anchor" do + markdown = "[Link to Header](start page#title)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start%20page#title\"") @@ -151,14 +151,14 @@ describe Banzai::Pipeline::WikiPipeline do end describe "when creating root links" do - it 'rewrites non-file links to be at the scope of the wiki root' do + it "rewrites non-file links to be at the scope of the wiki root" do markdown = "[Link to Page](/page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page\"") end - it 'rewrites file links to be at the scope of the wiki root' do + it "rewrites file links to be at the scope of the wiki root" do markdown = "[Link to Page](/page.md)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) @@ -179,20 +179,20 @@ describe Banzai::Pipeline::WikiPipeline do end end - describe 'videos' do + describe "videos" do let(:namespace) { create(:namespace, name: "wiki_link_ns") } let(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) } let(:project_wiki) { ProjectWiki.new(project, double(:user)) } - let(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: 'nested/twice/start-page')) } + let(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: "nested/twice/start-page")) } - it 'generates video html structure' do + it "generates video html structure" do markdown = "" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/video_file_name.mp4"') end - it 'rewrites and replaces video links names with white spaces to %20' do + it "rewrites and replaces video links names with white spaces to %20" do markdown = "" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) diff --git a/spec/lib/banzai/querying_spec.rb b/spec/lib/banzai/querying_spec.rb index 27da2a7439c..ea80c623c32 100644 --- a/spec/lib/banzai/querying_spec.rb +++ b/spec/lib/banzai/querying_spec.rb @@ -1,13 +1,13 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Querying do - describe '.css' do - it 'optimizes queries for elements with classes' do + describe ".css" do + it "optimizes queries for elements with classes" do document = double(:document) expect(document).to receive(:xpath).with(/^descendant::a/) - described_class.css(document, 'a.gfm') + described_class.css(document, "a.gfm") end end end diff --git a/spec/lib/banzai/redactor_spec.rb b/spec/lib/banzai/redactor_spec.rb index aaeec953e4b..1acd84b3467 100644 --- a/spec/lib/banzai/redactor_spec.rb +++ b/spec/lib/banzai/redactor_spec.rb @@ -1,48 +1,48 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Redactor do let(:user) { create(:user) } let(:project) { build(:project) } let(:redactor) { described_class.new(Banzai::RenderContext.new(project, user)) } - describe '#redact' do - context 'when reference not visible to user' do + describe "#redact" do + context "when reference not visible to user" do before do expect(redactor).to receive(:nodes_visible_to_user).and_return([]) end - it 'redacts an array of documents' do + it "redacts an array of documents" do doc1 = Nokogiri::HTML - .fragment('<a class="gfm" data-reference-type="issue">foo</a>') + .fragment('<a class="gfm" data-reference-type="issue">foo</a>') doc2 = Nokogiri::HTML - .fragment('<a class="gfm" data-reference-type="issue">bar</a>') + .fragment('<a class="gfm" data-reference-type="issue">bar</a>') redacted_data = redactor.redact([doc1, doc2]) expect(redacted_data.map { |data| data[:document] }).to eq([doc1, doc2]) expect(redacted_data.map { |data| data[:visible_reference_count] }).to eq([0, 0]) - expect(doc1.to_html).to eq('foo') - expect(doc2.to_html).to eq('bar') + expect(doc1.to_html).to eq("foo") + expect(doc2.to_html).to eq("bar") end - it 'replaces redacted reference with inner HTML' do + it "replaces redacted reference with inner HTML" do doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue'>foo</a>") redactor.redact([doc]) - expect(doc.to_html).to eq('foo') + expect(doc.to_html).to eq("foo") end - context 'when data-original attribute provided' do - let(:original_content) { '<code>foo</code>' } - it 'replaces redacted reference with original content' do + context "when data-original attribute provided" do + let(:original_content) { "<code>foo</code>" } + it "replaces redacted reference with original content" do doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue' data-original='#{original_content}'>bar</a>") redactor.redact([doc]) expect(doc.to_html).to eq(original_content) end end - it 'returns <a> tag with original href if it is originally a link reference' do - href = 'http://localhost:3000' + it "returns <a> tag with original href if it is originally a link reference" do + href = "http://localhost:3000" doc = Nokogiri::HTML .fragment("<a class='gfm' data-reference-type='issue' data-original=#{href} data-link-reference='true'>#{href}</a>") @@ -52,7 +52,7 @@ describe Banzai::Redactor do end end - context 'when project is in pending delete' do + context "when project is in pending delete" do let!(:issue) { create(:issue, project: project) } let(:redactor) { described_class.new(Banzai::RenderContext.new(project, user)) } @@ -60,25 +60,25 @@ describe Banzai::Redactor do project.update(pending_delete: true) end - it 'redacts an issue attached' do + it "redacts an issue attached" do doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue' data-issue='#{issue.id}'>foo</a>") redactor.redact([doc]) - expect(doc.to_html).to eq('foo') + expect(doc.to_html).to eq("foo") end - it 'redacts an external issue' do + it "redacts an external issue" do doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue' data-external-issue='#{issue.id}' data-project='#{project.id}'>foo</a>") redactor.redact([doc]) - expect(doc.to_html).to eq('foo') + expect(doc.to_html).to eq("foo") end end - context 'when reference visible to user' do - it 'does not redact an array of documents' do + context "when reference visible to user" do + it "does not redact an array of documents" do doc1_html = '<a class="gfm" data-reference-type="issue">foo</a>' doc1 = Nokogiri::HTML.fragment(doc1_html) @@ -98,20 +98,20 @@ describe Banzai::Redactor do end end - context 'when the user cannot read cross project' do + context "when the user cannot read cross project" do include ActionView::Helpers::UrlHelper let(:project) { create(:project) } let(:other_project) { create(:project, :public) } def create_link(issuable) type = issuable.class.name.underscore.downcase - link_to(issuable.to_reference, '', - class: 'gfm has-tooltip', - title: issuable.title, - data: { - reference_type: type, - "#{type}": issuable.id - }) + link_to(issuable.to_reference, "", + class: "gfm has-tooltip", + title: issuable.title, + data: { + :reference_type => type, + :"#{type}" => issuable.id, + }) end before do @@ -122,33 +122,33 @@ describe Banzai::Redactor do allow(Ability).to receive(:allowed?).with(user, :read_cross_project) { false } end - it 'skips links to issues within the same project' do + it "skips links to issues within the same project" do issue = create(:issue, project: project) link = create_link(issue) doc = Nokogiri::HTML.fragment(link) redactor.redact([doc]) - result = doc.css('a').last + result = doc.css("a").last - expect(result['class']).to include('has-tooltip') - expect(result['title']).to eq(issue.title) + expect(result["class"]).to include("has-tooltip") + expect(result["title"]).to eq(issue.title) end - it 'removes info from a cross project reference' do + it "removes info from a cross project reference" do issue = create(:issue, project: other_project) link = create_link(issue) doc = Nokogiri::HTML.fragment(link) redactor.redact([doc]) - result = doc.css('a').last + result = doc.css("a").last - expect(result['class']).not_to include('has-tooltip') - expect(result['title']).to be_empty + expect(result["class"]).not_to include("has-tooltip") + expect(result["title"]).to be_empty end end - describe '#redact_nodes' do - it 'redacts an Array of nodes' do + describe "#redact_nodes" do + it "redacts an Array of nodes" do doc = Nokogiri::HTML.fragment('<a href="foo">foo</a>') node = doc.children[0] @@ -156,14 +156,14 @@ describe Banzai::Redactor do .with([node]) .and_return(Set.new) - redactor.redact_document_nodes([{ document: doc, nodes: [node] }]) + redactor.redact_document_nodes([{document: doc, nodes: [node]}]) - expect(doc.to_html).to eq('foo') + expect(doc.to_html).to eq("foo") end end - describe '#nodes_visible_to_user' do - it 'returns a Set containing the visible nodes' do + describe "#nodes_visible_to_user" do + it "returns a Set containing the visible nodes" do doc = Nokogiri::HTML.fragment('<a data-reference-type="issue"></a>') node = doc.children[0] diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb index c6e9fc414a1..4d0a241bfbd 100644 --- a/spec/lib/banzai/reference_parser/base_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::BaseParser do include ReferenceParserHelpers @@ -8,15 +8,15 @@ describe Banzai::ReferenceParser::BaseParser do let(:context) { Banzai::RenderContext.new(project, user) } subject do - klass = Class.new(described_class) do + klass = Class.new(described_class) { self.reference_type = :foo - end + } klass.new(context) end - describe '.reference_type=' do - it 'sets the reference type' do + describe ".reference_type=" do + it "sets the reference type" do dummy = Class.new(described_class) dummy.reference_type = :foo @@ -24,12 +24,12 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#project_for_node' do - it 'returns the Project for a node' do - document = instance_double('document', fragment?: false) - project = instance_double('project') - object = instance_double('object', project: project) - node = instance_double('node', document: document) + describe "#project_for_node" do + it "returns the Project for a node" do + document = instance_double("document", fragment?: false) + project = instance_double("project") + object = instance_double("object", project: project) + node = instance_double("node", document: document) context.associate_document(document, object) @@ -37,12 +37,12 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#nodes_visible_to_user' do + describe "#nodes_visible_to_user" do let(:link) { empty_html_link } - context 'when the link has a data-project attribute' do - it 'checks if user can read the resource' do - link['data-project'] = project.id.to_s + context "when the link has a data-project attribute" do + it "checks if user can read the resource" do + link["data-project"] = project.id.to_s expect(subject).to receive(:can_read_reference?).with(user, project, link) @@ -50,24 +50,24 @@ describe Banzai::ReferenceParser::BaseParser do end end - context 'when the link does not have a data-project attribute' do - it 'returns the nodes' do + context "when the link does not have a data-project attribute" do + it "returns the nodes" do expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end end end - describe '#nodes_user_can_reference' do - it 'returns the nodes' do + describe "#nodes_user_can_reference" do + it "returns the nodes" do link = double(:link) expect(subject.nodes_user_can_reference(user, [link])).to eq([link]) end end - describe '#referenced_by' do - context 'when references_relation is implemented' do - it 'returns a collection of objects' do + describe "#referenced_by" do + context "when references_relation is implemented" do + it "returns a collection of objects" do links = Nokogiri::HTML.fragment("<a data-foo='#{user.id}'></a>") .children @@ -76,8 +76,8 @@ describe Banzai::ReferenceParser::BaseParser do end end - context 'when references_relation is not implemented' do - it 'raises NotImplementedError' do + context "when references_relation is not implemented" do + it "raises NotImplementedError" do links = Nokogiri::HTML.fragment('<a data-foo="1"></a>').children expect { subject.referenced_by(links) } @@ -86,97 +86,97 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#references_relation' do - it 'raises NotImplementedError' do + describe "#references_relation" do + it "raises NotImplementedError" do expect { subject.references_relation }.to raise_error(NotImplementedError) end end - describe '#gather_attributes_per_project' do - it 'returns a Hash containing attribute values per project' do + describe "#gather_attributes_per_project" do + it "returns a Hash containing attribute values per project" do link = Nokogiri::HTML.fragment('<a data-project="1" data-foo="2"></a>') .children[0] - hash = subject.gather_attributes_per_project([link], 'data-foo') + hash = subject.gather_attributes_per_project([link], "data-foo") expect(hash).to be_an_instance_of(Hash) - expect(hash[1].to_a).to eq(['2']) + expect(hash[1].to_a).to eq(["2"]) end end - describe '#grouped_objects_for_nodes' do - it 'returns a Hash grouping objects per node' do + describe "#grouped_objects_for_nodes" do + it "returns a Hash grouping objects per node" do link = double(:link) expect(link).to receive(:has_attribute?) - .with('data-user') + .with("data-user") .and_return(true) expect(link).to receive(:attr) - .with('data-user') + .with("data-user") .and_return(user.id.to_s) nodes = [link] expect(subject).to receive(:unique_attribute_values) - .with(nodes, 'data-user') + .with(nodes, "data-user") .and_return([user.id.to_s]) - hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user') + hash = subject.grouped_objects_for_nodes(nodes, User, "data-user") - expect(hash).to eq({ link => user }) + expect(hash).to eq({link => user}) end - it 'returns an empty Hash when entry does not exist in the database', :request_store do + it "returns an empty Hash when entry does not exist in the database", :request_store do link = double(:link) expect(link).to receive(:has_attribute?) - .with('data-user') - .and_return(true) + .with("data-user") + .and_return(true) expect(link).to receive(:attr) - .with('data-user') - .and_return('1') + .with("data-user") + .and_return("1") nodes = [link] bad_id = user.id + 100 expect(subject).to receive(:unique_attribute_values) - .with(nodes, 'data-user') - .and_return([bad_id.to_s]) + .with(nodes, "data-user") + .and_return([bad_id.to_s]) - hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user') + hash = subject.grouped_objects_for_nodes(nodes, User, "data-user") expect(hash).to eq({}) end end - describe '#unique_attribute_values' do - it 'returns an Array of unique values' do + describe "#unique_attribute_values" do + it "returns an Array of unique values" do link = double(:link) expect(link).to receive(:has_attribute?) - .with('data-foo') + .with("data-foo") .twice .and_return(true) expect(link).to receive(:attr) - .with('data-foo') + .with("data-foo") .twice - .and_return('1') + .and_return("1") nodes = [link, link] - expect(subject.unique_attribute_values(nodes, 'data-foo')).to eq(['1']) + expect(subject.unique_attribute_values(nodes, "data-foo")).to eq(["1"]) end end - describe '#process' do - it 'gathers the references for every node matching the reference type' do - dummy = Class.new(described_class) do + describe "#process" do + it "gathers the references for every node matching the reference type" do + dummy = Class.new(described_class) { self.reference_type = :test - end + } instance = dummy.new(Banzai::RenderContext.new(project, user)) document = Nokogiri::HTML.fragment('<a class="gfm"></a><a class="gfm" data-reference-type="test"></a>') @@ -189,10 +189,10 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#gather_references' do + describe "#gather_references" do let(:link) { double(:link) } - it 'does not process links a user can not reference' do + it "does not process links a user can not reference" do expect(subject).to receive(:nodes_user_can_reference) .with(user, [link]) .and_return([]) @@ -202,7 +202,7 @@ describe Banzai::ReferenceParser::BaseParser do subject.gather_references([link]) end - it 'does not process links a user can not see' do + it "does not process links a user can not see" do expect(subject).to receive(:nodes_user_can_reference) .with(user, [link]) .and_return([link]) @@ -216,7 +216,7 @@ describe Banzai::ReferenceParser::BaseParser do subject.gather_references([link]) end - it 'returns the references if a user can reference and see a link' do + it "returns the references if a user can reference and see a link" do expect(subject).to receive(:nodes_user_can_reference) .with(user, [link]) .and_return([link]) @@ -231,8 +231,8 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#can?' do - it 'delegates the permissions check to the Ability class' do + describe "#can?" do + it "delegates the permissions check to the Ability class" do user = double(:user) expect(Ability).to receive(:allowed?) @@ -242,16 +242,16 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#find_projects_for_hash_keys' do - it 'returns a list of Projects' do + describe "#find_projects_for_hash_keys" do + it "returns a list of Projects" do expect(subject.find_projects_for_hash_keys(project.id => project)) .to eq([project]) end end - describe '#collection_objects_for_ids' do - context 'with RequestStore disabled' do - it 'queries the collection directly' do + describe "#collection_objects_for_ids" do + context "with RequestStore disabled" do + it "queries the collection directly" do collection = User.all expect(collection).to receive(:where).twice.and_call_original @@ -263,19 +263,19 @@ describe Banzai::ReferenceParser::BaseParser do end end - context 'with RequestStore enabled', :request_store do + context "with RequestStore enabled", :request_store do before do cache = Hash.new { |hash, key| hash[key] = {} } allow(subject).to receive(:collection_cache).and_return(cache) end - it 'queries the collection on the first call' do + it "queries the collection on the first call" do expect(subject.collection_objects_for_ids(User, [user.id])) .to eq([user]) end - it 'does not query previously queried objects' do + it "does not query previously queried objects" do collection = User.all expect(collection).to receive(:where).once.and_call_original @@ -286,14 +286,14 @@ describe Banzai::ReferenceParser::BaseParser do end end - it 'casts String based IDs to Fixnums before querying objects' do + it "casts String based IDs to Fixnums before querying objects" do 2.times do expect(subject.collection_objects_for_ids(User, [user.id.to_s])) .to eq([user]) end end - it 'queries any additional objects after the first call' do + it "queries any additional objects after the first call" do other_user = create(:user) expect(subject.collection_objects_for_ids(User, [user.id])) @@ -303,7 +303,7 @@ describe Banzai::ReferenceParser::BaseParser do .to eq([user, other_user]) end - it 'caches objects on a per collection class basis' do + it "caches objects on a per collection class basis" do expect(subject.collection_objects_for_ids(User, [user.id])) .to eq([user]) @@ -313,12 +313,12 @@ describe Banzai::ReferenceParser::BaseParser do end end - describe '#collection_cache_key' do - it 'returns the cache key for a Class' do + describe "#collection_cache_key" do + it "returns the cache key for a Class" do expect(subject.collection_cache_key(Project)).to eq(Project) end - it 'returns the cache key for an ActiveRecord::Relation' do + it "returns the cache key for an ActiveRecord::Relation" do expect(subject.collection_cache_key(Project.all)).to eq(Project) end end diff --git a/spec/lib/banzai/reference_parser/commit_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_parser_spec.rb index f558dea209f..83eb9fdf08b 100644 --- a/spec/lib/banzai/reference_parser/commit_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::CommitParser do include ReferenceParserHelpers @@ -8,52 +8,52 @@ describe Banzai::ReferenceParser::CommitParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do - link['data-commit'] = 123 + link["data-commit"] = 123 end it_behaves_like "referenced feature visibility", "repository" end end - describe '#referenced_by' do - context 'when the link has a data-project attribute' do + describe "#referenced_by" do + context "when the link has a data-project attribute" do before do - link['data-project'] = project.id.to_s + link["data-project"] = project.id.to_s end - context 'when the link has a data-commit attribute' do + context "when the link has a data-commit attribute" do before do - link['data-commit'] = '123' + link["data-commit"] = "123" end - it 'returns an Array of commits' do + it "returns an Array of commits" do commit = double(:commit) allow_any_instance_of(Project).to receive(:valid_repo?) .and_return(true) expect(subject).to receive(:find_commits) - .with(project, ['123']) + .with(project, ["123"]) .and_return([commit]) expect(subject.referenced_by([link])).to eq([commit]) end - it 'returns an empty Array when the commit could not be found' do + it "returns an empty Array when the commit could not be found" do allow_any_instance_of(Project).to receive(:valid_repo?) .and_return(true) expect(subject).to receive(:find_commits) - .with(project, ['123']) + .with(project, ["123"]) .and_return([]) expect(subject.referenced_by([link])).to eq([]) end - it 'skips projects without valid repositories' do + it "skips projects without valid repositories" do allow_any_instance_of(Project).to receive(:valid_repo?) .and_return(false) @@ -61,8 +61,8 @@ describe Banzai::ReferenceParser::CommitParser do end end - context 'when the link does not have a data-commit attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-commit attribute" do + it "returns an empty Array" do allow_any_instance_of(Project).to receive(:valid_repo?) .and_return(true) @@ -71,8 +71,8 @@ describe Banzai::ReferenceParser::CommitParser do end end - context 'when the link does not have a data-project attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-project attribute" do + it "returns an empty Array" do allow_any_instance_of(Project).to receive(:valid_repo?) .and_return(true) @@ -81,47 +81,47 @@ describe Banzai::ReferenceParser::CommitParser do end end - describe '#commit_ids_per_project' do + describe "#commit_ids_per_project" do before do - link['data-project'] = project.id.to_s + link["data-project"] = project.id.to_s end - it 'returns a Hash containing commit IDs per project' do - link['data-commit'] = '123' + it "returns a Hash containing commit IDs per project" do + link["data-commit"] = "123" hash = subject.commit_ids_per_project([link]) expect(hash).to be_an_instance_of(Hash) - expect(hash[project.id].to_a).to eq(['123']) + expect(hash[project.id].to_a).to eq(["123"]) end - it 'does not add a project when the data-commit attribute is empty' do + it "does not add a project when the data-commit attribute is empty" do hash = subject.commit_ids_per_project([link]) expect(hash).to be_empty end end - describe '#find_commits' do - it 'returns an Array of commit objects' do + describe "#find_commits" do + it "returns an Array of commit objects" do commit = double(:commit) - expect(project).to receive(:commit).with('123').and_return(commit) + expect(project).to receive(:commit).with("123").and_return(commit) expect(project).to receive(:valid_repo?).and_return(true) - expect(subject.find_commits(project, %w{123})).to eq([commit]) + expect(subject.find_commits(project, %w[123])).to eq([commit]) end - it 'skips commit IDs for which no commit could be found' do - expect(project).to receive(:commit).with('123').and_return(nil) + it "skips commit IDs for which no commit could be found" do + expect(project).to receive(:commit).with("123").and_return(nil) expect(project).to receive(:valid_repo?).and_return(true) - expect(subject.find_commits(project, %w{123})).to eq([]) + expect(subject.find_commits(project, %w[123])).to eq([]) end end - context 'when checking commits on another projects' do + context "when checking commits on another projects" do let(:control_links) do [commit_link] end @@ -133,9 +133,9 @@ describe Banzai::ReferenceParser::CommitParser do def commit_link project = create(:project, :repository, :public) - Nokogiri::HTML.fragment(%Q{<a data-commit="#{project.commit.id}" data-project="#{project.id}"></a>}).children[0] + Nokogiri::HTML.fragment(%(<a data-commit="#{project.commit.id}" data-project="#{project.id}"></a>)).children[0] end - it_behaves_like 'no project N+1 queries' + it_behaves_like "no project N+1 queries" end end diff --git a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb index ff3b82cc482..28d8a6ffa71 100644 --- a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::CommitRangeParser do include ReferenceParserHelpers @@ -8,128 +8,128 @@ describe Banzai::ReferenceParser::CommitRangeParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do - link['data-commit-range'] = '123..456' + link["data-commit-range"] = "123..456" end it_behaves_like "referenced feature visibility", "repository" end end - describe '#referenced_by' do - context 'when the link has a data-project attribute' do + describe "#referenced_by" do + context "when the link has a data-project attribute" do before do - link['data-project'] = project.id.to_s + link["data-project"] = project.id.to_s end - context 'when the link as a data-commit-range attribute' do + context "when the link as a data-commit-range attribute" do before do - link['data-commit-range'] = '123..456' + link["data-commit-range"] = "123..456" end - it 'returns an Array of commit ranges' do + it "returns an Array of commit ranges" do range = double(:range) expect(subject).to receive(:find_object) - .with(project, '123..456') + .with(project, "123..456") .and_return(range) expect(subject.referenced_by([link])).to eq([range]) end - it 'returns an empty Array when the commit range could not be found' do + it "returns an empty Array when the commit range could not be found" do expect(subject).to receive(:find_object) - .with(project, '123..456') + .with(project, "123..456") .and_return(nil) expect(subject.referenced_by([link])).to eq([]) end end - context 'when the link does not have a data-commit-range attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-commit-range attribute" do + it "returns an empty Array" do expect(subject.referenced_by([link])).to eq([]) end end end - context 'when the link does not have a data-project attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-project attribute" do + it "returns an empty Array" do expect(subject.referenced_by([link])).to eq([]) end end end - describe '#commit_range_ids_per_project' do + describe "#commit_range_ids_per_project" do before do - link['data-project'] = project.id.to_s + link["data-project"] = project.id.to_s end - it 'returns a Hash containing range IDs per project' do - link['data-commit-range'] = '123..456' + it "returns a Hash containing range IDs per project" do + link["data-commit-range"] = "123..456" hash = subject.commit_range_ids_per_project([link]) expect(hash).to be_an_instance_of(Hash) - expect(hash[project.id].to_a).to eq(['123..456']) + expect(hash[project.id].to_a).to eq(["123..456"]) end - it 'does not add a project when the data-commit-range attribute is empty' do + it "does not add a project when the data-commit-range attribute is empty" do hash = subject.commit_range_ids_per_project([link]) expect(hash).to be_empty end end - describe '#find_ranges' do - it 'returns an Array of range objects' do + describe "#find_ranges" do + it "returns an Array of range objects" do range = double(:commit) expect(subject).to receive(:find_object) - .with(project, '123..456') + .with(project, "123..456") .and_return(range) - expect(subject.find_ranges(project, ['123..456'])).to eq([range]) + expect(subject.find_ranges(project, ["123..456"])).to eq([range]) end - it 'skips ranges that could not be found' do + it "skips ranges that could not be found" do expect(subject).to receive(:find_object) - .with(project, '123..456') + .with(project, "123..456") .and_return(nil) - expect(subject.find_ranges(project, ['123..456'])).to eq([]) + expect(subject.find_ranges(project, ["123..456"])).to eq([]) end end - describe '#find_object' do + describe "#find_object" do let(:range) { double(:range) } - context 'when the range has valid commits' do - it 'returns the commit range' do + context "when the range has valid commits" do + it "returns the commit range" do expect(CommitRange).to receive(:new).and_return(range) expect(range).to receive(:valid_commits?).and_return(true) - expect(subject.find_object(project, '123..456')).to eq(range) + expect(subject.find_object(project, "123..456")).to eq(range) end end - context 'when the range does not have any valid commits' do - it 'returns nil' do + context "when the range does not have any valid commits" do + it "returns nil" do expect(CommitRange).to receive(:new).and_return(range) expect(range).to receive(:valid_commits?).and_return(false) - expect(subject.find_object(project, '123..456')).to be_nil + expect(subject.find_object(project, "123..456")).to be_nil end end - context 'group context' do - it 'returns nil' do + context "group context" do + it "returns nil" do group = create(:group) - expect(subject.find_object(group, '123..456')).to be_nil + expect(subject.find_object(group, "123..456")).to be_nil end end end diff --git a/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb b/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb index 1cb31e57114..e1ad649b1d2 100644 --- a/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::ExternalIssueParser do include ReferenceParserHelpers @@ -8,10 +8,10 @@ describe Banzai::ReferenceParser::ExternalIssueParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do - link['data-external-issue'] = 123 + link["data-external-issue"] = 123 end levels = [ProjectFeature::DISABLED, ProjectFeature::PRIVATE, ProjectFeature::ENABLED] @@ -28,52 +28,52 @@ describe Banzai::ReferenceParser::ExternalIssueParser do end end - describe '#referenced_by' do - context 'when the link has a data-project attribute' do + describe "#referenced_by" do + context "when the link has a data-project attribute" do before do - link['data-project'] = project.id.to_s + link["data-project"] = project.id.to_s end - context 'when the link has a data-external-issue attribute' do - it 'returns an Array of ExternalIssue instances' do - link['data-external-issue'] = '123' + context "when the link has a data-external-issue attribute" do + it "returns an Array of ExternalIssue instances" do + link["data-external-issue"] = "123" refs = subject.referenced_by([link]) - expect(refs).to eq([ExternalIssue.new('123', project)]) + expect(refs).to eq([ExternalIssue.new("123", project)]) end end - context 'when the link does not have a data-external-issue attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-external-issue attribute" do + it "returns an empty Array" do expect(subject.referenced_by([link])).to eq([]) end end end - context 'when the link does not have a data-project attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-project attribute" do + it "returns an empty Array" do expect(subject.referenced_by([link])).to eq([]) end end end - describe '#issue_ids_per_project' do + describe "#issue_ids_per_project" do before do - link['data-project'] = project.id.to_s + link["data-project"] = project.id.to_s end - it 'returns a Hash containing range IDs per project' do - link['data-external-issue'] = '123' + it "returns a Hash containing range IDs per project" do + link["data-external-issue"] = "123" hash = subject.issue_ids_per_project([link]) expect(hash).to be_an_instance_of(Hash) - expect(hash[project.id].to_a).to eq(['123']) + expect(hash[project.id].to_a).to eq(["123"]) end - it 'does not add a project when the data-external-issue attribute is empty' do + it "does not add a project when the data-external-issue attribute is empty" do hash = subject.issue_ids_per_project([link]) expect(hash).to be_empty diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb index 77c2064caba..b92a7a408af 100644 --- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::IssueParser do include ReferenceParserHelpers @@ -9,31 +9,31 @@ describe Banzai::ReferenceParser::IssueParser do let(:link) { empty_html_link } subject { described_class.new(Banzai::RenderContext.new(project, user)) } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do - link['data-issue'] = issue.id.to_s + link["data-issue"] = issue.id.to_s end it_behaves_like "referenced feature visibility", "issues" - it 'returns the nodes when the user can read the issue' do + it "returns the nodes when the user can read the issue" do expect(Ability).to receive(:issues_readable_by_user) - .with([issue], user) - .and_return([issue]) + .with([issue], user) + .and_return([issue]) expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end - it 'returns an empty Array when the user can not read the issue' do + it "returns an empty Array when the user can not read the issue" do expect(Ability).to receive(:issues_readable_by_user) - .with([issue], user) - .and_return([]) + .with([issue], user) + .and_return([]) expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end - context 'when the user cannot read cross project' do + context "when the user cannot read cross project" do let(:issue) { create(:issue) } before do @@ -41,29 +41,29 @@ describe Banzai::ReferenceParser::IssueParser do allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global) { false } end - it 'returns the nodes when the user can read the issue' do + it "returns the nodes when the user can read the issue" do expect(Ability).to receive(:allowed?) - .with(user, :read_issue_iid, issue) - .and_return(true) + .with(user, :read_issue_iid, issue) + .and_return(true) expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end - it 'returns an empty Array when the user can not read the issue' do + it "returns an empty Array when the user can not read the issue" do expect(Ability).to receive(:allowed?) - .with(user, :read_issue_iid, issue) - .and_return(false) + .with(user, :read_issue_iid, issue) + .and_return(false) expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end - context 'when the issue is not cross project' do + context "when the issue is not cross project" do let(:issue) { create(:issue, project: project) } - it 'does not check `can_read_reference` if the issue is not cross project' do + it "does not check `can_read_reference` if the issue is not cross project" do expect(Ability).to receive(:issues_readable_by_user) - .with([issue], user) - .and_return([]) + .with([issue], user) + .and_return([]) expect(subject).not_to receive(:can_read_reference?).with(user, issue) @@ -73,52 +73,52 @@ describe Banzai::ReferenceParser::IssueParser do end end - context 'when the link does not have a data-issue attribute' do - it 'returns an empty Array' do + context "when the link does not have a data-issue attribute" do + it "returns an empty Array" do expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end end end - describe '#referenced_by' do - context 'when the link has a data-issue attribute' do - context 'using an existing issue ID' do + describe "#referenced_by" do + context "when the link has a data-issue attribute" do + context "using an existing issue ID" do before do - link['data-issue'] = issue.id.to_s + link["data-issue"] = issue.id.to_s end - it 'returns an Array of issues' do + it "returns an Array of issues" do expect(subject.referenced_by([link])).to eq([issue]) end - it 'returns an empty Array when the list of nodes is empty' do + it "returns an empty Array when the list of nodes is empty" do expect(subject.referenced_by([link])).to eq([issue]) expect(subject.referenced_by([])).to eq([]) end end - context 'when issue with given ID does not exist' do + context "when issue with given ID does not exist" do before do - link['data-issue'] = '-1' + link["data-issue"] = "-1" end - it 'returns an empty Array' do + it "returns an empty Array" do expect(subject.referenced_by([link])).to eq([]) end end end end - describe '#records_for_nodes' do - it 'returns a Hash containing the issues for a list of nodes' do - link['data-issue'] = issue.id.to_s + describe "#records_for_nodes" do + it "returns a Hash containing the issues for a list of nodes" do + link["data-issue"] = issue.id.to_s nodes = [link] - expect(subject.records_for_nodes(nodes)).to eq({ link => issue }) + expect(subject.records_for_nodes(nodes)).to eq({link => issue}) end end - context 'when checking multiple merge requests on another project' do + context "when checking multiple merge requests on another project" do let(:other_project) { create(:project, :public) } let(:other_issue) { create(:issue, project: other_project) } @@ -131,13 +131,13 @@ describe Banzai::ReferenceParser::IssueParser do end def issue_link(issue) - Nokogiri::HTML.fragment(%Q{<a data-issue="#{issue.id}"></a>}).children[0] + Nokogiri::HTML.fragment(%(<a data-issue="#{issue.id}"></a>)).children[0] end before do project.add_developer(user) end - it_behaves_like 'no N+1 queries' + it_behaves_like "no N+1 queries" end end diff --git a/spec/lib/banzai/reference_parser/label_parser_spec.rb b/spec/lib/banzai/reference_parser/label_parser_spec.rb index e4df2533821..cc5e1fb1928 100644 --- a/spec/lib/banzai/reference_parser/label_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/label_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::LabelParser do include ReferenceParserHelpers @@ -9,29 +9,29 @@ describe Banzai::ReferenceParser::LabelParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do - link['data-label'] = label.id.to_s + link["data-label"] = label.id.to_s end it_behaves_like "referenced feature visibility", "issues", "merge_requests" end end - describe '#referenced_by' do - describe 'when the link has a data-label attribute' do - context 'using an existing label ID' do - it 'returns an Array of labels' do - link['data-label'] = label.id.to_s + describe "#referenced_by" do + describe "when the link has a data-label attribute" do + context "using an existing label ID" do + it "returns an Array of labels" do + link["data-label"] = label.id.to_s expect(subject.referenced_by([link])).to eq([label]) end end - context 'using a non-existing label ID' do - it 'returns an empty Array' do - link['data-label'] = '' + context "using a non-existing label ID" do + it "returns an empty Array" do + link["data-label"] = "" expect(subject.referenced_by([link])).to eq([]) end diff --git a/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb b/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb index 5417b1f00be..f017ed12c2c 100644 --- a/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::MergeRequestParser do include ReferenceParserHelpers @@ -9,30 +9,30 @@ describe Banzai::ReferenceParser::MergeRequestParser do subject { described_class.new(Banzai::RenderContext.new(merge_request.target_project, user)) } let(:link) { empty_html_link } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC) - link['data-merge-request'] = merge_request.id.to_s + link["data-merge-request"] = merge_request.id.to_s end it_behaves_like "referenced feature visibility", "merge_requests" end end - describe '#referenced_by' do - describe 'when the link has a data-merge-request attribute' do - context 'using an existing merge request ID' do - it 'returns an Array of merge requests' do - link['data-merge-request'] = merge_request.id.to_s + describe "#referenced_by" do + describe "when the link has a data-merge-request attribute" do + context "using an existing merge request ID" do + it "returns an Array of merge requests" do + link["data-merge-request"] = merge_request.id.to_s expect(subject.referenced_by([link])).to eq([merge_request]) end end - context 'using a non-existing merge request ID' do - it 'returns an empty Array' do - link['data-merge-request'] = '' + context "using a non-existing merge request ID" do + it "returns an empty Array" do + link["data-merge-request"] = "" expect(subject.referenced_by([link])).to eq([]) end @@ -40,7 +40,7 @@ describe Banzai::ReferenceParser::MergeRequestParser do end end - context 'when checking multiple merge requests on another project' do + context "when checking multiple merge requests on another project" do let(:other_project) { create(:project, :public) } let(:other_merge_request) { create(:merge_request, source_project: other_project) } @@ -53,13 +53,13 @@ describe Banzai::ReferenceParser::MergeRequestParser do end def merge_request_link(merge_request) - Nokogiri::HTML.fragment(%Q{<a data-merge-request="#{merge_request.id}"></a>}).children[0] + Nokogiri::HTML.fragment(%(<a data-merge-request="#{merge_request.id}"></a>)).children[0] end before do project.add_developer(user) end - it_behaves_like 'no N+1 queries' + it_behaves_like "no N+1 queries" end end diff --git a/spec/lib/banzai/reference_parser/milestone_parser_spec.rb b/spec/lib/banzai/reference_parser/milestone_parser_spec.rb index 751d042ffde..c58a7f24b39 100644 --- a/spec/lib/banzai/reference_parser/milestone_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/milestone_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::MilestoneParser do include ReferenceParserHelpers @@ -9,29 +9,29 @@ describe Banzai::ReferenceParser::MilestoneParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + describe "#nodes_visible_to_user" do + context "when the link has a data-issue attribute" do before do - link['data-milestone'] = milestone.id.to_s + link["data-milestone"] = milestone.id.to_s end it_behaves_like "referenced feature visibility", "issues", "merge_requests" end end - describe '#referenced_by' do - describe 'when the link has a data-milestone attribute' do - context 'using an existing milestone ID' do - it 'returns an Array of milestones' do - link['data-milestone'] = milestone.id.to_s + describe "#referenced_by" do + describe "when the link has a data-milestone attribute" do + context "using an existing milestone ID" do + it "returns an Array of milestones" do + link["data-milestone"] = milestone.id.to_s expect(subject.referenced_by([link])).to eq([milestone]) end end - context 'using a non-existing milestone ID' do - it 'returns an empty Array' do - link['data-milestone'] = '' + context "using a non-existing milestone ID" do + it "returns an empty Array" do + link["data-milestone"] = "" expect(subject.referenced_by([link])).to eq([]) end diff --git a/spec/lib/banzai/reference_parser/project_parser_spec.rb b/spec/lib/banzai/reference_parser/project_parser_spec.rb index e4936aa9e57..1143728ff00 100644 --- a/spec/lib/banzai/reference_parser/project_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/project_parser_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::ProjectParser do include ReferenceParserHelpers @@ -10,37 +10,37 @@ describe Banzai::ReferenceParser::ProjectParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#referenced_by' do - describe 'when the link has a data-project attribute' do - context 'using an existing project ID' do - it 'returns an Array of projects' do - link['data-project'] = project.id.to_s + describe "#referenced_by" do + describe "when the link has a data-project attribute" do + context "using an existing project ID" do + it "returns an Array of projects" do + link["data-project"] = project.id.to_s expect(subject.gather_references([link])).to eq([project]) end end - context 'using a non-existing project ID' do - it 'returns an empty Array' do - link['data-project'] = '' + context "using a non-existing project ID" do + it "returns an empty Array" do + link["data-project"] = "" expect(subject.gather_references([link])).to eq([]) end end - context 'using a private project ID' do - it 'returns an empty Array when unauthorized' do + context "using a private project ID" do + it "returns an empty Array when unauthorized" do private_project = create(:project, :private) - link['data-project'] = private_project.id.to_s + link["data-project"] = private_project.id.to_s expect(subject.gather_references([link])).to eq([]) end - it 'returns an Array when authorized' do + it "returns an Array when authorized" do private_project = create(:project, :private, namespace: user.namespace) - link['data-project'] = private_project.id.to_s + link["data-project"] = private_project.id.to_s expect(subject.gather_references([link])).to eq([private_project]) end diff --git a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb index d410bd4c164..749e5505c33 100644 --- a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::SnippetParser do include ReferenceParserHelpers @@ -14,8 +14,8 @@ describe Banzai::ReferenceParser::SnippetParser do def visible_references(snippet_visibility, user = nil) snippet = create(:project_snippet, snippet_visibility, project: project) - link['data-project'] = project.id.to_s - link['data-snippet'] = snippet.id.to_s + link["data-project"] = project.id.to_s + link["data-snippet"] = snippet.id.to_s subject.nodes_visible_to_user(user, [link]) end @@ -24,191 +24,191 @@ describe Banzai::ReferenceParser::SnippetParser do project.add_user(project_member, :developer) end - describe '#nodes_visible_to_user' do - context 'when a project is public and the snippets feature is enabled for everyone' do + describe "#nodes_visible_to_user" do + context "when a project is public and the snippets feature is enabled for everyone" do before do project.project_feature.update_attribute(:snippets_access_level, ProjectFeature::ENABLED) end - it 'creates a reference for guest for a public snippet' do + it "creates a reference for guest for a public snippet" do expect(visible_references(:public)).to eq([link]) end - it 'creates a reference for a regular user for a public snippet' do + it "creates a reference for a regular user for a public snippet" do expect(visible_references(:public, user)).to eq([link]) end - it 'creates a reference for a regular user for an internal snippet' do + it "creates a reference for a regular user for an internal snippet" do expect(visible_references(:internal, user)).to eq([link]) end - it 'does not create a reference for an external user for an internal snippet' do + it "does not create a reference for an external user for an internal snippet" do expect(visible_references(:internal, external_user)).to be_empty end - it 'creates a reference for a project member for a private snippet' do + it "creates a reference for a project member for a private snippet" do expect(visible_references(:private, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for a private snippet' do + it "does not create a reference for a regular user for a private snippet" do expect(visible_references(:private, user)).to be_empty end end - context 'when a project is public and the snippets feature is enabled for project team members' do + context "when a project is public and the snippets feature is enabled for project team members" do before do project.project_feature.update_attribute(:snippets_access_level, ProjectFeature::PRIVATE) end - it 'creates a reference for a project member for a public snippet' do + it "creates a reference for a project member for a public snippet" do expect(visible_references(:public, project_member)).to eq([link]) end - it 'does not create a reference for guest for a public snippet' do + it "does not create a reference for guest for a public snippet" do expect(visible_references(:public, nil)).to be_empty end - it 'does not create a reference for a regular user for a public snippet' do + it "does not create a reference for a regular user for a public snippet" do expect(visible_references(:public, user)).to be_empty end - it 'creates a reference for a project member for an internal snippet' do + it "creates a reference for a project member for an internal snippet" do expect(visible_references(:internal, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for an internal snippet' do + it "does not create a reference for a regular user for an internal snippet" do expect(visible_references(:internal, user)).to be_empty end - it 'creates a reference for a project member for a private snippet' do + it "creates a reference for a project member for a private snippet" do expect(visible_references(:private, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for a private snippet' do + it "does not create a reference for a regular user for a private snippet" do expect(visible_references(:private, user)).to be_empty end end - context 'when a project is internal and the snippets feature is enabled for everyone' do + context "when a project is internal and the snippets feature is enabled for everyone" do before do project.update_attribute(:visibility, Gitlab::VisibilityLevel::INTERNAL) project.project_feature.update_attribute(:snippets_access_level, ProjectFeature::ENABLED) end - it 'does not create a reference for guest for a public snippet' do + it "does not create a reference for guest for a public snippet" do expect(visible_references(:public)).to be_empty end - it 'does not create a reference for an external user for a public snippet' do + it "does not create a reference for an external user for a public snippet" do expect(visible_references(:public, external_user)).to be_empty end - it 'creates a reference for a regular user for a public snippet' do + it "creates a reference for a regular user for a public snippet" do expect(visible_references(:public, user)).to eq([link]) end - it 'creates a reference for a regular user for an internal snippet' do + it "creates a reference for a regular user for an internal snippet" do expect(visible_references(:internal, user)).to eq([link]) end - it 'does not create a reference for an external user for an internal snippet' do + it "does not create a reference for an external user for an internal snippet" do expect(visible_references(:internal, external_user)).to be_empty end - it 'creates a reference for a project member for a private snippet' do + it "creates a reference for a project member for a private snippet" do expect(visible_references(:private, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for a private snippet' do + it "does not create a reference for a regular user for a private snippet" do expect(visible_references(:private, user)).to be_empty end end - context 'when a project is internal and the snippets feature is enabled for project team members' do + context "when a project is internal and the snippets feature is enabled for project team members" do before do project.update_attribute(:visibility, Gitlab::VisibilityLevel::INTERNAL) project.project_feature.update_attribute(:snippets_access_level, ProjectFeature::PRIVATE) end - it 'creates a reference for a project member for a public snippet' do + it "creates a reference for a project member for a public snippet" do expect(visible_references(:public, project_member)).to eq([link]) end - it 'does not create a reference for guest for a public snippet' do + it "does not create a reference for guest for a public snippet" do expect(visible_references(:public, nil)).to be_empty end - it 'does not create reference for a regular user for a public snippet' do + it "does not create reference for a regular user for a public snippet" do expect(visible_references(:public, user)).to be_empty end - it 'creates a reference for a project member for an internal snippet' do + it "creates a reference for a project member for an internal snippet" do expect(visible_references(:internal, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for an internal snippet' do + it "does not create a reference for a regular user for an internal snippet" do expect(visible_references(:internal, user)).to be_empty end - it 'creates a reference for a project member for a private snippet' do + it "creates a reference for a project member for a private snippet" do expect(visible_references(:private, project_member)).to eq([link]) end - it 'does not create reference for a regular user for a private snippet' do + it "does not create reference for a regular user for a private snippet" do expect(visible_references(:private, user)).to be_empty end end - context 'when a project is private and the snippets feature is enabled for project team members' do + context "when a project is private and the snippets feature is enabled for project team members" do before do project.update_attribute(:visibility, Gitlab::VisibilityLevel::PRIVATE) project.project_feature.update_attribute(:snippets_access_level, ProjectFeature::PRIVATE) end - it 'creates a reference for a project member for a public snippet' do + it "creates a reference for a project member for a public snippet" do expect(visible_references(:public, project_member)).to eq([link]) end - it 'does not create a reference for guest for a public snippet' do + it "does not create a reference for guest for a public snippet" do expect(visible_references(:public, nil)).to be_empty end - it 'does not create a reference for a regular user for a public snippet' do + it "does not create a reference for a regular user for a public snippet" do expect(visible_references(:public, user)).to be_empty end - it 'creates a reference for a project member for an internal snippet' do + it "creates a reference for a project member for an internal snippet" do expect(visible_references(:internal, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for an internal snippet' do + it "does not create a reference for a regular user for an internal snippet" do expect(visible_references(:internal, user)).to be_empty end - it 'creates a reference for a project member for a private snippet' do + it "creates a reference for a project member for a private snippet" do expect(visible_references(:private, project_member)).to eq([link]) end - it 'does not create a reference for a regular user for a private snippet' do + it "does not create a reference for a regular user for a private snippet" do expect(visible_references(:private, user)).to be_empty end end end - describe '#referenced_by' do + describe "#referenced_by" do let(:snippet) { create(:snippet, project: project) } - describe 'when the link has a data-snippet attribute' do - context 'using an existing snippet ID' do - it 'returns an Array of snippets' do - link['data-snippet'] = snippet.id.to_s + describe "when the link has a data-snippet attribute" do + context "using an existing snippet ID" do + it "returns an Array of snippets" do + link["data-snippet"] = snippet.id.to_s expect(subject.referenced_by([link])).to eq([snippet]) end end - context 'using a non-existing snippet ID' do - it 'returns an empty Array' do - link['data-snippet'] = '' + context "using a non-existing snippet ID" do + it "returns an empty Array" do + link["data-snippet"] = "" expect(subject.referenced_by([link])).to be_empty end diff --git a/spec/lib/banzai/reference_parser/user_parser_spec.rb b/spec/lib/banzai/reference_parser/user_parser_spec.rb index 112447f098e..47512c7d793 100644 --- a/spec/lib/banzai/reference_parser/user_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/user_parser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::ReferenceParser::UserParser do include ReferenceParserHelpers @@ -9,57 +9,57 @@ describe Banzai::ReferenceParser::UserParser do subject { described_class.new(Banzai::RenderContext.new(project, user)) } let(:link) { empty_html_link } - describe '#referenced_by' do - context 'when the link has a data-group attribute' do - context 'using an existing group ID' do + describe "#referenced_by" do + context "when the link has a data-group attribute" do + context "using an existing group ID" do before do - link['data-group'] = project.group.id.to_s + link["data-group"] = project.group.id.to_s end - it 'returns the users of the group' do + it "returns the users of the group" do create(:group_member, group: group, user: user) expect(subject.referenced_by([link])).to eq([user]) end - it 'returns an empty Array when the group has no users' do + it "returns an empty Array when the group has no users" do expect(subject.referenced_by([link])).to eq([]) end end - context 'using a non-existing group ID' do - it 'returns an empty Array' do - link['data-group'] = '' + context "using a non-existing group ID" do + it "returns an empty Array" do + link["data-group"] = "" expect(subject.referenced_by([link])).to eq([]) end end end - context 'when the link has a data-user attribute' do - it 'returns an Array of users' do - link['data-user'] = user.id.to_s + context "when the link has a data-user attribute" do + it "returns an Array of users" do + link["data-user"] = user.id.to_s expect(subject.referenced_by([link])).to eq([user]) end - context 'when RequestStore is active', :request_store do + context "when RequestStore is active", :request_store do let(:other_user) { create(:user) } - it 'does not return users from the first call in the second' do - link['data-user'] = user.id.to_s + it "does not return users from the first call in the second" do + link["data-user"] = user.id.to_s expect(subject.referenced_by([link])).to eq([user]) - link['data-user'] = other_user.id.to_s + link["data-user"] = other_user.id.to_s expect(subject.referenced_by([link])).to eq([other_user]) end end end - context 'when the link has a data-project attribute' do - context 'using an existing project ID' do + context "when the link has a data-project attribute" do + context "using an existing project ID" do let(:contributor) { create(:user) } before do @@ -67,8 +67,8 @@ describe Banzai::ReferenceParser::UserParser do project.add_developer(contributor) end - it 'returns the members of a project' do - link['data-project'] = project.id.to_s + it "returns the members of a project" do + link["data-project"] = project.id.to_s # This uses an explicit sort to make sure this spec doesn't randomly # fail when objects are returned in a different order. @@ -78,9 +78,9 @@ describe Banzai::ReferenceParser::UserParser do end end - context 'using a non-existing project ID' do - it 'returns an empty Array' do - link['data-project'] = '' + context "using a non-existing project ID" do + it "returns an empty Array" do + link["data-project"] = "" expect(subject.referenced_by([link])).to eq([]) end @@ -88,14 +88,14 @@ describe Banzai::ReferenceParser::UserParser do end end - describe '#nodes_visible_to_user' do - context 'when the link has a data-group attribute' do - context 'using an existing group ID' do + describe "#nodes_visible_to_user" do + context "when the link has a data-group attribute" do + context "using an existing group ID" do before do - link['data-group'] = group.id.to_s + link["data-group"] = group.id.to_s end - it 'returns the nodes if the user can read the group' do + it "returns the nodes if the user can read the group" do expect(Ability).to receive(:allowed?) .with(user, :read_group, group) .and_return(true) @@ -103,7 +103,7 @@ describe Banzai::ReferenceParser::UserParser do expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end - it 'returns an empty Array if the user can not read the group' do + it "returns an empty Array if the user can not read the group" do expect(Ability).to receive(:allowed?) .with(user, :read_group, group) .and_return(false) @@ -112,10 +112,10 @@ describe Banzai::ReferenceParser::UserParser do end end - context 'when the link does not have a data-group attribute' do - context 'with a data-project attribute' do - it 'returns the nodes if the attribute value equals the current project ID' do - link['data-project'] = project.id.to_s + context "when the link does not have a data-group attribute" do + context "with a data-project attribute" do + it "returns the nodes if the attribute value equals the current project ID" do + link["data-project"] = project.id.to_s # Ensure that we dont call for Ability.allowed? # When project_id in the node is equal to current project ID @@ -124,10 +124,10 @@ describe Banzai::ReferenceParser::UserParser do expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end - it 'returns the nodes if the user can read the project' do + it "returns the nodes if the user can read the project" do other_project = create(:project, :public) - link['data-project'] = other_project.id.to_s + link["data-project"] = other_project.id.to_s expect(Ability).to receive(:allowed?) .with(user, :read_project, other_project) @@ -136,10 +136,10 @@ describe Banzai::ReferenceParser::UserParser do expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end - it 'returns an empty Array if the user can not read the project' do + it "returns an empty Array if the user can not read the project" do other_project = create(:project, :public) - link['data-project'] = other_project.id.to_s + link["data-project"] = other_project.id.to_s expect(Ability).to receive(:allowed?) .with(user, :read_project, other_project) @@ -149,8 +149,8 @@ describe Banzai::ReferenceParser::UserParser do end end - context 'without a data-project attribute' do - it 'returns the nodes' do + context "without a data-project attribute" do + it "returns the nodes" do expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end end @@ -158,55 +158,55 @@ describe Banzai::ReferenceParser::UserParser do end end - describe '#nodes_user_can_reference' do - context 'when the link has a data-author attribute' do - it 'returns the nodes when the user is a member of the project' do + describe "#nodes_user_can_reference" do + context "when the link has a data-author attribute" do + it "returns the nodes when the user is a member of the project" do other_project = create(:project) other_project.add_developer(user) - link['data-project'] = other_project.id.to_s - link['data-author'] = user.id.to_s + link["data-project"] = other_project.id.to_s + link["data-author"] = user.id.to_s expect(subject.nodes_user_can_reference(user, [link])).to eq([link]) end - it 'returns an empty Array when the project could not be found' do - link['data-project'] = '' - link['data-author'] = user.id.to_s + it "returns an empty Array when the project could not be found" do + link["data-project"] = "" + link["data-author"] = user.id.to_s expect(subject.nodes_user_can_reference(user, [link])).to eq([]) end - it 'returns an empty Array when the user could not be found' do + it "returns an empty Array when the user could not be found" do other_project = create(:project) - link['data-project'] = other_project.id.to_s - link['data-author'] = '' + link["data-project"] = other_project.id.to_s + link["data-author"] = "" expect(subject.nodes_user_can_reference(user, [link])).to eq([]) end - it 'returns an empty Array when the user is not a team member' do + it "returns an empty Array when the user is not a team member" do other_project = create(:project) - link['data-project'] = other_project.id.to_s - link['data-author'] = user.id.to_s + link["data-project"] = other_project.id.to_s + link["data-author"] = user.id.to_s expect(subject.nodes_user_can_reference(user, [link])).to eq([]) end - it 'returns the nodes if the project attribute value equals the current project ID' do + it "returns the nodes if the project attribute value equals the current project ID" do other_user = create(:user) - link['data-project'] = project.id.to_s - link['data-author'] = other_user.id.to_s + link["data-project"] = project.id.to_s + link["data-author"] = other_user.id.to_s expect(subject.nodes_user_can_reference(user, [link])).to eq([link]) end end - context 'when the link does not have a data-author attribute' do - it 'returns the nodes' do + context "when the link does not have a data-author attribute" do + it "returns the nodes" do expect(subject.nodes_user_can_reference(user, [link])).to eq([link]) end end diff --git a/spec/lib/banzai/render_context_spec.rb b/spec/lib/banzai/render_context_spec.rb index ad17db11613..667418b6074 100644 --- a/spec/lib/banzai/render_context_spec.rb +++ b/spec/lib/banzai/render_context_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::RenderContext do - let(:document) { Nokogiri::HTML.fragment('<p>hello</p>') } + let(:document) { Nokogiri::HTML.fragment("<p>hello</p>") } - describe '#project_for_node' do - it 'returns the default project if no associated project was found' do - project = instance_double('project') + describe "#project_for_node" do + it "returns the default project if no associated project was found" do + project = instance_double("project") context = described_class.new(project) expect(context.project_for_node(document)).to eq(project) end - it 'returns the associated project if one was associated explicitly' do - project = instance_double('project') - obj = instance_double('object', project: project) + it "returns the associated project if one was associated explicitly" do + project = instance_double("project") + obj = instance_double("object", project: project) context = described_class.new context.associate_document(document, obj) @@ -23,9 +23,9 @@ describe Banzai::RenderContext do expect(context.project_for_node(document)).to eq(project) end - it 'returns the project associated with a DocumentFragment when using a node' do - project = instance_double('project') - obj = instance_double('object', project: project) + it "returns the project associated with a DocumentFragment when using a node" do + project = instance_double("project") + obj = instance_double("object", project: project) context = described_class.new node = document.children.first diff --git a/spec/lib/banzai/renderer_spec.rb b/spec/lib/banzai/renderer_spec.rb index 650cecfc778..e15ed417393 100644 --- a/spec/lib/banzai/renderer_spec.rb +++ b/spec/lib/banzai/renderer_spec.rb @@ -1,56 +1,56 @@ -require 'spec_helper' +require "spec_helper" describe Banzai::Renderer do def fake_object(fresh:) - object = double('object') + object = double("object") allow(object).to receive(:respond_to?).with(:cached_markdown_fields).and_return(true) allow(object).to receive(:cached_html_up_to_date?).with(:field).and_return(fresh) - allow(object).to receive(:cached_html_for).with(:field).and_return('field_html') + allow(object).to receive(:cached_html_for).with(:field).and_return("field_html") object end - describe '#render_field' do + describe "#render_field" do let(:renderer) { described_class } - context 'without cache' do + context "without cache" do let(:commit) { create(:project, :repository).commit } - it 'returns cacheless render field' do + it "returns cacheless render field" do expect(renderer).to receive(:cacheless_render_field).with(commit, :title, {}) renderer.render_field(commit, :title) end end - context 'with cache' do + context "with cache" do subject { renderer.render_field(object, :field) } - context 'with a stale cache' do + context "with a stale cache" do let(:object) { fake_object(fresh: false) } - it 'caches and returns the result' do + it "caches and returns the result" do expect(object).to receive(:refresh_markdown_cache!) - is_expected.to eq('field_html') + is_expected.to eq("field_html") end it "skips database caching on a GitLab read-only instance" do allow(Gitlab::Database).to receive(:read_only?).and_return(true) expect(object).to receive(:refresh_markdown_cache!) - is_expected.to eq('field_html') + is_expected.to eq("field_html") end end - context 'with an up-to-date cache' do + context "with an up-to-date cache" do let(:object) { fake_object(fresh: true) } - it 'uses the cache' do + it "uses the cache" do expect(object).to receive(:refresh_markdown_cache!).never - is_expected.to eq('field_html') + is_expected.to eq("field_html") end end end diff --git a/spec/lib/banzai/suggestions_parser_spec.rb b/spec/lib/banzai/suggestions_parser_spec.rb index 79658d710ce..5d36d02f08a 100644 --- a/spec/lib/banzai/suggestions_parser_spec.rb +++ b/spec/lib/banzai/suggestions_parser_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe Banzai::SuggestionsParser do - describe '.parse' do - it 'returns a list of suggestion contents' do + describe ".parse" do + it "returns a list of suggestion contents" do markdown = <<-MARKDOWN.strip_heredoc ```suggestion foo @@ -26,7 +26,7 @@ describe Banzai::SuggestionsParser do MARKDOWN expect(described_class.parse(markdown)).to eq([" foo\n bar", - " xpto\n baz"]) + " xpto\n baz",]) end end end |