pliny 0.26.1 → 0.29.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e4adaaedbebc3ae5352103ddadbf1f85ee0ea368
4
- data.tar.gz: d0c837f014f54d02eb7cc28903fdec073502564b
2
+ SHA256:
3
+ metadata.gz: e47d761bd19ec78a4558b81ab7018a268bea25545895a67c07f21623699c21ba
4
+ data.tar.gz: ee9b112e0a31a4e9646d3e60b02f8c8538440c770dae8c6376031bbad285b7dd
5
5
  SHA512:
6
- metadata.gz: f50ff132e89a39ca8d28c9e873dd3f85a9d4fb2210fda66eaa7634af7a4a4647db0e5e158554add566dbdea69400c70332317153e45aa945315466a9b64ea58a
7
- data.tar.gz: 88082d4d62b2b4b6e59011dfa22420f942242990fe32256be729f91400b5b5ab6d92035353c710053a82977db99dfc5929eccc7f0eca4bea1fe9488e05b21ac8
6
+ metadata.gz: 3e5682954ac33fa5b7231c50cc59101c4fe811611e21cdc9ffc0eb06d586281692d5bc6c9231f0d553cc4b3cc275640b953cd239d219c46576d2425725f92f72
7
+ data.tar.gz: 0be3d40932b255ca70c0101cfd20a5680d5bc01fd61d8d448d27ca9f4c52043d25ec48af172122f30ab28ef4a37315c37f28358feec36edebcf7bf068a24560d
@@ -8,6 +8,7 @@ require_relative "pliny/errors"
8
8
  require_relative "pliny/helpers/encode"
9
9
  require_relative "pliny/helpers/params"
10
10
  require_relative "pliny/helpers/serialize"
11
+ require_relative "pliny/helpers/zulu_time"
11
12
  require_relative "pliny/log"
12
13
  require_relative "pliny/metrics/backends/logger"
13
14
  require_relative "pliny/metrics"
@@ -1,7 +1,7 @@
1
- require 'fileutils'
2
- require 'pathname'
3
- require 'pliny/version'
4
- require 'uri'
1
+ require "fileutils"
2
+ require "pathname"
3
+ require "pliny/version"
4
+ require "uri"
5
5
 
6
6
  module Pliny::Commands
7
7
  class Updater
@@ -37,7 +37,7 @@ module Pliny::Commands
37
37
 
38
38
  # we need a local copy of the pliny repo to produce a diff
39
39
  def ensure_repo_available
40
- if File.exists?(repo_dir)
40
+ if File.exist?(repo_dir)
41
41
  unless system("cd #{repo_dir} && git fetch --tags")
42
42
  abort("Could not update Pliny repo at #{repo_dir}")
43
43
  end
@@ -1,6 +1,7 @@
1
1
  require "logger"
2
2
  require "sequel"
3
3
  require "sequel/extensions/migration"
4
+ require "stringio"
4
5
 
5
6
  module Pliny
6
7
  class DbSupport
@@ -21,6 +21,7 @@ module Pliny
21
21
  scope = { custom: context }
22
22
  unless rack_env.empty?
23
23
  scope[:request] = proc { extract_request_data_from_rack(rack_env) }
24
+ scope[:person] = proc { extract_person_data_from_controller(rack_env) }
24
25
  end
25
26
  scope
26
27
  rescue Exception => e
@@ -21,10 +21,21 @@ module Pliny::Helpers
21
21
  def load_params(data)
22
22
  # Sinatra 1.x only supports the method. Sinatra 2.x only supports the class
23
23
  if defined?(Sinatra::IndifferentHash)
24
- Sinatra::IndifferentHash[data]
24
+ indifferent_params_v2(data)
25
25
  else
26
26
  indifferent_params(data)
27
27
  end
28
28
  end
29
+
30
+ def indifferent_params_v2(data)
31
+ case data
32
+ when Hash
33
+ Sinatra::IndifferentHash[data]
34
+ when Array
35
+ data.map { |item| indifferent_params_v2(item) }
36
+ else
37
+ data
38
+ end
39
+ end
29
40
  end
30
41
  end
@@ -1,42 +1,41 @@
1
1
  module Pliny::Helpers
2
2
  module Serialize
3
- def self.included(base)
4
- base.send :extend, ClassMethods
3
+ def self.registered(base)
4
+ base.helpers Helpers
5
+ base.set :serializer_class, nil
5
6
  end
6
7
 
7
- def serialize(data, structure = :default)
8
- serializer_class = self.class.serializer_class
8
+ module Helpers
9
+ def serialize(data, structure = :default)
10
+ serializer_class = settings.serializer_class
9
11
 
