bullet 4.0.0 → 4.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -1
  4. data/.travis.yml +17 -6
  5. data/CHANGELOG.md +86 -0
  6. data/Gemfile +13 -12
  7. data/Gemfile.mongoid +14 -0
  8. data/Gemfile.mongoid-2.4 +19 -0
  9. data/Gemfile.mongoid-2.5 +19 -0
  10. data/Gemfile.mongoid-2.6 +19 -0
  11. data/Gemfile.mongoid-2.7 +19 -0
  12. data/Gemfile.mongoid-2.8 +19 -0
  13. data/Gemfile.mongoid-3.0 +19 -0
  14. data/Gemfile.mongoid-3.1 +19 -0
  15. data/Gemfile.mongoid-4.0 +19 -0
  16. data/Gemfile.rails-3.0 +19 -0
  17. data/Gemfile.rails-3.1 +19 -0
  18. data/Gemfile.rails-3.2 +19 -0
  19. data/Gemfile.rails-4.0 +19 -0
  20. data/Gemfile.rails-4.1 +19 -0
  21. data/{Hacking.textile → Hacking.md} +10 -5
  22. data/README.md +432 -0
  23. data/Rakefile +13 -6
  24. data/bullet.gemspec +6 -3
  25. data/lib/bullet/active_record3.rb +49 -11
  26. data/lib/bullet/active_record3x.rb +134 -0
  27. data/lib/bullet/{active_record31.rb → active_record4.rb} +45 -15
  28. data/lib/bullet/active_record41.rb +128 -0
  29. data/lib/bullet/dependency.rb +81 -0
  30. data/lib/bullet/detector/association.rb +24 -68
  31. data/lib/bullet/detector/base.rb +0 -6
  32. data/lib/bullet/detector/counter_cache.rb +59 -0
  33. data/lib/bullet/detector/n_plus_one_query.rb +56 -15
  34. data/lib/bullet/detector/unused_eager_loading.rb +84 -0
  35. data/lib/bullet/detector.rb +2 -2
  36. data/lib/bullet/ext/object.rb +10 -2
  37. data/lib/bullet/{mongoid.rb → mongoid2x.rb} +18 -18
  38. data/lib/bullet/mongoid3x.rb +56 -0
  39. data/lib/bullet/mongoid4x.rb +56 -0
  40. data/lib/bullet/notification/base.rb +22 -4
  41. data/lib/bullet/notification/n_plus_one_query.rb +1 -1
  42. data/lib/bullet/notification.rb +2 -0
  43. data/lib/bullet/rack.rb +51 -17
  44. data/lib/bullet/registry/base.rb +1 -1
  45. data/lib/bullet/registry/object.rb +4 -4
  46. data/lib/bullet/version.rb +1 -2
  47. data/lib/bullet.rb +119 -39
  48. data/perf/benchmark.rb +1 -4
  49. data/spec/bullet/detector/association_spec.rb +2 -70
  50. data/spec/bullet/detector/base_spec.rb +0 -6
  51. data/spec/bullet/detector/counter_cache_spec.rb +56 -0
  52. data/spec/bullet/detector/n_plus_one_query_spec.rb +78 -34
  53. data/spec/bullet/detector/unused_eager_loading_spec.rb +88 -0
  54. data/spec/bullet/ext/object_spec.rb +18 -7
  55. data/spec/bullet/ext/string_spec.rb +2 -2
  56. data/spec/bullet/notification/base_spec.rb +68 -15
  57. data/spec/bullet/notification/counter_cache_spec.rb +2 -2
  58. data/spec/bullet/notification/n_plus_one_query_spec.rb +4 -3
  59. data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
  60. data/spec/bullet/notification_collector_spec.rb +4 -4
  61. data/spec/bullet/rack_spec.rb +40 -39
  62. data/spec/bullet/registry/association_spec.rb +3 -3
  63. data/spec/bullet/registry/base_spec.rb +6 -6
  64. data/spec/bullet/registry/object_spec.rb +4 -5
  65. data/spec/bullet_spec.rb +41 -0
  66. data/spec/integration/active_record3/association_spec.rb +662 -0
  67. data/spec/integration/active_record4/association_spec.rb +660 -0
  68. data/spec/integration/counter_cache_spec.rb +63 -0
  69. data/spec/integration/mongoid/association_spec.rb +190 -208
  70. data/spec/models/category.rb +1 -1
  71. data/spec/models/client.rb +1 -1
  72. data/spec/models/comment.rb +2 -2
  73. data/spec/models/document.rb +2 -2
  74. data/spec/models/firm.rb +1 -1
  75. data/spec/models/mongoid/address.rb +2 -0
  76. data/spec/models/mongoid/category.rb +2 -0
  77. data/spec/models/mongoid/comment.rb +2 -0
  78. data/spec/models/mongoid/company.rb +2 -0
  79. data/spec/models/mongoid/entry.rb +2 -0
  80. data/spec/models/mongoid/post.rb +4 -0
  81. data/spec/models/mongoid/user.rb +5 -0
  82. data/spec/models/newspaper.rb +1 -1
  83. data/spec/models/pet.rb +1 -1
  84. data/spec/models/post.rb +6 -13
  85. data/spec/spec_helper.rb +60 -25
  86. data/spec/support/bullet_ext.rb +1 -1
  87. data/spec/support/mongo_seed.rb +26 -2
  88. data/spec/support/sqlite_seed.rb +0 -6
  89. data/test.sh +15 -0
  90. metadata +77 -54
  91. data/.rvmrc +0 -2
  92. data/.rvmrc.example +0 -2
  93. data/Gemfile.lock +0 -132
  94. data/Gemfile.rails-2.3.14 +0 -16
  95. data/Gemfile.rails-2.3.14.lock +0 -65
  96. data/Gemfile.rails-3.0.12 +0 -17
  97. data/Gemfile.rails-3.0.12.lock +0 -116
  98. data/Gemfile.rails-3.1.4 +0 -18
  99. data/Gemfile.rails-3.1.4.lock +0 -134
  100. data/README.textile +0 -395
  101. data/README_for_rails2.textile +0 -400
  102. data/lib/bullet/action_controller2.rb +0 -49
  103. data/lib/bullet/active_record2.rb +0 -121
  104. data/lib/bullet/detector/counter.rb +0 -48
  105. data/lib/bullet/detector/unused_eager_association.rb +0 -42
  106. data/spec/bullet/detector/counter_spec.rb +0 -64
  107. data/spec/bullet/detector/unused_eager_association_spec.rb +0 -62
  108. data/spec/integration/association_spec.rb +0 -593
  109. data/spec/integration/counter_spec.rb +0 -39
  110. data/spec/integration/rails2/association_spec.rb +0 -593
  111. data/spec/integration/rails2/counter_spec.rb +0 -39
  112. data/test.result +0 -2293
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Bullet
4
- module Detector
5
- describe Counter do
6
- before :all do
7
- @post1 = Post.first
8
- @post2 = Post.last
9
- end
10
- before(:each) { Counter.clear }
11
-
12
- context ".clear" do
13
- it "should clear all class variables" do
14
- Counter.class_variable_get(:@@possible_objects).should be_nil
15
- Counter.class_variable_get(:@@impossible_objects).should be_nil
16
- end
17
- end
18
-
19
- context ".add_counter_cache" do
20
- it "should create notification if conditions met" do
21
- Counter.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(true)
22
- Counter.should_receive(:create_notification).with("Post", [:comments])
23
- Counter.add_counter_cache(@post1, [:comments])
24
- end
25
-
26
- it "should not create notification if conditions not met" do
27
- Counter.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(false)
28
- Counter.should_receive(:create_notification).never
29
- Counter.add_counter_cache(@post1, [:comments])
30
- end
31
- end
32
-
33
- context ".add_possible_objects" do
34
- it "should add possible objects" do
35
- Counter.add_possible_objects([@post1, @post2])
36
- Counter.send(:possible_objects).should be_include(@post1.bullet_ar_key)
37
- Counter.send(:possible_objects).should be_include(@post2.bullet_ar_key)
38
- end
39
-
40
- it "should add impossible object" do
41
- Counter.add_impossible_object(@post1)
42
- Counter.send(:impossible_objects).should be_include(@post1.bullet_ar_key)
43
- end
44
- end
45
-
46
- context ".conditions_met?" do
47
- it "should be true when object is possible, not impossible" do
48
- Counter.add_possible_objects(@post1)
49
- Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_true
50
- end
51
-
52
- it "should be false when object is not possible" do
53
- Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
54
- end
55
-
56
- it "should be true when object is possible, and impossible" do
57
- Counter.add_possible_objects(@post1)
58
- Counter.add_impossible_object(@post1)
59
- Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Bullet
4
- module Detector
5
- describe UnusedEagerAssociation do
6
- before(:all) { @post = Post.first }
7
- before(:each) { UnusedEagerAssociation.clear }
8
-
9
- context ".call_associations" do
10
- it "should get empty array if eager_loadgins" do
11
- UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
12
- end
13
-
14
- it "should get call associations if object and association are both in eager_loadings and call_object_associations" do
15
- UnusedEagerAssociation.add_eager_loadings([@post], :association)
16
- UnusedEagerAssociation.add_call_object_associations(@post, :association)
17
- UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
18
- end
19
-
20
- it "should not get call associations if not exist in call_object_associations" do
21
- UnusedEagerAssociation.add_eager_loadings([@post], :association)
22
- UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
23
- end
24
- end
25
-
26
- context ".diff_object_associations" do
27
- it "should return associations not exist in call_association" do
28
- UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
29
- end
30
-
31
- it "should return empty if associations exist in call_association" do
32
- UnusedEagerAssociation.add_eager_loadings([@post], :association)
33
- UnusedEagerAssociation.add_call_object_associations(@post, :association)
34
- UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
35
- end
36
- end
37
-
38
- context ".check_unused_preload_associations" do
39
- it "should set @@checked to true" do
40
- UnusedEagerAssociation.check_unused_preload_associations
41
- UnusedEagerAssociation.class_variable_get(:@@checked).should be_true
42
- end
43
-
44
- it "should create notification if object_association_diff is not empty" do
45
- UnusedEagerAssociation.add_object_associations(@post, :association)
46
- UnusedEagerAssociation.should_receive(:create_notification).with("Post", [:association])
47
- UnusedEagerAssociation.check_unused_preload_associations
48
- end
49
-
50
- it "should not create notification if object_association_diff is empty" do
51
- UnusedEagerAssociation.clear
52
- UnusedEagerAssociation.add_object_associations(@post, :association)
53
- UnusedEagerAssociation.add_eager_loadings([@post], :association)
54
- UnusedEagerAssociation.add_call_object_associations(@post, :association)
55
- UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
56
- UnusedEagerAssociation.should_not_receive(:create_notification).with("Post", [:association])
57
- UnusedEagerAssociation.check_unused_preload_associations
58
- end
59
- end
60
- end
61
- end
62
- end