diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/ci/ansi2html_spec.rb | 134 | ||||
-rw-r--r-- | spec/lib/ci/charts_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 316 | ||||
-rw-r--r-- | spec/lib/extracts_path_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/backend/grack_auth_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/email/receiver_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/incoming_email_spec.rb | 61 | ||||
-rw-r--r-- | spec/lib/gitlab/ldap/auth_hash_spec.rb | 65 | ||||
-rw-r--r-- | spec/lib/gitlab/ldap/user_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/markdown/relative_link_filter_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/o_auth/auth_hash_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/o_auth/user_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/reply_by_email_spec.rb | 86 |
14 files changed, 646 insertions, 105 deletions
diff --git a/spec/lib/ci/ansi2html_spec.rb b/spec/lib/ci/ansi2html_spec.rb new file mode 100644 index 00000000000..75c023bbc43 --- /dev/null +++ b/spec/lib/ci/ansi2html_spec.rb @@ -0,0 +1,134 @@ +require 'spec_helper' + +describe Ci::Ansi2html do + subject { Ci::Ansi2html } + + it "prints non-ansi as-is" do + expect(subject.convert("Hello")).to eq('Hello') + end + + it "strips non-color-changing controll sequences" do + expect(subject.convert("Hello \e[2Kworld")).to eq('Hello world') + end + + it "prints simply red" do + expect(subject.convert("\e[31mHello\e[0m")).to eq('<span class="term-fg-red">Hello</span>') + end + + it "prints simply red without trailing reset" do + expect(subject.convert("\e[31mHello")).to eq('<span class="term-fg-red">Hello</span>') + end + + it "prints simply yellow" do + expect(subject.convert("\e[33mHello\e[0m")).to eq('<span class="term-fg-yellow">Hello</span>') + end + + it "prints default on blue" do + expect(subject.convert("\e[39;44mHello")).to eq('<span class="term-bg-blue">Hello</span>') + end + + it "prints red on blue" do + expect(subject.convert("\e[31;44mHello")).to eq('<span class="term-fg-red term-bg-blue">Hello</span>') + end + + it "resets colors after red on blue" do + expect(subject.convert("\e[31;44mHello\e[0m world")).to eq('<span class="term-fg-red term-bg-blue">Hello</span> world') + end + + it "performs color change from red/blue to yellow/blue" do + expect(subject.convert("\e[31;44mHello \e[33mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-blue">world</span>') + end + + it "performs color change from red/blue to yellow/green" do + expect(subject.convert("\e[31;44mHello \e[33;42mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-green">world</span>') + end + + it "performs color change from red/blue to reset to yellow/green" do + expect(subject.convert("\e[31;44mHello\e[0m \e[33;42mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello</span> <span class="term-fg-yellow term-bg-green">world</span>') + end + + it "ignores unsupported codes" do + expect(subject.convert("\e[51mHello\e[0m")).to eq('Hello') + end + + it "prints light red" do + expect(subject.convert("\e[91mHello\e[0m")).to eq('<span class="term-fg-l-red">Hello</span>') + end + + it "prints default on light red" do + expect(subject.convert("\e[101mHello\e[0m")).to eq('<span class="term-bg-l-red">Hello</span>') + end + + it "performs color change from red/blue to default/blue" do + expect(subject.convert("\e[31;44mHello \e[39mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>') + end + + it "performs color change from light red/blue to default/blue" do + expect(subject.convert("\e[91;44mHello \e[39mworld")).to eq('<span class="term-fg-l-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>') + end + + it "prints bold text" do + expect(subject.convert("\e[1mHello")).to eq('<span class="term-bold">Hello</span>') + end + + it "resets bold text" do + expect(subject.convert("\e[1mHello\e[21m world")).to eq('<span class="term-bold">Hello</span> world') + expect(subject.convert("\e[1mHello\e[22m world")).to eq('<span class="term-bold">Hello</span> world') + end + + it "prints italic text" do + expect(subject.convert("\e[3mHello")).to eq('<span class="term-italic">Hello</span>') + end + + it "resets italic text" do + expect(subject.convert("\e[3mHello\e[23m world")).to eq('<span class="term-italic">Hello</span> world') + end + + it "prints underlined text" do + expect(subject.convert("\e[4mHello")).to eq('<span class="term-underline">Hello</span>') + end + + it "resets underlined text" do + expect(subject.convert("\e[4mHello\e[24m world")).to eq('<span class="term-underline">Hello</span> world') + end + + it "prints concealed text" do + expect(subject.convert("\e[8mHello")).to eq('<span class="term-conceal">Hello</span>') + end + + it "resets concealed text" do + expect(subject.convert("\e[8mHello\e[28m world")).to eq('<span class="term-conceal">Hello</span> world') + end + + it "prints crossed-out text" do + expect(subject.convert("\e[9mHello")).to eq('<span class="term-cross">Hello</span>') + end + + it "resets crossed-out text" do + expect(subject.convert("\e[9mHello\e[29m world")).to eq('<span class="term-cross">Hello</span> world') + end + + it "can print 256 xterm fg colors" do + expect(subject.convert("\e[38;5;16mHello")).to eq('<span class="xterm-fg-16">Hello</span>') + end + + it "can print 256 xterm fg colors on normal magenta background" do + expect(subject.convert("\e[38;5;16;45mHello")).to eq('<span class="xterm-fg-16 term-bg-magenta">Hello</span>') + end + + it "can print 256 xterm bg colors" do + expect(subject.convert("\e[48;5;240mHello")).to eq('<span class="xterm-bg-240">Hello</span>') + end + + it "can print 256 xterm bg colors on normal magenta foreground" do + expect(subject.convert("\e[48;5;16;35mHello")).to eq('<span class="term-fg-magenta xterm-bg-16">Hello</span>') + end + + it "prints bold colored text vividly" do + expect(subject.convert("\e[1;31mHello\e[0m")).to eq('<span class="term-fg-l-red term-bold">Hello</span>') + end + + it "prints bold light colored text correctly" do + expect(subject.convert("\e[1;91mHello\e[0m")).to eq('<span class="term-fg-l-red term-bold">Hello</span>') + end +end diff --git a/spec/lib/ci/charts_spec.rb b/spec/lib/ci/charts_spec.rb new file mode 100644 index 00000000000..83e2ad220b8 --- /dev/null +++ b/spec/lib/ci/charts_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe "Charts" do + + context "build_times" do + before do + @commit = FactoryGirl.create(:ci_commit) + FactoryGirl.create(:ci_build, commit: @commit) + end + + it 'should return build times in minutes' do + chart = Ci::Charts::BuildTime.new(@commit.project) + expect(chart.build_times).to eq([2]) + end + end +end diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb new file mode 100644 index 00000000000..aba957da488 --- /dev/null +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -0,0 +1,316 @@ +require 'spec_helper' + +module Ci + describe GitlabCiYamlProcessor do + + describe "#builds_for_ref" do + let(:type) { 'test' } + + it "returns builds if no branch specified" do + config = YAML.dump({ + before_script: ["pwd"], + rspec: { script: "rspec" } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1) + expect(config_processor.builds_for_stage_and_ref(type, "master").first).to eq({ + stage: "test", + stage_idx: 1, + except: nil, + name: :rspec, + only: nil, + commands: "pwd\nrspec", + tag_list: [], + options: {}, + allow_failure: false + }) + end + + it "does not return builds if only has another branch" do + config = YAML.dump({ + before_script: ["pwd"], + rspec: { script: "rspec", only: ["deploy"] } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0) + end + + it "does not return builds if only has regexp with another branch" do + config = YAML.dump({ + before_script: ["pwd"], + rspec: { script: "rspec", only: ["/^deploy$/"] } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0) + end + + it "returns builds if only has specified this branch" do + config = YAML.dump({ + before_script: ["pwd"], + rspec: { script: "rspec", only: ["master"] } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1) + end + + it "does not build tags" do + config = YAML.dump({ + before_script: ["pwd"], + rspec: { script: "rspec", except: ["tags"] } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref(type, "0-1", true).size).to eq(0) + end + + it "returns builds if only has a list of branches including specified" do + config = YAML.dump({ + before_script: ["pwd"], + rspec: { script: "rspec", type: type, only: ["master", "deploy"] } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1) + end + + it "returns build only for specified type" do + + config = YAML.dump({ + before_script: ["pwd"], + build: { script: "build", type: "build", only: ["master", "deploy"] }, + rspec: { script: "rspec", type: type, only: ["master", "deploy"] }, + staging: { script: "deploy", type: "deploy", only: ["master", "deploy"] }, + production: { script: "deploy", type: "deploy", only: ["master", "deploy"] }, + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref("production", "deploy").size).to eq(0) + expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1) + expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq(2) + end + end + + describe "Image and service handling" do + it "returns image and service when defined" do + config = YAML.dump({ + image: "ruby:2.1", + services: ["mysql"], + before_script: ["pwd"], + rspec: { script: "rspec" } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1) + expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({ + except: nil, + stage: "test", + stage_idx: 1, + name: :rspec, + only: nil, + commands: "pwd\nrspec", + tag_list: [], + options: { + image: "ruby:2.1", + services: ["mysql"] + }, + allow_failure: false + }) + end + + it "returns image and service when overridden for job" do + config = YAML.dump({ + image: "ruby:2.1", + services: ["mysql"], + before_script: ["pwd"], + rspec: { image: "ruby:2.5", services: ["postgresql"], script: "rspec" } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + + expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1) + expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({ + except: nil, + stage: "test", + stage_idx: 1, + name: :rspec, + only: nil, + commands: "pwd\nrspec", + tag_list: [], + options: { + image: "ruby:2.5", + services: ["postgresql"] + }, + allow_failure: false + }) + end + end + + describe "Variables" do + it "returns variables when defined" do + variables = { + var1: "value1", + var2: "value2", + } + config = YAML.dump({ + variables: variables, + before_script: ["pwd"], + rspec: { script: "rspec" } + }) + + config_processor = GitlabCiYamlProcessor.new(config) + expect(config_processor.variables).to eq(variables) + end + end + + describe "Error handling" do + it "indicates that object is invalid" do + expect{GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(GitlabCiYamlProcessor::ValidationError) + end + + it "returns errors if tags parameter is invalid" do + config = YAML.dump({ rspec: { script: "test", tags: "mysql" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings") + end + + it "returns errors if before_script parameter is invalid" do + config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings") + end + + it "returns errors if image parameter is invalid" do + config = YAML.dump({ image: ["test"], rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string") + end + + it "returns errors if job image parameter is invalid" do + config = YAML.dump({ rspec: { script: "test", image: ["test"] } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string") + end + + it "returns errors if services parameter is not an array" do + config = YAML.dump({ services: "test", rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings") + end + + it "returns errors if services parameter is not an array of strings" do + config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings") + end + + it "returns errors if job services parameter is not an array" do + config = YAML.dump({ rspec: { script: "test", services: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings") + end + + it "returns errors if job services parameter is not an array of strings" do + config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings") + end + + it "returns errors if there are unknown parameters" do + config = YAML.dump({ extra: "bundle update" }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra") + end + + it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do + config = YAML.dump({ extra: { services: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra") + end + + it "returns errors if there is no any jobs defined" do + config = YAML.dump({ before_script: ["bundle update"] }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job") + end + + it "returns errors if job allow_failure parameter is not an boolean" do + config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean") + end + + it "returns errors if job stage is not a string" do + config = YAML.dump({ rspec: { script: "test", type: 1, allow_failure: "string" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") + end + + it "returns errors if job stage is not a pre-defined stage" do + config = YAML.dump({ rspec: { script: "test", type: "acceptance", allow_failure: "string" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") + end + + it "returns errors if job stage is not a defined stage" do + config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance", allow_failure: "string" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test") + end + + it "returns errors if stages is not an array" do + config = YAML.dump({ types: "test", rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings") + end + + it "returns errors if stages is not an array of strings" do + config = YAML.dump({ types: [true, "test"], rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings") + end + + it "returns errors if variables is not a map" do + config = YAML.dump({ variables: "test", rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings") + end + + it "returns errors if variables is not a map of key-valued strings" do + config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } }) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings") + end + end + end +end diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index 9c115bbfc6a..48bc60eed16 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe ExtractsPath do include ExtractsPath include RepoHelpers - include Rails.application.routes.url_helpers + include Gitlab::Application.routes.url_helpers let(:project) { double('project') } diff --git a/spec/lib/gitlab/backend/grack_auth_spec.rb b/spec/lib/gitlab/backend/grack_auth_spec.rb index d9676445908..37c527221a0 100644 --- a/spec/lib/gitlab/backend/grack_auth_spec.rb +++ b/spec/lib/gitlab/backend/grack_auth_spec.rb @@ -151,14 +151,14 @@ describe Grack::Auth do end it "repeated attempts followed by successful attempt" do - for n in 0..maxretry do + maxretry.times.each do expect(attempt_login(false)).to eq(401) end expect(attempt_login(true)).to eq(200) expect(Rack::Attack::Allow2Ban.banned?(ip)).to be_falsey - for n in 0..maxretry do + maxretry.times.each do expect(attempt_login(false)).to eq(401) end end @@ -175,12 +175,14 @@ describe Grack::Auth do context "when a gitlab ci token is provided" do let(:token) { "123" } + let(:gitlab_ci_project) { FactoryGirl.create :ci_project, token: token } before do + project.gitlab_ci_project = gitlab_ci_project + project.save + gitlab_ci_service = project.build_gitlab_ci_service gitlab_ci_service.active = true - gitlab_ci_service.token = token - gitlab_ci_service.project_url = "http://google.com" gitlab_ci_service.save env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Basic.encode_credentials("gitlab-ci-token", token) diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 1cc80f35f98..e470b7cd5f5 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" describe Gitlab::Email::Receiver do before do - stub_reply_by_email_setting(enabled: true, address: "reply+%{reply_key}@appmail.adventuretime.ooo") + stub_incoming_email_setting(enabled: true, address: "reply+%{key}@appmail.adventuretime.ooo") end let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } diff --git a/spec/lib/gitlab/incoming_email_spec.rb b/spec/lib/gitlab/incoming_email_spec.rb new file mode 100644 index 00000000000..5fdb9c723b1 --- /dev/null +++ b/spec/lib/gitlab/incoming_email_spec.rb @@ -0,0 +1,61 @@ +require "spec_helper" + +describe Gitlab::IncomingEmail do + describe "self.enabled?" do + context "when reply by email is enabled" do + before do + stub_incoming_email_setting(enabled: true) + end + + context "when the address is valid" do + before do + stub_incoming_email_setting(address: "replies+%{key}@example.com") + end + + it "returns true" do + expect(described_class.enabled?).to be_truthy + end + end + + context "when the address is invalid" do + before do + stub_incoming_email_setting(address: "replies@example.com") + end + + it "returns false" do + expect(described_class.enabled?).to be_falsey + end + end + end + + context "when reply by email is disabled" do + before do + stub_incoming_email_setting(enabled: false) + end + + it "returns false" do + expect(described_class.enabled?).to be_falsey + end + end + end + + context "self.reply_address" do + before do + stub_incoming_email_setting(address: "replies+%{key}@example.com") + end + + it "returns the address with an interpolated reply key" do + expect(described_class.reply_address("key")).to eq("replies+key@example.com") + end + end + + context "self.key_from_address" do + before do + stub_incoming_email_setting(address: "replies+%{key}@example.com") + end + + it "returns reply key" do + expect(described_class.key_from_address("replies+key@example.com")).to eq("key") + end + end +end diff --git a/spec/lib/gitlab/ldap/auth_hash_spec.rb b/spec/lib/gitlab/ldap/auth_hash_spec.rb new file mode 100644 index 00000000000..7d8268536a4 --- /dev/null +++ b/spec/lib/gitlab/ldap/auth_hash_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe Gitlab::LDAP::AuthHash do + let(:auth_hash) do + Gitlab::LDAP::AuthHash.new( + OmniAuth::AuthHash.new( + uid: '123456', + provider: 'ldapmain', + info: info, + extra: { + raw_info: raw_info + } + ) + ) + end + + let(:info) do + { + name: 'Smith, J.', + email: 'johnsmith@example.com', + nickname: '123456' + } + end + + let(:raw_info) do + { + uid: ['123456'], + email: ['johnsmith@example.com'], + cn: ['Smith, J.'], + fullName: ['John Smith'] + } + end + + context "without overridden attributes" do + + it "has the correct username" do + expect(auth_hash.username).to eq("123456") + end + + it "has the correct name" do + expect(auth_hash.name).to eq("Smith, J.") + end + end + + context "with overridden attributes" do + let(:attributes) do + { + 'username' => ['mail', 'email'], + 'name' => 'fullName' + } + end + + before do + allow_any_instance_of(Gitlab::LDAP::Config).to receive(:attributes).and_return(attributes) + end + + it "has the correct username" do + expect(auth_hash.username).to eq("johnsmith@example.com") + end + + it "has the correct name" do + expect(auth_hash.name).to eq("John Smith") + end + end +end diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb index 84d9fb54b61..fd2e5f6d0e1 100644 --- a/spec/lib/gitlab/ldap/user_spec.rb +++ b/spec/lib/gitlab/ldap/user_spec.rb @@ -11,7 +11,7 @@ describe Gitlab::LDAP::User do } end let(:auth_hash) do - double(uid: 'my-uid', provider: 'ldapmain', info: double(info)) + OmniAuth::AuthHash.new(uid: 'my-uid', provider: 'ldapmain', info: info) end describe :changed? do diff --git a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb index 7f4d67e403f..027336ceb73 100644 --- a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb +++ b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb @@ -4,14 +4,16 @@ require 'spec_helper' module Gitlab::Markdown describe RelativeLinkFilter do - def filter(doc) - described_class.call(doc, { + def filter(doc, contexts = {}) + contexts.reverse_merge!({ commit: project.commit, project: project, project_wiki: project_wiki, ref: ref, requested_path: requested_path }) + + described_class.call(doc, contexts) end def image(path) @@ -75,6 +77,22 @@ module Gitlab::Markdown 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') + + 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') + + 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 an anchor' do doc = filter(link('README.md#section')) expect(doc.at_css('a')['href']). @@ -108,8 +126,8 @@ module Gitlab::Markdown escaped = Addressable::URI.escape(path) # Stub these methods so the file doesn't actually need to be in the repo - allow_any_instance_of(described_class).to receive(:file_exists?). - and_return(true) + allow_any_instance_of(described_class). + to receive(:file_exists?).and_return(true) allow_any_instance_of(described_class). to receive(:image?).with(path).and_return(true) diff --git a/spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb b/spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb new file mode 100644 index 00000000000..6a490673728 --- /dev/null +++ b/spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +module Gitlab::Markdown + describe SyntaxHighlightFilter do + include FilterSpecHelper + + it 'highlights valid code blocks' do + result = filter('<pre><code>def fun end</code>') + expect(result.to_html).to eq("<pre class=\"code highlight js-syntax-highlight plaintext\"><code>def fun end</code></pre>\n") + end + + it 'passes through invalid code blocks' do + allow_any_instance_of(SyntaxHighlightFilter).to receive(:block_code).and_raise(StandardError) + + result = filter('<pre><code>This is a test</code></pre>') + expect(result.to_html).to eq('<pre>This is a test</pre>') + end + end +end diff --git a/spec/lib/gitlab/o_auth/auth_hash_spec.rb b/spec/lib/gitlab/o_auth/auth_hash_spec.rb index e4a6cd954cc..5632f2306ec 100644 --- a/spec/lib/gitlab/o_auth/auth_hash_spec.rb +++ b/spec/lib/gitlab/o_auth/auth_hash_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe Gitlab::OAuth::AuthHash do let(:auth_hash) do Gitlab::OAuth::AuthHash.new( - double({ + OmniAuth::AuthHash.new( provider: provider_ascii, uid: uid_ascii, - info: double(info_hash) - }) + info: info_hash + ) ) end diff --git a/spec/lib/gitlab/o_auth/user_spec.rb b/spec/lib/gitlab/o_auth/user_spec.rb index c6cca98a037..fd3ab1fb7c8 100644 --- a/spec/lib/gitlab/o_auth/user_spec.rb +++ b/spec/lib/gitlab/o_auth/user_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::OAuth::User do let(:gl_user) { oauth_user.gl_user } let(:uid) { 'my-uid' } let(:provider) { 'my-provider' } - let(:auth_hash) { double(uid: uid, provider: provider, info: double(info_hash)) } + let(:auth_hash) { OmniAuth::AuthHash.new(uid: uid, provider: provider, info: info_hash) } let(:info_hash) do { nickname: '-john+gitlab-ETC%.git@gmail.com', @@ -19,10 +19,6 @@ describe Gitlab::OAuth::User do let!(:existing_user) { create(:omniauth_user, extern_uid: 'my-uid', provider: 'my-provider') } it "finds an existing user based on uid and provider (facebook)" do - # FIXME (rspeicher): It's unlikely that this test is actually doing anything - # `auth` is never used and removing it entirely doesn't break the test, so - # what's it doing? - auth = double(info: double(name: 'John'), uid: 'my-uid', provider: 'my-provider') expect( oauth_user.persisted? ).to be_truthy end diff --git a/spec/lib/gitlab/reply_by_email_spec.rb b/spec/lib/gitlab/reply_by_email_spec.rb deleted file mode 100644 index a678c7e1a76..00000000000 --- a/spec/lib/gitlab/reply_by_email_spec.rb +++ /dev/null @@ -1,86 +0,0 @@ -require "spec_helper" - -describe Gitlab::ReplyByEmail do - describe "self.enabled?" do - context "when reply by email is enabled" do - before do - stub_reply_by_email_setting(enabled: true) - end - - context "when the address is valid" do - before do - stub_reply_by_email_setting(address: "replies+%{reply_key}@example.com") - end - - it "returns true" do - expect(described_class.enabled?).to be_truthy - end - end - - context "when the address is invalid" do - before do - stub_reply_by_email_setting(address: "replies@example.com") - end - - it "returns false" do - expect(described_class.enabled?).to be_falsey - end - end - end - - context "when reply by email is disabled" do - before do - stub_reply_by_email_setting(enabled: false) - end - - it "returns false" do - expect(described_class.enabled?).to be_falsey - end - end - end - - describe "self.reply_key" do - context "when enabled" do - before do - allow(described_class).to receive(:enabled?).and_return(true) - end - - it "returns a random hex" do - key = described_class.reply_key - key2 = described_class.reply_key - - expect(key).not_to eq(key2) - end - end - - context "when disabled" do - before do - allow(described_class).to receive(:enabled?).and_return(false) - end - - it "returns nil" do - expect(described_class.reply_key).to be_nil - end - end - end - - context "self.reply_address" do - before do - stub_reply_by_email_setting(address: "replies+%{reply_key}@example.com") - end - - it "returns the address with an interpolated reply key" do - expect(described_class.reply_address("key")).to eq("replies+key@example.com") - end - end - - context "self.reply_key_from_address" do - before do - stub_reply_by_email_setting(address: "replies+%{reply_key}@example.com") - end - - it "returns reply key" do - expect(described_class.reply_key_from_address("replies+key@example.com")).to eq("key") - end - end -end |