pliny 0.7.3 → 0.8.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
2
  SHA1:
3
- metadata.gz: 702133412ab83aee098c3fa82133553d080cbef8
4
- data.tar.gz: 6021eac4ce3f4281335cd272edf4ccb7ddea1d2c
3
+ metadata.gz: 1019acfa5b5b6e83005c8f795f10dce1841afc34
4
+ data.tar.gz: fdfe6d962f1e61e6ae60b81a0d577a7cae02892a
5
5
  SHA512:
6
- metadata.gz: 00abeaa10d12a504797759c4e71f70d387dac09fc84a13c47f777806fe83069d63a63f7a699fe298e6dbc769416d84a665342b4af071bd708ab4a75605613743
7
- data.tar.gz: cca368e25f7ced0ba28aefcebc52110a102ffe7e4e069b59ef274232baa0f648d2f8375caacaf432924bb6a24925b1171f4237983e8383ac03f3d4460a861209
6
+ metadata.gz: 341d1dd09d179a7bc5309b472773c983874e46bf73221965e360d430aab100fda09b9b2fc6864f0b21cb05576b436730d8e0690107695a7fae4aa1a38303cd85
7
+ data.tar.gz: dcda392183b6232a05b772b43b3fb6422c9533706fc977168371a78ebfecd427dd175e96fbae89429cfd70d8f76b74c14b8c9d1825c80eac6f76fe155b1046e9
@@ -1,4 +1,5 @@
1
1
  require "multi_json"
2
+ require "rack/timeout"
2
3
  require "sinatra/base"
3
4
 
4
5
  require_relative "pliny/version"
@@ -14,7 +15,6 @@ require_relative "pliny/middleware/cors"
14
15
  require_relative "pliny/middleware/request_id"
15
16
  require_relative "pliny/middleware/request_store"
16
17
  require_relative "pliny/middleware/rescue_errors"
17
- require_relative "pliny/middleware/timeout"
18
18
  require_relative "pliny/middleware/versioning"
19
19
 
20
20
  module Pliny
@@ -0,0 +1,46 @@
1
+ require "logger"
2
+ require "sequel"
3
+ require "sequel/extensions/migration"
4
+
5
+ module Pliny
6
+ class DbSupport
7
+ @@logger = nil
8
+
9
+ def self.logger=(logger)
10
+ @@logger=logger
11
+ end
12
+
13
+ def self.run(url)
14
+ instance = new(url)
15
+ yield instance
16
+ instance.disconnect
17
+ end
18
+
19
+ attr_accessor :db
20
+
21
+ def initialize(url)
22
+ @db = Sequel.connect(url)
23
+ if @@logger
24
+ @db.loggers << @@logger
25
+ end
26
+ end
27
+
28
+ def migrate
29
+ Sequel::Migrator.apply(db, "./db/migrate")
30
+ end
31
+
32
+ def rollback
33
+ migrations = Dir["./db/migrate/*.rb"].map { |f| File.basename(f).to_i }.sort
34
+ current = db[:schema_migrations].order(Sequel.desc(:filename)).first[:filename].to_i
35
+ target = 0 # by default, rollback everything
36
+ if i = migrations.index(current)
37
+ target = migrations[i - 1] || 0
38
+ end
39
+ Sequel::Migrator.apply(db, "./db/migrate", target)
40
+ end
41
+
42
+ def disconnect
43
+ @db.disconnect
44
+ end
45
+ end
46
+ end
@@ -1,7 +1,7 @@
1
1
  module Pliny
2
2
  module Log
3
3
  def log(data, &block)
4
- data = log_context.merge(local_context.merge(data))
4
+ data = default_context.merge(log_context.merge(local_context.merge(data)))
5
5
  log_to_stream(stdout || $stdout, data, &block)
6
6
  end
7
7
 
@@ -14,6 +14,14 @@ module Pliny
14
14
  res
15
15
  end
16
16
 
17
+ def default_context=(default_context)
18
+ @default_context = default_context
19
+ end
20
+
21
+ def default_context
22
+ @default_context || {}
23
+ end
24
+
17
25
  def stdout=(stream)
18
26
  @stdout = stream
19
27
  end
@@ -1,30 +1,34 @@
1
+ require "logger"
1
2
  require "sequel"
2
3
  require "sequel/extensions/migration"
3
4
  require "uri"
4
5
 
6
+ require "pliny/db_support"
5
7
  require "pliny/utils"
6
8
 
9
+ Pliny::DbSupport.logger = Logger.new($stdout)
10
+
7
11
  namespace :db do
8
12
  desc "Run database migrations"
9
13
  task :migrate do
10
14
  next if Dir["./db/migrate/*.rb"].empty?
11
15
  database_urls.each do |database_url|
12
- db = Sequel.connect(database_url)
13
- Sequel::Migrator.apply(db, "./db/migrate")
14
- puts "Migrated `#{name_from_uri(database_url)}`"
16
+ Pliny::DbSupport.run(database_url) do |helper|
17
+ helper.migrate
18
+ puts "Migrated `#{name_from_uri(database_url)}`"
19
+ end
15
20
  end
16
- disconnect
17
21
  end
18
22
 
19
- desc "Rollback the database"
23
+ desc "Rollback last database migration"
20
24
  task :rollback do
21
25
  next if Dir["./db/migrate/*.rb"].empty?
22
26
  database_urls.each do |database_url|
23
- db = Sequel.connect(database_url)
24
- Sequel::Migrator.apply(db, "./db/migrate", -1)
25
- puts "Rolled back `#{name_from_uri(database_url)}`"
27
+ Pliny::DbSupport.run(database_url) do |helper|
28
+ helper.rollback
29
+ puts "Rolled back `#{name_from_uri(database_url)}`"
30
+ end
26
31
  end
27
- disconnect
28
32
  end
29
33
 
30
34
  desc "Nuke the database (drop all tables)"
@@ -18,19 +18,19 @@ module Endpoints
18
18
  end
19
19
 
20
20
  get "/:id" do |id|
21
- <%= field_name %> = <%= singular_class_name %>.first(uuid: id) || halt(404)
21
+ <%= field_name %> = <%= singular_class_name %>.first(id: id) || halt(404)
22
22
  encode serialize(<%= field_name %>)
23
23
  end
24
24
 
25
25
  patch "/:id" do |id|
26
- <%= field_name %> = <%= singular_class_name %>.first(uuid: id) || halt(404)
26
+ <%= field_name %> = <%= singular_class_name %>.first(id: id) || halt(404)
27
27
  # warning: not safe
28
28
  #<%= field_name %>.update(body_params)
29
29
  encode serialize(<%= field_name %>)
30
30
  end
31
31
 
32
32
  delete "/:id" do |id|
33
- <%= field_name %> = <%= singular_class_name %>.first(uuid: id) || halt(404)
33
+ <%= field_name %> = <%= singular_class_name %>.first(id: id) || halt(404)
34
34
  <%= field_name %>.destroy
35
35
  encode serialize(<%= field_name %>)
36
36
  end
@@ -41,7 +41,7 @@ describe Endpoints::<%= plural_class_name %> do
41
41
 
42
42
  describe 'GET <%= url_path %>/:id' do
43
43
  it 'returns correct status code and conforms to schema' do
44
- get "<%= url_path %>/#{@<%= field_name %>.uuid}"
44
+ get "<%= url_path %>/#{@<%= field_name %>.id}"
45
45
  assert_equal 200, last_response.status
46
46
  assert_schema_conform
47
47
  end
@@ -50,7 +50,7 @@ describe Endpoints::<%= plural_class_name %> do
50
50
  describe 'PATCH <%= url_path %>/:id' do
51
51
  it 'returns correct status code and conforms to schema' do
52
52
  header "Content-Type", "application/json"
53
- patch "<%= url_path %>/#{@<%= field_name %>.uuid}", MultiJson.encode({})
53
+ patch "<%= url_path %>/#{@<%= field_name %>.id}", MultiJson.encode({})
54
54
  assert_equal 200, last_response.status
55
55
  assert_schema_conform
56
56
  end
@@ -58,7 +58,7 @@ describe Endpoints::<%= plural_class_name %> do
58
58
 