10
- if serializer_class.nil?
11
- raise <<-eos.strip
12
- No serializer has been specified for this endpoint. Please specify one with
13
- `serializer Serializers::ModelName` in the endpoint.
14
- eos
15
- end
12
+ if serializer_class.nil?
13
+ raise <<~eos.strip
14
+ No serializer has been specified for this endpoint. Please specify one with
15
+ `serializer Serializers::ModelName` in the endpoint.
16
+ eos
17
+ end
16
18
 
17
- env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
19
+ env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
18
20
 
19
- start = Time.now
20
- serializer_class.new(structure).serialize(data).tap do
21
- env['pliny.serializer_timing'] = (Time.now - start).to_f
21
+ start = Time.now
22
+ serializer_class.new(structure).serialize(data).tap do
23
+ env['pliny.serializer_timing'] = (Time.now - start).to_f
24
+ end
22
25
  end
23
26
  end
24
27
 
25
- module ClassMethods
26
- # Provide a way to specify endpoint serializer class.
27
- #
28
- # class Endpoints::User < Base
29
- # serializer Serializers::User
30
- #
31
- # get do
32
- # encode serialize(User.all)
33
- # end
34
- # end
35
- def serializer(serializer_class)
36
- @serializer_class = serializer_class
37
- end
38
-
39
- attr_reader :serializer_class
28
+ # Provide a way to specify endpoint serializer class.
29
+ #
30
+ # class Endpoints::User < Base
31
+ # serializer Serializers::User
32
+ #
33
+ # get do
34
+ # encode serialize(User.all)
35
+ # end
36
+ # end
37
+ def serializer(serializer_class)
38
+ set :serializer_class, serializer_class
40
39
  end
41
40
  end
42
41
  end
@@ -0,0 +1,7 @@
1
+ module Pliny::Helpers
2
+ module ZuluTime
3
+ def zulu_time(time)
4
+ time ? time.getutc.strftime("%Y-%m-%dT%H:%M:%SZ") : nil
5
+ end
6
+ end
7
+ end
@@ -124,7 +124,6 @@ module Pliny
124
124
  end
125
125
 
126
126
  def quote_string(k, v)
127
- # try to find a quote style that fits
128
127
  if !v.include?('"')
