devformance 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28211e6e59e94ed6dab36b693c72585d084491a2bb0d6d3dc4a7b37c8c96fb40
4
- data.tar.gz: 13a835b26dbbac8c9179eca106f098cb0f02c046adef66d9e3d63c28147780a5
3
+ metadata.gz: d4dbeb244e125c274d11edc1076f81967b4f2939a594094abd774384704789cf
4
+ data.tar.gz: a2f2499f058d55968708385748d7e9acd2bab7acccb2c27c26a9972723cab95c
5
5
  SHA512:
6
- metadata.gz: 40639e968973f0e9ef89ee401da59633c5c25cc99ddd3ade2cd489d394bdbdd952ea727ffbd16b26cad1ce133529a1a56a07451f46c5859e055de401945772d0
7
- data.tar.gz: cd4251f047e66bdb0fce61ea5d189e8026db679f47090b16be8d2c4e64807e6b114f0d4604b68c198f4e97935324d1b0cbc21abfb56cd28d85e91b4851bd7bfa
6
+ metadata.gz: d5be802a36a8ca2782acdc599f461d3006a75194498c603e66e6446b33881409c03f544258ba1b43a170edd5621bb1efaba518d7f1ff4d748e399285008b529b
7
+ data.tar.gz: 36aa0ed34f200ab7de0ab555427aec0ac3cc4763eddcc92a983c595de745a3c2a04b7d002b6e44809ee0ac1aa2cc39ad9b7d70c925f735c11d530697545c7454
@@ -7,8 +7,14 @@ module Devformance
7
7
  belongs_to :run, foreign_key: :run_id, primary_key: :run_id,
8
8
  class_name: "Devformance::Run"
9
9
 
10
+ validates :file_key, uniqueness: { scope: :run_id }
11
+
10
12
  def self.file_key_for(file_path)
11
- File.basename(file_path, ".rb").gsub(/[^a-z0-9_]/, "_")
13
+ relative_path = Pathname.new(file_path).relative_path_from(Rails.root).to_s
14
+
15
+ relative_path.gsub(/[^a-z0-9_]+/i, "_").downcase.sub(/_rb\z/, "")
16
+ rescue ArgumentError
17
+ file_path.to_s.gsub(/[^a-z0-9_]+/i, "_").downcase.sub(/_rb\z/, "")
12
18
  end
13
19
  end
14
20
  end
@@ -1,3 +1,3 @@
1
1
  module Devformance
2
- Version = "0.1.0"
2
+ Version = "0.1.1"
3
3
  end
@@ -13,22 +13,4 @@ FactoryBot.define do
13
13
  duration_ms { nil }
14
14
  log_path { nil }
15
15
  end
16
-
17
- trait :passed do
18
- status { :passed }
19
- total_tests { 10 }
20
- passed_tests { 10 }
21
- failed_tests { 0 }
22
- coverage { 95.5 }
23
- duration_ms { 2500 }
24
- end
25
-
26
- trait :failed do
27
- status { :failed }
28
- total_tests { 10 }
29
- passed_tests { 7 }
30
- failed_tests { 3 }
31
- coverage { 85.0 }
32
- duration_ms { 3000 }
33
- end
34
16
  end
@@ -18,8 +18,8 @@ RSpec.describe Devformance::FileResult, type: :model do
18
18
  context "with a standard spec path" do
19
19
  let(:file_path) { "spec/requests/users_spec.rb" }
20
20
 
21
- it "returns the basename without .rb extension" do
22
- expect(key).to eq("users_spec")
21
+ it "returns a sanitized key from the relative path" do
22
+ expect(key).to eq("spec_requests_users_spec")
23
23
  end
24
24
  end
25
25
 
@@ -27,15 +27,32 @@ RSpec.describe Devformance::FileResult, type: :model do
27
27
  let(:file_path) { "spec/requests/my-complex_spec.rb" }
28
28
 
29
29
  it "replaces non-alphanumeric characters with underscores" do
30
- expect(key).to eq("my_complex_spec")
30
+ expect(key).to eq("spec_requests_my_complex_spec")
31
31
  end
