From e6c1247a29b756095d14edddd30847fcbd16639c Mon Sep 17 00:00:00 2001 From: Juan Vasquez Date: Sun, 6 Aug 2023 20:57:47 -0600 Subject: [PATCH] Add event's name validation We've been using the event's name to know what kind of event it is. I think we should add the name presence validator, what do you think about it? If should be more validations, please let me know, and also, if the validation is not needed/desired feel free to close the pr. --- app/models/signalman/event.rb | 2 ++ test/models/signalman/entry_test.rb | 7 ------- test/models/signalman/event_test.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) delete mode 100644 test/models/signalman/entry_test.rb create mode 100644 test/models/signalman/event_test.rb diff --git a/app/models/signalman/event.rb b/app/models/signalman/event.rb index 6c02474..44e0c24 100644 --- a/app/models/signalman/event.rb +++ b/app/models/signalman/event.rb @@ -1,4 +1,6 @@ class Signalman::Event < ApplicationRecord + validates :name, presence: true + scope :requests, ->{ where(name: "process_action.action_controller") } scope :mails, ->{ where(name: "deliver.action_mailer") } scope :queries, ->{ where(name: "sql.active_record") } diff --git a/test/models/signalman/entry_test.rb b/test/models/signalman/entry_test.rb deleted file mode 100644 index ec2970c..0000000 --- a/test/models/signalman/entry_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "test_helper" - -class Signalman::EntryTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/signalman/event_test.rb b/test/models/signalman/event_test.rb new file mode 100644 index 0000000..c4b8114 --- /dev/null +++ b/test/models/signalman/event_test.rb @@ -0,0 +1,11 @@ +require "test_helper" + +class Signalman::EventTest < ActiveSupport::TestCase + test "is valid" do + assert Signalman::Event.new(name: "sql.active_record").valid? + end + + test "is not valid" do + assert_not Signalman::Event.new.valid? + end +end