59
59
  describe 'DELETE <%= url_path %>/:id' do
60
60
  it 'returns correct status code and conforms to schema' do
61
- delete "<%= url_path %>/#{@<%= field_name %>.uuid}"
61
+ delete "<%= url_path %>/#{@<%= field_name %>.id}"
62
62
  assert_equal 200, last_response.status
63
63
  assert_schema_conform
64
64
  end
@@ -1,12 +1,12 @@
1
1
  Sequel.migration do
2
2
  change do
3
3
  create_table(:<%= table_name %>) do
4
- uuid :uuid, default: Sequel.function(:uuid_generate_v4), primary_key: true
4
+ uuid :id, default: Sequel.function(:uuid_generate_v4), primary_key: true
5
5
  timestamptz :created_at, default: Sequel.function(:now), null: false
6
- timestamptz :updated_at
7
6
  <% if paranoid %>
8
7
  timestamptz :deleted_at
9
8
  <% end %>
9
+ timestamptz :updated_at
10
10
  end
11
11
  end
12
12
  end
@@ -11,7 +11,7 @@
11
11
  <%= ident %> structure(:default) do |arg|
12
12
  <%= ident %> {
13
13
  <%= ident %> created_at: arg.created_at.try(:iso8601),
14
- <%= ident %> id: arg.uuid,
14
+ <%= ident %> id: arg.id,
15
15
  <%= ident %> updated_at: arg.updated_at.try(:iso8601),
16
16
  <%= ident %> }
17
17
  <%= ident %> end
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.7.3"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  DATABASE_URL=postgres://localhost/pliny-development
2
- RACK_ENV=development
2
+ PLINY_ENV=development
3
3
  TZ=UTC
4
4
  RAISE_ERRORS=true
5
5
  FORCE_SSL=false
@@ -1,5 +1,5 @@
1
1
  DATABASE_URL=postgres://localhost/pliny-test
2
- RACK_ENV=test
2
+ PLINY_ENV=test
3
3
  TZ=UTC
4
4
  RAISE_ERRORS=true
5
5
  FORCE_SSL=false
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.2.1
@@ -1,10 +1,10 @@
1
1
  source "https://rubygems.org"
2
- ruby "2.2.0"
2
+ ruby "2.2.1"
3
3
 
4
4
  gem "multi_json"
5
5
  gem "oj"
6
6
  gem "pg"
7
- gem "pliny", "~> 0.7"
7
+ gem "pliny", "~> 0.8"
8
8
  gem "pry"
9
9
  gem "puma", "~> 2.10"
10
10
  gem "rack-ssl"
@@ -23,6 +23,7 @@ group :development, :test do
23
23
  end
24
24
 
25
25
  group :test do
26
+ gem "simpleconv", require: false
26
27
  gem "committee"
27
28
  gem "database_cleaner"
28
29
  gem "dotenv"
@@ -25,9 +25,11 @@ module Config
25
25
  override :puma_min_threads, 1, int
26
26
  override :puma_workers, 3, int
27
27
  override :rack_env, 'development', string
28
+ override :pliny_env, 'development', string
28
29
  override :raise_errors, false, bool
29
30
  override :root, File.expand_path("../../", __FILE__), string
30
31
  override :timeout, 10, int
32
+ override :database_timeout, 10, int
31
33
  override :force_ssl, true, bool
32
34
  override :versioning, false, bool
33
35
  override :pretty_json, false, bool
@@ -1 +1,10 @@
1
- Sequel.connect(Config.database_url, max_connections: Config.db_pool)
1
+ database_setup_proc = lambda do |conn|
2
+ # identify postgres connections coming from this process in pg_stat_activity
3
+ process_identifier = ENV["DYNO"] || File.basename($0).gsub(/\W+/, "_")
4
+ conn.execute "SET statement_timeout = '#{Config.database_timeout}s'"
5
+ conn.execute "SET application_name = #{process_identifier}"
6
+ end
7
+
8
+ Sequel.connect(Config.database_url,
9
+ max_connections: Config.db_pool,
10
+ after_connect: database_setup_proc)
@@ -0,0 +1 @@
1
+ Pliny.default_context = {}
@@ -0,0 +1,3 @@
1
+ if Config.timeout > 0
2
+ Rack::Timeout.timeout = Config.timeout
3
+ end
@@ -1,6 +1,6 @@
1
1
  require "./config/config"
