From 9ccda901271eb755cf37f37831f6beef83ed7037 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 30 May 2017 15:25:05 +0200 Subject: Add Prometheus client tests --- spec/lib/gitlab/prometheus_client_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus_client_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 2d8bd2f6b97..46eaadae206 100644 --- a/spec/lib/gitlab/prometheus_client_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -119,6 +119,36 @@ describe Gitlab::PrometheusClient, lib: true do end end + describe '#series' do + let(:query_url) { prometheus_series_url('series_name', 'other_service') } + + around do |example| + Timecop.freeze { example.run } + end + + it 'calls endpoint and returns list of series' do + req_stub = stub_prometheus_request(query_url, body: prometheus_series('series_name')) + expected = prometheus_series('series_name').deep_stringify_keys['data'] + + expect(subject.series('series_name', 'other_service')).to eq(expected) + + expect(req_stub).to have_been_requested + end + end + + describe '#label_values' do + let(:query_url) { prometheus_label_values_url('__name__') } + + it 'calls endpoint and returns label values' do + req_stub = stub_prometheus_request(query_url, body: prometheus_label_values) + expected = prometheus_label_values.deep_stringify_keys['data'] + + expect(subject.label_values('__name__')).to eq(expected) + + expect(req_stub).to have_been_requested + end + end + describe '#query_range' do let(:prometheus_query) { prometheus_memory_query('env-slug') } let(:query_url) { prometheus_query_range_url(prometheus_query) } -- cgit v1.2.1 From e74896df0c7d0d88958a3d35b3144361cfdd0594 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Wed, 31 May 2017 19:36:07 +0200 Subject: Matched Metrics tests --- .../queries/matched_metrics_query_spec.rb | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb new file mode 100644 index 00000000000..0aee9d37889 --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do + let(:environment) { create(:environment, slug: 'environment-slug') } + let(:deployment) { create(:deployment, environment: environment) } + + let(:client) { double('prometheus_client') } + subject { described_class.new(client) } + + around do |example| + time_without_subsecond_values = Time.local(2008, 9, 1, 12, 0, 0) + Timecop.freeze(time_without_subsecond_values) { example.run } + end + + let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } + let(:metric_class) { Gitlab::Prometheus::Metric } + + let(:simple_metrics) do + [ + metric_class.new('title', ['metrica', 'metricb'], '1', 'y_label', [{ :query_range => 'avg' }]) + ] + end + + let(:simple_metric_group) do + metric_group_class.new('name', 1, simple_metrics) + end + + let(:xx) do + [{ + '__name__': 'metrica', + 'environment': 'mattermost' + }, + { + '__name__': 'metricb', + 'environment': 'mattermost' + }] + end + + before do + allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) + + allow(client).to receive(:label_values).and_return(['metrica', 'metricb']) + allow(client).to receive(:series).and_return(xx) + end + + it "something something" do + + expect(subject.query).to eq("asf") + end +end -- cgit v1.2.1 From 6a70509a2763717e592c603249855bfb43519d2f Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Fri, 2 Jun 2017 23:32:59 +0200 Subject: Towards Reviewable prometheus --- .../queries/matched_metrics_query_spec.rb | 125 ++++++++++++++++----- 1 file changed, 94 insertions(+), 31 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb index 0aee9d37889..d46de56f520 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -1,50 +1,113 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do - let(:environment) { create(:environment, slug: 'environment-slug') } - let(:deployment) { create(:deployment, environment: environment) } + include Prometheus::MatchedMetricsQueryHelper + + let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } + let(:metric_class) { Gitlab::Prometheus::Metric } let(:client) { double('prometheus_client') } + subject { described_class.new(client) } - around do |example| - time_without_subsecond_values = Time.local(2008, 9, 1, 12, 0, 0) - Timecop.freeze(time_without_subsecond_values) { example.run } - end + context 'with one group where two metrics are found' do + before do + allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) + allow(client).to receive(:label_values).and_return(metric_names) + end - let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } - let(:metric_class) { Gitlab::Prometheus::Metric } + context 'both metrics in the group pass requirements' do + before do + allow(client).to receive(:series).and_return(series_info_with_environment) + end - let(:simple_metrics) do - [ - metric_class.new('title', ['metrica', 'metricb'], '1', 'y_label', [{ :query_range => 'avg' }]) - ] - end + it 'responds with both metrics as actve' do + expect(subject.query).to eq([{ group: 'name', priority: 1, active_metrics: 2, metrics_missing_requirements: 0 }]) + end + end - let(:simple_metric_group) do - metric_group_class.new('name', 1, simple_metrics) - end + context 'none of the metrics pass requirements' do + before do + allow(client).to receive(:series).and_return(series_info_without_environment) + end - let(:xx) do - [{ - '__name__': 'metrica', - 'environment': 'mattermost' - }, - { - '__name__': 'metricb', - 'environment': 'mattermost' - }] + it 'responds with both metrics missing requirements' do + expect(subject.query).to eq([{ group: 'name', priority: 1, active_metrics: 0, metrics_missing_requirements: 2 }]) + end + end + + context 'no series information found about the metrics' do + before do + allow(client).to receive(:series).and_return(empty_series_info) + end + + it 'responds with both metrics missing requirements' do + expect(subject.query).to eq([{ group: 'name', priority: 1, active_metrics: 0, metrics_missing_requirements: 2 }]) + end + end + + context 'one of the series info was not found' do + before do + allow(client).to receive(:series).and_return(partialy_empty_series_info) + end + it 'responds with one active and one missing metric' do + expect(subject.query).to eq([{ group: 'name', priority: 1, active_metrics: 1, metrics_missing_requirements: 1 }]) + end + end end - before do - allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) + context 'with one group where only one metric is found' do + before do + allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) + allow(client).to receive(:label_values).and_return('metric_a') + end + + context 'both metrics in the group pass requirements' do + before do + allow(client).to receive(:series).and_return(series_info_with_environment) + end + + it 'responds with one metrics as active and no missing requiremens' do + expect(subject.query).to eq([{ group: 'name', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }]) + end + end - allow(client).to receive(:label_values).and_return(['metrica', 'metricb']) - allow(client).to receive(:series).and_return(xx) + context 'no metrics in group pass requirements' do + before do + allow(client).to receive(:series).and_return(series_info_without_environment) + end + + it 'responds with one metrics as active and no missing requiremens' do + expect(subject.query).to eq([{ group: 'name', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }]) + end + end end - it "something something" do + context 'with two groups where only one metric is found' do + before do + allow(metric_group_class).to receive(:all).and_return([simple_metric_group, + simple_metric_group('nameb', simple_metrics('metric_c'))]) + allow(client).to receive(:label_values).and_return('metric_c') + end + + context 'both metrics in the group pass requirements' do + before do + allow(client).to receive(:series).and_return(series_info_with_environment('metric_c')) + end + + it 'responds with one metrics as active and no missing requiremens' do + expect(subject.query).to eq([{ group: 'nameb', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }]) + end + end + + context 'no metris in group pass requirements' do + before do + allow(client).to receive(:series).and_return(series_info_without_environment) + end - expect(subject.query).to eq("asf") + it 'responds with one metrics as active and no missing requiremens' do + expect(subject.query).to eq([{ group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }]) + end + end end end -- cgit v1.2.1 From ae5268ce8cc533be4086a11d9d89fa726136d59d Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 11:32:56 +0200 Subject: Additional Metrics tests --- .../queries/additional_metrics_query_spec.rb | 49 ++++++++++++++++++++++ .../queries/matched_metrics_query_spec.rb | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb new file mode 100644 index 00000000000..c7e2dbc12ec --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do + include Prometheus::AdditionalMetricsQueryHelper + + let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } + let(:metric_class) { Gitlab::Prometheus::Metric } + + let(:client) { double('prometheus_client') } + let(:environment) { create(:environment, slug: 'environment-slug') } + + subject(:query_result) { described_class.new(client).query(environment.id) } + + + context 'with one group where two metrics is found' do + before do + allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) + allow(client).to receive(:label_values).and_return(metric_names) + end + + context 'some querie return results' do + before do + expect(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + expect(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) + expect(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) + end + + it 'return results only for queries with results' do + puts query_result + expected = { + group: 'name', + priority: 1, + metrics: + [ + { + title: 'title', weight: nil, y_label: 'Values', queries: + [ + { query_range: 'query_range_a', result: query_range_result }, + { query_range: 'query_range_b', label: 'label', unit: 'unit', result: query_range_result } + ] + } + ] + } + + expect(query_result).to eq([expected]) + end + end + end +end diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb index d46de56f520..390fff568cc 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do subject { described_class.new(client) } - context 'with one group where two metrics are found' do + context 'with one group where two metrics is found' do before do allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) allow(client).to receive(:label_values).and_return(metric_names) -- cgit v1.2.1 From eaaad702deab2ff73cc204d55056745bf34c703e Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 13:33:11 +0200 Subject: Additional metrics test using multiple groups --- .../queries/additional_metrics_query_spec.rb | 96 +++++++++++++++++++--- 1 file changed, 84 insertions(+), 12 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb index c7e2dbc12ec..617028cde37 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do include Prometheus::AdditionalMetricsQueryHelper + include Prometheus::MetricBuilders let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } let(:metric_class) { Gitlab::Prometheus::Metric } @@ -11,6 +12,9 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do subject(:query_result) { described_class.new(client).query(environment.id) } + around do |example| + Timecop.freeze { example.run } + end context 'with one group where two metrics is found' do before do @@ -18,31 +22,99 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do allow(client).to receive(:label_values).and_return(metric_names) end - context 'some querie return results' do + context 'some queries return results' do before do expect(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) expect(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) expect(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) end + it 'return results only for queries with results' do + expected = [ + { + group: 'name', + priority: 1, + metrics: [ + { + title: 'title', weight: nil, y_label: 'Values', queries: [ + { query_range: 'query_range_a', result: query_range_result }, + { query_range: 'query_range_b', label: 'label', unit: 'unit', result: query_range_result } + ] + } + ] + } + ] + + expect(query_result).to eq(expected) + end + end + end + + context 'with two groups with one metric each' do + let(:metrics) { [simple_metric(queries: [simple_query])] } + before do + allow(metric_group_class).to receive(:all).and_return( + [ + simple_metric_group('group_a', [simple_metric(queries: [simple_query])]), + simple_metric_group('group_b', [simple_metric(title: 'title_b', queries: [simple_query('b')])]) + ]) + allow(client).to receive(:label_values).and_return(metric_names) + end + + context 'some queries return results' do + before do + expect(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + expect(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) + end + it 'return results only for queries with results' do puts query_result - expected = { - group: 'name', - priority: 1, - metrics: - [ + expected = [ + { + group: 'group_a', + priority: 1, + metrics: [ + { + title: 'title', + weight: nil, + y_label: 'Values', + queries: [ + { + query_range: 'query_range_a', + result: [ + { + metric: {}, + values: [[1488758662.506, '0.00002996364761904785'], [1488758722.506, '0.00003090239047619091']] } + ] + } + ] + } + ] + }, + { + group: 'group_b', + priority: 1, + metrics: [ { - title: 'title', weight: nil, y_label: 'Values', queries: - [ - { query_range: 'query_range_a', result: query_range_result }, - { query_range: 'query_range_b', label: 'label', unit: 'unit', result: query_range_result } + title: 'title_b', + weight: nil, + y_label: 'Values', + queries: [ + { + query_range: 'query_range_b', result: [ + { + metric: {}, + values: [[1488758662.506, '0.00002996364761904785'], [1488758722.506, '0.00003090239047619091']] + } + ] + } ] } ] - } + } + ] - expect(query_result).to eq([expected]) + expect(query_result).to eq(expected) end end end -- cgit v1.2.1 From cf4aeafa6f3baaec7652f486cd04b7170dde9fbf Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 14:42:53 +0200 Subject: Test Partial additional query response --- .../queries/additional_metrics_query_spec.rb | 54 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb index 617028cde37..2291c4d67bb 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -24,12 +24,12 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do context 'some queries return results' do before do - expect(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) - expect(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) - expect(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) + allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) end - it 'return results only for queries with results' do + it 'return group data only for queries with results' do expected = [ { group: 'name', @@ -61,14 +61,13 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do allow(client).to receive(:label_values).and_return(metric_names) end - context 'some queries return results' do + context 'both queries return results' do before do - expect(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) - expect(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) end - it 'return results only for queries with results' do - puts query_result + it 'return group data both queries' do expected = [ { group: 'group_a', @@ -117,5 +116,42 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do expect(query_result).to eq(expected) end end + + context 'one query returns result' do + before do + allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) + allow(client).to receive(:query_range).with('query_range_b', any_args).and_return([]) + end + + it 'queries using specific time' do + expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) + + expect(query_result).not_to be_nil + end + + it 'return group data only for query with results' do + expected = [ + { + group: 'group_a', + priority: 1, + metrics: [ + { + title: 'title', + weight: nil, + y_label: 'Values', + queries: [ + { + query_range: 'query_range_a', + result: query_range_result + } + ] + } + ] + } + ] + + expect(query_result).to eq(expected) + end + end end end -- cgit v1.2.1 From eccc187a70a6745ca02211648814c89ff390dfa3 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 19:26:46 +0200 Subject: Additional Metrics of deployment tests --- .../additional_metrics_deployment_query_spec.rb | 29 +++++ .../queries/additional_metrics_query_spec.rb | 143 +-------------------- 2 files changed, 33 insertions(+), 139 deletions(-) create mode 100644 spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb new file mode 100644 index 00000000000..93a9ce38d80 --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery, lib: true do + include Prometheus::AdditionalMetricsQueryHelper + include Prometheus::MetricBuilders + + let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } + let(:metric_class) { Gitlab::Prometheus::Metric } + + let(:client) { double('prometheus_client') } + let(:environment) { create(:environment, slug: 'environment-slug') } + let(:deployment) { create(:deployment, environment: environment) } + + subject(:query_result) { described_class.new(client).query(deployment.id) } + + around do |example| + Timecop.freeze { example.run } + end + + include_examples 'additional metrics query' do + it 'queries using specific time' do + expect(client).to receive(:query_range).with(anything, + start: (deployment.created_at - 30.minutes).to_f, + stop: (deployment.created_at + 30.minutes).to_f) + + expect(query_result).not_to be_nil + end + end +end diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb index 2291c4d67bb..e5db1326597 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -4,9 +4,6 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do include Prometheus::AdditionalMetricsQueryHelper include Prometheus::MetricBuilders - let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } - let(:metric_class) { Gitlab::Prometheus::Metric } - let(:client) { double('prometheus_client') } let(:environment) { create(:environment, slug: 'environment-slug') } @@ -16,142 +13,10 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do Timecop.freeze { example.run } end - context 'with one group where two metrics is found' do - before do - allow(metric_group_class).to receive(:all).and_return([simple_metric_group]) - allow(client).to receive(:label_values).and_return(metric_names) - end - - context 'some queries return results' do - before do - allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) - allow(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) - allow(client).to receive(:query_range).with('query_range_empty', any_args).and_return([]) - end - - it 'return group data only for queries with results' do - expected = [ - { - group: 'name', - priority: 1, - metrics: [ - { - title: 'title', weight: nil, y_label: 'Values', queries: [ - { query_range: 'query_range_a', result: query_range_result }, - { query_range: 'query_range_b', label: 'label', unit: 'unit', result: query_range_result } - ] - } - ] - } - ] - - expect(query_result).to eq(expected) - end - end - end - - context 'with two groups with one metric each' do - let(:metrics) { [simple_metric(queries: [simple_query])] } - before do - allow(metric_group_class).to receive(:all).and_return( - [ - simple_metric_group('group_a', [simple_metric(queries: [simple_query])]), - simple_metric_group('group_b', [simple_metric(title: 'title_b', queries: [simple_query('b')])]) - ]) - allow(client).to receive(:label_values).and_return(metric_names) - end - - context 'both queries return results' do - before do - allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) - allow(client).to receive(:query_range).with('query_range_b', any_args).and_return(query_range_result) - end - - it 'return group data both queries' do - expected = [ - { - group: 'group_a', - priority: 1, - metrics: [ - { - title: 'title', - weight: nil, - y_label: 'Values', - queries: [ - { - query_range: 'query_range_a', - result: [ - { - metric: {}, - values: [[1488758662.506, '0.00002996364761904785'], [1488758722.506, '0.00003090239047619091']] } - ] - } - ] - } - ] - }, - { - group: 'group_b', - priority: 1, - metrics: [ - { - title: 'title_b', - weight: nil, - y_label: 'Values', - queries: [ - { - query_range: 'query_range_b', result: [ - { - metric: {}, - values: [[1488758662.506, '0.00002996364761904785'], [1488758722.506, '0.00003090239047619091']] - } - ] - } - ] - } - ] - } - ] - - expect(query_result).to eq(expected) - end - end - - context 'one query returns result' do - before do - allow(client).to receive(:query_range).with('query_range_a', any_args).and_return(query_range_result) - allow(client).to receive(:query_range).with('query_range_b', any_args).and_return([]) - end - - it 'queries using specific time' do - expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) - - expect(query_result).not_to be_nil - end - - it 'return group data only for query with results' do - expected = [ - { - group: 'group_a', - priority: 1, - metrics: [ - { - title: 'title', - weight: nil, - y_label: 'Values', - queries: [ - { - query_range: 'query_range_a', - result: query_range_result - } - ] - } - ] - } - ] - - expect(query_result).to eq(expected) - end + include_examples 'additional metrics query' do + it 'queries using specific time' do + expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) + expect(query_result).not_to be_nil end end end -- cgit v1.2.1 From a3eb8264f31a79fc05113df4276d7dcf4e0bad75 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 19:43:30 +0200 Subject: Refactor Metric tests to use more common code --- .../prometheus/queries/matched_metrics_query_spec.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb index 390fff568cc..34f11205878 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do include Prometheus::MatchedMetricsQueryHelper + include Prometheus::MetricBuilders let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } let(:metric_class) { Gitlab::Prometheus::Metric } @@ -83,30 +84,35 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do end end - context 'with two groups where only one metric is found' do + context 'with two groups where metrics are found in each group' do + let(:second_metric_group) { simple_metric_group(name: 'nameb', metrics: simple_metrics(added_metric_name: 'metric_c')) } + before do - allow(metric_group_class).to receive(:all).and_return([simple_metric_group, - simple_metric_group('nameb', simple_metrics('metric_c'))]) + allow(metric_group_class).to receive(:all).and_return([simple_metric_group, second_metric_group]) allow(client).to receive(:label_values).and_return('metric_c') end - context 'both metrics in the group pass requirements' do + context 'all metrics in both groups pass requirements' do before do allow(client).to receive(:series).and_return(series_info_with_environment('metric_c')) end it 'responds with one metrics as active and no missing requiremens' do - expect(subject.query).to eq([{ group: 'nameb', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }]) + expect(subject.query).to eq([ + { group: 'name', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }, + { group: 'nameb', priority: 1, active_metrics: 2, metrics_missing_requirements: 0 }]) end end - context 'no metris in group pass requirements' do + context 'no metrics in groups pass requirements' do before do allow(client).to receive(:series).and_return(series_info_without_environment) end it 'responds with one metrics as active and no missing requiremens' do - expect(subject.query).to eq([{ group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }]) + expect(subject.query).to eq([ + { group: 'name', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }, + { group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 2 }]) end end end -- cgit v1.2.1 From ffedc52eaa33a7a31d3a7b4893387e81163a3d5f Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 20:11:22 +0200 Subject: Cleanup Additional Metrics tests --- .../queries/additional_metrics_deployment_query_spec.rb | 8 -------- .../prometheus/queries/additional_metrics_query_spec.rb | 1 - .../gitlab/prometheus/queries/matched_metrics_query_spec.rb | 12 +++++++++++- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb index 93a9ce38d80..836f2be629f 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb @@ -1,22 +1,14 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery, lib: true do - include Prometheus::AdditionalMetricsQueryHelper include Prometheus::MetricBuilders - let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } - let(:metric_class) { Gitlab::Prometheus::Metric } - let(:client) { double('prometheus_client') } let(:environment) { create(:environment, slug: 'environment-slug') } let(:deployment) { create(:deployment, environment: environment) } subject(:query_result) { described_class.new(client).query(deployment.id) } - around do |example| - Timecop.freeze { example.run } - end - include_examples 'additional metrics query' do it 'queries using specific time' do expect(client).to receive(:query_range).with(anything, diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb index e5db1326597..6fbd2fd17d6 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do - include Prometheus::AdditionalMetricsQueryHelper include Prometheus::MetricBuilders let(:client) { double('prometheus_client') } diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb index 34f11205878..2395675a247 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -1,12 +1,22 @@ require 'spec_helper' describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do - include Prometheus::MatchedMetricsQueryHelper include Prometheus::MetricBuilders let(:metric_group_class) { Gitlab::Prometheus::MetricGroup } let(:metric_class) { Gitlab::Prometheus::Metric } + def series_info_with_environment(*more_metrics) + %w{metric_a metric_b}.concat(more_metrics).map { |metric_name| { '__name__' => metric_name, 'environment' => '' } } + end + let(:metric_names) { %w{metric_a metric_b} } + let(:series_info_without_environment) do + [{ '__name__' => 'metric_a' }, + { '__name__' => 'metric_b' }] + end + let(:partialy_empty_series_info) { [{ '__name__' => 'metric_a', 'environment' => '' }] } + let(:empty_series_info) { [] } + let(:client) { double('prometheus_client') } subject { described_class.new(client) } -- cgit v1.2.1 From 1b6ab2dffce29df53f57cd857720b9f77ab4a7ca Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 5 Jun 2017 21:00:57 +0200 Subject: Remove orig file + rubocop cleanup --- spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb index 2395675a247..d2796ab72da 100644 --- a/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb @@ -9,6 +9,7 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do def series_info_with_environment(*more_metrics) %w{metric_a metric_b}.concat(more_metrics).map { |metric_name| { '__name__' => metric_name, 'environment' => '' } } end + let(:metric_names) { %w{metric_a metric_b} } let(:series_info_without_environment) do [{ '__name__' => 'metric_a' }, @@ -110,7 +111,9 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do it 'responds with one metrics as active and no missing requiremens' do expect(subject.query).to eq([ { group: 'name', priority: 1, active_metrics: 1, metrics_missing_requirements: 0 }, - { group: 'nameb', priority: 1, active_metrics: 2, metrics_missing_requirements: 0 }]) + { group: 'nameb', priority: 1, active_metrics: 2, metrics_missing_requirements: 0 } + ] + ) end end @@ -122,7 +125,9 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do it 'responds with one metrics as active and no missing requiremens' do expect(subject.query).to eq([ { group: 'name', priority: 1, active_metrics: 0, metrics_missing_requirements: 1 }, - { group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 2 }]) + { group: 'nameb', priority: 1, active_metrics: 0, metrics_missing_requirements: 2 } + ] + ) end end end -- cgit v1.2.1 From 336cef434372244b9f17bd1fd222e54f8b70979e Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 6 Jun 2017 11:07:29 +0200 Subject: Fix transient error in deployment test --- .../prometheus/queries/additional_metrics_deployment_query_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb index 836f2be629f..4909aec5a4d 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb @@ -9,6 +9,10 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery, lib: tru subject(:query_result) { described_class.new(client).query(deployment.id) } + around do |example| + Timecop.freeze(Time.local(2008, 9, 1, 12, 0, 0)) { example.run } + end + include_examples 'additional metrics query' do it 'queries using specific time' do expect(client).to receive(:query_range).with(anything, -- cgit v1.2.1 From ccf89acc7145bb129f5666108854daa71a022827 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 6 Jun 2017 16:07:33 +0200 Subject: expand Namespaces:: and refactoring yaml parsing out of MetricGroup class --- .../additional_metrics_environment_query_spec.rb | 21 +++++++++++++++++++++ .../queries/additional_metrics_query_spec.rb | 21 --------------------- 2 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb delete mode 100644 spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb new file mode 100644 index 00000000000..8e6e3bb5946 --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery, lib: true do + include Prometheus::MetricBuilders + + let(:client) { double('prometheus_client') } + let(:environment) { create(:environment, slug: 'environment-slug') } + + subject(:query_result) { described_class.new(client).query(environment.id) } + + around do |example| + Timecop.freeze { example.run } + end + + include_examples 'additional metrics query' do + it 'queries using specific time' do + expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) + expect(query_result).not_to be_nil + end + end +end diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb deleted file mode 100644 index 6fbd2fd17d6..00000000000 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do - include Prometheus::MetricBuilders - - let(:client) { double('prometheus_client') } - let(:environment) { create(:environment, slug: 'environment-slug') } - - subject(:query_result) { described_class.new(client).query(environment.id) } - - around do |example| - Timecop.freeze { example.run } - end - - include_examples 'additional metrics query' do - it 'queries using specific time' do - expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) - expect(query_result).not_to be_nil - end - end -end -- cgit v1.2.1 From 0e7e7c2f2bd0e9c913cda438826a60e761130271 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Fri, 9 Jun 2017 12:43:12 +0200 Subject: Test Additional metrics parser and fix query checking tests --- .../prometheus/additional_metrics_parser_spec.rb | 250 +++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb b/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb new file mode 100644 index 00000000000..97280de173e --- /dev/null +++ b/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb @@ -0,0 +1,250 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do + include Prometheus::MetricBuilders + + let(:parser_error_class) { Gitlab::Prometheus::ParsingError } + + describe '#load_groups_from_yaml' do + subject { described_class.load_groups_from_yaml } + + describe 'parsing sample yaml' do + let(:sample_yaml) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: "title" + required_metrics: [ metric_a, metric_b ] + weight: 1 + queries: [{ query_range: 'query_range_a', label: label, unit: unit }] + - title: "title" + required_metrics: [metric_a] + weight: 1 + queries: [{ query_range: 'query_range_empty' }] + - group: group_b + priority: 1 + metrics: + - title: title + required_metrics: [] + weight: 1 + queries: [{query_range: query_range_a}] + EOF + end + + before do + described_class.instance_variable_set :@additional_metrics_raw, nil + allow(described_class).to receive(:load_yaml_file) { YAML.load(sample_yaml) } + end + + it 'parses to two metric groups with 2 and 1 metric respectively' do + expect(subject.count).to eq(2) + expect(subject[0].metrics.count).to eq(2) + expect(subject[1].metrics.count).to eq(1) + end + + it 'provide group data' do + expect(subject[0]).to have_attributes(name: 'group_a', priority: 1) + expect(subject[1]).to have_attributes(name: 'group_b', priority: 1) + end + + it 'provides metrics data' do + metrics = subject.flat_map(&:metrics) + + expect(metrics.count).to eq(3) + expect(metrics[0]).to have_attributes(title: 'title', required_metrics: %w(metric_a metric_b), weight: 1) + expect(metrics[1]).to have_attributes(title: 'title', required_metrics: %w(metric_a), weight: 1) + expect(metrics[2]).to have_attributes(title: 'title', required_metrics: [], weight: 1) + end + + it 'provides query data' do + queries = subject.flat_map(&:metrics).flat_map(&:queries) + + expect(queries.count).to eq(3) + expect(queries[0]).to eq(query_range: 'query_range_a', label: 'label', unit: 'unit') + expect(queries[1]).to eq(query_range: 'query_range_empty') + expect(queries[2]).to eq(query_range: 'query_range_a') + end + end + + shared_examples 'required field' do |field_name| + before do + described_class.instance_variable_set :@additional_metrics_raw, nil + end + + context "when #{field_name} is nil" do + before do + allow(described_class).to receive(:load_yaml_file) { YAML.load(field_missing) } + end + + it 'throws parsing error' do + expect { subject }.to raise_error(parser_error_class, /missing.*#{field_name}/) + end + end + + context "when #{field_name} are not specified" do + before do + allow(described_class).to receive(:load_yaml_file) { YAML.load(field_nil) } + end + + it 'throws parsing error' do + expect { subject }.to raise_error(parser_error_class, /missing.*#{field_name}/) + end + end + end + + describe 'group required fields' do + it_behaves_like 'required field', :metrics do + let(:field_nil) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + EOF + end + end + + it_behaves_like 'required field', :group do + let(:field_nil) do + <<-EOF.strip_heredoc + - priority: 1 + metrics: [] + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - priority: 1 + metrics: [] + EOF + end + end + + it_behaves_like 'required field', :priority do + let(:field_nil) do + <<-EOF.strip_heredoc + - group: group_a + priority: + metrics: [] + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - group: group_a + metrics: [] + EOF + end + end + end + + describe 'metrics fields parsing' do + it_behaves_like 'required field', :title do + let(:field_nil) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: + required_metrics: [] + weight: 1 + queries: [] + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - required_metrics: [] + weight: 1 + queries: [] + EOF + end + end + + it_behaves_like 'required field', :required_metrics do + let(:field_nil) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: title + required_metrics: + weight: 1 + queries: [] + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: title + weight: 1 + queries: [] + EOF + end + end + + it_behaves_like 'required field', :weight do + let(:field_nil) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: title + required_metrics: [] + weight: + queries: [] + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: title + required_metrics: [] + queries: [] + EOF + end + end + + it_behaves_like 'required field', :queries do + let(:field_nil) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: title + required_metrics: [] + weight: 1 + queries: + EOF + end + + let(:field_missing) do + <<-EOF.strip_heredoc + - group: group_a + priority: 1 + metrics: + - title: title + required_metrics: [] + weight: 1 + EOF + end + end + end + end +end -- cgit v1.2.1 From ef1811f4bc211929997a5b8cc1ecd511b52ca6f4 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Tue, 13 Jun 2017 09:11:33 +0200 Subject: Subgroups page should show groups authorized through inheritance When a user is authorized to a group, they are also authorized to see all the ancestor groups and descendant groups. When a user is authorized to a project, they are authorized to see all the ancestor groups too. Closes #32135 See merge request !11764 --- spec/lib/gitlab/group_hierarchy_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/group_hierarchy_spec.rb b/spec/lib/gitlab/group_hierarchy_spec.rb index 5d0ed1522b3..08010c2d0e2 100644 --- a/spec/lib/gitlab/group_hierarchy_spec.rb +++ b/spec/lib/gitlab/group_hierarchy_spec.rb @@ -17,6 +17,12 @@ describe Gitlab::GroupHierarchy, :postgresql do it 'includes all of the ancestors' do expect(relation).to include(parent, child1) end + + it 'uses ancestors_base #initialize argument' do + relation = described_class.new(Group.where(id: child2.id), Group.none).base_and_ancestors + + expect(relation).to include(parent, child1, child2) + end end describe '#base_and_descendants' do @@ -31,6 +37,12 @@ describe Gitlab::GroupHierarchy, :postgresql do it 'includes all the descendants' do expect(relation).to include(child1, child2) end + + it 'uses descendants_base #initialize argument' do + relation = described_class.new(Group.none, Group.where(id: parent.id)).base_and_descendants + + expect(relation).to include(parent, child1, child2) + end end describe '#all_groups' do @@ -49,5 +61,17 @@ describe Gitlab::GroupHierarchy, :postgresql do it 'includes the descendants' do expect(relation).to include(child2) end + + it 'uses ancestors_base #initialize argument for ancestors' do + relation = described_class.new(Group.where(id: child1.id), Group.where(id: Group.maximum(:id).succ)).all_groups + + expect(relation).to include(parent) + end + + it 'uses descendants_base #initialize argument for descendants' do + relation = described_class.new(Group.where(id: Group.maximum(:id).succ), Group.where(id: child1.id)).all_groups + + expect(relation).to include(child2) + end end end -- cgit v1.2.1 From ea090291bba6bb665b3631cc5a2659e6673a6959 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 31 May 2017 00:50:53 -0500 Subject: Rename "Slash commands" to "Quick actions" Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/27070 Deprecate "chat commands" in favor of "slash commands" We looked for things like: - `slash commmand` - `slash_command` - `slash-command` - `SlashCommand` --- spec/lib/gitlab/chat_commands/command_spec.rb | 111 ---------- spec/lib/gitlab/chat_commands/deploy_spec.rb | 90 --------- spec/lib/gitlab/chat_commands/issue_new_spec.rb | 78 ------- spec/lib/gitlab/chat_commands/issue_search_spec.rb | 48 ----- spec/lib/gitlab/chat_commands/issue_show_spec.rb | 59 ------ .../gitlab/chat_commands/presenters/access_spec.rb | 49 ----- .../gitlab/chat_commands/presenters/deploy_spec.rb | 47 ----- .../chat_commands/presenters/issue_new_spec.rb | 17 -- .../chat_commands/presenters/issue_search_spec.rb | 25 --- .../chat_commands/presenters/issue_show_spec.rb | 52 ----- .../email/handler/create_note_handler_spec.rb | 2 +- .../quick_actions/command_definition_spec.rb | 225 +++++++++++++++++++++ spec/lib/gitlab/quick_actions/dsl_spec.rb | 109 ++++++++++ spec/lib/gitlab/quick_actions/extractor_spec.rb | 223 ++++++++++++++++++++ .../slash_commands/command_definition_spec.rb | 225 --------------------- spec/lib/gitlab/slash_commands/command_spec.rb | 111 ++++++++++ spec/lib/gitlab/slash_commands/deploy_spec.rb | 90 +++++++++ spec/lib/gitlab/slash_commands/dsl_spec.rb | 109 ---------- spec/lib/gitlab/slash_commands/extractor_spec.rb | 223 -------------------- spec/lib/gitlab/slash_commands/issue_new_spec.rb | 78 +++++++ .../lib/gitlab/slash_commands/issue_search_spec.rb | 48 +++++ spec/lib/gitlab/slash_commands/issue_show_spec.rb | 59 ++++++ .../slash_commands/presenters/access_spec.rb | 49 +++++ .../slash_commands/presenters/deploy_spec.rb | 47 +++++ .../slash_commands/presenters/issue_new_spec.rb | 17 ++ .../slash_commands/presenters/issue_search_spec.rb | 25 +++ .../slash_commands/presenters/issue_show_spec.rb | 52 +++++ 27 files changed, 1134 insertions(+), 1134 deletions(-) delete mode 100644 spec/lib/gitlab/chat_commands/command_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/deploy_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/issue_new_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/issue_search_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/issue_show_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/access_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/deploy_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb create mode 100644 spec/lib/gitlab/quick_actions/command_definition_spec.rb create mode 100644 spec/lib/gitlab/quick_actions/dsl_spec.rb create mode 100644 spec/lib/gitlab/quick_actions/extractor_spec.rb delete mode 100644 spec/lib/gitlab/slash_commands/command_definition_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/command_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/deploy_spec.rb delete mode 100644 spec/lib/gitlab/slash_commands/dsl_spec.rb delete mode 100644 spec/lib/gitlab/slash_commands/extractor_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/issue_new_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/issue_search_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/issue_show_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/presenters/access_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/presenters/deploy_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/presenters/issue_new_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/presenters/issue_search_spec.rb create mode 100644 spec/lib/gitlab/slash_commands/presenters/issue_show_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb deleted file mode 100644 index 13e6953147b..00000000000 --- a/spec/lib/gitlab/chat_commands/command_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Command, service: true do - let(:project) { create(:empty_project) } - let(:user) { create(:user) } - - describe '#execute' do - subject do - described_class.new(project, user, params).execute - end - - context 'when no command is available' do - let(:params) { { text: 'issue show 1' } } - let(:project) { create(:empty_project, has_external_issue_tracker: true) } - - it 'displays 404 messages' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to start_with('404 not found') - end - end - - context 'when an unknown command is triggered' do - let(:params) { { command: '/gitlab', text: "unknown command 123" } } - - it 'displays the help message' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to start_with('Unknown command') - expect(subject[:text]).to match('/gitlab issue show') - end - end - - context 'the user can not create an issue' do - let(:params) { { text: "issue create my new issue" } } - - it 'rejects the actions' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to start_with('Whoops! This action is not allowed') - end - end - - context 'when trying to do deployment' do - let(:params) { { text: 'deploy staging to production' } } - let!(:build) { create(:ci_build, pipeline: pipeline) } - let!(:pipeline) { create(:ci_pipeline, project: project) } - let!(:staging) { create(:environment, name: 'staging', project: project) } - let!(:deployment) { create(:deployment, environment: staging, deployable: build) } - - let!(:manual) do - create(:ci_build, :manual, pipeline: pipeline, - name: 'first', - environment: 'production') - end - - context 'and user can not create deployment' do - it 'returns action' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to start_with('Whoops! This action is not allowed') - end - end - - context 'and user has deployment permission' do - before do - build.project.add_developer(user) - - create(:protected_branch, :developers_can_merge, - name: build.ref, project: project) - end - - it 'returns action' do - expect(subject[:text]).to include('Deployment started from staging to production') - expect(subject[:response_type]).to be(:in_channel) - end - - context 'when duplicate action exists' do - let!(:manual2) do - create(:ci_build, :manual, pipeline: pipeline, - name: 'second', - environment: 'production') - end - - it 'returns error' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to include('Too many actions defined') - end - end - end - end - end - - describe '#match_command' do - subject { described_class.new(project, user, params).match_command.first } - - context 'IssueShow is triggered' do - let(:params) { { text: 'issue show 123' } } - - it { is_expected.to eq(Gitlab::ChatCommands::IssueShow) } - end - - context 'IssueCreate is triggered' do - let(:params) { { text: 'issue create my title' } } - - it { is_expected.to eq(Gitlab::ChatCommands::IssueNew) } - end - - context 'IssueSearch is triggered' do - let(:params) { { text: 'issue search my query' } } - - it { is_expected.to eq(Gitlab::ChatCommands::IssueSearch) } - end - end -end diff --git a/spec/lib/gitlab/chat_commands/deploy_spec.rb b/spec/lib/gitlab/chat_commands/deploy_spec.rb deleted file mode 100644 index 46dbdeae37c..00000000000 --- a/spec/lib/gitlab/chat_commands/deploy_spec.rb +++ /dev/null @@ -1,90 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Deploy, service: true do - describe '#execute' do - let(:project) { create(:empty_project) } - let(:user) { create(:user) } - let(:regex_match) { described_class.match('deploy staging to production') } - - before do - # Make it possible to trigger protected manual actions for developers. - # - project.add_developer(user) - - create(:protected_branch, :developers_can_merge, - name: 'master', project: project) - end - - subject do - described_class.new(project, user).execute(regex_match) - end - - context 'if no environment is defined' do - it 'does not execute an action' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to eq("No action found to be executed") - end - end - - context 'with environment' do - let!(:staging) { create(:environment, name: 'staging', project: project) } - let!(:pipeline) { create(:ci_pipeline, project: project) } - let!(:build) { create(:ci_build, pipeline: pipeline) } - let!(:deployment) { create(:deployment, environment: staging, deployable: build) } - - context 'without actions' do - it 'does not execute an action' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to eq("No action found to be executed") - end - end - - context 'with action' do - let!(:manual1) do - create(:ci_build, :manual, pipeline: pipeline, - name: 'first', - environment: 'production') - end - - it 'returns success result' do - expect(subject[:response_type]).to be(:in_channel) - expect(subject[:text]).to start_with('Deployment started from staging to production') - end - - context 'when duplicate action exists' do - let!(:manual2) do - create(:ci_build, :manual, pipeline: pipeline, - name: 'second', - environment: 'production') - end - - it 'returns error' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to eq('Too many actions defined') - end - end - - context 'when teardown action exists' do - let!(:teardown) do - create(:ci_build, :manual, :teardown_environment, - pipeline: pipeline, name: 'teardown', environment: 'production') - end - - it 'returns the success message' do - expect(subject[:response_type]).to be(:in_channel) - expect(subject[:text]).to start_with('Deployment started from staging to production') - end - end - end - end - end - - describe 'self.match' do - it 'matches the environment' do - match = described_class.match('deploy staging to production') - - expect(match[:from]).to eq('staging') - expect(match[:to]).to eq('production') - end - end -end diff --git a/spec/lib/gitlab/chat_commands/issue_new_spec.rb b/spec/lib/gitlab/chat_commands/issue_new_spec.rb deleted file mode 100644 index 84c22328064..00000000000 --- a/spec/lib/gitlab/chat_commands/issue_new_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::IssueNew, service: true do - describe '#execute' do - let(:project) { create(:empty_project) } - let(:user) { create(:user) } - let(:regex_match) { described_class.match("issue create bird is the word") } - - before do - project.team << [user, :master] - end - - subject do - described_class.new(project, user).execute(regex_match) - end - - context 'without description' do - it 'creates the issue' do - expect { subject }.to change { project.issues.count }.by(1) - - expect(subject[:response_type]).to be(:in_channel) - end - end - - context 'with description' do - let(:description) { "Surfin bird" } - let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") } - - it 'creates the issue with description' do - subject - - expect(Issue.last.description).to eq(description) - end - end - - context "with more newlines between the title and the description" do - let(:description) { "Surfin bird" } - let(:regex_match) { described_class.match("issue create bird is the word\n\n#{description}\n") } - - it 'creates the issue' do - expect { subject }.to change { project.issues.count }.by(1) - end - end - - context 'issue cannot be created' do - let!(:issue) { create(:issue, project: project, title: 'bird is the word') } - let(:regex_match) { described_class.match("issue create #{'a' * 512}}") } - - it 'displays the errors' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to match("- Title is too long") - end - end - end - - describe '.match' do - it 'matches the title without description' do - match = described_class.match("issue create my title") - - expect(match[:title]).to eq('my title') - expect(match[:description]).to eq("") - end - - it 'matches the title with description' do - match = described_class.match("issue create my title\n\ndescription") - - expect(match[:title]).to eq('my title') - expect(match[:description]).to eq('description') - end - - it 'matches the alias new' do - match = described_class.match("issue new my title") - - expect(match).not_to be_nil - expect(match[:title]).to eq('my title') - end - end -end diff --git a/spec/lib/gitlab/chat_commands/issue_search_spec.rb b/spec/lib/gitlab/chat_commands/issue_search_spec.rb deleted file mode 100644 index 551ccb79a58..00000000000 --- a/spec/lib/gitlab/chat_commands/issue_search_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::IssueSearch, service: true do - describe '#execute' do - let!(:issue) { create(:issue, project: project, title: 'find me') } - let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') } - let(:project) { create(:empty_project) } - let(:user) { issue.author } - let(:regex_match) { described_class.match("issue search find") } - - subject do - described_class.new(project, user).execute(regex_match) - end - - context 'when the user has no access' do - it 'only returns the open issues' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to match("not found") - end - end - - context 'the user has access' do - before do - project.team << [user, :master] - end - - it 'returns all results' do - expect(subject).to have_key(:attachments) - expect(subject[:text]).to eq("Here are the 2 issues I found:") - end - end - - context 'without hits on the query' do - it 'returns an empty collection' do - expect(subject[:text]).to match("not found") - end - end - end - - describe 'self.match' do - let(:query) { "my search keywords" } - it 'matches the query' do - match = described_class.match("issue search #{query}") - - expect(match[:query]).to eq(query) - end - end -end diff --git a/spec/lib/gitlab/chat_commands/issue_show_spec.rb b/spec/lib/gitlab/chat_commands/issue_show_spec.rb deleted file mode 100644 index 1f20d0a44ce..00000000000 --- a/spec/lib/gitlab/chat_commands/issue_show_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::IssueShow, service: true do - describe '#execute' do - let(:issue) { create(:issue, project: project) } - let(:project) { create(:empty_project) } - let(:user) { issue.author } - let(:regex_match) { described_class.match("issue show #{issue.iid}") } - - before do - project.team << [user, :master] - end - - subject do - described_class.new(project, user).execute(regex_match) - end - - context 'the issue exists' do - let(:title) { subject[:attachments].first[:title] } - - it 'returns the issue' do - expect(subject[:response_type]).to be(:in_channel) - expect(title).to start_with(issue.title) - end - - context 'when its reference is given' do - let(:regex_match) { described_class.match("issue show #{issue.to_reference}") } - - it 'shows the issue' do - expect(subject[:response_type]).to be(:in_channel) - expect(title).to start_with(issue.title) - end - end - end - - context 'the issue does not exist' do - let(:regex_match) { described_class.match("issue show 2343242") } - - it "returns not found" do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to match("not found") - end - end - end - - describe '.match' do - it 'matches the iid' do - match = described_class.match("issue show 123") - - expect(match[:iid]).to eq("123") - end - - it 'accepts a reference' do - match = described_class.match("issue show #{Issue.reference_prefix}123") - - expect(match[:iid]).to eq("123") - end - end -end diff --git a/spec/lib/gitlab/chat_commands/presenters/access_spec.rb b/spec/lib/gitlab/chat_commands/presenters/access_spec.rb deleted file mode 100644 index ae41d75ab0c..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/access_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::Access do - describe '#access_denied' do - subject { described_class.new.access_denied } - - it { is_expected.to be_a(Hash) } - - it 'displays an error message' do - expect(subject[:text]).to match("is not allowed") - expect(subject[:response_type]).to be(:ephemeral) - end - end - - describe '#not_found' do - subject { described_class.new.not_found } - - it { is_expected.to be_a(Hash) } - - it 'tells the user the resource was not found' do - expect(subject[:text]).to match("not found!") - expect(subject[:response_type]).to be(:ephemeral) - end - end - - describe '#authorize' do - context 'with an authorization URL' do - subject { described_class.new('http://authorize.me').authorize } - - it { is_expected.to be_a(Hash) } - - it 'tells the user to authorize' do - expect(subject[:text]).to match("connect your GitLab account") - expect(subject[:response_type]).to be(:ephemeral) - end - end - - context 'without authorization url' do - subject { described_class.new.authorize } - - it { is_expected.to be_a(Hash) } - - it 'tells the user to authorize' do - expect(subject[:text]).to match("Couldn't identify you") - expect(subject[:response_type]).to be(:ephemeral) - end - end - end -end diff --git a/spec/lib/gitlab/chat_commands/presenters/deploy_spec.rb b/spec/lib/gitlab/chat_commands/presenters/deploy_spec.rb deleted file mode 100644 index dc2dd300072..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/deploy_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::Deploy do - let(:build) { create(:ci_build) } - - describe '#present' do - subject { described_class.new(build).present('staging', 'prod') } - - it { is_expected.to have_key(:text) } - it { is_expected.to have_key(:response_type) } - it { is_expected.to have_key(:status) } - it { is_expected.not_to have_key(:attachments) } - - it 'messages the channel of the deploy' do - expect(subject[:response_type]).to be(:in_channel) - expect(subject[:text]).to start_with("Deployment started from staging to prod") - end - end - - describe '#no_actions' do - subject { described_class.new(nil).no_actions } - - it { is_expected.to have_key(:text) } - it { is_expected.to have_key(:response_type) } - it { is_expected.to have_key(:status) } - it { is_expected.not_to have_key(:attachments) } - - it 'tells the user there is no action' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to eq("No action found to be executed") - end - end - - describe '#too_many_actions' do - subject { described_class.new([]).too_many_actions } - - it { is_expected.to have_key(:text) } - it { is_expected.to have_key(:response_type) } - it { is_expected.to have_key(:status) } - it { is_expected.not_to have_key(:attachments) } - - it 'tells the user there is no action' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to eq("Too many actions defined") - end - end -end diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb deleted file mode 100644 index 17fcdbc2452..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::IssueNew do - let(:project) { create(:empty_project) } - let(:issue) { create(:issue, project: project) } - let(:attachment) { subject[:attachments].first } - - subject { described_class.new(issue).present } - - it { is_expected.to be_a(Hash) } - - it 'shows the issue' do - expect(subject[:response_type]).to be(:in_channel) - expect(subject).to have_key(:attachments) - expect(attachment[:title]).to start_with(issue.title) - end -end diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb deleted file mode 100644 index 3799a324db4..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::IssueSearch do - let(:project) { create(:empty_project) } - let(:message) { subject[:text] } - - before do - create_list(:issue, 2, project: project) - end - - subject { described_class.new(project.issues).present } - - it 'formats the message correct' do - is_expected.to have_key(:text) - is_expected.to have_key(:status) - is_expected.to have_key(:response_type) - is_expected.to have_key(:attachments) - end - - it 'shows a list of results' do - expect(subject[:response_type]).to be(:ephemeral) - - expect(message).to start_with("Here are the 2 issues I found") - end -end diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb deleted file mode 100644 index 3916fc704a4..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::IssueShow do - let(:project) { create(:empty_project) } - let(:issue) { create(:issue, project: project) } - let(:attachment) { subject[:attachments].first } - - subject { described_class.new(issue).present } - - it { is_expected.to be_a(Hash) } - - it 'shows the issue' do - expect(subject[:response_type]).to be(:in_channel) - expect(subject).to have_key(:attachments) - expect(attachment[:title]).to start_with(issue.title) - end - - context 'with upvotes' do - before do - create(:award_emoji, :upvote, awardable: issue) - end - - it 'shows the upvote count' do - expect(subject[:response_type]).to be(:in_channel) - expect(attachment[:text]).to start_with("**Open** · :+1: 1") - end - end - - context 'with labels' do - let(:label) { create(:label, project: project, title: 'mep') } - let(:label1) { create(:label, project: project, title: 'mop') } - - before do - issue.labels << [label, label1] - end - - it 'shows the labels' do - labels = attachment[:fields].find { |f| f[:title] == 'Labels' } - - expect(labels[:value]).to eq("mep, mop") - end - end - - context 'confidential issue' do - let(:issue) { create(:issue, project: project) } - - it 'shows an ephemeral response' do - expect(subject[:response_type]).to be(:in_channel) - expect(attachment[:text]).to start_with("**Open**") - end - end -end diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb index 3f79eaf7afb..cd0309e248d 100644 --- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -91,7 +91,7 @@ describe Gitlab::Email::Handler::CreateNoteHandler, lib: true do end end - context 'when the note contains slash commands' do + context 'when the note contains quick actions' do let!(:email_raw) { fixture_file("emails/commands_in_reply.eml") } context 'and current user cannot update noteable' do diff --git a/spec/lib/gitlab/quick_actions/command_definition_spec.rb b/spec/lib/gitlab/quick_actions/command_definition_spec.rb new file mode 100644 index 00000000000..f44a562dc63 --- /dev/null +++ b/spec/lib/gitlab/quick_actions/command_definition_spec.rb @@ -0,0 +1,225 @@ +require 'spec_helper' + +describe Gitlab::QuickActions::CommandDefinition do + subject { described_class.new(:command) } + + describe "#all_names" do + context "when the command has aliases" do + before do + subject.aliases = [:alias1, :alias2] + end + + it "returns an array with the name and aliases" do + expect(subject.all_names).to eq([:command, :alias1, :alias2]) + end + end + + context "when the command doesn't have aliases" do + it "returns an array with the name" do + expect(subject.all_names).to eq([:command]) + end + end + end + + describe "#noop?" do + context "when the command has an action block" do + before do + subject.action_block = proc { } + end + + it "returns false" do + expect(subject.noop?).to be false + end + end + + context "when the command doesn't have an action block" do + it "returns true" do + expect(subject.noop?).to be true + end + end + end + + describe "#available?" do + let(:opts) { { go: false } } + + context "when the command has a condition block" do + before do + subject.condition_block = proc { go } + end + + context "when the condition block returns true" do + before do + opts[:go] = true + end + + it "returns true" do + expect(subject.available?(opts)).to be true + end + end + + context "when the condition block returns false" do + it "returns false" do + expect(subject.available?(opts)).to be false + end + end + end + + context "when the command doesn't have a condition block" do + it "returns true" do + expect(subject.available?(opts)).to be true + end + end + end + + describe "#execute" do + let(:context) { OpenStruct.new(run: false) } + + context "when the command is a noop" do + it "doesn't execute the command" do + expect(context).not_to receive(:instance_exec) + + subject.execute(context, {}, nil) + + expect(context.run).to be false + end + end + + context "when the command is not a noop" do + before do + subject.action_block = proc { self.run = true } + end + + context "when the command is not available" do + before do + subject.condition_block = proc { false } + end + + it "doesn't execute the command" do + subject.execute(context, {}, nil) + + expect(context.run).to be false + end + end + + context "when the command is available" do + context "when the commnd has no arguments" do + before do + subject.action_block = proc { self.run = true } + end + + context "when the command is provided an argument" do + it "executes the command" do + subject.execute(context, {}, true) + + expect(context.run).to be true + end + end + + context "when the command is not provided an argument" do + it "executes the command" do + subject.execute(context, {}, nil) + + expect(context.run).to be true + end + end + end + + context "when the command has 1 required argument" do + before do + subject.action_block = ->(arg) { self.run = arg } + end + + context "when the command is provided an argument" do + it "executes the command" do + subject.execute(context, {}, true) + + expect(context.run).to be true + end + end + + context "when the command is not provided an argument" do + it "doesn't execute the command" do + subject.execute(context, {}, nil) + + expect(context.run).to be false + end + end + end + + context "when the command has 1 optional argument" do + before do + subject.action_block = proc { |arg = nil| self.run = arg || true } + end + + context "when the command is provided an argument" do + it "executes the command" do + subject.execute(context, {}, true) + + expect(context.run).to be true + end + end + + context "when the command is not provided an argument" do + it "executes the command" do + subject.execute(context, {}, nil) + + expect(context.run).to be true + end + end + end + + context 'when the command defines parse_params block' do + before do + subject.parse_params_block = ->(raw) { raw.strip } + subject.action_block = ->(parsed) { self.received_arg = parsed } + end + + it 'executes the command passing the parsed param' do + subject.execute(context, {}, 'something ') + + expect(context.received_arg).to eq('something') + end + end + end + end + end + + describe '#explain' do + context 'when the command is not available' do + before do + subject.condition_block = proc { false } + subject.explanation = 'Explanation' + end + + it 'returns nil' do + result = subject.explain({}, {}, nil) + + expect(result).to be_nil + end + end + + context 'when the explanation is a static string' do + before do + subject.explanation = 'Explanation' + end + + it 'returns this static string' do + result = subject.explain({}, {}, nil) + + expect(result).to eq 'Explanation' + end + end + + context 'when the explanation is dynamic' do + before do + subject.explanation = proc { |arg| "Dynamic #{arg}" } + end + + it 'invokes the proc' do + result = subject.explain({}, {}, 'explanation') + + expect(result).to eq 'Dynamic explanation' + end + end + end +end diff --git a/spec/lib/gitlab/quick_actions/dsl_spec.rb b/spec/lib/gitlab/quick_actions/dsl_spec.rb new file mode 100644 index 00000000000..a4bb3f911d7 --- /dev/null +++ b/spec/lib/gitlab/quick_actions/dsl_spec.rb @@ -0,0 +1,109 @@ +require 'spec_helper' + +describe Gitlab::QuickActions::Dsl do + before :all do + DummyClass = Struct.new(:project) do + include Gitlab::QuickActions::Dsl # rubocop:disable RSpec/DescribedClass + + desc 'A command with no args' + command :no_args, :none do + "Hello World!" + end + + params 'The first argument' + explanation 'Static explanation' + command :explanation_with_aliases, :once, :first do |arg| + arg + end + + desc do + "A dynamic description for #{noteable.upcase}" + end + params 'The first argument', 'The second argument' + command :dynamic_description do |args| + args.split + end + + command :cc + + explanation do |arg| + "Action does something with #{arg}" + end + condition do + project == 'foo' + end + command :cond_action do |arg| + arg + end + + parse_params do |raw_arg| + raw_arg.strip + end + command :with_params_parsing do |parsed| + parsed + end + end + end + + describe '.command_definitions' do + it 'returns an array with commands definitions' do + no_args_def, explanation_with_aliases_def, dynamic_description_def, + cc_def, cond_action_def, with_params_parsing_def = + DummyClass.command_definitions + + expect(no_args_def.name).to eq(:no_args) + expect(no_args_def.aliases).to eq([:none]) + expect(no_args_def.description).to eq('A command with no args') + expect(no_args_def.explanation).to eq('') + expect(no_args_def.params).to eq([]) + expect(no_args_def.condition_block).to be_nil + expect(no_args_def.action_block).to be_a_kind_of(Proc) + expect(no_args_def.parse_params_block).to be_nil + + expect(explanation_with_aliases_def.name).to eq(:explanation_with_aliases) + expect(explanation_with_aliases_def.aliases).to eq([:once, :first]) + expect(explanation_with_aliases_def.description).to eq('') + expect(explanation_with_aliases_def.explanation).to eq('Static explanation') + expect(explanation_with_aliases_def.params).to eq(['The first argument']) + expect(explanation_with_aliases_def.condition_block).to be_nil + expect(explanation_with_aliases_def.action_block).to be_a_kind_of(Proc) + expect(explanation_with_aliases_def.parse_params_block).to be_nil + + expect(dynamic_description_def.name).to eq(:dynamic_description) + expect(dynamic_description_def.aliases).to eq([]) + expect(dynamic_description_def.to_h(noteable: 'issue')[:description]).to eq('A dynamic description for ISSUE') + expect(dynamic_description_def.explanation).to eq('') + expect(dynamic_description_def.params).to eq(['The first argument', 'The second argument']) + expect(dynamic_description_def.condition_block).to be_nil + expect(dynamic_description_def.action_block).to be_a_kind_of(Proc) + expect(dynamic_description_def.parse_params_block).to be_nil + + expect(cc_def.name).to eq(:cc) + expect(cc_def.aliases).to eq([]) + expect(cc_def.description).to eq('') + expect(cc_def.explanation).to eq('') + expect(cc_def.params).to eq([]) + expect(cc_def.condition_block).to be_nil + expect(cc_def.action_block).to be_nil + expect(cc_def.parse_params_block).to be_nil + + expect(cond_action_def.name).to eq(:cond_action) + expect(cond_action_def.aliases).to eq([]) + expect(cond_action_def.description).to eq('') + expect(cond_action_def.explanation).to be_a_kind_of(Proc) + expect(cond_action_def.params).to eq([]) + expect(cond_action_def.condition_block).to be_a_kind_of(Proc) + expect(cond_action_def.action_block).to be_a_kind_of(Proc) + expect(cond_action_def.parse_params_block).to be_nil + + expect(with_params_parsing_def.name).to eq(:with_params_parsing) + expect(with_params_parsing_def.aliases).to eq([]) + expect(with_params_parsing_def.description).to eq('') + expect(with_params_parsing_def.explanation).to eq('') + expect(with_params_parsing_def.params).to eq([]) + expect(with_params_parsing_def.condition_block).to be_nil + expect(with_params_parsing_def.action_block).to be_a_kind_of(Proc) + expect(with_params_parsing_def.parse_params_block).to be_a_kind_of(Proc) + end + end +end diff --git a/spec/lib/gitlab/quick_actions/extractor_spec.rb b/spec/lib/gitlab/quick_actions/extractor_spec.rb new file mode 100644 index 00000000000..9d32938e155 --- /dev/null +++ b/spec/lib/gitlab/quick_actions/extractor_spec.rb @@ -0,0 +1,223 @@ +require 'spec_helper' + +describe Gitlab::QuickActions::Extractor do + let(:definitions) do + Class.new do + include Gitlab::QuickActions::Dsl + + command(:reopen, :open) { } + command(:assign) { } + command(:labels) { } + command(:power) { } + end.command_definitions + end + + let(:extractor) { described_class.new(definitions) } + + shared_examples 'command with no argument' do + it 'extracts command' do + msg, commands = extractor.extract_commands(original_msg) + + expect(commands).to eq [['reopen']] + expect(msg).to eq final_msg + end + end + + shared_examples 'command with a single argument' do + it 'extracts command' do + msg, commands = extractor.extract_commands(original_msg) + + expect(commands).to eq [['assign', '@joe']] + expect(msg).to eq final_msg + end + end + + shared_examples 'command with multiple arguments' do + it 'extracts command' do + msg, commands = extractor.extract_commands(original_msg) + + expect(commands).to eq [['labels', '~foo ~"bar baz" label']] + expect(msg).to eq final_msg + end + end + + describe '#extract_commands' do + describe 'command with no argument' do + context 'at the start of content' do + it_behaves_like 'command with no argument' do + let(:original_msg) { "/reopen\nworld" } + let(:final_msg) { "world" } + end + end + + context 'in the middle of content' do + it_behaves_like 'command with no argument' do + let(:original_msg) { "hello\n/reopen\nworld" } + let(:final_msg) { "hello\nworld" } + end + end + + context 'in the middle of a line' do + it 'does not extract command' do + msg = "hello\nworld /reopen" + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq "hello\nworld /reopen" + end + end + + context 'at the end of content' do + it_behaves_like 'command with no argument' do + let(:original_msg) { "hello\n/reopen" } + let(:final_msg) { "hello" } + end + end + end + + describe 'command with a single argument' do + context 'at the start of content' do + it_behaves_like 'command with a single argument' do + let(:original_msg) { "/assign @joe\nworld" } + let(:final_msg) { "world" } + end + + it 'allows slash in command arguments' do + msg = "/assign @joe / @jane\nworld" + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['assign', '@joe / @jane']] + expect(msg).to eq 'world' + end + end + + context 'in the middle of content' do + it_behaves_like 'command with a single argument' do + let(:original_msg) { "hello\n/assign @joe\nworld" } + let(:final_msg) { "hello\nworld" } + end + end + + context 'in the middle of a line' do + it 'does not extract command' do + msg = "hello\nworld /assign @joe" + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq "hello\nworld /assign @joe" + end + end + + context 'at the end of content' do + it_behaves_like 'command with a single argument' do + let(:original_msg) { "hello\n/assign @joe" } + let(:final_msg) { "hello" } + end + end + + context 'when argument is not separated with a space' do + it 'does not extract command' do + msg = "hello\n/assign@joe\nworld" + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq "hello\n/assign@joe\nworld" + end + end + end + + describe 'command with multiple arguments' do + context 'at the start of content' do + it_behaves_like 'command with multiple arguments' do + let(:original_msg) { %(/labels ~foo ~"bar baz" label\nworld) } + let(:final_msg) { "world" } + end + end + + context 'in the middle of content' do + it_behaves_like 'command with multiple arguments' do + let(:original_msg) { %(hello\n/labels ~foo ~"bar baz" label\nworld) } + let(:final_msg) { "hello\nworld" } + end + end + + context 'in the middle of a line' do + it 'does not extract command' do + msg = %(hello\nworld /labels ~foo ~"bar baz" label) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq %(hello\nworld /labels ~foo ~"bar baz" label) + end + end + + context 'at the end of content' do + it_behaves_like 'command with multiple arguments' do + let(:original_msg) { %(hello\n/labels ~foo ~"bar baz" label) } + let(:final_msg) { "hello" } + end + end + + context 'when argument is not separated with a space' do + it 'does not extract command' do + msg = %(hello\n/labels~foo ~"bar baz" label\nworld) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq %(hello\n/labels~foo ~"bar baz" label\nworld) + end + end + end + + it 'extracts command with multiple arguments and various prefixes' do + msg = %(hello\n/power @user.name %9.10 ~"bar baz.2"\nworld) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['power', '@user.name %9.10 ~"bar baz.2"']] + expect(msg).to eq "hello\nworld" + end + + it 'extracts multiple commands' do + msg = %(hello\n/power @user.name %9.10 ~"bar baz.2" label\nworld\n/reopen) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['power', '@user.name %9.10 ~"bar baz.2" label'], ['reopen']] + expect(msg).to eq "hello\nworld" + end + + it 'does not alter original content if no command is found' do + msg = 'Fixes #123' + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq 'Fixes #123' + end + + it 'does not extract commands inside a blockcode' do + msg = "Hello\r\n```\r\nThis is some text\r\n/close\r\n/assign @user\r\n```\r\n\r\nWorld" + expected = msg.delete("\r") + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq expected + end + + it 'does not extract commands inside a blockquote' do + msg = "Hello\r\n>>>\r\nThis is some text\r\n/close\r\n/assign @user\r\n>>>\r\n\r\nWorld" + expected = msg.delete("\r") + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq expected + end + + it 'does not extract commands inside a HTML tag' do + msg = "Hello\r\n
\r\nThis is some text\r\n/close\r\n/assign @user\r\n
\r\n\r\nWorld" + expected = msg.delete("\r") + msg, commands = extractor.extract_commands(msg) + + expect(commands).to be_empty + expect(msg).to eq expected + end + end +end diff --git a/spec/lib/gitlab/slash_commands/command_definition_spec.rb b/spec/lib/gitlab/slash_commands/command_definition_spec.rb deleted file mode 100644 index 5b9173d3d3f..00000000000 --- a/spec/lib/gitlab/slash_commands/command_definition_spec.rb +++ /dev/null @@ -1,225 +0,0 @@ -require 'spec_helper' - -describe Gitlab::SlashCommands::CommandDefinition do - subject { described_class.new(:command) } - - describe "#all_names" do - context "when the command has aliases" do - before do - subject.aliases = [:alias1, :alias2] - end - - it "returns an array with the name and aliases" do - expect(subject.all_names).to eq([:command, :alias1, :alias2]) - end - end - - context "when the command doesn't have aliases" do - it "returns an array with the name" do - expect(subject.all_names).to eq([:command]) - end - end - end - - describe "#noop?" do - context "when the command has an action block" do - before do - subject.action_block = proc { } - end - - it "returns false" do - expect(subject.noop?).to be false - end - end - - context "when the command doesn't have an action block" do - it "returns true" do - expect(subject.noop?).to be true - end - end - end - - describe "#available?" do - let(:opts) { { go: false } } - - context "when the command has a condition block" do - before do - subject.condition_block = proc { go } - end - - context "when the condition block returns true" do - before do - opts[:go] = true - end - - it "returns true" do - expect(subject.available?(opts)).to be true - end - end - - context "when the condition block returns false" do - it "returns false" do - expect(subject.available?(opts)).to be false - end - end - end - - context "when the command doesn't have a condition block" do - it "returns true" do - expect(subject.available?(opts)).to be true - end - end - end - - describe "#execute" do - let(:context) { OpenStruct.new(run: false) } - - context "when the command is a noop" do - it "doesn't execute the command" do - expect(context).not_to receive(:instance_exec) - - subject.execute(context, {}, nil) - - expect(context.run).to be false - end - end - - context "when the command is not a noop" do - before do - subject.action_block = proc { self.run = true } - end - - context "when the command is not available" do - before do - subject.condition_block = proc { false } - end - - it "doesn't execute the command" do - subject.execute(context, {}, nil) - - expect(context.run).to be false - end - end - - context "when the command is available" do - context "when the commnd has no arguments" do - before do - subject.action_block = proc { self.run = true } - end - - context "when the command is provided an argument" do - it "executes the command" do - subject.execute(context, {}, true) - - expect(context.run).to be true - end - end - - context "when the command is not provided an argument" do - it "executes the command" do - subject.execute(context, {}, nil) - - expect(context.run).to be true - end - end - end - - context "when the command has 1 required argument" do - before do - subject.action_block = ->(arg) { self.run = arg } - end - - context "when the command is provided an argument" do - it "executes the command" do - subject.execute(context, {}, true) - - expect(context.run).to be true - end - end - - context "when the command is not provided an argument" do - it "doesn't execute the command" do - subject.execute(context, {}, nil) - - expect(context.run).to be false - end - end - end - - context "when the command has 1 optional argument" do - before do - subject.action_block = proc { |arg = nil| self.run = arg || true } - end - - context "when the command is provided an argument" do - it "executes the command" do - subject.execute(context, {}, true) - - expect(context.run).to be true - end - end - - context "when the command is not provided an argument" do - it "executes the command" do - subject.execute(context, {}, nil) - - expect(context.run).to be true - end - end - end - - context 'when the command defines parse_params block' do - before do - subject.parse_params_block = ->(raw) { raw.strip } - subject.action_block = ->(parsed) { self.received_arg = parsed } - end - - it 'executes the command passing the parsed param' do - subject.execute(context, {}, 'something ') - - expect(context.received_arg).to eq('something') - end - end - end - end - end - - describe '#explain' do - context 'when the command is not available' do - before do - subject.condition_block = proc { false } - subject.explanation = 'Explanation' - end - - it 'returns nil' do - result = subject.explain({}, {}, nil) - - expect(result).to be_nil - end - end - - context 'when the explanation is a static string' do - before do - subject.explanation = 'Explanation' - end - - it 'returns this static string' do - result = subject.explain({}, {}, nil) - - expect(result).to eq 'Explanation' - end - end - - context 'when the explanation is dynamic' do - before do - subject.explanation = proc { |arg| "Dynamic #{arg}" } - end - - it 'invokes the proc' do - result = subject.explain({}, {}, 'explanation') - - expect(result).to eq 'Dynamic explanation' - end - end - end -end diff --git a/spec/lib/gitlab/slash_commands/command_spec.rb b/spec/lib/gitlab/slash_commands/command_spec.rb new file mode 100644 index 00000000000..28d7f9858c3 --- /dev/null +++ b/spec/lib/gitlab/slash_commands/command_spec.rb @@ -0,0 +1,111 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Command, service: true do + let(:project) { create(:empty_project) } + let(:user) { create(:user) } + + describe '#execute' do + subject do + described_class.new(project, user, params).execute + end + + context 'when no command is available' do + let(:params) { { text: 'issue show 1' } } + let(:project) { create(:empty_project, has_external_issue_tracker: true) } + + it 'displays 404 messages' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to start_with('404 not found') + end + end + + context 'when an unknown command is triggered' do + let(:params) { { command: '/gitlab', text: "unknown command 123" } } + + it 'displays the help message' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to start_with('Unknown command') + expect(subject[:text]).to match('/gitlab issue show') + end + end + + context 'the user can not create an issue' do + let(:params) { { text: "issue create my new issue" } } + + it 'rejects the actions' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to start_with('Whoops! This action is not allowed') + end + end + + context 'when trying to do deployment' do + let(:params) { { text: 'deploy staging to production' } } + let!(:build) { create(:ci_build, pipeline: pipeline) } + let!(:pipeline) { create(:ci_pipeline, project: project) } + let!(:staging) { create(:environment, name: 'staging', project: project) } + let!(:deployment) { create(:deployment, environment: staging, deployable: build) } + + let!(:manual) do + create(:ci_build, :manual, pipeline: pipeline, + name: 'first', + environment: 'production') + end + + context 'and user can not create deployment' do + it 'returns action' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to start_with('Whoops! This action is not allowed') + end + end + + context 'and user has deployment permission' do + before do + build.project.add_developer(user) + + create(:protected_branch, :developers_can_merge, + name: build.ref, project: project) + end + + it 'returns action' do + expect(subject[:text]).to include('Deployment started from staging to production') + expect(subject[:response_type]).to be(:in_channel) + end + + context 'when duplicate action exists' do + let!(:manual2) do + create(:ci_build, :manual, pipeline: pipeline, + name: 'second', + environment: 'production') + end + + it 'returns error' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to include('Too many actions defined') + end + end + end + end + end + + describe '#match_command' do + subject { described_class.new(project, user, params).match_command.first } + + context 'IssueShow is triggered' do + let(:params) { { text: 'issue show 123' } } + + it { is_expected.to eq(Gitlab::SlashCommands::IssueShow) } + end + + context 'IssueCreate is triggered' do + let(:params) { { text: 'issue create my title' } } + + it { is_expected.to eq(Gitlab::SlashCommands::IssueNew) } + end + + context 'IssueSearch is triggered' do + let(:params) { { text: 'issue search my query' } } + + it { is_expected.to eq(Gitlab::SlashCommands::IssueSearch) } + end + end +end diff --git a/spec/lib/gitlab/slash_commands/deploy_spec.rb b/spec/lib/gitlab/slash_commands/deploy_spec.rb new file mode 100644 index 00000000000..d919f7260db --- /dev/null +++ b/spec/lib/gitlab/slash_commands/deploy_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Deploy, service: true do + describe '#execute' do + let(:project) { create(:empty_project) } + let(:user) { create(:user) } + let(:regex_match) { described_class.match('deploy staging to production') } + + before do + # Make it possible to trigger protected manual actions for developers. + # + project.add_developer(user) + + create(:protected_branch, :developers_can_merge, + name: 'master', project: project) + end + + subject do + described_class.new(project, user).execute(regex_match) + end + + context 'if no environment is defined' do + it 'does not execute an action' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to eq("No action found to be executed") + end + end + + context 'with environment' do + let!(:staging) { create(:environment, name: 'staging', project: project) } + let!(:pipeline) { create(:ci_pipeline, project: project) } + let!(:build) { create(:ci_build, pipeline: pipeline) } + let!(:deployment) { create(:deployment, environment: staging, deployable: build) } + + context 'without actions' do + it 'does not execute an action' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to eq("No action found to be executed") + end + end + + context 'with action' do + let!(:manual1) do + create(:ci_build, :manual, pipeline: pipeline, + name: 'first', + environment: 'production') + end + + it 'returns success result' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject[:text]).to start_with('Deployment started from staging to production') + end + + context 'when duplicate action exists' do + let!(:manual2) do + create(:ci_build, :manual, pipeline: pipeline, + name: 'second', + environment: 'production') + end + + it 'returns error' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to eq('Too many actions defined') + end + end + + context 'when teardown action exists' do + let!(:teardown) do + create(:ci_build, :manual, :teardown_environment, + pipeline: pipeline, name: 'teardown', environment: 'production') + end + + it 'returns the success message' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject[:text]).to start_with('Deployment started from staging to production') + end + end + end + end + end + + describe 'self.match' do + it 'matches the environment' do + match = described_class.match('deploy staging to production') + + expect(match[:from]).to eq('staging') + expect(match[:to]).to eq('production') + end + end +end diff --git a/spec/lib/gitlab/slash_commands/dsl_spec.rb b/spec/lib/gitlab/slash_commands/dsl_spec.rb deleted file mode 100644 index 33b49a5ddf9..00000000000 --- a/spec/lib/gitlab/slash_commands/dsl_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -require 'spec_helper' - -describe Gitlab::SlashCommands::Dsl do - before :all do - DummyClass = Struct.new(:project) do - include Gitlab::SlashCommands::Dsl # rubocop:disable RSpec/DescribedClass - - desc 'A command with no args' - command :no_args, :none do - "Hello World!" - end - - params 'The first argument' - explanation 'Static explanation' - command :explanation_with_aliases, :once, :first do |arg| - arg - end - - desc do - "A dynamic description for #{noteable.upcase}" - end - params 'The first argument', 'The second argument' - command :dynamic_description do |args| - args.split - end - - command :cc - - explanation do |arg| - "Action does something with #{arg}" - end - condition do - project == 'foo' - end - command :cond_action do |arg| - arg - end - - parse_params do |raw_arg| - raw_arg.strip - end - command :with_params_parsing do |parsed| - parsed - end - end - end - - describe '.command_definitions' do - it 'returns an array with commands definitions' do - no_args_def, explanation_with_aliases_def, dynamic_description_def, - cc_def, cond_action_def, with_params_parsing_def = - DummyClass.command_definitions - - expect(no_args_def.name).to eq(:no_args) - expect(no_args_def.aliases).to eq([:none]) - expect(no_args_def.description).to eq('A command with no args') - expect(no_args_def.explanation).to eq('') - expect(no_args_def.params).to eq([]) - expect(no_args_def.condition_block).to be_nil - expect(no_args_def.action_block).to be_a_kind_of(Proc) - expect(no_args_def.parse_params_block).to be_nil - - expect(explanation_with_aliases_def.name).to eq(:explanation_with_aliases) - expect(explanation_with_aliases_def.aliases).to eq([:once, :first]) - expect(explanation_with_aliases_def.description).to eq('') - expect(explanation_with_aliases_def.explanation).to eq('Static explanation') - expect(explanation_with_aliases_def.params).to eq(['The first argument']) - expect(explanation_with_aliases_def.condition_block).to be_nil - expect(explanation_with_aliases_def.action_block).to be_a_kind_of(Proc) - expect(explanation_with_aliases_def.parse_params_block).to be_nil - - expect(dynamic_description_def.name).to eq(:dynamic_description) - expect(dynamic_description_def.aliases).to eq([]) - expect(dynamic_description_def.to_h(noteable: 'issue')[:description]).to eq('A dynamic description for ISSUE') - expect(dynamic_description_def.explanation).to eq('') - expect(dynamic_description_def.params).to eq(['The first argument', 'The second argument']) - expect(dynamic_description_def.condition_block).to be_nil - expect(dynamic_description_def.action_block).to be_a_kind_of(Proc) - expect(dynamic_description_def.parse_params_block).to be_nil - - expect(cc_def.name).to eq(:cc) - expect(cc_def.aliases).to eq([]) - expect(cc_def.description).to eq('') - expect(cc_def.explanation).to eq('') - expect(cc_def.params).to eq([]) - expect(cc_def.condition_block).to be_nil - expect(cc_def.action_block).to be_nil - expect(cc_def.parse_params_block).to be_nil - - expect(cond_action_def.name).to eq(:cond_action) - expect(cond_action_def.aliases).to eq([]) - expect(cond_action_def.description).to eq('') - expect(cond_action_def.explanation).to be_a_kind_of(Proc) - expect(cond_action_def.params).to eq([]) - expect(cond_action_def.condition_block).to be_a_kind_of(Proc) - expect(cond_action_def.action_block).to be_a_kind_of(Proc) - expect(cond_action_def.parse_params_block).to be_nil - - expect(with_params_parsing_def.name).to eq(:with_params_parsing) - expect(with_params_parsing_def.aliases).to eq([]) - expect(with_params_parsing_def.description).to eq('') - expect(with_params_parsing_def.explanation).to eq('') - expect(with_params_parsing_def.params).to eq([]) - expect(with_params_parsing_def.condition_block).to be_nil - expect(with_params_parsing_def.action_block).to be_a_kind_of(Proc) - expect(with_params_parsing_def.parse_params_block).to be_a_kind_of(Proc) - end - end -end diff --git a/spec/lib/gitlab/slash_commands/extractor_spec.rb b/spec/lib/gitlab/slash_commands/extractor_spec.rb deleted file mode 100644 index d7f77486b3e..00000000000 --- a/spec/lib/gitlab/slash_commands/extractor_spec.rb +++ /dev/null @@ -1,223 +0,0 @@ -require 'spec_helper' - -describe Gitlab::SlashCommands::Extractor do - let(:definitions) do - Class.new do - include Gitlab::SlashCommands::Dsl - - command(:reopen, :open) { } - command(:assign) { } - command(:labels) { } - command(:power) { } - end.command_definitions - end - - let(:extractor) { described_class.new(definitions) } - - shared_examples 'command with no argument' do - it 'extracts command' do - msg, commands = extractor.extract_commands(original_msg) - - expect(commands).to eq [['reopen']] - expect(msg).to eq final_msg - end - end - - shared_examples 'command with a single argument' do - it 'extracts command' do - msg, commands = extractor.extract_commands(original_msg) - - expect(commands).to eq [['assign', '@joe']] - expect(msg).to eq final_msg - end - end - - shared_examples 'command with multiple arguments' do - it 'extracts command' do - msg, commands = extractor.extract_commands(original_msg) - - expect(commands).to eq [['labels', '~foo ~"bar baz" label']] - expect(msg).to eq final_msg - end - end - - describe '#extract_commands' do - describe 'command with no argument' do - context 'at the start of content' do - it_behaves_like 'command with no argument' do - let(:original_msg) { "/reopen\nworld" } - let(:final_msg) { "world" } - end - end - - context 'in the middle of content' do - it_behaves_like 'command with no argument' do - let(:original_msg) { "hello\n/reopen\nworld" } - let(:final_msg) { "hello\nworld" } - end - end - - context 'in the middle of a line' do - it 'does not extract command' do - msg = "hello\nworld /reopen" - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq "hello\nworld /reopen" - end - end - - context 'at the end of content' do - it_behaves_like 'command with no argument' do - let(:original_msg) { "hello\n/reopen" } - let(:final_msg) { "hello" } - end - end - end - - describe 'command with a single argument' do - context 'at the start of content' do - it_behaves_like 'command with a single argument' do - let(:original_msg) { "/assign @joe\nworld" } - let(:final_msg) { "world" } - end - - it 'allows slash in command arguments' do - msg = "/assign @joe / @jane\nworld" - msg, commands = extractor.extract_commands(msg) - - expect(commands).to eq [['assign', '@joe / @jane']] - expect(msg).to eq 'world' - end - end - - context 'in the middle of content' do - it_behaves_like 'command with a single argument' do - let(:original_msg) { "hello\n/assign @joe\nworld" } - let(:final_msg) { "hello\nworld" } - end - end - - context 'in the middle of a line' do - it 'does not extract command' do - msg = "hello\nworld /assign @joe" - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq "hello\nworld /assign @joe" - end - end - - context 'at the end of content' do - it_behaves_like 'command with a single argument' do - let(:original_msg) { "hello\n/assign @joe" } - let(:final_msg) { "hello" } - end - end - - context 'when argument is not separated with a space' do - it 'does not extract command' do - msg = "hello\n/assign@joe\nworld" - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq "hello\n/assign@joe\nworld" - end - end - end - - describe 'command with multiple arguments' do - context 'at the start of content' do - it_behaves_like 'command with multiple arguments' do - let(:original_msg) { %(/labels ~foo ~"bar baz" label\nworld) } - let(:final_msg) { "world" } - end - end - - context 'in the middle of content' do - it_behaves_like 'command with multiple arguments' do - let(:original_msg) { %(hello\n/labels ~foo ~"bar baz" label\nworld) } - let(:final_msg) { "hello\nworld" } - end - end - - context 'in the middle of a line' do - it 'does not extract command' do - msg = %(hello\nworld /labels ~foo ~"bar baz" label) - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq %(hello\nworld /labels ~foo ~"bar baz" label) - end - end - - context 'at the end of content' do - it_behaves_like 'command with multiple arguments' do - let(:original_msg) { %(hello\n/labels ~foo ~"bar baz" label) } - let(:final_msg) { "hello" } - end - end - - context 'when argument is not separated with a space' do - it 'does not extract command' do - msg = %(hello\n/labels~foo ~"bar baz" label\nworld) - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq %(hello\n/labels~foo ~"bar baz" label\nworld) - end - end - end - - it 'extracts command with multiple arguments and various prefixes' do - msg = %(hello\n/power @user.name %9.10 ~"bar baz.2"\nworld) - msg, commands = extractor.extract_commands(msg) - - expect(commands).to eq [['power', '@user.name %9.10 ~"bar baz.2"']] - expect(msg).to eq "hello\nworld" - end - - it 'extracts multiple commands' do - msg = %(hello\n/power @user.name %9.10 ~"bar baz.2" label\nworld\n/reopen) - msg, commands = extractor.extract_commands(msg) - - expect(commands).to eq [['power', '@user.name %9.10 ~"bar baz.2" label'], ['reopen']] - expect(msg).to eq "hello\nworld" - end - - it 'does not alter original content if no command is found' do - msg = 'Fixes #123' - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq 'Fixes #123' - end - - it 'does not extract commands inside a blockcode' do - msg = "Hello\r\n```\r\nThis is some text\r\n/close\r\n/assign @user\r\n```\r\n\r\nWorld" - expected = msg.delete("\r") - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq expected - end - - it 'does not extract commands inside a blockquote' do - msg = "Hello\r\n>>>\r\nThis is some text\r\n/close\r\n/assign @user\r\n>>>\r\n\r\nWorld" - expected = msg.delete("\r") - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq expected - end - - it 'does not extract commands inside a HTML tag' do - msg = "Hello\r\n
\r\nThis is some text\r\n/close\r\n/assign @user\r\n
\r\n\r\nWorld" - expected = msg.delete("\r") - msg, commands = extractor.extract_commands(msg) - - expect(commands).to be_empty - expect(msg).to eq expected - end - end -end diff --git a/spec/lib/gitlab/slash_commands/issue_new_spec.rb b/spec/lib/gitlab/slash_commands/issue_new_spec.rb new file mode 100644 index 00000000000..4de50d4a8bb --- /dev/null +++ b/spec/lib/gitlab/slash_commands/issue_new_spec.rb @@ -0,0 +1,78 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::IssueNew, service: true do + describe '#execute' do + let(:project) { create(:empty_project) } + let(:user) { create(:user) } + let(:regex_match) { described_class.match("issue create bird is the word") } + + before do + project.team << [user, :master] + end + + subject do + described_class.new(project, user).execute(regex_match) + end + + context 'without description' do + it 'creates the issue' do + expect { subject }.to change { project.issues.count }.by(1) + + expect(subject[:response_type]).to be(:in_channel) + end + end + + context 'with description' do + let(:description) { "Surfin bird" } + let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") } + + it 'creates the issue with description' do + subject + + expect(Issue.last.description).to eq(description) + end + end + + context "with more newlines between the title and the description" do + let(:description) { "Surfin bird" } + let(:regex_match) { described_class.match("issue create bird is the word\n\n#{description}\n") } + + it 'creates the issue' do + expect { subject }.to change { project.issues.count }.by(1) + end + end + + context 'issue cannot be created' do + let!(:issue) { create(:issue, project: project, title: 'bird is the word') } + let(:regex_match) { described_class.match("issue create #{'a' * 512}}") } + + it 'displays the errors' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to match("- Title is too long") + end + end + end + + describe '.match' do + it 'matches the title without description' do + match = described_class.match("issue create my title") + + expect(match[:title]).to eq('my title') + expect(match[:description]).to eq("") + end + + it 'matches the title with description' do + match = described_class.match("issue create my title\n\ndescription") + + expect(match[:title]).to eq('my title') + expect(match[:description]).to eq('description') + end + + it 'matches the alias new' do + match = described_class.match("issue new my title") + + expect(match).not_to be_nil + expect(match[:title]).to eq('my title') + end + end +end diff --git a/spec/lib/gitlab/slash_commands/issue_search_spec.rb b/spec/lib/gitlab/slash_commands/issue_search_spec.rb new file mode 100644 index 00000000000..06fff0afc50 --- /dev/null +++ b/spec/lib/gitlab/slash_commands/issue_search_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::IssueSearch, service: true do + describe '#execute' do + let!(:issue) { create(:issue, project: project, title: 'find me') } + let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') } + let(:project) { create(:empty_project) } + let(:user) { issue.author } + let(:regex_match) { described_class.match("issue search find") } + + subject do + described_class.new(project, user).execute(regex_match) + end + + context 'when the user has no access' do + it 'only returns the open issues' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to match("not found") + end + end + + context 'the user has access' do + before do + project.team << [user, :master] + end + + it 'returns all results' do + expect(subject).to have_key(:attachments) + expect(subject[:text]).to eq("Here are the 2 issues I found:") + end + end + + context 'without hits on the query' do + it 'returns an empty collection' do + expect(subject[:text]).to match("not found") + end + end + end + + describe 'self.match' do + let(:query) { "my search keywords" } + it 'matches the query' do + match = described_class.match("issue search #{query}") + + expect(match[:query]).to eq(query) + end + end +end diff --git a/spec/lib/gitlab/slash_commands/issue_show_spec.rb b/spec/lib/gitlab/slash_commands/issue_show_spec.rb new file mode 100644 index 00000000000..1899f664ccd --- /dev/null +++ b/spec/lib/gitlab/slash_commands/issue_show_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::IssueShow, service: true do + describe '#execute' do + let(:issue) { create(:issue, project: project) } + let(:project) { create(:empty_project) } + let(:user) { issue.author } + let(:regex_match) { described_class.match("issue show #{issue.iid}") } + + before do + project.team << [user, :master] + end + + subject do + described_class.new(project, user).execute(regex_match) + end + + context 'the issue exists' do + let(:title) { subject[:attachments].first[:title] } + + it 'returns the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(title).to start_with(issue.title) + end + + context 'when its reference is given' do + let(:regex_match) { described_class.match("issue show #{issue.to_reference}") } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(title).to start_with(issue.title) + end + end + end + + context 'the issue does not exist' do + let(:regex_match) { described_class.match("issue show 2343242") } + + it "returns not found" do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to match("not found") + end + end + end + + describe '.match' do + it 'matches the iid' do + match = described_class.match("issue show 123") + + expect(match[:iid]).to eq("123") + end + + it 'accepts a reference' do + match = described_class.match("issue show #{Issue.reference_prefix}123") + + expect(match[:iid]).to eq("123") + end + end +end diff --git a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb new file mode 100644 index 00000000000..ef3d217f7be --- /dev/null +++ b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Presenters::Access do + describe '#access_denied' do + subject { described_class.new.access_denied } + + it { is_expected.to be_a(Hash) } + + it 'displays an error message' do + expect(subject[:text]).to match("is not allowed") + expect(subject[:response_type]).to be(:ephemeral) + end + end + + describe '#not_found' do + subject { described_class.new.not_found } + + it { is_expected.to be_a(Hash) } + + it 'tells the user the resource was not found' do + expect(subject[:text]).to match("not found!") + expect(subject[:response_type]).to be(:ephemeral) + end + end + + describe '#authorize' do + context 'with an authorization URL' do + subject { described_class.new('http://authorize.me').authorize } + + it { is_expected.to be_a(Hash) } + + it 'tells the user to authorize' do + expect(subject[:text]).to match("connect your GitLab account") + expect(subject[:response_type]).to be(:ephemeral) + end + end + + context 'without authorization url' do + subject { described_class.new.authorize } + + it { is_expected.to be_a(Hash) } + + it 'tells the user to authorize' do + expect(subject[:text]).to match("Couldn't identify you") + expect(subject[:response_type]).to be(:ephemeral) + end + end + end +end diff --git a/spec/lib/gitlab/slash_commands/presenters/deploy_spec.rb b/spec/lib/gitlab/slash_commands/presenters/deploy_spec.rb new file mode 100644 index 00000000000..dee3c77db27 --- /dev/null +++ b/spec/lib/gitlab/slash_commands/presenters/deploy_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Presenters::Deploy do + let(:build) { create(:ci_build) } + + describe '#present' do + subject { described_class.new(build).present('staging', 'prod') } + + it { is_expected.to have_key(:text) } + it { is_expected.to have_key(:response_type) } + it { is_expected.to have_key(:status) } + it { is_expected.not_to have_key(:attachments) } + + it 'messages the channel of the deploy' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject[:text]).to start_with("Deployment started from staging to prod") + end + end + + describe '#no_actions' do + subject { described_class.new(nil).no_actions } + + it { is_expected.to have_key(:text) } + it { is_expected.to have_key(:response_type) } + it { is_expected.to have_key(:status) } + it { is_expected.not_to have_key(:attachments) } + + it 'tells the user there is no action' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to eq("No action found to be executed") + end + end + + describe '#too_many_actions' do + subject { described_class.new([]).too_many_actions } + + it { is_expected.to have_key(:text) } + it { is_expected.to have_key(:response_type) } + it { is_expected.to have_key(:status) } + it { is_expected.not_to have_key(:attachments) } + + it 'tells the user there is no action' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to eq("Too many actions defined") + end + end +end diff --git a/spec/lib/gitlab/slash_commands/presenters/issue_new_spec.rb b/spec/lib/gitlab/slash_commands/presenters/issue_new_spec.rb new file mode 100644 index 00000000000..7f81ebb47db --- /dev/null +++ b/spec/lib/gitlab/slash_commands/presenters/issue_new_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Presenters::IssueNew do + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:attachment) { subject[:attachments].first } + + subject { described_class.new(issue).present } + + it { is_expected.to be_a(Hash) } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject).to have_key(:attachments) + expect(attachment[:title]).to start_with(issue.title) + end +end diff --git a/spec/lib/gitlab/slash_commands/presenters/issue_search_spec.rb b/spec/lib/gitlab/slash_commands/presenters/issue_search_spec.rb new file mode 100644 index 00000000000..7e57a0addcb --- /dev/null +++ b/spec/lib/gitlab/slash_commands/presenters/issue_search_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Presenters::IssueSearch do + let(:project) { create(:empty_project) } + let(:message) { subject[:text] } + + before do + create_list(:issue, 2, project: project) + end + + subject { described_class.new(project.issues).present } + + it 'formats the message correct' do + is_expected.to have_key(:text) + is_expected.to have_key(:status) + is_expected.to have_key(:response_type) + is_expected.to have_key(:attachments) + end + + it 'shows a list of results' do + expect(subject[:response_type]).to be(:ephemeral) + + expect(message).to start_with("Here are the 2 issues I found") + end +end diff --git a/spec/lib/gitlab/slash_commands/presenters/issue_show_spec.rb b/spec/lib/gitlab/slash_commands/presenters/issue_show_spec.rb new file mode 100644 index 00000000000..2a6ed860737 --- /dev/null +++ b/spec/lib/gitlab/slash_commands/presenters/issue_show_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe Gitlab::SlashCommands::Presenters::IssueShow do + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:attachment) { subject[:attachments].first } + + subject { described_class.new(issue).present } + + it { is_expected.to be_a(Hash) } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject).to have_key(:attachments) + expect(attachment[:title]).to start_with(issue.title) + end + + context 'with upvotes' do + before do + create(:award_emoji, :upvote, awardable: issue) + end + + it 'shows the upvote count' do + expect(subject[:response_type]).to be(:in_channel) + expect(attachment[:text]).to start_with("**Open** · :+1: 1") + end + end + + context 'with labels' do + let(:label) { create(:label, project: project, title: 'mep') } + let(:label1) { create(:label, project: project, title: 'mop') } + + before do + issue.labels << [label, label1] + end + + it 'shows the labels' do + labels = attachment[:fields].find { |f| f[:title] == 'Labels' } + + expect(labels[:value]).to eq("mep, mop") + end + end + + context 'confidential issue' do + let(:issue) { create(:issue, project: project) } + + it 'shows an ephemeral response' do + expect(subject[:response_type]).to be(:in_channel) + expect(attachment[:text]).to start_with("**Open**") + end + end +end -- cgit v1.2.1 From d29347220c07ab0191cf208d3775475c7b5d71ca Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 13 Jun 2017 16:44:55 +0200 Subject: Refactor ProjectsFinder#init_collection This changes ProjectsFinder#init_collection so it no longer relies on a UNION. For example, to get starred projects of a user we used to run: SELECT projects.* FROM projects WHERE projects.pending_delete = 'f' AND ( projects.id IN ( SELECT projects.id FROM projects INNER JOIN users_star_projects ON users_star_projects.project_id = projects.id INNER JOIN project_authorizations ON projects.id = project_authorizations.project_id WHERE projects.pending_delete = 'f' AND project_authorizations.user_id = 1 AND users_star_projects.user_id = 1 UNION SELECT projects.id FROM projects INNER JOIN users_star_projects ON users_star_projects.project_id = projects.id WHERE projects.visibility_level IN (20, 10) AND users_star_projects.user_id = 1 ) ) ORDER BY projects.id DESC; With these changes the above query is turned into the following instead: SELECT projects.* FROM projects INNER JOIN users_star_projects ON users_star_projects.project_id = projects.id WHERE projects.pending_delete = 'f' AND ( EXISTS ( SELECT 1 FROM project_authorizations WHERE project_authorizations.user_id = 1 AND (project_id = projects.id) ) OR projects.visibility_level IN (20,10) ) AND users_star_projects.user_id = 1 ORDER BY projects.id DESC; This query in turn produces a better execution plan and takes less time, though the difference is only a few milliseconds (this however depends on the amount of data involved and additional conditions that may be added). --- spec/lib/gitlab/visibility_level_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/visibility_level_spec.rb b/spec/lib/gitlab/visibility_level_spec.rb index 3255c6f1ef7..a8f21803ec7 100644 --- a/spec/lib/gitlab/visibility_level_spec.rb +++ b/spec/lib/gitlab/visibility_level_spec.rb @@ -18,4 +18,35 @@ describe Gitlab::VisibilityLevel, lib: true do expect(described_class.level_value(100)).to eq(Gitlab::VisibilityLevel::PRIVATE) end end + + describe '.levels_for_user' do + it 'returns all levels for an admin' do + user = double(:user, admin?: true) + + expect(described_class.levels_for_user(user)). + to eq([Gitlab::VisibilityLevel::PRIVATE, + Gitlab::VisibilityLevel::INTERNAL, + Gitlab::VisibilityLevel::PUBLIC]) + end + + it 'returns INTERNAL and PUBLIC for internal users' do + user = double(:user, admin?: false, external?: false) + + expect(described_class.levels_for_user(user)). + to eq([Gitlab::VisibilityLevel::INTERNAL, + Gitlab::VisibilityLevel::PUBLIC]) + end + + it 'returns PUBLIC for external users' do + user = double(:user, admin?: false, external?: true) + + expect(described_class.levels_for_user(user)). + to eq([Gitlab::VisibilityLevel::PUBLIC]) + end + + it 'returns PUBLIC when no user is given' do + expect(described_class.levels_for_user). + to eq([Gitlab::VisibilityLevel::PUBLIC]) + end + end end -- cgit v1.2.1 From b97d5b65dd40fb5d8753c0677534e82cb5636f2d Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Fri, 16 Jun 2017 14:23:33 +0200 Subject: Use include ActiveModel::Model to hold metrics data parsed from yaml. --- .../prometheus/additional_metrics_parser_spec.rb | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb b/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb index 97280de173e..f8b2746b43d 100644 --- a/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb +++ b/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb @@ -26,7 +26,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do priority: 1 metrics: - title: title - required_metrics: [] + required_metrics: ['metric_a'] weight: 1 queries: [{query_range: query_range_a}] EOF @@ -54,7 +54,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do expect(metrics.count).to eq(3) expect(metrics[0]).to have_attributes(title: 'title', required_metrics: %w(metric_a metric_b), weight: 1) expect(metrics[1]).to have_attributes(title: 'title', required_metrics: %w(metric_a), weight: 1) - expect(metrics[2]).to have_attributes(title: 'title', required_metrics: [], weight: 1) + expect(metrics[2]).to have_attributes(title: 'title', required_metrics: %w{metric_a}, weight: 1) end it 'provides query data' do @@ -78,7 +78,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end it 'throws parsing error' do - expect { subject }.to raise_error(parser_error_class, /missing.*#{field_name}/) + expect { subject }.to raise_error(parser_error_class, /#{field_name} can't be blank/i) end end @@ -88,13 +88,13 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end it 'throws parsing error' do - expect { subject }.to raise_error(parser_error_class, /missing.*#{field_name}/) + expect { subject }.to raise_error(parser_error_class, /#{field_name} can't be blank/i) end end end describe 'group required fields' do - it_behaves_like 'required field', :metrics do + it_behaves_like 'required field', 'metrics' do let(:field_nil) do <<-EOF.strip_heredoc - group: group_a @@ -111,10 +111,11 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end end - it_behaves_like 'required field', :group do + it_behaves_like 'required field', 'name' do let(:field_nil) do <<-EOF.strip_heredoc - - priority: 1 + - group: + priority: 1 metrics: [] EOF end @@ -127,7 +128,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end end - it_behaves_like 'required field', :priority do + it_behaves_like 'required field', 'priority' do let(:field_nil) do <<-EOF.strip_heredoc - group: group_a @@ -146,7 +147,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end describe 'metrics fields parsing' do - it_behaves_like 'required field', :title do + it_behaves_like 'required field', 'title' do let(:field_nil) do <<-EOF.strip_heredoc - group: group_a @@ -171,7 +172,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end end - it_behaves_like 'required field', :required_metrics do + it_behaves_like 'required field', 'required metrics' do let(:field_nil) do <<-EOF.strip_heredoc - group: group_a @@ -196,7 +197,7 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end end - it_behaves_like 'required field', :weight do + it_behaves_like 'required field', 'weight' do let(:field_nil) do <<-EOF.strip_heredoc - group: group_a -- cgit v1.2.1 From 9a73b634ab4220f68a8296ccb582a68293874489 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 9 Jun 2017 12:48:25 +0100 Subject: Add table for files in merge request diffs This adds an ID-less table containing one row per file, per merge request diff. It has a column for each attribute on Gitlab::Git::Diff that is serialised currently, with the advantage that we can easily query the attributes of this new table. It does not migrate existing data, so we have fallback code when the legacy st_diffs column is present instead. For a merge request diff to be valid, it should have at most one of: * Rows in this new table, with the correct merge_request_diff_id. * A non-NULL st_diffs column. It may have neither, if the diff is empty. --- spec/lib/gitlab/database_spec.rb | 49 ++++++++++++++++++++++ spec/lib/gitlab/git/diff_spec.rb | 2 +- spec/lib/gitlab/import_export/all_models.yml | 3 ++ spec/lib/gitlab/import_export/project.json | 38 ++++++++++++----- .../import_export/project_tree_restorer_spec.rb | 7 +++- .../import_export/project_tree_saver_spec.rb | 10 +++++ .../gitlab/import_export/safe_model_attributes.yml | 11 +++++ 7 files changed, 108 insertions(+), 12 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 26e5d73d333..428b6edb7d6 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -129,6 +129,55 @@ describe Gitlab::Database, lib: true do end end + describe '.bulk_insert' do + before do + allow(described_class).to receive(:connection).and_return(connection) + allow(connection).to receive(:quote_column_name, &:itself) + allow(connection).to receive(:quote, &:itself) + allow(connection).to receive(:execute) + end + + let(:connection) { double(:connection) } + + let(:rows) do + [ + { a: 1, b: 2, c: 3 }, + { c: 6, a: 4, b: 5 } + ] + end + + it 'does nothing with empty rows' do + expect(connection).not_to receive(:execute) + + described_class.bulk_insert('test', []) + end + + it 'uses the ordering from the first row' do + expect(connection).to receive(:execute) do |sql| + expect(sql).to include('(1, 2, 3)') + expect(sql).to include('(4, 5, 6)') + end + + described_class.bulk_insert('test', rows) + end + + it 'quotes column names' do + expect(connection).to receive(:quote_column_name).with(:a) + expect(connection).to receive(:quote_column_name).with(:b) + expect(connection).to receive(:quote_column_name).with(:c) + + described_class.bulk_insert('test', rows) + end + + it 'quotes values' do + 1.upto(6) do |i| + expect(connection).to receive(:quote).with(i) + end + + described_class.bulk_insert('test', rows) + end + end + describe '.create_connection_pool' do it 'creates a new connection pool with specific pool size' do pool = described_class.create_connection_pool(5) diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb index da213f617cc..78d741f0110 100644 --- a/spec/lib/gitlab/git/diff_spec.rb +++ b/spec/lib/gitlab/git/diff_spec.rb @@ -90,7 +90,7 @@ EOT let(:diff) { described_class.new(@rugged_diff) } it 'initializes the diff' do - expect(diff.to_hash).to eq(@raw_diff_hash.merge(too_large: nil)) + expect(diff.to_hash).to eq(@raw_diff_hash) end it 'does not prune the diff' do diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 412eb33b35b..a5f09f1856e 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -88,6 +88,9 @@ merge_requests: - head_pipeline merge_request_diff: - merge_request +- merge_request_diff_files +merge_request_diff_files: +- merge_request_diff pipelines: - project - user diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json index e3599d6fe59..98c117b4cd8 100644 --- a/spec/lib/gitlab/import_export/project.json +++ b/spec/lib/gitlab/import_export/project.json @@ -2821,9 +2821,11 @@ "committer_email": "dmitriy.zaporozhets@gmail.com" } ], - "utf8_st_diffs": [ + "merge_request_diff_files": [ { - "diff": "Binary files a/.DS_Store and /dev/null differ\n", + "merge_request_diff_id": 27, + "relative_order": 0, + "utf8_diff": "Binary files a/.DS_Store and /dev/null differ\n", "new_path": ".DS_Store", "old_path": ".DS_Store", "a_mode": "100644", @@ -2834,7 +2836,9 @@ "too_large": false }, { - "diff": "--- a/.gitignore\n+++ b/.gitignore\n@@ -17,3 +17,4 @@ rerun.txt\n pickle-email-*.html\n .project\n config/initializers/secret_token.rb\n+.DS_Store\n", + "merge_request_diff_id": 27, + "relative_order": 1, + "utf8_diff": "--- a/.gitignore\n+++ b/.gitignore\n@@ -17,3 +17,4 @@ rerun.txt\n pickle-email-*.html\n .project\n config/initializers/secret_token.rb\n+.DS_Store\n", "new_path": ".gitignore", "old_path": ".gitignore", "a_mode": "100644", @@ -2845,7 +2849,9 @@ "too_large": false }, { - "diff": "--- a/.gitmodules\n+++ b/.gitmodules\n@@ -1,3 +1,9 @@\n [submodule \"six\"]\n \tpath = six\n \turl = git://github.com/randx/six.git\n+[submodule \"gitlab-shell\"]\n+\tpath = gitlab-shell\n+\turl = https://github.com/gitlabhq/gitlab-shell.git\n+[submodule \"gitlab-grack\"]\n+\tpath = gitlab-grack\n+\turl = https://gitlab.com/gitlab-org/gitlab-grack.git\n", + "merge_request_diff_id": 27, + "relative_order": 2, + "utf8_diff": "--- a/.gitmodules\n+++ b/.gitmodules\n@@ -1,3 +1,9 @@\n [submodule \"six\"]\n \tpath = six\n \turl = git://github.com/randx/six.git\n+[submodule \"gitlab-shell\"]\n+\tpath = gitlab-shell\n+\turl = https://github.com/gitlabhq/gitlab-shell.git\n+[submodule \"gitlab-grack\"]\n+\tpath = gitlab-grack\n+\turl = https://gitlab.com/gitlab-org/gitlab-grack.git\n", "new_path": ".gitmodules", "old_path": ".gitmodules", "a_mode": "100644", @@ -2856,7 +2862,9 @@ "too_large": false }, { - "diff": "Binary files a/files/.DS_Store and /dev/null differ\n", + "merge_request_diff_id": 27, + "relative_order": 3, + "utf8_diff": "Binary files a/files/.DS_Store and /dev/null differ\n", "new_path": "files/.DS_Store", "old_path": "files/.DS_Store", "a_mode": "100644", @@ -2867,7 +2875,9 @@ "too_large": false }, { - "diff": "--- /dev/null\n+++ b/files/ruby/feature.rb\n@@ -0,0 +1,4 @@\n+# This file was changed in feature branch\n+# We put different code here to make merge conflict\n+class Conflict\n+end\n", + "merge_request_diff_id": 27, + "relative_order": 4, + "utf8_diff": "--- /dev/null\n+++ b/files/ruby/feature.rb\n@@ -0,0 +1,4 @@\n+# This file was changed in feature branch\n+# We put different code here to make merge conflict\n+class Conflict\n+end\n", "new_path": "files/ruby/feature.rb", "old_path": "files/ruby/feature.rb", "a_mode": "0", @@ -2878,7 +2888,9 @@ "too_large": false }, { - "diff": "--- a/files/ruby/popen.rb\n+++ b/files/ruby/popen.rb\n@@ -6,12 +6,18 @@ module Popen\n \n def popen(cmd, path=nil)\n unless cmd.is_a?(Array)\n- raise \"System commands must be given as an array of strings\"\n+ raise RuntimeError, \"System commands must be given as an array of strings\"\n end\n \n path ||= Dir.pwd\n- vars = { \"PWD\" =\u003e path }\n- options = { chdir: path }\n+\n+ vars = {\n+ \"PWD\" =\u003e path\n+ }\n+\n+ options = {\n+ chdir: path\n+ }\n \n unless File.directory?(path)\n FileUtils.mkdir_p(path)\n@@ -19,6 +25,7 @@ module Popen\n \n @cmd_output = \"\"\n @cmd_status = 0\n+\n Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|\n @cmd_output \u003c\u003c stdout.read\n @cmd_output \u003c\u003c stderr.read\n", + "merge_request_diff_id": 27, + "relative_order": 5, + "utf8_diff": "--- a/files/ruby/popen.rb\n+++ b/files/ruby/popen.rb\n@@ -6,12 +6,18 @@ module Popen\n \n def popen(cmd, path=nil)\n unless cmd.is_a?(Array)\n- raise \"System commands must be given as an array of strings\"\n+ raise RuntimeError, \"System commands must be given as an array of strings\"\n end\n \n path ||= Dir.pwd\n- vars = { \"PWD\" =\u003e path }\n- options = { chdir: path }\n+\n+ vars = {\n+ \"PWD\" =\u003e path\n+ }\n+\n+ options = {\n+ chdir: path\n+ }\n \n unless File.directory?(path)\n FileUtils.mkdir_p(path)\n@@ -19,6 +25,7 @@ module Popen\n \n @cmd_output = \"\"\n @cmd_status = 0\n+\n Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|\n @cmd_output \u003c\u003c stdout.read\n @cmd_output \u003c\u003c stderr.read\n", "new_path": "files/ruby/popen.rb", "old_path": "files/ruby/popen.rb", "a_mode": "100644", @@ -2889,7 +2901,9 @@ "too_large": false }, { - "diff": "--- a/files/ruby/regex.rb\n+++ b/files/ruby/regex.rb\n@@ -19,14 +19,12 @@ module Gitlab\n end\n \n def archive_formats_regex\n- #|zip|tar| tar.gz | tar.bz2 |\n- /(zip|tar|tar\\.gz|tgz|gz|tar\\.bz2|tbz|tbz2|tb2|bz2)/\n+ /(zip|tar|7z|tar\\.gz|tgz|gz|tar\\.bz2|tbz|tbz2|tb2|bz2)/\n end\n \n def git_reference_regex\n # Valid git ref regex, see:\n # https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html\n-\n %r{\n (?!\n (?# doesn't begins with)\n", + "merge_request_diff_id": 27, + "relative_order": 6, + "utf8_diff": "--- a/files/ruby/regex.rb\n+++ b/files/ruby/regex.rb\n@@ -19,14 +19,12 @@ module Gitlab\n end\n \n def archive_formats_regex\n- #|zip|tar| tar.gz | tar.bz2 |\n- /(zip|tar|tar\\.gz|tgz|gz|tar\\.bz2|tbz|tbz2|tb2|bz2)/\n+ /(zip|tar|7z|tar\\.gz|tgz|gz|tar\\.bz2|tbz|tbz2|tb2|bz2)/\n end\n \n def git_reference_regex\n # Valid git ref regex, see:\n # https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html\n-\n %r{\n (?!\n (?# doesn't begins with)\n", "new_path": "files/ruby/regex.rb", "old_path": "files/ruby/regex.rb", "a_mode": "100644", @@ -2900,7 +2914,9 @@ "too_large": false }, { - "diff": "--- /dev/null\n+++ b/gitlab-grack\n@@ -0,0 +1 @@\n+Subproject commit 645f6c4c82fd3f5e06f67134450a570b795e55a6\n", + "merge_request_diff_id": 27, + "relative_order": 7, + "utf8_diff": "--- /dev/null\n+++ b/gitlab-grack\n@@ -0,0 +1 @@\n+Subproject commit 645f6c4c82fd3f5e06f67134450a570b795e55a6\n", "new_path": "gitlab-grack", "old_path": "gitlab-grack", "a_mode": "0", @@ -2911,7 +2927,9 @@ "too_large": false }, { - "diff": "--- /dev/null\n+++ b/gitlab-shell\n@@ -0,0 +1 @@\n+Subproject commit 79bceae69cb5750d6567b223597999bfa91cb3b9\n", + "merge_request_diff_id": 27, + "relative_order": 8, + "utf8_diff": "--- /dev/null\n+++ b/gitlab-shell\n@@ -0,0 +1 @@\n+Subproject commit 79bceae69cb5750d6567b223597999bfa91cb3b9\n", "new_path": "gitlab-shell", "old_path": "gitlab-shell", "a_mode": "0", diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 14338515892..c11b15a811b 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -86,8 +86,13 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do it 'has the correct data for merge request st_diffs' do # makes sure we are renaming the custom method +utf8_st_diffs+ into +st_diffs+ + # one MergeRequestDiff uses the new format, where st_diffs is expected to be nil - expect(MergeRequestDiff.where.not(st_diffs: nil).count).to eq(9) + expect(MergeRequestDiff.where.not(st_diffs: nil).count).to eq(8) + end + + it 'has the correct data for merge request diff files' do + expect(MergeRequestDiffFile.where.not(diff: nil).count).to eq(9) end it 'has the correct time for merge request st_commits' do diff --git a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb index 5aeb29b7fec..e52f79513f1 100644 --- a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb @@ -83,6 +83,10 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do expect(saved_project_json['merge_requests'].first['merge_request_diff']['utf8_st_diffs']).not_to be_nil end + it 'has merge request diff files' do + expect(saved_project_json['merge_requests'].first['merge_request_diff']['merge_request_diff_files']).not_to be_empty + end + it 'has merge requests comments' do expect(saved_project_json['merge_requests'].first['notes']).not_to be_empty end @@ -145,6 +149,12 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do expect(project_tree_saver.save).to be true end + it 'does not complain about non UTF-8 characters in MR diff files' do + ActiveRecord::Base.connection.execute("UPDATE merge_request_diff_files SET diff = '---\n- :diff: !binary |-\n LS0tIC9kZXYvbnVsbAorKysgYi9pbWFnZXMvbnVjb3IucGRmCkBAIC0wLDAg\n KzEsMTY3OSBAQAorJVBERi0xLjUNJeLjz9MNCisxIDAgb2JqDTw8L01ldGFk\n YXR'") + + expect(project_tree_saver.save).to be true + end + context 'group members' do let(:user2) { create(:user, email: 'group@member.com') } let(:member_emails) do diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 50ff6ecc1e0..fadd3ad1330 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -172,6 +172,17 @@ MergeRequestDiff: - real_size - head_commit_sha - start_commit_sha +MergeRequestDiffFile: +- merge_request_diff_id +- relative_order +- new_file +- renamed_file +- deleted_file +- new_path +- old_path +- a_mode +- b_mode +- too_large Ci::Pipeline: - id - project_id -- cgit v1.2.1 From b30c16aa3298221b1957fef61e69c47be74bb25e Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 17 Apr 2017 20:13:08 -0400 Subject: repository: index submodules by path Submodules have a name in the configuration, but this name is simply the path at which the submodule was initially checked in (by default -- the name is totally arbitrary). If a submodule is moved, it retains its original name, but its path changes. Since we discover submodules inside trees, we have their path but not necessarily their name. Make the submodules() function return the submodule hash indexed by path rather than name, so that renamed submodules can be looked up. Signed-off-by: David Turner --- spec/lib/gitlab/git/gitmodules_parser_spec.rb | 28 +++++++++++++++++++++++++++ spec/lib/gitlab/git/repository_spec.rb | 8 ++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 spec/lib/gitlab/git/gitmodules_parser_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/gitmodules_parser_spec.rb b/spec/lib/gitlab/git/gitmodules_parser_spec.rb new file mode 100644 index 00000000000..143aa2218c9 --- /dev/null +++ b/spec/lib/gitlab/git/gitmodules_parser_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Gitlab::Git::GitmodulesParser do + it 'should parse a .gitmodules file correctly' do + parser = described_class.new(<<-'GITMODULES'.strip_heredoc) + [submodule "vendor/libgit2"] + path = vendor/libgit2 + [submodule "vendor/libgit2"] + url = https://github.com/nodegit/libgit2.git + + # a comment + [submodule "moved"] + path = new/path + url = https://example.com/some/project + [submodule "bogus"] + url = https://example.com/another/project + GITMODULES + + modules = parser.parse + + expect(modules).to eq({ + 'vendor/libgit2' => { 'name' => 'vendor/libgit2', + 'url' => 'https://github.com/nodegit/libgit2.git' }, + 'new/path' => { 'name' => 'moved', + 'url' => 'https://example.com/some/project' } + }) + end +end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index e1e4aa9fde9..20ed84ee1e6 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -341,7 +341,7 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(submodule).to eq([ "six", { "id" => "409f37c4f05865e4fb208c771485f211a22c4c2d", - "path" => "six", + "name" => "six", "url" => "git://github.com/randx/six.git" } ]) @@ -349,14 +349,14 @@ describe Gitlab::Git::Repository, seed_helper: true do it 'should handle nested submodules correctly' do nested = submodules['nested/six'] - expect(nested['path']).to eq('nested/six') + expect(nested['name']).to eq('nested/six') expect(nested['url']).to eq('git://github.com/randx/six.git') expect(nested['id']).to eq('24fb71c79fcabc63dfd8832b12ee3bf2bf06b196') end it 'should handle deeply nested submodules correctly' do nested = submodules['deeper/nested/six'] - expect(nested['path']).to eq('deeper/nested/six') + expect(nested['name']).to eq('deeper/nested/six') expect(nested['url']).to eq('git://github.com/randx/six.git') expect(nested['id']).to eq('24fb71c79fcabc63dfd8832b12ee3bf2bf06b196') end @@ -376,7 +376,7 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(submodules.first).to eq([ "six", { "id" => "409f37c4f05865e4fb208c771485f211a22c4c2d", - "path" => "six", + "name" => "six", "url" => "git://github.com/randx/six.git" } ]) -- cgit v1.2.1 From 13902e40a8c11ca8d19bd7dc7e7c44fc62ee31dc Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Fri, 16 Jun 2017 20:58:18 +0200 Subject: Memoize only yaml loading method --- spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb b/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb index f8b2746b43d..61d48b05454 100644 --- a/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb +++ b/spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb @@ -33,7 +33,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end before do - described_class.instance_variable_set :@additional_metrics_raw, nil allow(described_class).to receive(:load_yaml_file) { YAML.load(sample_yaml) } end @@ -68,10 +67,6 @@ describe Gitlab::Prometheus::AdditionalMetricsParser, lib: true do end shared_examples 'required field' do |field_name| - before do - described_class.instance_variable_set :@additional_metrics_raw, nil - end - context "when #{field_name} is nil" do before do allow(described_class).to receive(:load_yaml_file) { YAML.load(field_missing) } -- cgit v1.2.1 From af784cc6e22ca915f20111828ae3252619834419 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Thu, 15 Jun 2017 17:03:54 -0700 Subject: =?UTF-8?q?Add=20=E2=80=9CProject=20moved=E2=80=9D=20error=20to=20?= =?UTF-8?q?Git-over-SSH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/lib/gitlab/git_access_spec.rb | 43 ++++++++++++++++++- spec/lib/gitlab/git_access_wiki_spec.rb | 3 +- spec/lib/gitlab/repo_path_spec.rb | 75 +++++++++++++++++++++++++++------ 3 files changed, 106 insertions(+), 15 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 3dcc20c48e8..9a86cfa66e4 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -3,11 +3,12 @@ require 'spec_helper' describe Gitlab::GitAccess, lib: true do let(:pull_access_check) { access.check('git-upload-pack', '_any') } let(:push_access_check) { access.check('git-receive-pack', '_any') } - let(:access) { Gitlab::GitAccess.new(actor, project, protocol, authentication_abilities: authentication_abilities) } + let(:access) { Gitlab::GitAccess.new(actor, project, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path) } let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:actor) { user } let(:protocol) { 'ssh' } + let(:redirected_path) { nil } let(:authentication_abilities) do [ :read_project, @@ -162,6 +163,46 @@ describe Gitlab::GitAccess, lib: true do end end + describe '#check_project_moved!' do + before do + project.team << [user, :master] + end + + context 'when a redirect was not followed to find the project' do + context 'pull code' do + it { expect { pull_access_check }.not_to raise_error } + end + + context 'push code' do + it { expect { push_access_check }.not_to raise_error } + end + end + + context 'when a redirect was followed to find the project' do + let(:redirected_path) { 'some/other-path' } + + context 'pull code' do + it { expect { pull_access_check }.to raise_not_found(/Project '#{redirected_path}' was moved to '#{project.full_path}'/) } + it { expect { pull_access_check }.to raise_not_found(/git remote set-url origin #{project.ssh_url_to_repo}/) } + + context 'http protocol' do + let(:protocol) { 'http' } + it { expect { pull_access_check }.to raise_not_found(/git remote set-url origin #{project.http_url_to_repo}/) } + end + end + + context 'push code' do + it { expect { push_access_check }.to raise_not_found(/Project '#{redirected_path}' was moved to '#{project.full_path}'/) } + it { expect { push_access_check }.to raise_not_found(/git remote set-url origin #{project.ssh_url_to_repo}/) } + + context 'http protocol' do + let(:protocol) { 'http' } + it { expect { push_access_check }.to raise_not_found(/git remote set-url origin #{project.http_url_to_repo}/) } + end + end + end + end + describe '#check_command_disabled!' do before do project.team << [user, :master] diff --git a/spec/lib/gitlab/git_access_wiki_spec.rb b/spec/lib/gitlab/git_access_wiki_spec.rb index a1eb95750ba..797ec8cb23e 100644 --- a/spec/lib/gitlab/git_access_wiki_spec.rb +++ b/spec/lib/gitlab/git_access_wiki_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe Gitlab::GitAccessWiki, lib: true do - let(:access) { Gitlab::GitAccessWiki.new(user, project, 'web', authentication_abilities: authentication_abilities) } + let(:access) { Gitlab::GitAccessWiki.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) } let(:project) { create(:project, :repository) } let(:user) { create(:user) } + let(:redirected_path) { nil } let(:authentication_abilities) do [ :read_project, diff --git a/spec/lib/gitlab/repo_path_spec.rb b/spec/lib/gitlab/repo_path_spec.rb index f9025397107..efea4f429bf 100644 --- a/spec/lib/gitlab/repo_path_spec.rb +++ b/spec/lib/gitlab/repo_path_spec.rb @@ -4,24 +4,44 @@ describe ::Gitlab::RepoPath do describe '.parse' do set(:project) { create(:project) } - it 'parses a full repository path' do - expect(described_class.parse(project.repository.path)).to eq([project, false]) - end + context 'a repository storage path' do + it 'parses a full repository path' do + expect(described_class.parse(project.repository.path)).to eq([project, false, nil]) + end - it 'parses a full wiki path' do - expect(described_class.parse(project.wiki.repository.path)).to eq([project, true]) + it 'parses a full wiki path' do + expect(described_class.parse(project.wiki.repository.path)).to eq([project, true, nil]) + end end - it 'parses a relative repository path' do - expect(described_class.parse(project.full_path + '.git')).to eq([project, false]) - end + context 'a relative path' do + it 'parses a relative repository path' do + expect(described_class.parse(project.full_path + '.git')).to eq([project, false, nil]) + end - it 'parses a relative wiki path' do - expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, true]) - end + it 'parses a relative wiki path' do + expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, true, nil]) + end + + it 'parses a relative path starting with /' do + expect(described_class.parse('/' + project.full_path + '.git')).to eq([project, false, nil]) + end + + context 'of a redirected project' do + let(:redirect) { project.route.create_redirect('foo/bar') } + + it 'parses a relative repository path' do + expect(described_class.parse(redirect.path + '.git')).to eq([project, false, 'foo/bar']) + end + + it 'parses a relative wiki path' do + expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project, true, 'foo/bar.wiki']) + end - it 'parses a relative path starting with /' do - expect(described_class.parse('/' + project.full_path + '.git')).to eq([project, false]) + it 'parses a relative path starting with /' do + expect(described_class.parse('/' + redirect.path + '.git')).to eq([project, false, 'foo/bar']) + end + end end end @@ -43,4 +63,33 @@ describe ::Gitlab::RepoPath do ) end end + + describe '.find_project' do + let(:project) { create(:empty_project) } + let(:redirect) { project.route.create_redirect('foo/bar/baz') } + + context 'when finding a project by its canonical path' do + context 'when the cases match' do + it 'returns the project and false' do + expect(described_class.find_project(project.full_path)).to eq([project, false]) + end + end + + context 'when the cases do not match' do + # This is slightly different than web behavior because on the web it is + # easy and safe to redirect someone to the correctly-cased URL. For git + # requests, we should accept wrongly-cased URLs because it is a pain to + # block people's git operations and force them to update remote URLs. + it 'returns the project and false' do + expect(described_class.find_project(project.full_path.upcase)).to eq([project, false]) + end + end + end + + context 'when finding a project via a redirect' do + it 'returns the project and true' do + expect(described_class.find_project(redirect.path)).to eq([project, true]) + end + end + end end -- cgit v1.2.1 From 76bafc00e62b3a90252f0d229c7ce98c2691da30 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 16 Jun 2017 18:42:41 +0200 Subject: Pass Gitaly token on Ruby gRPC requests --- spec/lib/gitlab/gitaly_client/commit_spec.rb | 8 ++++---- spec/lib/gitlab/gitaly_client/notifications_spec.rb | 2 +- spec/lib/gitlab/gitaly_client/ref_spec.rb | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/gitaly_client/commit_spec.rb b/spec/lib/gitlab/gitaly_client/commit_spec.rb index cf1bc74779e..dff5b25c712 100644 --- a/spec/lib/gitlab/gitaly_client/commit_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_spec.rb @@ -16,7 +16,7 @@ describe Gitlab::GitalyClient::Commit do right_commit_id: commit.id ) - expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_diff).with(request) + expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) described_class.new(repository).diff_from_parent(commit) end @@ -31,7 +31,7 @@ describe Gitlab::GitalyClient::Commit do right_commit_id: initial_commit.id ) - expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_diff).with(request) + expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) described_class.new(repository).diff_from_parent(initial_commit) end @@ -61,7 +61,7 @@ describe Gitlab::GitalyClient::Commit do right_commit_id: commit.id ) - expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_delta).with(request).and_return([]) + expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_delta).with(request, kind_of(Hash)).and_return([]) described_class.new(repository).commit_deltas(commit) end @@ -76,7 +76,7 @@ describe Gitlab::GitalyClient::Commit do right_commit_id: initial_commit.id ) - expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_delta).with(request).and_return([]) + expect_any_instance_of(Gitaly::Diff::Stub).to receive(:commit_delta).with(request, kind_of(Hash)).and_return([]) described_class.new(repository).commit_deltas(initial_commit) end diff --git a/spec/lib/gitlab/gitaly_client/notifications_spec.rb b/spec/lib/gitlab/gitaly_client/notifications_spec.rb index e5c9e06a15e..c2b8ca9f501 100644 --- a/spec/lib/gitlab/gitaly_client/notifications_spec.rb +++ b/spec/lib/gitlab/gitaly_client/notifications_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::GitalyClient::Notifications do it 'sends a post_receive message' do expect_any_instance_of(Gitaly::Notifications::Stub). - to receive(:post_receive).with(gitaly_request_with_path(storage_name, relative_path)) + to receive(:post_receive).with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) subject.post_receive end diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index 2ea44ef74b0..3272333bb33 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -21,7 +21,7 @@ describe Gitlab::GitalyClient::Ref do it 'sends a find_all_branch_names message' do expect_any_instance_of(Gitaly::Ref::Stub). to receive(:find_all_branch_names). - with(gitaly_request_with_path(storage_name, relative_path)). + with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). and_return([]) client.branch_names @@ -32,7 +32,7 @@ describe Gitlab::GitalyClient::Ref do it 'sends a find_all_tag_names message' do expect_any_instance_of(Gitaly::Ref::Stub). to receive(:find_all_tag_names). - with(gitaly_request_with_path(storage_name, relative_path)). + with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). and_return([]) client.tag_names @@ -43,7 +43,7 @@ describe Gitlab::GitalyClient::Ref do it 'sends a find_default_branch_name message' do expect_any_instance_of(Gitaly::Ref::Stub). to receive(:find_default_branch_name). - with(gitaly_request_with_path(storage_name, relative_path)). + with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). and_return(double(name: 'foo')) client.default_branch_name @@ -54,7 +54,7 @@ describe Gitlab::GitalyClient::Ref do it 'sends a find_local_branches message' do expect_any_instance_of(Gitaly::Ref::Stub). to receive(:find_local_branches). - with(gitaly_request_with_path(storage_name, relative_path)). + with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). and_return([]) client.local_branches @@ -63,7 +63,7 @@ describe Gitlab::GitalyClient::Ref do it 'parses and sends the sort parameter' do expect_any_instance_of(Gitaly::Ref::Stub). to receive(:find_local_branches). - with(gitaly_request_with_params(sort_by: :UPDATED_DESC)). + with(gitaly_request_with_params(sort_by: :UPDATED_DESC), kind_of(Hash)). and_return([]) client.local_branches(sort_by: 'updated_desc') -- cgit v1.2.1 From ed5c7d11b19c9507206ada5c6e12eef477370fa9 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 15 Jun 2017 23:41:47 +0200 Subject: Do not enable prometheus metrics when data folder is not present. + Set defaults correctly only for when not in production or staging + set ENV['prometheus_multiproc_dir'] in config/boot.rb instead of config.ru Test prometheus metrics unmemoized --- spec/lib/gitlab/metrics_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 5a87b906609..58a84cd3fe1 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -15,6 +15,36 @@ describe Gitlab::Metrics do end end + describe '.prometheus_metrics_enabled_unmemoized' do + subject { described_class.send(:prometheus_metrics_enabled_unmemoized) } + + context 'prometheus metrics enabled in config' do + before do + allow(described_class).to receive(:current_application_settings).and_return(prometheus_metrics_enabled: true) + end + + context 'when metrics folder is present' do + before do + allow(described_class).to receive(:metrics_folder_present?).and_return(true) + end + + it 'metrics are enabled' do + expect(subject).to eq(true) + end + end + + context 'when metrics folder is missing' do + before do + allow(described_class).to receive(:metrics_folder_present?).and_return(false) + end + + it 'metrics are disabled' do + expect(subject).to eq(false) + end + end + end + end + describe '.prometheus_metrics_enabled?' do it 'returns a boolean' do expect(described_class.prometheus_metrics_enabled?).to be_in([true, false]) -- cgit v1.2.1 From 575dced5d777e2e0db58ba8dbec6438456c9ff93 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 17 Jun 2017 07:35:30 -0700 Subject: If migrations are pending, make CurrentSettings use existing values and populate missing columns with defaults master was failing because `ApplicationSetting.create_from_defaults` attempted to write to a column that did not exist in the database. This occurred in a `rake db:migrate` task, which was unable to perform the migration that would have added the missing column in the first place. In 9.3 RC2, we also had a bug where password sign-ins were disabled because there were many pending migrations. The problem occurred because `fake_application_settings` was being returned with an OpenStruct that did not include the predicate method `signup_enabled?`. As a result, the value would erroneously return `nil` instead of `true`. This commit uses the values of the defaults to mimic this behavior. This commit also refactors some of the logic to be clearer. --- spec/lib/gitlab/current_settings_spec.rb | 31 ++++++++++++++++++++++ spec/lib/gitlab/fake_application_settings_spec.rb | 32 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 spec/lib/gitlab/fake_application_settings_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb index fda39d78610..a566f24f6a6 100644 --- a/spec/lib/gitlab/current_settings_spec.rb +++ b/spec/lib/gitlab/current_settings_spec.rb @@ -32,6 +32,37 @@ describe Gitlab::CurrentSettings do expect(current_application_settings).to be_a(ApplicationSetting) end + + context 'with migrations pending' do + before do + expect(ActiveRecord::Migrator).to receive(:needs_migration?).and_return(true) + end + + it 'returns an in-memory ApplicationSetting object' do + settings = current_application_settings + + expect(settings).to be_a(OpenStruct) + expect(settings.sign_in_enabled?).to eq(settings.sign_in_enabled) + expect(settings.sign_up_enabled?).to eq(settings.sign_up_enabled) + end + + it 'uses the existing database settings and falls back to defaults' do + db_settings = create(:application_setting, + home_page_url: 'http://mydomain.com', + signup_enabled: false) + settings = current_application_settings + app_defaults = ApplicationSetting.last + + expect(settings).to be_a(OpenStruct) + expect(settings.home_page_url).to eq(db_settings.home_page_url) + expect(settings.signup_enabled?).to be_falsey + expect(settings.signup_enabled).to be_falsey + + # Check that unspecified values use the defaults + settings.reject! { |key, _| [:home_page_url, :signup_enabled].include? key } + settings.each { |key, _| expect(settings[key]).to eq(app_defaults[key]) } + end + end end context 'with DB unavailable' do diff --git a/spec/lib/gitlab/fake_application_settings_spec.rb b/spec/lib/gitlab/fake_application_settings_spec.rb new file mode 100644 index 00000000000..b793176d84a --- /dev/null +++ b/spec/lib/gitlab/fake_application_settings_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Gitlab::FakeApplicationSettings do + let(:defaults) { { signin_enabled: false, foobar: 'asdf', signup_enabled: true, 'test?' => 123 } } + + subject { described_class.new(defaults) } + + it 'wraps OpenStruct variables properly' do + expect(subject.signin_enabled).to be_falsey + expect(subject.signup_enabled).to be_truthy + expect(subject.foobar).to eq('asdf') + end + + it 'defines predicate methods' do + expect(subject.signin_enabled?).to be_falsey + expect(subject.signup_enabled?).to be_truthy + end + + it 'predicate method changes when value is updated' do + subject.signin_enabled = true + + expect(subject.signin_enabled?).to be_truthy + end + + it 'does not define a predicate method' do + expect(subject.foobar?).to be_nil + end + + it 'does not override an existing predicate method' do + expect(subject.test?).to eq(123) + end +end -- cgit v1.2.1 From d866c7763cdaa801a0b6dacf125250c5117843d9 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 19 Jun 2017 12:06:33 -0700 Subject: add a spec for no-href link parsing --- spec/lib/gitlab/email/reply_parser_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index 28698e89c33..71659d5e8b0 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -208,5 +208,9 @@ describe Gitlab::Email::ReplyParser, lib: true do it "properly renders html-only email from MS Outlook" do expect(test_parse_body(fixture_file("emails/outlook_html.eml"))).to eq("Microsoft Outlook 2010") end + + it "does not wrap links with no href in unnecessary brackets" do + expect(test_parse_body(fixture_file("emails/html_empty_link.eml"))).to eq("no brackets!") + end end end -- cgit v1.2.1 From 7bda1030a59b0723eade42b03f72918a75c20e9d Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 20 Jun 2017 16:09:58 +0200 Subject: Send gitaly token to workhorse when needed --- spec/lib/gitlab/workhorse_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index ad19998dff4..a3e8166cb70 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -202,7 +202,11 @@ describe Gitlab::Workhorse, lib: true do context 'when Gitaly is enabled' do let(:gitaly_params) do { - GitalyAddress: Gitlab::GitalyClient.address('default') + GitalyAddress: Gitlab::GitalyClient.address('default'), + GitalyServer: { + address: Gitlab::GitalyClient.address('default'), + token: Gitlab::GitalyClient.token('default') + } } end -- cgit v1.2.1 From 5eb940da76193524bd81d006fee9f7971c750ec0 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 21 Jun 2017 11:16:38 +0000 Subject: Replace invalid chars while seeding environments --- spec/lib/gitlab/regex_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb index 0bee892fe0c..979f4fefcb6 100644 --- a/spec/lib/gitlab/regex_spec.rb +++ b/spec/lib/gitlab/regex_spec.rb @@ -20,6 +20,18 @@ describe Gitlab::Regex, lib: true do it { is_expected.to match('foo@bar') } end + describe '.environment_slug_regex' do + subject { described_class.environment_name_regex } + + it { is_expected.to match('foo') } + it { is_expected.to match('foo-1') } + it { is_expected.to match('FOO') } + it { is_expected.to match('foo/1') } + it { is_expected.to match('foo.1') } + it { is_expected.not_to match('9&foo') } + it { is_expected.not_to match('foo-^') } + end + describe '.environment_slug_regex' do subject { described_class.environment_slug_regex } -- cgit v1.2.1 From e4d42a62d928d31390ce29fc52891a8973784f2d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 21 Jun 2017 14:31:49 +0200 Subject: Raise if updating columns in batches within a transaction --- spec/lib/gitlab/database/migration_helpers_spec.rb | 56 ++++++++++++++-------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 30aa463faf8..29656667b02 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -262,39 +262,53 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end describe '#update_column_in_batches' do - before do - create_list(:empty_project, 5) - end + context 'when running outside of a transaction' do + before do + expect(model).to receive(:transaction_open?).and_return(false) - it 'updates all the rows in a table' do - model.update_column_in_batches(:projects, :import_error, 'foo') + create_list(:empty_project, 5) + end - expect(Project.where(import_error: 'foo').count).to eq(5) - end + it 'updates all the rows in a table' do + model.update_column_in_batches(:projects, :import_error, 'foo') - it 'updates boolean values correctly' do - model.update_column_in_batches(:projects, :archived, true) + expect(Project.where(import_error: 'foo').count).to eq(5) + end - expect(Project.where(archived: true).count).to eq(5) - end + it 'updates boolean values correctly' do + model.update_column_in_batches(:projects, :archived, true) + + expect(Project.where(archived: true).count).to eq(5) + end - context 'when a block is supplied' do - it 'yields an Arel table and query object to the supplied block' do - first_id = Project.first.id + context 'when a block is supplied' do + it 'yields an Arel table and query object to the supplied block' do + first_id = Project.first.id - model.update_column_in_batches(:projects, :archived, true) do |t, query| - query.where(t[:id].eq(first_id)) + model.update_column_in_batches(:projects, :archived, true) do |t, query| + query.where(t[:id].eq(first_id)) + end + + expect(Project.where(archived: true).count).to eq(1) end + end - expect(Project.where(archived: true).count).to eq(1) + context 'when the value is Arel.sql (Arel::Nodes::SqlLiteral)' do + it 'updates the value as a SQL expression' do + model.update_column_in_batches(:projects, :star_count, Arel.sql('1+1')) + + expect(Project.sum(:star_count)).to eq(2 * Project.count) + end end end - context 'when the value is Arel.sql (Arel::Nodes::SqlLiteral)' do - it 'updates the value as a SQL expression' do - model.update_column_in_batches(:projects, :star_count, Arel.sql('1+1')) + context 'when running inside the transaction' do + it 'raises RuntimeError' do + expect(model).to receive(:transaction_open?).and_return(true) - expect(Project.sum(:star_count)).to eq(2 * Project.count) + expect do + model.update_column_in_batches(:projects, :star_count, Arel.sql('1+1')) + end.to raise_error(RuntimeError) end end end -- cgit v1.2.1 From 0430b7644101fc70ed4be6bf69ccf05b900f4cdf Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 21 Jun 2017 13:48:12 +0000 Subject: Enable Style/DotPosition Rubocop :cop: --- spec/lib/banzai/cross_project_reference_spec.rb | 4 +- .../filter/abstract_reference_filter_spec.rb | 28 +-- .../filter/commit_range_reference_filter_spec.rb | 36 ++-- .../banzai/filter/commit_reference_filter_spec.rb | 8 +- .../filter/external_issue_reference_filter_spec.rb | 4 +- .../banzai/filter/issue_reference_filter_spec.rb | 70 +++---- .../banzai/filter/label_reference_filter_spec.rb | 76 ++++---- .../filter/merge_request_reference_filter_spec.rb | 20 +- .../filter/milestone_reference_filter_spec.rb | 68 +++---- spec/lib/banzai/filter/redactor_filter_spec.rb | 6 +- spec/lib/banzai/filter/reference_filter_spec.rb | 4 +- .../lib/banzai/filter/relative_link_filter_spec.rb | 48 ++--- spec/lib/banzai/filter/sanitization_filter_spec.rb | 4 +- .../banzai/filter/snippet_reference_filter_spec.rb | 20 +- spec/lib/banzai/filter/upload_link_filter_spec.rb | 24 +-- spec/lib/banzai/note_renderer_spec.rb | 12 +- spec/lib/banzai/redactor_spec.rb | 22 +-- .../banzai/reference_parser/base_parser_spec.rb | 140 +++++++------- .../banzai/reference_parser/commit_parser_spec.rb | 32 ++-- .../reference_parser/commit_range_parser_spec.rb | 24 +-- .../banzai/reference_parser/issue_parser_spec.rb | 12 +- .../banzai/reference_parser/user_parser_spec.rb | 24 +-- spec/lib/container_registry/blob_spec.rb | 10 +- spec/lib/container_registry/client_spec.rb | 22 +-- spec/lib/container_registry/tag_spec.rb | 28 +-- spec/lib/extracts_path_spec.rb | 4 +- spec/lib/feature_spec.rb | 8 +- spec/lib/gitlab/background_migration_spec.rb | 18 +- spec/lib/gitlab/bitbucket_import/importer_spec.rb | 8 +- .../cache/ci/project_pipeline_status_spec.rb | 16 +- .../lib/gitlab/ci/build/artifacts/metadata_spec.rb | 12 +- spec/lib/gitlab/closing_issue_extractor_spec.rb | 32 ++-- spec/lib/gitlab/conflict/file_spec.rb | 24 +-- spec/lib/gitlab/conflict/parser_spec.rb | 64 +++---- spec/lib/gitlab/data_builder/push_spec.rb | 4 +- spec/lib/gitlab/database/migration_helpers_spec.rb | 212 ++++++++++----------- .../v1/rename_namespaces_spec.rb | 34 ++-- .../v1/rename_projects_spec.rb | 30 +-- .../rename_reserved_paths_migration/v1_spec.rb | 26 +-- spec/lib/gitlab/database_spec.rb | 8 +- spec/lib/gitlab/downtime_check_spec.rb | 32 ++-- spec/lib/gitlab/email/reply_parser_spec.rb | 36 ++-- spec/lib/gitlab/etag_caching/middleware_spec.rb | 4 +- spec/lib/gitlab/file_detector_spec.rb | 8 +- spec/lib/gitlab/git/attributes_spec.rb | 44 ++--- spec/lib/gitlab/git/blob_spec.rb | 6 +- spec/lib/gitlab/git/branch_spec.rb | 4 +- spec/lib/gitlab/git/diff_collection_spec.rb | 16 +- spec/lib/gitlab/git/diff_spec.rb | 8 +- spec/lib/gitlab/git/repository_spec.rb | 40 ++-- .../lib/gitlab/gitaly_client/notifications_spec.rb | 4 +- spec/lib/gitlab/gitaly_client/ref_spec.rb | 40 ++-- spec/lib/gitlab/gitlab_import/importer_spec.rb | 4 +- spec/lib/gitlab/highlight_spec.rb | 4 +- spec/lib/gitlab/identifier_spec.rb | 12 +- spec/lib/gitlab/job_waiter_spec.rb | 10 +- spec/lib/gitlab/ldap/authentication_spec.rb | 12 +- spec/lib/gitlab/ldap/user_spec.rb | 4 +- spec/lib/gitlab/metrics/instrumentation_spec.rb | 32 ++-- spec/lib/gitlab/metrics/rack_middleware_spec.rb | 12 +- spec/lib/gitlab/metrics/sampler_spec.rb | 54 +++--- spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb | 36 ++-- .../gitlab/metrics/subscribers/action_view_spec.rb | 8 +- .../metrics/subscribers/active_record_spec.rb | 18 +- .../gitlab/metrics/subscribers/rails_cache_spec.rb | 80 ++++---- spec/lib/gitlab/metrics/transaction_spec.rb | 28 +-- spec/lib/gitlab/metrics_spec.rb | 48 ++--- spec/lib/gitlab/project_authorizations_spec.rb | 4 +- spec/lib/gitlab/route_map_spec.rb | 24 +-- spec/lib/gitlab/sherlock/file_sample_spec.rb | 4 +- spec/lib/gitlab/sherlock/line_profiler_spec.rb | 6 +- spec/lib/gitlab/sherlock/middleware_spec.rb | 4 +- spec/lib/gitlab/sherlock/query_spec.rb | 4 +- spec/lib/gitlab/sherlock/transaction_spec.rb | 28 +-- .../sidekiq_status/client_middleware_spec.rb | 4 +- .../sidekiq_status/server_middleware_spec.rb | 4 +- spec/lib/gitlab/url_builder_spec.rb | 4 +- spec/lib/gitlab/view/presenter/delegated_spec.rb | 4 +- spec/lib/gitlab/visibility_level_spec.rb | 22 +-- spec/lib/mattermost/command_spec.rb | 16 +- spec/lib/mattermost/session_spec.rb | 14 +- spec/lib/mattermost/team_spec.rb | 12 +- 82 files changed, 1001 insertions(+), 1003 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/banzai/cross_project_reference_spec.rb b/spec/lib/banzai/cross_project_reference_spec.rb index deaabceef1c..787212581e2 100644 --- a/spec/lib/banzai/cross_project_reference_spec.rb +++ b/spec/lib/banzai/cross_project_reference_spec.rb @@ -24,8 +24,8 @@ describe Banzai::CrossProjectReference, lib: true 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) + expect(Project).to receive(:find_by_full_path) + .with('cross/reference').and_return(project2) expect(project_from_ref('cross/reference')).to eq project2 end diff --git a/spec/lib/banzai/filter/abstract_reference_filter_spec.rb b/spec/lib/banzai/filter/abstract_reference_filter_spec.rb index 787c2372c5b..27532f96f56 100644 --- a/spec/lib/banzai/filter/abstract_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/abstract_reference_filter_spec.rb @@ -23,11 +23,11 @@ describe Banzai::Filter::AbstractReferenceFilter do doc = Nokogiri::HTML.fragment('') filter = described_class.new(doc, project: project) - expect(filter).to receive(:references_per_project). - and_return({ project.path_with_namespace => Set.new(%w[1]) }) + expect(filter).to receive(:references_per_project) + .and_return({ project.path_with_namespace => Set.new(%w[1]) }) - expect(filter.projects_per_reference). - to eq({ project.path_with_namespace => project }) + expect(filter.projects_per_reference) + .to eq({ project.path_with_namespace => project }) end end @@ -37,26 +37,26 @@ describe Banzai::Filter::AbstractReferenceFilter do context 'with RequestStore disabled' do it 'returns a list of Projects for a list of paths' do - expect(filter.find_projects_for_paths([project.path_with_namespace])). - to eq([project]) + expect(filter.find_projects_for_paths([project.path_with_namespace])) + .to eq([project]) end it "return an empty array for paths that don't exist" do - expect(filter.find_projects_for_paths(['nonexistent/project'])). - to eq([]) + expect(filter.find_projects_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 - expect(filter.find_projects_for_paths([project.path_with_namespace])). - to eq([project]) + expect(filter.find_projects_for_paths([project.path_with_namespace])) + .to eq([project]) end context "when no project with that path exists" do it "returns no value" do - expect(filter.find_projects_for_paths(['nonexistent/project'])). - to eq([]) + expect(filter.find_projects_for_paths(['nonexistent/project'])) + .to eq([]) end it "adds the ref to the project refs cache" do @@ -75,8 +75,8 @@ describe Banzai::Filter::AbstractReferenceFilter do end it "return an empty array for paths that don't exist" do - expect(filter.find_projects_for_paths(['nonexistent/project'])). - to eq([]) + expect(filter.find_projects_for_paths(['nonexistent/project'])) + .to eq([]) end end end 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 deadc36524c..fc67c7ec3c4 100644 --- a/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb @@ -28,15 +28,15 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do it 'links to a valid two-dot reference' do doc = reference_filter("See #{reference2}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_compare_url(project.namespace, project, range2.to_param) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_compare_url(project.namespace, project, range2.to_param) end it 'links to a valid three-dot reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_compare_url(project.namespace, project, range.to_param) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_compare_url(project.namespace, project, range.to_param) end it 'links to a valid short ID' do @@ -105,15 +105,15 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) end it 'link has valid text' do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text). - to eql("#{project2.path_with_namespace}@#{commit1.short_id}...#{commit2.short_id}") + expect(doc.css('a').first.text) + .to eql("#{project2.path_with_namespace}@#{commit1.short_id}...#{commit2.short_id}") end it 'has valid text' do @@ -140,15 +140,15 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) end it 'link has valid text' do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text). - to eql("#{project2.path}@#{commit1.short_id}...#{commit2.short_id}") + expect(doc.css('a').first.text) + .to eql("#{project2.path}@#{commit1.short_id}...#{commit2.short_id}") end it 'has valid text' do @@ -175,15 +175,15 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) end it 'link has valid text' do doc = reference_filter("Fixed (#{reference}.)") - expect(doc.css('a').first.text). - to eql("#{project2.path}@#{commit1.short_id}...#{commit2.short_id}") + expect(doc.css('a').first.text) + .to eql("#{project2.path}@#{commit1.short_id}...#{commit2.short_id}") end it 'has valid text' do @@ -214,8 +214,8 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq reference + expect(doc.css('a').first.attr('href')) + .to eq reference end it 'links with adjacent text' do diff --git a/spec/lib/banzai/filter/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_reference_filter_spec.rb index a19aac61229..c4d8d3b6682 100644 --- a/spec/lib/banzai/filter/commit_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_reference_filter_spec.rb @@ -26,8 +26,8 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true 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')). - to eq urls.namespace_project_commit_url(project.namespace, project, reference) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_commit_url(project.namespace, project, reference) end end @@ -180,8 +180,8 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_commit_url(project2.namespace, project2, commit.id) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_commit_url(project2.namespace, project2, commit.id) end it 'links with adjacent text' do 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 76cefe112fb..a4bb043f8f1 100644 --- a/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb @@ -58,8 +58,8 @@ describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do end it 'escapes the title attribute' do - allow(project.external_issue_tracker).to receive(:title). - and_return(%{">whateverwhatever project }) + expect(filter).to receive(:projects_per_reference) + .and_return({ project.path_with_namespace => project }) - expect(filter).to receive(:references_per_project). - and_return({ project.path_with_namespace => Set.new([issue.iid]) }) + expect(filter).to receive(:references_per_project) + .and_return({ project.path_with_namespace => Set.new([issue.iid]) }) - expect(filter.issues_per_project). - to eq({ project => { issue.iid => issue } }) + expect(filter.issues_per_project) + .to eq({ project => { issue.iid => issue } }) end end @@ -348,14 +348,14 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do expect(project).to receive(:default_issues_tracker?).and_return(false) - expect(filter).to receive(:projects_per_reference). - and_return({ project.path_with_namespace => project }) + expect(filter).to receive(:projects_per_reference) + .and_return({ project.path_with_namespace => project }) - expect(filter).to receive(:references_per_project). - and_return({ project.path_with_namespace => Set.new([1]) }) + expect(filter).to receive(:references_per_project) + .and_return({ project.path_with_namespace => Set.new([1]) }) - expect(filter.issues_per_project[project][1]). - to be_an_instance_of(ExternalIssue) + expect(filter.issues_per_project[project][1]) + .to be_an_instance_of(ExternalIssue) 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 284641fb20a..cb3cf982351 100644 --- a/spec/lib/banzai/filter/label_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb @@ -72,8 +72,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) end it 'links with adjacent text' do @@ -95,8 +95,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) expect(doc.text).to eq 'See gfm' end @@ -119,8 +119,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) expect(doc.text).to eq 'See 2fa' end @@ -143,8 +143,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) expect(doc.text).to eq 'See ?g.fm&' end @@ -168,8 +168,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) expect(doc.text).to eq 'See gfm references' end @@ -192,8 +192,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) expect(doc.text).to eq 'See 2 factor authentication' end @@ -216,8 +216,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) expect(doc.text).to eq 'See g.fm & references?' end @@ -287,8 +287,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_issues_url(project.namespace, project, label_name: label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: label.name) end it 'links with adjacent text' do @@ -324,8 +324,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true 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. - namespace_project_issues_url(project.namespace, project, label_name: group_label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: group_label.name) expect(doc.text).to eq 'See gfm references' end @@ -347,8 +347,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true 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. - namespace_project_issues_url(project.namespace, project, label_name: group_label.name) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_issues_url(project.namespace, project, label_name: group_label.name) expect(doc.text).to eq "See gfm references" end @@ -447,8 +447,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do end it 'has valid color' do - expect(result.css('a span').first.attr('style')). - to match /background-color: #00ff00/ + expect(result.css('a span').first.attr('style')) + .to match /background-color: #00ff00/ end it 'has valid link text' do @@ -483,18 +483,18 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do end it 'has valid color' do - expect(result.css('a span').first.attr('style')). - to match /background-color: #00ff00/ + 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} in #{another_project.name_with_namespace}" + expect(result.css('a').first.text) + .to eq "#{group_label.name} in #{another_project.name_with_namespace}" end it 'has valid text' do - expect(result.text). - to eq "See #{group_label.name} in #{another_project.name_with_namespace}" + expect(result.text) + .to eq "See #{group_label.name} in #{another_project.name_with_namespace}" end it 'ignores invalid IDs on the referenced label' do @@ -513,25 +513,25 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do let!(:result) { reference_filter("See #{reference}", project: project) } it 'points to referenced project issues page' do - expect(result.css('a').first.attr('href')). - to eq urls.namespace_project_issues_url(another_project.namespace, + expect(result.css('a').first.attr('href')) + .to eq urls.namespace_project_issues_url(another_project.namespace, another_project, label_name: group_label.name) end it 'has valid color' do - expect(result.css('a span').first.attr('style')). - to match /background-color: #00ff00/ + 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} in #{another_project.name}" + expect(result.css('a').first.text) + .to eq "#{group_label.name} in #{another_project.name}" end it 'has valid text' do - expect(result.text). - to eq "See #{group_label.name} in #{another_project.name}" + expect(result.text) + .to eq "See #{group_label.name} in #{another_project.name}" end it 'ignores invalid IDs on the referenced label' do @@ -590,8 +590,8 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do end it 'has valid color' do - expect(result.css('a span').first.attr('style')). - to match /background-color: #00ff00/ + expect(result.css('a span').first.attr('style')) + .to match /background-color: #00ff00/ end it 'has valid link text' do 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 40232f6e426..cd91681551e 100644 --- a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb @@ -36,8 +36,8 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_merge_request_url(project.namespace, project, merge) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_merge_request_url(project.namespace, project, merge) end it 'links with adjacent text' do @@ -107,8 +107,8 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_merge_request_url(project2.namespace, + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_merge_request_url(project2.namespace, project2, merge) end @@ -141,8 +141,8 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_merge_request_url(project2.namespace, + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_merge_request_url(project2.namespace, project2, merge) end @@ -175,8 +175,8 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_merge_request_url(project2.namespace, + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_merge_request_url(project2.namespace, project2, merge) end @@ -208,8 +208,8 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq reference + expect(doc.css('a').first.attr('href')) + .to eq reference end it 'links with adjacent text' do diff --git a/spec/lib/banzai/filter/milestone_reference_filter_spec.rb b/spec/lib/banzai/filter/milestone_reference_filter_spec.rb index a317c751d32..fe88b9cb73e 100644 --- a/spec/lib/banzai/filter/milestone_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/milestone_reference_filter_spec.rb @@ -44,16 +44,16 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls. - namespace_project_milestone_path(project.namespace, project, milestone) + expect(link).to eq urls + .namespace_project_milestone_path(project.namespace, project, milestone) end 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. - namespace_project_milestone_url(project.namespace, project, milestone) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(project.namespace, project, milestone) end it 'links with adjacent text' do @@ -75,8 +75,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_milestone_url(project.namespace, project, milestone) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(project.namespace, project, milestone) expect(doc.text).to eq 'See gfm' end @@ -99,8 +99,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_milestone_url(project.namespace, project, milestone) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(project.namespace, project, milestone) expect(doc.text).to eq 'See gfm references' end @@ -122,8 +122,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_milestone_url(project.namespace, project, milestone) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(project.namespace, project, milestone) end it 'links with adjacent text' do @@ -156,8 +156,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do let!(:result) { reference_filter("See #{reference}") } it 'points to referenced project milestone page' do - expect(result.css('a').first.attr('href')).to eq urls. - namespace_project_milestone_url(another_project.namespace, + expect(result.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(another_project.namespace, another_project, milestone) end @@ -165,15 +165,15 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'link has valid text' do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text). - to eq("#{milestone.name} in #{another_project.path_with_namespace}") + expect(doc.css('a').first.text) + .to eq("#{milestone.name} in #{another_project.path_with_namespace}") end it 'has valid text' do doc = reference_filter("See (#{reference}.)") - expect(doc.text). - to eq("See (#{milestone.name} in #{another_project.path_with_namespace}.)") + expect(doc.text) + .to eq("See (#{milestone.name} in #{another_project.path_with_namespace}.)") end it 'escapes the name attribute' do @@ -181,8 +181,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text). - to eq "#{milestone.name} in #{another_project.path_with_namespace}" + expect(doc.css('a').first.text) + .to eq "#{milestone.name} in #{another_project.path_with_namespace}" end end @@ -195,8 +195,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do let!(:result) { reference_filter("See #{reference}") } it 'points to referenced project milestone page' do - expect(result.css('a').first.attr('href')).to eq urls. - namespace_project_milestone_url(another_project.namespace, + expect(result.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(another_project.namespace, another_project, milestone) end @@ -204,15 +204,15 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'link has valid text' do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text). - to eq("#{milestone.name} in #{another_project.path}") + expect(doc.css('a').first.text) + .to eq("#{milestone.name} in #{another_project.path}") end it 'has valid text' do doc = reference_filter("See (#{reference}.)") - expect(doc.text). - to eq("See (#{milestone.name} in #{another_project.path}.)") + expect(doc.text) + .to eq("See (#{milestone.name} in #{another_project.path}.)") end it 'escapes the name attribute' do @@ -220,8 +220,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text). - to eq "#{milestone.name} in #{another_project.path}" + expect(doc.css('a').first.text) + .to eq "#{milestone.name} in #{another_project.path}" end end @@ -234,8 +234,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do let!(:result) { reference_filter("See #{reference}") } it 'points to referenced project milestone page' do - expect(result.css('a').first.attr('href')).to eq urls. - namespace_project_milestone_url(another_project.namespace, + expect(result.css('a').first.attr('href')).to eq urls + .namespace_project_milestone_url(another_project.namespace, another_project, milestone) end @@ -243,15 +243,15 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'link has valid text' do doc = reference_filter("See (#{reference}.)") - expect(doc.css('a').first.text). - to eq("#{milestone.name} in #{another_project.path}") + expect(doc.css('a').first.text) + .to eq("#{milestone.name} in #{another_project.path}") end it 'has valid text' do doc = reference_filter("See (#{reference}.)") - expect(doc.text). - to eq("See (#{milestone.name} in #{another_project.path}.)") + expect(doc.text) + .to eq("See (#{milestone.name} in #{another_project.path}.)") end it 'escapes the name attribute' do @@ -259,8 +259,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.text). - to eq "#{milestone.name} in #{another_project.path}" + expect(doc.css('a').first.text) + .to eq "#{milestone.name} in #{another_project.path}" end end end diff --git a/spec/lib/banzai/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb index 97504aebed5..b81cdbb8957 100644 --- a/spec/lib/banzai/filter/redactor_filter_spec.rb +++ b/spec/lib/banzai/filter/redactor_filter_spec.rb @@ -33,9 +33,9 @@ describe Banzai::Filter::RedactorFilter, lib: true do end before do - allow(Banzai::ReferenceParser).to receive(:[]). - with('test'). - and_return(parser_class) + allow(Banzai::ReferenceParser).to receive(:[]) + .with('test') + .and_return(parser_class) end context 'valid projects' do diff --git a/spec/lib/banzai/filter/reference_filter_spec.rb b/spec/lib/banzai/filter/reference_filter_spec.rb index 55e681f6faf..ba0fa4a609a 100644 --- a/spec/lib/banzai/filter/reference_filter_spec.rb +++ b/spec/lib/banzai/filter/reference_filter_spec.rb @@ -8,8 +8,8 @@ describe Banzai::Filter::ReferenceFilter, lib: true do document = Nokogiri::HTML.fragment('foo') filter = described_class.new(document, project: project) - expect { |b| filter.each_node(&b) }. - to yield_with_args(an_instance_of(Nokogiri::XML::Element)) + expect { |b| filter.each_node(&b) } + .to yield_with_args(an_instance_of(Nokogiri::XML::Element)) end it 'returns an Enumerator when no block is given' do diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index 1957ba739e2..1ce7bd7706e 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -72,15 +72,15 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do 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 + 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']). - to eq "/#{project_path}/blob/#{ref}/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 @@ -90,71 +90,71 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do 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" + 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']). - to eq "/#{project_path}/blob/#{ref}/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') - expect(doc.at_css('a')['href']). - to eq "/#{project_path}/blob/#{ref}/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 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" + 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') - expect(doc.at_css('a')['href']). - to eq "/#{project_path}/blob/#{ref}/README.md" + 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']). - to eq "/#{project_path}/blob/#{ref}/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']). - to eq "/#{project_path}/tree/#{ref}/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')) - expect(doc.at_css('img')['src']). - to eq "/#{project_path}/raw/#{ref}/files/images/logo-black.png" + 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')) - expect(doc.at_css('a')['href']). - to eq "/#{project_path}/raw/#{ref}/files/images/logo-black.png" + 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') - expect(doc.at_css('video')['src']). - to eq "/#{project_path}/raw/video/files/videos/intro.mp4" + 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 diff --git a/spec/lib/banzai/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb index fb7862f49a2..a8a0aa6d395 100644 --- a/spec/lib/banzai/filter/sanitization_filter_spec.rb +++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb @@ -221,8 +221,8 @@ describe Banzai::Filter::SanitizationFilter, lib: true do end it 'disallows invalid URIs' do - expect(Addressable::URI).to receive(:parse).with('foo://example.com'). - and_raise(Addressable::URI::InvalidURIError) + expect(Addressable::URI).to receive(:parse).with('foo://example.com') + .and_raise(Addressable::URI::InvalidURIError) input = 'Foo' output = filter(input) diff --git a/spec/lib/banzai/filter/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb index e036514d283..e851120bc3a 100644 --- a/spec/lib/banzai/filter/snippet_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb @@ -22,8 +22,8 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')).to eq urls. - namespace_project_snippet_url(project.namespace, project, snippet) + expect(doc.css('a').first.attr('href')).to eq urls + .namespace_project_snippet_url(project.namespace, project, snippet) end it 'links with adjacent text' do @@ -88,8 +88,8 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) end it 'link has valid text' do @@ -121,8 +121,8 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) end it 'link has valid text' do @@ -154,8 +154,8 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) end it 'link has valid text' do @@ -186,8 +186,8 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do it 'links to a valid reference' do doc = reference_filter("See #{reference}") - expect(doc.css('a').first.attr('href')). - to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + expect(doc.css('a').first.attr('href')) + .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) end it 'links with adjacent text' do diff --git a/spec/lib/banzai/filter/upload_link_filter_spec.rb b/spec/lib/banzai/filter/upload_link_filter_spec.rb index 639cac6406a..6327ca8bbfd 100644 --- a/spec/lib/banzai/filter/upload_link_filter_spec.rb +++ b/spec/lib/banzai/filter/upload_link_filter_spec.rb @@ -51,22 +51,22 @@ describe Banzai::Filter::UploadLinkFilter, lib: true do context 'with a valid repository' do it 'rebuilds relative URL for a link' do doc = filter(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('a')['href']). - to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + expect(doc.at_css('a')['href']) + .to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" doc = filter(nested_link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('a')['href']). - to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + expect(doc.at_css('a')['href']) + .to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" end it 'rebuilds relative URL for an image' do doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('img')['src']). - to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + expect(doc.at_css('img')['src']) + .to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" doc = filter(nested_image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('img')['src']). - to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + expect(doc.at_css('img')['src']) + .to eq "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" end it 'does not modify absolute URL' do @@ -79,10 +79,10 @@ describe Banzai::Filter::UploadLinkFilter, lib: true do 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(:image?).with(path).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) doc = filter(image(escaped)) expect(doc.at_css('img')['src']).to match "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/%ED%95%9C%EA%B8%80.png" diff --git a/spec/lib/banzai/note_renderer_spec.rb b/spec/lib/banzai/note_renderer_spec.rb index 49556074278..32764bee5eb 100644 --- a/spec/lib/banzai/note_renderer_spec.rb +++ b/spec/lib/banzai/note_renderer_spec.rb @@ -8,15 +8,15 @@ describe Banzai::NoteRenderer do wiki = double(:wiki) user = double(:user) - expect(Banzai::ObjectRenderer).to receive(:new). - with(project, user, + expect(Banzai::ObjectRenderer).to receive(:new) + .with(project, user, requested_path: 'foo', project_wiki: wiki, - ref: 'bar'). - and_call_original + ref: 'bar') + .and_call_original - expect_any_instance_of(Banzai::ObjectRenderer). - to receive(:render).with([note], :note) + expect_any_instance_of(Banzai::ObjectRenderer) + .to receive(:render).with([note], :note) described_class.render([note], project, user, 'foo', wiki, 'bar') end diff --git a/spec/lib/banzai/redactor_spec.rb b/spec/lib/banzai/redactor_spec.rb index e6f2963193c..81ae5685b10 100644 --- a/spec/lib/banzai/redactor_spec.rb +++ b/spec/lib/banzai/redactor_spec.rb @@ -12,11 +12,11 @@ describe Banzai::Redactor do end it 'redacts an array of documents' do - doc1 = Nokogiri::HTML. - fragment('foo') + doc1 = Nokogiri::HTML + .fragment('foo') - doc2 = Nokogiri::HTML. - fragment('bar') + doc2 = Nokogiri::HTML + .fragment('bar') redacted_data = redactor.redact([doc1, doc2]) @@ -93,9 +93,9 @@ describe Banzai::Redactor do doc = Nokogiri::HTML.fragment('foo') node = doc.children[0] - expect(redactor).to receive(:nodes_visible_to_user). - with([node]). - and_return(Set.new) + expect(redactor).to receive(:nodes_visible_to_user) + .with([node]) + .and_return(Set.new) redactor.redact_document_nodes([{ document: doc, nodes: [node] }]) @@ -108,10 +108,10 @@ describe Banzai::Redactor do doc = Nokogiri::HTML.fragment('') node = doc.children[0] - expect_any_instance_of(Banzai::ReferenceParser::IssueParser). - to receive(:nodes_visible_to_user). - with(user, [node]). - and_return([node]) + expect_any_instance_of(Banzai::ReferenceParser::IssueParser) + .to receive(:nodes_visible_to_user) + .with(user, [node]) + .and_return([node]) expect(redactor.nodes_visible_to_user([node])).to eq(Set.new([node])) end diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb index 76fab93821a..b444ca05b8e 100644 --- a/spec/lib/banzai/reference_parser/base_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb @@ -54,8 +54,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do describe '#referenced_by' do context 'when references_relation is implemented' do it 'returns a collection of objects' do - links = Nokogiri::HTML.fragment(""). - children + links = Nokogiri::HTML.fragment("") + .children expect(subject).to receive(:references_relation).and_return(User) expect(subject.referenced_by(links)).to eq([user]) @@ -66,8 +66,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do it 'raises NotImplementedError' do links = Nokogiri::HTML.fragment('').children - expect { subject.referenced_by(links) }. - to raise_error(NotImplementedError) + expect { subject.referenced_by(links) } + .to raise_error(NotImplementedError) end end end @@ -80,8 +80,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do describe '#gather_attributes_per_project' do it 'returns a Hash containing attribute values per project' do - link = Nokogiri::HTML.fragment(''). - children[0] + link = Nokogiri::HTML.fragment('') + .children[0] hash = subject.gather_attributes_per_project([link], 'data-foo') @@ -95,19 +95,19 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do it 'returns a Hash grouping objects per node' do link = double(:link) - expect(link).to receive(:has_attribute?). - with('data-user'). - and_return(true) + expect(link).to receive(:has_attribute?) + .with('data-user') + .and_return(true) - expect(link).to receive(:attr). - with('data-user'). - and_return(user.id.to_s) + expect(link).to receive(:attr) + .with('data-user') + .and_return(user.id.to_s) nodes = [link] - expect(subject).to receive(:unique_attribute_values). - with(nodes, 'data-user'). - and_return([user.id.to_s]) + expect(subject).to receive(:unique_attribute_values) + .with(nodes, 'data-user') + .and_return([user.id.to_s]) hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user') @@ -117,20 +117,20 @@ describe Banzai::ReferenceParser::BaseParser, lib: true 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) + expect(link).to receive(:has_attribute?) + .with('data-user') + .and_return(true) - expect(link).to receive(:attr). - with('data-user'). - and_return('1') + expect(link).to receive(:attr) + .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]) + expect(subject).to receive(:unique_attribute_values) + .with(nodes, 'data-user') + .and_return([bad_id.to_s]) hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user') @@ -142,15 +142,15 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do it 'returns an Array of unique values' do link = double(:link) - expect(link).to receive(:has_attribute?). - with('data-foo'). - twice. - and_return(true) + expect(link).to receive(:has_attribute?) + .with('data-foo') + .twice + .and_return(true) - expect(link).to receive(:attr). - with('data-foo'). - twice. - and_return('1') + expect(link).to receive(:attr) + .with('data-foo') + .twice + .and_return('1') nodes = [link, link] @@ -167,9 +167,9 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do instance = dummy.new(project, user) document = Nokogiri::HTML.fragment('') - expect(instance).to receive(:gather_references). - with([document.children[1]]). - and_return([user]) + expect(instance).to receive(:gather_references) + .with([document.children[1]]) + .and_return([user]) expect(instance.process([document])).to eq([user]) end @@ -179,9 +179,9 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do let(:link) { double(:link) } it 'does not process links a user can not reference' do - expect(subject).to receive(:nodes_user_can_reference). - with(user, [link]). - and_return([]) + expect(subject).to receive(:nodes_user_can_reference) + .with(user, [link]) + .and_return([]) expect(subject).to receive(:referenced_by).with([]) @@ -189,13 +189,13 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do end 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]) + expect(subject).to receive(:nodes_user_can_reference) + .with(user, [link]) + .and_return([link]) - expect(subject).to receive(:nodes_visible_to_user). - with(user, [link]). - and_return([]) + expect(subject).to receive(:nodes_visible_to_user) + .with(user, [link]) + .and_return([]) expect(subject).to receive(:referenced_by).with([]) @@ -203,13 +203,13 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do end 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]) + expect(subject).to receive(:nodes_user_can_reference) + .with(user, [link]) + .and_return([link]) - expect(subject).to receive(:nodes_visible_to_user). - with(user, [link]). - and_return([link]) + expect(subject).to receive(:nodes_visible_to_user) + .with(user, [link]) + .and_return([link]) expect(subject).to receive(:referenced_by).with([link]) @@ -221,8 +221,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do it 'delegates the permissions check to the Ability class' do user = double(:user) - expect(Ability).to receive(:allowed?). - with(user, :read_project, project) + expect(Ability).to receive(:allowed?) + .with(user, :read_project, project) subject.can?(user, :read_project, project) end @@ -230,8 +230,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true 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]) + expect(subject.find_projects_for_hash_keys(project.id => project)) + .to eq([project]) end end @@ -243,8 +243,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do expect(collection).to receive(:where).twice.and_call_original 2.times do - expect(subject.collection_objects_for_ids(collection, [user.id])). - to eq([user]) + expect(subject.collection_objects_for_ids(collection, [user.id])) + .to eq([user]) end end end @@ -258,8 +258,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do end it 'queries the collection on the first call' do - expect(subject.collection_objects_for_ids(User, [user.id])). - to eq([user]) + expect(subject.collection_objects_for_ids(User, [user.id])) + .to eq([user]) end it 'does not query previously queried objects' do @@ -268,34 +268,34 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do expect(collection).to receive(:where).once.and_call_original 2.times do - expect(subject.collection_objects_for_ids(collection, [user.id])). - to eq([user]) + expect(subject.collection_objects_for_ids(collection, [user.id])) + .to eq([user]) end end 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]) + 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 other_user = create(:user) - expect(subject.collection_objects_for_ids(User, [user.id])). - to eq([user]) + expect(subject.collection_objects_for_ids(User, [user.id])) + .to eq([user]) - expect(subject.collection_objects_for_ids(User, [user.id, other_user.id])). - to eq([user, other_user]) + expect(subject.collection_objects_for_ids(User, [user.id, other_user.id])) + .to eq([user, other_user]) end it 'caches objects on a per collection class basis' do - expect(subject.collection_objects_for_ids(User, [user.id])). - to eq([user]) + expect(subject.collection_objects_for_ids(User, [user.id])) + .to eq([user]) - expect(subject.collection_objects_for_ids(Project, [project.id])). - to eq([project]) + expect(subject.collection_objects_for_ids(Project, [project.id])) + .to eq([project]) end 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 583ce63a8ab..a314a6119cb 100644 --- a/spec/lib/banzai/reference_parser/commit_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_parser_spec.rb @@ -32,30 +32,30 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do it 'returns an Array of commits' do commit = double(:commit) - allow_any_instance_of(Project).to receive(:valid_repo?). - and_return(true) + allow_any_instance_of(Project).to receive(:valid_repo?) + .and_return(true) - expect(subject).to receive(:find_commits). - with(project, ['123']). - and_return([commit]) + expect(subject).to receive(:find_commits) + .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 - allow_any_instance_of(Project).to receive(:valid_repo?). - and_return(true) + allow_any_instance_of(Project).to receive(:valid_repo?) + .and_return(true) - expect(subject).to receive(:find_commits). - with(project, ['123']). - and_return([]) + expect(subject).to receive(:find_commits) + .with(project, ['123']) + .and_return([]) expect(subject.referenced_by([link])).to eq([]) end it 'skips projects without valid repositories' do - allow_any_instance_of(Project).to receive(:valid_repo?). - and_return(false) + allow_any_instance_of(Project).to receive(:valid_repo?) + .and_return(false) expect(subject.referenced_by([link])).to eq([]) end @@ -63,8 +63,8 @@ describe Banzai::ReferenceParser::CommitParser, lib: true 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) + allow_any_instance_of(Project).to receive(:valid_repo?) + .and_return(true) expect(subject.referenced_by([link])).to eq([]) end @@ -73,8 +73,8 @@ describe Banzai::ReferenceParser::CommitParser, lib: true 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) + allow_any_instance_of(Project).to receive(:valid_repo?) + .and_return(true) expect(subject.referenced_by([link])).to eq([]) 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 8c0f5d7df97..5dca5e784da 100644 --- a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb @@ -32,17 +32,17 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do it 'returns an Array of commit ranges' do range = double(:range) - expect(subject).to receive(:find_object). - with(project, '123..456'). - and_return(range) + expect(subject).to receive(:find_object) + .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 - expect(subject).to receive(:find_object). - with(project, '123..456'). - and_return(nil) + expect(subject).to receive(:find_object) + .with(project, '123..456') + .and_return(nil) expect(subject.referenced_by([link])).to eq([]) end @@ -88,17 +88,17 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do it 'returns an Array of range objects' do range = double(:commit) - expect(subject).to receive(:find_object). - with(project, '123..456'). - and_return(range) + expect(subject).to receive(:find_object) + .with(project, '123..456') + .and_return(range) expect(subject.find_ranges(project, ['123..456'])).to eq([range]) end it 'skips ranges that could not be found' do - expect(subject).to receive(:find_object). - with(project, '123..456'). - and_return(nil) + expect(subject).to receive(:find_object) + .with(project, '123..456') + .and_return(nil) expect(subject.find_ranges(project, ['123..456'])).to eq([]) end diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb index 7031c47231c..58e1a0c1bc1 100644 --- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb @@ -18,17 +18,17 @@ describe Banzai::ReferenceParser::IssueParser, lib: true do it_behaves_like "referenced feature visibility", "issues" 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]) + expect(Ability).to receive(:issues_readable_by_user) + .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 - expect(Ability).to receive(:issues_readable_by_user). - with([issue], user). - and_return([]) + expect(Ability).to receive(:issues_readable_by_user) + .with([issue], user) + .and_return([]) expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end diff --git a/spec/lib/banzai/reference_parser/user_parser_spec.rb b/spec/lib/banzai/reference_parser/user_parser_spec.rb index 4d560667342..dfebb971f3a 100644 --- a/spec/lib/banzai/reference_parser/user_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/user_parser_spec.rb @@ -96,17 +96,17 @@ describe Banzai::ReferenceParser::UserParser, lib: true do end 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) + expect(Ability).to receive(:allowed?) + .with(user, :read_group, group) + .and_return(true) 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 - expect(Ability).to receive(:allowed?). - with(user, :read_group, group). - and_return(false) + expect(Ability).to receive(:allowed?) + .with(user, :read_group, group) + .and_return(false) expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end @@ -129,9 +129,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do link['data-project'] = other_project.id.to_s - expect(Ability).to receive(:allowed?). - with(user, :read_project, other_project). - and_return(true) + expect(Ability).to receive(:allowed?) + .with(user, :read_project, other_project) + .and_return(true) expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end @@ -141,9 +141,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do link['data-project'] = other_project.id.to_s - expect(Ability).to receive(:allowed?). - with(user, :read_project, other_project). - and_return(false) + expect(Ability).to receive(:allowed?) + .with(user, :read_project, other_project) + .and_return(false) expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end diff --git a/spec/lib/container_registry/blob_spec.rb b/spec/lib/container_registry/blob_spec.rb index ab010c6dfeb..175fd2e7e13 100644 --- a/spec/lib/container_registry/blob_spec.rb +++ b/spec/lib/container_registry/blob_spec.rb @@ -72,8 +72,8 @@ describe ContainerRegistry::Blob do describe '#data' do context 'when locally stored' do before do - stub_request(:get, 'http://registry.gitlab/v2/group/test/image/blobs/sha256:0123456789012345'). - to_return( + stub_request(:get, 'http://registry.gitlab/v2/group/test/image/blobs/sha256:0123456789012345') + .to_return( status: 200, headers: { 'Content-Type' => 'application/json' }, body: '{"key":"value"}') @@ -97,9 +97,9 @@ describe ContainerRegistry::Blob do context 'for a valid address' do before do - stub_request(:get, location). - with { |request| !request.headers.include?('Authorization') }. - to_return( + stub_request(:get, location) + .with { |request| !request.headers.include?('Authorization') } + .to_return( status: 200, headers: { 'Content-Type' => 'application/json' }, body: '{"key":"value"}') diff --git a/spec/lib/container_registry/client_spec.rb b/spec/lib/container_registry/client_spec.rb index ec03b533383..3df33f48adb 100644 --- a/spec/lib/container_registry/client_spec.rb +++ b/spec/lib/container_registry/client_spec.rb @@ -8,28 +8,28 @@ describe ContainerRegistry::Client do describe '#blob' do it 'GET /v2/:name/blobs/:digest' do - stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345"). - with(headers: { + stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345") + .with(headers: { 'Accept' => 'application/octet-stream', 'Authorization' => "bearer #{token}" - }). - to_return(status: 200, body: "Blob") + }) + .to_return(status: 200, body: "Blob") expect(client.blob('group/test', 'sha256:0123456789012345')).to eq('Blob') end it 'follows 307 redirect for GET /v2/:name/blobs/:digest' do - stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345"). - with(headers: { + stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345") + .with(headers: { 'Accept' => 'application/octet-stream', 'Authorization' => "bearer #{token}" - }). - to_return(status: 307, body: "", headers: { Location: 'http://redirected' }) + }) + .to_return(status: 307, body: "", headers: { Location: 'http://redirected' }) # We should probably use hash_excluding here, but that requires an update to WebMock: # https://github.com/bblimke/webmock/blob/master/lib/webmock/matchers/hash_excluding_matcher.rb - stub_request(:get, "http://redirected/"). - with { |request| !request.headers.include?('Authorization') }. - to_return(status: 200, body: "Successfully redirected") + stub_request(:get, "http://redirected/") + .with { |request| !request.headers.include?('Authorization') } + .to_return(status: 200, body: "Successfully redirected") response = client.blob('group/test', 'sha256:0123456789012345') diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb index f8fffbdca41..cb4ae3be525 100644 --- a/spec/lib/container_registry/tag_spec.rb +++ b/spec/lib/container_registry/tag_spec.rb @@ -60,9 +60,9 @@ describe ContainerRegistry::Tag do context 'manifest processing' do context 'schema v1' do before do - stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag'). - with(headers: headers). - to_return( + stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag') + .with(headers: headers) + .to_return( status: 200, body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest_1.json'), headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v1+prettyjws' }) @@ -97,9 +97,9 @@ describe ContainerRegistry::Tag do context 'schema v2' do before do - stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag'). - with(headers: headers). - to_return( + stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag') + .with(headers: headers) + .to_return( status: 200, body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json'), headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json' }) @@ -134,9 +134,9 @@ describe ContainerRegistry::Tag do context 'when locally stored' do before do - stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'). - with(headers: { 'Accept' => 'application/octet-stream' }). - to_return( + stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac') + .with(headers: { 'Accept' => 'application/octet-stream' }) + .to_return( status: 200, body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json')) end @@ -146,14 +146,14 @@ describe ContainerRegistry::Tag do context 'when externally stored' do before do - stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'). - with(headers: { 'Accept' => 'application/octet-stream' }). - to_return( + stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac') + .with(headers: { 'Accept' => 'application/octet-stream' }) + .to_return( status: 307, headers: { 'Location' => 'http://external.com/blob/file' }) - stub_request(:get, 'http://external.com/blob/file'). - to_return( + stub_request(:get, 'http://external.com/blob/file') + .to_return( status: 200, body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json')) end diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index 2b26a318583..f2132d485ab 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -14,8 +14,8 @@ describe ExtractsPath, lib: true do repo = double(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0', 'release/app', 'release/app/v1.0.0']) allow(project).to receive(:repository).and_return(repo) - allow(project).to receive(:path_with_namespace). - and_return('gitlab/gitlab-ci') + allow(project).to receive(:path_with_namespace) + .and_return('gitlab/gitlab-ci') allow(request).to receive(:format=) end diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb index 1d92a5cb33f..5cc3a3745e4 100644 --- a/spec/lib/feature_spec.rb +++ b/spec/lib/feature_spec.rb @@ -6,8 +6,8 @@ describe Feature, lib: true do let(:key) { 'my_feature' } it 'returns the Flipper feature' do - expect_any_instance_of(Flipper::DSL).to receive(:feature).with(key). - and_return(feature) + expect_any_instance_of(Flipper::DSL).to receive(:feature).with(key) + .and_return(feature) expect(described_class.get(key)).to be(feature) end @@ -17,8 +17,8 @@ describe Feature, lib: true do let(:features) { Set.new } it 'returns the Flipper features as an array' do - expect_any_instance_of(Flipper::DSL).to receive(:features). - and_return(features) + expect_any_instance_of(Flipper::DSL).to receive(:features) + .and_return(features) expect(described_class.all).to eq(features.to_a) end diff --git a/spec/lib/gitlab/background_migration_spec.rb b/spec/lib/gitlab/background_migration_spec.rb index f2073b9bcb3..64f82fe27b2 100644 --- a/spec/lib/gitlab/background_migration_spec.rb +++ b/spec/lib/gitlab/background_migration_spec.rb @@ -5,9 +5,9 @@ describe Gitlab::BackgroundMigration do it 'steals jobs from a queue' do queue = [double(:job, args: ['Foo', [10, 20]])] - allow(Sidekiq::Queue).to receive(:new). - with(BackgroundMigrationWorker.sidekiq_options['queue']). - and_return(queue) + allow(Sidekiq::Queue).to receive(:new) + .with(BackgroundMigrationWorker.sidekiq_options['queue']) + .and_return(queue) expect(queue[0]).to receive(:delete) @@ -19,9 +19,9 @@ describe Gitlab::BackgroundMigration do it 'does not steal jobs for a different migration' do queue = [double(:job, args: ['Foo', [10, 20]])] - allow(Sidekiq::Queue).to receive(:new). - with(BackgroundMigrationWorker.sidekiq_options['queue']). - and_return(queue) + allow(Sidekiq::Queue).to receive(:new) + .with(BackgroundMigrationWorker.sidekiq_options['queue']) + .and_return(queue) expect(described_class).not_to receive(:perform) @@ -36,9 +36,9 @@ describe Gitlab::BackgroundMigration do instance = double(:instance) klass = double(:klass, new: instance) - expect(described_class).to receive(:const_get). - with('Foo'). - and_return(klass) + expect(described_class).to receive(:const_get) + .with('Foo') + .and_return(klass) expect(instance).to receive(:perform).with(10, 20) diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index a7ee7f53a6b..d8beb05601c 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -86,11 +86,9 @@ describe Gitlab::BitbucketImport::Importer, lib: true do headers: { "Content-Type" => "application/json" }, body: issues_statuses_sample_data.to_json) - stub_request(:get, "https://api.bitbucket.org/2.0/repositories/namespace/repo?pagelen=50&sort=created_on"). - with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer', 'User-Agent' => 'Faraday v0.9.2' }). - to_return(status: 200, - body: "", - headers: {}) + stub_request(:get, "https://api.bitbucket.org/2.0/repositories/namespace/repo?pagelen=50&sort=created_on") + .with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer', 'User-Agent' => 'Faraday v0.9.2' }) + .to_return(status: 200, body: "", headers: {}) sample_issues_statuses.each_with_index do |issue, index| stub_request( diff --git a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb index cfb5cba054e..07db6c3a640 100644 --- a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb +++ b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb @@ -37,11 +37,11 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :redis do loaded_from_cache: false ) - expect(described_class).to receive(:new). - with(project_without_status, + expect(described_class).to receive(:new) + .with(project_without_status, pipeline_info: empty_status, - loaded_from_cache: false). - and_return(fake_pipeline) + loaded_from_cache: false) + .and_return(fake_pipeline) expect(fake_pipeline).to receive(:load_from_project) expect(fake_pipeline).to receive(:store_in_cache) @@ -112,12 +112,12 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :redis do pipeline = build_stubbed(:ci_pipeline, sha: '123456', status: 'success', ref: 'master') fake_status = double - expect(described_class).to receive(:new). - with(pipeline.project, + expect(described_class).to receive(:new) + .with(pipeline.project, pipeline_info: { sha: '123456', status: 'success', ref: 'master' - }). - and_return(fake_status) + }) + .and_return(fake_status) expect(fake_status).to receive(:store_in_cache_if_needed) diff --git a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb index eea01f91879..6a52ae01b2f 100644 --- a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb +++ b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb @@ -33,8 +33,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do subject { metadata('other_artifacts_0.1.2/').find_entries! } it 'matches correct paths' do - expect(subject.keys). - to contain_exactly 'other_artifacts_0.1.2/', + expect(subject.keys) + .to contain_exactly 'other_artifacts_0.1.2/', 'other_artifacts_0.1.2/doc_sample.txt', 'other_artifacts_0.1.2/another-subdirectory/' end @@ -44,8 +44,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do subject { metadata('other_artifacts_0.1.2/another-subdirectory/').find_entries! } it 'matches correct paths' do - expect(subject.keys). - to contain_exactly 'other_artifacts_0.1.2/another-subdirectory/', + expect(subject.keys) + .to contain_exactly 'other_artifacts_0.1.2/another-subdirectory/', 'other_artifacts_0.1.2/another-subdirectory/empty_directory/', 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' end @@ -55,8 +55,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do subject { metadata('other_artifacts_0.1.2/', recursive: true).find_entries! } it 'matches correct paths' do - expect(subject.keys). - to contain_exactly 'other_artifacts_0.1.2/', + expect(subject.keys) + .to contain_exactly 'other_artifacts_0.1.2/', 'other_artifacts_0.1.2/doc_sample.txt', 'other_artifacts_0.1.2/another-subdirectory/', 'other_artifacts_0.1.2/another-subdirectory/empty_directory/', diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb index 97af1c2523d..ca68010cb89 100644 --- a/spec/lib/gitlab/closing_issue_extractor_spec.rb +++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb @@ -306,58 +306,58 @@ describe Gitlab::ClosingIssueExtractor, lib: true do it 'fetches issues in single line message' do message = "Closes #{reference} and fix #{reference2}" - expect(subject.closed_by_message(message)). - to match_array([issue, other_issue]) + expect(subject.closed_by_message(message)) + .to match_array([issue, other_issue]) end it 'fetches comma-separated issues references in single line message' do message = "Closes #{reference}, closes #{reference2}" - expect(subject.closed_by_message(message)). - to match_array([issue, other_issue]) + expect(subject.closed_by_message(message)) + .to match_array([issue, other_issue]) end it 'fetches comma-separated issues numbers in single line message' do message = "Closes #{reference}, #{reference2} and #{reference3}" - expect(subject.closed_by_message(message)). - to match_array([issue, other_issue, third_issue]) + expect(subject.closed_by_message(message)) + .to match_array([issue, other_issue, third_issue]) end it 'fetches issues in multi-line message' do message = "Awesome commit (closes #{reference})\nAlso fixes #{reference2}" - expect(subject.closed_by_message(message)). - to match_array([issue, other_issue]) + expect(subject.closed_by_message(message)) + .to match_array([issue, other_issue]) end it 'fetches issues in hybrid message' do message = "Awesome commit (closes #{reference})\n"\ "Also fixing issues #{reference2}, #{reference3} and #4" - expect(subject.closed_by_message(message)). - to match_array([issue, other_issue, third_issue]) + expect(subject.closed_by_message(message)) + .to match_array([issue, other_issue, third_issue]) end it "fetches cross-project references" do message = "Closes #{reference} and #{cross_reference}" - expect(subject.closed_by_message(message)). - to match_array([issue, issue2]) + expect(subject.closed_by_message(message)) + .to match_array([issue, issue2]) end it "fetches cross-project URL references" do message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)} and #{reference}" - expect(subject.closed_by_message(message)). - to match_array([issue, issue2]) + expect(subject.closed_by_message(message)) + .to match_array([issue, issue2]) end it "ignores invalid cross-project URL references" do message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)} and #{reference}" - expect(subject.closed_by_message(message)). - to match_array([issue]) + expect(subject.closed_by_message(message)) + .to match_array([issue]) end end end diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb index 780ac0ad97e..585eeb77bd5 100644 --- a/spec/lib/gitlab/conflict/file_spec.rb +++ b/spec/lib/gitlab/conflict/file_spec.rb @@ -43,8 +43,8 @@ describe Gitlab::Conflict::File, lib: true do end it 'returns a file containing only the chosen parts of the resolved sections' do - expect(resolved_lines.chunk { |line| line.type || 'both' }.map(&:first)). - to eq(%w(both new both old both new both)) + expect(resolved_lines.chunk { |line| line.type || 'both' }.map(&:first)) + .to eq(%w(both new both old both new both)) end end @@ -52,14 +52,14 @@ describe Gitlab::Conflict::File, lib: true do empty_hash = section_keys.map { |key| [key, nil] }.to_h invalid_hash = section_keys.map { |key| [key, 'invalid'] }.to_h - expect { conflict_file.resolve_lines({}) }. - to raise_error(Gitlab::Conflict::File::MissingResolution) + expect { conflict_file.resolve_lines({}) } + .to raise_error(Gitlab::Conflict::File::MissingResolution) - expect { conflict_file.resolve_lines(empty_hash) }. - to raise_error(Gitlab::Conflict::File::MissingResolution) + expect { conflict_file.resolve_lines(empty_hash) } + .to raise_error(Gitlab::Conflict::File::MissingResolution) - expect { conflict_file.resolve_lines(invalid_hash) }. - to raise_error(Gitlab::Conflict::File::MissingResolution) + expect { conflict_file.resolve_lines(invalid_hash) } + .to raise_error(Gitlab::Conflict::File::MissingResolution) end end @@ -250,8 +250,8 @@ FILE describe '#as_json' do it 'includes the blob path for the file' do - expect(conflict_file.as_json[:blob_path]). - to eq("/#{project.full_path}/blob/#{our_commit.oid}/files/ruby/regex.rb") + expect(conflict_file.as_json[:blob_path]) + .to eq("/#{project.full_path}/blob/#{our_commit.oid}/files/ruby/regex.rb") end it 'includes the blob icon for the file' do @@ -264,8 +264,8 @@ FILE end it 'includes the detected language of the conflict file' do - expect(conflict_file.as_json(full_content: true)[:blob_ace_mode]). - to eq('ruby') + expect(conflict_file.as_json(full_content: true)[:blob_ace_mode]) + .to eq('ruby') end end end diff --git a/spec/lib/gitlab/conflict/parser_spec.rb b/spec/lib/gitlab/conflict/parser_spec.rb index 2570f95dd21..aed57b75789 100644 --- a/spec/lib/gitlab/conflict/parser_spec.rb +++ b/spec/lib/gitlab/conflict/parser_spec.rb @@ -122,18 +122,18 @@ CONFLICT context 'when the file contents include conflict delimiters' do context 'when there is a non-start delimiter first' do it 'raises UnexpectedDelimiter when there is a middle delimiter first' do - expect { parse_text('=======') }. - to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) + expect { parse_text('=======') } + .to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) end it 'raises UnexpectedDelimiter when there is an end delimiter first' do - expect { parse_text('>>>>>>> README.md') }. - to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) + expect { parse_text('>>>>>>> README.md') } + .to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) end it 'does not raise when there is an end delimiter for a different path first' do - expect { parse_text('>>>>>>> some-other-path.md') }. - not_to raise_error + expect { parse_text('>>>>>>> some-other-path.md') } + .not_to raise_error end end @@ -142,18 +142,18 @@ CONFLICT let(:end_text) { "\n=======\n>>>>>>> README.md" } it 'raises UnexpectedDelimiter when it is followed by an end delimiter' do - expect { parse_text(start_text + '>>>>>>> README.md' + end_text) }. - to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) + expect { parse_text(start_text + '>>>>>>> README.md' + end_text) } + .to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) end it 'raises UnexpectedDelimiter when it is followed by another start delimiter' do - expect { parse_text(start_text + start_text + end_text) }. - to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) + expect { parse_text(start_text + start_text + end_text) } + .to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) end it 'does not raise when it is followed by a start delimiter for a different path' do - expect { parse_text(start_text + '>>>>>>> some-other-path.md' + end_text) }. - not_to raise_error + expect { parse_text(start_text + '>>>>>>> some-other-path.md' + end_text) } + .not_to raise_error end end @@ -162,59 +162,59 @@ CONFLICT let(:end_text) { "\n>>>>>>> README.md" } it 'raises UnexpectedDelimiter when it is followed by another middle delimiter' do - expect { parse_text(start_text + '=======' + end_text) }. - to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) + expect { parse_text(start_text + '=======' + end_text) } + .to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) end it 'raises UnexpectedDelimiter when it is followed by a start delimiter' do - expect { parse_text(start_text + start_text + end_text) }. - to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) + expect { parse_text(start_text + start_text + end_text) } + .to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) end it 'does not raise when it is followed by a start delimiter for another path' do - expect { parse_text(start_text + '<<<<<<< some-other-path.md' + end_text) }. - not_to raise_error + expect { parse_text(start_text + '<<<<<<< some-other-path.md' + end_text) } + .not_to raise_error end end it 'raises MissingEndDelimiter when there is no end delimiter at the end' do start_text = "<<<<<<< README.md\n=======\n" - expect { parse_text(start_text) }. - to raise_error(Gitlab::Conflict::Parser::MissingEndDelimiter) + expect { parse_text(start_text) } + .to raise_error(Gitlab::Conflict::Parser::MissingEndDelimiter) - expect { parse_text(start_text + '>>>>>>> some-other-path.md') }. - to raise_error(Gitlab::Conflict::Parser::MissingEndDelimiter) + expect { parse_text(start_text + '>>>>>>> some-other-path.md') } + .to raise_error(Gitlab::Conflict::Parser::MissingEndDelimiter) end end context 'other file types' do it 'raises UnmergeableFile when lines is blank, indicating a binary file' do - expect { parse_text('') }. - to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) + expect { parse_text('') } + .to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) - expect { parse_text(nil) }. - to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) + expect { parse_text(nil) } + .to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) end it 'raises UnmergeableFile when the file is over 200 KB' do - expect { parse_text('a' * 204801) }. - to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) + expect { parse_text('a' * 204801) } + .to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) end # All text from Rugged has an encoding of ASCII_8BIT, so force that in # these strings. context 'when the file contains UTF-8 characters' do it 'does not raise' do - expect { parse_text("Espa\xC3\xB1a".force_encoding(Encoding::ASCII_8BIT)) }. - not_to raise_error + expect { parse_text("Espa\xC3\xB1a".force_encoding(Encoding::ASCII_8BIT)) } + .not_to raise_error end end context 'when the file contains non-UTF-8 characters' do it 'raises UnsupportedEncoding' do - expect { parse_text("a\xC4\xFC".force_encoding(Encoding::ASCII_8BIT)) }. - to raise_error(Gitlab::Conflict::Parser::UnsupportedEncoding) + expect { parse_text("a\xC4\xFC".force_encoding(Encoding::ASCII_8BIT)) } + .to raise_error(Gitlab::Conflict::Parser::UnsupportedEncoding) end end end diff --git a/spec/lib/gitlab/data_builder/push_spec.rb b/spec/lib/gitlab/data_builder/push_spec.rb index e59cba35b2f..73936969832 100644 --- a/spec/lib/gitlab/data_builder/push_spec.rb +++ b/spec/lib/gitlab/data_builder/push_spec.rb @@ -47,8 +47,8 @@ describe Gitlab::DataBuilder::Push, lib: true do include_examples 'deprecated repository hook data' it 'does not raise an error when given nil commits' do - expect { described_class.build(spy, spy, spy, spy, spy, nil) }. - not_to raise_error + expect { described_class.build(spy, spy, spy, spy, spy, nil) } + .not_to raise_error end end end diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 30aa463faf8..6a0485112c1 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -57,15 +57,15 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end it 'creates the index concurrently' do - expect(model).to receive(:add_index). - with(:users, :foo, algorithm: :concurrently) + expect(model).to receive(:add_index) + .with(:users, :foo, algorithm: :concurrently) model.add_concurrent_index(:users, :foo) end it 'creates unique index concurrently' do - expect(model).to receive(:add_index). - with(:users, :foo, { algorithm: :concurrently, unique: true }) + expect(model).to receive(:add_index) + .with(:users, :foo, { algorithm: :concurrently, unique: true }) model.add_concurrent_index(:users, :foo, unique: true) end @@ -75,8 +75,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'creates a regular index' do expect(Gitlab::Database).to receive(:postgresql?).and_return(false) - expect(model).to receive(:add_index). - with(:users, :foo, {}) + expect(model).to receive(:add_index) + .with(:users, :foo, {}) model.add_concurrent_index(:users, :foo) end @@ -87,8 +87,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'raises RuntimeError' do expect(model).to receive(:transaction_open?).and_return(true) - expect { model.add_concurrent_index(:users, :foo) }. - to raise_error(RuntimeError) + expect { model.add_concurrent_index(:users, :foo) } + .to raise_error(RuntimeError) end end end @@ -106,15 +106,15 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end it 'removes the index concurrently by column name' do - expect(model).to receive(:remove_index). - with(:users, { algorithm: :concurrently, column: :foo }) + expect(model).to receive(:remove_index) + .with(:users, { algorithm: :concurrently, column: :foo }) model.remove_concurrent_index(:users, :foo) end it 'removes the index concurrently by index name' do - expect(model).to receive(:remove_index). - with(:users, { algorithm: :concurrently, name: "index_x_by_y" }) + expect(model).to receive(:remove_index) + .with(:users, { algorithm: :concurrently, name: "index_x_by_y" }) model.remove_concurrent_index_by_name(:users, "index_x_by_y") end @@ -124,8 +124,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'removes an index' do expect(Gitlab::Database).to receive(:postgresql?).and_return(false) - expect(model).to receive(:remove_index). - with(:users, { column: :foo }) + expect(model).to receive(:remove_index) + .with(:users, { column: :foo }) model.remove_concurrent_index(:users, :foo) end @@ -136,8 +136,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'raises RuntimeError' do expect(model).to receive(:transaction_open?).and_return(true) - expect { model.remove_concurrent_index(:users, :foo) }. - to raise_error(RuntimeError) + expect { model.remove_concurrent_index(:users, :foo) } + .to raise_error(RuntimeError) end end end @@ -162,8 +162,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'creates a regular foreign key' do allow(Gitlab::Database).to receive(:mysql?).and_return(true) - expect(model).to receive(:add_foreign_key). - with(:projects, :users, column: :user_id, on_delete: :cascade) + expect(model).to receive(:add_foreign_key) + .with(:projects, :users, column: :user_id, on_delete: :cascade) model.add_concurrent_foreign_key(:projects, :users, column: :user_id) end @@ -307,16 +307,16 @@ describe Gitlab::Database::MigrationHelpers, lib: true do expect(model).to receive(:transaction).and_yield - expect(model).to receive(:add_column). - with(:projects, :foo, :integer, default: nil) + expect(model).to receive(:add_column) + .with(:projects, :foo, :integer, default: nil) - expect(model).to receive(:change_column_default). - with(:projects, :foo, 10) + expect(model).to receive(:change_column_default) + .with(:projects, :foo, 10) end it 'adds the column while allowing NULL values' do - expect(model).to receive(:update_column_in_batches). - with(:projects, :foo, 10) + expect(model).to receive(:update_column_in_batches) + .with(:projects, :foo, 10) expect(model).not_to receive(:change_column_null) @@ -326,22 +326,22 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end it 'adds the column while not allowing NULL values' do - expect(model).to receive(:update_column_in_batches). - with(:projects, :foo, 10) + expect(model).to receive(:update_column_in_batches) + .with(:projects, :foo, 10) - expect(model).to receive(:change_column_null). - with(:projects, :foo, false) + expect(model).to receive(:change_column_null) + .with(:projects, :foo, false) model.add_column_with_default(:projects, :foo, :integer, default: 10) end it 'removes the added column whenever updating the rows fails' do - expect(model).to receive(:update_column_in_batches). - with(:projects, :foo, 10). - and_raise(RuntimeError) + expect(model).to receive(:update_column_in_batches) + .with(:projects, :foo, 10) + .and_raise(RuntimeError) - expect(model).to receive(:remove_column). - with(:projects, :foo) + expect(model).to receive(:remove_column) + .with(:projects, :foo) expect do model.add_column_with_default(:projects, :foo, :integer, default: 10) @@ -349,12 +349,12 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end it 'removes the added column whenever changing a column NULL constraint fails' do - expect(model).to receive(:change_column_null). - with(:projects, :foo, false). - and_raise(RuntimeError) + expect(model).to receive(:change_column_null) + .with(:projects, :foo, false) + .and_raise(RuntimeError) - expect(model).to receive(:remove_column). - with(:projects, :foo) + expect(model).to receive(:remove_column) + .with(:projects, :foo) expect do model.add_column_with_default(:projects, :foo, :integer, default: 10) @@ -370,8 +370,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do allow(model).to receive(:change_column_null).with(:projects, :foo, false) allow(model).to receive(:change_column_default).with(:projects, :foo, 10) - expect(model).to receive(:add_column). - with(:projects, :foo, :integer, default: nil, limit: 8) + expect(model).to receive(:add_column) + .with(:projects, :foo, :integer, default: nil, limit: 8) model.add_column_with_default(:projects, :foo, :integer, default: 10, limit: 8) end @@ -394,8 +394,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'raises RuntimeError' do allow(model).to receive(:transaction_open?).and_return(true) - expect { model.rename_column_concurrently(:users, :old, :new) }. - to raise_error(RuntimeError) + expect { model.rename_column_concurrently(:users, :old, :new) } + .to raise_error(RuntimeError) end end @@ -426,17 +426,17 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'renames a column concurrently' do allow(Gitlab::Database).to receive(:postgresql?).and_return(false) - expect(model).to receive(:install_rename_triggers_for_mysql). - with(trigger_name, 'users', 'old', 'new') + expect(model).to receive(:install_rename_triggers_for_mysql) + .with(trigger_name, 'users', 'old', 'new') - expect(model).to receive(:add_column). - with(:users, :new, :integer, + expect(model).to receive(:add_column) + .with(:users, :new, :integer, limit: old_column.limit, precision: old_column.precision, scale: old_column.scale) - expect(model).to receive(:change_column_default). - with(:users, :new, old_column.default) + expect(model).to receive(:change_column_default) + .with(:users, :new, old_column.default) expect(model).to receive(:update_column_in_batches) @@ -453,17 +453,17 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'renames a column concurrently' do allow(Gitlab::Database).to receive(:postgresql?).and_return(true) - expect(model).to receive(:install_rename_triggers_for_postgresql). - with(trigger_name, 'users', 'old', 'new') + expect(model).to receive(:install_rename_triggers_for_postgresql) + .with(trigger_name, 'users', 'old', 'new') - expect(model).to receive(:add_column). - with(:users, :new, :integer, + expect(model).to receive(:add_column) + .with(:users, :new, :integer, limit: old_column.limit, precision: old_column.precision, scale: old_column.scale) - expect(model).to receive(:change_column_default). - with(:users, :new, old_column.default) + expect(model).to receive(:change_column_default) + .with(:users, :new, old_column.default) expect(model).to receive(:update_column_in_batches) @@ -482,8 +482,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'cleans up the renaming procedure for PostgreSQL' do allow(Gitlab::Database).to receive(:postgresql?).and_return(true) - expect(model).to receive(:remove_rename_triggers_for_postgresql). - with(:users, /trigger_.{12}/) + expect(model).to receive(:remove_rename_triggers_for_postgresql) + .with(:users, /trigger_.{12}/) expect(model).to receive(:remove_column).with(:users, :old) @@ -493,8 +493,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'cleans up the renaming procedure for MySQL' do allow(Gitlab::Database).to receive(:postgresql?).and_return(false) - expect(model).to receive(:remove_rename_triggers_for_mysql). - with(/trigger_.{12}/) + expect(model).to receive(:remove_rename_triggers_for_mysql) + .with(/trigger_.{12}/) expect(model).to receive(:remove_column).with(:users, :old) @@ -504,8 +504,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do describe '#change_column_type_concurrently' do it 'changes the column type' do - expect(model).to receive(:rename_column_concurrently). - with('users', 'username', 'username_for_type_change', type: :text) + expect(model).to receive(:rename_column_concurrently) + .with('users', 'username', 'username_for_type_change', type: :text) model.change_column_type_concurrently('users', 'username', :text) end @@ -513,11 +513,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do describe '#cleanup_concurrent_column_type_change' do it 'cleans up the type changing procedure' do - expect(model).to receive(:cleanup_concurrent_column_rename). - with('users', 'username', 'username_for_type_change') + expect(model).to receive(:cleanup_concurrent_column_rename) + .with('users', 'username', 'username_for_type_change') - expect(model).to receive(:rename_column). - with('users', 'username_for_type_change', 'username') + expect(model).to receive(:rename_column) + .with('users', 'username_for_type_change', 'username') model.cleanup_concurrent_column_type_change('users', 'username') end @@ -525,11 +525,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do describe '#install_rename_triggers_for_postgresql' do it 'installs the triggers for PostgreSQL' do - expect(model).to receive(:execute). - with(/CREATE OR REPLACE FUNCTION foo()/m) + expect(model).to receive(:execute) + .with(/CREATE OR REPLACE FUNCTION foo()/m) - expect(model).to receive(:execute). - with(/CREATE TRIGGER foo/m) + expect(model).to receive(:execute) + .with(/CREATE TRIGGER foo/m) model.install_rename_triggers_for_postgresql('foo', :users, :old, :new) end @@ -537,11 +537,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do describe '#install_rename_triggers_for_mysql' do it 'installs the triggers for MySQL' do - expect(model).to receive(:execute). - with(/CREATE TRIGGER foo_insert.+ON users/m) + expect(model).to receive(:execute) + .with(/CREATE TRIGGER foo_insert.+ON users/m) - expect(model).to receive(:execute). - with(/CREATE TRIGGER foo_update.+ON users/m) + expect(model).to receive(:execute) + .with(/CREATE TRIGGER foo_update.+ON users/m) model.install_rename_triggers_for_mysql('foo', :users, :old, :new) end @@ -567,8 +567,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do describe '#rename_trigger_name' do it 'returns a String' do - expect(model.rename_trigger_name(:users, :foo, :bar)). - to match(/trigger_.{12}/) + expect(model.rename_trigger_name(:users, :foo, :bar)) + .to match(/trigger_.{12}/) end end @@ -607,11 +607,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do lengths: [], orders: []) - allow(model).to receive(:indexes_for).with(:issues, 'project_id'). - and_return([index]) + allow(model).to receive(:indexes_for).with(:issues, 'project_id') + .and_return([index]) - expect(model).to receive(:add_concurrent_index). - with(:issues, + expect(model).to receive(:add_concurrent_index) + .with(:issues, %w(gl_project_id), unique: false, name: 'index_on_issues_gl_project_id', @@ -634,11 +634,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do lengths: [], orders: []) - allow(model).to receive(:indexes_for).with(:issues, 'project_id'). - and_return([index]) + allow(model).to receive(:indexes_for).with(:issues, 'project_id') + .and_return([index]) - expect(model).to receive(:add_concurrent_index). - with(:issues, + expect(model).to receive(:add_concurrent_index) + .with(:issues, %w(gl_project_id foobar), unique: false, name: 'index_on_issues_gl_project_id_foobar', @@ -661,11 +661,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do lengths: [], orders: []) - allow(model).to receive(:indexes_for).with(:issues, 'project_id'). - and_return([index]) + allow(model).to receive(:indexes_for).with(:issues, 'project_id') + .and_return([index]) - expect(model).to receive(:add_concurrent_index). - with(:issues, + expect(model).to receive(:add_concurrent_index) + .with(:issues, %w(gl_project_id), unique: false, name: 'index_on_issues_gl_project_id', @@ -689,11 +689,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do lengths: [], orders: []) - allow(model).to receive(:indexes_for).with(:issues, 'project_id'). - and_return([index]) + allow(model).to receive(:indexes_for).with(:issues, 'project_id') + .and_return([index]) - expect(model).to receive(:add_concurrent_index). - with(:issues, + expect(model).to receive(:add_concurrent_index) + .with(:issues, %w(gl_project_id), unique: false, name: 'index_on_issues_gl_project_id', @@ -717,11 +717,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do lengths: [], orders: []) - allow(model).to receive(:indexes_for).with(:issues, 'project_id'). - and_return([index]) + allow(model).to receive(:indexes_for).with(:issues, 'project_id') + .and_return([index]) - expect(model).to receive(:add_concurrent_index). - with(:issues, + expect(model).to receive(:add_concurrent_index) + .with(:issues, %w(gl_project_id), unique: false, name: 'index_on_issues_gl_project_id', @@ -745,11 +745,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do lengths: [], orders: []) - allow(model).to receive(:indexes_for).with(:issues, 'project_id'). - and_return([index]) + allow(model).to receive(:indexes_for).with(:issues, 'project_id') + .and_return([index]) - expect { model.copy_indexes(:issues, :project_id, :gl_project_id) }. - to raise_error(RuntimeError) + expect { model.copy_indexes(:issues, :project_id, :gl_project_id) } + .to raise_error(RuntimeError) end end end @@ -761,11 +761,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do to_table: 'projects', on_delete: :cascade) - allow(model).to receive(:foreign_keys_for).with(:issues, :project_id). - and_return([fk]) + allow(model).to receive(:foreign_keys_for).with(:issues, :project_id) + .and_return([fk]) - expect(model).to receive(:add_concurrent_foreign_key). - with('issues', 'projects', column: :gl_project_id, on_delete: :cascade) + expect(model).to receive(:add_concurrent_foreign_key) + .with('issues', 'projects', column: :gl_project_id, on_delete: :cascade) model.copy_foreign_keys(:issues, :project_id, :gl_project_id) end @@ -790,8 +790,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end it 'builds the sql with correct functions' do - expect(model.replace_sql(Arel::Table.new(:users)[:first_name], "Alice", "Eve").to_s). - to include('regexp_replace') + expect(model.replace_sql(Arel::Table.new(:users)[:first_name], "Alice", "Eve").to_s) + .to include('regexp_replace') end end @@ -801,8 +801,8 @@ describe Gitlab::Database::MigrationHelpers, lib: true do end it 'builds the sql with the correct functions' do - expect(model.replace_sql(Arel::Table.new(:users)[:first_name], "Alice", "Eve").to_s). - to include('locate', 'insert') + expect(model.replace_sql(Arel::Table.new(:users)[:first_name], "Alice", "Eve").to_s) + .to include('locate', 'insert') end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index ce2b5d620fd..aa63f6f9805 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -21,8 +21,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do parent = create(:group, path: 'parent') child = create(:group, path: 'the-path', parent: parent) - found_ids = subject.namespaces_for_paths(type: :child). - map(&:id) + found_ids = subject.namespaces_for_paths(type: :child) + .map(&:id) expect(found_ids).to contain_exactly(child.id) end @@ -38,8 +38,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do path: 'the-path', parent: create(:group)) - found_ids = subject.namespaces_for_paths(type: :child). - map(&:id) + found_ids = subject.namespaces_for_paths(type: :child) + .map(&:id) expect(found_ids).to contain_exactly(namespace.id) end @@ -53,8 +53,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do path: 'the-path', parent: create(:group)) - found_ids = subject.namespaces_for_paths(type: :child). - map(&:id) + found_ids = subject.namespaces_for_paths(type: :child) + .map(&:id) expect(found_ids).to contain_exactly(namespace.id) end @@ -68,8 +68,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do path: 'the-path', parent: create(:group)) - found_ids = subject.namespaces_for_paths(type: :top_level). - map(&:id) + found_ids = subject.namespaces_for_paths(type: :top_level) + .map(&:id) expect(found_ids).to contain_exactly(root_namespace.id) end @@ -81,8 +81,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do path: 'the-path', parent: create(:group)) - found_ids = subject.namespaces_for_paths(type: :top_level). - map(&:id) + found_ids = subject.namespaces_for_paths(type: :top_level) + .map(&:id) expect(found_ids).to contain_exactly(root_namespace.id) end @@ -140,9 +140,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do let(:namespace) { create(:group, name: 'the-path') } it 'renames paths & routes for the namespace' do - expect(subject).to receive(:rename_path_for_routable). - with(namespace). - and_call_original + expect(subject).to receive(:rename_path_for_routable) + .with(namespace) + .and_call_original subject.rename_namespace(namespace) @@ -211,15 +211,15 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do end it 'renames top level namespaces the namespace' do - expect(subject).to receive(:rename_namespace). - with(migration_namespace(top_level_namespace)) + expect(subject).to receive(:rename_namespace) + .with(migration_namespace(top_level_namespace)) subject.rename_namespaces(type: :top_level) end it 'renames child namespaces' do - expect(subject).to receive(:rename_namespace). - with(migration_namespace(child_namespace)) + expect(subject).to receive(:rename_namespace) + .with(migration_namespace(child_namespace)) subject.rename_namespaces(type: :child) end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index 59e8de2712d..9a6ed98898d 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -13,8 +13,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects do namespace = create(:namespace, path: 'hello') project = create(:empty_project, path: 'THE-path', namespace: namespace) - result_ids = described_class.new(['Hello/the-path'], migration). - projects_for_paths.map(&:id) + result_ids = described_class.new(['Hello/the-path'], migration) + .projects_for_paths.map(&:id) expect(result_ids).to contain_exactly(project.id) end @@ -39,8 +39,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects do end it 'invalidates the markdown cache of related projects' do - expect(subject).to receive(:remove_cached_html_for_projects). - with(projects.map(&:id)) + expect(subject).to receive(:remove_cached_html_for_projects) + .with(projects.map(&:id)) subject.rename_projects end @@ -54,9 +54,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects do end it 'renames path & route for the project' do - expect(subject).to receive(:rename_path_for_routable). - with(project). - and_call_original + expect(subject).to receive(:rename_path_for_routable) + .with(project) + .and_call_original subject.rename_project(project) @@ -64,24 +64,24 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects do end it 'moves the wiki & the repo' do - expect(subject).to receive(:move_repository). - with(project, 'known-parent/the-path.wiki', 'known-parent/the-path0.wiki') - expect(subject).to receive(:move_repository). - with(project, 'known-parent/the-path', 'known-parent/the-path0') + expect(subject).to receive(:move_repository) + .with(project, 'known-parent/the-path.wiki', 'known-parent/the-path0.wiki') + expect(subject).to receive(:move_repository) + .with(project, 'known-parent/the-path', 'known-parent/the-path0') subject.rename_project(project) end it 'moves uploads' do - expect(subject).to receive(:move_uploads). - with('known-parent/the-path', 'known-parent/the-path0') + expect(subject).to receive(:move_uploads) + .with('known-parent/the-path', 'known-parent/the-path0') subject.rename_project(project) end it 'moves pages' do - expect(subject).to receive(:move_pages). - with('known-parent/the-path', 'known-parent/the-path0') + expect(subject).to receive(:move_pages) + .with('known-parent/the-path', 'known-parent/the-path0') subject.rename_project(project) end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb index f8cc1eb91ec..bdd3af4ad44 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' shared_examples 'renames child namespaces' do |type| it 'renames namespaces' do rename_namespaces = double - expect(described_class::RenameNamespaces). - to receive(:new).with(['first-path', 'second-path'], subject). - and_return(rename_namespaces) - expect(rename_namespaces).to receive(:rename_namespaces). - with(type: :child) + expect(described_class::RenameNamespaces) + .to receive(:new).with(['first-path', 'second-path'], subject) + .and_return(rename_namespaces) + expect(rename_namespaces).to receive(:rename_namespaces) + .with(type: :child) subject.rename_wildcard_paths(['first-path', 'second-path']) end @@ -29,9 +29,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1 do it 'should rename projects' do rename_projects = double - expect(described_class::RenameProjects). - to receive(:new).with(['the-path'], subject). - and_return(rename_projects) + expect(described_class::RenameProjects) + .to receive(:new).with(['the-path'], subject) + .and_return(rename_projects) expect(rename_projects).to receive(:rename_projects) @@ -42,11 +42,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1 do describe '#rename_root_paths' do it 'should rename namespaces' do rename_namespaces = double - expect(described_class::RenameNamespaces). - to receive(:new).with(['the-path'], subject). - and_return(rename_namespaces) - expect(rename_namespaces).to receive(:rename_namespaces). - with(type: :top_level) + expect(described_class::RenameNamespaces) + .to receive(:new).with(['the-path'], subject) + .and_return(rename_namespaces) + expect(rename_namespaces).to receive(:rename_namespaces) + .with(type: :top_level) subject.rename_root_paths('the-path') end diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 428b6edb7d6..5e6206b96c7 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -34,8 +34,8 @@ describe Gitlab::Database, lib: true do describe '.version' do context "on mysql" do it "extracts the version number" do - allow(described_class).to receive(:database_version). - and_return("5.7.12-standard") + allow(described_class).to receive(:database_version) + .and_return("5.7.12-standard") expect(described_class.version).to eq '5.7.12-standard' end @@ -43,8 +43,8 @@ describe Gitlab::Database, lib: true do context "on postgresql" do it "extracts the version number" do - allow(described_class).to receive(:database_version). - and_return("PostgreSQL 9.4.4 on x86_64-apple-darwin14.3.0") + allow(described_class).to receive(:database_version) + .and_return("PostgreSQL 9.4.4 on x86_64-apple-darwin14.3.0") expect(described_class.version).to eq '9.4.4' end diff --git a/spec/lib/gitlab/downtime_check_spec.rb b/spec/lib/gitlab/downtime_check_spec.rb index 42d895e548e..1f1e4e0216c 100644 --- a/spec/lib/gitlab/downtime_check_spec.rb +++ b/spec/lib/gitlab/downtime_check_spec.rb @@ -11,12 +11,12 @@ describe Gitlab::DowntimeCheck do context 'when a migration does not specify if downtime is required' do it 'raises RuntimeError' do - expect(subject).to receive(:class_for_migration_file). - with(path). - and_return(Class.new) + expect(subject).to receive(:class_for_migration_file) + .with(path) + .and_return(Class.new) - expect { subject.check([path]) }. - to raise_error(RuntimeError, /it requires downtime/) + expect { subject.check([path]) } + .to raise_error(RuntimeError, /it requires downtime/) end end @@ -25,12 +25,12 @@ describe Gitlab::DowntimeCheck do it 'raises RuntimeError' do stub_const('TestMigration::DOWNTIME', true) - expect(subject).to receive(:class_for_migration_file). - with(path). - and_return(TestMigration) + expect(subject).to receive(:class_for_migration_file) + .with(path) + .and_return(TestMigration) - expect { subject.check([path]) }. - to raise_error(RuntimeError, /no reason was given/) + expect { subject.check([path]) } + .to raise_error(RuntimeError, /no reason was given/) end end @@ -39,9 +39,9 @@ describe Gitlab::DowntimeCheck do stub_const('TestMigration::DOWNTIME', true) stub_const('TestMigration::DOWNTIME_REASON', 'foo') - expect(subject).to receive(:class_for_migration_file). - with(path). - and_return(TestMigration) + expect(subject).to receive(:class_for_migration_file) + .with(path) + .and_return(TestMigration) messages = subject.check([path]) @@ -65,9 +65,9 @@ describe Gitlab::DowntimeCheck do expect(subject).to receive(:require).with(path) - expect(subject).to receive(:class_for_migration_file). - with(path). - and_return(TestMigration) + expect(subject).to receive(:class_for_migration_file) + .with(path) + .and_return(TestMigration) expect(subject).to receive(:puts).with(an_instance_of(String)) diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index 71659d5e8b0..2ea5e6460a3 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -20,8 +20,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "properly renders plaintext-only email" do - expect(test_parse_body(fixture_file("emails/plaintext_only.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/plaintext_only.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp ### reply from default mail client in Windows 8.1 Metro @@ -46,8 +46,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "handles multiple paragraphs" do - expect(test_parse_body(fixture_file("emails/paragraphs.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/paragraphs.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp Is there any reason the *old* candy can't be be kept in silos while the new candy is imported into *new* silos? @@ -61,8 +61,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "handles multiple paragraphs when parsing html" do - expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp Awesome! @@ -74,8 +74,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "handles newlines" do - expect(test_parse_body(fixture_file("emails/newlines.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/newlines.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp This is my reply. It is my best reply. @@ -85,8 +85,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "handles inline reply" do - expect(test_parse_body(fixture_file("emails/inline_reply.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/inline_reply.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp > techAPJ > November 28 @@ -132,8 +132,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "properly renders email reply from gmail web client" do - expect(test_parse_body(fixture_file("emails/gmail_web.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/gmail_web.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp ### This is a reply from standard GMail in Google Chrome. @@ -151,8 +151,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "properly renders email reply from iOS default mail client" do - expect(test_parse_body(fixture_file("emails/ios_default.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/ios_default.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp ### this is a reply from iOS default mail @@ -166,8 +166,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "properly renders email reply from Android 5 gmail client" do - expect(test_parse_body(fixture_file("emails/android_gmail.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/android_gmail.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp ### this is a reply from Android 5 gmail @@ -184,8 +184,8 @@ describe Gitlab::Email::ReplyParser, lib: true do end it "properly renders email reply from Windows 8.1 Metro default mail client" do - expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))). - to eq( + expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))) + .to eq( <<-BODY.strip_heredoc.chomp ### reply from default mail client in Windows 8.1 Metro diff --git a/spec/lib/gitlab/etag_caching/middleware_spec.rb b/spec/lib/gitlab/etag_caching/middleware_spec.rb index 4acf4f047f1..4a54d641b4e 100644 --- a/spec/lib/gitlab/etag_caching/middleware_spec.rb +++ b/spec/lib/gitlab/etag_caching/middleware_spec.rb @@ -108,8 +108,8 @@ describe Gitlab::EtagCaching::Middleware do context 'when polling is disabled' do before do - allow(Gitlab::PollingInterval).to receive(:polling_enabled?). - and_return(false) + allow(Gitlab::PollingInterval).to receive(:polling_enabled?) + .and_return(false) end it 'returns status code 429' do diff --git a/spec/lib/gitlab/file_detector_spec.rb b/spec/lib/gitlab/file_detector_spec.rb index e5ba13bbaf8..695fd6f8573 100644 --- a/spec/lib/gitlab/file_detector_spec.rb +++ b/spec/lib/gitlab/file_detector_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' describe Gitlab::FileDetector do describe '.types_in_paths' do it 'returns the file types for the given paths' do - expect(described_class.types_in_paths(%w(README.md CHANGELOG VERSION VERSION))). - to eq(%i{readme changelog version}) + expect(described_class.types_in_paths(%w(README.md CHANGELOG VERSION VERSION))) + .to eq(%i{readme changelog version}) end it 'does not include unrecognized file paths' do - expect(described_class.types_in_paths(%w(README.md foo.txt))). - to eq(%i{readme}) + expect(described_class.types_in_paths(%w(README.md foo.txt))) + .to eq(%i{readme}) end end diff --git a/spec/lib/gitlab/git/attributes_spec.rb b/spec/lib/gitlab/git/attributes_spec.rb index 1cfd8db09a5..b715fc3410a 100644 --- a/spec/lib/gitlab/git/attributes_spec.rb +++ b/spec/lib/gitlab/git/attributes_spec.rb @@ -14,13 +14,13 @@ describe Gitlab::Git::Attributes, seed_helper: true do end it 'returns a Hash containing multiple attributes' do - expect(subject.attributes('test.sh')). - to eq({ 'eol' => 'lf', 'gitlab-language' => 'shell' }) + expect(subject.attributes('test.sh')) + .to eq({ 'eol' => 'lf', 'gitlab-language' => 'shell' }) end it 'returns a Hash containing attributes for a file with multiple extensions' do - expect(subject.attributes('test.haml.html')). - to eq({ 'gitlab-language' => 'haml' }) + expect(subject.attributes('test.haml.html')) + .to eq({ 'gitlab-language' => 'haml' }) end it 'returns a Hash containing attributes for a file in a directory' do @@ -28,8 +28,8 @@ describe Gitlab::Git::Attributes, seed_helper: true do end it 'returns a Hash containing attributes with query string parameters' do - expect(subject.attributes('foo.cgi')). - to eq({ 'key' => 'value?p1=v1&p2=v2' }) + expect(subject.attributes('foo.cgi')) + .to eq({ 'key' => 'value?p1=v1&p2=v2' }) end it 'returns a Hash containing the attributes for an absolute path' do @@ -39,11 +39,11 @@ describe Gitlab::Git::Attributes, seed_helper: true do it 'returns a Hash containing the attributes when a pattern is defined using an absolute path' do # When a path is given without a leading slash it should still match # patterns defined with a leading slash. - expect(subject.attributes('foo.png')). - to eq({ 'gitlab-language' => 'png' }) + expect(subject.attributes('foo.png')) + .to eq({ 'gitlab-language' => 'png' }) - expect(subject.attributes('/foo.png')). - to eq({ 'gitlab-language' => 'png' }) + expect(subject.attributes('/foo.png')) + .to eq({ 'gitlab-language' => 'png' }) end it 'returns an empty Hash for a defined path without attributes' do @@ -74,8 +74,8 @@ describe Gitlab::Git::Attributes, seed_helper: true do end it 'parses an entry that uses a tab to separate the pattern and attributes' do - expect(subject.patterns[File.join(path, '*.md')]). - to eq({ 'gitlab-language' => 'markdown' }) + expect(subject.patterns[File.join(path, '*.md')]) + .to eq({ 'gitlab-language' => 'markdown' }) end it 'stores patterns in reverse order' do @@ -91,9 +91,9 @@ describe Gitlab::Git::Attributes, seed_helper: true do end it 'does not parse anything when the attributes file does not exist' do - expect(File).to receive(:exist?). - with(File.join(path, 'info/attributes')). - and_return(false) + expect(File).to receive(:exist?) + .with(File.join(path, 'info/attributes')) + .and_return(false) expect(subject.patterns).to eq({}) end @@ -115,13 +115,13 @@ describe Gitlab::Git::Attributes, seed_helper: true do it 'parses multiple attributes' do input = 'boolean key=value -negated' - expect(subject.parse_attributes(input)). - to eq({ 'boolean' => true, 'key' => 'value', 'negated' => false }) + expect(subject.parse_attributes(input)) + .to eq({ 'boolean' => true, 'key' => 'value', 'negated' => false }) end it 'parses attributes with query string parameters' do - expect(subject.parse_attributes('foo=bar?baz=1')). - to eq({ 'foo' => 'bar?baz=1' }) + expect(subject.parse_attributes('foo=bar?baz=1')) + .to eq({ 'foo' => 'bar?baz=1' }) end end @@ -133,9 +133,9 @@ describe Gitlab::Git::Attributes, seed_helper: true do end it 'does not yield when the attributes file does not exist' do - expect(File).to receive(:exist?). - with(File.join(path, 'info/attributes')). - and_return(false) + expect(File).to receive(:exist?) + .with(File.join(path, 'info/attributes')) + .and_return(false) expect { |b| subject.each_line(&b) }.not_to yield_control end diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index e6a07a58d73..5b8648392b9 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -92,9 +92,9 @@ describe Gitlab::Git::Blob, seed_helper: true do end it 'marks the blob as binary' do - expect(Gitlab::Git::Blob).to receive(:new). - with(hash_including(binary: true)). - and_call_original + expect(Gitlab::Git::Blob).to receive(:new) + .with(hash_including(binary: true)) + .and_call_original expect(blob).to be_binary end diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb index 9eac7660cd1..9dba4397e79 100644 --- a/spec/lib/gitlab/git/branch_spec.rb +++ b/spec/lib/gitlab/git/branch_spec.rb @@ -45,8 +45,8 @@ describe Gitlab::Git::Branch, seed_helper: true do let(:branch) { described_class.new(repository, 'foo', gitaly_branch) } it 'parses Gitaly::FindLocalBranchResponse correctly' do - expect(Gitlab::Git::Commit).to receive(:decorate). - with(hash_including(attributes)).and_call_original + expect(Gitlab::Git::Commit).to receive(:decorate) + .with(hash_including(attributes)).and_call_original expect(branch.dereferenced_target.message.encoding).to be(Encoding::UTF_8) end diff --git a/spec/lib/gitlab/git/diff_collection_spec.rb b/spec/lib/gitlab/git/diff_collection_spec.rb index a9a7bba2c05..d20298fa139 100644 --- a/spec/lib/gitlab/git/diff_collection_spec.rb +++ b/spec/lib/gitlab/git/diff_collection_spec.rb @@ -325,8 +325,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do end it 'yields Diff instances even when they are too large' do - expect { |b| collection.each(&b) }. - to yield_with_args(an_instance_of(Gitlab::Git::Diff)) + expect { |b| collection.each(&b) } + .to yield_with_args(an_instance_of(Gitlab::Git::Diff)) end it 'prunes diffs that are too large' do @@ -348,8 +348,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do let(:expanded) { true } it 'yields Diff instances even when they are quite big' do - expect { |b| subject.each(&b) }. - to yield_with_args(an_instance_of(Gitlab::Git::Diff)) + expect { |b| subject.each(&b) } + .to yield_with_args(an_instance_of(Gitlab::Git::Diff)) end it 'does not prune diffs' do @@ -367,8 +367,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do let(:expanded) { false } it 'yields Diff instances even when they are quite big' do - expect { |b| subject.each(&b) }. - to yield_with_args(an_instance_of(Gitlab::Git::Diff)) + expect { |b| subject.each(&b) } + .to yield_with_args(an_instance_of(Gitlab::Git::Diff)) end it 'prunes diffs that are quite big' do @@ -454,8 +454,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do let(:limits) { false } it 'yields Diff instances even when they are quite big' do - expect { |b| subject.each(&b) }. - to yield_with_args(an_instance_of(Gitlab::Git::Diff)) + expect { |b| subject.each(&b) } + .to yield_with_args(an_instance_of(Gitlab::Git::Diff)) end it 'does not prune diffs' do diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb index 78d741f0110..5627562abfb 100644 --- a/spec/lib/gitlab/git/diff_spec.rb +++ b/spec/lib/gitlab/git/diff_spec.rb @@ -100,8 +100,8 @@ EOT context 'using a diff that is too large' do it 'prunes the diff' do - expect_any_instance_of(String).to receive(:bytesize). - and_return(1024 * 1024 * 1024) + expect_any_instance_of(String).to receive(:bytesize) + .and_return(1024 * 1024 * 1024) diff = described_class.new(@rugged_diff) @@ -130,8 +130,8 @@ EOT context 'using a large binary diff' do it 'does not prune the diff' do - expect_any_instance_of(Rugged::Diff::Delta).to receive(:binary?). - and_return(true) + expect_any_instance_of(Rugged::Diff::Delta).to receive(:binary?) + .and_return(true) diff = described_class.new(@rugged_diff) diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 02b3f167250..703b0c2c202 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -41,14 +41,14 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name). - and_raise(GRPC::NotFound) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) + .and_raise(GRPC::NotFound) expect { repository.root_ref }.to raise_error(Gitlab::Git::Repository::NoRepository) end it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name). - and_raise(GRPC::Unknown) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) + .and_raise(GRPC::Unknown) expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError) end end @@ -141,14 +141,14 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names). - and_raise(GRPC::NotFound) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) + .and_raise(GRPC::NotFound) expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository) end it 'wraps GRPC other exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names). - and_raise(GRPC::Unknown) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) + .and_raise(GRPC::Unknown) expect { subject }.to raise_error(Gitlab::Git::CommandError) end end @@ -184,14 +184,14 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names). - and_raise(GRPC::NotFound) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) + .and_raise(GRPC::NotFound) expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository) end it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names). - and_raise(GRPC::Unknown) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) + .and_raise(GRPC::Unknown) expect { subject }.to raise_error(Gitlab::Git::CommandError) end end @@ -472,8 +472,8 @@ describe Gitlab::Git::Repository, seed_helper: true do end it "should move the tip of the master branch to the correct commit" do - new_tip = @normal_repo.rugged.references["refs/heads/master"]. - target.oid + new_tip = @normal_repo.rugged.references["refs/heads/master"] + .target.oid expect(new_tip).to eq(reset_commit) end @@ -1306,20 +1306,20 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'gets the branches from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches). - and_return([]) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) + .and_return([]) @repo.local_branches end it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches). - and_raise(GRPC::NotFound) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) + .and_raise(GRPC::NotFound) expect { @repo.local_branches }.to raise_error(Gitlab::Git::Repository::NoRepository) end it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches). - and_raise(GRPC::Unknown) + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) + .and_raise(GRPC::Unknown) expect { @repo.local_branches }.to raise_error(Gitlab::Git::CommandError) end end diff --git a/spec/lib/gitlab/gitaly_client/notifications_spec.rb b/spec/lib/gitlab/gitaly_client/notifications_spec.rb index c2b8ca9f501..7404ffe0f06 100644 --- a/spec/lib/gitlab/gitaly_client/notifications_spec.rb +++ b/spec/lib/gitlab/gitaly_client/notifications_spec.rb @@ -8,8 +8,8 @@ describe Gitlab::GitalyClient::Notifications do subject { described_class.new(project.repository) } it 'sends a post_receive message' do - expect_any_instance_of(Gitaly::Notifications::Stub). - to receive(:post_receive).with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) + expect_any_instance_of(Gitaly::Notifications::Stub) + .to receive(:post_receive).with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) subject.post_receive end diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index 3272333bb33..42dba2ff874 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -19,10 +19,10 @@ describe Gitlab::GitalyClient::Ref do describe '#branch_names' do it 'sends a find_all_branch_names message' do - expect_any_instance_of(Gitaly::Ref::Stub). - to receive(:find_all_branch_names). - with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). - and_return([]) + expect_any_instance_of(Gitaly::Ref::Stub) + .to receive(:find_all_branch_names) + .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) + .and_return([]) client.branch_names end @@ -30,10 +30,10 @@ describe Gitlab::GitalyClient::Ref do describe '#tag_names' do it 'sends a find_all_tag_names message' do - expect_any_instance_of(Gitaly::Ref::Stub). - to receive(:find_all_tag_names). - with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). - and_return([]) + expect_any_instance_of(Gitaly::Ref::Stub) + .to receive(:find_all_tag_names) + .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) + .and_return([]) client.tag_names end @@ -41,10 +41,10 @@ describe Gitlab::GitalyClient::Ref do describe '#default_branch_name' do it 'sends a find_default_branch_name message' do - expect_any_instance_of(Gitaly::Ref::Stub). - to receive(:find_default_branch_name). - with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). - and_return(double(name: 'foo')) + expect_any_instance_of(Gitaly::Ref::Stub) + .to receive(:find_default_branch_name) + .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) + .and_return(double(name: 'foo')) client.default_branch_name end @@ -52,19 +52,19 @@ describe Gitlab::GitalyClient::Ref do describe '#local_branches' do it 'sends a find_local_branches message' do - expect_any_instance_of(Gitaly::Ref::Stub). - to receive(:find_local_branches). - with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)). - and_return([]) + expect_any_instance_of(Gitaly::Ref::Stub) + .to receive(:find_local_branches) + .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) + .and_return([]) client.local_branches end it 'parses and sends the sort parameter' do - expect_any_instance_of(Gitaly::Ref::Stub). - to receive(:find_local_branches). - with(gitaly_request_with_params(sort_by: :UPDATED_DESC), kind_of(Hash)). - and_return([]) + expect_any_instance_of(Gitaly::Ref::Stub) + .to receive(:find_local_branches) + .with(gitaly_request_with_params(sort_by: :UPDATED_DESC), kind_of(Hash)) + .and_return([]) client.local_branches(sort_by: 'updated_desc') end diff --git a/spec/lib/gitlab/gitlab_import/importer_spec.rb b/spec/lib/gitlab/gitlab_import/importer_spec.rb index 9b499b593d3..4f588da0a83 100644 --- a/spec/lib/gitlab/gitlab_import/importer_spec.rb +++ b/spec/lib/gitlab/gitlab_import/importer_spec.rb @@ -45,8 +45,8 @@ describe Gitlab::GitlabImport::Importer, lib: true do def stub_request(path, body) url = "https://gitlab.com/api/v3/projects/asd%2Fvim/#{path}?page=1&per_page=100" - WebMock.stub_request(:get, url). - to_return( + WebMock.stub_request(:get, url) + .to_return( headers: { 'Content-Type' => 'application/json' }, body: body ) diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index fdc5b484ef1..07687b470c5 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -51,8 +51,8 @@ describe Gitlab::Highlight, lib: true do end it 'links dependencies via DependencyLinker' do - expect(Gitlab::DependencyLinker).to receive(:link). - with('file.name', 'Contents', anything).and_call_original + expect(Gitlab::DependencyLinker).to receive(:link) + .with('file.name', 'Contents', anything).and_call_original described_class.highlight('file.name', 'Contents') end diff --git a/spec/lib/gitlab/identifier_spec.rb b/spec/lib/gitlab/identifier_spec.rb index bb758a8a202..29912da2e25 100644 --- a/spec/lib/gitlab/identifier_spec.rb +++ b/spec/lib/gitlab/identifier_spec.rb @@ -12,8 +12,8 @@ describe Gitlab::Identifier do describe '#identify' do context 'without an identifier' do it 'identifies the user using a commit' do - expect(identifier).to receive(:identify_using_commit). - with(project, '123') + expect(identifier).to receive(:identify_using_commit) + .with(project, '123') identifier.identify('', project, '123') end @@ -21,8 +21,8 @@ describe Gitlab::Identifier do context 'with a user identifier' do it 'identifies the user using a user ID' do - expect(identifier).to receive(:identify_using_user). - with("user-#{user.id}") + expect(identifier).to receive(:identify_using_user) + .with("user-#{user.id}") identifier.identify("user-#{user.id}", project, '123') end @@ -30,8 +30,8 @@ describe Gitlab::Identifier do context 'with an SSH key identifier' do it 'identifies the user using an SSH key ID' do - expect(identifier).to receive(:identify_using_ssh_key). - with("key-#{key.id}") + expect(identifier).to receive(:identify_using_ssh_key) + .with("key-#{key.id}") identifier.identify("key-#{key.id}", project, '123') end diff --git a/spec/lib/gitlab/job_waiter_spec.rb b/spec/lib/gitlab/job_waiter_spec.rb index 780f5b1f8d7..6186cec2689 100644 --- a/spec/lib/gitlab/job_waiter_spec.rb +++ b/spec/lib/gitlab/job_waiter_spec.rb @@ -4,8 +4,8 @@ describe Gitlab::JobWaiter do describe '#wait' do let(:waiter) { described_class.new(%w(a)) } it 'returns when all jobs have been completed' do - expect(Gitlab::SidekiqStatus).to receive(:all_completed?).with(%w(a)). - and_return(true) + expect(Gitlab::SidekiqStatus).to receive(:all_completed?).with(%w(a)) + .and_return(true) expect(waiter).not_to receive(:sleep) @@ -13,9 +13,9 @@ describe Gitlab::JobWaiter do end it 'sleeps between checking the job statuses' do - expect(Gitlab::SidekiqStatus).to receive(:all_completed?). - with(%w(a)). - and_return(false, true) + expect(Gitlab::SidekiqStatus).to receive(:all_completed?) + .with(%w(a)) + .and_return(false, true) expect(waiter).to receive(:sleep).with(described_class::INTERVAL) diff --git a/spec/lib/gitlab/ldap/authentication_spec.rb b/spec/lib/gitlab/ldap/authentication_spec.rb index b8f3290e84c..f689b47fec4 100644 --- a/spec/lib/gitlab/ldap/authentication_spec.rb +++ b/spec/lib/gitlab/ldap/authentication_spec.rb @@ -16,8 +16,8 @@ describe Gitlab::LDAP::Authentication, lib: true do # try only to fake the LDAP call adapter = double('adapter', dn: dn).as_null_object - allow_any_instance_of(described_class). - to receive(:adapter).and_return(adapter) + allow_any_instance_of(described_class) + .to receive(:adapter).and_return(adapter) expect(described_class.login(login, password)).to be_truthy end @@ -25,8 +25,8 @@ describe Gitlab::LDAP::Authentication, lib: true do it "is false if the user does not exist" do # try only to fake the LDAP call adapter = double('adapter', dn: dn).as_null_object - allow_any_instance_of(described_class). - to receive(:adapter).and_return(adapter) + allow_any_instance_of(described_class) + .to receive(:adapter).and_return(adapter) expect(described_class.login(login, password)).to be_falsey end @@ -36,8 +36,8 @@ describe Gitlab::LDAP::Authentication, lib: true do # try only to fake the LDAP call adapter = double('adapter', bind_as: nil).as_null_object - allow_any_instance_of(described_class). - to receive(:adapter).and_return(adapter) + allow_any_instance_of(described_class) + .to receive(:adapter).and_return(adapter) expect(described_class.login(login, password)).to be_falsey end diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb index f0a1dd22fee..b796d8bf076 100644 --- a/spec/lib/gitlab/ldap/user_spec.rb +++ b/spec/lib/gitlab/ldap/user_spec.rb @@ -167,8 +167,8 @@ describe Gitlab::LDAP::User, lib: true do describe 'blocking' do def configure_block(value) - allow_any_instance_of(Gitlab::LDAP::Config). - to receive(:block_auto_created_users).and_return(value) + allow_any_instance_of(Gitlab::LDAP::Config) + .to receive(:block_auto_created_users).and_return(value) end context 'signup' do diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb index a986cb520fb..4b19ee19103 100644 --- a/spec/lib/gitlab/metrics/instrumentation_spec.rb +++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb @@ -78,11 +78,11 @@ describe Gitlab::Metrics::Instrumentation do end it 'tracks the call duration upon calling the method' do - allow(Gitlab::Metrics).to receive(:method_call_threshold). - and_return(0) + allow(Gitlab::Metrics).to receive(:method_call_threshold) + .and_return(0) - allow(described_class).to receive(:transaction). - and_return(transaction) + allow(described_class).to receive(:transaction) + .and_return(transaction) expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure) @@ -90,8 +90,8 @@ describe Gitlab::Metrics::Instrumentation do end it 'does not track method calls below a given duration threshold' do - allow(Gitlab::Metrics).to receive(:method_call_threshold). - and_return(100) + allow(Gitlab::Metrics).to receive(:method_call_threshold) + .and_return(100) expect(transaction).not_to receive(:add_metric) @@ -137,8 +137,8 @@ describe Gitlab::Metrics::Instrumentation do before do allow(Gitlab::Metrics).to receive(:enabled?).and_return(true) - described_class. - instrument_instance_method(@dummy, :bar) + described_class + .instrument_instance_method(@dummy, :bar) end it 'instruments instances of the Class' do @@ -156,11 +156,11 @@ describe Gitlab::Metrics::Instrumentation do end it 'tracks the call duration upon calling the method' do - allow(Gitlab::Metrics).to receive(:method_call_threshold). - and_return(0) + allow(Gitlab::Metrics).to receive(:method_call_threshold) + .and_return(0) - allow(described_class).to receive(:transaction). - and_return(transaction) + allow(described_class).to receive(:transaction) + .and_return(transaction) expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure) @@ -168,8 +168,8 @@ describe Gitlab::Metrics::Instrumentation do end it 'does not track method calls below a given duration threshold' do - allow(Gitlab::Metrics).to receive(:method_call_threshold). - and_return(100) + allow(Gitlab::Metrics).to receive(:method_call_threshold) + .and_return(100) expect(transaction).not_to receive(:add_metric) @@ -183,8 +183,8 @@ describe Gitlab::Metrics::Instrumentation do end it 'does not instrument the method' do - described_class. - instrument_instance_method(@dummy, :bar) + described_class + .instrument_instance_method(@dummy, :bar) expect(described_class.instrumented?(@dummy)).to eq(false) end diff --git a/spec/lib/gitlab/metrics/rack_middleware_spec.rb b/spec/lib/gitlab/metrics/rack_middleware_spec.rb index fb470ea7568..ec415f2bd85 100644 --- a/spec/lib/gitlab/metrics/rack_middleware_spec.rb +++ b/spec/lib/gitlab/metrics/rack_middleware_spec.rb @@ -26,8 +26,8 @@ describe Gitlab::Metrics::RackMiddleware do allow(app).to receive(:call).with(env) - expect(middleware).to receive(:tag_controller). - with(an_instance_of(Gitlab::Metrics::Transaction), env) + expect(middleware).to receive(:tag_controller) + .with(an_instance_of(Gitlab::Metrics::Transaction), env) middleware.call(env) end @@ -40,8 +40,8 @@ describe Gitlab::Metrics::RackMiddleware do allow(app).to receive(:call).with(env) - expect(middleware).to receive(:tag_endpoint). - with(an_instance_of(Gitlab::Metrics::Transaction), env) + expect(middleware).to receive(:tag_endpoint) + .with(an_instance_of(Gitlab::Metrics::Transaction), env) middleware.call(env) end @@ -49,8 +49,8 @@ describe Gitlab::Metrics::RackMiddleware do it 'tracks any raised exceptions' do expect(app).to receive(:call).with(env).and_raise(RuntimeError) - expect_any_instance_of(Gitlab::Metrics::Transaction). - to receive(:add_event).with(:rails_exception) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .to receive(:add_event).with(:rails_exception) expect { middleware.call(env) }.to raise_error(RuntimeError) end diff --git a/spec/lib/gitlab/metrics/sampler_spec.rb b/spec/lib/gitlab/metrics/sampler_spec.rb index 1ab923b58cf..d07ce6f81af 100644 --- a/spec/lib/gitlab/metrics/sampler_spec.rb +++ b/spec/lib/gitlab/metrics/sampler_spec.rb @@ -38,8 +38,8 @@ describe Gitlab::Metrics::Sampler do describe '#flush' do it 'schedules the metrics using Sidekiq' do - expect(Gitlab::Metrics).to receive(:submit_metrics). - with([an_instance_of(Hash)]) + expect(Gitlab::Metrics).to receive(:submit_metrics) + .with([an_instance_of(Hash)]) sampler.sample_memory_usage sampler.flush @@ -48,12 +48,12 @@ describe Gitlab::Metrics::Sampler do describe '#sample_memory_usage' do it 'adds a metric containing the memory usage' do - expect(Gitlab::Metrics::System).to receive(:memory_usage). - and_return(9000) + expect(Gitlab::Metrics::System).to receive(:memory_usage) + .and_return(9000) - expect(sampler).to receive(:add_metric). - with(/memory_usage/, value: 9000). - and_call_original + expect(sampler).to receive(:add_metric) + .with(/memory_usage/, value: 9000) + .and_call_original sampler.sample_memory_usage end @@ -61,12 +61,12 @@ describe Gitlab::Metrics::Sampler do describe '#sample_file_descriptors' do it 'adds a metric containing the amount of open file descriptors' do - expect(Gitlab::Metrics::System).to receive(:file_descriptor_count). - and_return(4) + expect(Gitlab::Metrics::System).to receive(:file_descriptor_count) + .and_return(4) - expect(sampler).to receive(:add_metric). - with(/file_descriptors/, value: 4). - and_call_original + expect(sampler).to receive(:add_metric) + .with(/file_descriptors/, value: 4) + .and_call_original sampler.sample_file_descriptors end @@ -75,10 +75,10 @@ describe Gitlab::Metrics::Sampler do if Gitlab::Metrics.mri? describe '#sample_objects' do it 'adds a metric containing the amount of allocated objects' do - expect(sampler).to receive(:add_metric). - with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)). - at_least(:once). - and_call_original + expect(sampler).to receive(:add_metric) + .with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)) + .at_least(:once) + .and_call_original sampler.sample_objects end @@ -86,8 +86,8 @@ describe Gitlab::Metrics::Sampler do it 'ignores classes without a name' do expect(Allocations).to receive(:to_hash).and_return({ Class.new => 4 }) - expect(sampler).not_to receive(:add_metric). - with('object_counts', an_instance_of(Hash), type: nil) + expect(sampler).not_to receive(:add_metric) + .with('object_counts', an_instance_of(Hash), type: nil) sampler.sample_objects end @@ -98,9 +98,9 @@ describe Gitlab::Metrics::Sampler do it 'adds a metric containing garbage collection statistics' do expect(GC::Profiler).to receive(:total_time).and_return(0.24) - expect(sampler).to receive(:add_metric). - with(/gc_statistics/, an_instance_of(Hash)). - and_call_original + expect(sampler).to receive(:add_metric) + .with(/gc_statistics/, an_instance_of(Hash)) + .and_call_original sampler.sample_gc end @@ -110,9 +110,9 @@ describe Gitlab::Metrics::Sampler do it 'prefixes the series name for a Rails process' do expect(sampler).to receive(:sidekiq?).and_return(false) - expect(Gitlab::Metrics::Metric).to receive(:new). - with('rails_cats', { value: 10 }, {}). - and_call_original + expect(Gitlab::Metrics::Metric).to receive(:new) + .with('rails_cats', { value: 10 }, {}) + .and_call_original sampler.add_metric('cats', value: 10) end @@ -120,9 +120,9 @@ describe Gitlab::Metrics::Sampler do it 'prefixes the series name for a Sidekiq process' do expect(sampler).to receive(:sidekiq?).and_return(true) - expect(Gitlab::Metrics::Metric).to receive(:new). - with('sidekiq_cats', { value: 10 }, {}). - and_call_original + expect(Gitlab::Metrics::Metric).to receive(:new) + .with('sidekiq_cats', { value: 10 }, {}) + .and_call_original sampler.add_metric('cats', value: 10) end diff --git a/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb b/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb index acaba785606..b576d7173f5 100644 --- a/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb +++ b/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb @@ -8,12 +8,12 @@ describe Gitlab::Metrics::SidekiqMiddleware do it 'tracks the transaction' do worker = double(:worker, class: double(:class, name: 'TestWorker')) - expect(Gitlab::Metrics::Transaction).to receive(:new). - with('TestWorker#perform'). - and_call_original + expect(Gitlab::Metrics::Transaction).to receive(:new) + .with('TestWorker#perform') + .and_call_original - expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set). - with(:sidekiq_queue_duration, instance_of(Float)) + expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set) + .with(:sidekiq_queue_duration, instance_of(Float)) expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:finish) @@ -23,12 +23,12 @@ describe Gitlab::Metrics::SidekiqMiddleware do it 'tracks the transaction (for messages without `enqueued_at`)' do worker = double(:worker, class: double(:class, name: 'TestWorker')) - expect(Gitlab::Metrics::Transaction).to receive(:new). - with('TestWorker#perform'). - and_call_original + expect(Gitlab::Metrics::Transaction).to receive(:new) + .with('TestWorker#perform') + .and_call_original - expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set). - with(:sidekiq_queue_duration, instance_of(Float)) + expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set) + .with(:sidekiq_queue_duration, instance_of(Float)) expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:finish) @@ -38,17 +38,17 @@ describe Gitlab::Metrics::SidekiqMiddleware do it 'tracks any raised exceptions' do worker = double(:worker, class: double(:class, name: 'TestWorker')) - expect_any_instance_of(Gitlab::Metrics::Transaction). - to receive(:run).and_raise(RuntimeError) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .to receive(:run).and_raise(RuntimeError) - expect_any_instance_of(Gitlab::Metrics::Transaction). - to receive(:add_event).with(:sidekiq_exception) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .to receive(:add_event).with(:sidekiq_exception) - expect_any_instance_of(Gitlab::Metrics::Transaction). - to receive(:finish) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .to receive(:finish) - expect { middleware.call(worker, message, :test) }. - to raise_error(RuntimeError) + expect { middleware.call(worker, message, :test) } + .to raise_error(RuntimeError) end end end diff --git a/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb b/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb index 0695c5ce096..e7b595405a8 100644 --- a/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb @@ -21,11 +21,11 @@ describe Gitlab::Metrics::Subscribers::ActionView do values = { duration: 2.1 } tags = { view: 'app/views/x.html.haml' } - expect(transaction).to receive(:increment). - with(:view_duration, 2.1) + expect(transaction).to receive(:increment) + .with(:view_duration, 2.1) - expect(transaction).to receive(:add_metric). - with(described_class::SERIES, values, tags) + expect(transaction).to receive(:add_metric) + .with(described_class::SERIES, values, tags) subscriber.render_template(event) end diff --git a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb index 49699ffe28f..ce6587e993f 100644 --- a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb @@ -12,8 +12,8 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do describe '#sql' do describe 'without a current transaction' do it 'simply returns' do - expect_any_instance_of(Gitlab::Metrics::Transaction). - not_to receive(:increment) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .not_to receive(:increment) subscriber.sql(event) end @@ -21,15 +21,15 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do describe 'with a current transaction' do it 'increments the :sql_duration value' do - expect(subscriber).to receive(:current_transaction). - at_least(:once). - and_return(transaction) + expect(subscriber).to receive(:current_transaction) + .at_least(:once) + .and_return(transaction) - expect(transaction).to receive(:increment). - with(:sql_duration, 0.2) + expect(transaction).to receive(:increment) + .with(:sql_duration, 0.2) - expect(transaction).to receive(:increment). - with(:sql_count, 1) + expect(transaction).to receive(:increment) + .with(:sql_count, 1) subscriber.sql(event) end diff --git a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb index d986c6fac43..f04dc8dcc02 100644 --- a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb @@ -8,26 +8,26 @@ describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_read' do it 'increments the cache_read duration' do - expect(subscriber).to receive(:increment). - with(:cache_read, event.duration) + expect(subscriber).to receive(:increment) + .with(:cache_read, event.duration) subscriber.cache_read(event) end context 'with a transaction' do before do - allow(subscriber).to receive(:current_transaction). - and_return(transaction) + allow(subscriber).to receive(:current_transaction) + .and_return(transaction) end context 'with hit event' do let(:event) { double(:event, duration: 15.2, payload: { hit: true }) } it 'increments the cache_read_hit count' do - expect(transaction).to receive(:increment). - with(:cache_read_hit_count, 1) - expect(transaction).to receive(:increment). - with(any_args).at_least(1) # Other calls + expect(transaction).to receive(:increment) + .with(:cache_read_hit_count, 1) + expect(transaction).to receive(:increment) + .with(any_args).at_least(1) # Other calls subscriber.cache_read(event) end @@ -36,8 +36,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do let(:event) { double(:event, duration: 15.2, payload: { hit: true, super_operation: :fetch }) } it 'does not increment cache read miss' do - expect(transaction).not_to receive(:increment). - with(:cache_read_hit_count, 1) + expect(transaction).not_to receive(:increment) + .with(:cache_read_hit_count, 1) subscriber.cache_read(event) end @@ -48,10 +48,10 @@ describe Gitlab::Metrics::Subscribers::RailsCache do let(:event) { double(:event, duration: 15.2, payload: { hit: false }) } it 'increments the cache_read_miss count' do - expect(transaction).to receive(:increment). - with(:cache_read_miss_count, 1) - expect(transaction).to receive(:increment). - with(any_args).at_least(1) # Other calls + expect(transaction).to receive(:increment) + .with(:cache_read_miss_count, 1) + expect(transaction).to receive(:increment) + .with(any_args).at_least(1) # Other calls subscriber.cache_read(event) end @@ -60,8 +60,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do let(:event) { double(:event, duration: 15.2, payload: { hit: false, super_operation: :fetch }) } it 'does not increment cache read miss' do - expect(transaction).not_to receive(:increment). - with(:cache_read_miss_count, 1) + expect(transaction).not_to receive(:increment) + .with(:cache_read_miss_count, 1) subscriber.cache_read(event) end @@ -72,8 +72,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_write' do it 'increments the cache_write duration' do - expect(subscriber).to receive(:increment). - with(:cache_write, event.duration) + expect(subscriber).to receive(:increment) + .with(:cache_write, event.duration) subscriber.cache_write(event) end @@ -81,8 +81,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_delete' do it 'increments the cache_delete duration' do - expect(subscriber).to receive(:increment). - with(:cache_delete, event.duration) + expect(subscriber).to receive(:increment) + .with(:cache_delete, event.duration) subscriber.cache_delete(event) end @@ -90,8 +90,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_exist?' do it 'increments the cache_exists duration' do - expect(subscriber).to receive(:increment). - with(:cache_exists, event.duration) + expect(subscriber).to receive(:increment) + .with(:cache_exists, event.duration) subscriber.cache_exist?(event) end @@ -108,13 +108,13 @@ describe Gitlab::Metrics::Subscribers::RailsCache do context 'with a transaction' do before do - allow(subscriber).to receive(:current_transaction). - and_return(transaction) + allow(subscriber).to receive(:current_transaction) + .and_return(transaction) end it 'increments the cache_read_hit count' do - expect(transaction).to receive(:increment). - with(:cache_read_hit_count, 1) + expect(transaction).to receive(:increment) + .with(:cache_read_hit_count, 1) subscriber.cache_fetch_hit(event) end @@ -132,13 +132,13 @@ describe Gitlab::Metrics::Subscribers::RailsCache do context 'with a transaction' do before do - allow(subscriber).to receive(:current_transaction). - and_return(transaction) + allow(subscriber).to receive(:current_transaction) + .and_return(transaction) end it 'increments the cache_fetch_miss count' do - expect(transaction).to receive(:increment). - with(:cache_read_miss_count, 1) + expect(transaction).to receive(:increment) + .with(:cache_read_miss_count, 1) subscriber.cache_generate(event) end @@ -156,22 +156,22 @@ describe Gitlab::Metrics::Subscribers::RailsCache do context 'with a transaction' do before do - allow(subscriber).to receive(:current_transaction). - and_return(transaction) + allow(subscriber).to receive(:current_transaction) + .and_return(transaction) end it 'increments the total and specific cache duration' do - expect(transaction).to receive(:increment). - with(:cache_duration, event.duration) + expect(transaction).to receive(:increment) + .with(:cache_duration, event.duration) - expect(transaction).to receive(:increment). - with(:cache_count, 1) + expect(transaction).to receive(:increment) + .with(:cache_count, 1) - expect(transaction).to receive(:increment). - with(:cache_delete_duration, event.duration) + expect(transaction).to receive(:increment) + .with(:cache_delete_duration, event.duration) - expect(transaction).to receive(:increment). - with(:cache_delete_count, 1) + expect(transaction).to receive(:increment) + .with(:cache_delete_count, 1) subscriber.increment(:cache_delete, event.duration) end diff --git a/spec/lib/gitlab/metrics/transaction_spec.rb b/spec/lib/gitlab/metrics/transaction_spec.rb index 0c5a6246d85..3779af81512 100644 --- a/spec/lib/gitlab/metrics/transaction_spec.rb +++ b/spec/lib/gitlab/metrics/transaction_spec.rb @@ -39,8 +39,8 @@ describe Gitlab::Metrics::Transaction do describe '#add_metric' do it 'adds a metric to the transaction' do - expect(Gitlab::Metrics::Metric).to receive(:new). - with('rails_foo', { number: 10 }, {}) + expect(Gitlab::Metrics::Metric).to receive(:new) + .with('rails_foo', { number: 10 }, {}) transaction.add_metric('foo', number: 10) end @@ -61,8 +61,8 @@ describe Gitlab::Metrics::Transaction do values = { duration: 0.0, time: 3, allocated_memory: a_kind_of(Numeric) } - expect(transaction).to receive(:add_metric). - with('transactions', values, {}) + expect(transaction).to receive(:add_metric) + .with('transactions', values, {}) transaction.track_self end @@ -78,8 +78,8 @@ describe Gitlab::Metrics::Transaction do allocated_memory: a_kind_of(Numeric) } - expect(transaction).to receive(:add_metric). - with('transactions', values, {}) + expect(transaction).to receive(:add_metric) + .with('transactions', values, {}) transaction.track_self end @@ -109,8 +109,8 @@ describe Gitlab::Metrics::Transaction do allocated_memory: a_kind_of(Numeric) } - expect(transaction).to receive(:add_metric). - with('transactions', values, {}) + expect(transaction).to receive(:add_metric) + .with('transactions', values, {}) transaction.track_self end @@ -120,8 +120,8 @@ describe Gitlab::Metrics::Transaction do it 'submits the metrics to Sidekiq' do transaction.track_self - expect(Gitlab::Metrics).to receive(:submit_metrics). - with([an_instance_of(Hash)]) + expect(Gitlab::Metrics).to receive(:submit_metrics) + .with([an_instance_of(Hash)]) transaction.submit end @@ -137,8 +137,8 @@ describe Gitlab::Metrics::Transaction do timestamp: a_kind_of(Integer) } - expect(Gitlab::Metrics).to receive(:submit_metrics). - with([hash]) + expect(Gitlab::Metrics).to receive(:submit_metrics) + .with([hash]) transaction.submit end @@ -154,8 +154,8 @@ describe Gitlab::Metrics::Transaction do timestamp: a_kind_of(Integer) } - expect(Gitlab::Metrics).to receive(:submit_metrics). - with([hash]) + expect(Gitlab::Metrics).to receive(:submit_metrics) + .with([hash]) transaction.submit end diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 58a84cd3fe1..599b8807d8d 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -72,8 +72,8 @@ describe Gitlab::Metrics do describe '.prepare_metrics' do it 'returns a Hash with the keys as Symbols' do - metrics = described_class. - prepare_metrics([{ 'values' => {}, 'tags' => {} }]) + metrics = described_class + .prepare_metrics([{ 'values' => {}, 'tags' => {} }]) expect(metrics).to eq([{ values: {}, tags: {} }]) end @@ -118,19 +118,19 @@ describe Gitlab::Metrics do let(:transaction) { Gitlab::Metrics::Transaction.new } before do - allow(described_class).to receive(:current_transaction). - and_return(transaction) + allow(described_class).to receive(:current_transaction) + .and_return(transaction) end it 'adds a metric to the current transaction' do - expect(transaction).to receive(:increment). - with('foo_real_time', a_kind_of(Numeric)) + expect(transaction).to receive(:increment) + .with('foo_real_time', a_kind_of(Numeric)) - expect(transaction).to receive(:increment). - with('foo_cpu_time', a_kind_of(Numeric)) + expect(transaction).to receive(:increment) + .with('foo_cpu_time', a_kind_of(Numeric)) - expect(transaction).to receive(:increment). - with('foo_call_count', 1) + expect(transaction).to receive(:increment) + .with('foo_call_count', 1) described_class.measure(:foo) { 10 } end @@ -146,8 +146,8 @@ describe Gitlab::Metrics do describe '.tag_transaction' do context 'without a transaction' do it 'does nothing' do - expect_any_instance_of(Gitlab::Metrics::Transaction). - not_to receive(:add_tag) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .not_to receive(:add_tag) described_class.tag_transaction(:foo, 'bar') end @@ -157,11 +157,11 @@ describe Gitlab::Metrics do let(:transaction) { Gitlab::Metrics::Transaction.new } it 'adds the tag to the transaction' do - expect(described_class).to receive(:current_transaction). - and_return(transaction) + expect(described_class).to receive(:current_transaction) + .and_return(transaction) - expect(transaction).to receive(:add_tag). - with(:foo, 'bar') + expect(transaction).to receive(:add_tag) + .with(:foo, 'bar') described_class.tag_transaction(:foo, 'bar') end @@ -171,8 +171,8 @@ describe Gitlab::Metrics do describe '.action=' do context 'without a transaction' do it 'does nothing' do - expect_any_instance_of(Gitlab::Metrics::Transaction). - not_to receive(:action=) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .not_to receive(:action=) described_class.action = 'foo' end @@ -182,8 +182,8 @@ describe Gitlab::Metrics do it 'sets the action of a transaction' do trans = Gitlab::Metrics::Transaction.new - expect(described_class).to receive(:current_transaction). - and_return(trans) + expect(described_class).to receive(:current_transaction) + .and_return(trans) expect(trans).to receive(:action=).with('foo') @@ -201,8 +201,8 @@ describe Gitlab::Metrics do describe '.add_event' do context 'without a transaction' do it 'does nothing' do - expect_any_instance_of(Gitlab::Metrics::Transaction). - not_to receive(:add_event) + expect_any_instance_of(Gitlab::Metrics::Transaction) + .not_to receive(:add_event) described_class.add_event(:meow) end @@ -214,8 +214,8 @@ describe Gitlab::Metrics do expect(transaction).to receive(:add_event).with(:meow) - expect(described_class).to receive(:current_transaction). - and_return(transaction) + expect(described_class).to receive(:current_transaction) + .and_return(transaction) described_class.add_event(:meow) end diff --git a/spec/lib/gitlab/project_authorizations_spec.rb b/spec/lib/gitlab/project_authorizations_spec.rb index 67321f43710..9ce33685697 100644 --- a/spec/lib/gitlab/project_authorizations_spec.rb +++ b/spec/lib/gitlab/project_authorizations_spec.rb @@ -34,8 +34,8 @@ describe Gitlab::ProjectAuthorizations do end it 'includes the correct projects' do - expect(authorizations.pluck(:project_id)). - to include(owned_project.id, other_project.id, group_project.id) + expect(authorizations.pluck(:project_id)) + .to include(owned_project.id, other_project.id, group_project.id) end it 'includes the correct access levels' do diff --git a/spec/lib/gitlab/route_map_spec.rb b/spec/lib/gitlab/route_map_spec.rb index 2370f56a613..21c00c6e5b8 100644 --- a/spec/lib/gitlab/route_map_spec.rb +++ b/spec/lib/gitlab/route_map_spec.rb @@ -4,43 +4,43 @@ describe Gitlab::RouteMap, lib: true do describe '#initialize' do context 'when the data is not YAML' do it 'raises an error' do - expect { described_class.new('"') }. - to raise_error(Gitlab::RouteMap::FormatError, /valid YAML/) + expect { described_class.new('"') } + .to raise_error(Gitlab::RouteMap::FormatError, /valid YAML/) end end context 'when the data is not a YAML array' do it 'raises an error' do - expect { described_class.new(YAML.dump('foo')) }. - to raise_error(Gitlab::RouteMap::FormatError, /an array/) + expect { described_class.new(YAML.dump('foo')) } + .to raise_error(Gitlab::RouteMap::FormatError, /an array/) end end context 'when an entry is not a hash' do it 'raises an error' do - expect { described_class.new(YAML.dump(['foo'])) }. - to raise_error(Gitlab::RouteMap::FormatError, /a hash/) + expect { described_class.new(YAML.dump(['foo'])) } + .to raise_error(Gitlab::RouteMap::FormatError, /a hash/) end end context 'when an entry does not have a source key' do it 'raises an error' do - expect { described_class.new(YAML.dump([{ 'public' => 'index.html' }])) }. - to raise_error(Gitlab::RouteMap::FormatError, /source key/) + expect { described_class.new(YAML.dump([{ 'public' => 'index.html' }])) } + .to raise_error(Gitlab::RouteMap::FormatError, /source key/) end end context 'when an entry does not have a public key' do it 'raises an error' do - expect { described_class.new(YAML.dump([{ 'source' => '/index\.html/' }])) }. - to raise_error(Gitlab::RouteMap::FormatError, /public key/) + expect { described_class.new(YAML.dump([{ 'source' => '/index\.html/' }])) } + .to raise_error(Gitlab::RouteMap::FormatError, /public key/) end end context 'when an entry source is not a valid regex' do it 'raises an error' do - expect { described_class.new(YAML.dump([{ 'source' => '/[/', 'public' => 'index.html' }])) }. - to raise_error(Gitlab::RouteMap::FormatError, /regular expression/) + expect { described_class.new(YAML.dump([{ 'source' => '/[/', 'public' => 'index.html' }])) } + .to raise_error(Gitlab::RouteMap::FormatError, /regular expression/) end end diff --git a/spec/lib/gitlab/sherlock/file_sample_spec.rb b/spec/lib/gitlab/sherlock/file_sample_spec.rb index cadf8bbce78..4989d14def3 100644 --- a/spec/lib/gitlab/sherlock/file_sample_spec.rb +++ b/spec/lib/gitlab/sherlock/file_sample_spec.rb @@ -35,8 +35,8 @@ describe Gitlab::Sherlock::FileSample, lib: true do describe '#relative_path' do it 'returns the relative path' do - expect(sample.relative_path). - to eq('spec/lib/gitlab/sherlock/file_sample_spec.rb') + expect(sample.relative_path) + .to eq('spec/lib/gitlab/sherlock/file_sample_spec.rb') end end diff --git a/spec/lib/gitlab/sherlock/line_profiler_spec.rb b/spec/lib/gitlab/sherlock/line_profiler_spec.rb index d57627bba2b..39c6b2a4844 100644 --- a/spec/lib/gitlab/sherlock/line_profiler_spec.rb +++ b/spec/lib/gitlab/sherlock/line_profiler_spec.rb @@ -20,9 +20,9 @@ describe Gitlab::Sherlock::LineProfiler, lib: true do describe '#profile_mri' do it 'returns an Array containing the return value and profiling samples' do - allow(profiler).to receive(:lineprof). - and_yield. - and_return({ __FILE__ => [[0, 0, 0, 0]] }) + allow(profiler).to receive(:lineprof) + .and_yield + .and_return({ __FILE__ => [[0, 0, 0, 0]] }) retval, samples = profiler.profile_mri { 42 } diff --git a/spec/lib/gitlab/sherlock/middleware_spec.rb b/spec/lib/gitlab/sherlock/middleware_spec.rb index 2bbeb25ce98..b98ab0b14a2 100644 --- a/spec/lib/gitlab/sherlock/middleware_spec.rb +++ b/spec/lib/gitlab/sherlock/middleware_spec.rb @@ -72,8 +72,8 @@ describe Gitlab::Sherlock::Middleware, lib: true do 'REQUEST_URI' => '/cats' } - expect(middleware.transaction_from_env(env)). - to be_an_instance_of(Gitlab::Sherlock::Transaction) + expect(middleware.transaction_from_env(env)) + .to be_an_instance_of(Gitlab::Sherlock::Transaction) end end end diff --git a/spec/lib/gitlab/sherlock/query_spec.rb b/spec/lib/gitlab/sherlock/query_spec.rb index 0a620428138..d97b5eef573 100644 --- a/spec/lib/gitlab/sherlock/query_spec.rb +++ b/spec/lib/gitlab/sherlock/query_spec.rb @@ -13,8 +13,8 @@ describe Gitlab::Sherlock::Query, lib: true do sql = 'SELECT COUNT(*) FROM users WHERE id = $1' bindings = [[double(:column), 10]] - query = described_class. - new_with_bindings(sql, bindings, started_at, finished_at) + query = described_class + .new_with_bindings(sql, bindings, started_at, finished_at) expect(query.query).to eq('SELECT COUNT(*) FROM users WHERE id = 10;') end diff --git a/spec/lib/gitlab/sherlock/transaction_spec.rb b/spec/lib/gitlab/sherlock/transaction_spec.rb index 9fe18f253f0..6ae1aa20ea7 100644 --- a/spec/lib/gitlab/sherlock/transaction_spec.rb +++ b/spec/lib/gitlab/sherlock/transaction_spec.rb @@ -109,8 +109,8 @@ describe Gitlab::Sherlock::Transaction, lib: true do query1 = Gitlab::Sherlock::Query.new('SELECT 1', start_time, start_time) - query2 = Gitlab::Sherlock::Query. - new('SELECT 2', start_time, start_time + 5) + query2 = Gitlab::Sherlock::Query + .new('SELECT 2', start_time, start_time + 5) transaction.queries << query1 transaction.queries << query2 @@ -162,11 +162,11 @@ describe Gitlab::Sherlock::Transaction, lib: true do describe '#profile_lines' do describe 'when line profiling is enabled' do it 'yields the block using the line profiler' do - allow(Gitlab::Sherlock).to receive(:enable_line_profiler?). - and_return(true) + allow(Gitlab::Sherlock).to receive(:enable_line_profiler?) + .and_return(true) - allow_any_instance_of(Gitlab::Sherlock::LineProfiler). - to receive(:profile).and_return('cats are amazing', []) + allow_any_instance_of(Gitlab::Sherlock::LineProfiler) + .to receive(:profile).and_return('cats are amazing', []) retval = transaction.profile_lines { 'cats are amazing' } @@ -176,8 +176,8 @@ describe Gitlab::Sherlock::Transaction, lib: true do describe 'when line profiling is disabled' do it 'yields the block' do - allow(Gitlab::Sherlock).to receive(:enable_line_profiler?). - and_return(false) + allow(Gitlab::Sherlock).to receive(:enable_line_profiler?) + .and_return(false) retval = transaction.profile_lines { 'cats are amazing' } @@ -196,8 +196,8 @@ describe Gitlab::Sherlock::Transaction, lib: true do end it 'tracks executed queries' do - expect(transaction).to receive(:track_query). - with('SELECT 1', [], time, time) + expect(transaction).to receive(:track_query) + .with('SELECT 1', [], time, time) subscription.publish('test', time, time, nil, query_data) end @@ -205,8 +205,8 @@ describe Gitlab::Sherlock::Transaction, lib: true do it 'only tracks queries triggered from the transaction thread' do expect(transaction).not_to receive(:track_query) - Thread.new { subscription.publish('test', time, time, nil, query_data) }. - join + Thread.new { subscription.publish('test', time, time, nil, query_data) } + .join end end @@ -228,8 +228,8 @@ describe Gitlab::Sherlock::Transaction, lib: true do it 'only tracks views rendered from the transaction thread' do expect(transaction).not_to receive(:track_view) - Thread.new { subscription.publish('test', time, time, nil, view_data) }. - join + Thread.new { subscription.publish('test', time, time, nil, view_data) } + .join end end end diff --git a/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb b/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb index 6307f8c16a3..37d9e1d3e6b 100644 --- a/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb +++ b/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb @@ -5,8 +5,8 @@ describe Gitlab::SidekiqStatus::ClientMiddleware do it 'tracks the job in Redis' do expect(Gitlab::SidekiqStatus).to receive(:set).with('123', Gitlab::SidekiqStatus::DEFAULT_EXPIRATION) - described_class.new. - call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil } + described_class.new + .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil } end end end diff --git a/spec/lib/gitlab/sidekiq_status/server_middleware_spec.rb b/spec/lib/gitlab/sidekiq_status/server_middleware_spec.rb index 80728197b8c..04e09d3dec8 100644 --- a/spec/lib/gitlab/sidekiq_status/server_middleware_spec.rb +++ b/spec/lib/gitlab/sidekiq_status/server_middleware_spec.rb @@ -5,8 +5,8 @@ describe Gitlab::SidekiqStatus::ServerMiddleware do it 'stops tracking of a job upon completion' do expect(Gitlab::SidekiqStatus).to receive(:unset).with('123') - ret = described_class.new. - call(double(:worker), { 'jid' => '123' }, double(:queue)) { 10 } + ret = described_class.new + .call(double(:worker), { 'jid' => '123' }, double(:queue)) { 10 } expect(ret).to eq(10) end diff --git a/spec/lib/gitlab/url_builder_spec.rb b/spec/lib/gitlab/url_builder_spec.rb index e8a37e8d77b..e9a6e273516 100644 --- a/spec/lib/gitlab/url_builder_spec.rb +++ b/spec/lib/gitlab/url_builder_spec.rb @@ -112,8 +112,8 @@ describe Gitlab::UrlBuilder, lib: true do it 'returns a proper URL' do project = build_stubbed(:empty_project) - expect { described_class.build(project) }. - to raise_error(NotImplementedError, 'No URL builder defined for Project') + expect { described_class.build(project) } + .to raise_error(NotImplementedError, 'No URL builder defined for Project') end end end diff --git a/spec/lib/gitlab/view/presenter/delegated_spec.rb b/spec/lib/gitlab/view/presenter/delegated_spec.rb index e9d4af54389..940a2ce6ebd 100644 --- a/spec/lib/gitlab/view/presenter/delegated_spec.rb +++ b/spec/lib/gitlab/view/presenter/delegated_spec.rb @@ -18,8 +18,8 @@ describe Gitlab::View::Presenter::Delegated do end it 'raise an error if the presentee already respond to method' do - expect { presenter_class.new(project, user: 'Jane Doe') }. - to raise_error Gitlab::View::Presenter::CannotOverrideMethodError + expect { presenter_class.new(project, user: 'Jane Doe') } + .to raise_error Gitlab::View::Presenter::CannotOverrideMethodError end end diff --git a/spec/lib/gitlab/visibility_level_spec.rb b/spec/lib/gitlab/visibility_level_spec.rb index a8f21803ec7..84d2484cc8a 100644 --- a/spec/lib/gitlab/visibility_level_spec.rb +++ b/spec/lib/gitlab/visibility_level_spec.rb @@ -23,30 +23,30 @@ describe Gitlab::VisibilityLevel, lib: true do it 'returns all levels for an admin' do user = double(:user, admin?: true) - expect(described_class.levels_for_user(user)). - to eq([Gitlab::VisibilityLevel::PRIVATE, - Gitlab::VisibilityLevel::INTERNAL, - Gitlab::VisibilityLevel::PUBLIC]) + expect(described_class.levels_for_user(user)) + .to eq([Gitlab::VisibilityLevel::PRIVATE, + Gitlab::VisibilityLevel::INTERNAL, + Gitlab::VisibilityLevel::PUBLIC]) end it 'returns INTERNAL and PUBLIC for internal users' do user = double(:user, admin?: false, external?: false) - expect(described_class.levels_for_user(user)). - to eq([Gitlab::VisibilityLevel::INTERNAL, - Gitlab::VisibilityLevel::PUBLIC]) + expect(described_class.levels_for_user(user)) + .to eq([Gitlab::VisibilityLevel::INTERNAL, + Gitlab::VisibilityLevel::PUBLIC]) end it 'returns PUBLIC for external users' do user = double(:user, admin?: false, external?: true) - expect(described_class.levels_for_user(user)). - to eq([Gitlab::VisibilityLevel::PUBLIC]) + expect(described_class.levels_for_user(user)) + .to eq([Gitlab::VisibilityLevel::PUBLIC]) end it 'returns PUBLIC when no user is given' do - expect(described_class.levels_for_user). - to eq([Gitlab::VisibilityLevel::PUBLIC]) + expect(described_class.levels_for_user) + .to eq([Gitlab::VisibilityLevel::PUBLIC]) end end end diff --git a/spec/lib/mattermost/command_spec.rb b/spec/lib/mattermost/command_spec.rb index 4b5938edeb9..369e7b181b9 100644 --- a/spec/lib/mattermost/command_spec.rb +++ b/spec/lib/mattermost/command_spec.rb @@ -6,8 +6,8 @@ describe Mattermost::Command do before do Mattermost::Session.base_uri('http://mattermost.example.com') - allow_any_instance_of(Mattermost::Client).to receive(:with_session). - and_yield(Mattermost::Session.new(nil)) + allow_any_instance_of(Mattermost::Client).to receive(:with_session) + .and_yield(Mattermost::Session.new(nil)) end describe '#create' do @@ -20,12 +20,12 @@ describe Mattermost::Command do context 'for valid trigger word' do before do - stub_request(:post, 'http://mattermost.example.com/api/v3/teams/abc/commands/create'). - with(body: { + stub_request(:post, 'http://mattermost.example.com/api/v3/teams/abc/commands/create') + .with(body: { team_id: 'abc', trigger: 'gitlab' - }.to_json). - to_return( + }.to_json) + .to_return( status: 200, headers: { 'Content-Type' => 'application/json' }, body: { token: 'token' }.to_json @@ -39,8 +39,8 @@ describe Mattermost::Command do context 'for error message' do before do - stub_request(:post, 'http://mattermost.example.com/api/v3/teams/abc/commands/create'). - to_return( + stub_request(:post, 'http://mattermost.example.com/api/v3/teams/abc/commands/create') + .to_return( status: 500, headers: { 'Content-Type' => 'application/json' }, body: { diff --git a/spec/lib/mattermost/session_spec.rb b/spec/lib/mattermost/session_spec.rb index 74d12e37181..be3908e8f6a 100644 --- a/spec/lib/mattermost/session_spec.rb +++ b/spec/lib/mattermost/session_spec.rb @@ -21,8 +21,8 @@ describe Mattermost::Session, type: :request do describe '#with session' do let(:location) { 'http://location.tld' } let!(:stub) do - WebMock.stub_request(:get, "#{mattermost_url}/api/v3/oauth/gitlab/login"). - to_return(headers: { 'location' => location }, status: 307) + WebMock.stub_request(:get, "#{mattermost_url}/api/v3/oauth/gitlab/login") + .to_return(headers: { 'location' => location }, status: 307) end context 'without oauth uri' do @@ -60,9 +60,9 @@ describe Mattermost::Session, type: :request do end before do - WebMock.stub_request(:get, "#{mattermost_url}/signup/gitlab/complete"). - with(query: hash_including({ 'state' => state })). - to_return do |request| + WebMock.stub_request(:get, "#{mattermost_url}/signup/gitlab/complete") + .with(query: hash_including({ 'state' => state })) + .to_return do |request| post "/oauth/token", client_id: doorkeeper.uid, client_secret: doorkeeper.secret, @@ -75,8 +75,8 @@ describe Mattermost::Session, type: :request do end end - WebMock.stub_request(:post, "#{mattermost_url}/api/v3/users/logout"). - to_return(headers: { Authorization: 'token thisworksnow' }, status: 200) + WebMock.stub_request(:post, "#{mattermost_url}/api/v3/users/logout") + .to_return(headers: { Authorization: 'token thisworksnow' }, status: 200) end it 'can setup a session' do diff --git a/spec/lib/mattermost/team_spec.rb b/spec/lib/mattermost/team_spec.rb index ac493fdb20f..e638ad7a2c9 100644 --- a/spec/lib/mattermost/team_spec.rb +++ b/spec/lib/mattermost/team_spec.rb @@ -4,8 +4,8 @@ describe Mattermost::Team do before do Mattermost::Session.base_uri('http://mattermost.example.com') - allow_any_instance_of(Mattermost::Client).to receive(:with_session). - and_yield(Mattermost::Session.new(nil)) + allow_any_instance_of(Mattermost::Client).to receive(:with_session) + .and_yield(Mattermost::Session.new(nil)) end describe '#all' do @@ -30,8 +30,8 @@ describe Mattermost::Team do end before do - stub_request(:get, 'http://mattermost.example.com/api/v3/teams/all'). - to_return( + stub_request(:get, 'http://mattermost.example.com/api/v3/teams/all') + .to_return( status: 200, headers: { 'Content-Type' => 'application/json' }, body: response.to_json @@ -45,8 +45,8 @@ describe Mattermost::Team do context 'for error message' do before do - stub_request(:get, 'http://mattermost.example.com/api/v3/teams/all'). - to_return( + stub_request(:get, 'http://mattermost.example.com/api/v3/teams/all') + .to_return( status: 500, headers: { 'Content-Type' => 'application/json' }, body: { -- cgit v1.2.1 From 4419289bff21fbb84999f2faf8b6ad213551d561 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 21 Jun 2017 15:36:02 +0200 Subject: Fix migration specs that can not run within transaction --- .../database/rename_reserved_paths_migration/v1/rename_base_spec.rb | 2 +- .../database/rename_reserved_paths_migration/v1/rename_projects_spec.rb | 2 +- spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb index a3ab4e3dd9e..5653cfee686 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase do +describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :truncate do let(:migration) { FakeRenameReservedPathMigrationV1.new } let(:subject) { described_class.new(['the-path'], migration) } diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index 59e8de2712d..b04547f59fe 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects do +describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :truncate do let(:migration) { FakeRenameReservedPathMigrationV1.new } let(:subject) { described_class.new(['the-path'], migration) } diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb index f8cc1eb91ec..04a6592aac5 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb @@ -13,7 +13,7 @@ shared_examples 'renames child namespaces' do |type| end end -describe Gitlab::Database::RenameReservedPathsMigration::V1 do +describe Gitlab::Database::RenameReservedPathsMigration::V1, :truncate do let(:subject) { FakeRenameReservedPathMigrationV1.new } before do -- cgit v1.2.1 From 0284f01716cfdcbe8d9e7a0281e551414b4c0239 Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Mon, 12 Jun 2017 20:55:28 +0200 Subject: Migrate Gitlab::Git::Blob.find to Gitaly --- spec/lib/gitlab/git/blob_spec.rb | 12 +++++++++++- spec/lib/gitlab/workhorse_spec.rb | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index e6a07a58d73..610a08b3400 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::Git::Blob, seed_helper: true do end end - describe '.find' do + shared_examples 'finding blobs' do context 'file in subdir' do let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") } @@ -101,6 +101,16 @@ describe Gitlab::Git::Blob, seed_helper: true do end end + describe '.find' do + context 'when project_raw_show Gitaly feature is enabled' do + it_behaves_like 'finding blobs' + end + + context 'when project_raw_show Gitaly feature is disabled', skip_gitaly_mock: true do + it_behaves_like 'finding blobs' + end + end + describe '.raw' do let(:raw_blob) { Gitlab::Git::Blob.raw(repository, SeedRepo::RubyBlob::ID) } it { expect(raw_blob.id).to eq(SeedRepo::RubyBlob::ID) } diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index a3e8166cb70..493ff3bb5fb 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -216,7 +216,6 @@ describe Gitlab::Workhorse, lib: true do it 'includes a Repository param' do repo_param = { Repository: { - path: '', # deprecated field; grpc automatically creates it anyway storage_name: 'default', relative_path: project.full_path + '.git' } } -- cgit v1.2.1 From 5b092d21cca71dde8f032dfcb9b7b41612a8727f Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Thu, 22 Jun 2017 01:51:46 +0200 Subject: Encode Gitaly diff patches properly --- spec/lib/gitlab/git/diff_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb index 5627562abfb..d50ccb0df30 100644 --- a/spec/lib/gitlab/git/diff_spec.rb +++ b/spec/lib/gitlab/git/diff_spec.rb @@ -175,6 +175,14 @@ EOT expect(diff).to be_too_large end end + + context 'when the patch passed is not UTF-8-encoded' do + let(:raw_patch) { @raw_diff_hash[:diff].encode(Encoding::ASCII_8BIT) } + + it 'encodes diff patch to UTF-8' do + expect(diff.diff.encoding).to eq(Encoding::UTF_8) + end + end end end -- cgit v1.2.1 From 3447f97b448b0fa999351ed959b9d6a8656f9523 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Jun 2017 12:34:16 +0200 Subject: Fix specs for database migration helpers with transactions --- spec/lib/gitlab/database/migration_helpers_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 29656667b02..1efc19a2e65 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -317,7 +317,9 @@ describe Gitlab::Database::MigrationHelpers, lib: true do context 'outside of a transaction' do context 'when a column limit is not set' do before do - expect(model).to receive(:transaction_open?).and_return(false) + expect(model).to receive(:transaction_open?) + .and_return(false) + .at_least(:once) expect(model).to receive(:transaction).and_yield @@ -824,7 +826,11 @@ describe Gitlab::Database::MigrationHelpers, lib: true do let!(:user) { create(:user, name: 'Kathy Alice Aliceson') } it 'replaces the correct part of the string' do - model.update_column_in_batches(:users, :name, model.replace_sql(Arel::Table.new(:users)[:name], 'Alice', 'Eve')) + allow(model).to receive(:transaction_open?).and_return(false) + query = model.replace_sql(Arel::Table.new(:users)[:name], 'Alice', 'Eve') + + model.update_column_in_batches(:users, :name, query) + expect(user.reload.name).to eq('Kathy Eve Aliceson') end end -- cgit v1.2.1 From 3a3dd539208f75be9b2944c752ac3dc18a1b4306 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Jun 2017 12:35:47 +0200 Subject: Disable transaction in specs for some migrations --- .../rename_reserved_paths_migration/v1/rename_namespaces_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index ce2b5d620fd..0a6e6bbe2e8 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do +describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :truncate do let(:migration) { FakeRenameReservedPathMigrationV1.new } let(:subject) { described_class.new(['the-path'], migration) } -- cgit v1.2.1 From 019b4d34651d0638567ddd337c0cf74ba9ddeced Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Jun 2017 13:55:35 +0200 Subject: Fix Rubocop offense in migration helpers specs --- spec/lib/gitlab/database/migration_helpers_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index fc269f33be9..4259be3f522 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -827,7 +827,7 @@ describe Gitlab::Database::MigrationHelpers, lib: true do it 'replaces the correct part of the string' do allow(model).to receive(:transaction_open?).and_return(false) - query = model.replace_sql(Arel::Table.new(:users)[:name], 'Alice', 'Eve') + query = model.replace_sql(Arel::Table.new(:users)[:name], 'Alice', 'Eve') model.update_column_in_batches(:users, :name, query) -- cgit v1.2.1 From b90f1098cf42889c32eb6f12779def005f15cbae Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Thu, 22 Jun 2017 08:35:49 +0200 Subject: Add User#full_private_access? to check if user has Private access In CE only the admin has access to all private groups & projects. In EE also an auditor can have full private access. To overcome merge conflicts, or accidental incorrect access rights, abstract this out in `User#full_private_access?`. `User#admin?` now only should be used for admin-only features. For private access-related features `User#full_private_access?` should be used. Backported from gitlab-org/gitlab-ee!2199 --- spec/lib/gitlab/visibility_level_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/visibility_level_spec.rb b/spec/lib/gitlab/visibility_level_spec.rb index 84d2484cc8a..db9d2807be6 100644 --- a/spec/lib/gitlab/visibility_level_spec.rb +++ b/spec/lib/gitlab/visibility_level_spec.rb @@ -21,7 +21,7 @@ describe Gitlab::VisibilityLevel, lib: true do describe '.levels_for_user' do it 'returns all levels for an admin' do - user = double(:user, admin?: true) + user = build(:user, :admin) expect(described_class.levels_for_user(user)) .to eq([Gitlab::VisibilityLevel::PRIVATE, @@ -30,7 +30,7 @@ describe Gitlab::VisibilityLevel, lib: true do end it 'returns INTERNAL and PUBLIC for internal users' do - user = double(:user, admin?: false, external?: false) + user = build(:user) expect(described_class.levels_for_user(user)) .to eq([Gitlab::VisibilityLevel::INTERNAL, @@ -38,7 +38,7 @@ describe Gitlab::VisibilityLevel, lib: true do end it 'returns PUBLIC for external users' do - user = double(:user, admin?: false, external?: true) + user = build(:user, :external) expect(described_class.levels_for_user(user)) .to eq([Gitlab::VisibilityLevel::PUBLIC]) -- cgit v1.2.1 From 9b2ae90d2cac9184f9c66051e8040559771dac98 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 23 Jun 2017 12:18:52 +0200 Subject: Remove references to build in pipeline charts Being the good boyscouts, but mainly because of [the comment in the review](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12378#note_33302115) the words used for classes and variables are changed to not use builds anymore. --- spec/lib/ci/charts_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/charts_spec.rb b/spec/lib/ci/charts_spec.rb index fb6cc398307..51cbfd2a848 100644 --- a/spec/lib/ci/charts_spec.rb +++ b/spec/lib/ci/charts_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' describe Ci::Charts, lib: true do - context "build_times" do + context "pipeline_times" do let(:project) { create(:empty_project) } - let(:chart) { Ci::Charts::BuildTime.new(project) } + let(:chart) { Ci::Charts::PipelineTime.new(project) } - subject { chart.build_times } + subject { chart.pipeline_times } before do create(:ci_empty_pipeline, project: project, duration: 120) end - it 'returns build times in minutes' do + it 'returns pipeline times in minutes' do is_expected.to contain_exactly(2) end - it 'handles nil build times' do + it 'handles nil pipeline times' do create(:ci_empty_pipeline, project: project, duration: nil) is_expected.to contain_exactly(2, 0) -- cgit v1.2.1 From 11e22835ed7a003c7b31856d1dbad9b8fa22d37f Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 23 Jun 2017 13:07:29 -0500 Subject: Don't match tilde and exclamation mark as part of requirements.txt package name --- spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb b/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb index 4da8821726c..7e32770f95d 100644 --- a/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb +++ b/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb @@ -54,6 +54,8 @@ describe Gitlab::DependencyLinker::RequirementsTxtLinker, lib: true do Sphinx>=1.3 docutils>=0.7 markupsafe + pytest~=3.0 + foop!=3.0 CONTENT end @@ -78,6 +80,8 @@ describe Gitlab::DependencyLinker::RequirementsTxtLinker, lib: true do expect(subject).to include(link('Sphinx', 'https://pypi.python.org/pypi/Sphinx')) expect(subject).to include(link('docutils', 'https://pypi.python.org/pypi/docutils')) expect(subject).to include(link('markupsafe', 'https://pypi.python.org/pypi/markupsafe')) + expect(subject).to include(link('pytest', 'https://pypi.python.org/pypi/pytest')) + expect(subject).to include(link('foop', 'https://pypi.python.org/pypi/foop')) end it 'links URLs' do -- cgit v1.2.1 From 43c3fa4455c5a4d943b0ef9db68b111f52a1177a Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 23 Jun 2017 07:36:19 +0200 Subject: Introduce #renew for ExclusiveLease --- spec/lib/gitlab/exclusive_lease_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/exclusive_lease_spec.rb b/spec/lib/gitlab/exclusive_lease_spec.rb index a366d68a146..81bbd70ffb8 100644 --- a/spec/lib/gitlab/exclusive_lease_spec.rb +++ b/spec/lib/gitlab/exclusive_lease_spec.rb @@ -19,6 +19,19 @@ describe Gitlab::ExclusiveLease, type: :redis do end end + describe '#renew' do + it 'returns true when we have the existing lease' do + lease = described_class.new(unique_key, timeout: 3600) + expect(lease.try_obtain).to be_present + expect(lease.renew).to be_truthy + end + + it 'returns false when we dont have a lease' do + lease = described_class.new(unique_key, timeout: 3600) + expect(lease.renew).to be_falsey + end + end + describe '#exists?' do it 'returns true for an existing lease' do lease = described_class.new(unique_key, timeout: 3600) -- cgit v1.2.1 From 0eb3d18c569cbae0f4b58284857c7a21972c4153 Mon Sep 17 00:00:00 2001 From: Adam Niedzielski Date: Mon, 26 Jun 2017 17:36:09 +0200 Subject: Store merge request ref_fetched status in the database Closes #34052 --- spec/lib/gitlab/import_export/fork_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/import_export/fork_spec.rb b/spec/lib/gitlab/import_export/fork_spec.rb index 42f3fc59f04..70796781532 100644 --- a/spec/lib/gitlab/import_export/fork_spec.rb +++ b/spec/lib/gitlab/import_export/fork_spec.rb @@ -44,6 +44,8 @@ describe 'forked project import', services: true do end it 'can access the MR' do - expect(project.merge_requests.first.ensure_ref_fetched.first).to include('refs/merge-requests/1/head') + project.merge_requests.first.ensure_ref_fetched + + expect(project.repository.ref_exists?('refs/merge-requests/1/head')).to be_truthy end end -- cgit v1.2.1 From 3e84b6336f3d61ff56e3e8ef5cc5d8ca08ef0432 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 6 Jun 2017 12:28:28 +0200 Subject: Track all renames in redis --- .../v1/rename_base_spec.rb | 17 +++++++++++++++++ .../v1/rename_namespaces_spec.rb | 7 +++++++ .../v1/rename_projects_spec.rb | 7 +++++++ 3 files changed, 31 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb index 5653cfee686..fa3c86bbb4f 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb @@ -203,4 +203,21 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca expect(File.exist?(expected_file)).to be(true) end end + + describe '#track_rename', redis: true do + it 'tracks a rename in redis' do + key = 'rename:20170316163845:namespace' + + subject.track_rename('namespace', 'path/to/namespace', 'path/to/renamed') + + old_path, new_path = [nil, nil] + Gitlab::Redis.with do |redis| + rename_info = redis.lpop(key) + old_path, new_path = JSON.parse(rename_info) + end + + expect(old_path).to eq('path/to/namespace') + expect(new_path).to eq('path/to/renamed') + end + end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index 8125dedd3fc..142ebfaf232 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -191,6 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : subject.rename_namespace(user.namespace) end + + it 'tracks the rename' do + expect(subject).to receive(:track_rename) + .with('namespace', 'the-path', 'the-path0') + + subject.rename_namespace(namespace) + end end describe '#rename_user' do diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index 802f77ad430..ed2f2241ab6 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -85,6 +85,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr subject.rename_project(project) end + + it 'tracks the rename' do + expect(subject).to receive(:track_rename) + .with('project', 'known-parent/the-path', 'known-parent/the-path0') + + subject.rename_project(project) + end end describe '#move_repository' do -- cgit v1.2.1 From 0faff42d7cc62dba50ca99ab1bc034c285311409 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 6 Jun 2017 17:24:32 +0200 Subject: Add methods to revert project renames --- .../v1/rename_base_spec.rb | 37 +++++++++++ .../v1/rename_projects_spec.rb | 76 +++++++++++++++++----- 2 files changed, 97 insertions(+), 16 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb index fa3c86bbb4f..4f6f06f0d07 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb @@ -153,6 +153,30 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca end end + describe '#perform_rename' do + describe 'for namespaces' do + let(:namespace) { create(:namespace, path: 'the-path') } + it 'renames the path' do + subject.perform_rename(migration_namespace(namespace), 'the-path', 'renamed') + + expect(namespace.reload.path).to eq('renamed') + end + + it 'renames all the routes for the namespace' do + child = create(:group, path: 'child', parent: namespace) + project = create(:project, namespace: child, path: 'the-project') + other_one = create(:namespace, path: 'the-path-is-similar') + + subject.perform_rename(migration_namespace(namespace), 'the-path', 'renamed') + + expect(namespace.reload.route.path).to eq('renamed') + expect(child.reload.route.path).to eq('renamed/child') + expect(project.reload.route.path).to eq('renamed/child/the-project') + expect(other_one.reload.route.path).to eq('the-path-is-similar') + end + end + end + describe '#move_pages' do it 'moves the pages directory' do expect(subject).to receive(:move_folders) @@ -220,4 +244,17 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca expect(new_path).to eq('path/to/renamed') end end + + describe '#reverts_for_type', redis: true do + it 'yields for each tracked rename' do + subject.track_rename('project', 'old_path', 'new_path') + subject.track_rename('project', 'old_path2', 'new_path2') + subject.track_rename('namespace', 'namespace_path', 'new_namespace_path') + + expect { |b| subject.reverts_for_type('project', &b) } + .to yield_successive_args(%w(old_path2 new_path2), %w(old_path new_path)) + expect { |b| subject.reverts_for_type('namespace', &b) } + .to yield_with_args('namespace_path', 'new_namespace_path') + end + end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index ed2f2241ab6..f87f4371353 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -3,6 +3,12 @@ require 'spec_helper' describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :truncate do let(:migration) { FakeRenameReservedPathMigrationV1.new } let(:subject) { described_class.new(['the-path'], migration) } + let(:project) do + create(:empty_project, + path: 'the-path', + namespace: create(:namespace, path: 'known-parent' )) + end + before do allow(migration).to receive(:say) @@ -47,12 +53,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr end describe '#rename_project' do - let(:project) do - create(:empty_project, - path: 'the-path', - namespace: create(:namespace, path: 'known-parent' )) - end - it 'renames path & route for the project' do expect(subject).to receive(:rename_path_for_routable) .with(project) @@ -63,34 +63,42 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr expect(project.reload.path).to eq('the-path0') end + it 'tracks the rename' do + expect(subject).to receive(:track_rename) + .with('project', 'known-parent/the-path', 'known-parent/the-path0') + + subject.rename_project(project) + end + + it 'renames the folders for the project' do + expect(subject).to receive(:move_project_folders).with(project, 'known-parent/the-path', 'known-parent/the-path0') + + subject.rename_project(project) + end + end + + describe '#move_project_folders' do it 'moves the wiki & the repo' do expect(subject).to receive(:move_repository) .with(project, 'known-parent/the-path.wiki', 'known-parent/the-path0.wiki') expect(subject).to receive(:move_repository) .with(project, 'known-parent/the-path', 'known-parent/the-path0') - subject.rename_project(project) + subject.move_project_folders(project, 'known-parent/the-path', 'known-parent/the-path0') end it 'moves uploads' do expect(subject).to receive(:move_uploads) .with('known-parent/the-path', 'known-parent/the-path0') - subject.rename_project(project) + subject.move_project_folders(project, 'known-parent/the-path', 'known-parent/the-path0') end it 'moves pages' do expect(subject).to receive(:move_pages) .with('known-parent/the-path', 'known-parent/the-path0') - subject.rename_project(project) - end - - it 'tracks the rename' do - expect(subject).to receive(:track_rename) - .with('project', 'known-parent/the-path', 'known-parent/the-path0') - - subject.rename_project(project) + subject.move_project_folders(project, 'known-parent/the-path', 'known-parent/the-path0') end end @@ -106,4 +114,40 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr expect(File.directory?(expected_path)).to be(true) end end + + describe '#revert_renames', redis: true do + it 'renames the routes back to the previous values' do + subject.rename_project(project) + + expect(subject).to receive(:perform_rename) + .with( + kind_of(Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Project), + 'known-parent/the-path0', + 'known-parent/the-path' + ).and_call_original + + subject.revert_renames + + expect(project.reload.path).to eq('the-path') + expect(project.route.path).to eq('known-parent/the-path') + end + + it 'moves the repositories back to their original place' do + project.create_repository + subject.rename_project(project) + + expected_path = File.join(TestEnv.repos_path, 'known-parent', 'the-path.git') + + expect(subject).to receive(:move_project_folders) + .with( + kind_of(Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Project), + 'known-parent/the-path0', + 'known-parent/the-path' + ).and_call_original + + subject.revert_renames + + expect(File.directory?(expected_path)).to be_truthy + end + end end -- cgit v1.2.1 From 152cba56e4004de1b1c2accee77e40a019d8c667 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 6 Jun 2017 18:40:11 +0200 Subject: Revert namespace renames --- .../v1/rename_base_spec.rb | 1 + .../v1/rename_namespaces_spec.rb | 78 +++++++++++++++++----- .../v1/rename_projects_spec.rb | 2 +- 3 files changed, 65 insertions(+), 16 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb index 4f6f06f0d07..f4e19f09419 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb @@ -6,6 +6,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca before do allow(migration).to receive(:say) + TestEnv.clean_test_path end def migration_namespace(namespace) diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index 142ebfaf232..5fa3d809c7a 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -3,9 +3,11 @@ require 'spec_helper' describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :truncate do let(:migration) { FakeRenameReservedPathMigrationV1.new } let(:subject) { described_class.new(['the-path'], migration) } + let(:namespace) { create(:group, name: 'the-path') } before do allow(migration).to receive(:say) + TestEnv.clean_test_path end def migration_namespace(namespace) @@ -137,8 +139,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : end describe "#rename_namespace" do - let(:namespace) { create(:group, name: 'the-path') } - it 'renames paths & routes for the namespace' do expect(subject).to receive(:rename_path_for_routable) .with(namespace) @@ -149,11 +149,27 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : expect(namespace.reload.path).to eq('the-path0') end + it 'tracks the rename' do + expect(subject).to receive(:track_rename) + .with('namespace', 'the-path', 'the-path0') + + subject.rename_namespace(namespace) + end + + it 'renames things related to the namespace' do + expect(subject).to receive(:rename_namespace_dependencies) + .with(namespace, 'the-path', 'the-path0') + + subject.rename_namespace(namespace) + end + end + + describe '#rename_namespace_dependencies' do it "moves the the repository for a project in the namespace" do create(:project, namespace: namespace, path: "the-path-project") expected_repo = File.join(TestEnv.repos_path, "the-path0", "the-path-project.git") - subject.rename_namespace(namespace) + subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0') expect(File.directory?(expected_repo)).to be(true) end @@ -161,13 +177,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : it "moves the uploads for the namespace" do expect(subject).to receive(:move_uploads).with("the-path", "the-path0") - subject.rename_namespace(namespace) + subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0') end it "moves the pages for the namespace" do expect(subject).to receive(:move_pages).with("the-path", "the-path0") - subject.rename_namespace(namespace) + subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0') end it 'invalidates the markdown cache of related projects' do @@ -175,13 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : expect(subject).to receive(:remove_cached_html_for_projects).with([project.id]) - subject.rename_namespace(namespace) + subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0') end it "doesn't rename users for other namespaces" do expect(subject).not_to receive(:rename_user) - subject.rename_namespace(namespace) + subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0') end it 'renames the username of a namespace for a user' do @@ -189,14 +205,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : expect(subject).to receive(:rename_user).with('the-path', 'the-path0') - subject.rename_namespace(user.namespace) - end - - it 'tracks the rename' do - expect(subject).to receive(:track_rename) - .with('namespace', 'the-path', 'the-path0') - - subject.rename_namespace(namespace) + subject.rename_namespace_dependencies(user.namespace, 'the-path', 'the-path0') end end @@ -231,4 +240,43 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : subject.rename_namespaces(type: :child) end end + + describe '#revert_renames', redis: true do + it 'renames the routes back to the previous values' do + project = create(:project, path: 'a-project', namespace: namespace) + subject.rename_namespace(namespace) + + expect(subject).to receive(:perform_rename) + .with( + kind_of(Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Namespace), + 'the-path0', + 'the-path' + ).and_call_original + + subject.revert_renames + + expect(namespace.reload.path).to eq('the-path') + expect(namespace.reload.route.path).to eq('the-path') + expect(project.reload.route.path).to eq('the-path/a-project') + end + + it 'moves the repositories back to their original place' do + project = create(:project, path: 'a-project', namespace: namespace) + project.create_repository + subject.rename_namespace(namespace) + + expected_path = File.join(TestEnv.repos_path, 'the-path', 'a-project.git') + + expect(subject).to receive(:rename_namespace_dependencies) + .with( + kind_of(Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Namespace), + 'the-path0', + 'the-path' + ).and_call_original + + subject.revert_renames + + expect(File.directory?(expected_path)).to be_truthy + end + end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index f87f4371353..ca741a4989b 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -9,9 +9,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr namespace: create(:namespace, path: 'known-parent' )) end - before do allow(migration).to receive(:say) + TestEnv.clean_test_path end describe '#projects_for_paths' do -- cgit v1.2.1 From c98ed42d01d4a15ce2a588079601b7d620b029ff Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 12 Jun 2017 11:03:28 +0200 Subject: Revert renames from a migration --- .../rename_reserved_paths_migration/v1_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb index 1d5e58855c1..9a48bc3a048 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb @@ -51,4 +51,26 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1, :truncate do subject.rename_root_paths('the-path') end end + + describe '#revert_renames' do + it 'renames namespaces' do + rename_namespaces = double + expect(described_class::RenameNamespaces). + to receive(:new).with([], subject). + and_return(rename_namespaces) + expect(rename_namespaces).to receive(:revert_renames) + + subject.revert_renames + end + + it 'renames projects' do + rename_projects = double + expect(described_class::RenameProjects). + to receive(:new).with([], subject). + and_return(rename_projects) + expect(rename_projects).to receive(:revert_renames) + + subject.revert_renames + end + end end -- cgit v1.2.1 From 229ac39a4c7f7cc4fa207ffa1c826e114df2906a Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 12 Jun 2017 19:10:00 +0200 Subject: Don't break rolling back when a namespace or project was renamed --- .../rename_reserved_paths_migration/v1/rename_namespaces_spec.rb | 7 +++++++ .../rename_reserved_paths_migration/v1/rename_projects_spec.rb | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index 5fa3d809c7a..803e923b4a5 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -278,5 +278,12 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : expect(File.directory?(expected_path)).to be_truthy end + + it "doesn't break when the namespace was renamed" do + subject.rename_namespace(namespace) + namespace.update_attributes!(path: 'renamed-afterwards') + + expect { subject.revert_renames }.not_to raise_error + end end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index ca741a4989b..0e240a5ccf1 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -149,5 +149,12 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr expect(File.directory?(expected_path)).to be_truthy end + + it "doesn't break when the project was renamed" do + subject.rename_project(project) + project.update_attributes!(path: 'renamed-afterwards') + + expect { subject.revert_renames }.not_to raise_error + end end end -- cgit v1.2.1 From d6a0c288c89765fa8f0e96aedefc608dd7025491 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 12 Jun 2017 19:19:00 +0200 Subject: Use the migration name as a key in redis --- .../database/rename_reserved_paths_migration/v1/rename_base_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb index f4e19f09419..2ce3fc0b497 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb @@ -231,7 +231,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca describe '#track_rename', redis: true do it 'tracks a rename in redis' do - key = 'rename:20170316163845:namespace' + key = 'rename:FakeRenameReservedPathMigrationV1:namespace' subject.track_rename('namespace', 'path/to/namespace', 'path/to/renamed') -- cgit v1.2.1 From 171f2d97dcc508ff6031248c6f78fc8ba75e939c Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 14 Jun 2017 15:20:03 +0200 Subject: Keep failed renames in redis --- .../v1/rename_base_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb index 2ce3fc0b497..8813f129ef5 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb @@ -257,5 +257,24 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca expect { |b| subject.reverts_for_type('namespace', &b) } .to yield_with_args('namespace_path', 'new_namespace_path') end + + it 'keeps the revert in redis if it failed' do + subject.track_rename('project', 'old_path', 'new_path') + + subject.reverts_for_type('project') do + raise 'whatever happens, keep going!' + end + + key = 'rename:FakeRenameReservedPathMigrationV1:project' + stored_renames = nil + rename_count = 0 + Gitlab::Redis.with do |redis| + stored_renames = redis.lrange(key, 0, 1) + rename_count = redis.llen(key) + end + + expect(rename_count).to eq(1) + expect(JSON.parse(stored_renames.first)).to eq(%w(old_path new_path)) + end end end -- cgit v1.2.1 From d4a3474b9b7321898a00ddcbaf651099ab96b2ba Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Mon, 26 Jun 2017 17:21:40 +0100 Subject: Fix Gitlab::Database.bulk_insert for non-UTF-8 data --- spec/lib/gitlab/database_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 5e6206b96c7..cbf6c35356e 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -176,6 +176,10 @@ describe Gitlab::Database, lib: true do described_class.bulk_insert('test', rows) end + + it 'handles non-UTF-8 data' do + expect { described_class.bulk_insert('test', [{ a: "\255" }]) }.not_to raise_error + end end describe '.create_connection_pool' do -- cgit v1.2.1 From e7d12a70d283b766cbcd4f417c293f34df10de3b Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Thu, 15 Jun 2017 12:50:45 +0200 Subject: Add in_review_folder to usage ping As its hard to reliably check how many review apps there are on the clients machine, we start by checking where the type is `review`. This means the folder is called that way. This will lead to a seq scan on the table. However, this is done once a week, so the benefit of adding an index seems not to apply here. --- spec/lib/gitlab/usage_data_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index b47e1b56fa9..3c7c7562b46 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -37,6 +37,7 @@ describe Gitlab::UsageData do deploy_keys deployments environments + in_review_folder groups issues keys -- cgit v1.2.1 From 144e37c667c1681ce8c1c8292ee8f48b9eb455c5 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 27 Jun 2017 12:17:14 +0200 Subject: Remove Gitlab::Git::Repository#find_all --- spec/lib/gitlab/git/commit_spec.rb | 27 +++++++++++++++++++++++++++ spec/lib/gitlab/git/repository_spec.rb | 29 ----------------------------- 2 files changed, 27 insertions(+), 29 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 3e44c577643..9e44aefc2db 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -244,6 +244,33 @@ describe Gitlab::Git::Commit, seed_helper: true do end describe '.find_all' do + it 'should return a return a collection of commits' do + commits = described_class.find_all(repository) + + expect(commits).not_to be_empty + expect(commits).to all( be_a_kind_of(Gitlab::Git::Commit) ) + end + + context 'while applying a sort order based on the `order` option' do + it "allows ordering topologically (no parents shown before their children)" do + expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_TOPO) + + described_class.find_all(repository, order: :topo) + end + + it "allows ordering by date" do + expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_DATE | Rugged::SORT_TOPO) + + described_class.find_all(repository, order: :date) + end + + it "applies no sorting by default" do + expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_NONE) + + described_class.find_all(repository) + end + end + context 'max_count' do subject do commits = Gitlab::Git::Commit.find_all( diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 703b0c2c202..4894b558e03 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1101,35 +1101,6 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - describe '#find_commits' do - it 'should return a return a collection of commits' do - commits = repository.find_commits - - expect(commits).not_to be_empty - expect(commits).to all( be_a_kind_of(Gitlab::Git::Commit) ) - end - - context 'while applying a sort order based on the `order` option' do - it "allows ordering topologically (no parents shown before their children)" do - expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_TOPO) - - repository.find_commits(order: :topo) - end - - it "allows ordering by date" do - expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_DATE | Rugged::SORT_TOPO) - - repository.find_commits(order: :date) - end - - it "applies no sorting by default" do - expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_NONE) - - repository.find_commits - end - end - end - describe '#branches with deleted branch' do before(:each) do ref = double() -- cgit v1.2.1 From 43c3a65062ed321427634d88f81755daf5611900 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 27 Jun 2017 12:30:15 +0200 Subject: Remove 'contains' option from Commit.find_all --- spec/lib/gitlab/git/commit_spec.rb | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 9e44aefc2db..f20a14155dc 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -308,26 +308,6 @@ describe Gitlab::Git::Commit, seed_helper: true do it { is_expected.to include(SeedRepo::FirstCommit::ID) } it { is_expected.not_to include(SeedRepo::LastCommit::ID) } end - - context 'contains feature + max_count' do - subject do - commits = Gitlab::Git::Commit.find_all( - repository, - contains: 'feature', - max_count: 7 - ) - - commits.map { |c| c.id } - end - - it 'has 7 elements' do - expect(subject.size).to eq(7) - end - - it { is_expected.not_to include(SeedRepo::Commit::PARENT_ID) } - it { is_expected.not_to include(SeedRepo::Commit::ID) } - it { is_expected.to include(SeedRepo::BigCommit::ID) } - end end end -- cgit v1.2.1 From 4447006832d8955f371e2430988e0c95b20f155d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 19 Jun 2017 19:56:27 +0200 Subject: Split pipelines by origin on usage data When sending the usage data, it now includes all pipelines. This commit will split the pipelines in two; internal and external. This will lead to historical data being incorrectly marked this way. Fixes gitlab-org/gitlab-ce#33172 --- spec/lib/gitlab/usage_data_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index b47e1b56fa9..9196d0ccc3f 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -30,7 +30,8 @@ describe Gitlab::UsageData do expect(count_data.keys).to match_array(%i( boards ci_builds - ci_pipelines + ci_internal_pipelines + ci_external_pipelines ci_runners ci_triggers ci_pipeline_schedules -- cgit v1.2.1 From 7c53fcf11fff8a05442ae813c9da76a9ed710abd Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 27 Jun 2017 13:05:02 +0200 Subject: Adjust for new static-analysis failures --- .../database/rename_reserved_paths_migration/v1_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb index 9a48bc3a048..7695b95dc57 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb @@ -55,9 +55,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1, :truncate do describe '#revert_renames' do it 'renames namespaces' do rename_namespaces = double - expect(described_class::RenameNamespaces). - to receive(:new).with([], subject). - and_return(rename_namespaces) + expect(described_class::RenameNamespaces) + .to receive(:new).with([], subject) + .and_return(rename_namespaces) expect(rename_namespaces).to receive(:revert_renames) subject.revert_renames @@ -65,9 +65,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1, :truncate do it 'renames projects' do rename_projects = double - expect(described_class::RenameProjects). - to receive(:new).with([], subject). - and_return(rename_projects) + expect(described_class::RenameProjects) + .to receive(:new).with([], subject) + .and_return(rename_projects) expect(rename_projects).to receive(:revert_renames) subject.revert_renames -- cgit v1.2.1 From cf131bf71323ee9812c503adedbcd347097efe48 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 27 Jun 2017 14:20:26 +0200 Subject: Make Gitlab::Ggit::Repository#submodules private --- spec/lib/gitlab/git/repository_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 703b0c2c202..fafb2cc2350 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -348,7 +348,7 @@ describe Gitlab::Git::Repository, seed_helper: true do let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } context 'where repo has submodules' do - let(:submodules) { repository.submodules('master') } + let(:submodules) { repository.send(:submodules, 'master') } let(:submodule) { submodules.first } it { expect(submodules).to be_kind_of Hash } @@ -383,12 +383,12 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'should not have an entry for an uncommited submodule dir' do - submodules = repository.submodules('fix-existing-submodule-dir') + submodules = repository.send(:submodules, 'fix-existing-submodule-dir') expect(submodules).not_to have_key('submodule-existing-dir') end it 'should handle tags correctly' do - submodules = repository.submodules('v1.2.1') + submodules = repository.send(:submodules, 'v1.2.1') expect(submodules.first).to eq([ "six", { @@ -414,7 +414,7 @@ describe Gitlab::Git::Repository, seed_helper: true do end context 'where repo doesn\'t have submodules' do - let(:submodules) { repository.submodules('6d39438') } + let(:submodules) { repository.send(:submodules, '6d39438') } it 'should return an empty hash' do expect(submodules).to be_empty end -- cgit v1.2.1 From b0f2861c3dd662a82ecbf535d1c259ad81df378b Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Tue, 27 Jun 2017 17:41:58 +0200 Subject: Make the SimpleExecutor rescue exceptions in the executing Checks --- spec/lib/system_check/simple_executor_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/system_check/simple_executor_spec.rb b/spec/lib/system_check/simple_executor_spec.rb index a5c6170cd7d..5de768d99ed 100644 --- a/spec/lib/system_check/simple_executor_spec.rb +++ b/spec/lib/system_check/simple_executor_spec.rb @@ -75,6 +75,15 @@ describe SystemCheck::SimpleExecutor, lib: true do end end + class BugousCheck < SystemCheck::BaseCheck + CustomError = Class.new(StandardError) + set_name 'my bugous check' + + def check? + raise CustomError, 'omg' + end + end + describe '#component' do it 'returns stored component name' do expect(subject.component).to eq('Test') @@ -138,14 +147,14 @@ describe SystemCheck::SimpleExecutor, lib: true do context 'when check pass' do it 'prints yes' do expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original - expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. yes/).to_stdout + expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. \e\[32myes/).to_stdout end end context 'when check fails' do it 'prints no' do expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original - expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. no/).to_stdout + expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. \e\[31mno/).to_stdout end it 'displays error message from #show_error' do @@ -219,5 +228,11 @@ describe SystemCheck::SimpleExecutor, lib: true do end end end + + context 'when there is an exception' do + it 'rescues the exception' do + expect{ subject.run_check(BugousCheck) }.not_to raise_exception + end + end end end -- cgit v1.2.1 From 758e020019860c611237e23a8898fa59c9bca5eb Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Tue, 27 Jun 2017 20:18:23 +0200 Subject: Disable rainbow during SimpleExecutor specs to have consistence --- spec/lib/system_check/simple_executor_spec.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/system_check/simple_executor_spec.rb b/spec/lib/system_check/simple_executor_spec.rb index 5de768d99ed..795f11ee1f8 100644 --- a/spec/lib/system_check/simple_executor_spec.rb +++ b/spec/lib/system_check/simple_executor_spec.rb @@ -84,6 +84,15 @@ describe SystemCheck::SimpleExecutor, lib: true do end end + before do + @rainbow = Rainbow.enabled + Rainbow.enabled = false + end + + after do + Rainbow.enabled = @rainbow + end + describe '#component' do it 'returns stored component name' do expect(subject.component).to eq('Test') @@ -147,14 +156,14 @@ describe SystemCheck::SimpleExecutor, lib: true do context 'when check pass' do it 'prints yes' do expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original - expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. \e\[32myes/).to_stdout + expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. yes/).to_stdout end end context 'when check fails' do it 'prints no' do expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original - expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. \e\[31mno/).to_stdout + expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. no/).to_stdout end it 'displays error message from #show_error' do -- cgit v1.2.1 From 34f7c3bd1a189ff79205f75d8f8b45b1e6a43c15 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 27 Jun 2017 14:47:57 -0500 Subject: Fix diff of requirements.txt file by not matching newlines as part of package names --- spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb b/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb index 7e32770f95d..64b233f3e68 100644 --- a/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb +++ b/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb @@ -87,5 +87,9 @@ describe Gitlab::DependencyLinker::RequirementsTxtLinker, lib: true do it 'links URLs' do expect(subject).to include(link('http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl', 'http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl')) end + + it 'does not contain link with a newline as package name' do + expect(subject).not_to include(link("\n", "https://pypi.python.org/pypi/\n")) + end end end -- cgit v1.2.1 From d2eb5bbd9cf194a67624044ee3cabc1280f33f4e Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 28 Jun 2017 09:30:18 +0200 Subject: Fix setting `last_credential_check` on LDAP-login --- spec/lib/gitlab/ldap/access_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb index 9dd997aa7dc..756fcb0fcaf 100644 --- a/spec/lib/gitlab/ldap/access_spec.rb +++ b/spec/lib/gitlab/ldap/access_spec.rb @@ -4,6 +4,16 @@ describe Gitlab::LDAP::Access, lib: true do let(:access) { Gitlab::LDAP::Access.new user } let(:user) { create(:omniauth_user) } + describe '.allowed?' do + it 'updates the users `last_credential_check_at' do + expect(access).to receive(:allowed?) { true } + expect(described_class).to receive(:open).and_yield(access) + + expect { described_class.allowed?(user) } + .to change { user.last_credential_check_at } + end + end + describe '#allowed?' do subject { access.allowed? } -- cgit v1.2.1 From 468e8b55585d54b1f92f647e8a1932f22610889e Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 28 Jun 2017 18:17:53 +0800 Subject: Fix doc, test, and form --- spec/lib/gitlab/import_export/safe_model_attributes.yml | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index fadd3ad1330..f782cf533e8 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -383,6 +383,7 @@ Project: - printing_merge_request_link_enabled - build_allow_git_fetch - last_repository_updated_at +- ci_config_file Author: - name ProjectFeature: -- cgit v1.2.1 From d3bcf8ac2ae7e89d0ec6eddcd6374bc1e1c8b5fb Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 28 Jun 2017 14:20:29 +0200 Subject: Fix gitaly ref encoding bugs --- spec/lib/gitlab/git/repository_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index ee25aeefa95..0cd458bf933 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -26,6 +26,10 @@ describe Gitlab::Git::Repository, seed_helper: true do end end + it 'returns UTF-8' do + expect(repository.root_ref.encoding).to eq(Encoding.find('UTF-8')) + end + context 'with gitaly enabled' do before do stub_gitaly @@ -123,6 +127,11 @@ describe Gitlab::Git::Repository, seed_helper: true do it 'has SeedRepo::Repo::BRANCHES.size elements' do expect(subject.size).to eq(SeedRepo::Repo::BRANCHES.size) end + + it 'returns UTF-8' do + expect(subject.first.encoding).to eq(Encoding.find('UTF-8')) + end + it { is_expected.to include("master") } it { is_expected.not_to include("branch-from-space") } @@ -158,10 +167,15 @@ describe Gitlab::Git::Repository, seed_helper: true do subject { repository.tag_names } it { is_expected.to be_kind_of Array } + it 'has SeedRepo::Repo::TAGS.size elements' do expect(subject.size).to eq(SeedRepo::Repo::TAGS.size) end + it 'returns UTF-8' do + expect(subject.first.encoding).to eq(Encoding.find('UTF-8')) + end + describe '#last' do subject { super().last } it { is_expected.to eq("v1.2.1") } @@ -1276,6 +1290,16 @@ describe Gitlab::Git::Repository, seed_helper: true do Gitlab::GitalyClient.clear_stubs! end + it 'returns a Branch with UTF-8 fields' do + branches = @repo.local_branches.to_a + expect(branches.size).to be > 0 + utf_8 = Encoding.find('utf-8') + branches.each do |branch| + expect(branch.name.encoding).to eq(utf_8) + expect(branch.target.encoding).to eq(utf_8) unless branch.target.nil? + end + end + it 'gets the branches from GitalyClient' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) .and_return([]) -- cgit v1.2.1 From 5681bf63490a945df6a70c85bebd94f376181307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 28 Jun 2017 15:38:00 -0400 Subject: Fix a bug where an invalid sort param value was passed to Gitaly --- spec/lib/gitlab/gitaly_client/ref_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index 42dba2ff874..8ad39a02b93 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -69,6 +69,15 @@ describe Gitlab::GitalyClient::Ref do client.local_branches(sort_by: 'updated_desc') end + it 'translates known mismatches on sort param values' do + expect_any_instance_of(Gitaly::Ref::Stub) + .to receive(:find_local_branches) + .with(gitaly_request_with_params(sort_by: :NAME), kind_of(Hash)) + .and_return([]) + + client.local_branches(sort_by: 'name_asc') + end + it 'raises an argument error if an invalid sort_by parameter is passed' do expect { client.local_branches(sort_by: 'invalid_sort') }.to raise_error(ArgumentError) end -- cgit v1.2.1 From af1f6844c98bfb4adda1c20dc75b808f031a4256 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 29 Jun 2017 15:37:37 +0200 Subject: Added code for defining SHA attributes These attributes are stored in binary in the database, but exposed as strings. This allows one to query/create data using plain SHA1 hashes as Strings, while storing them more efficiently as binary. --- spec/lib/gitlab/database/sha_attribute_spec.rb | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/lib/gitlab/database/sha_attribute_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database/sha_attribute_spec.rb b/spec/lib/gitlab/database/sha_attribute_spec.rb new file mode 100644 index 00000000000..62c1d37ea1c --- /dev/null +++ b/spec/lib/gitlab/database/sha_attribute_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe Gitlab::Database::ShaAttribute do + let(:sha) do + '9a573a369a5bfbb9a4a36e98852c21af8a44ea8b' + end + + let(:binary_sha) do + [sha].pack('H*') + end + + let(:binary_from_db) do + if Gitlab::Database.postgresql? + "\\x#{sha}" + else + binary_sha + end + end + + let(:attribute) { described_class.new } + + describe '#type_cast_from_database' do + it 'converts the binary SHA to a String' do + expect(attribute.type_cast_from_database(binary_from_db)).to eq(sha) + end + end + + describe '#type_cast_for_database' do + it 'converts a SHA String to binary data' do + expect(attribute.type_cast_for_database(sha).to_s).to eq(binary_sha) + end + end +end -- cgit v1.2.1 From f4e6aba1bbeca043a29b4903cef2f5b99a1faac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Thu, 29 Jun 2017 15:22:40 -0400 Subject: Set the GL_REPOSITORY env variable on Gitlab::Git::Hook --- spec/lib/gitlab/git/hook_spec.rb | 38 ++++++++++++++++------ .../lib/gitlab/import_export/repo_restorer_spec.rb | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/hook_spec.rb b/spec/lib/gitlab/git/hook_spec.rb index 3f279c21865..73518656bde 100644 --- a/spec/lib/gitlab/git/hook_spec.rb +++ b/spec/lib/gitlab/git/hook_spec.rb @@ -4,18 +4,20 @@ require 'fileutils' describe Gitlab::Git::Hook, lib: true do describe "#trigger" do let(:project) { create(:project, :repository) } + let(:repo_path) { project.repository.path } let(:user) { create(:user) } + let(:gl_id) { Gitlab::GlId.gl_id(user) } def create_hook(name) - FileUtils.mkdir_p(File.join(project.repository.path, 'hooks')) - File.open(File.join(project.repository.path, 'hooks', name), 'w', 0755) do |f| + FileUtils.mkdir_p(File.join(repo_path, 'hooks')) + File.open(File.join(repo_path, 'hooks', name), 'w', 0755) do |f| f.write('exit 0') end end def create_failing_hook(name) - FileUtils.mkdir_p(File.join(project.repository.path, 'hooks')) - File.open(File.join(project.repository.path, 'hooks', name), 'w', 0755) do |f| + FileUtils.mkdir_p(File.join(repo_path, 'hooks')) + File.open(File.join(repo_path, 'hooks', name), 'w', 0755) do |f| f.write(<<-HOOK) echo 'regular message from the hook' echo 'error message from the hook' 1>&2 @@ -27,13 +29,29 @@ describe Gitlab::Git::Hook, lib: true do ['pre-receive', 'post-receive', 'update'].each do |hook_name| context "when triggering a #{hook_name} hook" do context "when the hook is successful" do + let(:hook_path) { File.join(repo_path, 'hooks', hook_name) } + let(:gl_repository) { Gitlab::GlRepository.gl_repository(project, false) } + let(:env) do + { + 'GL_ID' => gl_id, + 'PWD' => repo_path, + 'GL_PROTOCOL' => 'web', + 'GL_REPOSITORY' => gl_repository + } + end + it "returns success with no errors" do create_hook(hook_name) - hook = Gitlab::Git::Hook.new(hook_name, project.repository.path) + hook = Gitlab::Git::Hook.new(hook_name, project) blank = Gitlab::Git::BLANK_SHA ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' - status, errors = hook.trigger(Gitlab::GlId.gl_id(user), blank, blank, ref) + if hook_name != 'update' + expect(Open3).to receive(:popen3) + .with(env, hook_path, chdir: repo_path).and_call_original + end + + status, errors = hook.trigger(gl_id, blank, blank, ref) expect(status).to be true expect(errors).to be_blank end @@ -42,11 +60,11 @@ describe Gitlab::Git::Hook, lib: true do context "when the hook is unsuccessful" do it "returns failure with errors" do create_failing_hook(hook_name) - hook = Gitlab::Git::Hook.new(hook_name, project.repository.path) + hook = Gitlab::Git::Hook.new(hook_name, project) blank = Gitlab::Git::BLANK_SHA ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' - status, errors = hook.trigger(Gitlab::GlId.gl_id(user), blank, blank, ref) + status, errors = hook.trigger(gl_id, blank, blank, ref) expect(status).to be false expect(errors).to eq("error message from the hook\n") end @@ -56,11 +74,11 @@ describe Gitlab::Git::Hook, lib: true do context "when the hook doesn't exist" do it "returns success with no errors" do - hook = Gitlab::Git::Hook.new('unknown_hook', project.repository.path) + hook = Gitlab::Git::Hook.new('unknown_hook', project) blank = Gitlab::Git::BLANK_SHA ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' - status, errors = hook.trigger(Gitlab::GlId.gl_id(user), blank, blank, ref) + status, errors = hook.trigger(gl_id, blank, blank, ref) expect(status).to be true expect(errors).to be_nil end diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb index 168a59e5139..30b6a0d8845 100644 --- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb @@ -34,7 +34,7 @@ describe Gitlab::ImportExport::RepoRestorer, services: true do it 'has the webhooks' do restorer.restore - expect(Gitlab::Git::Hook.new('post-receive', project.repository.path_to_repo)).to exist + expect(Gitlab::Git::Hook.new('post-receive', project)).to exist end end end -- cgit v1.2.1 From 790c740cce8487d1155607355d06f42ee2e83fac Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Thu, 29 Jun 2017 10:54:10 -0700 Subject: Increase CI retries to 4 for these examples By default it is 2 tries in CI. --- spec/lib/gitlab/health_checks/fs_shards_check_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb index 61c10d47434..c8c402b4f71 100644 --- a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb +++ b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb @@ -97,6 +97,12 @@ describe Gitlab::HealthChecks::FsShardsCheck do }.with_indifferent_access end + # Unsolved intermittent failure in CI https://gitlab.com/gitlab-org/gitlab-ce/issues/31128 + around(:each) do |example| + times_to_try = ENV['CI'] ? 4 : 1 + example.run_with_retry retry: times_to_try + end + it { is_expected.to all(have_attributes(labels: { shard: :default })) } it { is_expected.to include(an_object_having_attributes(name: :filesystem_accessible, value: 0)) } -- cgit v1.2.1 From 53c409cb07d295043c5e1cff738c84b3aa7405a8 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Thu, 29 Jun 2017 16:53:41 -0700 Subject: =?UTF-8?q?Rspec/AroundBlock=20doesn=E2=80=99t=20know=20about=20rs?= =?UTF-8?q?pec-retry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/lib/gitlab/health_checks/fs_shards_check_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb index c8c402b4f71..fbacbc4a338 100644 --- a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb +++ b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb @@ -98,7 +98,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do end # Unsolved intermittent failure in CI https://gitlab.com/gitlab-org/gitlab-ce/issues/31128 - around(:each) do |example| + around(:each) do |example| # rubocop:disable RSpec/AroundBlock times_to_try = ENV['CI'] ? 4 : 1 example.run_with_retry retry: times_to_try end -- cgit v1.2.1 From 7648f113814a78ffde802172197ba2b0074ec753 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 28 Jun 2017 17:33:48 +0200 Subject: Remove unnecessary contexts --- spec/lib/gitlab/git/repository_spec.rb | 174 ++++++++++++------------------ spec/lib/gitlab/gitaly_client/ref_spec.rb | 4 - 2 files changed, 66 insertions(+), 112 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 0cd458bf933..464cb41a842 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -5,6 +5,11 @@ describe Gitlab::Git::Repository, seed_helper: true do let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } + after do + # Prevent cached stubs (gRPC connection objects) from poisoning tests. + Gitlab::GitalyClient.clear_stubs! + end + describe "Respond to" do subject { repository } @@ -30,31 +35,21 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(repository.root_ref.encoding).to eq(Encoding.find('UTF-8')) end - context 'with gitaly enabled' do - before do - stub_gitaly - end - - after do - Gitlab::GitalyClient.clear_stubs! - end - - it 'gets the branch name from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) - repository.root_ref - end + it 'gets the branch name from GitalyClient' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) + repository.root_ref + end - it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) - .and_raise(GRPC::NotFound) - expect { repository.root_ref }.to raise_error(Gitlab::Git::Repository::NoRepository) - end + it 'wraps GRPC not found' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) + .and_raise(GRPC::NotFound) + expect { repository.root_ref }.to raise_error(Gitlab::Git::Repository::NoRepository) + end - it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) - .and_raise(GRPC::Unknown) - expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError) - end + it 'wraps GRPC exceptions' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) + .and_raise(GRPC::Unknown) + expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError) end end @@ -135,31 +130,21 @@ describe Gitlab::Git::Repository, seed_helper: true do it { is_expected.to include("master") } it { is_expected.not_to include("branch-from-space") } - context 'with gitaly enabled' do - before do - stub_gitaly - end - - after do - Gitlab::GitalyClient.clear_stubs! - end - - it 'gets the branch names from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) - subject - end + it 'gets the branch names from GitalyClient' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) + subject + end - it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) - .and_raise(GRPC::NotFound) - expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository) - end + it 'wraps GRPC not found' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) + .and_raise(GRPC::NotFound) + expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository) + end - it 'wraps GRPC other exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) - .and_raise(GRPC::Unknown) - expect { subject }.to raise_error(Gitlab::Git::CommandError) - end + it 'wraps GRPC other exceptions' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) + .and_raise(GRPC::Unknown) + expect { subject }.to raise_error(Gitlab::Git::CommandError) end end @@ -183,31 +168,21 @@ describe Gitlab::Git::Repository, seed_helper: true do it { is_expected.to include("v1.0.0") } it { is_expected.not_to include("v5.0.0") } - context 'with gitaly enabled' do - before do - stub_gitaly - end - - after do - Gitlab::GitalyClient.clear_stubs! - end - - it 'gets the tag names from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) - subject - end + it 'gets the tag names from GitalyClient' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) + subject + end - it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) - .and_raise(GRPC::NotFound) - expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository) - end + it 'wraps GRPC not found' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) + .and_raise(GRPC::NotFound) + expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository) + end - it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) - .and_raise(GRPC::Unknown) - expect { subject }.to raise_error(Gitlab::Git::CommandError) - end + it 'wraps GRPC exceptions' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) + .and_raise(GRPC::Unknown) + expect { subject }.to raise_error(Gitlab::Git::CommandError) end end @@ -1281,42 +1256,32 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(@repo.local_branches.any? { |branch| branch.name == 'local_branch' }).to eq(true) end - context 'with gitaly enabled' do - before do - stub_gitaly - end - - after do - Gitlab::GitalyClient.clear_stubs! - end - - it 'returns a Branch with UTF-8 fields' do - branches = @repo.local_branches.to_a - expect(branches.size).to be > 0 - utf_8 = Encoding.find('utf-8') - branches.each do |branch| - expect(branch.name.encoding).to eq(utf_8) - expect(branch.target.encoding).to eq(utf_8) unless branch.target.nil? - end + it 'returns a Branch with UTF-8 fields' do + branches = @repo.local_branches.to_a + expect(branches.size).to be > 0 + utf_8 = Encoding.find('utf-8') + branches.each do |branch| + expect(branch.name.encoding).to eq(utf_8) + expect(branch.target.encoding).to eq(utf_8) unless branch.target.nil? end + end - it 'gets the branches from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) - .and_return([]) - @repo.local_branches - end + it 'gets the branches from GitalyClient' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) + .and_return([]) + @repo.local_branches + end - it 'wraps GRPC not found' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) - .and_raise(GRPC::NotFound) - expect { @repo.local_branches }.to raise_error(Gitlab::Git::Repository::NoRepository) - end + it 'wraps GRPC not found' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) + .and_raise(GRPC::NotFound) + expect { @repo.local_branches }.to raise_error(Gitlab::Git::Repository::NoRepository) + end - it 'wraps GRPC exceptions' do - expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) - .and_raise(GRPC::Unknown) - expect { @repo.local_branches }.to raise_error(Gitlab::Git::CommandError) - end + it 'wraps GRPC exceptions' do + expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:local_branches) + .and_raise(GRPC::Unknown) + expect { @repo.local_branches }.to raise_error(Gitlab::Git::CommandError) end end @@ -1395,11 +1360,4 @@ describe Gitlab::Git::Repository, seed_helper: true do sha = Rugged::Commit.create(repo, options) repo.lookup(sha) end - - def stub_gitaly - allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(true) - - stub = double(:stub) - allow(Gitaly::Ref::Stub).to receive(:new).and_return(stub) - end end diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index 8ad39a02b93..986ae348652 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -6,10 +6,6 @@ describe Gitlab::GitalyClient::Ref do let(:relative_path) { project.path_with_namespace + '.git' } let(:client) { described_class.new(project.repository) } - before do - allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true) - end - after do # When we say `expect_any_instance_of(Gitaly::Ref::Stub)` a double is created, # and because GitalyClient shares stubs these will get passed from example to -- cgit v1.2.1 From 8a62f304ef541b93ac47dab3b69b645f2b65537a Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 28 Jun 2017 17:44:37 +0200 Subject: Add a UTF-8 encoding matcher --- spec/lib/gitlab/git/blame_spec.rb | 3 +++ spec/lib/gitlab/git/branch_spec.rb | 2 +- spec/lib/gitlab/git/diff_spec.rb | 2 +- spec/lib/gitlab/git/repository_spec.rb | 11 +++++------ 4 files changed, 10 insertions(+), 8 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/blame_spec.rb b/spec/lib/gitlab/git/blame_spec.rb index 8b041ac69b1..66c016d14b3 100644 --- a/spec/lib/gitlab/git/blame_spec.rb +++ b/spec/lib/gitlab/git/blame_spec.rb @@ -20,6 +20,7 @@ describe Gitlab::Git::Blame, seed_helper: true do expect(data.size).to eq(95) expect(data.first[:commit]).to be_kind_of(Gitlab::Git::Commit) expect(data.first[:line]).to eq("# Contribute to GitLab") + expect(data.first[:line]).to be_utf8 end end @@ -40,6 +41,7 @@ describe Gitlab::Git::Blame, seed_helper: true do expect(data.size).to eq(1) expect(data.first[:commit]).to be_kind_of(Gitlab::Git::Commit) expect(data.first[:line]).to eq("Ä ü") + expect(data.first[:line]).to be_utf8 end end @@ -61,6 +63,7 @@ describe Gitlab::Git::Blame, seed_helper: true do expect(data.size).to eq(1) expect(data.first[:commit]).to be_kind_of(Gitlab::Git::Commit) expect(data.first[:line]).to eq(" ") + expect(data.first[:line]).to be_utf8 end end end diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb index 9dba4397e79..d1d7ed1d02a 100644 --- a/spec/lib/gitlab/git/branch_spec.rb +++ b/spec/lib/gitlab/git/branch_spec.rb @@ -48,7 +48,7 @@ describe Gitlab::Git::Branch, seed_helper: true do expect(Gitlab::Git::Commit).to receive(:decorate) .with(hash_including(attributes)).and_call_original - expect(branch.dereferenced_target.message.encoding).to be(Encoding::UTF_8) + expect(branch.dereferenced_target.message).to be_utf8 end end diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb index d50ccb0df30..d97e85364c2 100644 --- a/spec/lib/gitlab/git/diff_spec.rb +++ b/spec/lib/gitlab/git/diff_spec.rb @@ -180,7 +180,7 @@ EOT let(:raw_patch) { @raw_diff_hash[:diff].encode(Encoding::ASCII_8BIT) } it 'encodes diff patch to UTF-8' do - expect(diff.diff.encoding).to eq(Encoding::UTF_8) + expect(diff.diff).to be_utf8 end end end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 464cb41a842..9e924c2541b 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -32,7 +32,7 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'returns UTF-8' do - expect(repository.root_ref.encoding).to eq(Encoding.find('UTF-8')) + expect(repository.root_ref).to be_utf8 end it 'gets the branch name from GitalyClient' do @@ -124,7 +124,7 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'returns UTF-8' do - expect(subject.first.encoding).to eq(Encoding.find('UTF-8')) + expect(subject.first).to be_utf8 end it { is_expected.to include("master") } @@ -158,7 +158,7 @@ describe Gitlab::Git::Repository, seed_helper: true do end it 'returns UTF-8' do - expect(subject.first.encoding).to eq(Encoding.find('UTF-8')) + expect(subject.first).to be_utf8 end describe '#last' do @@ -1259,10 +1259,9 @@ describe Gitlab::Git::Repository, seed_helper: true do it 'returns a Branch with UTF-8 fields' do branches = @repo.local_branches.to_a expect(branches.size).to be > 0 - utf_8 = Encoding.find('utf-8') branches.each do |branch| - expect(branch.name.encoding).to eq(utf_8) - expect(branch.target.encoding).to eq(utf_8) unless branch.target.nil? + expect(branch.name).to be_utf8 + expect(branch.target).to be_utf8 unless branch.target.nil? end end -- cgit v1.2.1 From 9da3076944146444cb864d5db066a766c76b1935 Mon Sep 17 00:00:00 2001 From: Adam Niedzielski Date: Fri, 30 Jun 2017 14:47:53 +0200 Subject: Improve support for external issue references --- .../filter/external_issue_reference_filter_spec.rb | 4 +-- .../banzai/filter/issue_reference_filter_spec.rb | 25 ---------------- spec/lib/banzai/pipeline/gfm_pipeline_spec.rb | 33 ++++++++++++++++++++++ .../banzai/reference_parser/issue_parser_spec.rb | 10 ------- 4 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 spec/lib/banzai/pipeline/gfm_pipeline_spec.rb (limited to 'spec/lib') 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 a4bb043f8f1..b7d82c36ddd 100644 --- a/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb @@ -88,12 +88,12 @@ describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true 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(:issue_reference_pattern).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 }) expect_any_instance_of(Project).not_to receive(:default_issues_tracker?) - expect_any_instance_of(Project).not_to receive(:issue_reference_pattern) + expect_any_instance_of(Project).not_to receive(:external_issue_reference_pattern) cached = reference_filter.call("look for #{reference}", { project: project }) diff --git a/spec/lib/banzai/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb index e5c1deb338b..a79d365d6c5 100644 --- a/spec/lib/banzai/filter/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb @@ -39,13 +39,6 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do let(:reference) { "##{issue.iid}" } - it 'ignores valid references when using non-default tracker' do - allow(project).to receive(:default_issues_tracker?).and_return(false) - - exp = act = "Issue #{reference}" - expect(reference_filter(act).to_html).to eq exp - end - it 'links to a valid reference' do doc = reference_filter("Fixed #{reference}") @@ -340,24 +333,6 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do .to eq({ project => { issue.iid => issue } }) end end - - context 'using an external 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(project).to receive(:default_issues_tracker?).and_return(false) - - expect(filter).to receive(:projects_per_reference) - .and_return({ project.path_with_namespace => project }) - - expect(filter).to receive(:references_per_project) - .and_return({ project.path_with_namespace => Set.new([1]) }) - - expect(filter.issues_per_project[project][1]) - .to be_an_instance_of(ExternalIssue) - end - end end describe '.references_in' do diff --git a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb new file mode 100644 index 00000000000..2b8c76f2bb8 --- /dev/null +++ b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +describe Banzai::Pipeline::GfmPipeline do + describe 'integration between parsing regular and external issue references' do + let(:project) { create(:redmine_project, :public) } + + 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 + + expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + end + + it 'parses cross-project references to regular issues' do + other_project = create(:empty_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 + + expect(link['href']).to eq( + Gitlab::Routing.url_helpers.namespace_project_issue_path( + other_project.namespace, + other_project, + issue + ) + ) + end + end +end diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb index 58e1a0c1bc1..acdd23f81f3 100644 --- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb @@ -39,16 +39,6 @@ describe Banzai::ReferenceParser::IssueParser, lib: true do expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end end - - context 'when the project uses an external issue tracker' do - it 'returns all nodes' do - link = double(:link) - - expect(project).to receive(:external_issue_tracker).and_return(true) - - expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) - end - end end describe '#referenced_by' do -- cgit v1.2.1 From 912613c41be3790b004f65935e8380aea9e5895f Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Fri, 30 Jun 2017 09:00:07 -0700 Subject: Reduce 28 test runs to 4 14 to 2, but these shared examples are used twice. This was already done in another context further down the file. --- .../gitlab/health_checks/fs_shards_check_spec.rb | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb index fbacbc4a338..b333e162909 100644 --- a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb +++ b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb @@ -103,30 +103,34 @@ describe Gitlab::HealthChecks::FsShardsCheck do example.run_with_retry retry: times_to_try end - it { is_expected.to all(have_attributes(labels: { shard: :default })) } - - it { is_expected.to include(an_object_having_attributes(name: :filesystem_accessible, value: 0)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_readable, value: 0)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_writable, value: 0)) } - - it { is_expected.to include(an_object_having_attributes(name: :filesystem_access_latency, value: be >= 0)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_read_latency, value: be >= 0)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_write_latency, value: be >= 0)) } + it 'provides metrics' do + expect(subject).to all(have_attributes(labels: { shard: :default })) + expect(subject).to include(an_object_having_attributes(name: :filesystem_accessible, value: 0)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_readable, value: 0)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_writable, value: 0)) + + expect(subject).to include(an_object_having_attributes(name: :filesystem_access_latency, value: be >= 0)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_read_latency, value: be >= 0)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_write_latency, value: be >= 0)) + end end context 'storage points to directory that has both read and write rights' do before do FileUtils.chmod_R(0755, tmp_dir) end - it { is_expected.to all(have_attributes(labels: { shard: :default })) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_accessible, value: 1)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_readable, value: 1)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_writable, value: 1)) } + it 'provides metrics' do + expect(subject).to all(have_attributes(labels: { shard: :default })) - it { is_expected.to include(an_object_having_attributes(name: :filesystem_access_latency, value: be >= 0)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_read_latency, value: be >= 0)) } - it { is_expected.to include(an_object_having_attributes(name: :filesystem_write_latency, value: be >= 0)) } + expect(subject).to include(an_object_having_attributes(name: :filesystem_accessible, value: 1)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_readable, value: 1)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_writable, value: 1)) + + expect(subject).to include(an_object_having_attributes(name: :filesystem_access_latency, value: be >= 0)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_read_latency, value: be >= 0)) + expect(subject).to include(an_object_having_attributes(name: :filesystem_write_latency, value: be >= 0)) + end end end end -- cgit v1.2.1 From dcdf2a8bc58e5a9750f3a4dfdb4b1795863b3853 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 28 Jun 2017 21:30:38 +0200 Subject: Make entrypoint and command keys to be array of strings --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 25 +++++++++++++++++-------- spec/lib/gitlab/ci/config/entry/image_spec.rb | 4 ++-- spec/lib/gitlab/ci/config/entry/service_spec.rb | 6 +++--- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index af0e7855a9b..e02317adbad 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -598,8 +598,10 @@ module Ci describe "Image and service handling" do context "when extended docker configuration is used" do it "returns image and service when defined" do - config = YAML.dump({ image: { name: "ruby:2.1" }, - services: ["mysql", { name: "docker:dind", alias: "docker" }], + config = YAML.dump({ image: { name: "ruby:2.1", entrypoint: ["/usr/local/bin/init", "run"] }, + services: ["mysql", { name: "docker:dind", alias: "docker", + entrypoint: ["/usr/local/bin/init", "run"], + command: ["/usr/local/bin/init", "run"] }], before_script: ["pwd"], rspec: { script: "rspec" } }) @@ -614,8 +616,10 @@ module Ci coverage_regex: nil, tag_list: [], options: { - image: { name: "ruby:2.1" }, - services: [{ name: "mysql" }, { name: "docker:dind", alias: "docker" }] + image: { name: "ruby:2.1", entrypoint: ["/usr/local/bin/init", "run"] }, + services: [{ name: "mysql" }, + { name: "docker:dind", alias: "docker", entrypoint: ["/usr/local/bin/init", "run"], + command: ["/usr/local/bin/init", "run"] }] }, allow_failure: false, when: "on_success", @@ -628,8 +632,11 @@ module Ci config = YAML.dump({ image: "ruby:2.1", services: ["mysql"], before_script: ["pwd"], - rspec: { image: { name: "ruby:2.5" }, - services: [{ name: "postgresql", alias: "db-pg" }, "docker:dind"], script: "rspec" } }) + rspec: { image: { name: "ruby:2.5", entrypoint: ["/usr/local/bin/init", "run"] }, + services: [{ name: "postgresql", alias: "db-pg", + entrypoint: ["/usr/local/bin/init", "run"], + command: ["/usr/local/bin/init", "run"] }, "docker:dind"], + script: "rspec" } }) config_processor = GitlabCiYamlProcessor.new(config, path) @@ -642,8 +649,10 @@ module Ci coverage_regex: nil, tag_list: [], options: { - image: { name: "ruby:2.5" }, - services: [{ name: "postgresql", alias: "db-pg" }, { name: "docker:dind" }] + image: { name: "ruby:2.5", entrypoint: ["/usr/local/bin/init", "run"] }, + services: [{ name: "postgresql", alias: "db-pg", entrypoint: ["/usr/local/bin/init", "run"], + command: ["/usr/local/bin/init", "run"]}, + { name: "docker:dind" }] }, allow_failure: false, when: "on_success", diff --git a/spec/lib/gitlab/ci/config/entry/image_spec.rb b/spec/lib/gitlab/ci/config/entry/image_spec.rb index bca22e39500..d8800fb675b 100644 --- a/spec/lib/gitlab/ci/config/entry/image_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/image_spec.rb @@ -38,7 +38,7 @@ describe Gitlab::Ci::Config::Entry::Image do end context 'when configuration is a hash' do - let(:config) { { name: 'ruby:2.2', entrypoint: '/bin/sh' } } + let(:config) { { name: 'ruby:2.2', entrypoint: ['/bin/sh', 'run'] } } describe '#value' do it 'returns image hash' do @@ -66,7 +66,7 @@ describe Gitlab::Ci::Config::Entry::Image do describe '#entrypoint' do it "returns image's entrypoint" do - expect(entry.entrypoint).to eq '/bin/sh' + expect(entry.entrypoint).to eq ['/bin/sh', 'run'] end end end diff --git a/spec/lib/gitlab/ci/config/entry/service_spec.rb b/spec/lib/gitlab/ci/config/entry/service_spec.rb index 7202fe525e4..24b7086c34c 100644 --- a/spec/lib/gitlab/ci/config/entry/service_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/service_spec.rb @@ -43,7 +43,7 @@ describe Gitlab::Ci::Config::Entry::Service do context 'when configuration is a hash' do let(:config) do - { name: 'postgresql:9.5', alias: 'db', command: 'cmd', entrypoint: '/bin/sh' } + { name: 'postgresql:9.5', alias: 'db', command: ['cmd', 'run'], entrypoint: ['/bin/sh', 'run'] } end describe '#valid?' do @@ -72,13 +72,13 @@ describe Gitlab::Ci::Config::Entry::Service do describe '#command' do it "returns service's command" do - expect(entry.command).to eq 'cmd' + expect(entry.command).to eq ['cmd', 'run'] end end describe '#entrypoint' do it "returns service's entrypoint" do - expect(entry.entrypoint).to eq '/bin/sh' + expect(entry.entrypoint).to eq ['/bin/sh', 'run'] end end end -- cgit v1.2.1 From 16ff3229cbb71e05f9cea3a16b481a8120dfcb7e Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Fri, 30 Jun 2017 13:30:19 +0200 Subject: Fix rubocop offenses --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 +- spec/lib/gitlab/ci/config/entry/image_spec.rb | 4 ++-- spec/lib/gitlab/ci/config/entry/service_spec.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index e02317adbad..482f03aa0cc 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -651,7 +651,7 @@ module Ci options: { image: { name: "ruby:2.5", entrypoint: ["/usr/local/bin/init", "run"] }, services: [{ name: "postgresql", alias: "db-pg", entrypoint: ["/usr/local/bin/init", "run"], - command: ["/usr/local/bin/init", "run"]}, + command: ["/usr/local/bin/init", "run"] }, { name: "docker:dind" }] }, allow_failure: false, diff --git a/spec/lib/gitlab/ci/config/entry/image_spec.rb b/spec/lib/gitlab/ci/config/entry/image_spec.rb index d8800fb675b..1a4d9ed5517 100644 --- a/spec/lib/gitlab/ci/config/entry/image_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/image_spec.rb @@ -38,7 +38,7 @@ describe Gitlab::Ci::Config::Entry::Image do end context 'when configuration is a hash' do - let(:config) { { name: 'ruby:2.2', entrypoint: ['/bin/sh', 'run'] } } + let(:config) { { name: 'ruby:2.2', entrypoint: %w(/bin/sh run) } } describe '#value' do it 'returns image hash' do @@ -66,7 +66,7 @@ describe Gitlab::Ci::Config::Entry::Image do describe '#entrypoint' do it "returns image's entrypoint" do - expect(entry.entrypoint).to eq ['/bin/sh', 'run'] + expect(entry.entrypoint).to eq %w(/bin/sh run) end end end diff --git a/spec/lib/gitlab/ci/config/entry/service_spec.rb b/spec/lib/gitlab/ci/config/entry/service_spec.rb index 24b7086c34c..9ebf947a751 100644 --- a/spec/lib/gitlab/ci/config/entry/service_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/service_spec.rb @@ -43,7 +43,7 @@ describe Gitlab::Ci::Config::Entry::Service do context 'when configuration is a hash' do let(:config) do - { name: 'postgresql:9.5', alias: 'db', command: ['cmd', 'run'], entrypoint: ['/bin/sh', 'run'] } + { name: 'postgresql:9.5', alias: 'db', command: %w(cmd run), entrypoint: %w(/bin/sh run) } end describe '#valid?' do @@ -72,13 +72,13 @@ describe Gitlab::Ci::Config::Entry::Service do describe '#command' do it "returns service's command" do - expect(entry.command).to eq ['cmd', 'run'] + expect(entry.command).to eq %w(cmd run) end end describe '#entrypoint' do it "returns service's entrypoint" do - expect(entry.entrypoint).to eq ['/bin/sh', 'run'] + expect(entry.entrypoint).to eq %w(/bin/sh run) end end end -- cgit v1.2.1 From d8cc0d0115aefe02b611489a89cb11c125d802af Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 3 Jul 2017 18:28:29 +0000 Subject: Speed up operations performed by gitlab-shell --- spec/lib/gitlab/popen_spec.rb | 13 ++++++- spec/lib/gitlab/shell_spec.rb | 87 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/popen_spec.rb b/spec/lib/gitlab/popen_spec.rb index 4ae216d55b0..af50ecdb2ab 100644 --- a/spec/lib/gitlab/popen_spec.rb +++ b/spec/lib/gitlab/popen_spec.rb @@ -32,6 +32,17 @@ describe 'Gitlab::Popen', lib: true, no_db: true do end end + context 'with custom options' do + let(:vars) { { 'foobar' => 123, 'PWD' => path } } + let(:options) { { chdir: path } } + + it 'calls popen3 with the provided environment variables' do + expect(Open3).to receive(:popen3).with(vars, 'ls', options) + + @output, @status = @klass.new.popen(%w(ls), path, { 'foobar' => 123 }) + end + end + context 'without a directory argument' do before do @output, @status = @klass.new.popen(%w(ls)) @@ -45,7 +56,7 @@ describe 'Gitlab::Popen', lib: true, no_db: true do before do @output, @status = @klass.new.popen(%w[cat]) { |stdin| stdin.write 'hello' } end - + it { expect(@status).to be_zero } it { expect(@output).to eq('hello') } end diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index a97a0f8452b..5b1b8f9516a 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -4,6 +4,7 @@ require 'stringio' describe Gitlab::Shell, lib: true do let(:project) { double('Project', id: 7, path: 'diaspora') } let(:gitlab_shell) { Gitlab::Shell.new } + let(:popen_vars) { { 'GIT_TERMINAL_PROMPT' => ENV['GIT_TERMINAL_PROMPT'] } } before do allow(Project).to receive(:find).and_return(project) @@ -50,7 +51,7 @@ describe Gitlab::Shell, lib: true do describe '#add_key' do it 'removes trailing garbage' do allow(gitlab_shell).to receive(:gitlab_shell_keys_path).and_return(:gitlab_shell_keys_path) - expect(Gitlab::Utils).to receive(:system_silent).with( + expect(gitlab_shell).to receive(:gitlab_shell_fast_execute).with( [:gitlab_shell_keys_path, 'add-key', 'key-123', 'ssh-rsa foobar'] ) @@ -100,17 +101,91 @@ describe Gitlab::Shell, lib: true do allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800) end + describe '#add_repository' do + it 'returns true when the command succeeds' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'add-project', 'current/storage', 'project/path.git'], + nil, popen_vars).and_return([nil, 0]) + + expect(gitlab_shell.add_repository('current/storage', 'project/path')).to be true + end + + it 'returns false when the command fails' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'add-project', 'current/storage', 'project/path.git'], + nil, popen_vars).and_return(["error", 1]) + + expect(gitlab_shell.add_repository('current/storage', 'project/path')).to be false + end + end + + describe '#remove_repository' do + it 'returns true when the command succeeds' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'rm-project', 'current/storage', 'project/path.git'], + nil, popen_vars).and_return([nil, 0]) + + expect(gitlab_shell.remove_repository('current/storage', 'project/path')).to be true + end + + it 'returns false when the command fails' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'rm-project', 'current/storage', 'project/path.git'], + nil, popen_vars).and_return(["error", 1]) + + expect(gitlab_shell.remove_repository('current/storage', 'project/path')).to be false + end + end + + describe '#mv_repository' do + it 'returns true when the command succeeds' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'mv-project', 'current/storage', 'project/path.git', 'project/newpath.git'], + nil, popen_vars).and_return([nil, 0]) + + expect(gitlab_shell.mv_repository('current/storage', 'project/path', 'project/newpath')).to be true + end + + it 'returns false when the command fails' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'mv-project', 'current/storage', 'project/path.git', 'project/newpath.git'], + nil, popen_vars).and_return(["error", 1]) + + expect(gitlab_shell.mv_repository('current/storage', 'project/path', 'project/newpath')).to be false + end + end + + describe '#fork_repository' do + it 'returns true when the command succeeds' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'fork-project', 'current/storage', 'project/path.git', 'new/storage', 'new-namespace'], + nil, popen_vars).and_return([nil, 0]) + + expect(gitlab_shell.fork_repository('current/storage', 'project/path', 'new/storage', 'new-namespace')).to be true + end + + it 'return false when the command fails' do + expect(Gitlab::Popen).to receive(:popen) + .with([projects_path, 'fork-project', 'current/storage', 'project/path.git', 'new/storage', 'new-namespace'], + nil, popen_vars).and_return(["error", 1]) + + expect(gitlab_shell.fork_repository('current/storage', 'project/path', 'new/storage', 'new-namespace')).to be false + end + end + describe '#fetch_remote' do it 'returns true when the command succeeds' do expect(Gitlab::Popen).to receive(:popen) - .with([projects_path, 'fetch-remote', 'current/storage', 'project/path.git', 'new/storage', '800']).and_return([nil, 0]) + .with([projects_path, 'fetch-remote', 'current/storage', 'project/path.git', 'new/storage', '800'], + nil, popen_vars).and_return([nil, 0]) expect(gitlab_shell.fetch_remote('current/storage', 'project/path', 'new/storage')).to be true end it 'raises an exception when the command fails' do expect(Gitlab::Popen).to receive(:popen) - .with([projects_path, 'fetch-remote', 'current/storage', 'project/path.git', 'new/storage', '800']).and_return(["error", 1]) + .with([projects_path, 'fetch-remote', 'current/storage', 'project/path.git', 'new/storage', '800'], + nil, popen_vars).and_return(["error", 1]) expect { gitlab_shell.fetch_remote('current/storage', 'project/path', 'new/storage') }.to raise_error(Gitlab::Shell::Error, "error") end @@ -119,14 +194,16 @@ describe Gitlab::Shell, lib: true do describe '#import_repository' do it 'returns true when the command succeeds' do expect(Gitlab::Popen).to receive(:popen) - .with([projects_path, 'import-project', 'current/storage', 'project/path.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', "800"]).and_return([nil, 0]) + .with([projects_path, 'import-project', 'current/storage', 'project/path.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', "800"], + nil, popen_vars).and_return([nil, 0]) expect(gitlab_shell.import_repository('current/storage', 'project/path', 'https://gitlab.com/gitlab-org/gitlab-ce.git')).to be true end it 'raises an exception when the command fails' do expect(Gitlab::Popen).to receive(:popen) - .with([projects_path, 'import-project', 'current/storage', 'project/path.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', "800"]).and_return(["error", 1]) + .with([projects_path, 'import-project', 'current/storage', 'project/path.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', "800"], + nil, popen_vars).and_return(["error", 1]) expect { gitlab_shell.import_repository('current/storage', 'project/path', 'https://gitlab.com/gitlab-org/gitlab-ce.git') }.to raise_error(Gitlab::Shell::Error, "error") end -- cgit v1.2.1 From f39fe34afb4a69ebca462219abb881e243f4a955 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 29 Jun 2017 14:11:42 +0200 Subject: Add test for GitalyClient::Ref#find_ref_name --- spec/lib/gitlab/gitaly_client/ref_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index 986ae348652..b7de7e598e3 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -78,4 +78,13 @@ describe Gitlab::GitalyClient::Ref do expect { client.local_branches(sort_by: 'invalid_sort') }.to raise_error(ArgumentError) end end + + describe '#find_ref_name', seed_helper: true do + let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } + let(:client) { described_class.new(repository) } + subject { client.find_ref_name(SeedRepo::Commit::ID, 'refs/heads/master') } + + it { should be_utf8 } + it { should eq('refs/heads/master') } + end end -- cgit v1.2.1 From ec35a9e8609c3e110e025629f5058433ce06b123 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 29 Jun 2017 14:37:54 +0200 Subject: Remove unnecessary clear_stubs calls --- spec/lib/gitlab/git/repository_spec.rb | 5 ----- spec/lib/gitlab/gitaly_client/ref_spec.rb | 7 ------- 2 files changed, 12 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 9e924c2541b..f1cdd86edb9 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -5,11 +5,6 @@ describe Gitlab::Git::Repository, seed_helper: true do let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } - after do - # Prevent cached stubs (gRPC connection objects) from poisoning tests. - Gitlab::GitalyClient.clear_stubs! - end - describe "Respond to" do subject { repository } diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index b7de7e598e3..df22fcad902 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -6,13 +6,6 @@ describe Gitlab::GitalyClient::Ref do let(:relative_path) { project.path_with_namespace + '.git' } let(:client) { described_class.new(project.repository) } - after do - # When we say `expect_any_instance_of(Gitaly::Ref::Stub)` a double is created, - # and because GitalyClient shares stubs these will get passed from example to - # example, which will cause an error, so we clean the stubs after each example. - Gitlab::GitalyClient.clear_stubs! - end - describe '#branch_names' do it 'sends a find_all_branch_names message' do expect_any_instance_of(Gitaly::Ref::Stub) -- cgit v1.2.1 From 26ac691a688cb569a7345d8f31a406d467240bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chojnacki?= Date: Tue, 4 Jul 2017 15:28:34 +0000 Subject: Instrument Unicorn with Ruby exporter --- .../metrics/connection_rack_middleware_spec.rb | 88 ++++++++++++ spec/lib/gitlab/metrics/influx_sampler_spec.rb | 150 +++++++++++++++++++++ spec/lib/gitlab/metrics/sampler_spec.rb | 150 --------------------- spec/lib/gitlab/metrics/unicorn_sampler_spec.rb | 108 +++++++++++++++ 4 files changed, 346 insertions(+), 150 deletions(-) create mode 100644 spec/lib/gitlab/metrics/connection_rack_middleware_spec.rb create mode 100644 spec/lib/gitlab/metrics/influx_sampler_spec.rb delete mode 100644 spec/lib/gitlab/metrics/sampler_spec.rb create mode 100644 spec/lib/gitlab/metrics/unicorn_sampler_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/metrics/connection_rack_middleware_spec.rb b/spec/lib/gitlab/metrics/connection_rack_middleware_spec.rb new file mode 100644 index 00000000000..94251af305f --- /dev/null +++ b/spec/lib/gitlab/metrics/connection_rack_middleware_spec.rb @@ -0,0 +1,88 @@ +require 'spec_helper' + +describe Gitlab::Metrics::ConnectionRackMiddleware do + let(:app) { double('app') } + subject { described_class.new(app) } + + around do |example| + Timecop.freeze { example.run } + end + + describe '#call' do + let(:status) { 100 } + let(:env) { { 'REQUEST_METHOD' => 'GET' } } + let(:stack_result) { [status, {}, 'body'] } + + before do + allow(app).to receive(:call).and_return(stack_result) + end + + context '@app.call succeeds with 200' do + before do + allow(app).to receive(:call).and_return([200, nil, nil]) + end + + it 'increments response count with status label' do + expect(described_class).to receive_message_chain(:rack_response_count, :increment).with(include(status: 200, method: 'get')) + + subject.call(env) + end + + it 'increments requests count' do + expect(described_class).to receive_message_chain(:rack_request_count, :increment).with(method: 'get') + + subject.call(env) + end + + it 'measures execution time' do + execution_time = 10 + allow(app).to receive(:call) do |*args| + Timecop.freeze(execution_time.seconds) + end + + expect(described_class).to receive_message_chain(:rack_execution_time, :observe).with({}, execution_time) + + subject.call(env) + end + end + + context '@app.call throws exception' do + let(:rack_response_count) { double('rack_response_count') } + + before do + allow(app).to receive(:call).and_raise(StandardError) + allow(described_class).to receive(:rack_response_count).and_return(rack_response_count) + end + + it 'increments exceptions count' do + expect(described_class).to receive_message_chain(:rack_uncaught_errors_count, :increment) + + expect { subject.call(env) }.to raise_error(StandardError) + end + + it 'increments requests count' do + expect(described_class).to receive_message_chain(:rack_request_count, :increment).with(method: 'get') + + expect { subject.call(env) }.to raise_error(StandardError) + end + + it "does't increment response count" do + expect(described_class.rack_response_count).not_to receive(:increment) + + expect { subject.call(env) }.to raise_error(StandardError) + end + + it 'measures execution time' do + execution_time = 10 + allow(app).to receive(:call) do |*args| + Timecop.freeze(execution_time.seconds) + raise StandardError + end + + expect(described_class).to receive_message_chain(:rack_execution_time, :observe).with({}, execution_time) + + expect { subject.call(env) }.to raise_error(StandardError) + end + end + end +end diff --git a/spec/lib/gitlab/metrics/influx_sampler_spec.rb b/spec/lib/gitlab/metrics/influx_sampler_spec.rb new file mode 100644 index 00000000000..0bc68d64276 --- /dev/null +++ b/spec/lib/gitlab/metrics/influx_sampler_spec.rb @@ -0,0 +1,150 @@ +require 'spec_helper' + +describe Gitlab::Metrics::InfluxSampler do + let(:sampler) { described_class.new(5) } + + after do + Allocations.stop if Gitlab::Metrics.mri? + end + + describe '#start' do + it 'runs once and gathers a sample at a given interval' do + expect(sampler).to receive(:sleep).with(a_kind_of(Numeric)).twice + expect(sampler).to receive(:sample).once + expect(sampler).to receive(:running).and_return(false, true, false) + + sampler.start.join + end + end + + describe '#sample' do + it 'samples various statistics' do + expect(sampler).to receive(:sample_memory_usage) + expect(sampler).to receive(:sample_file_descriptors) + expect(sampler).to receive(:sample_objects) + expect(sampler).to receive(:sample_gc) + expect(sampler).to receive(:flush) + + sampler.sample + end + + it 'clears any GC profiles' do + expect(sampler).to receive(:flush) + expect(GC::Profiler).to receive(:clear) + + sampler.sample + end + end + + describe '#flush' do + it 'schedules the metrics using Sidekiq' do + expect(Gitlab::Metrics).to receive(:submit_metrics) + .with([an_instance_of(Hash)]) + + sampler.sample_memory_usage + sampler.flush + end + end + + describe '#sample_memory_usage' do + it 'adds a metric containing the memory usage' do + expect(Gitlab::Metrics::System).to receive(:memory_usage) + .and_return(9000) + + expect(sampler).to receive(:add_metric) + .with(/memory_usage/, value: 9000) + .and_call_original + + sampler.sample_memory_usage + end + end + + describe '#sample_file_descriptors' do + it 'adds a metric containing the amount of open file descriptors' do + expect(Gitlab::Metrics::System).to receive(:file_descriptor_count) + .and_return(4) + + expect(sampler).to receive(:add_metric) + .with(/file_descriptors/, value: 4) + .and_call_original + + sampler.sample_file_descriptors + end + end + + if Gitlab::Metrics.mri? + describe '#sample_objects' do + it 'adds a metric containing the amount of allocated objects' do + expect(sampler).to receive(:add_metric) + .with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)) + .at_least(:once) + .and_call_original + + sampler.sample_objects + end + + it 'ignores classes without a name' do + expect(Allocations).to receive(:to_hash).and_return({ Class.new => 4 }) + + expect(sampler).not_to receive(:add_metric) + .with('object_counts', an_instance_of(Hash), type: nil) + + sampler.sample_objects + end + end + end + + describe '#sample_gc' do + it 'adds a metric containing garbage collection statistics' do + expect(GC::Profiler).to receive(:total_time).and_return(0.24) + + expect(sampler).to receive(:add_metric) + .with(/gc_statistics/, an_instance_of(Hash)) + .and_call_original + + sampler.sample_gc + end + end + + describe '#add_metric' do + it 'prefixes the series name for a Rails process' do + expect(sampler).to receive(:sidekiq?).and_return(false) + + expect(Gitlab::Metrics::Metric).to receive(:new) + .with('rails_cats', { value: 10 }, {}) + .and_call_original + + sampler.add_metric('cats', value: 10) + end + + it 'prefixes the series name for a Sidekiq process' do + expect(sampler).to receive(:sidekiq?).and_return(true) + + expect(Gitlab::Metrics::Metric).to receive(:new) + .with('sidekiq_cats', { value: 10 }, {}) + .and_call_original + + sampler.add_metric('cats', value: 10) + end + end + + describe '#sleep_interval' do + it 'returns a Numeric' do + expect(sampler.sleep_interval).to be_a_kind_of(Numeric) + end + + # Testing random behaviour is very hard, so treat this test as a basic smoke + # test instead of a very accurate behaviour/unit test. + it 'does not return the same interval twice in a row' do + last = nil + + 100.times do + interval = sampler.sleep_interval + + expect(interval).not_to eq(last) + + last = interval + end + end + end +end diff --git a/spec/lib/gitlab/metrics/sampler_spec.rb b/spec/lib/gitlab/metrics/sampler_spec.rb deleted file mode 100644 index d07ce6f81af..00000000000 --- a/spec/lib/gitlab/metrics/sampler_spec.rb +++ /dev/null @@ -1,150 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Metrics::Sampler do - let(:sampler) { described_class.new(5) } - - after do - Allocations.stop if Gitlab::Metrics.mri? - end - - describe '#start' do - it 'gathers a sample at a given interval' do - expect(sampler).to receive(:sleep).with(a_kind_of(Numeric)) - expect(sampler).to receive(:sample) - expect(sampler).to receive(:loop).and_yield - - sampler.start.join - end - end - - describe '#sample' do - it 'samples various statistics' do - expect(sampler).to receive(:sample_memory_usage) - expect(sampler).to receive(:sample_file_descriptors) - expect(sampler).to receive(:sample_objects) - expect(sampler).to receive(:sample_gc) - expect(sampler).to receive(:flush) - - sampler.sample - end - - it 'clears any GC profiles' do - expect(sampler).to receive(:flush) - expect(GC::Profiler).to receive(:clear) - - sampler.sample - end - end - - describe '#flush' do - it 'schedules the metrics using Sidekiq' do - expect(Gitlab::Metrics).to receive(:submit_metrics) - .with([an_instance_of(Hash)]) - - sampler.sample_memory_usage - sampler.flush - end - end - - describe '#sample_memory_usage' do - it 'adds a metric containing the memory usage' do - expect(Gitlab::Metrics::System).to receive(:memory_usage) - .and_return(9000) - - expect(sampler).to receive(:add_metric) - .with(/memory_usage/, value: 9000) - .and_call_original - - sampler.sample_memory_usage - end - end - - describe '#sample_file_descriptors' do - it 'adds a metric containing the amount of open file descriptors' do - expect(Gitlab::Metrics::System).to receive(:file_descriptor_count) - .and_return(4) - - expect(sampler).to receive(:add_metric) - .with(/file_descriptors/, value: 4) - .and_call_original - - sampler.sample_file_descriptors - end - end - - if Gitlab::Metrics.mri? - describe '#sample_objects' do - it 'adds a metric containing the amount of allocated objects' do - expect(sampler).to receive(:add_metric) - .with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)) - .at_least(:once) - .and_call_original - - sampler.sample_objects - end - - it 'ignores classes without a name' do - expect(Allocations).to receive(:to_hash).and_return({ Class.new => 4 }) - - expect(sampler).not_to receive(:add_metric) - .with('object_counts', an_instance_of(Hash), type: nil) - - sampler.sample_objects - end - end - end - - describe '#sample_gc' do - it 'adds a metric containing garbage collection statistics' do - expect(GC::Profiler).to receive(:total_time).and_return(0.24) - - expect(sampler).to receive(:add_metric) - .with(/gc_statistics/, an_instance_of(Hash)) - .and_call_original - - sampler.sample_gc - end - end - - describe '#add_metric' do - it 'prefixes the series name for a Rails process' do - expect(sampler).to receive(:sidekiq?).and_return(false) - - expect(Gitlab::Metrics::Metric).to receive(:new) - .with('rails_cats', { value: 10 }, {}) - .and_call_original - - sampler.add_metric('cats', value: 10) - end - - it 'prefixes the series name for a Sidekiq process' do - expect(sampler).to receive(:sidekiq?).and_return(true) - - expect(Gitlab::Metrics::Metric).to receive(:new) - .with('sidekiq_cats', { value: 10 }, {}) - .and_call_original - - sampler.add_metric('cats', value: 10) - end - end - - describe '#sleep_interval' do - it 'returns a Numeric' do - expect(sampler.sleep_interval).to be_a_kind_of(Numeric) - end - - # Testing random behaviour is very hard, so treat this test as a basic smoke - # test instead of a very accurate behaviour/unit test. - it 'does not return the same interval twice in a row' do - last = nil - - 100.times do - interval = sampler.sleep_interval - - expect(interval).not_to eq(last) - - last = interval - end - end - end -end diff --git a/spec/lib/gitlab/metrics/unicorn_sampler_spec.rb b/spec/lib/gitlab/metrics/unicorn_sampler_spec.rb new file mode 100644 index 00000000000..dc0d1f2e940 --- /dev/null +++ b/spec/lib/gitlab/metrics/unicorn_sampler_spec.rb @@ -0,0 +1,108 @@ +require 'spec_helper' + +describe Gitlab::Metrics::UnicornSampler do + subject { described_class.new(1.second) } + + describe '#sample' do + let(:unicorn) { double('unicorn') } + let(:raindrops) { double('raindrops') } + let(:stats) { double('stats') } + + before do + stub_const('Unicorn', unicorn) + stub_const('Raindrops::Linux', raindrops) + allow(raindrops).to receive(:unix_listener_stats).and_return({}) + allow(raindrops).to receive(:tcp_listener_stats).and_return({}) + end + + context 'unicorn listens on unix sockets' do + let(:socket_address) { '/some/sock' } + let(:sockets) { [socket_address] } + + before do + allow(unicorn).to receive(:listener_names).and_return(sockets) + end + + it 'samples socket data' do + expect(raindrops).to receive(:unix_listener_stats).with(sockets) + + subject.sample + end + + context 'stats collected' do + before do + allow(stats).to receive(:active).and_return('active') + allow(stats).to receive(:queued).and_return('queued') + allow(raindrops).to receive(:unix_listener_stats).and_return({ socket_address => stats }) + end + + it 'updates metrics type unix and with addr' do + labels = { type: 'unix', address: socket_address } + + expect(subject).to receive_message_chain(:unicorn_active_connections, :set).with(labels, 'active') + expect(subject).to receive_message_chain(:unicorn_queued_connections, :set).with(labels, 'queued') + + subject.sample + end + end + end + + context 'unicorn listens on tcp sockets' do + let(:tcp_socket_address) { '0.0.0.0:8080' } + let(:tcp_sockets) { [tcp_socket_address] } + + before do + allow(unicorn).to receive(:listener_names).and_return(tcp_sockets) + end + + it 'samples socket data' do + expect(raindrops).to receive(:tcp_listener_stats).with(tcp_sockets) + + subject.sample + end + + context 'stats collected' do + before do + allow(stats).to receive(:active).and_return('active') + allow(stats).to receive(:queued).and_return('queued') + allow(raindrops).to receive(:tcp_listener_stats).and_return({ tcp_socket_address => stats }) + end + + it 'updates metrics type unix and with addr' do + labels = { type: 'tcp', address: tcp_socket_address } + + expect(subject).to receive_message_chain(:unicorn_active_connections, :set).with(labels, 'active') + expect(subject).to receive_message_chain(:unicorn_queued_connections, :set).with(labels, 'queued') + + subject.sample + end + end + end + end + + describe '#start' do + context 'when enabled' do + before do + allow(subject).to receive(:enabled?).and_return(true) + end + + it 'creates new thread' do + expect(Thread).to receive(:new) + + subject.start + end + end + + context 'when disabled' do + before do + allow(subject).to receive(:enabled?).and_return(false) + end + + it "doesn't create new thread" do + expect(Thread).not_to receive(:new) + + subject.start + end + end + end +end -- cgit v1.2.1 From b67d1d64cce624dfc9e99d836ebd23cbd0e21eb6 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 4 Jul 2017 15:14:13 +0200 Subject: Migrate #submodule_url_for to Gitaly --- spec/lib/gitlab/git/repository_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 0cd458bf933..aa7326721b7 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -358,6 +358,38 @@ describe Gitlab::Git::Repository, seed_helper: true do end end + describe '#submodule_url_for' do + let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } + let(:ref) { 'master' } + + def submodule_url(path) + repository.submodule_url_for(ref, path) + end + + it { expect(submodule_url('six')).to eq('git://github.com/randx/six.git') } + it { expect(submodule_url('nested/six')).to eq('git://github.com/randx/six.git') } + it { expect(submodule_url('deeper/nested/six')).to eq('git://github.com/randx/six.git') } + it { expect(submodule_url('invalid/path')).to eq(nil) } + + context 'uncommitted submodule dir' do + let(:ref) { 'fix-existing-submodule-dir' } + + it { expect(submodule_url('submodule-existing-dir')).to eq(nil) } + end + + context 'tags' do + let(:ref) { 'v1.2.1' } + + it { expect(submodule_url('six')).to eq('git://github.com/randx/six.git') } + end + + context 'no submodules at commit' do + let(:ref) { '6d39438' } + + it { expect(submodule_url('six')).to eq(nil) } + end + end + context '#submodules' do let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) } -- cgit v1.2.1 From 9f5ac179d1ca4819006c66ae385ba7153f6c7e4f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 5 Jul 2017 20:11:01 +0800 Subject: Rename ci_config_file to ci_config_path --- spec/lib/gitlab/import_export/safe_model_attributes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index f782cf533e8..697ddf52af9 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -383,7 +383,7 @@ Project: - printing_merge_request_link_enabled - build_allow_git_fetch - last_repository_updated_at -- ci_config_file +- ci_config_path Author: - name ProjectFeature: -- cgit v1.2.1 From 35f4a00f371ae60477bdbafe9f8274c8560320cb Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Tue, 27 Jun 2017 15:38:12 +0100 Subject: Introduce cache policies for CI jobs --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 9 +++-- spec/lib/gitlab/ci/config/entry/cache_spec.rb | 52 ++++++++++++++++++++------ spec/lib/gitlab/ci/config/entry/global_spec.rb | 8 ++-- spec/lib/gitlab/ci/config/entry/job_spec.rb | 4 +- 4 files changed, 52 insertions(+), 21 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 482f03aa0cc..ef58ef1b0cd 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -878,7 +878,8 @@ module Ci expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq( paths: ["logs/", "binaries/"], untracked: true, - key: 'key' + key: 'key', + policy: 'pull-push' ) end @@ -896,7 +897,8 @@ module Ci expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq( paths: ["logs/", "binaries/"], untracked: true, - key: 'key' + key: 'key', + policy: 'pull-push' ) end @@ -915,7 +917,8 @@ module Ci expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq( paths: ["test/"], untracked: false, - key: 'local' + key: 'local', + policy: 'pull-push' ) end end diff --git a/spec/lib/gitlab/ci/config/entry/cache_spec.rb b/spec/lib/gitlab/ci/config/entry/cache_spec.rb index 878b1d6b862..8f711e02f9b 100644 --- a/spec/lib/gitlab/ci/config/entry/cache_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/cache_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Entry::Cache do - let(:entry) { described_class.new(config) } + subject(:entry) { described_class.new(config) } describe 'validations' do before do @@ -9,22 +9,44 @@ describe Gitlab::Ci::Config::Entry::Cache do end context 'when entry config value is correct' do + let(:policy) { nil } + let(:config) do { key: 'some key', untracked: true, - paths: ['some/path/'] } + paths: ['some/path/'], + policy: policy } end describe '#value' do it 'returns hash value' do - expect(entry.value).to eq config + expect(entry.value).to eq(key: 'some key', untracked: true, paths: ['some/path/'], policy: 'pull-push') end end describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end + it { is_expected.to be_valid } + end + + context 'policy is pull-push' do + let(:policy) { 'pull-push' } + + it { is_expected.to be_valid } + it { expect(entry.value).to include(policy: 'pull-push') } + end + + context 'policy is push' do + let(:policy) { 'push' } + + it { is_expected.to be_valid } + it { expect(entry.value).to include(policy: 'push') } + end + + context 'policy is pull' do + let(:policy) { 'pull' } + + it { is_expected.to be_valid } + it { expect(entry.value).to include(policy: 'pull') } end context 'when key is missing' do @@ -44,12 +66,20 @@ describe Gitlab::Ci::Config::Entry::Cache do context 'when entry value is not correct' do describe '#errors' do + subject { entry.errors } context 'when is not a hash' do let(:config) { 'ls' } it 'reports errors with config value' do - expect(entry.errors) - .to include 'cache config should be a hash' + is_expected.to include 'cache config should be a hash' + end + end + + context 'when policy is unknown' do + let(:config) { { policy: "unknown" } } + + it 'reports error' do + is_expected.to include('cache policy should be pull-push, push, or pull') end end @@ -57,8 +87,7 @@ describe Gitlab::Ci::Config::Entry::Cache do let(:config) { { key: 1 } } it 'reports error with descendants' do - expect(entry.errors) - .to include 'key config should be a string or symbol' + is_expected.to include 'key config should be a string or symbol' end end @@ -66,8 +95,7 @@ describe Gitlab::Ci::Config::Entry::Cache do let(:config) { { invalid: true } } it 'reports error with descendants' do - expect(entry.errors) - .to include 'cache config contains unknown keys: invalid' + is_expected.to include 'cache config contains unknown keys: invalid' end end end diff --git a/spec/lib/gitlab/ci/config/entry/global_spec.rb b/spec/lib/gitlab/ci/config/entry/global_spec.rb index 293f112b2b0..1860ed79bfd 100644 --- a/spec/lib/gitlab/ci/config/entry/global_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/global_spec.rb @@ -143,7 +143,7 @@ describe Gitlab::Ci::Config::Entry::Global do describe '#cache_value' do it 'returns cache configuration' do expect(global.cache_value) - .to eq(key: 'k', untracked: true, paths: ['public/']) + .to eq(key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push') end end @@ -157,7 +157,7 @@ describe Gitlab::Ci::Config::Entry::Global do image: { name: 'ruby:2.2' }, services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }], stage: 'test', - cache: { key: 'k', untracked: true, paths: ['public/'] }, + cache: { key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push' }, variables: { 'VAR' => 'value' }, ignore: false, after_script: ['make clean'] }, @@ -168,7 +168,7 @@ describe Gitlab::Ci::Config::Entry::Global do image: { name: 'ruby:2.2' }, services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }], stage: 'test', - cache: { key: 'k', untracked: true, paths: ['public/'] }, + cache: { key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push' }, variables: {}, ignore: false, after_script: ['make clean'] } @@ -212,7 +212,7 @@ describe Gitlab::Ci::Config::Entry::Global do describe '#cache_value' do it 'returns correct cache definition' do - expect(global.cache_value).to eq(key: 'a') + expect(global.cache_value).to eq(key: 'a', policy: 'pull-push') end end end diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 92cba689f47..c5cad887b64 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -109,7 +109,7 @@ describe Gitlab::Ci::Config::Entry::Job do it 'overrides global config' do expect(entry[:image].value).to eq(name: 'some_image') - expect(entry[:cache].value).to eq(key: 'test') + expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push') end end @@ -123,7 +123,7 @@ describe Gitlab::Ci::Config::Entry::Job do it 'uses config from global entry' do expect(entry[:image].value).to eq 'specified' - expect(entry[:cache].value).to eq(key: 'test') + expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push') end end end -- cgit v1.2.1 From d1e0b1b3a8404f3a7b54db09c46fb614ca3fcb93 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Mon, 3 Jul 2017 13:55:43 +0100 Subject: Allow creation of files and directories with spaces in web UI --- spec/lib/gitlab/git/index_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/index_spec.rb b/spec/lib/gitlab/git/index_spec.rb index 21b71654251..8d63f81e4fd 100644 --- a/spec/lib/gitlab/git/index_spec.rb +++ b/spec/lib/gitlab/git/index_spec.rb @@ -25,6 +25,16 @@ describe Gitlab::Git::Index, seed_helper: true do expect(entry).not_to be_nil expect(repository.lookup(entry[:oid]).content).to eq(options[:content]) end + + it 'creates the file if file_path has spaces in between words' do + options[:file_path] = 'new file.txt' + + index.create(options) + entry = index.get(options[:file_path]) + + expect(entry).not_to be_nil + expect(repository.lookup(entry[:oid]).content).to eq(options[:content]) + end end context 'when a file at that path exists' do @@ -81,6 +91,15 @@ describe Gitlab::Git::Index, seed_helper: true do expect(entry).not_to be_nil end + + it 'creates the dir if it has spaces in between words' do + options[:file_path] = 'new dir' + + index.create_dir(options) + entry = index.get(options[:file_path] + '/.gitkeep') + + expect(entry).not_to be_nil + end end context 'when a file at that path exists' do -- cgit v1.2.1 From fe13f110412d85c05dc68e5ee1db499f681bf722 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 29 Jun 2017 12:06:35 -0500 Subject: Create and use project path helpers that only need a project, no namespace --- .../filter/commit_range_reference_filter_spec.rb | 14 ++--- .../banzai/filter/commit_reference_filter_spec.rb | 8 +-- .../banzai/filter/label_reference_filter_spec.rb | 62 +++++++++------------- .../filter/merge_request_reference_filter_spec.rb | 15 +++--- .../filter/milestone_reference_filter_spec.rb | 22 +++----- .../banzai/filter/snippet_reference_filter_spec.rb | 14 ++--- .../banzai/filter/user_reference_filter_spec.rb | 2 +- spec/lib/banzai/pipeline/gfm_pipeline_spec.rb | 6 +-- spec/lib/gitlab/closing_issue_extractor_spec.rb | 8 +-- 9 files changed, 62 insertions(+), 89 deletions(-) (limited to 'spec/lib') 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 fc67c7ec3c4..60c27bc0d3c 100644 --- a/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb @@ -29,14 +29,14 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do doc = reference_filter("See #{reference2}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_compare_url(project.namespace, project, range2.to_param) + .to eq urls.project_compare_url(project, range2.to_param) end it 'links to a valid three-dot reference' do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_compare_url(project.namespace, project, range.to_param) + .to eq urls.project_compare_url(project, range.to_param) end it 'links to a valid short ID' do @@ -94,7 +94,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls.namespace_project_compare_url(project.namespace, project, from: commit1.id, to: commit2.id, only_path: true) + expect(link).to eq urls.project_compare_url(project, from: commit1.id, to: commit2.id, only_path: true) end end @@ -106,7 +106,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) + .to eq urls.project_compare_url(project2, range.to_param) end it 'link has valid text' do @@ -141,7 +141,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) + .to eq urls.project_compare_url(project2, range.to_param) end it 'link has valid text' do @@ -176,7 +176,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_compare_url(project2.namespace, project2, range.to_param) + .to eq urls.project_compare_url(project2, range.to_param) end it 'link has valid text' do @@ -205,7 +205,7 @@ describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:range) { CommitRange.new("#{commit1.id}...master", project) } - let(:reference) { urls.namespace_project_compare_url(project2.namespace, project2, from: commit1.id, to: 'master') } + let(:reference) { urls.project_compare_url(project2, from: commit1.id, to: 'master') } before do range.project = project2 diff --git a/spec/lib/banzai/filter/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_reference_filter_spec.rb index c4d8d3b6682..f6893641481 100644 --- a/spec/lib/banzai/filter/commit_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_reference_filter_spec.rb @@ -27,7 +27,7 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do expect(doc.css('a').first.text).to eq commit.short_id expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_commit_url(project.namespace, project, reference) + .to eq urls.project_commit_url(project, reference) end end @@ -90,7 +90,7 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls.namespace_project_commit_url(project.namespace, project, reference, only_path: true) + expect(link).to eq urls.project_commit_url(project, reference, only_path: true) end end @@ -175,13 +175,13 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do let(:namespace) { create(:namespace) } let(:project2) { create(:project, :public, :repository, namespace: namespace) } let(:commit) { project2.commit } - let(:reference) { urls.namespace_project_commit_url(project2.namespace, project2, commit.id) } + let(:reference) { urls.project_commit_url(project2, commit.id) } it 'links to a valid reference' do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_commit_url(project2.namespace, project2, commit.id) + .to eq urls.project_commit_url(project2, commit.id) end it 'links with adjacent text' do diff --git a/spec/lib/banzai/filter/label_reference_filter_spec.rb b/spec/lib/banzai/filter/label_reference_filter_spec.rb index cb3cf982351..8daef3ca691 100644 --- a/spec/lib/banzai/filter/label_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb @@ -45,7 +45,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls.namespace_project_issues_path(project.namespace, project, label_name: label.name) + expect(link).to eq urls.project_issues_path(project, label_name: label.name) end context 'project that does not exist referenced' do @@ -73,7 +73,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) end it 'links with adjacent text' do @@ -96,7 +96,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) expect(doc.text).to eq 'See gfm' end @@ -120,7 +120,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) expect(doc.text).to eq 'See 2fa' end @@ -144,7 +144,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) expect(doc.text).to eq 'See ?g.fm&' end @@ -169,7 +169,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) expect(doc.text).to eq 'See gfm references' end @@ -193,7 +193,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) expect(doc.text).to eq 'See 2 factor authentication' end @@ -217,7 +217,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) expect(doc.text).to eq 'See g.fm & references?' end @@ -250,9 +250,9 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{references}") expect(doc.css('a').map { |a| a.attr('href') }).to match_array([ - urls.namespace_project_issues_url(project.namespace, project, label_name: bug.name), - urls.namespace_project_issues_url(project.namespace, project, label_name: feature_proposal.name), - urls.namespace_project_issues_url(project.namespace, project, label_name: technical_debt.name) + 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) ]) expect(doc.text).to eq 'See bug, feature proposal, technical debt' end @@ -265,9 +265,9 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{references}") expect(doc.css('a').map { |a| a.attr('href') }).to match_array([ - urls.namespace_project_issues_url(project.namespace, project, label_name: bug.name), - urls.namespace_project_issues_url(project.namespace, project, label_name: feature_proposal.name), - urls.namespace_project_issues_url(project.namespace, project, label_name: technical_debt.name) + 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) ]) expect(doc.text).to eq 'See bug feature proposal technical debt' end @@ -288,7 +288,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: label.name) + .project_issues_url(project, label_name: label.name) end it 'links with adjacent text' do @@ -325,7 +325,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}", project: project) expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: group_label.name) + .project_issues_url(project, label_name: group_label.name) expect(doc.text).to eq 'See gfm references' end @@ -348,7 +348,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do doc = reference_filter("See #{reference}", project: project) expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_issues_url(project.namespace, project, label_name: group_label.name) + .project_issues_url(project, label_name: group_label.name) expect(doc.text).to eq "See gfm references" end @@ -373,9 +373,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(project2.namespace, - project2, - label_name: label.name) + .to eq urls.project_issues_url(project2, label_name: label.name) end it 'has valid color' do @@ -407,9 +405,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(project2.namespace, - project2, - label_name: label.name) + .to eq urls.project_issues_url(project2, label_name: label.name) end it 'has valid color' do @@ -441,9 +437,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'links to a valid reference' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(project2.namespace, - project2, - label_name: label.name) + .to eq urls.project_issues_url(project2, label_name: label.name) end it 'has valid color' do @@ -477,9 +471,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'points to referenced project issues page' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(another_project.namespace, - another_project, - label_name: group_label.name) + .to eq urls.project_issues_url(another_project, label_name: group_label.name) end it 'has valid color' do @@ -514,9 +506,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'points to referenced project issues page' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(another_project.namespace, - another_project, - label_name: group_label.name) + .to eq urls.project_issues_url(another_project, label_name: group_label.name) end it 'has valid color' do @@ -550,9 +540,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'points to referenced project issues page' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(project.namespace, - project, - label_name: group_label.name) + .to eq urls.project_issues_url(project, label_name: group_label.name) end it 'has valid color' do @@ -584,9 +572,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do it 'points to referenced project issues page' do expect(result.css('a').first.attr('href')) - .to eq urls.namespace_project_issues_url(project.namespace, - project, - label_name: group_label.name) + .to eq urls.project_issues_url(project, label_name: group_label.name) end it 'has valid color' do 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 cd91681551e..1ad329b6452 100644 --- a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb @@ -37,7 +37,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_merge_request_url(project.namespace, project, merge) + .project_merge_request_url(project, merge) end it 'links with adjacent text' do @@ -95,7 +95,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls.namespace_project_merge_request_url(project.namespace, project, merge, only_path: true) + expect(link).to eq urls.project_merge_request_url(project, merge, only_path: true) end end @@ -108,8 +108,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_merge_request_url(project2.namespace, - project2, merge) + .to eq urls.project_merge_request_url(project2, merge) end it 'link has valid text' do @@ -142,8 +141,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_merge_request_url(project2.namespace, - project2, merge) + .to eq urls.project_merge_request_url(project2, merge) end it 'link has valid text' do @@ -176,8 +174,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_merge_request_url(project2.namespace, - project2, merge) + .to eq urls.project_merge_request_url(project2, merge) end it 'link has valid text' do @@ -203,7 +200,7 @@ describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do let(:namespace) { create(:namespace, name: 'cross-reference') } let(:project2) { create(:empty_project, :public, namespace: namespace) } let(:merge) { create(:merge_request, source_project: project2, target_project: project2) } - let(:reference) { urls.namespace_project_merge_request_url(project2.namespace, project2, merge) + '/diffs#note_123' } + let(:reference) { urls.project_merge_request_url(project2, merge) + '/diffs#note_123' } it 'links to a valid reference' do doc = reference_filter("See #{reference}") diff --git a/spec/lib/banzai/filter/milestone_reference_filter_spec.rb b/spec/lib/banzai/filter/milestone_reference_filter_spec.rb index fe88b9cb73e..7fab5613afc 100644 --- a/spec/lib/banzai/filter/milestone_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/milestone_reference_filter_spec.rb @@ -45,7 +45,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do expect(link).not_to match %r(https?://) expect(link).to eq urls - .namespace_project_milestone_path(project.namespace, project, milestone) + .project_milestone_path(project, milestone) end context 'Integer-based references' do @@ -53,7 +53,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(project.namespace, project, milestone) + .project_milestone_url(project, milestone) end it 'links with adjacent text' do @@ -76,7 +76,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(project.namespace, project, milestone) + .project_milestone_url(project, milestone) expect(doc.text).to eq 'See gfm' end @@ -100,7 +100,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(project.namespace, project, milestone) + .project_milestone_url(project, milestone) expect(doc.text).to eq 'See gfm references' end @@ -123,7 +123,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(project.namespace, project, milestone) + .project_milestone_url(project, milestone) end it 'links with adjacent text' do @@ -157,9 +157,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'points to referenced project milestone page' do expect(result.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(another_project.namespace, - another_project, - milestone) + .project_milestone_url(another_project, milestone) end it 'link has valid text' do @@ -196,9 +194,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'points to referenced project milestone page' do expect(result.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(another_project.namespace, - another_project, - milestone) + .project_milestone_url(another_project, milestone) end it 'link has valid text' do @@ -235,9 +231,7 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do it 'points to referenced project milestone page' do expect(result.css('a').first.attr('href')).to eq urls - .namespace_project_milestone_url(another_project.namespace, - another_project, - milestone) + .project_milestone_url(another_project, milestone) end it 'link has valid text' do diff --git a/spec/lib/banzai/filter/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb index e851120bc3a..9704db0c221 100644 --- a/spec/lib/banzai/filter/snippet_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb @@ -23,7 +23,7 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')).to eq urls - .namespace_project_snippet_url(project.namespace, project, snippet) + .project_snippet_url(project, snippet) end it 'links with adjacent text' do @@ -75,7 +75,7 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls.namespace_project_snippet_url(project.namespace, project, snippet, only_path: true) + expect(link).to eq urls.project_snippet_url(project, snippet, only_path: true) end end @@ -89,7 +89,7 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + .to eq urls.project_snippet_url(project2, snippet) end it 'link has valid text' do @@ -122,7 +122,7 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + .to eq urls.project_snippet_url(project2, snippet) end it 'link has valid text' do @@ -155,7 +155,7 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + .to eq urls.project_snippet_url(project2, snippet) end it 'link has valid text' do @@ -181,13 +181,13 @@ describe Banzai::Filter::SnippetReferenceFilter, lib: true do let(:namespace) { create(:namespace, name: 'cross-reference') } let(:project2) { create(:empty_project, :public, namespace: namespace) } let(:snippet) { create(:project_snippet, project: project2) } - let(:reference) { urls.namespace_project_snippet_url(project2.namespace, project2, snippet) } + let(:reference) { urls.project_snippet_url(project2, snippet) } it 'links to a valid reference' do doc = reference_filter("See #{reference}") expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet) + .to eq urls.project_snippet_url(project2, snippet) end it 'links with adjacent text' do diff --git a/spec/lib/banzai/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb index edf3846b742..77561e00573 100644 --- a/spec/lib/banzai/filter/user_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb @@ -43,7 +43,7 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do expect(doc.css('a').length).to eq 1 expect(doc.css('a').first.attr('href')) - .to eq urls.namespace_project_url(project.namespace, project) + .to eq urls.project_url(project) end it 'includes a data-author attribute when there is an author' do diff --git a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb index 2b8c76f2bb8..1eb90dc1847 100644 --- a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb @@ -22,11 +22,7 @@ describe Banzai::Pipeline::GfmPipeline do link = result.css('a').first expect(link['href']).to eq( - Gitlab::Routing.url_helpers.namespace_project_issue_path( - other_project.namespace, - other_project, - issue - ) + Gitlab::Routing.url_helpers.project_issue_path(other_project, issue) ) end end diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb index ca68010cb89..fe988266ae3 100644 --- a/spec/lib/gitlab/closing_issue_extractor_spec.rb +++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb @@ -276,7 +276,7 @@ describe Gitlab::ClosingIssueExtractor, lib: true do context "with a cross-project URL" do it do - message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)}" + message = "Closes #{urls.project_issue_url(issue2.project, issue2)}" expect(subject.closed_by_message(message)).to eq([issue2]) end end @@ -292,7 +292,7 @@ describe Gitlab::ClosingIssueExtractor, lib: true do context "with an invalid URL" do it do - message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)}" + message = "Closes https://google.com#{urls.project_issue_path(issue2.project, issue2)}" expect(subject.closed_by_message(message)).to eq([]) end end @@ -347,14 +347,14 @@ describe Gitlab::ClosingIssueExtractor, lib: true do end it "fetches cross-project URL references" do - message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)} and #{reference}" + message = "Closes #{urls.project_issue_url(issue2.project, issue2)} and #{reference}" expect(subject.closed_by_message(message)) .to match_array([issue, issue2]) end it "ignores invalid cross-project URL references" do - message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)} and #{reference}" + message = "Closes https://google.com#{urls.project_issue_path(issue2.project, issue2)} and #{reference}" expect(subject.closed_by_message(message)) .to match_array([issue]) -- cgit v1.2.1 From 1207d451ed934f3ce2d8c02130a8e6b2cac88a70 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Wed, 5 Jul 2017 17:01:38 +0100 Subject: Removes file_name_regex from Gitlab::Regex --- spec/lib/gitlab/git/index_spec.rb | 19 ------------------- spec/lib/gitlab/regex_spec.rb | 6 ------ 2 files changed, 25 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git/index_spec.rb b/spec/lib/gitlab/git/index_spec.rb index 8d63f81e4fd..21b71654251 100644 --- a/spec/lib/gitlab/git/index_spec.rb +++ b/spec/lib/gitlab/git/index_spec.rb @@ -25,16 +25,6 @@ describe Gitlab::Git::Index, seed_helper: true do expect(entry).not_to be_nil expect(repository.lookup(entry[:oid]).content).to eq(options[:content]) end - - it 'creates the file if file_path has spaces in between words' do - options[:file_path] = 'new file.txt' - - index.create(options) - entry = index.get(options[:file_path]) - - expect(entry).not_to be_nil - expect(repository.lookup(entry[:oid]).content).to eq(options[:content]) - end end context 'when a file at that path exists' do @@ -91,15 +81,6 @@ describe Gitlab::Git::Index, seed_helper: true do expect(entry).not_to be_nil end - - it 'creates the dir if it has spaces in between words' do - options[:file_path] = 'new dir' - - index.create_dir(options) - entry = index.get(options[:file_path] + '/.gitkeep') - - expect(entry).not_to be_nil - end end context 'when a file at that path exists' do diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb index 979f4fefcb6..51e2c3c38c6 100644 --- a/spec/lib/gitlab/regex_spec.rb +++ b/spec/lib/gitlab/regex_spec.rb @@ -14,12 +14,6 @@ describe Gitlab::Regex, lib: true do it { is_expected.not_to match('?gitlab') } end - describe '.file_name_regex' do - subject { described_class.file_name_regex } - - it { is_expected.to match('foo@bar') } - end - describe '.environment_slug_regex' do subject { described_class.environment_name_regex } -- cgit v1.2.1 From 49c121e31aef127c5f04a0c197899a4cb15fa39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 5 Jul 2017 22:12:10 +0200 Subject: Fix Rubocop offense MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/lib/gitlab/gitaly_client/ref_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/gitaly_client/ref_spec.rb b/spec/lib/gitlab/gitaly_client/ref_spec.rb index df22fcad902..7c090460764 100644 --- a/spec/lib/gitlab/gitaly_client/ref_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_spec.rb @@ -77,7 +77,7 @@ describe Gitlab::GitalyClient::Ref do let(:client) { described_class.new(repository) } subject { client.find_ref_name(SeedRepo::Commit::ID, 'refs/heads/master') } - it { should be_utf8 } - it { should eq('refs/heads/master') } + it { is_expected.to be_utf8 } + it { is_expected.to eq('refs/heads/master') } end end -- cgit v1.2.1