temescal 0.1.0 → 0.1.1

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
2
  SHA1:
3
- metadata.gz: 668a0e9c9bb3d5400a4b9b28302607767828bc0c
4
- data.tar.gz: 1f1a62d3e48d5db8cd32b853a06ea116be8a3b69
3
+ metadata.gz: 2d87fe04c5479ea7fc4081a5c20c1e00ecab56f7
4
+ data.tar.gz: 311bdc3696f87f883d63b77924f05a1d9c448518
5
5
  SHA512:
6
- metadata.gz: 614f71816ca80c27852abe47a8aef37702fc8eced6143613ed25735dd1bc3bc051a7e9d4f4dd1eefb1709aedc6537191354abaab13a837cc57bbc70469f91564
7
- data.tar.gz: 1bf5f51abe2f31d8e2cd7b8595f97c4d6a86083f99d34f1d800e7e96495de41bae2017b62ec1bb6b7f1ced4a8ccf4fd04062b7c7ea7edde87484a2fd3c0799e9
6
+ metadata.gz: f478224b88e7cd8ca0bd5ecf9119c5593856c3c355a808953a0837ddd5f978c7a0e7529ec491306913e9365063095f2d3554f116c3cb3c099af31817606c7437
7
+ data.tar.gz: f713acaf1042b6864275125bfcdd01c2bb448a33119248b8ff9e548d978a5ce92f6e9e2a3bdc862b7b7e6f71c4ee81f0e3cb913dc4a97bac5e95c6820ca71475
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  temescal
2
2
  ========
3
3
 
4
- [![Build Status](https://travis-ci.org/todd/temescal.png?branch=master)](https://travis-ci.org/todd/temescal) [![Coverage Status](https://coveralls.io/repos/todd/temescal/badge.png?branch=master)](https://coveralls.io/r/todd/temescal?branch=master) [![Code Climate](https://codeclimate.com/github/todd/temescal.png)](https://codeclimate.com/github/todd/temescal) [![Dependency Status](https://gemnasium.com/todd/temescal.png)](https://gemnasium.com/todd/temescal)
4
+ [![Gem Version](https://badge.fury.io/rb/temescal.png)](http://badge.fury.io/rb/temescal) [![Build Status](https://travis-ci.org/todd/temescal.png?branch=master)](https://travis-ci.org/todd/temescal) [![Coverage Status](https://coveralls.io/repos/todd/temescal/badge.png?branch=master)](https://coveralls.io/r/todd/temescal?branch=master) [![Code Climate](https://codeclimate.com/github/todd/temescal.png)](https://codeclimate.com/github/todd/temescal) [![Dependency Status](https://gemnasium.com/todd/temescal.png)](https://gemnasium.com/todd/temescal)
5
5
 
6
6
  Temescal is Rack middleware that will automatically rescue exceptions for JSON APIs and render a nice, clean JSON response with the error information. No need to write custom error handling logic for your apps - Temescal will take care of it for you!
7
7
  ## Getting Started
@@ -1,5 +1,6 @@
1
1
  module Temescal
2
2
  class Middleware
3
+ NOT_FOUND_ERRORS = ["ActiveRecord::RecordNotFound", "Sinatra::NotFound"]
3
4
 
4
5
  # Public: Initializes the middleware.
5
6
  #
@@ -31,7 +32,7 @@ module Temescal
31
32
  $stderr.print formatted_error
32
33
  configuration.monitors.each { |monitor| monitor.report(@error) }
33
34
 
34
- @status = @error.respond_to?(:http_status) ? @error.http_status : 500
35
+ @status = set_status
35
36
  @response = Response.build(@status, @error, message)
36
37
  @headers = { "Content-Type" => "application/json" }
37
38
  end
@@ -51,5 +52,11 @@ module Temescal
51
52
  message << @error.backtrace.join("\n ")
52
53
  message << "\n\n"
53
54
  end
55
+
56
+ # Private: Returns the proper error code for the exception.
57
+ def set_status
58
+ return 404 if NOT_FOUND_ERRORS.include? @error.class.to_s
59
+ @error.respond_to?(:http_status) ? @error.http_status : 500
60
+ end
54
61
  end
55
62
  end
@@ -1,3 +1,3 @@
1
1
  module Temescal
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,5 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
+ require "active_record"
4
+ require "sinatra"
5
+
3
6
  describe Temescal::Middleware do
4
7
  context "Ok response" do
5
8
  let(:app) { ->(env) { [200, env, "app" ] } }
@@ -86,6 +89,28 @@ describe Temescal::Middleware do
86
89
  expect(json["message"]).to eq "An error has occured - we'll get on it right away!"
87
90
  end
88
91
  end
92
+
93
+ context "with a Sinatra::NotFound error" do
94
+ it "should build a response with a 404 status code" do
95
+ app = ->(env) { raise Sinatra::NotFound.new }
96
+ middleware = Temescal::Middleware.new(app)
97
+
98
+ code, _, _ = middleware.call env_for("http://foobar.com")
99
+
100
+ expect(code).to eq 404
101
+ end
102
+ end
103
+
104
+ context "with an ActiveRecord::RecordNotFound error" do
105
+ it "should build a response with a 404 status code" do
106
+ app = ->(env) { raise ActiveRecord::RecordNotFound.new }
107
+ middleware = Temescal::Middleware.new(app)
108
+
109
+ code, _, _ = middleware.call env_for("http://foobar.com")
110
+
111
+ expect(code).to eq 404
112
+ end
113
+ end
89
114
  end
90
115
 
91
116
  context "Override middleware to raise exception" do
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temescal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Bealmear
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Rack Middleware for gracefully handling exceptions for JSON APIs.
@@ -48,17 +48,17 @@ files:
48
48
  - LICENSE
49
49
  - README.md
50
50
  - Rakefile
51
- - temescal.gemspec
51
+ - lib/temescal.rb
52
52
  - lib/temescal/configuration.rb
53
53
  - lib/temescal/middleware.rb
54
54
  - lib/temescal/monitors.rb
55
55
  - lib/temescal/response.rb
56
56
  - lib/temescal/version.rb
57
- - lib/temescal.rb
58
57
  - spec/lib/temescal/configuration_spec.rb
59
58
  - spec/lib/temescal/middleware_spec.rb
60
59
  - spec/lib/temescal/monitors_spec.rb
61
60
  - spec/spec_helper.rb
61
+ - temescal.gemspec
62
62
  homepage: https://github.com/todd/temescal
63
63
  licenses:
64
64
  - MIT
@@ -69,17 +69,17 @@ require_paths:
69
69
  - lib
70
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - '>='
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.1.10
82
+ rubygems_version: 2.2.0
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Rack Middleware for gracefully handling exceptions for JSON APIs.