Commit a18b8ba9 authored by Max Woolf's avatar Max Woolf

Merge branch 'pl-error-tracking-project-settings-specs-rubocop' into 'master'

Fix RuboCop offenses in error tracking project setting specs

See merge request gitlab-org/gitlab!83994
parents 4db6fec3 f4144267
...@@ -878,7 +878,6 @@ RSpec/VerifiedDoubles: ...@@ -878,7 +878,6 @@ RSpec/VerifiedDoubles:
- spec/models/design_management/design_at_version_spec.rb - spec/models/design_management/design_at_version_spec.rb
- spec/models/diff_viewer/image_spec.rb - spec/models/diff_viewer/image_spec.rb
- spec/models/environment_spec.rb - spec/models/environment_spec.rb
- spec/models/error_tracking/project_error_tracking_setting_spec.rb
- spec/models/event_spec.rb - spec/models/event_spec.rb
- spec/models/external_issue_spec.rb - spec/models/external_issue_spec.rb
- spec/models/hooks/web_hook_spec.rb - spec/models/hooks/web_hook_spec.rb
......
...@@ -135,7 +135,7 @@ module ErrorTracking ...@@ -135,7 +135,7 @@ module ErrorTracking
end end
end end
def update_issue(opts = {} ) def update_issue(opts = {})
handle_exceptions do handle_exceptions do
{ updated: sentry_client.update_issue(opts) } { updated: sentry_client.update_issue(opts) }
end end
......
...@@ -8,6 +8,8 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -8,6 +8,8 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:sentry_client) { instance_double(ErrorTracking::SentryClient) }
subject(:setting) { build(:project_error_tracking_setting, project: project) } subject(:setting) { build(:project_error_tracking_setting, project: project) }
describe 'Associations' do describe 'Associations' do
...@@ -48,7 +50,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -48,7 +50,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
expect(subject.errors.messages[:project]).to include('is a required field') expect(subject.errors.messages[:project]).to include('is a required field')
end end
context 'presence validations' do describe 'presence validations' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
valid_api_url = 'http://example.com/api/0/projects/org-slug/proj-slug/' valid_api_url = 'http://example.com/api/0/projects/org-slug/proj-slug/'
...@@ -83,12 +85,12 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -83,12 +85,12 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
describe 'after_save :create_client_key!' do describe 'after_save :create_client_key!' do
subject { build(:project_error_tracking_setting, :integrated, project: project) } subject { build(:project_error_tracking_setting, :integrated, project: project) }
context 'no client key yet' do context 'without client key' do
it 'creates a new client key' do it 'creates a new client key' do
expect { subject.save! }.to change { ErrorTracking::ClientKey.count }.by(1) expect { subject.save! }.to change { ErrorTracking::ClientKey.count }.by(1)
end end
context 'sentry backend' do context 'with sentry backend' do
before do before do
subject.integrated = false subject.integrated = false
end end
...@@ -98,7 +100,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -98,7 +100,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
end end
context 'feature disabled' do context 'when feature disabled' do
before do before do
subject.enabled = false subject.enabled = false
end end
...@@ -109,7 +111,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -109,7 +111,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
end end
context 'client key already exists' do context 'when client key already exists' do
let!(:client_key) { create(:error_tracking_client_key, project: project) } let!(:client_key) { create(:error_tracking_client_key, project: project) }
it 'does not create a new client key' do it 'does not create a new client key' do
...@@ -122,13 +124,13 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -122,13 +124,13 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
describe '.extract_sentry_external_url' do describe '.extract_sentry_external_url' do
subject { described_class.extract_sentry_external_url(sentry_url) } subject { described_class.extract_sentry_external_url(sentry_url) }
describe 'when passing a URL' do context 'when passing a URL' do
let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' } let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' }
it { is_expected.to eq('https://sentrytest.gitlab.com/sentry-org/sentry-project') } it { is_expected.to eq('https://sentrytest.gitlab.com/sentry-org/sentry-project') }
end end
describe 'when passing nil' do context 'when passing nil' do
let(:sentry_url) { nil } let(:sentry_url) { nil }
it { is_expected.to be_nil } it { is_expected.to be_nil }
...@@ -159,23 +161,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -159,23 +161,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
describe '#list_sentry_issues' do describe '#list_sentry_issues' do
let(:issues) { [:list, :of, :issues] } let(:issues) { [:list, :of, :issues] }
let(:result) { subject.list_sentry_issues(**opts) }
let(:opts) do let(:opts) { { issue_status: 'unresolved', limit: 10 } }
{ issue_status: 'unresolved', limit: 10 }
end
let(:result) do
subject.list_sentry_issues(**opts)
end
context 'when cached' do context 'when cached' do
let(:sentry_client) { spy(:sentry_client) }
before do before do
stub_reactive_cache(subject, issues, opts) stub_reactive_cache(subject, issues, opts)
synchronous_reactive_cache(subject) synchronous_reactive_cache(subject)
expect(subject).to receive(:sentry_client).and_return(sentry_client) allow(subject).to receive(:sentry_client).and_return(sentry_client)
end end
it 'returns cached issues' do it 'returns cached issues' do
...@@ -195,8 +189,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -195,8 +189,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
context 'when sentry client raises ErrorTracking::SentryClient::Error' do context 'when sentry client raises ErrorTracking::SentryClient::Error' do
let(:sentry_client) { spy(:sentry_client) }
before do before do
synchronous_reactive_cache(subject) synchronous_reactive_cache(subject)
...@@ -214,14 +206,13 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -214,14 +206,13 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
context 'when sentry client raises ErrorTracking::SentryClient::MissingKeysError' do context 'when sentry client raises ErrorTracking::SentryClient::MissingKeysError' do
let(:sentry_client) { spy(:sentry_client) }
before do before do
synchronous_reactive_cache(subject) synchronous_reactive_cache(subject)
allow(subject).to receive(:sentry_client).and_return(sentry_client) allow(subject).to receive(:sentry_client).and_return(sentry_client)
allow(sentry_client).to receive(:list_issues).with(opts) allow(sentry_client).to receive(:list_issues).with(opts)
.and_raise(ErrorTracking::SentryClient::MissingKeysError, 'Sentry API response is missing keys. key not found: "id"') .and_raise(ErrorTracking::SentryClient::MissingKeysError,
'Sentry API response is missing keys. key not found: "id"')
end end
it 'returns error' do it 'returns error' do
...@@ -233,8 +224,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -233,8 +224,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
context 'when sentry client raises ErrorTracking::SentryClient::ResponseInvalidSizeError' do context 'when sentry client raises ErrorTracking::SentryClient::ResponseInvalidSizeError' do
let(:sentry_client) { spy(:sentry_client) } let(:error_msg) { "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}." }
let(:error_msg) {"Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."}
before do before do
synchronous_reactive_cache(subject) synchronous_reactive_cache(subject)
...@@ -253,8 +243,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -253,8 +243,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
context 'when sentry client raises StandardError' do context 'when sentry client raises StandardError' do
let(:sentry_client) { spy(:sentry_client) }
before do before do
synchronous_reactive_cache(subject) synchronous_reactive_cache(subject)
...@@ -270,7 +258,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -270,7 +258,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
describe '#list_sentry_projects' do describe '#list_sentry_projects' do
let(:projects) { [:list, :of, :projects] } let(:projects) { [:list, :of, :projects] }
let(:sentry_client) { spy(:sentry_client) }
it 'calls sentry client' do it 'calls sentry client' do
expect(subject).to receive(:sentry_client).and_return(sentry_client) expect(subject).to receive(:sentry_client).and_return(sentry_client)
...@@ -284,19 +271,17 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -284,19 +271,17 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
describe '#issue_details' do describe '#issue_details' do
let(:issue) { build(:error_tracking_sentry_detailed_error) } let(:issue) { build(:error_tracking_sentry_detailed_error) }
let(:sentry_client) { double('sentry_client', issue_details: issue) }
let(:commit_id) { issue.first_release_version } let(:commit_id) { issue.first_release_version }
let(:result) { subject.issue_details(opts) }
let(:result) do let(:opts) { { issue_id: 1 } }
subject.issue_details
end
context 'when cached' do context 'when cached' do
before do before do
stub_reactive_cache(subject, issue, {}) stub_reactive_cache(subject, issue, {})
synchronous_reactive_cache(subject) synchronous_reactive_cache(subject)
expect(subject).to receive(:sentry_client).and_return(sentry_client) allow(subject).to receive(:sentry_client).and_return(sentry_client)
allow(sentry_client).to receive(:issue_details).with(opts).and_return(issue)
end end
it { expect(result).to eq(issue: issue) } it { expect(result).to eq(issue: issue) }
...@@ -314,15 +299,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -314,15 +299,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
context 'when repo commit matches first relase version' do context 'when repo commit matches first relase version' do
let(:commit) { double('commit', id: commit_id) } let(:commit) { instance_double(Commit, id: commit_id) }
let(:repository) { double('repository', commit: commit) } let(:repository) { instance_double(Repository, commit: commit) }
before do before do
expect(project).to receive(:repository).and_return(repository) allow(project).to receive(:repository).and_return(repository)
end end
it { expect(result[:issue].gitlab_commit).to eq(commit_id) } it { expect(result[:issue].gitlab_commit).to eq(commit_id) }
it { expect(result[:issue].gitlab_commit_path).to eq("/#{project.namespace.path}/#{project.path}/-/commit/#{commit_id}") } it { expect(result[:issue].gitlab_commit_path).to eq(project_commit_path(project, commit_id)) }
end end
end end
...@@ -333,19 +318,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -333,19 +318,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
describe '#update_issue' do describe '#update_issue' do
let(:opts) do let(:result) { subject.update_issue(**opts) }
{ status: 'resolved' } let(:opts) { { issue_id: 1, params: {} } }
end
let(:result) do before do
subject.update_issue(**opts) allow(subject).to receive(:sentry_client).and_return(sentry_client)
end end
let(:sentry_client) { spy(:sentry_client) } context 'when sentry response is successful' do
context 'successful call to sentry' do
before do before do
allow(subject).to receive(:sentry_client).and_return(sentry_client)
allow(sentry_client).to receive(:update_issue).with(opts).and_return(true) allow(sentry_client).to receive(:update_issue).with(opts).and_return(true)
end end
...@@ -354,9 +335,8 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -354,9 +335,8 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
end end
context 'sentry raises an error' do context 'when sentry raises an error' do
before do before do
allow(subject).to receive(:sentry_client).and_return(sentry_client)
allow(sentry_client).to receive(:update_issue).with(opts).and_raise(StandardError) allow(sentry_client).to receive(:update_issue).with(opts).and_raise(StandardError)
end end
...@@ -366,7 +346,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -366,7 +346,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
end end
context 'slugs' do describe 'slugs' do
shared_examples_for 'slug from api_url' do |method, slug| shared_examples_for 'slug from api_url' do |method, slug|
context 'when api_url is correct' do context 'when api_url is correct' do
before do before do
...@@ -393,9 +373,9 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -393,9 +373,9 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
it_behaves_like 'slug from api_url', :organization_slug, 'org-slug' it_behaves_like 'slug from api_url', :organization_slug, 'org-slug'
end end
context 'names from api_url' do describe 'names from api_url' do
shared_examples_for 'name from api_url' do |name, titleized_slug| shared_examples_for 'name from api_url' do |name, titleized_slug|
context 'name is present in DB' do context 'when name is present in DB' do
it 'returns name from DB' do it 'returns name from DB' do
subject[name] = 'Sentry name' subject[name] = 'Sentry name'
subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug' subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug'
...@@ -404,7 +384,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -404,7 +384,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do
end end
end end
context 'name is null in DB' do context 'when name is null in DB' do
it 'titleizes and returns slug from api_url' do it 'titleizes and returns slug from api_url' do
subject[name] = nil subject[name] = nil
subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug' subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment