Skip to content

Commit

Permalink
View and Db models specs (#32)
Browse files Browse the repository at this point in the history
* View and Db models specs

* Fix rubocop
  • Loading branch information
mbajur authored Feb 18, 2025
1 parent 4d9d6bb commit 61daeaa
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/inner_performance/traces/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Db < InnerPerformance::Trace
class << self
def initialize_for_insert(trace:, event:)
{
type: self.class.name,
type: name,
name: trace[:name],
payload: trace[:payload].to_json,
duration: trace[:duration],
Expand Down
2 changes: 1 addition & 1 deletion app/models/inner_performance/traces/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class View < InnerPerformance::Trace
class << self
def initialize_for_insert(trace:, event:)
{
type: self.class.name,
type: name,
name: trace[:name],
payload: trace[:payload].to_json,
duration: trace[:duration],
Expand Down
31 changes: 31 additions & 0 deletions spec/models/inner_performance/traces/db_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "rails_helper"

describe InnerPerformance::Traces::Db do
describe ".initialize_for_insert" do
subject { described_class.initialize_for_insert(trace: trace, event: event) }

let(:trace) do
{
name: "sql.active_record",
payload: { sql: "foo" },
duration: 123,
time: Time.current.to_i,
}
end

let(:event) { create(:event) }

it "returns a hash with the correct keys and values" do
expect(subject).to(eq({
type: "InnerPerformance::Traces::Db",
name: "sql.active_record",
payload: { sql: "foo" }.to_json,
duration: 123,
created_at: trace[:time],
event_id: event.id,
}))
end
end
end
31 changes: 31 additions & 0 deletions spec/models/inner_performance/traces/view_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "rails_helper"

describe InnerPerformance::Traces::View do
describe ".initialize_for_insert" do
subject { described_class.initialize_for_insert(trace: trace, event: event) }

let(:trace) do
{
name: "render_template.action_view",
payload: { identifier: "foo" },
duration: 123,
time: Time.current.to_i,
}
end

let(:event) { create(:event) }

it "returns a hash with the correct keys and values" do
expect(subject).to(eq({
type: "InnerPerformance::Traces::View",
name: "render_template.action_view",
payload: { identifier: "foo" }.to_json,
duration: 123,
created_at: trace[:time],
event_id: event.id,
}))
end
end
end

0 comments on commit 61daeaa

Please sign in to comment.