diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-03 18:06:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-03 18:06:20 +0300 |
commit | 4204cf308596e0e26f578a6e2da88f49c0f4aad9 (patch) | |
tree | 644447bcb576a459e079318b06712b7c89416e2b /spec | |
parent | cd4cb29b2c304f00d238ee72fe40c767cb3e2675 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/oauth_openid_requests.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/data_builder/pipeline_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/grafana_embed_usage_data_spec.rb | 70 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/oauth_access_grant_spec.rb | 17 |
5 files changed, 100 insertions, 0 deletions
diff --git a/spec/factories/oauth_openid_requests.rb b/spec/factories/oauth_openid_requests.rb new file mode 100644 index 00000000000..82d89b5c8ca --- /dev/null +++ b/spec/factories/oauth_openid_requests.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :oauth_openid_request, class: 'Doorkeeper::OpenidConnect::Request' do + access_grant factory: :oauth_access_grant + sequence(:nonce) { |n| n.to_s } + end +end diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb index 931477d19c2..635bf56b72e 100644 --- a/spec/lib/gitlab/data_builder/pipeline_spec.rb +++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb @@ -34,6 +34,7 @@ describe Gitlab::DataBuilder::Pipeline do expect(build_data).to be_a(Hash) expect(build_data[:id]).to eq(build.id) expect(build_data[:status]).to eq(build.status) + expect(build_data[:allow_failure]).to eq(build.allow_failure) expect(project_data).to eq(project.hook_attrs(backward: false)) expect(data[:merge_request]).to be_nil end diff --git a/spec/lib/gitlab/grafana_embed_usage_data_spec.rb b/spec/lib/gitlab/grafana_embed_usage_data_spec.rb new file mode 100644 index 00000000000..162db46719b --- /dev/null +++ b/spec/lib/gitlab/grafana_embed_usage_data_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::GrafanaEmbedUsageData do + describe '#issue_count' do + subject { described_class.issue_count } + + let(:project) { create(:project) } + let(:description_with_embed) { "Some comment\n\nhttps://grafana.example.com/d/xvAk4q0Wk/go-processes?orgId=1&from=1573238522762&to=1573240322762&var-job=prometheus&var-interval=10m&panelId=1&fullscreen" } + let(:description_with_unintegrated_embed) { "Some comment\n\nhttps://grafana.exp.com/d/xvAk4q0Wk/go-processes?orgId=1&from=1573238522762&to=1573240322762&var-job=prometheus&var-interval=10m&panelId=1&fullscreen" } + let(:description_with_non_grafana_inline_metric) { "Some comment\n\n#{Gitlab::Routing.url_helpers.metrics_namespace_project_environment_url(*['foo', 'bar', 12])}" } + + shared_examples "zero count" do + it "does not count the issue" do + expect(subject).to eq(0) + end + end + + context 'with project grafana integration enabled' do + before do + create(:grafana_integration, project: project, enabled: true) + end + + context 'with valid and invalid embeds' do + before do + # Valid + create(:issue, project: project, description: description_with_embed) + create(:issue, project: project, description: description_with_embed) + # In-Valid + create(:issue, project: project, description: description_with_unintegrated_embed) + create(:issue, project: project, description: description_with_non_grafana_inline_metric) + create(:issue, project: project, description: nil) + create(:issue, project: project, description: '') + create(:issue, project: project) + end + + it 'counts only the issues with embeds' do + expect(subject).to eq(2) + end + end + end + + context 'with project grafana integration disabled' do + before do + create(:grafana_integration, project: project, enabled: false) + end + + context 'with one issue having a grafana link in the description and one without' do + before do + create(:issue, project: project, description: description_with_embed) + create(:issue, project: project) + end + + it_behaves_like('zero count') + end + end + + context 'with an un-integrated project' do + context 'with one issue having a grafana link in the description and one without' do + before do + create(:issue, project: project, description: description_with_embed) + create(:issue, project: project) + end + + it_behaves_like('zero count') + end + end + end +end diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 484684eeb65..713ddca6c2b 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -53,6 +53,8 @@ describe Gitlab::UsageData do create(:grafana_integration, project: projects[1], enabled: true) create(:grafana_integration, project: projects[2], enabled: false) + allow(Gitlab::GrafanaEmbedUsageData).to receive(:issue_count).and_return(2) + ProjectFeature.first.update_attribute('repository_access_level', 0) end @@ -152,6 +154,7 @@ describe Gitlab::UsageData do issues issues_with_associated_zoom_link issues_using_zoom_quick_actions + issues_with_embedded_grafana_charts_approx keys label_lists labels @@ -211,6 +214,7 @@ describe Gitlab::UsageData do expect(count_data[:projects_with_error_tracking_enabled]).to eq(1) expect(count_data[:issues_with_associated_zoom_link]).to eq(2) expect(count_data[:issues_using_zoom_quick_actions]).to eq(3) + expect(count_data[:issues_with_embedded_grafana_charts_approx]).to eq(2) expect(count_data[:clusters_enabled]).to eq(4) expect(count_data[:project_clusters_enabled]).to eq(3) diff --git a/spec/models/oauth_access_grant_spec.rb b/spec/models/oauth_access_grant_spec.rb new file mode 100644 index 00000000000..955dae906f3 --- /dev/null +++ b/spec/models/oauth_access_grant_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe OauthAccessGrant do + let(:user) { create(:user) } + let(:application) { create(:oauth_application, owner: user) } + + describe '#delete' do + it 'cascades to oauth_openid_requests' do + access_grant = create(:oauth_access_grant, application: application) + create(:oauth_openid_request, access_grant: access_grant) + + expect { access_grant.delete }.to change(Doorkeeper::OpenidConnect::Request, :count).by(-1) + end + end +end |