-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CE): Sync alerts - added models (#741) (#555)
Co-authored-by: Basil V Bose <bvb007@gmail.com>
- Loading branch information
1 parent
8c395c7
commit 5c82069
Showing
10 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class Alert < ApplicationRecord | ||
belongs_to :workspace | ||
has_many :alert_channels, dependent: :destroy | ||
accepts_nested_attributes_for :alert_channels | ||
|
||
validates :workspace_id, presence: true | ||
validates :row_failure_threshold_percent, numericality: { only_integer: true, allow_nil: true } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class AlertChannel < ApplicationRecord | ||
belongs_to :alert | ||
|
||
validates :platform, presence: true, inclusion: { in: %w[email slack] } | ||
enum :platform, %i[email slack] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateAlerts < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :alerts do |t| | ||
t.string :name | ||
t.references :workspace, null: false, foreign_key: true | ||
t.boolean :alert_sync_success, default: false | ||
t.boolean :alert_sync_failure, default: false | ||
t.boolean :alert_row_failure, default: false | ||
t.integer :row_failure_threshold_percent | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateAlertChannels < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :alert_channels do |t| | ||
t.references :alert, null: false, foreign_key: true | ||
t.integer :platform, null: false | ||
t.jsonb :configuration | ||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :alert_channel do | ||
association :alert | ||
|
||
trait :email do | ||
platform { "email" } | ||
configuration { { extra_email_recipients: ["user1@example.com", "user2@example.com"] } } | ||
end | ||
|
||
trait :slack do | ||
platform { "slack" } | ||
configuration { { slack_email_alias: ["slackemailtemplate@slack.com"] } } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :alert do | ||
association :workspace | ||
name { "Test alert" } | ||
alert_sync_success { false } | ||
alert_sync_failure { false } | ||
alert_row_failure { false } | ||
row_failure_threshold_percent { 50 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe AlertChannel, type: :model do | ||
describe "associations" do | ||
it { should belong_to(:alert) } | ||
end | ||
|
||
describe "validations" do | ||
it { should validate_presence_of(:platform) } | ||
end | ||
|
||
describe "platform" do | ||
it "defines platform enum with specified values" do | ||
expect(AlertChannel.platforms).to eq({ "email" => 0, "slack" => 1 }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Alert, type: :model do | ||
describe "associations" do | ||
it { should belong_to(:workspace) } | ||
it { should have_many(:alert_channels).dependent(:destroy) } | ||
end | ||
|
||
describe "validations" do | ||
it { should validate_presence_of(:workspace_id) } | ||
it { should validate_numericality_of(:row_failure_threshold_percent).only_integer.allow_nil } | ||
end | ||
end |