129
128
  %{#{k}="#{v}"}
130
129
  elsif !v.include?("'")
@@ -140,19 +139,22 @@ module Pliny
140
139
 
141
140
  def unparse_pair(k, v)
142
141
  v = v.call if v.is_a?(Proc)
143
- # only quote strings if they include whitespace
142
+
144
143
  if v == nil
145
144
  nil
146
145
  elsif v == true
147
146
  k
148
147
  elsif v.is_a?(Float)
149
148
  "#{k}=#{format("%.3f", v)}"
150
- elsif v.is_a?(String) && v =~ /\s/
151
- quote_string(k, v)
152
149
  elsif v.is_a?(Time)
153
150
  "#{k}=#{v.iso8601}"
154
151
  else
155
- "#{k}=#{v}"
152
+ v = "#{v}"
153
+ if v =~ /\s/
154
+ quote_string(k, v)
155
+ else
156
+ "#{k}=#{v}"
157
+ end
156
158
  end
157
159
  end
158
160
  end
@@ -32,12 +32,12 @@ begin
32
32
 
33
33
  desc "Seed the database with data"
34
34
  task :seed do
35
- if File.exist?('./db/seeds.rb')
35
+ if File.exist?("./db/seeds.rb")
36
36
  database_urls.each do |database_url|
37
37
  # make a DB instance available to the seeds file
38
- self.class.send(:remove_const, 'DB') if self.class.const_defined?('DB')
39
- self.class.const_set('DB', Sequel.connect(database_url))
40
- load 'db/seeds.rb'
38
+ self.class.send(:remove_const, "DB") if self.class.const_defined?("DB")
39
+ self.class.const_set("DB", Sequel.connect(database_url))
40
+ load "db/seeds.rb"
41
41
  end
42
42
  disconnect
43
43
  end
@@ -66,7 +66,7 @@ begin
66
66
  admin_url = Pliny::DbSupport.admin_url(database_url)
67
67
  db = Sequel.connect(admin_url)
68
68
  name = name_from_uri(database_url)
69
- db.run(%{DROP DATABASE IF EXISTS "#{name}"})
69
+ db.run(%(DROP DATABASE IF EXISTS "#{name}"))
70
70
  puts "Dropped `#{name}`"
71
71
  end
72
72
  disconnect
@@ -75,7 +75,7 @@ begin
75
75
  namespace :schema do
76
76
  desc "Load the database schema"
77
77
  task :load do
78
- if File.exists?("./db/schema.sql")
78
+ if File.exist?("./db/schema.sql")
79
79
  schema = File.read("./db/schema.sql")
80
80
  database_urls.each do |database_url|
81
81
  db = Sequel.connect(database_url)
@@ -107,7 +107,7 @@ begin
107
107
  search_path = db.dataset.with_sql("SHOW search_path").single_value
108
108
  schema << "SET search_path = #{search_path};\n\n"
109
109
 
110
- db[:schema_migrations].each do |migration|
110
+ db[:schema_migrations].order_by(:filename).each do |migration|
111
111
  schema << db[:schema_migrations].insert_sql(migration) + ";\n"
112
112
  end
113
113
  end
@@ -118,14 +118,14 @@ begin
118
118
  end
119
119
 
120
120
  desc "Merges migrations into schema and removes them"
121
- task :merge => ["db:setup", "db:schema:dump"] do
121
+ task merge: ["db:setup", "db:schema:dump"] do
122
122
  FileUtils.rm Dir["./db/migrate/*.rb"]
123
123
  puts "Removed migrations"
124
124
  end
125
125
  end
126
126
 
127
127
  desc "Setup the database"
128
- task :setup => [:drop, :create, "schema:load", :migrate, :seed]
128
+ task setup: [:drop, :create, "schema:load", :migrate, :seed]
129
129
 
130
130
  private
131
131
 
@@ -138,12 +138,10 @@ begin
138
138
  if ENV["DATABASE_URL"]
139
139
  [ENV["DATABASE_URL"]]
140
140
  else
141
- %w(.env .env.test).map { |env_file|
141
+ %w[.env .env.test].map { |env_file|
142
142
  env_path = "./#{env_file}"
143
- if File.exists?(env_path)
143
+ if File.exist?(env_path)
144
144
  Pliny::Utils.parse_env(env_path)["DATABASE_URL"]
145
- else
146
- nil
147
145
  end
148
146
  }.compact
149
147
  end
@@ -153,7 +151,6 @@ begin
153
151
  URI.parse(uri).path[1..-1]
154
152
  end
155
153
  end
156
-
157
154
  rescue LoadError
158
155
  puts "Couldn't load sequel. Skipping database tasks"
159
156
  end
@@ -10,9 +10,9 @@
10
10
  <%= ident %>class <%= modules.last %> < Serializers::Base
11
11
  <%= ident %> structure(:default) do |arg|
12
12
  <%= ident %> {
13
- <%= ident %> created_at: arg.created_at.try(:iso8601),
13
+ <%= ident %> created_at: zulu_time(arg.created_at),
14
14
  <%= ident %> id: arg.id,
15
- <%= ident %> updated_at: arg.updated_at.try(:iso8601),
15
+ <%= ident %> updated_at: zulu_time(arg.updated_at)
16
16
  <%= ident %> }
17
17
  <%= ident %> end
18
18
  <%= ident %>end
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.26.1"
2
+ VERSION = "0.29.0"
3
3
  end
@@ -4,7 +4,7 @@ ruby "2.4.0"
4
4
  gem "multi_json"
5
5
  gem "oj"
6
6
  gem "pg"
7
- gem "pliny", "~> 0.26"
7
+ gem "pliny", "~> 0.28"
8
8
  gem "pry"
9
9
  gem "puma", "~> 3"
10
10
  gem "rack-ssl"
@@ -21,7 +21,7 @@ gem "sucker_punch"
21
21
 
22
22
  group :development, :test do
23
23
  gem "pry-byebug"
24
- gem "rubocop", "~> 0.46.0", require: false
24
+ gem "rubocop", "~> 0.52.1", require: false
25
25
  gem "rubocop-rspec", require: false
26
26
  end
27
27
 
@@ -5,7 +5,7 @@ module Endpoints
5
5
 
6
6
  helpers Pliny::Helpers::Encode
7
7
  helpers Pliny::Helpers::Params
8
- helpers Pliny::Helpers::Serialize
8
+ register Pliny::Helpers::Serialize
9
9
 
10
10
  set :dump_errors, false
11
11
  set :raise_errors, true
@@ -1,5 +1,7 @@
1
1
  module Serializers
2
2
  class Base
3
+ extend Pliny::Helpers::ZuluTime
4
+
3
5
  @@structures = {}
4
6
 
5
7
  def self.structure(type, &blk)
@@ -1,5 +1,5 @@
1
- require 'pliny/commands/creator'
2
- require 'spec_helper'
1
+ require "pliny/commands/creator"
2
+ require "spec_helper"
3
3
 
4
4
  describe Pliny::Commands::Creator do
5
5
  before do
@@ -7,21 +7,23 @@ describe Pliny::Commands::Creator do
7
7
  end
8
8
 
9
9
  describe "#run!" do
10
- before do
11
- FileUtils.rm_rf("/tmp/plinytest")
12
- FileUtils.mkdir_p("/tmp/plinytest")
13
- Dir.chdir("/tmp/plinytest")
10
+ around do |example|
11
+ Dir.mktmpdir("plinytest-") do |dir|
12
+ Dir.chdir(dir) do
13
+ example.run
14
+ end
15
+ end
14
16
  end
15
17
 
16
18
  it "copies the template app over" do
17
19
  @gen.run!
18
- assert File.exists?("./foobar")
19
- assert File.exists?("./foobar/Gemfile")
20
+ assert File.exist?("./foobar")
21
+ assert File.exist?("./foobar/Gemfile")
20
22
  end
21
23
 
22
24
  it "deletes the .git from it" do
23
25
  @gen.run!
24
- refute File.exists?("./foobar/.git")
26
+ refute File.exist?("./foobar/.git")
25
27
  end
26
28
 
27
29
  it "deletes the .erb files from it" do
@@ -31,25 +33,25 @@ describe Pliny::Commands::Creator do
31
33
 
32
34
  it "changes DATABASE_URL in .env.sample to use the app name" do
33
35
  @gen.run!
34
- db_url = File.read("./foobar/.env.sample").split("\n").detect do |line|
36
+ db_url = File.read("./foobar/.env.sample").split("\n").detect { |line|
35
37
  line.include?("DATABASE_URL=")
36
- end
38
+ }
37
39
  assert_equal "DATABASE_URL=postgres:///foobar-development", db_url
38
40
  end
39
41
 
40
42
  it "changes DATABASE_URL in .env.test to use the app name" do
41
43
  @gen.run!
42
- db_url = File.read("./foobar/.env.test").split("\n").detect do |line|
44
+ db_url = File.read("./foobar/.env.test").split("\n").detect { |line|
43
45
  line.include?("DATABASE_URL=")
44
- end
46
+ }
45
47
  assert_equal "DATABASE_URL=postgres:///foobar-test", db_url
46
48
  end
47
49
 
48
50
  it "changes APP_NAME in app.json to use the app name" do
49
51
  @gen.run!
50
- db_url = File.read("./foobar/app.json").split("\n").detect do |line|
52
+ db_url = File.read("./foobar/app.json").split("\n").detect { |line|
51
53
  line.include?("\"name\":")
52
- end
54
+ }
53
55
  assert_equal " \"name\": \"foobar\",", db_url
54
56
  end
55
57
  end
@@ -1,5 +1,5 @@
1
- require 'pliny/commands/updater'
2
- require 'spec_helper'
1
+ require "pliny/commands/updater"
2
+ require "spec_helper"
3
3
 
4
4
  describe Pliny::Commands::Updater do
5
5
  before do
@@ -10,19 +10,21 @@ describe Pliny::Commands::Updater do
10
10
  end
11
11
 
12
12
  describe "#run!" do
13
- before do
14
- FileUtils.rm_rf("/tmp/plinytest")
15
- FileUtils.mkdir_p("/tmp/plinytest")
16
- Dir.chdir("/tmp/plinytest")
17
- File.open("/tmp/plinytest/Gemfile.lock", "w") do |f|
18
- f.puts " pliny (0.6.3)"
13
+ around do |example|
14
+ Dir.mktmpdir("plinytest-") do |dir|
15
+ Dir.chdir(dir) do
16
+ File.open("./Gemfile.lock", "w") do |f|
17
+ f.puts " pliny (0.6.3)"
18
+ end
19
+ example.run
20
+ end
19
21
  end
20
22
  end
21
23
 
22
24
  it "creates a patch with Pliny diffs between the two versions" do
23
25
  @cmd.run!
24
26
  patch = File.read(@cmd.patch_file)
25
- assert patch.include?('--- a/Gemfile')
27
+ assert patch.include?("--- a/Gemfile")
26
28
  assert patch.include?('-gem "pliny", "~> 0.6"')
27
29
  end
28
30
  end
@@ -6,15 +6,18 @@ describe Pliny::DbSupport do
6
6
  let(:logger) { Logger.new(StringIO.new) }
7
7
  let(:support) { Pliny::DbSupport.new(url, logger) }
8
8
 
9
- before do
10
- @path = "/tmp/pliny-test"
9
+ around do |example|
10
+ Dir.mktmpdir("plinytest-") do |dir|
11
+ Dir.chdir(dir) do
12
+ FileUtils.mkdir_p("./db/migrate")
13
+
14
+ example.run
15
+ end
16
+ end
11
17
  end
12
18
 
13
- before(:each) do
19
+ before do
14
20
  DB.tables.each { |t| DB.drop_table(t) }
15
- FileUtils.rm_rf(@path)
16
- FileUtils.mkdir_p("#{@path}/db/migrate")
17
- Dir.chdir(@path)
18
21
  end
19
22
 
20
23
  describe ".admin_url" do
@@ -33,7 +36,7 @@ describe Pliny::DbSupport do
33
36
 
34
37
  describe "#migrate" do
35
38
  before do
36
- File.open("#{@path}/db/migrate/#{Time.now.to_i}_create_foo.rb", "w") do |f|
39
+ File.open("./db/migrate/#{Time.now.to_i}_create_foo.rb", "w") do |f|
37
40
  f.puts "
38
41
  Sequel.migration do
39
42
  change do
@@ -57,11 +60,11 @@ describe Pliny::DbSupport do
57
60
  describe "#rollback" do
58
61
  before do
59
62
  @t = Time.now
60
- File.open("#{@path}/db/migrate/#{(@t-2).to_i}_first.rb", "w") do |f|
63
+ File.open("./db/migrate/#{(@t - 2).to_i}_first.rb", "w") do |f|
61
64
  f.puts "Sequel.migration { change { create_table(:first) } }"
62
65
  end
63
66
 
64
- File.open("#{@path}/db/migrate/#{(@t-1).to_i}_second.rb", "w") do |f|
67
+ File.open("./db/migrate/#{(@t - 1).to_i}_second.rb", "w") do |f|
65
68
  f.puts "Sequel.migration { change { create_table(:second) } }"
66
69
  end
67
70
  end
@@ -80,7 +83,7 @@ describe Pliny::DbSupport do
80
83
  end
81
84
 
82
85
  it "handles databases not migrated (schema_migrations is empty)" do
83
- support.migrate (@t-2).to_i
86
+ support.migrate((@t - 2).to_i)
84
87
  support.rollback # destroy table, leave schema_migrations
85
88
  support.rollback # should noop
86
89
  end
@@ -33,6 +33,24 @@ describe Pliny::ErrorReporters::Rollbar do
33
33
  ))
