Skip to content

Commit

Permalink
Add event's name validation (#5)
Browse files Browse the repository at this point in the history
* 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.

* Add constrain to signalman_events name
  • Loading branch information
JuanVqz authored Aug 8, 2023
1 parent 6e0dcc2 commit e0574c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/models/signalman/event.rb
Original file line number Diff line number Diff line change
@@ -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") }
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

ActiveRecord::Schema[7.0].define(version: 2023_07_30_020301) do
create_table "signalman_events", force: :cascade do |t|
t.string "name"
t.string "name", null: false
t.datetime "started_at"
t.datetime "finished_at"
t.float "duration"
Expand Down
7 changes: 0 additions & 7 deletions test/models/signalman/entry_test.rb

This file was deleted.

11 changes: 11 additions & 0 deletions test/models/signalman/event_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e0574c4

Please sign in to comment.