2
2
 
3
- environment Config.rack_env
3
+ environment Config.pliny_env
4
4
  port Config.port
5
5
  quiet
6
6
  threads Config.puma_min_threads, Config.puma_max_threads
@@ -9,6 +9,7 @@ module Endpoints
9
9
 
10
10
  set :dump_errors, false
11
11
  set :raise_errors, true
12
+ set :root, Config.root
12
13
  set :show_exceptions, false
13
14
 
14
15
  configure :development do
@@ -4,7 +4,7 @@ Routes = Rack::Builder.new do
4
4
  use Pliny::Middleware::CORS
5
5
  use Pliny::Middleware::RequestID
6
6
  use Pliny::Middleware::RequestStore, store: Pliny::RequestStore
7
- use Pliny::Middleware::Timeout, timeout: Config.timeout if Config.timeout > 0
7
+ use Rack::Timeout if Config.timeout > 0
8
8
  use Pliny::Middleware::Versioning,
9
9
  default: Config.versioning_default,
10
10
  app_name: Config.versioning_app_name if Config.versioning?
@@ -10,6 +10,22 @@ ENV["RACK_ENV"] = "test"
10
10
  require "bundler"
11
11
  Bundler.require(:default, :test)
12
12
 
13
+ # setting ENV["CI"] configures simplecov for continuous integration output
14
+ # setting ENV["COVERAGE"] generates a report when running tests locally
15
+ if ENV["COVERAGE"] || ENV["CI"]
16
+ require "simplecov"
17
+ if ENV["CI"]
18
+ SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
19
+ SimpleCov.at_exit do
20
+ puts SimpleCov.result.format!
21
+ end
22
+ end
23
+ SimpleCov.start do
24
+ # without this the simple formatter won't do anything
25
+ add_group "lib", "lib"
26
+ end
27
+ end
28
+
13
29
  require 'dotenv'
14
30
  Dotenv.load('.env.test')
15
31
 
@@ -27,7 +43,7 @@ RSpec.configure do |config|
27
43
  config.before :all do
28
44
  load('db/seeds.rb') if File.exist?('db/seeds.rb')
29
45
  end
30
-
46
+
31
47
  config.before :each do
32
48
  DatabaseCleaner.start
33
49
  end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+ require "pliny/db_support"
3
+
4
+ describe Pliny::DbSupport do
5
+ let(:support) { Pliny::DbSupport.new(ENV["TEST_DATABASE_URL"]) }
6
+
7
+ before(:all) do
8
+ @path = "/tmp/pliny-test"
9
+ end
10
+
11
+ before(:each) do
12
+ DB.tables.each { |t| DB.drop_table(t) }
13
+ FileUtils.rm_rf(@path)
14
+ FileUtils.mkdir_p("#{@path}/db/migrate")
15
+ Dir.chdir(@path)
16
+ end
17
+
18
+ describe "#migrate" do
19
+ before do
20
+ File.open("#{@path}/db/migrate/#{Time.now.to_i}_create_foo.rb", "w") do |f|
21
+ f.puts "
22
+ Sequel.migration do
23
+ change do
24
+ create_table(:foo) do
25
+ primary_key :id
26
+ text :bar
27
+ end
28
+ end
29
+ end
30
+ "
31
+ end
32
+ end
33
+
34
+ it "migrates the database" do
35
+ support.migrate
36
+ assert_equal [:foo, :schema_migrations], DB.tables.sort
37
+ assert_equal [:bar, :id], DB[:foo].columns.sort
38
+ end
39
+ end
40
+
41
+ describe "#rollback" do
42
+ before do
43
+ t = Time.now
44
+ File.open("#{@path}/db/migrate/#{(t-3).to_i}_first.rb", "w") do |f|
45
+ f.puts "Sequel.migration { change { create_table(:first) } }"
46
+ end
47
+
48
+ File.open("#{@path}/db/migrate/#{(t-2).to_i}_second.rb", "w") do |f|
49
+ f.puts "Sequel.migration { change { create_table(:second) } }"
50
+ end
51
+
52
+ File.open("#{@path}/db/migrate/#{(t-1).to_i}_third.rb", "w") do |f|
53
+ f.puts "Sequel.migration { change { create_table(:third) } }"
54
+ end
55
+ end
56
+
57
+ it "reverts one migration" do
58
+ support.migrate
59
+ support.rollback
60
+ assert_equal [:first, :schema_migrations, :second], DB.tables.sort
61
+ support.rollback
62
+ assert_equal [:first, :schema_migrations], DB.tables.sort
63
+ end
64
+ end
65
+ end
@@ -7,6 +7,10 @@ describe Pliny::Log do
7
7
  stub(@io).print