34
34
  end
35
35
 
36
+ context "given a rack_env with person data" do
37
+ let(:rack_env) do
38
+ { "rollbar.person_data" => {
39
+ id: SecureRandom.uuid,
40
+ email: "foo@bar.com",
41
+ username: "foo"
42
+ }}
43
+ end
44
+
45
+ it "adds person to the rollbar notification" do
46
+ scope = nil
47
+ allow(::Rollbar).to receive(:scoped) { |arg| scope = arg }
48
+ notify
49
+ assert_kind_of(Proc, scope[:person])
50
+ assert_equal(rack_env["rollbar.person_data"], scope[:person].call)
51
+ end
52
+ end
53
+
36
54
  it "delegates to #report_exception_to_rollbar" do
37
55
  notify
38
56
  expect(reporter).to have_received(:report_exception_to_rollbar)
@@ -1,7 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Pliny::Helpers::Params do
4
-
5
4
  def app
6
5
  Sinatra.new do
7
6
  helpers Pliny::Helpers::Params
@@ -12,17 +11,27 @@ describe Pliny::Helpers::Params do
12
11
  end
13
12
 
14
13
  it "loads json params" do
15
- post "/", {hello: "world"}.to_json, {'CONTENT_TYPE' => 'application/json'}
14
+ post "/", {hello: "world"}.to_json, {"CONTENT_TYPE" => "application/json"}
16
15
  assert_equal "{\"hello\":\"world\"}", last_response.body