32
32
  end
33
33
 
34
34
  context "with a deeply nested path" do
35
- let(:file_path) { "/home/user/app/spec/requests/api/v1/orders_spec.rb" }
35
+ let(:file_path) { Rails.root.join("spec/requests/api/v1/orders_spec.rb").to_s }
36
36
 
37
- it "uses only the basename" do
38
- expect(key).to eq("orders_spec")
37
+ it "uses the full relative path" do
38
+ expect(key).to eq("spec_requests_api_v1_orders_spec")
39
+ end
40
+ end
41
+
42
+ it "distinguishes files with the same basename in different directories" do
43
+ first_path = Rails.root.join("spec/requests/api/v1/categories_petitions/list_spec.rb").to_s
44
+ second_path = Rails.root.join("spec/requests/api/v1/core/document_types/list_spec.rb").to_s
45
+
46
+ expect(described_class.file_key_for(first_path)).to eq("spec_requests_api_v1_categories_petitions_list_spec")
47
+ expect(described_class.file_key_for(second_path)).to eq("spec_requests_api_v1_core_document_types_list_spec")
48
+ expect(described_class.file_key_for(first_path)).not_to eq(described_class.file_key_for(second_path))
49
+ end
50
+
51
+ context "when the path cannot be made relative to Rails.root" do
52
+ let(:file_path) { "/tmp/external/list_spec.rb" }
53
+
54
+ it "falls back to sanitizing the full path" do
55
+ expect(key).to eq("_tmp_external_list_spec")
39
56
  end
40
57
  end
41
58
  end
data/spec/rails_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
2
  require_relative '../config/environment'
3
3
  require 'rspec/rails'
4
- require 'factory_bot'
4
+ require 'factory_bot_rails'
5
5
  require 'simplecov'
6
6
  SimpleCov.start 'rails' do
7
7
  enable_coverage :branch
@@ -16,5 +16,5 @@ end
16
16
 
17
17
  Dir[Rails.root.join("spec/fixtures/devformance/**/*.rb")].each { |f| require f }
18
18
 
19
- require_relative '../spec/support/devformance_formatter'
20
- require_relative '../spec/support/devformance_metrics'
19
+ require_relative '../spec/support/devmetrics_formatter'
20
+ require_relative '../spec/support/devmetrics_metrics'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devformance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devformance Contributors
@@ -166,7 +166,6 @@ files:
166
166
  - spec/lib/devmetrics/sql_instrumentor_spec.rb
167
167
  - spec/models/devmetrics/file_result_spec.rb
168
168
  - spec/models/devmetrics/run_spec.rb
169
- - spec/models/query_log_spec.rb
170
169
  - spec/rails_helper.rb
171
170
  - spec/requests/devmetrics/metrics_controller_spec.rb
172
171
  - spec/requests/devmetrics_pages_spec.rb
@@ -176,10 +175,12 @@ files:
176
175
  - spec/support/devmetrics_formatter.rb
177
176
  - spec/support/devmetrics_metrics.rb
178
177
  - spec/support/factory_bot.rb
179
- homepage: https://github.com/yourusername/devformance
178
+ homepage: https://github.com/anyelopetit/devformance
180
179
  licenses:
181
180
  - MIT
182
- metadata: {}
181
+ metadata:
182
+ source_code_uri: https://github.com/anyelopetit/devformance
183
+ bug_tracker_uri: https://github.com/anyelopetit/devformance/issues
183
184
  rdoc_options: []
184
185
  require_paths:
185
186
  - lib
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails_helper"
4
-
5
- RSpec.describe QueryLog, type: :model do
6
- describe "#initialize" do
7
- subject(:instance) { described_class.new(query: "SELECT 1") }
8
-
9
- it "stores the query attribute" do
10
- expect(instance.query).to eq("SELECT 1")
11
- end
12
- end
13
-
14
- describe "validations" do
15
- subject(:log) { described_class.new(query: "SELECT * FROM users", duration: 150, user_id: 1) }
16
-
17
- it "is valid with basic attributes" do
18
- expect(log).to be_valid
19
- end
20
- end
21
- end