yogi_berra 0.1.1 → 0.1.3
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 +8 -8
- data/README.md +2 -0
- data/lib/yogi_berra/catcher.rb +4 -2
- data/lib/yogi_berra/engine.rb +2 -1
- data/lib/yogi_berra/exception_middleware.rb +3 -9
- data/lib/yogi_berra/logger.rb +1 -1
- data/lib/yogi_berra/version.rb +1 -1
- data/spec/fixtures/rails.rb +1 -1
- data/spec/spec_helper.rb +7 -7
- data/spec/yogi_berra_exception_middleware_spec.rb +37 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2IwMzU1NmVjNzlkYzIxYjFjYjIwZGE4YjhhMTg5YWVjZTIyMTg3OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTRhMmVjNTY1NGVkNjhmZTRjYjQ5NzVjMmU1YTgyZTliZWNkNmU5Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTk4NTY2NjVmYjc5OTdjNjU1M2IwZDU2ODUyOTUzOTY2ZmEzMTE5ZTQ3NDYw
|
10
|
+
ZGE0MWMzY2QxOGI4MmIwMjNkOTgxM2U3ZTYxZmViMzlmZGQ0ZmU1OWYzOGY5
|
11
|
+
YmVmMDBkOTMwOWY5OWM1YTc1OTkzOGVmNDNhZmI5YzdmNzY3NzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTQxOGE5ZjI1ZGZiZjU2MzExZTA2YTA0NmYxNDc5NWQ5NTkxNDZmYjAwYTk1
|
14
|
+
YWU4NWMwMmEzMDJmY2MxZTBjY2JmMWU3MmRhOWZkNDlkOGM5MjIzY2MzODM1
|
15
|
+
YWM5MGVjZDhjNjU3YmE4MjNlNDVjOWYxOTA4MjEzNzNhNWE0ZDc=
|
data/README.md
CHANGED
data/lib/yogi_berra/catcher.rb
CHANGED
@@ -12,11 +12,12 @@ module YogiBerra
|
|
12
12
|
def load_db_settings(config_file = nil)
|
13
13
|
if config_file
|
14
14
|
database_config = config_file
|
15
|
-
elsif defined?(Rails)
|
16
|
-
database_config = "#{Rails.root}/config/yogi.yml"
|
15
|
+
elsif defined?(::Rails)
|
16
|
+
database_config = Rails.root ? "#{Rails.root}/config/yogi.yml" : "config/yogi.yml"
|
17
17
|
else
|
18
18
|
YogiBerra::Logger.log("No config file specified!", :error)
|
19
19
|
end
|
20
|
+
|
20
21
|
if database_config
|
21
22
|
begin
|
22
23
|
File.open(database_config, 'r') do |f|
|
@@ -64,6 +65,7 @@ module YogiBerra
|
|
64
65
|
retry
|
65
66
|
rescue => error
|
66
67
|
YogiBerra::Logger.log("Couldn't connect to the mongo database on host: #{host} port: #{port}.\n #{error.inspect}", :error)
|
68
|
+
sleep 1
|
67
69
|
retry
|
68
70
|
end
|
69
71
|
|
data/lib/yogi_berra/engine.rb
CHANGED
@@ -2,11 +2,12 @@ module YogiBerra
|
|
2
2
|
class ExceptionMiddleware
|
3
3
|
def initialize(app)
|
4
4
|
@app = app
|
5
|
-
YogiBerra::Catcher.connect(true)
|
6
5
|
end
|
7
6
|
|
8
7
|
def call(env)
|
9
8
|
begin
|
9
|
+
response = @app.call(env)
|
10
|
+
rescue Exception => raised
|
10
11
|
path_parameters = env['action_controller.request.path_parameters'] || {}
|
11
12
|
query_hash = env['rack.request.query_hash'] || {}
|
12
13
|
environment = {
|
@@ -19,8 +20,7 @@ module YogiBerra
|
|
19
20
|
:controller => env['action_controller.instance'],
|
20
21
|
:remote_address => env['REMOTE_ADDR']
|
21
22
|
}
|
22
|
-
|
23
|
-
rescue Exception => raised
|
23
|
+
|
24
24
|
YogiBerra.exceptionize(raised, environment)
|
25
25
|
raise raised
|
26
26
|
end
|
@@ -31,14 +31,8 @@ module YogiBerra
|
|
31
31
|
response
|
32
32
|
end
|
33
33
|
|
34
|
-
def _call(env)
|
35
|
-
@status, @headers, @response = @app.call(env)
|
36
|
-
[@status, @headers, self]
|
37
|
-
end
|
38
|
-
|
39
34
|
def each(&block)
|
40
35
|
@response.each(&block)
|
41
36
|
end
|
42
|
-
|
43
37
|
end
|
44
38
|
end
|
data/lib/yogi_berra/logger.rb
CHANGED
data/lib/yogi_berra/version.rb
CHANGED
data/spec/fixtures/rails.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -23,25 +23,25 @@ def mock_mongo(opts)
|
|
23
23
|
mongo_connection = double('mongo connection')
|
24
24
|
|
25
25
|
if opts[:mongo_client_stub]
|
26
|
-
Mongo::MongoClient.should_receive(:new) { mongo_client }
|
27
|
-
mongo_client.should_receive(:[]) { mongo_connection }
|
26
|
+
Mongo::MongoClient.should_receive(:new).at_least(1).times { mongo_client }
|
27
|
+
mongo_client.should_receive(:[]).at_least(1).times { mongo_connection }
|
28
28
|
end
|
29
29
|
|
30
30
|
if opts[:authenticate_stub] == :error
|
31
|
-
mongo_connection.should_receive(:authenticate).and_raise
|
31
|
+
mongo_connection.should_receive(:authenticate).at_least(1).times.and_raise
|
32
32
|
else
|
33
|
-
mongo_connection.should_receive(:authenticate)
|
33
|
+
mongo_connection.should_receive(:authenticate).at_least(1).times
|
34
34
|
end
|
35
35
|
|
36
36
|
if opts[:connection_stub]
|
37
|
-
mongo_connection.should_receive(:[]) { mongo_connection }
|
38
|
-
mongo_connection.should_receive(:insert)
|
37
|
+
mongo_connection.should_receive(:[]).at_least(1).times { mongo_connection }
|
38
|
+
mongo_connection.should_receive(:insert).at_least(1).times
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def mock_yogi_fork_database
|
43
43
|
client = YogiBerra::Catcher.fork_database.join
|
44
|
-
YogiBerra::Catcher.should_receive(:fork_database) { client }
|
44
|
+
YogiBerra::Catcher.should_receive(:fork_database).at_least(1).times { client }
|
45
45
|
end
|
46
46
|
|
47
47
|
def reset_if_rails
|
@@ -2,25 +2,28 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe YogiBerra::ExceptionMiddleware do
|
4
4
|
before(:each) do
|
5
|
-
|
6
|
-
|
5
|
+
@test_yaml = "#{SPEC_FOLDER}/fixtures/test.yml"
|
6
|
+
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should call the upstream app with the environment" do
|
10
|
+
# YogiBerra::Logger.stub(:log)
|
10
11
|
mock_mongo(:mongo_client_stub => true)
|
11
12
|
mock_yogi_fork_database
|
12
13
|
environment = { 'key' => 'value' }
|
13
14
|
app = lambda { |env| ['response', {}, env] }
|
15
|
+
|
16
|
+
YogiBerra::Catcher.connect
|
14
17
|
stack = YogiBerra::ExceptionMiddleware.new(app)
|
15
18
|
|
16
19
|
response = stack.call(environment)
|
17
|
-
|
18
20
|
response[0].should == 'response'
|
19
21
|
response[1].should == {}
|
20
|
-
response[2].
|
22
|
+
response[2].should == { 'key' => 'value' }
|
21
23
|
end
|
22
24
|
|
23
25
|
it "deliver an exception raised while calling an upstream app" do
|
26
|
+
YogiBerra::Logger.stub(:log)
|
24
27
|
mock_mongo(:mongo_client_stub => true, :connection_stub => true)
|
25
28
|
mock_yogi_fork_database
|
26
29
|
exception = build_exception
|
@@ -29,6 +32,7 @@ describe YogiBerra::ExceptionMiddleware do
|
|
29
32
|
raise exception
|
30
33
|
end
|
31
34
|
|
35
|
+
YogiBerra::Catcher.connect
|
32
36
|
begin
|
33
37
|
stack = YogiBerra::ExceptionMiddleware.new(app)
|
34
38
|
stack.call(environment)
|
@@ -38,6 +42,7 @@ describe YogiBerra::ExceptionMiddleware do
|
|
38
42
|
end
|
39
43
|
|
40
44
|
it "should deliver an exception in rack.exception" do
|
45
|
+
# YogiBerra::Logger.stub(:log)
|
41
46
|
mock_mongo(:mongo_client_stub => true, :connection_stub => true)
|
42
47
|
mock_yogi_fork_database
|
43
48
|
exception = build_exception
|
@@ -48,12 +53,39 @@ describe YogiBerra::ExceptionMiddleware do
|
|
48
53
|
env['rack.exception'] = exception
|
49
54
|
response
|
50
55
|
end
|
56
|
+
YogiBerra::Catcher.connect
|
57
|
+
stack = YogiBerra::ExceptionMiddleware.new(app)
|
58
|
+
|
59
|
+
actual_response = stack.call(environment)
|
60
|
+
actual_response[0].should == 200
|
61
|
+
actual_response[1].should == {}
|
62
|
+
actual_response[2].should == ["okay"]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "log only once on app initialization and then be quiet" do
|
66
|
+
YogiBerra::Logger.should_receive(:log).exactly(1).times
|
67
|
+
mock_mongo(:mongo_client_stub => true, :connection_stub => true, :authenticate_stub => :error)
|
68
|
+
mock_yogi_fork_database
|
69
|
+
exception = build_exception
|
70
|
+
environment = { 'key' => 'value' }
|
71
|
+
|
72
|
+
response = [200, {}, ['okay']]
|
73
|
+
app = lambda do |env|
|
74
|
+
env['rack.exception'] = exception
|
75
|
+
response
|
76
|
+
end
|
77
|
+
|
78
|
+
YogiBerra::Catcher.connect
|
51
79
|
stack = YogiBerra::ExceptionMiddleware.new(app)
|
52
80
|
|
53
81
|
actual_response = stack.call(environment)
|
82
|
+
actual_response[0].should == 200
|
83
|
+
actual_response[1].should == {}
|
84
|
+
actual_response[2].should == ["okay"]
|
54
85
|
|
86
|
+
actual_response = stack.call(environment)
|
55
87
|
actual_response[0].should == 200
|
56
88
|
actual_response[1].should == {}
|
57
|
-
actual_response[2].
|
89
|
+
actual_response[2].should == ["okay"]
|
58
90
|
end
|
59
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yogi_berra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Earl Krauss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|