17
16
  end
18
17
 
18
+ it "loads json array of params" do
19
+ post "/", [{hello: "world"}, {goodbye: "moon"}].to_json, {"CONTENT_TYPE" => "application/json"}
20
+ assert_equal "[{\"hello\":\"world\"},{\"goodbye\":\"moon\"}]", last_response.body
21
+ end
22
+
23
+ it "loads json array of arrays of params" do
24
+ post "/", [[{hello: "world"}], [{goodbye: "moon"}]].to_json, {"CONTENT_TYPE" => "application/json"}
25
+ assert_equal "[[{\"hello\":\"world\"}],[{\"goodbye\":\"moon\"}]]", last_response.body
26
+ end
27
+
19
28
  it "loads form data params" do
20
29
  post "/", {hello: "world"}
21
30
  assert_equal "{\"hello\":\"world\"}", last_response.body
22
31
  end
23
32
 
24
33
  it "loads from an unknown content type" do
25
- post "/", "<hello>world</hello>", {'CONTENT_TYPE' => 'application/xml'}
34
+ post "/", "<hello>world</hello>", {"CONTENT_TYPE" => "application/xml"}
26
35
  assert_equal "{}", last_response.body
27
36
  end
28
37
  end
@@ -4,7 +4,7 @@ describe Pliny::Helpers::Serialize do
4
4
  context "without a serializer" do
