pliny 1.2.0 → 2.0.0

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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/bin/pliny-generate +2 -1
  3. data/bin/pliny-new +2 -1
  4. data/bin/pliny-update +2 -1
  5. data/lib/pliny/canonical_log_line_helpers.rb +2 -0
  6. data/lib/pliny/commands/creator.rb +13 -12
  7. data/lib/pliny/commands/generator/base.rb +11 -9
  8. data/lib/pliny/commands/generator/endpoint.rb +19 -17
  9. data/lib/pliny/commands/generator/mediator.rb +7 -5
  10. data/lib/pliny/commands/generator/migration.rb +4 -2
  11. data/lib/pliny/commands/generator/model.rb +11 -9
  12. data/lib/pliny/commands/generator/schema.rb +4 -2
  13. data/lib/pliny/commands/generator/serializer.rb +7 -5
  14. data/lib/pliny/commands/generator.rb +19 -17
  15. data/lib/pliny/commands/updater.rb +5 -3
  16. data/lib/pliny/config_helpers.rb +10 -35
  17. data/lib/pliny/db_support.rb +21 -21
  18. data/lib/pliny/error_reporters/rollbar.rb +5 -3
  19. data/lib/pliny/error_reporters/sentry.rb +40 -0
  20. data/lib/pliny/error_reporters.rb +5 -5
  21. data/lib/pliny/errors.rb +46 -44
  22. data/lib/pliny/helpers/encode.rb +4 -2
  23. data/lib/pliny/helpers/params.rb +2 -0
  24. data/lib/pliny/helpers/serialize.rb +6 -4
  25. data/lib/pliny/helpers/zulu_time.rb +3 -1
  26. data/lib/pliny/log.rb +26 -25
  27. data/lib/pliny/metrics/backends/logger.rb +5 -3
  28. data/lib/pliny/metrics.rb +4 -2
  29. data/lib/pliny/middleware/canonical_log_line.rb +5 -3
  30. data/lib/pliny/middleware/cors.rb +13 -12
  31. data/lib/pliny/middleware/instruments.rb +9 -7
  32. data/lib/pliny/middleware/metrics.rb +3 -1
  33. data/lib/pliny/middleware/request_id.rb +4 -2
  34. data/lib/pliny/middleware/request_store/clear.rb +3 -1
  35. data/lib/pliny/middleware/request_store/seed.rb +3 -1
  36. data/lib/pliny/middleware/rescue_errors.rb +2 -0
  37. data/lib/pliny/middleware/versioning.rb +11 -11
  38. data/lib/pliny/request_store.rb +4 -2
  39. data/lib/pliny/rollbar_logger.rb +6 -4
  40. data/lib/pliny/router.rb +3 -2
  41. data/lib/pliny/tasks/db.rake +3 -1
  42. data/lib/pliny/tasks/schema.rake +3 -1
  43. data/lib/pliny/tasks.rb +2 -0
  44. data/lib/pliny/utils.rb +4 -2
  45. data/lib/pliny/version.rb +3 -1
  46. data/lib/pliny.rb +2 -0
  47. data/lib/template/{.rubocop.yml → .rubocop_template.yml} +1 -5
  48. data/lib/template/Gemfile +7 -4
  49. data/lib/template/Rakefile +1 -0
  50. data/lib/template/bin/console +2 -1
  51. data/lib/template/bin/run +4 -1
  52. data/lib/template/config/config.rb +18 -16
  53. data/lib/template/config/initializers/database.rb +4 -2
  54. data/lib/template/config/initializers/log.rb +2 -0
  55. data/lib/template/config/initializers/metrics.rb +2 -0
  56. data/lib/template/config/initializers/sentry.rb +14 -0
  57. data/lib/template/config/puma.rb +3 -1
  58. data/lib/template/config.ru +2 -0
  59. data/lib/template/db/seeds.rb +2 -0
  60. data/lib/template/lib/application.rb +2 -0
  61. data/lib/template/lib/endpoints/base.rb +2 -0
  62. data/lib/template/lib/endpoints/health.rb +2 -0
  63. data/lib/template/lib/endpoints/root.rb +2 -0
  64. data/lib/template/lib/endpoints/schema.rb +2 -0
  65. data/lib/template/lib/initializer.rb +6 -4
  66. data/lib/template/lib/mediators/base.rb +2 -0
  67. data/lib/template/lib/routes.rb +8 -6
  68. data/lib/template/lib/serializers/base.rb +2 -0
  69. data/lib/template/lib/tasks/rubocop.rake +2 -0
  70. data/lib/template/lib/tasks/spec.rake +2 -1
  71. data/lib/template/spec/endpoints/health_spec.rb +2 -0
  72. data/lib/template/spec/endpoints/schema_spec.rb +2 -0
  73. data/lib/template/spec/spec_helper.rb +2 -0
  74. data/lib/template/spec/spec_support/auto_define_rack_app.rb +2 -0
  75. data/lib/template/spec/spec_support/coverage.rb +2 -0
  76. data/lib/template/spec/spec_support/log.rb +2 -0
  77. data/spec/canonical_log_line_helpers_spec.rb +10 -8
  78. data/spec/commands/creator_spec.rb +3 -0
  79. data/spec/commands/generator/base_spec.rb +61 -59
  80. data/spec/commands/generator/endpoint_spec.rb +16 -15
  81. data/spec/commands/generator/mediator_spec.rb +11 -9
  82. data/spec/commands/generator/migration_spec.rb +7 -5
  83. data/spec/commands/generator/model_spec.rb +13 -11
  84. data/spec/commands/generator/schema_spec.rb +29 -28
  85. data/spec/commands/generator/serializer_spec.rb +11 -9
  86. data/spec/commands/generator_spec.rb +64 -62
  87. data/spec/commands/updater_spec.rb +2 -0
  88. data/spec/config_helpers_spec.rb +7 -85
  89. data/spec/db_support_spec.rb +46 -44
  90. data/spec/error_reporters/rollbar_spec.rb +8 -6
  91. data/spec/error_reporters/sentry_spec.rb +83 -0
  92. data/spec/error_reporters_spec.rb +4 -2
  93. data/spec/errors_spec.rb +4 -1
  94. data/spec/helpers/encode_spec.rb +2 -0
  95. data/spec/helpers/params_spec.rb +9 -7
  96. data/spec/helpers/serialize_spec.rb +11 -7
  97. data/spec/helpers/zulu_time_spec.rb +6 -4
  98. data/spec/integration_spec.rb +14 -12
  99. data/spec/log_spec.rb +8 -6
  100. data/spec/metrics/backends/logger_spec.rb +10 -6
  101. data/spec/metrics_spec.rb +15 -13
  102. data/spec/middleware/canonical_log_line_spec.rb +5 -2
  103. data/spec/middleware/cors_spec.rb +2 -0
  104. data/spec/middleware/instruments_spec.rb +10 -8
  105. data/spec/middleware/metrics_spec.rb +3 -1
  106. data/spec/middleware/request_id_spec.rb +2 -0
  107. data/spec/middleware/request_store/clear_spec.rb +2 -0
  108. data/spec/middleware/request_store/seed_spec.rb +2 -0
  109. data/spec/middleware/rescue_errors_spec.rb +13 -13
  110. data/spec/middleware/versioning_spec.rb +22 -20
  111. data/spec/request_store_spec.rb +3 -1
  112. data/spec/rollbar_logger_spec.rb +11 -9
  113. data/spec/router_spec.rb +9 -7
  114. data/spec/spec_helper.rb +3 -1
  115. data/spec/support/config.rb +2 -0
  116. data/spec/support/endpoints.rb +2 -0
  117. metadata +91 -100
  118. data/lib/template/config/initializers/rollbar.rb +0 -12
data/spec/errors_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Errors do
@@ -9,7 +11,8 @@ describe Pliny::Errors do
9
11
 
10
12
  it "includes an HTTP error that will take generic parameters" do
11
13
  e = Pliny::Errors::HTTPStatusError.new(
12
- "Custom HTTP error.", :custom_http_error, 499)
14
+ "Custom HTTP error.", :custom_http_error, 499,
15
+ )
13
16
  assert_equal "Custom HTTP error.", e.message
14
17
  assert_equal :custom_http_error, e.id
15
18
  assert_equal 499, e.status
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Helpers::Encode do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Helpers::Params do
@@ -11,35 +13,35 @@ describe Pliny::Helpers::Params do
11
13
  end
12
14
 
13
15
  it "loads json params" do
14
- post "/", {hello: "world"}.to_json, {"CONTENT_TYPE" => "application/json"}
16
+ post "/", { hello: "world" }.to_json, { "CONTENT_TYPE" => "application/json" }
15
17
  assert_equal "{\"hello\":\"world\"}", last_response.body
16
18
  end
17
19
 
18
20
  it "loads json array of params" do
19
- post "/", [{hello: "world"}, {goodbye: "moon"}].to_json, {"CONTENT_TYPE" => "application/json"}
21
+ post "/", [{ hello: "world" }, { goodbye: "moon" }].to_json, { "CONTENT_TYPE" => "application/json" }
20
22
  assert_equal "[{\"hello\":\"world\"},{\"goodbye\":\"moon\"}]", last_response.body