8
8
  end
9
9
 
10
+ after do
11
+ Pliny.default_context = {}
12
+ end
13
+
10
14
  it "logs in structured format" do
11
15
  mock(@io).print "foo=bar baz=42\n"
12
16
  Pliny.log(foo: "bar", baz: 42)
@@ -19,6 +23,12 @@ describe Pliny::Log do
19
23
  end
20
24
  end
21
25
 
26
+ it "merges default context" do
27
+ Pliny.default_context = { app: "pliny" }
28
+ mock(@io).print "app=pliny foo=bar\n"
29
+ Pliny.log(foo: "bar")
30
+ end
31
+
22
32
  it "merges context from RequestStore" do
23
33
  Pliny::RequestStore.store[:log_context] = { app: "pliny" }
24
34
  mock(@io).print "app=pliny foo=bar\n"
@@ -32,13 +42,20 @@ describe Pliny::Log do
32
42
  end
33
43
  end
34
44
 
35
- it "local context does not overwrite global" do
45
+ it "local context does not overwrite default context" do
46
+ Pliny.default_context = { app: "pliny" }
47
+ mock(@io).print "app=not_pliny foo=bar\n"
48
+ Pliny.log(app: 'not_pliny', foo: "bar")
49
+ assert Pliny.default_context[:app] == "pliny"
50
+ end
51
+
52
+ it "local context does not overwrite request context" do
36
53
  Pliny::RequestStore.store[:log_context] = { app: "pliny" }
37
54
  mock(@io).print "app=not_pliny foo=bar\n"
38
55
  Pliny.context(app: "not_pliny") do
39
56
  Pliny.log(foo: "bar")
40
57
  end
41
- assert Pliny::RequestStore.store[:log_context][:app] = "pliny"
58
+ assert Pliny::RequestStore.store[:log_context][:app] == "pliny"
42
59
  end
43
60
 
44
61
  it "local context does not propagate outside" do
@@ -1,16 +1,22 @@
1
1
  # make sure this is set before Sinatra is required
2
2
  ENV["RACK_ENV"] = "test"
3
3
 
4
+ # have this database is available for tests
5
+ ENV["TEST_DATABASE_URL"] ||= "postgres://localhost/pliny-gem-test"
6
+
4
7
  require "bundler"
5
8
  Bundler.require
6
9
 
10
+ require "fileutils"
7
11
  require "rack/test"
12
+ require "sequel"
8
13
  require "sinatra/namespace"
9
14
  require "sinatra/router"
10
15
  require "timecop"
11
16
 
12
17
  require_relative "../lib/pliny"
13
18
  Pliny::Utils.require_glob("./spec/support/**/*.rb")
19
+ DB = Sequel.connect(ENV["TEST_DATABASE_URL"])
14
20
 
15
21
  RSpec.configure do |config|
16
22
  config.include Rack::Test::Methods
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.7.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur Leach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-19 00:00:00.000000000 Z
12
+ date: 2015-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -85,6 +85,26 @@ dependencies:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
87
  version: 0.7.0
88
+ - !ruby/object:Gem::Dependency
89
+ name: rack-timeout
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '0.2'
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 0.2.3
98
+ type: :runtime
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.2'
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 0.2.3
88
108
  - !ruby/object:Gem::Dependency
89
109
  name: sequel
90
110
  requirement: !ruby/object:Gem::Requirement
@@ -344,6 +364,7 @@ files:
344
364
  - lib/pliny/commands/generator/schema.rb
345
365
  - lib/pliny/commands/generator/serializer.rb
346
366
  - lib/pliny/config_helpers.rb
367
+ - lib/pliny/db_support.rb
347
368
  - lib/pliny/errors.rb
348
369
  - lib/pliny/extensions/instruments.rb
349
370
  - lib/pliny/helpers/encode.rb
@@ -353,7 +374,6 @@ files:
353
374
  - lib/pliny/middleware/request_id.rb
354
375
  - lib/pliny/middleware/request_store.rb
355
376
  - lib/pliny/middleware/rescue_errors.rb
356
- - lib/pliny/middleware/timeout.rb
357
377
  - lib/pliny/middleware/versioning.rb
358
378
  - lib/pliny/request_store.rb
359
379
  - lib/pliny/router.rb
@@ -391,6 +411,8 @@ files:
391
411
  - lib/template/config.ru
392
412
  - lib/template/config/config.rb
393
413
  - lib/template/config/initializers/database.rb
414
+ - lib/template/config/initializers/log.rb
415
+ - lib/template/config/initializers/rack_timeout.rb
394
416
  - lib/template/config/initializers/rollbar.rb
395
417
  - lib/template/config/puma.rb
396
418
  - lib/template/db/schema.sql
@@ -413,6 +435,7 @@ files:
413
435
  - spec/commands/generator/endpoint_spec.rb
414
436
  - spec/commands/generator/schema_spec.rb
415
437
  - spec/commands/generator_spec.rb
438
+ - spec/db_support_spec.rb
416
439
  - spec/errors_spec.rb
417
440
  - spec/extensions/instruments_spec.rb
418
441
  - spec/integration_spec.rb
@@ -421,7 +444,6 @@ files:
421
444
  - spec/middleware/request_id_spec.rb
422
445
  - spec/middleware/request_store_spec.rb
423
446
  - spec/middleware/rescue_errors_spec.rb
424
- - spec/middleware/timeout_spec.rb
425
447
  - spec/middleware/versioning_spec.rb
426
448
  - spec/request_store_spec.rb
427
449
  - spec/router_spec.rb
@@ -448,7 +470,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
448
470
  version: '0'
449
471
  requirements: []
450
472
  rubyforge_project:
451
- rubygems_version: 2.2.2
473
+ rubygems_version: 2.4.3
452
474
  signing_key:
453
475
  specification_version: 4
454
476
  summary: Basic tooling to support API apps in Sinatra
@@ -1,25 +0,0 @@
1
- require "timeout"
2
-
3
- module Pliny::Middleware
4
- # Requires that Pliny::Middleware::RescueErrors is nested above it.
5
- class Timeout
6
- def initialize(app, options={})
7
- @app = app
8
- @timeout = options[:timeout] || 45
9
- end
10
-
11
- def call(env)
12
- ::Timeout.timeout(@timeout, RequestTimeout) do
13
- @app.call(env)
14
- end
15
- rescue RequestTimeout
16
- # Pliny::Sample.measure "requests.timeouts"
17
- raise Pliny::Errors::ServiceUnavailable, "Timeout reached."
18
- end
19
-
20
- # use a custom Timeout class so it can't be rescued accidentally by
21
- # internal calls
22
- class RequestTimeout < Exception
23
- end
24
- end
25
- end
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Pliny::Middleware::Timeout do
4
- include Rack::Test::Methods
5
-
6
- def app
7
- Rack::Builder.new do
8
- use Rack::Lint
9
- use Pliny::Middleware::Timeout
10
- run Sinatra.new {
11
- get "/" do
12
- 200
13
- end
14
-
15
- get "/timeout" do
16
- raise Pliny::Middleware::Timeout::RequestTimeout
17
- end
18
- }
19
- end
20
- end
21
-
22
- it "passes through requests that don't timeout normally" do
23
- get "/"
24
- assert_equal 200, last_response.status
25
- end
26
-
27
- it "responds with an error on a timeout" do
28
- assert_raises(Pliny::Errors::ServiceUnavailable) do
29
- get "/timeout"
30
- end
31
- end
32
- end