bullet 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/Gemfile.lock +1 -1
- data/README.textile +6 -7
- data/README_for_rails2.textile +2 -5
- data/lib/bullet.rb +1 -1
- data/lib/bullet/rack.rb +2 -2
- data/lib/bullet/version.rb +1 -1
- data/spec/bullet/rack_spec.rb +40 -0
- data/spec/spec_helper.rb +55 -0
- metadata +9 -6
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm: 1.9.2
|
data/Gemfile.lock
CHANGED
data/README.textile
CHANGED
@@ -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.
|
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></
|
23
|
+
</code></pre>
|
22
24
|
|
23
25
|
****************************************************************************
|
24
26
|
|
@@ -166,10 +168,7 @@ h2. Links
|
|
166
168
|
|
167
169
|
h2. Contributors
|
168
170
|
|
169
|
-
|
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 -
|
395
|
+
Copyright (c) 2009 - 2012 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/README_for_rails2.textile
CHANGED
@@ -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
|
-
|
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 -
|
400
|
+
Copyright (c) 2009 - 2012 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/lib/bullet.rb
CHANGED
@@ -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\.
|
7
|
+
elsif Rails.version =~ /^3\.[12]/
|
8
8
|
autoload :ActiveRecord, 'bullet/active_record31'
|
9
9
|
else
|
10
10
|
autoload :ActiveRecord, 'bullet/active_record2'
|
data/lib/bullet/rack.rb
CHANGED
@@ -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
|
data/lib/bullet/version.rb
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -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.
|
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:
|
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: &
|
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: *
|
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: -
|
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.
|
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
|