21
23
  end
22
24
 
23
25
  it "loads json array of arrays of params" do
24
- post "/", [[{hello: "world"}], [{goodbye: "moon"}]].to_json, {"CONTENT_TYPE" => "application/json"}
26
+ post "/", [[{ hello: "world" }], [{ goodbye: "moon" }]].to_json, { "CONTENT_TYPE" => "application/json" }
25
27
  assert_equal "[[{\"hello\":\"world\"}],[{\"goodbye\":\"moon\"}]]", last_response.body
26
28
  end
27
29
 
28
30
  it "loads form data params" do
29
- post "/", {hello: "world"}
31
+ post "/", { hello: "world" }
30
32
  assert_equal "{\"hello\":\"world\"}", last_response.body
31
33
  end
32
34
 
33
35
  it "loads from an unknown content type" do
34
- post "/", "<hello>world</hello>", {"CONTENT_TYPE" => "application/xml"}
36
+ post "/", "<hello>world</hello>", { "CONTENT_TYPE" => "application/xml" }
35
37
  assert_equal "{}", last_response.body
36
38
  end
37
39
 
38
40
  it "should throw bad request when receiving invalid json via post" do
39
41
  err = assert_raises(Pliny::Errors::BadRequest) do
40
- post "/", "{\"foo\"}", {"CONTENT_TYPE" => "application/json"}
42
+ post "/", "{\"foo\"}", { "CONTENT_TYPE" => "application/json" }
41
43
  end
42
44
 
43
- assert_match /unexpected token/, err.message
45
+ assert_match(/expected ':' after object key at line 1 column 7/, err.message)
44
46
  end
45
47
  end
@@ -1,5 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
5
+ class Serializer
6
+ def initialize(opts)
7
+ end
8
+
9
+ def serialize(data)
10
+ data
11
+ end
12
+ end
13
+
3
14
  describe Pliny::Helpers::Serialize do
4
15
  context "without a serializer" do
5
16
  def app
@@ -20,13 +31,6 @@ describe Pliny::Helpers::Serialize do
20
31
  end
21
32
 
22
33
  context "with a serializer" do
23
- class Serializer
24
- def initialize(opts); end
25
- def serialize(data)
26
- data
27
- end
28
- end
29
-
30
34
  def app
31
35
  Sinatra.new do
32
36
  register Pliny::Helpers::Serialize
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
5
+ class ZuluTimeTest
6
+ extend Pliny::Helpers::ZuluTime
7
+ end
8
+
3
9
  describe Pliny::Helpers::ZuluTime do
4
10
  context "zulu_time" do
5
- class ZuluTimeTest
6
- extend Pliny::Helpers::ZuluTime
7
- end
8
-
9
11
  it "it formats Time instances" do
10
12
  formatted = ZuluTimeTest.zulu_time(Time.parse("2017-11-28T21:49:52.123+00:00"))
11
13
  assert_equal "2017-11-28T21:49:52Z", formatted
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
  require "open3"
3
5
 
@@ -79,41 +81,41 @@ describe "Pliny integration test" do
79
81
 
80
82
  it "returns a migration in the DOWN state when not migrated" do
81
83
  bash "pliny-generate model artist"
82
- migration_file = Dir.glob('db/migrate/*').first
84
+ migration_file = Dir.glob("db/migrate/*").first
83
85
 
84
- stdout, stderr = bash_with_output("rake db:migrate:status")
86
+ stdout, _ = bash_with_output("rake db:migrate:status")
85
87
 
86
- statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }]
88
+ statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h
87
89
  assert statuses[migration_file.split("/").last] == "DOWN"
88
90
  end
89
91
 
90
92
  it "returns a migration in the UP state when not migrated" do
91
93
  bash "pliny-generate model artist"
92
- migration_file = Dir.glob('db/migrate/*').first
94
+ migration_file = Dir.glob("db/migrate/*").first
93
95
  bash "rake db:migrate"
94
96
 
95
- stdout, stderr = bash_with_output("rake db:migrate:status")
97
+ stdout, _ = bash_with_output("rake db:migrate:status")
96
98
 
97
- statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }]
99
+ statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h
98
100
  assert statuses[migration_file.split("/").last] == "UP"
99
101
  end
100
102
 
101
103
  it "returns a migration in the FILE MISSING state when the file is missing" do
102
104
  bash "pliny-generate model artist"
103
- migration_file = Dir.glob('db/migrate/*').first
105
+ migration_file = Dir.glob("db/migrate/*").first
104
106
  bash "rake db:migrate"
105
107
 
106
108
  FileUtils.rm_f(migration_file)
107
109
 
108
- stdout, stderr = bash_with_output("rake db:migrate:status")
110
+ stdout, _ = bash_with_output("rake db:migrate:status")
109
111
 
110
- statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^[ ]+|[ ]+$)/, "") }.select(&:present?).reverse }]
112
+ statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^ +| +$)/, "") }.select(&:present?).reverse }.to_h
111
113
  assert statuses[migration_file.split("/").last] == "FILE MISSING"
112
114
  end
113
115
  end
114
116
 
115
117
  def bash_with_output(cmd)
116
- bin = File.expand_path('../bin', File.dirname(__FILE__))
118
+ bin = File.expand_path("../bin", File.dirname(__FILE__))
117
119
  path = "#{bin}:#{ENV["PATH"]}"
118
120
  env = { "PATH" => path }
119
121
  stdout, stderr, status = Open3.capture3(env, cmd)
@@ -122,11 +124,11 @@ describe "Pliny integration test" do
122
124
  raise "Failed to run #{cmd}, error was #{stderr}"
123
125
  end
124
126
 
125
- return stdout, stderr
127
+ [stdout, stderr]
126
128
  end
127
129
 
128
130
  def bash(cmd)
129
- bin = File.expand_path('../bin', File.dirname(__FILE__))
131
+ bin = File.expand_path("../bin", File.dirname(__FILE__))
130
132
  path = "#{bin}:#{ENV["PATH"]}"
131
133
  env = { "PATH" => path }
132
134
  unless system(env, "#{cmd} > /dev/null")
data/spec/log_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Log do
@@ -66,7 +68,7 @@ describe Pliny::Log do
66
68
  it "local context does not overwrite default context" do
67
69
  Pliny.default_context = { app: "pliny" }
68
70
  expect(@io).to receive(:print).with("app=not_pliny foo=bar\n")
69
- Pliny.log(app: 'not_pliny', foo: "bar")
71
+ Pliny.log(app: "not_pliny", foo: "bar")
70
72
  assert Pliny.default_context[:app] == "pliny"
71
73
  end
72
74
 
@@ -95,20 +97,20 @@ describe Pliny::Log do
95
97
  end
96
98
 
97
99
  describe "scrubbing" do
98
-
99
100
  it "allows a Proc to be assigned as a log scrubber" do
100
- Pliny.log_scrubber = -> (hash) { hash }
101
+ Pliny.log_scrubber = ->(hash) { hash }
101
102
 
102
103
  begin
103
104
  Pliny.log_scrubber = Object.new
104
105
  fail
105
- rescue ArgumentError; end
106
+ rescue ArgumentError
107
+ end
106
108
  end
107
109
 
108
110
  describe "when a scrubber is present" do
109
111
  before do
110
- Pliny.log_scrubber = -> (hash) {
111
- Hash.new.tap do |h|
112
+ Pliny.log_scrubber = ->(hash) {
113
+ {}.tap do |h|
112
114
  hash.keys.each do |k|
113
115
  h[k] = "*SCRUBBED*"
114
116
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Metrics::Backends::Logger do
@@ -18,27 +20,29 @@ describe Pliny::Metrics::Backends::Logger do
18
20
 
19
21
  context "#count" do
20
22
  it "logs a single key with a value" do
21
- backend.report_counts('app.foo' => 1)
23
+ backend.report_counts("app.foo" => 1)
22
24
  expect(io).to have_received(:print).with("count#app.foo=1\n")
23
25
  end
24
26
 
25
27
  it "logs multiple keys with values" do
26
- backend.report_counts('app.foo' => 1, 'app.bar' => 2)
28
+ backend.report_counts("app.foo" => 1, "app.bar" => 2)
27
29
  expect(io).to have_received(:print).with(
28
- "count#app.foo=1 count#app.bar=2\n")
30
+ "count#app.foo=1 count#app.bar=2\n",
31
+ )
29
32
  end
30
33
  end
31
34
 
32
35
  context "#measure" do
33
36
  it "logs a single key with a value" do
34
- backend.report_measures('pliny.foo' => 0.001)
37
+ backend.report_measures("pliny.foo" => 0.001)
35
38
  expect(io).to have_received(:print).with("measure#pliny.foo=0.001\n")
36
39
  end
37
40
 
38
41
  it "logs multiple keys with values" do
39
- backend.report_measures('pliny.foo' => 0.3, 'pliny.bar' => 0.5)
42
+ backend.report_measures("pliny.foo" => 0.3, "pliny.bar" => 0.5)
40
43
  expect(io).to have_received(:print).with(
41
- "measure#pliny.foo=0.300 measure#pliny.bar=0.500\n")
44
+ "measure#pliny.foo=0.300 measure#pliny.bar=0.500\n",
45
+ )
42
46
  end
43
47
  end
44
48
  end
data/spec/metrics_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Metrics do
@@ -8,7 +10,7 @@ describe Pliny::Metrics do
8
10
  end
9
11
 
10
12
  before do
11
- allow(Config).to receive(:app_name).and_return('pliny')
13
+ allow(Config).to receive(:app_name).and_return("pliny")
12
14
  end
13
15
 
14
16
  around do |example|
@@ -41,7 +43,7 @@ describe Pliny::Metrics do
41
43
  metrics.count(:foo, :bar)
42
44
  expect(test_backend).to have_received(:report_counts).once.with(
43
45
  "pliny.foo" => 1,
44
- "pliny.bar" => 1
46
+ "pliny.bar" => 1,
45
47
  )
46
48
  end
47
49
  end
@@ -57,9 +59,9 @@ describe Pliny::Metrics do
57
59
  end
58
60
 
59
61
  it "measures a block's execution time with a single key" do
60
- metrics.measure(:foo) { }
62
+ metrics.measure(:foo) {}
61
63
  expect(test_backend).to have_received(:report_measures).once.with(
62
- "pliny.foo" => 0
64
+ "pliny.foo" => 0,
63
65
  )
64
66
  end
65
67
 
@@ -69,37 +71,37 @@ describe Pliny::Metrics do
69
71
  end
70
72
 
71
73
  expect(test_backend).to have_received(:report_measures) do |opts|
72
- assert(60 <= opts['pliny.foo'] && opts['pliny.foo'] <= 61)
74
+ assert(opts["pliny.foo"].between?(60, 61))
73
75
  end
74
76
  end
75
77
 
76
78
  it "measures a block's execution time with multiple keys" do
77
- metrics.measure(:foo, :bar) { }
79
+ metrics.measure(:foo, :bar) {}
78
80
  expect(test_backend).to have_received(:report_measures).once.with(
79
81
  "pliny.foo" => 0,
80
- "pliny.bar" => 0
82
+ "pliny.bar" => 0,
81
83
  )
82
84
  end
83
85
 
84
86
  it "measures a given value for a single key without a block" do
85
87
  metrics.measure(:baz, value: 3.14)
86
88
  expect(test_backend).to have_received(:report_measures).once.with(
87
- "pliny.baz" => 3.14
89
+ "pliny.baz" => 3.14,
88
90
  )
89
91
  end
90
92
 
91
93
  it "measures a given value for multiple keys with a block" do
92
- metrics.measure(:qux, :corge, value: 42) { }
94
+ metrics.measure(:qux, :corge, value: 42) {}
93
95
  expect(test_backend).to have_received(:report_measures).once.with(
94
96
  "pliny.qux" => 42,
95
- "pliny.corge" => 42
97
+ "pliny.corge" => 42,
96
98
  )
97
99
  end
98
100
 
99
101
  it "measures a value of 0 when no key or block is provided" do
100
102
  metrics.measure(:waldo)
101
103
  expect(test_backend).to have_received(:report_measures).once.with(
102
- "pliny.waldo" => 0
104
+ "pliny.waldo" => 0,
103
105
  )
104
106
  end
105
107
 
@@ -107,7 +109,7 @@ describe Pliny::Metrics do
107
109
  metrics.measure("metric.name", "another.name", value: 3.14, foo: :bar)
108
110
  expect(test_backend).to have_received(:report_measures).once.with(
109
111
  "pliny.metric.name" => 3.14,
110
- "pliny.another.name" => 3.14
112
+ "pliny.another.name" => 3.14,
111
113
  )
112
114
  end
113
115
 
@@ -115,7 +117,7 @@ describe Pliny::Metrics do
115
117
  metrics.measure("metric.name", "another.name", { value: 3.14, foo: :bar })
116
118
  expect(test_backend).to have_received(:report_measures).once.with(
117
119
  "pliny.metric.name" => 3.14,
118
- "pliny.another.name" => 3.14
120
+ "pliny.another.name" => 3.14,
119
121
  )
120
122
  end
121
123
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::CanonicalLogLine do
@@ -7,7 +9,7 @@ describe Pliny::Middleware::CanonicalLogLine do
7
9
  use Pliny::Middleware::RequestID
8
10
 
9
11
  use Pliny::Middleware::CanonicalLogLine,
10
- emitter: -> (data) { Pliny.log_without_context(data) }
12
+ emitter: ->(data) { Pliny.log_without_context(data) }
11
13
 
12
14
  use Pliny::Middleware::RescueErrors, raise: false
13
15
 
@@ -48,7 +50,8 @@ describe Pliny::Middleware::CanonicalLogLine do
48
50
 
49
51
  it "never fails a request on failure" do
50
52
  expect(Pliny).to receive(:log).with(
51
- message: "Failed to emit canonical log line")
53
+ message: "Failed to emit canonical log line",
54
+ )
52
55
  expect(Pliny).to receive(:log_without_context) { |d| raise "bang!" }
53
56
 
54
57
  get "/apps/123"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::CORS do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::Instruments do
@@ -25,17 +27,17 @@ describe Pliny::Middleware::Instruments do
25
27
  it "performs logging" do
26
28
  expect(Pliny).to receive(:log).with(hash_including(
27
29
  instrumentation: true,
28
- at: "start",
29
- method: "GET",
30
- path: "/apps/123",
30
+ at: "start",
31
+ method: "GET",
32
+ path: "/apps/123",
31
33
  ))
32
34
  expect(Pliny).to receive(:log).with(hash_including(
33
35
  instrumentation: true,
34
- at: "finish",
35
- method: "GET",
36
- path: "/apps/123",
36
+ at: "finish",
37
+ method: "GET",
38
+ path: "/apps/123",
37
39
  route_signature: "/apps/:id",
38
- status: 201
40
+ status: 201,
39
41
  ))
40
42
  get "/apps/123"
41
43
  end
@@ -43,7 +45,7 @@ describe Pliny::Middleware::Instruments do
43
45
  it "respects Pliny error status codes" do
44
46
  expect(Pliny).to receive(:log)
45
47
  expect(Pliny).to receive(:log).with(hash_including(
46
- status: 404
48
+ status: 404,
47
49
  ))
48
50
  get "/error"
49
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::Instruments do
@@ -57,7 +59,7 @@ describe Pliny::Middleware::Instruments do
57
59
  it "measures the request latency" do
58
60
  expect(Pliny::Metrics).to receive(:measure) do |key, opts|
59
61
  assert_equal(key, "requests.latency")
60
- assert(4 < opts[:value] && opts[:value] < 6)
62
+ assert_in_delta(5, opts[:value], 1)
61
63
  end
62
64
 
63
65
  get "/hello"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::RequestID do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::RequestStore::Clear do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::RequestStore::Seed do
@@ -1,21 +1,21 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Pliny::Middleware::RescueErrors do
4
- include Rack::Test::Methods
3
+ require "spec_helper"
5
4
 
6
- class BadMiddleware
7
- def call(env)
8
- if env["PATH_INFO"] == "/api-error"
9
- raise Pliny::Errors::ServiceUnavailable
10
- else
11
- raise "Omg!"
12
- end
5
+ class BadMiddleware
6
+ def call(env)
7
+ if env["PATH_INFO"] == "/api-error"
8
+ raise Pliny::Errors::ServiceUnavailable
9
+ else
10
+ raise "Omg!"
13
11
  end
14
12
  end
13
+ end
15
14
 
16
- def app
17
- @app
18
- end
15
+ describe Pliny::Middleware::RescueErrors do
16
+ include Rack::Test::Methods
17
+
18
+ attr_reader :app
19
19
 
20
20
  it "intercepts Pliny errors and renders" do
21
21
  @app = new_rack_app
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::Middleware::Versioning do
@@ -10,7 +12,7 @@ describe Pliny::Middleware::Versioning do
10
12
  def app
11
13
  Rack::Builder.new do
12
14
  use Rack::Lint
13
- use Pliny::Middleware::Versioning, default: '2', app_name: 'pliny'
15
+ use Pliny::Middleware::Versioning, default: "2", app_name: "pliny"
14
16
  run Sinatra.new {
15
17
  get "/" do
16
18
  JSON.generate env
@@ -20,48 +22,48 @@ describe Pliny::Middleware::Versioning do
20
22
  end
21
23
 
22
24
  it "produces default version on application/json" do
23
- get '/', {}, {'HTTP_ACCEPT' => 'application/json'}
25
+ get "/", {}, { "HTTP_ACCEPT" => "application/json" }
24
26
  json = JSON.parse(last_response.body)
25
- assert_equal 'application/json', json['HTTP_ACCEPT']
26
- assert_equal '2', json['HTTP_X_API_VERSION']
27
+ assert_equal "application/json", json["HTTP_ACCEPT"]
28
+ assert_equal "2", json["HTTP_X_API_VERSION"]
27
29
  end
28
30
 
29
31
  it "errors without a version specified on application/vnd.pliny+json" do
30
- get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json'}
31
- error = { id: :bad_version, message: <<-eos }
32
- Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`.
33
- eos
32
+ get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json" }
33
+ error = { id: :bad_version, message: <<~EOS }
34
+ Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`.
35
+ EOS
34
36
 
35
37
  assert_equal 400, last_response.status
36
38
  assert_equal JSON.generate(error), last_response.body
37
39
  end
38
40
 
39
41
  it "ignores a wrong app name" do
40
- get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.chuck_norris+json'}
42
+ get "/", {}, { "HTTP_ACCEPT" => "application/vnd.chuck_norris+json" }
41
43
  json = JSON.parse(last_response.body)
42
- assert_equal 'application/vnd.chuck_norris+json', json['HTTP_ACCEPT']
43
- assert_equal '2', json['HTTP_X_API_VERSION']
44
+ assert_equal "application/vnd.chuck_norris+json", json["HTTP_ACCEPT"]
45
+ assert_equal "2", json["HTTP_X_API_VERSION"]
44
46
  end
45
47
 
46
48
  it "produces a version on application/vnd.pliny+json; version=3" do
47
- get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3'}
49
+ get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=3" }
48
50
  json = JSON.parse(last_response.body)
49
- assert_equal 'application/json', json['HTTP_ACCEPT']
50
- assert_equal '3', json['HTTP_X_API_VERSION']
51
+ assert_equal "application/json", json["HTTP_ACCEPT"]
52
+ assert_equal "3", json["HTTP_X_API_VERSION"]
51
53
  end
52
54
 
53
55
  # this behavior is pretty sketchy, but a pretty extreme edge case
54
56
  it "handles multiple MIME types" do
55
- get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3; q=0.5, text/xml'}
57
+ get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=3; q=0.5, text/xml" }
56
58
  json = JSON.parse(last_response.body)
57
- assert_equal 'text/xml, application/json; q=0.5', json['HTTP_ACCEPT']
58
- assert_equal '3', json['HTTP_X_API_VERSION']
59
+ assert_equal "text/xml, application/json; q=0.5", json["HTTP_ACCEPT"]
60
+ assert_equal "3", json["HTTP_X_API_VERSION"]
59
61
  end
60
62
 
61
63
  it "produces the priority version on multiple types" do
62
- get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3'}
64
+ get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3" }
63
65
  json = JSON.parse(last_response.body)
64
- assert_equal 'application/json, application/json; q=0.5', json['HTTP_ACCEPT']
65
- assert_equal '3', json['HTTP_X_API_VERSION']
66
+ assert_equal "application/json, application/json; q=0.5", json["HTTP_ACCEPT"]
67
+ assert_equal "3", json["HTTP_X_API_VERSION"]
66
68
  end
67
69
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Pliny::RequestStore do
4
6
  before do
5
7
  @env = {
6
- "REQUEST_IDS" => ["abc", "def"]
8
+ "REQUEST_IDS" => ["abc", "def"],
7
9
  }
8
10
  end
9
11