diff options
Diffstat (limited to 'spec/models/error_tracking')
-rw-r--r-- | spec/models/error_tracking/error_spec.rb | 56 | ||||
-rw-r--r-- | spec/models/error_tracking/project_error_tracking_setting_spec.rb | 11 |
2 files changed, 61 insertions, 6 deletions
diff --git a/spec/models/error_tracking/error_spec.rb b/spec/models/error_tracking/error_spec.rb index 57899985daf..5543392b624 100644 --- a/spec/models/error_tracking/error_spec.rb +++ b/spec/models/error_tracking/error_spec.rb @@ -16,6 +16,62 @@ RSpec.describe ErrorTracking::Error, type: :model do it { is_expected.to validate_presence_of(:actor) } end + describe '.report_error' do + it 'updates existing record with a new timestamp' do + timestamp = Time.zone.now + + reported_error = described_class.report_error( + name: error.name, + description: 'Lorem ipsum', + actor: error.actor, + platform: error.platform, + timestamp: timestamp + ) + + expect(reported_error.id).to eq(error.id) + expect(reported_error.last_seen_at).to eq(timestamp) + expect(reported_error.description).to eq('Lorem ipsum') + end + end + + describe '.sort_by_attribute' do + let!(:error2) { create(:error_tracking_error, first_seen_at: Time.zone.now - 2.weeks, last_seen_at: Time.zone.now - 1.week) } + let!(:error3) { create(:error_tracking_error, first_seen_at: Time.zone.now - 3.weeks, last_seen_at: Time.zone.now.yesterday) } + let!(:errors) { [error, error2, error3] } + + subject { described_class.where(id: errors).sort_by_attribute(sort) } + + context 'id desc by default' do + let(:sort) { nil } + + it { is_expected.to eq([error3, error2, error]) } + end + + context 'first_seen' do + let(:sort) { 'first_seen' } + + it { is_expected.to eq([error, error2, error3]) } + end + + context 'last_seen' do + let(:sort) { 'last_seen' } + + it { is_expected.to eq([error, error3, error2]) } + end + + context 'frequency' do + let(:sort) { 'frequency' } + + before do + create(:error_tracking_error_event, error: error2) + create(:error_tracking_error_event, error: error2) + create(:error_tracking_error_event, error: error3) + end + + it { is_expected.to eq([error2, error3, error]) } + end + end + describe '#title' do it { expect(error.title).to eq('ActionView::MissingTemplate Missing template posts/edit') } end diff --git a/spec/models/error_tracking/project_error_tracking_setting_spec.rb b/spec/models/error_tracking/project_error_tracking_setting_spec.rb index 7be61f4950e..29255e53fcf 100644 --- a/spec/models/error_tracking/project_error_tracking_setting_spec.rb +++ b/spec/models/error_tracking/project_error_tracking_setting_spec.rb @@ -478,18 +478,17 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do describe '#sentry_enabled' do using RSpec::Parameterized::TableSyntax - where(:enabled, :integrated, :feature_flag, :sentry_enabled) do - true | false | false | true - true | true | false | true - true | true | true | false - false | false | false | false + where(:enabled, :integrated, :sentry_enabled) do + true | false | true + true | true | false + true | true | false + false | false | false end with_them do before do subject.enabled = enabled subject.integrated = integrated - stub_feature_flags(integrated_error_tracking: feature_flag) end it { expect(subject.sentry_enabled).to eq(sentry_enabled) } |