yogi_berra 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDFmMzdiZTAwNDVjMDA3M2U2YWJiNzQxOWQ5N2RmOTJkNjFjNjE3YQ==
4
+ Y2IwMzU1NmVjNzlkYzIxYjFjYjIwZGE4YjhhMTg5YWVjZTIyMTg3OQ==
5
5
  data.tar.gz: !binary |-
6
- ZDI1NTA3MDEwOGQ5ZmFjN2E5OGQ4NzNjY2YyNDliNTRmYzFkM2IxNw==
6
+ MTRhMmVjNTY1NGVkNjhmZTRjYjQ5NzVjMmU1YTgyZTliZWNkNmU5Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTQyNTkxYTI1Nzg3NjQ2NmI3MjI0NTFmY2FjZDMzMDc1NWY5NzM2Y2E2Njk2
10
- NzJmMGQzNDQyNzI4NzYxODRhZDEyY2M3ZTNiN2ZhMDEzNmQyNmI2NTc2Yzcw
11
- N2RlM2JhYTI2NDhkZTY3ZTJiYTY4Y2IxMDRlODc2MDVlNjU3MmE=
9
+ MTk4NTY2NjVmYjc5OTdjNjU1M2IwZDU2ODUyOTUzOTY2ZmEzMTE5ZTQ3NDYw
10
+ ZGE0MWMzY2QxOGI4MmIwMjNkOTgxM2U3ZTYxZmViMzlmZGQ0ZmU1OWYzOGY5
11
+ YmVmMDBkOTMwOWY5OWM1YTc1OTkzOGVmNDNhZmI5YzdmNzY3NzE=
12
12
  data.tar.gz: !binary |-
13
- YWVmMDg2MDhlNjI3ZjZmZjQ4MjZjZDZhNTMxMWJkOGJjOGRlOGU4ZmZhZDRk
14
- YmZjNGQ0MDdjMGY0MzViZGNkNDUyNTM3ZjM0NTdlMmQ1Y2U4MGFmMDJkNWY0
15
- MGNlYWNlMWU1NDllY2E1YWZlZThjMzJmNjIyNGVkNjg3ZWQzNjE=
13
+ MTQxOGE5ZjI1ZGZiZjU2MzExZTA2YTA0NmYxNDc5NWQ5NTkxNDZmYjAwYTk1
14
+ YWU4NWMwMmEzMDJmY2MxZTBjY2JmMWU3MmRhOWZkNDlkOGM5MjIzY2MzODM1
15
+ YWM5MGVjZDhjNjU3YmE4MjNlNDVjOWYxOTA4MjEzNzNhNWE0ZDc=
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/earlonrails/yogi_berra.png?branch=master)](https://travis-ci.org/earlonrails/yogi_berra)
2
+
1
3
  Yogi Berra
2
4
  ==========
3
5
 
@@ -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
 
@@ -1,5 +1,6 @@
1
1
  module YogiBerra
2
- class Engine < Rails::Engine
2
+ class Engine < ::Rails::Engine
3
+ YogiBerra::Catcher.connect(true)
3
4
  config.app_middleware.use "YogiBerra::ExceptionMiddleware"
4
5
  end
5
6
  end
@@ -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
- response = dup._call(env)
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
@@ -2,7 +2,7 @@ module YogiBerra
2
2
  class Logger
3
3
  def self.log(log_string, level = :info)
4
4
  message = "[YogiBerra #{level.to_s.capitalize}] #{log_string}"
5
- if defined?(Rails)
5
+ if defined?(Rails) && Rails.logger
6
6
  Rails.logger.send(level, message)
7
7
  else
8
8
  $stderr.puts(message)
@@ -1,3 +1,3 @@
1
1
  module YogiBerra
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -9,4 +9,4 @@ class Rails
9
9
  end
10
10
  end
11
11
 
12
- ENV['RAILS_ENV'] = "test"
12
+ ENV['RAILS_ENV'] = "test"
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
- YogiBerra::Logger.stub(:log)
6
- load "#{SPEC_FOLDER}/fixtures/rails.rb"
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].instance_variable_get("@response").should == { 'key' => 'value' }
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].instance_variable_get("@response").should == ["okay"]
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.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-12 00:00:00.000000000 Z
11
+ date: 2013-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake