2019-12-10 07:07:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe SentryIssue do
|
2019-12-10 07:07:55 -05:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:issue) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
let!(:sentry_issue) { create(:sentry_issue) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:issue) }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:issue) }
|
|
|
|
it { is_expected.to validate_presence_of(:sentry_issue_identifier) }
|
2020-02-05 10:08:48 -05:00
|
|
|
|
|
|
|
it 'allows duplicated sentry_issue_identifier' do
|
|
|
|
duplicate_sentry_issue = build(:sentry_issue, sentry_issue_identifier: sentry_issue.sentry_issue_identifier)
|
|
|
|
|
|
|
|
expect(duplicate_sentry_issue).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'validates uniqueness of sentry_issue_identifier per project' do
|
|
|
|
second_issue = create(:issue, project: sentry_issue.issue.project)
|
|
|
|
duplicate_sentry_issue = build(:sentry_issue, issue: second_issue, sentry_issue_identifier: sentry_issue.sentry_issue_identifier)
|
|
|
|
|
|
|
|
expect(duplicate_sentry_issue).to be_invalid
|
|
|
|
expect(duplicate_sentry_issue.errors.full_messages.first).to include('is already associated')
|
|
|
|
end
|
2020-12-16 10:10:18 -05:00
|
|
|
|
|
|
|
describe 'when importing' do
|
|
|
|
subject { create(:sentry_issue, importing: true) }
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:issue) }
|
|
|
|
end
|
2020-01-16 16:08:24 -05:00
|
|
|
end
|
|
|
|
|
2020-01-20 13:08:44 -05:00
|
|
|
describe 'callbacks' do
|
|
|
|
context 'after create commit do' do
|
|
|
|
it 'updates Sentry with a reciprocal link on creation' do
|
|
|
|
issue = create(:issue)
|
|
|
|
|
|
|
|
expect(ErrorTrackingIssueLinkWorker).to receive(:perform_async).with(issue.id)
|
|
|
|
|
|
|
|
create(:sentry_issue, issue: issue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-16 16:08:24 -05:00
|
|
|
describe '.for_project_and_identifier' do
|
2020-02-05 10:08:48 -05:00
|
|
|
it 'finds the most recent per project and sentry_issue_identifier' do
|
|
|
|
sentry_issue = create(:sentry_issue)
|
|
|
|
create(:sentry_issue)
|
|
|
|
project = sentry_issue.issue.project
|
|
|
|
sentry_issue_3 = build(:sentry_issue, issue: create(:issue, project: project), sentry_issue_identifier: sentry_issue.sentry_issue_identifier)
|
2021-11-03 17:10:35 -04:00
|
|
|
sentry_issue_3.save!(validate: false)
|
2020-01-16 16:08:24 -05:00
|
|
|
|
2020-02-05 10:08:48 -05:00
|
|
|
result = described_class.for_project_and_identifier(project, sentry_issue.sentry_issue_identifier)
|
2020-01-16 16:08:24 -05:00
|
|
|
|
2020-02-05 10:08:48 -05:00
|
|
|
expect(result).to eq(sentry_issue_3)
|
|
|
|
end
|
2019-12-10 07:07:55 -05:00
|
|
|
end
|
|
|
|
end
|