bullet 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ rvm: 1.9.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bullet (2.1.0)
4
+ bullet (2.2.0)
5
5
  uniform_notifier (~> 1.0.0)
6
6
 
7
7
  GEM
@@ -1,10 +1,12 @@
1
1
  h1. Bullet
2
2
 
3
+ !https://secure.travis-ci.org/flyerhzm/rails_best_practices.png!:http://travis-ci.org/flyerhzm/rails_best_practices
4
+
3
5
  The Bullet plugin/gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
4
6
 
5
7
  Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
6
8
 
7
- The Bullet plugin/gem now supports rails 2.1, 2.2, 2.3 and 3.0.
9
+ The Bullet plugin/gem now supports rails 2.1, 2.2, 2.3, 3.0 and 3.1.
8
10
 
9
11
  ****************************************************************************
10
12
 
@@ -18,7 +20,7 @@ gem install bullet
18
20
  or add it into a Gemfile (Bundler):
19
21
  <pre><code>
20
22
  gem "bullet", :group => "development"
21
- </code></code>
23
+ </code></pre>
22
24
 
23
25
  ****************************************************************************
24
26
 
@@ -166,10 +168,7 @@ h2. Links
166
168
 
167
169
  h2. Contributors
168
170
 
169
- sriedel did a lot of awesome refactors, added xmpp notification support, and added Hacking.textile about how to extend to bullet plugin.
170
- flipsasser added Growl, console.log and Rails.log support, very awesome. And he also improved README.
171
- rainux added group style console.log.
172
- 2collegebums added some great specs to generate red bar.
171
+ "https://github.com/flyerhzm/bullet/contributors":https://github.com/flyerhzm/bullet/contributors
173
172
 
174
173
  ****************************************************************************
175
174
 
@@ -393,4 +392,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
393
392
  ****************************************************************************
394
393
 
395
394
 
396
- Copyright (c) 2009 - 2011 Richard Huang (flyerhzm@gmail.com), released under the MIT license
395
+ Copyright (c) 2009 - 2012 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -16,10 +16,7 @@ There is a large refactor from gem 1.4 to 1.5, so if you upgrade to 1.5 gem, ple
16
16
 
17
17
  h2. Contributors
18
18
 
19
- sriedel did a lot of awesome refactors, added xmpp notification support, and added Hacking.textile about how to extend to bullet plugin.
20
- flipsasser added Growl, console.log and Rails.log support, very awesome. And he also improved README.
21
- rainux added group style console.log.
22
- 2collegebums added some great specs to generate red bar.
19
+ "https://github.com/flyerhzm/bullet/contributors":https://github.com/flyerhzm/bullet/contributors
23
20
 
24
21
  ****************************************************************************
25
22
 
@@ -400,4 +397,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
400
397
  ****************************************************************************
401
398
 
402
399
 
403
- Copyright (c) 2009 - 2011 Richard Huang (flyerhzm@gmail.com), released under the MIT license
400
+ Copyright (c) 2009 - 2012 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -4,7 +4,7 @@ require 'uniform_notifier'
4
4
  module Bullet
5
5
  if Rails.version =~ /^3\.0/
6
6
  autoload :ActiveRecord, 'bullet/active_record3'
7
- elsif Rails.version =~ /^3\.1/
7
+ elsif Rails.version =~ /^3\.[12]/
8
8
  autoload :ActiveRecord, 'bullet/active_record31'
9
9
  else
10
10
  autoload :ActiveRecord, 'bullet/active_record2'
@@ -11,6 +11,7 @@ module Bullet
11
11
  status, headers, response = @app.call(env)
12
12
  return [status, headers, response] if empty?(response)
13
13
 
14
+ response_body = nil
14
15
  if Bullet.notification?
15
16
  if status == 200 and !response.body.frozen? and check_html?(headers, response)
16
17
  response_body = response.body << Bullet.gather_inline_notifications
@@ -18,10 +19,9 @@ module Bullet
18
19
  end
19
20
  Bullet.perform_out_of_channel_notifications(env)
20
21
  end
21
- response_body ||= response.body
22
22
  Bullet.end_request
23
23
  no_browser_cache(headers) if Bullet.disable_browser_cache
24
- [status, headers, [response_body]]
24
+ [status, headers, response_body ? [response_body] : response]
25
25
  end
26
26
 