5
5
  def app
6
6
  Sinatra.new do
7
- helpers Pliny::Helpers::Serialize
7
+ register Pliny::Helpers::Serialize
8
8
 
9
9
  get "/" do
10
10
  MultiJson.encode(serialize([]))
@@ -29,7 +29,7 @@ describe Pliny::Helpers::Serialize do
29
29
 
30
30
  def app
31
31
  Sinatra.new do
32
- helpers Pliny::Helpers::Serialize
32
+ register Pliny::Helpers::Serialize
33
33
 
34
34
  serializer Serializer
35
35
 
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+ require "active_support/core_ext/numeric/time"
3
+
4
+ describe Pliny::Helpers::ZuluTime do
5
+ context "zulu_time" do
6
+ class ZuluTimeTest
7
+ extend Pliny::Helpers::ZuluTime
8
+ end
9
+
10
+ it "it formats Time instances" do
11
+ formatted = ZuluTimeTest.zulu_time(Time.parse("2017-11-28T21:49:52.123+00:00"))
12
+ assert_equal "2017-11-28T21:49:52Z", formatted
13
+ end
14
+
15
+ it "it formats DateTime instances" do
16
+ formatted = ZuluTimeTest.zulu_time(DateTime.parse("2017-11-28T21:49:52.123+00:00"))
17
+ assert_equal "2017-11-28T21:49:52Z", formatted
18
+ end
19
+
20
+ it "when called with nil" do
21
+ assert_nil ZuluTimeTest.zulu_time(nil)
22
+ end
23
+ end
24
+ end
@@ -2,19 +2,24 @@ require "spec_helper"
2
2
 
3
3
  describe "Pliny integration test" do
4
4
  before(:all) do
5
- FileUtils.rm_rf("/tmp/plinytest")
6
- FileUtils.mkdir_p("/tmp/plinytest")
7
- Dir.chdir("/tmp/plinytest")
5
+ @original_dir = Dir.pwd
6
+
7
+ test_dir = Dir.mktmpdir("plinytest-")
8
+ Dir.chdir(test_dir)
8
9
 
9
10
  bash "pliny-new myapp"
10
11
 
11
- Dir.chdir("/tmp/plinytest/myapp")
12
+ Dir.chdir("myapp")
12
13
  bash "bin/setup"
13
14
  end
14
15
 
16
+ after(:all) do
17
+ Dir.chdir(@original_dir)
18
+ end
19
+
15
20
  describe "bin/setup" do
16
21
  it "generates .env" do
17
- assert File.exists?("./.env")
22
+ assert File.exist?("./.env")
18
23
  end
19
24
  end
20
25
 
@@ -24,19 +29,19 @@ describe "Pliny integration test" do
24
29
  end
25
30
 
26
31
  it "creates the model file" do
27
- assert File.exists?("./lib/models/artist.rb")
32
+ assert File.exist?("./lib/models/artist.rb")
28
33
  end
29
34
 
30
35
  it "creates the endpoint file" do
31
- assert File.exists?("./lib/endpoints/artists.rb")
36
+ assert File.exist?("./lib/endpoints/artists.rb")
32
37
  end
33
38
 
34
39
  it "creates the serializer file" do
35
- assert File.exists?("./lib/serializers/artist.rb")
40
+ assert File.exist?("./lib/serializers/artist.rb")
36
41
  end
37
42
 
38
43
  it "creates the schema file" do
39
- assert File.exists?("./schema/schemata/artist.yaml")
44
+ assert File.exist?("./schema/schemata/artist.yaml")
40
45
  end
41
46
  end
42
47
 
@@ -5,7 +5,6 @@ describe Pliny::Log do
5
5
  @io = StringIO.new
6
6
  Pliny.stdout = @io
7
7
  Pliny.stderr = @io
8
- allow(@io).to receive(:print)
9
8
  end
10
9
 
11
10
  after do
@@ -130,4 +129,66 @@ describe Pliny::Log do
130
129
  end
131
130
  end
132
131
  end
