bullet 4.14.2 → 4.14.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb724ff2fab91cffc833fdf09ec6c9661b805c50
4
- data.tar.gz: 65a2701588d1af6703608ce5c1e0b8505cf1c330
3
+ metadata.gz: dbe02316f8b3e0b61718c940420f189423c3f5f0
4
+ data.tar.gz: 93db165a6618fb9c470081013e4b2f5fe002c602
5
5
  SHA512:
6
- metadata.gz: e1e047c94101b65ee2360bd04f1432f7cb7965f50b9c613469dcec12603e4f9f4cdd5d973a86e0a68a5bb186d3a49d0cfef92b829b3c1169b9c8f48894ae810c
7
- data.tar.gz: 0ee846a9c3963c6097dc7c98c157df6a78fc553efea2e668336ec20c64b109022dfe9e87e755a6b0807598fbd0de5fdca8c0e8d6bea2f11a439ec8d033fe3cab
6
+ metadata.gz: 6c9ec0b4e3c23e6de5f59f74cb9378f5db7c32a448a42d4304b2399c3762308bab649dffc7f86bd04aaf175946391df9658994a1a190fb2a64fb8ec5bd21dbb3
7
+ data.tar.gz: 47451dec206f2d05aaa11466d8f6c063bbb9e3e9c03929d7dc8867b11e77be6871ee6a58f1f2b52435db3bb6854e913228dc9b310bf7dd78f5b968de5f042932
@@ -1,5 +1,9 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.14.3
4
+
5
+ * Fix false positive on create
6
+
3
7
  ## 4.14.2
4
8
 
5
9
  * Hotfix nil object when add_impossible_object
data/README.md CHANGED
@@ -430,4 +430,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
430
430
  Post => [:comments]
431
431
  ```
432
432
 
433
- Copyright (c) 2009 - 2014 Richard Huang (flyerhzm@gmail.com), released under the MIT license
433
+ Copyright (c) 2009 - 2015 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -104,8 +104,10 @@ module Bullet
104
104
  alias_method :origin_reader, :reader
105
105
  def reader(force_reload = false)
106
106
  result = origin_reader(force_reload)
107
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
108
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
107
+ unless @inversed
108
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
109
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
110
+ end
109
111
  result
110
112
  end
111
113
  end
@@ -106,8 +106,8 @@ module Bullet
106
106
  alias_method :origin_reader, :reader
107
107
  def reader(force_reload = false)
108
108
  result = origin_reader(force_reload)
109
- if @owner.class.name !~ /^HABTM_/
110
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
109
+ if @owner.class.name !~ /^HABTM_/ && !@inversed
110
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
111
111
  Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
112
112
  end
113
113
  result
@@ -117,8 +117,8 @@ module Bullet
117
117
  alias_method :origin_reader, :reader
118
118
  def reader(force_reload = false)
119
119
  result = origin_reader(force_reload)
120
- if @owner.class.name !~ /^HABTM_/
121
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
120
+ if @owner.class.name !~ /^HABTM_/ && !@inversed
121
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
122
122
  Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
123
123
  end
124
124
  if ::ActiveRecord::Reflection::HasOneReflection === @reflection && result
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.14.2"
3
+ VERSION = "4.14.3"
4
4
  end
@@ -219,6 +219,20 @@ if !mongoid? && active_record4?
219
219
 
220
220
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
221
221
  end
222
+
223
+ it "should not detect unused preload with category => posts" do
224
+ category = Category.first
225
+ category.draft_post.destroy!
226
+ post = category.draft_post
227
+ post.update_attributes!(link: true)
228
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
229
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
230
+
231
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
232
+
233
+ Support::SqliteSeed.setup_db
234
+ Support::SqliteSeed.seed_db
235
+ end
222
236
  end
223
237
 
224
238
  context "category => posts => writer" do
@@ -313,7 +327,7 @@ if !mongoid? && active_record4?
313
327
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
314
328
  end
315
329
 
316
- it "should detect unused preload with comments => post" do
330
+ it "should detect unused preload with comment => post" do
317
331
  Comment.includes(:post).map(&:name)
318
332
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
319
333
  expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Comment, :post)
@@ -3,4 +3,8 @@ class Category < ActiveRecord::Base
3
3
  has_many :entries
4
4
 
5
5
  has_many :users
6
+
7
+ def draft_post
8
+ posts.draft.first_or_create
9
+ end
6
10
  end
@@ -1,4 +1,6 @@
1
1
  class Comment < ActiveRecord::Base
2
2
  belongs_to :post, inverse_of: :comments
3
3
  belongs_to :author, class_name: "BaseUser"
4
+
5
+ validates :post, presence: true
4
6
  end
@@ -3,6 +3,13 @@ class Post < ActiveRecord::Base
3
3
  belongs_to :writer
4
4
  has_many :comments, inverse_of: :post
5
5
 
6
+ validates :category, presence: true
7
+
6
8
  scope :preload_comments, -> { includes(:comments) }
7
9
  scope :in_category_name, ->(name) { where(['categories.name = ?', name]).includes(:category) }
10
+ scope :draft, -> { where(active: false) }
11
+
12
+ def link=(*)
13
+ comments.new
14
+ end
8
15
  end
@@ -56,11 +56,11 @@ if active_record?
56
56
  Support::SqliteSeed.seed_db
57
57
  end
58
58
 
59
- config.before(:each) do
59
+ config.before(:example) do
60
60
  Bullet.start_request
61
61
  end
62
62
 
63
- config.after(:each) do
63
+ config.after(:example) do
64
64
  Bullet.end_request
65
65
  end
66
66
  end
@@ -14,7 +14,7 @@ module Support
14
14
  category2 = Category.create(:name => 'second')
15
15
 
16
16
  post1 = category1.posts.create(:name => 'first', :writer => writer1)
17
- post1a = category1.posts.create(:name => 'like first', :writer => writer2)
17
+ post1a = category1.posts.create(:name => 'like first', :writer => writer2, active: false)
18
18
  post2 = category2.posts.create(:name => 'second', :writer => writer2)
19
19
 
20
20
  comment1 = post1.comments.create(:name => 'first', :author => writer1)
@@ -194,6 +194,7 @@ module Support
194
194
  t.column :name, :string
195
195
  t.column :category_id, :integer
196
196
  t.column :writer_id, :integer
197
+ t.column :active, :boolean, :default => true
197
198
  end
198
199
 
199
200
  create_table :relationships do |t|
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: 4.14.2
4
+ version: 4.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport