diff options
Diffstat (limited to 'spec/models/alert_management')
-rw-r--r-- | spec/models/alert_management/alert_assignee_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/alert_management/alert_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/alert_management/alert_user_mention_spec.rb | 12 |
3 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/alert_management/alert_assignee_spec.rb b/spec/models/alert_management/alert_assignee_spec.rb new file mode 100644 index 00000000000..c51a5d543ab --- /dev/null +++ b/spec/models/alert_management/alert_assignee_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe AlertManagement::AlertAssignee do + describe 'associations' do + it { is_expected.to belong_to(:alert) } + it { is_expected.to belong_to(:assignee) } + end + + describe 'validations' do + let(:alert) { create(:alert_management_alert) } + let(:user) { create(:user) } + + subject { alert.alert_assignees.build(assignee: user) } + + it { is_expected.to validate_presence_of(:alert) } + it { is_expected.to validate_presence_of(:assignee) } + it { is_expected.to validate_uniqueness_of(:assignee).scoped_to(:alert_id) } + end +end diff --git a/spec/models/alert_management/alert_spec.rb b/spec/models/alert_management/alert_spec.rb index 1da0c6d4071..27b8bb48073 100644 --- a/spec/models/alert_management/alert_spec.rb +++ b/spec/models/alert_management/alert_spec.rb @@ -6,6 +6,10 @@ describe AlertManagement::Alert do describe 'associations' do it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:issue) } + it { is_expected.to have_many(:assignees).through(:alert_assignees) } + it { is_expected.to have_many(:notes) } + it { is_expected.to have_many(:ordered_notes) } + it { is_expected.to have_many(:user_mentions) } end describe 'validations' do @@ -241,6 +245,12 @@ describe AlertManagement::Alert do end end + describe '#to_reference' do + let(:alert) { build(:alert_management_alert) } + + it { expect(alert.to_reference).to eq('') } + end + describe '#trigger' do subject { alert.trigger } @@ -317,4 +327,14 @@ describe AlertManagement::Alert do expect { subject }.to change { alert.reload.ended_at }.to nil end end + + describe '#register_new_event!' do + subject { alert.register_new_event! } + + let(:alert) { create(:alert_management_alert) } + + it 'increments the events count by 1' do + expect { subject }.to change { alert.events }.by(1) + end + end end diff --git a/spec/models/alert_management/alert_user_mention_spec.rb b/spec/models/alert_management/alert_user_mention_spec.rb new file mode 100644 index 00000000000..cce090a2231 --- /dev/null +++ b/spec/models/alert_management/alert_user_mention_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe AlertManagement::AlertUserMention do + describe 'associations' do + it { is_expected.to belong_to(:alert_management_alert) } + it { is_expected.to belong_to(:note) } + end + + it_behaves_like 'has user mentions' +end |