132
+
133
+ describe "unparsing" do
134
+ it "removes nils from log" do
135
+ expect(@io).to receive(:print).with("\n")
136
+
137
+ Pliny.log(foo: nil)
138
+ end
139
+
140
+ it "leaves bare keys for true values" do
141
+ expect(@io).to receive(:print).with("foo\n")
142
+
143
+ Pliny.log(foo: true)
144
+ end
145
+
146
+ it "truncates floats" do
147
+ expect(@io).to receive(:print).with("foo=3.142\n")
148
+
149
+ Pliny.log(foo: Math::PI)
150
+ end
151
+
152
+ it "outputs times in ISO8601 format" do
153
+ expect(@io).to receive(:print).with("foo=2020-01-01T00:00:00Z\n")
154
+
155
+ Pliny.log(foo: Time.utc(2020))
156
+ end
157
+
158
+ it "quotes strings that contain spaces" do
159
+ expect(@io).to receive(:print).with("foo=\"string with spaces\"\n")
160
+
161
+ Pliny.log(foo: "string with spaces")
162
+ end
163
+
164
+ it "by default interpolates objects into strings" do
165
+ expect(@io).to receive(:print).with("foo=message\n")
166
+ expect(@io).to receive(:print).with("foo=42\n")
167
+ expect(@io).to receive(:print).with("foo=bar\n")
168
+
169
+ Pliny.log(foo: StandardError.new("message"))
170
+ Pliny.log(foo: 42)
171
+
172
+ klass = Class.new do
173
+ def to_s
174
+ "bar"
175
+ end
176
+ end
177
+ Pliny.log(foo: klass.new)
178
+ end
179
+
180
+ it "quotes strings that are generated from object interpolation" do
181
+ expect(@io).to receive(:print).with("foo=\"message with space\"\n")
182
+ expect(@io).to receive(:print).with("foo=\"bar with space\"\n")
183
+
184
+ Pliny.log(foo: StandardError.new("message with space"))
185
+
186
+ klass = Class.new do
187
+ def to_s
188
+ "bar with space"
189
+ end
190
+ end
191
+ Pliny.log(foo: klass.new)
192
+ end
193
+ end
133
194
  end
metadata CHANGED
@@ -1,36 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pliny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.1
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur Leach
8
8
  - Pedro Belo
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-04 00:00:00.000000000 Z
12
+ date: 2020-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '5.0'
21
18
  - - ">="
22
19
  - !ruby/object:Gem::Version
23
20
  version: 5.0.1
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '7.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: '5.0'
31
28
  - - ">="
32
29
  - !ruby/object:Gem::Version
33
30
  version: 5.0.1
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: multi_json
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -157,60 +157,48 @@ dependencies:
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: '0.8'
161
- - - ">="
162
- - !ruby/object:Gem::Version
163
- version: 0.8.7
160
+ version: '13.0'
164
161
  type: :development
165
162
  prerelease: false
166
163
  version_requirements: !ruby/object:Gem::Requirement
167
164
  requirements:
168
165
  - - "~>"
169
166
  - !ruby/object:Gem::Version
170
- version: '0.8'
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: 0.8.7
167
+ version: '13.0'
174
168
  - !ruby/object:Gem::Dependency
175
169
  name: rack-test
176
170
  requirement: !ruby/object:Gem::Requirement
177
171
  requirements:
178
172
  - - "~>"
179
173
  - !ruby/object:Gem::Version
180
- version: '0.6'
181
- - - ">="
182
- - !ruby/object:Gem::Version
183
- version: 0.6.2
174
+ version: 1.1.0
184
175
  type: :development
185
176
  prerelease: false
186
177
  version_requirements: !ruby/object:Gem::Requirement
187
178
  requirements:
188
179
  - - "~>"
189
180
  - !ruby/object:Gem::Version
190
- version: '0.6'
191
- - - ">="
192
- - !ruby/object:Gem::Version
193
- version: 0.6.2
181
+ version: 1.1.0
194
182
  - !ruby/object:Gem::Dependency
195
183
  name: rspec
196
184
  requirement: !ruby/object:Gem::Requirement
197
185
  requirements:
198
- - - "~>"
199
- - !ruby/object:Gem::Version
200
- version: '3.1'
201
186
  - - ">="
202
187
  - !ruby/object:Gem::Version
203
188
  version: 3.1.0
189
+ - - "~>"
190
+ - !ruby/object:Gem::Version
191
+ version: '3.1'
204
192
  type: :development
205
193
  prerelease: false
206
194
  version_requirements: !ruby/object:Gem::Requirement
207
195
  requirements:
208
- - - "~>"
209
- - !ruby/object:Gem::Version
210
- version: '3.1'
211
196
  - - ">="
212
197
  - !ruby/object:Gem::Version
213
198
  version: 3.1.0
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '3.1'
214
202
  - !ruby/object:Gem::Dependency
