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 +5 -5
- data/lib/pliny/commands/updater.rb +5 -5
- data/lib/pliny/db_support.rb +1 -0
- data/lib/pliny/helpers/params.rb +18 -3
- data/lib/pliny/helpers/serialize.rb +28 -29
- data/lib/pliny/log.rb +13 -8
- data/lib/pliny/tasks/db.rake +11 -14
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +2 -2
- data/lib/template/lib/endpoints/base.rb +1 -1
- data/spec/commands/creator_spec.rb +17 -15
- data/spec/commands/updater_spec.rb +11 -9
- data/spec/db_support_spec.rb +13 -10
- data/spec/helpers/params_spec.rb +20 -3
- data/spec/helpers/serialize_spec.rb +2 -2
- data/spec/integration_spec.rb +14 -9
- data/spec/log_spec.rb +68 -1
- metadata +35 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 279c8a9ee0783e1a6627cdb320f5b1158861d2b780ba7c04ecfca5b3143d1714
|
4
|
+
data.tar.gz: c986b467e5647f3d9fef59636945b5a3beb554b47c89a5fae7bd4b324ed311fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4720a9394893df84c2eb8eeb5b39afef82bb07f8b86289ab50fbdec600d874be6c0558ac0fbbb1e42f07fb33fda8bf2b1309dc179485179f3ec14e98b658ae
|
7
|
+
data.tar.gz: f70983c80a528a574c5be08037799593928b2c564b04a69f91a0f31be747da183f70bccc7dc9744fe692b5de36dfdb340984e4e306f9f4928031b4cbae612b35
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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.
|
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
|
data/lib/pliny/db_support.rb
CHANGED
data/lib/pliny/helpers/params.rb
CHANGED
@@ -8,9 +8,13 @@ module Pliny::Helpers
|
|
8
8
|
|
9
9
|
def parse_body_params
|
10
10
|
if request.media_type == "application/json"
|
11
|
-
|
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
|
-
|
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
|
-
|
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.
|
4
|
-
base.
|
3
|
+
def self.registered(base)
|
4
|
+
base.helpers Helpers
|
5
|
+
base.set :serializer_class, nil
|
5
6
|
end
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
module Helpers
|
9
|
+
def serialize(data, structure = :default)
|
10
|
+
serializer_class = settings.serializer_class
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
No serializer has been specified for this endpoint. Please specify one with
|
13
|
-
`serializer Serializers::ModelName` in the endpoint.
|
14
|
-
|
15
|
-
|
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
|
-
|
19
|
+
env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
data/lib/pliny/log.rb
CHANGED
@@ -123,14 +123,17 @@ module Pliny
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
def
|
127
|
-
|
126
|
+
def replace_newlines(v)
|
127
|
+
v.gsub("\n", "\\n")
|
128
|
+
end
|
129
|
+
|
130
|
+
def quote_string(v)
|
128
131
|
if !v.include?('"')
|
129
|
-
%{
|
132
|
+
%{"#{v}"}
|
130
133
|
elsif !v.include?("'")
|
131
|
-
%{
|
134
|
+
%{'#{v}'}
|
132
135
|
else
|
133
|
-
%{
|
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
|
-
|
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
|
data/lib/pliny/tasks/db.rake
CHANGED
@@ -32,12 +32,12 @@ begin
|
|
32
32
|
|
33
33
|
desc "Seed the database with data"
|
34
34
|
task :seed do
|
35
|
-
if File.exist?(
|
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,
|
39
|
-
self.class.const_set(
|
40
|
-
load
|
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(%
|
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.
|
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 :
|
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 :
|
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
|
141
|
+
%w[.env .env.test].map { |env_file|
|
142
142
|
env_path = "./#{env_file}"
|
143
|
-
if File.
|
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
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
@@ -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.
|
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.
|
24
|
+
gem "rubocop", "~> 0.52.1", require: false
|
25
25
|
gem "rubocop-rspec", require: false
|
26
26
|
end
|
27
27
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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.
|
19
|
-
assert File.
|
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.
|
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
|
36
|
+
db_url = File.read("./foobar/.env.sample").split("\n").detect { |line|
|
35
37
|
line.include?("DATABASE_URL=")
|
36
|
-
|
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
|
44
|
+
db_url = File.read("./foobar/.env.test").split("\n").detect { |line|
|
43
45
|
line.include?("DATABASE_URL=")
|
44
|
-
|
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
|
52
|
+
db_url = File.read("./foobar/app.json").split("\n").detect { |line|
|
51
53
|
line.include?("\"name\":")
|
52
|
-
|
54
|
+
}
|
53
55
|
assert_equal " \"name\": \"foobar\",", db_url
|
54
56
|
end
|
55
57
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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?(
|
27
|
+
assert patch.include?("--- a/Gemfile")
|
26
28
|
assert patch.include?('-gem "pliny", "~> 0.6"')
|
27
29
|
end
|
28
30
|
end
|
data/spec/db_support_spec.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
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
|
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("
|
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("
|
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("
|
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
|
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
|
data/spec/helpers/params_spec.rb
CHANGED
@@ -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, {
|
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>", {
|
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
|
-
|
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
|
-
|
32
|
+
register Pliny::Helpers::Serialize
|
33
33
|
|
34
34
|
serializer Serializer
|
35
35
|
|
data/spec/integration_spec.rb
CHANGED
@@ -2,19 +2,24 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Pliny integration test" do
|
4
4
|
before(:all) do
|
5
|
-
|
6
|
-
|
7
|
-
Dir.
|
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("
|
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.
|
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.
|
32
|
+
assert File.exist?("./lib/models/artist.rb")
|
28
33
|
end
|
29
34
|
|
30
35
|
it "creates the endpoint file" do
|
31
|
-
assert File.
|
36
|
+
assert File.exist?("./lib/endpoints/artists.rb")
|
32
37
|
end
|
33
38
|
|
34
39
|
it "creates the serializer file" do
|
35
|
-
assert File.
|
40
|
+
assert File.exist?("./lib/serializers/artist.rb")
|
36
41
|
end
|
37
42
|
|
38
43
|
it "creates the schema file" do
|
39
|
-
assert File.
|
44
|
+
assert File.exist?("./schema/schemata/artist.yaml")
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
data/spec/log_spec.rb
CHANGED
@@ -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.
|
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:
|
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
|
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
|
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:
|
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:
|
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.
|
336
|
+
version: '0.52'
|
349
337
|
- - ">="
|
350
338
|
- !ruby/object:Gem::Version
|
351
|
-
version: 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.
|
346
|
+
version: '0.52'
|
359
347
|
- - ">="
|
360
348
|
- !ruby/object:Gem::Version
|
361
|
-
version: 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
|
-
|
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
|