27
27
  # fix issue if response's body is a Proc
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
 
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+
4
+ describe Bullet::Rack do
5
+ let(:middleware) { Bullet::Rack.new app }
6
+ let(:app) { AppDouble.new }
7
+
8
+ describe "#call" do
9
+ context "when Bullet is enabled" do
10
+ before(:each) { Bullet.enable = true }
11
+
12
+ it "should invoke Bullet.start_request" do
13
+ Bullet.should_receive(:start_request)
14
+ middleware.call([])
15
+ end
16
+
17
+ it "should invoke Bullet.end_request" do
18
+ Bullet.should_receive(:end_request)
19
+ middleware.call([])
20
+ end
21
+
22
+ it "should return original response body" do
23
+ expected_response = ResponseDouble.new "Actual body"
24
+ app.response = expected_response
25
+ status, headers, response = middleware.call([])
26
+ response.should eq expected_response
27
+ end
28
+ end
29
+
30
+ context "when Bullet is disabled" do
31
+ before(:each) { Bullet.enable = false }
32
+ after(:each) { Bullet.enable = true }
33
+
34
+ it "should not call Bullet.start_request" do
35
+ Bullet.should_not_receive(:start_request)
36
+ middleware.call([])
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,4 @@
1
+ require 'pry'
1
2
  require 'rubygems'
2
3
  require 'rspec'
3
4
  require 'rspec/autorun'
@@ -77,3 +78,57 @@ module Bullet
77
78
  end
78
79
  end
79
80
  end
81
+
82
+ class AppDouble
83
+ def call env
84
+ env = @env
85
+ [ status, headers, response ]
86
+ end
87
+
88
+ def status= status
89
+ @status = status
90
+ end
91
+
92
+ def headers= headers
93
+ @headers = headers
94
+ end
95
+
96
+ def headers
97
+ @headers ||= {}
98
+ @headers
99
+ end
100
+
101
+ def response= response
102
+ @response = response
103
+ end
104
+
105
+ private
106
+ def status
107
+ @status || 200
108
+ end
109
+
110
+ def response
111
+ @response || ResponseDouble.new
112
+ end
113
+ end
114
+
115
+ class ResponseDouble
116
+ def initialize actual_body = nil
117
+ @actual_body = actual_body
118
+ end
119
+
120
+ def body
121
+ @body ||= "Hello world!"
122
+ end
123
+
124
+ def body= body
125
+ @body = body
126
+ end
127
+
128
+ def each
129
+ yield body
130
+ end
131
+
132
+ def close
133
+ end
134
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-11 00:00:00.000000000 Z
12
+ date: 2012-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uniform_notifier
16
- requirement: &2156581180 !ruby/object:Gem::Requirement
16
+ requirement: &70142210251740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156581180
24
+ version_requirements: *70142210251740
25
25
  description: A rails plugin to kill N+1 queries and unused eager loading.
26
26
  email:
27
27
  - flyerhzm@gmail.com
@@ -33,6 +33,7 @@ files:
33
33
  - .rspec
34
34
  - .rvmrc
35
35
  - .rvmrc.example
36
+ - .travis.yml
36
37
  - .watchr
37
38
  - Gemfile
38
39
  - Gemfile.lock
@@ -71,6 +72,7 @@ files:
71
72
  - spec/bullet/association_for_peschkaj_spec.rb
72
73
  - spec/bullet/association_spec.rb
73
74
  - spec/bullet/counter_spec.rb
75
+ - spec/bullet/rack_spec.rb
74
76
  - spec/spec_helper.rb
75
77
  - tasks/bullet_tasks.rake
76
78
  homepage: http://github.com/flyerhzm/bullet
@@ -87,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
89
  version: '0'
88
90
  segments:
89
91
  - 0
90
- hash: -1237939251235315374
92
+ hash: -891202166897363067
91
93
  required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  none: false
93
95
  requirements:
@@ -96,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  version: 1.3.6
97
99
  requirements: []
98
100
  rubyforge_project:
99
- rubygems_version: 1.8.10
101
+ rubygems_version: 1.8.17
100
102
  signing_key:
101
103
  specification_version: 3
102
104
  summary: A rails plugin to kill N+1 queries and unused eager loading.
@@ -105,4 +107,5 @@ test_files:
105
107
  - spec/bullet/association_for_peschkaj_spec.rb
106
108
  - spec/bullet/association_spec.rb
107
109
  - spec/bullet/counter_spec.rb
110
+ - spec/bullet/rack_spec.rb
108
111
  - spec/spec_helper.rb