215
203
  name: sinatra-contrib
216
204
  requirement: !ruby/object:Gem::Requirement
@@ -303,62 +291,62 @@ dependencies:
303
291
  name: rollbar
304
292
  requirement: !ruby/object:Gem::Requirement
305
293
  requirements:
306
- - - "~>"
307
- - !ruby/object:Gem::Version
308
- version: '2.11'
309
294
  - - ">="
310
295
  - !ruby/object:Gem::Version
311
296
  version: 2.11.0
297
+ - - "~>"
298
+ - !ruby/object:Gem::Version
299
+ version: '2.11'
312
300
  type: :development
313
301
  prerelease: false
314
302
  version_requirements: !ruby/object:Gem::Requirement
315
303
  requirements:
316
- - - "~>"
317
- - !ruby/object:Gem::Version
318
- version: '2.11'
319
304
  - - ">="
320
305
  - !ruby/object:Gem::Version
321
306
  version: 2.11.0
307
+ - - "~>"
308
+ - !ruby/object:Gem::Version
309
+ version: '2.11'
322
310
  - !ruby/object:Gem::Dependency
323
311
  name: sequel
324
312
  requirement: !ruby/object:Gem::Requirement
325
313
  requirements:
326
- - - "~>"
327
- - !ruby/object:Gem::Version
328
- version: '4.9'
329
314
  - - ">="
330
315
  - !ruby/object:Gem::Version
331
316
  version: 4.9.0
317
+ - - "~>"
318
+ - !ruby/object:Gem::Version
319
+ version: '4.9'
332
320
  type: :development
333
321
  prerelease: false
334
322
  version_requirements: !ruby/object:Gem::Requirement
335
323
  requirements:
336
- - - "~>"
337
- - !ruby/object:Gem::Version
338
- version: '4.9'
339
324
  - - ">="
340
325
  - !ruby/object:Gem::Version
341
326
  version: 4.9.0
327
+ - - "~>"
328
+ - !ruby/object:Gem::Version
329
+ version: '4.9'
342
330
  - !ruby/object:Gem::Dependency
343
331
  name: rubocop
344
332
  requirement: !ruby/object:Gem::Requirement
345
333
  requirements:
346
334
  - - "~>"
347
335
  - !ruby/object:Gem::Version
348
- version: '0.46'
336
+ version: '0.52'
349
337
  - - ">="
350
338
  - !ruby/object:Gem::Version
351
- version: 0.46.0
339
+ version: 0.52.1
352
340
  type: :development
353
341
  prerelease: false
354
342
  version_requirements: !ruby/object:Gem::Requirement
355
343
  requirements:
356
344
  - - "~>"
357
345
  - !ruby/object:Gem::Version
358
- version: '0.46'
346
+ version: '0.52'
359
347
  - - ">="
360
348
  - !ruby/object:Gem::Version
361
- version: 0.46.0
349
+ version: 0.52.1
362
350
  description: Pliny is a set of base classes and helpers to help developers write excellent
363
351
  APIs in Sinatra
364
352
  email:
@@ -395,6 +383,7 @@ files:
395
383
  - lib/pliny/helpers/encode.rb
396
384
  - lib/pliny/helpers/params.rb
397
385
  - lib/pliny/helpers/serialize.rb
386
+ - lib/pliny/helpers/zulu_time.rb
398
387
  - lib/pliny/log.rb
399
388
  - lib/pliny/metrics.rb
400
389
  - lib/pliny/metrics/backends/logger.rb
@@ -490,6 +479,7 @@ files:
490
479
  - spec/helpers/encode_spec.rb
491
480
  - spec/helpers/params_spec.rb
492
481
  - spec/helpers/serialize_spec.rb
482
+ - spec/helpers/zulu_time_spec.rb
493
483
  - spec/integration_spec.rb
494
484
  - spec/log_spec.rb
495
485
  - spec/metrics/backends/logger_spec.rb
@@ -513,7 +503,7 @@ homepage: https://github.com/interagent/pliny
513
503
  licenses:
514
504
  - MIT
515
505
  metadata: {}
516
- post_install_message:
506
+ post_install_message:
517
507
  rdoc_options: []
518
508
  require_paths:
519
509
  - lib
@@ -528,9 +518,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
528
518
  - !ruby/object:Gem::Version
529
519
  version: '0'
530
520
  requirements: []
531
- rubyforge_project:
532
- rubygems_version: 2.6.13
533
- signing_key:
521
+ rubygems_version: 3.0.3
522
+ signing_key:
534
523
  specification_version: 4
535
524
  summary: Basic tooling to support API apps in Sinatra
536
525
  test_files: []