bullet 5.2.0 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/bullet.rb +10 -1
- data/lib/bullet/active_record42.rb +23 -3
- data/lib/bullet/active_record5.rb +28 -8
- data/lib/bullet/version.rb +1 -1
- data/spec/bullet/rack_spec.rb +4 -4
- data/spec/bullet_spec.rb +43 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c06cf9b6f47c5e634fc97060ca54c2921435d2d
|
4
|
+
data.tar.gz: ad3f7ac0141cf94446805db9495c06db19bf5073
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 323e475243dc0416bc4d0e5c884642685e05d54ed7681de6406a168326846e4e5b220c53ea41b1bcb814ca5159f1d22a75e54baba4e51877cea631f47e8e4398
|
7
|
+
data.tar.gz: b84c10f9be778b1db9577857c39261669fd64889190b2aecaee5dbaf80b07542c75a3a1b976c5b132075875a008338d744ad370437ffdecbc0246b0a802026f1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
+
## 5.2.1
|
4
|
+
|
5
|
+
* Fix env REQUEST_URI
|
6
|
+
* Fix false alert on through association with join sql #301
|
7
|
+
* Fix association.target in through_association can be singular #302
|
8
|
+
|
3
9
|
## 5.2.0 (07/26/2016)
|
4
10
|
|
5
11
|
* Fix `has_cached_counter?` is not defined in HABTM #297
|
data/lib/bullet.rb
CHANGED
@@ -166,8 +166,9 @@ module Bullet
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def perform_out_of_channel_notifications(env = {})
|
169
|
+
request_uri = env['REQUEST_URI'] || build_request_uri(env)
|
169
170
|
for_each_active_notifier_with_notification do |notification|
|
170
|
-
notification.url =
|
171
|
+
notification.url = request_uri
|
171
172
|
notification.notify_out_of_channel
|
172
173
|
end
|
173
174
|
end
|
@@ -217,5 +218,13 @@ module Bullet
|
|
217
218
|
end
|
218
219
|
end
|
219
220
|
end
|
221
|
+
|
222
|
+
def build_request_uri(env)
|
223
|
+
if env['QUERY_STRING'].present?
|
224
|
+
"#{env['PATH_INFO']}?#{env['QUERY_STRING']}"
|
225
|
+
else
|
226
|
+
env['PATH_INFO']
|
227
|
+
end
|
228
|
+
end
|
220
229
|
end
|
221
230
|
end
|
@@ -96,6 +96,7 @@ module Bullet
|
|
96
96
|
|
97
97
|
::ActiveRecord::Associations::JoinDependency.class_eval do
|
98
98
|
alias_method :origin_instantiate, :instantiate
|
99
|
+
alias_method :origin_construct, :construct
|
99
100
|
alias_method :origin_construct_model, :construct_model
|
100
101
|
|
101
102
|
def instantiate(result_set, aliases)
|
@@ -111,6 +112,27 @@ module Bullet
|
|
111
112
|
records
|
112
113
|
end
|
113
114
|
|
115
|
+
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
|
116
|
+
if Bullet.start?
|
117
|
+
unless ar_parent.nil?
|
118
|
+
parent.children.each do |node|
|
119
|
+
key = aliases.column_alias(node, node.primary_key)
|
120
|
+
id = row[key]
|
121
|
+
if id.nil?
|
122
|
+
associations = node.reflection.name
|
123
|
+
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
|
124
|
+
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
|
125
|
+
@bullet_eager_loadings[ar_parent.class] ||= {}
|
126
|
+
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
|
127
|
+
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
origin_construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
|
134
|
+
end
|
135
|
+
|
114
136
|
# call join associations
|
115
137
|
def construct_model(record, node, row, model_cache, id, aliases)
|
116
138
|
result = origin_construct_model(record, node, row, model_cache, id, aliases)
|
@@ -135,9 +157,7 @@ module Bullet
|
|
135
157
|
records = origin_load_target
|
136
158
|
|
137
159
|
if Bullet.start?
|
138
|
-
|
139
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
140
|
-
end
|
160
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
141
161
|
if records.first.class.name !~ /^HABTM_/
|
142
162
|
if records.size > 1
|
143
163
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
@@ -96,6 +96,7 @@ module Bullet
|
|
96
96
|
|
97
97
|
::ActiveRecord::Associations::JoinDependency.class_eval do
|
98
98
|
alias_method :origin_instantiate, :instantiate
|
99
|
+
alias_method :origin_construct, :construct
|
99
100
|
alias_method :origin_construct_model, :construct_model
|
100
101
|
|
101
102
|
def instantiate(result_set, aliases)
|
@@ -111,6 +112,27 @@ module Bullet
|
|
111
112
|
records
|
112
113
|
end
|
113
114
|
|
115
|
+
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
|
116
|
+
if Bullet.start?
|
117
|
+
unless ar_parent.nil?
|
118
|
+
parent.children.each do |node|
|
119
|
+
key = aliases.column_alias(node, node.primary_key)
|
120
|
+
id = row[key]
|
121
|
+
if id.nil?
|
122
|
+
associations = node.reflection.name
|
123
|
+
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
|
124
|
+
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
|
125
|
+
@bullet_eager_loadings[ar_parent.class] ||= {}
|
126
|
+
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
|
127
|
+
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
origin_construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
|
134
|
+
end
|
135
|
+
|
114
136
|
# call join associations
|
115
137
|
def construct_model(record, node, row, model_cache, id, aliases)
|
116
138
|
result = origin_construct_model(record, node, row, model_cache, id, aliases)
|
@@ -135,16 +157,14 @@ module Bullet
|
|
135
157
|
records = origin_load_target
|
136
158
|
|
137
159
|
if Bullet.start?
|
138
|
-
if
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
144
|
-
end
|
160
|
+
if self.is_a? ::ActiveRecord::Associations::ThroughAssociation
|
161
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
|
162
|
+
association = self.owner.association self.through_reflection.name
|
163
|
+
Array(association.target).each do |through_record|
|
164
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
145
165
|
end
|
146
|
-
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
|
147
166
|
end
|
167
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
|
148
168
|
if records.first.class.name !~ /^HABTM_/
|
149
169
|
if records.size > 1
|
150
170
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
data/lib/bullet/version.rb
CHANGED
data/spec/bullet/rack_spec.rb
CHANGED
@@ -60,7 +60,7 @@ module Bullet
|
|
60
60
|
it "should return original response body" do
|
61
61
|
expected_response = Support::ResponseDouble.new "Actual body"
|
62
62
|
app.response = expected_response
|
63
|
-
_, _, response = middleware.call(
|
63
|
+
_, _, response = middleware.call({})
|
64
64
|
expect(response).to eq(expected_response)
|
65
65
|
end
|
66
66
|
|
@@ -68,7 +68,7 @@ module Bullet
|
|
68
68
|
expect(Bullet).to receive(:notification?).and_return(true)
|
69
69
|
expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
|
70
70
|
expect(Bullet).to receive(:perform_out_of_channel_notifications)
|
71
|
-
status, headers, response = middleware.call(
|
71
|
+
status, headers, response = middleware.call({"Content-Type" => "text/html"})
|
72
72
|
expect(headers["Content-Length"]).to eq("56")
|
73
73
|
expect(response).to eq(["<html><head></head><body><bullet></bullet></body></html>"])
|
74
74
|
end
|
@@ -79,7 +79,7 @@ module Bullet
|
|
79
79
|
app.response = response
|
80
80
|
expect(Bullet).to receive(:notification?).and_return(true)
|
81
81
|
expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
|
82
|
-
status, headers, response = middleware.call(
|
82
|
+
status, headers, response = middleware.call({"Content-Type" => "text/html"})
|
83
83
|
expect(headers["Content-Length"]).to eq("58")
|
84
84
|
end
|
85
85
|
end
|
@@ -89,7 +89,7 @@ module Bullet
|
|
89
89
|
|
90
90
|
it "should not call Bullet.start_request" do
|
91
91
|
expect(Bullet).not_to receive(:start_request)
|
92
|
-
middleware.call(
|
92
|
+
middleware.call({})
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
data/spec/bullet_spec.rb
CHANGED
@@ -94,4 +94,47 @@ describe Bullet, focused: true do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
describe '#perform_out_of_channel_notifications' do
|
99
|
+
let(:notification) { double }
|
100
|
+
|
101
|
+
before do
|
102
|
+
allow(Bullet).to receive(:for_each_active_notifier_with_notification).and_yield(notification)
|
103
|
+
allow(notification).to receive(:notify_out_of_channel)
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when called with no args' do
|
107
|
+
it 'should notification.url is nil' do
|
108
|
+
expect(notification).to receive(:url=).with(nil)
|
109
|
+
Bullet.perform_out_of_channel_notifications
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when called with Rack environment hash' do
|
114
|
+
let(:env) {
|
115
|
+
{
|
116
|
+
'PATH_INFO' => '/path',
|
117
|
+
'QUERY_STRING' => 'foo=bar',
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
context "when env['REQUEST_URI'] is nil" do
|
122
|
+
before { env['REQUEST_URI'] = nil }
|
123
|
+
|
124
|
+
it 'should notification.url is built' do
|
125
|
+
expect(notification).to receive(:url=).with('/path?foo=bar')
|
126
|
+
Bullet.perform_out_of_channel_notifications(env)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when env['REQUEST_URI'] is present" do
|
131
|
+
before { env['REQUEST_URI'] = 'http://example.com/path' }
|
132
|
+
|
133
|
+
it "should notification.url is env['REQUEST_URI']" do
|
134
|
+
expect(notification).to receive(:url=).with(env['REQUEST_URI'])
|
135
|
+
Bullet.perform_out_of_channel_notifications(env)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
97
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.2.
|
4
|
+
version: 5.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|