pliny 0.26.2 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0674c9e51c614274d0723faf5909baaf3bd30ae0
4
- data.tar.gz: cc4c3a90ffec075c45faec036c20e7c2952c8841
2
+ SHA256:
3
+ metadata.gz: 279c8a9ee0783e1a6627cdb320f5b1158861d2b780ba7c04ecfca5b3143d1714
4
+ data.tar.gz: c986b467e5647f3d9fef59636945b5a3beb554b47c89a5fae7bd4b324ed311fb
5
5
  SHA512:
6
- metadata.gz: 96e3f87b327e5f1dde9d38ac1c650c97c2444e150d7e517f7fc8ff3969f8809f129608441b7ba4f0b7eba68e157cc3dc13699edf8a56fe10dd24d27a8d350c42
7
- data.tar.gz: c715b6fd2f04af1869549d7999c1f2f0f79990a9f9e0eeb6de1b47b73f6895d7ebea913f5277f67988ab5c8b5a2bd58273feb6bd4fe5f919eef38854aeb98393
6
+ metadata.gz: 7a4720a9394893df84c2eb8eeb5b39afef82bb07f8b86289ab50fbdec600d874be6c0558ac0fbbb1e42f07fb33fda8bf2b1309dc179485179f3ec14e98b658ae
7
+ data.tar.gz: f70983c80a528a574c5be08037799593928b2c564b04a69f91a0f31be747da183f70bccc7dc9744fe692b5de36dfdb340984e4e306f9f4928031b4cbae612b35
@@ -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
@@ -8,9 +8,13 @@ module Pliny::Helpers
8
8
 
9
9
  def parse_body_params
10
10
  if request.media_type == "application/json"
11
- p = load_params(MultiJson.decode(request.body.read))
11
+ begin
12
+ decoded = MultiJson.decode(request.body.read)
13
+ rescue MultiJson::ParseError => e
14
+ raise Pliny::Errors::BadRequest, e.message
15
+ end
12
16
  request.body.rewind
13
- p
17
+ load_params(decoded)
14
18
  elsif request.form_data?
15
19
  load_params(request.POST)
16
20
  else
@@ -21,10 +25,21 @@ module Pliny::Helpers
21
25
  def load_params(data)
22
26
  # Sinatra 1.x only supports the method. Sinatra 2.x only supports the class
23
27
  if defined?(Sinatra::IndifferentHash)
24
- Sinatra::IndifferentHash[data]
28
+ indifferent_params_v2(data)
25
29
  else
26
30
  indifferent_params(data)
27
31
  end
28
32
  end
33
+
34
+ def indifferent_params_v2(data)
35
+ case data
36
+ when Hash
37
+ Sinatra::IndifferentHash[data]
38
+ when Array
39
+ data.map { |item| indifferent_params_v2(item) }
40
+ else
41
+ data
42
+ end
43
+ end
29
44
  end
30
45
  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
@@ -123,14 +123,17 @@ module Pliny
123
123
  end
124
124
  end
125
125
 
126
- def quote_string(k, v)
127
- # try to find a quote style that fits
126
+ def replace_newlines(v)
127
+ v.gsub("\n", "\\n")
128
+ end
129
+
130
+ def quote_string(v)
128
131
  if !v.include?('"')
129
- %{#{k}="#{v}"}
132
+ %{"#{v}"}
130
133
  elsif !v.include?("'")
131
- %{#{k}='#{v}'}
134
+ %{'#{v}'}
132
135
  else
133
- %{#{k}="#{v.gsub(/"/, '\\"')}"}
136
+ %{"#{v.gsub(/"/, '\\"')}"}
134
137
  end
135
138
  end
136
139
 
@@ -140,18 +143,20 @@ module Pliny
140
143
 
141
144
  def unparse_pair(k, v)
142
145
  v = v.call if v.is_a?(Proc)
143
- # only quote strings if they include whitespace
146
+
144
147
  if v == nil
145
148
  nil
146
149
  elsif v == true
147
150
  k
148
151
  elsif v.is_a?(Float)
149
152
  "#{k}=#{format("%.3f", v)}"
150
- elsif v.is_a?(String) && v =~ /\s/
151
- quote_string(k, v)
152
153
  elsif v.is_a?(Time)
153
154
  "#{k}=#{v.iso8601}"
154
155
  else
156
+ v = "#{v}"
157
+ v = replace_newlines(v)
158
+ v = quote_string(v) if v =~ /\s/
159
+
155
160
  "#{k}=#{v}"
156
161
  end
157
162
  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
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.26.2"
2
+ VERSION = "0.30.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,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
@@ -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,35 @@ 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
37
+
38
+ it "should throw bad request when receiving invalid json via post" do
39
+ err = assert_raises(Pliny::Errors::BadRequest) do
40
+ post "/", "{\"foo\"}", {"CONTENT_TYPE" => "application/json"}
41
+ end
42
+
43
+ assert_match /unexpected token/, err.message
44
+ end
28
45
  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
 
@@ -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,72 @@ 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 "replaces newlines in strings" do
165
+ expect(@io).to receive(:print).with("foo=\"string\\nwith newlines\\n\"\n")
166
+
167
+ Pliny.log(foo: "string\nwith newlines\n")
168
+ end
169
+
170
+ it "by default interpolates objects into strings" do
171
+ expect(@io).to receive(:print).with("foo=message\n")
172
+ expect(@io).to receive(:print).with("foo=42\n")
173
+ expect(@io).to receive(:print).with("foo=bar\n")
174
+
175
+ Pliny.log(foo: StandardError.new("message"))
176
+ Pliny.log(foo: 42)
177
+
178
+ klass = Class.new do
179
+ def to_s
180
+ "bar"
181
+ end
182
+ end
183
+ Pliny.log(foo: klass.new)
184
+ end
185
+
186
+ it "quotes strings that are generated from object interpolation" do
187
+ expect(@io).to receive(:print).with("foo=\"message with space\"\n")
188
+ expect(@io).to receive(:print).with("foo=\"bar with space\"\n")
189
+
190
+ Pliny.log(foo: StandardError.new("message with space"))
191
+
192
+ klass = Class.new do
193
+ def to_s
194
+ "bar with space"
195
+ end
196
+ end
197
+ Pliny.log(foo: klass.new)
198
+ end
199
+ end
133
200
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pliny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.2
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur Leach
@@ -9,28 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-15 00:00:00.000000000 Z
12
+ date: 2020-12-14 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:
@@ -530,8 +518,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
530
518
  - !ruby/object:Gem::Version
531
519
  version: '0'
532
520
  requirements: []
533
- rubyforge_project:
534
- rubygems_version: 2.6.13
521
+ rubygems_version: 3.0.3
535
522
  signing_key:
536
523
  specification_version: 4
537
524
  summary: Basic tooling to support API apps in Sinatra