bullet 4.7.1 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +17 -17
  4. data/CHANGELOG.md +15 -0
  5. data/Gemfile +9 -2
  6. data/Gemfile.mongoid-2.4 +22 -0
  7. data/Gemfile.mongoid-2.5 +22 -0
  8. data/Gemfile.mongoid-2.6 +22 -0
  9. data/Gemfile.mongoid-2.7 +22 -0
  10. data/Gemfile.mongoid-2.8 +22 -0
  11. data/Gemfile.mongoid-3.0 +22 -0
  12. data/Gemfile.mongoid-3.1 +22 -0
  13. data/Gemfile.rails-3.0 +21 -0
  14. data/Gemfile.rails-3.1 +21 -0
  15. data/Gemfile.rails-3.2 +21 -0
  16. data/Gemfile.rails-4.0 +21 -0
  17. data/{Gemfile.rails-3.0.20 → Gemfile.rails-4.1} +1 -1
  18. data/README.md +24 -23
  19. data/Rakefile +13 -6
  20. data/lib/bullet.rb +1 -1
  21. data/lib/bullet/active_record41.rb +97 -0
  22. data/lib/bullet/dependency.rb +11 -1
  23. data/lib/bullet/mongoid4x.rb +1 -1
  24. data/lib/bullet/registry/base.rb +1 -1
  25. data/lib/bullet/version.rb +1 -1
  26. data/spec/bullet/detector/association_spec.rb +8 -8
  27. data/spec/bullet/detector/base_spec.rb +1 -1
  28. data/spec/bullet/detector/counter_cache_spec.rb +12 -12
  29. data/spec/bullet/detector/n_plus_one_query_spec.rb +32 -32
  30. data/spec/bullet/detector/unused_eager_loading_spec.rb +18 -18
  31. data/spec/bullet/ext/object_spec.rb +2 -2
  32. data/spec/bullet/ext/string_spec.rb +2 -2
  33. data/spec/bullet/notification/base_spec.rb +19 -13
  34. data/spec/bullet/notification/counter_cache_spec.rb +2 -2
  35. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
  36. data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
  37. data/spec/bullet/notification_collector_spec.rb +4 -4
  38. data/spec/bullet/rack_spec.rb +21 -21
  39. data/spec/bullet/registry/association_spec.rb +3 -3
  40. data/spec/bullet/registry/base_spec.rb +6 -6
  41. data/spec/bullet/registry/object_spec.rb +2 -2
  42. data/spec/integration/active_record3/association_spec.rb +107 -107
  43. data/spec/integration/active_record4/association_spec.rb +105 -105
  44. data/spec/integration/counter_cache_spec.rb +4 -4
  45. data/spec/integration/mongoid/association_spec.rb +52 -52
  46. data/spec/spec_helper.rb +0 -1
  47. data/test.sh +12 -11
  48. metadata +25 -38
  49. data/.ruby-gemset +0 -1
  50. data/.ruby-version +0 -1
  51. data/Gemfile.lock +0 -160
  52. data/Gemfile.mongoid-2.4.12 +0 -15
  53. data/Gemfile.mongoid-2.4.12.lock +0 -163
  54. data/Gemfile.mongoid-2.5.2 +0 -15
  55. data/Gemfile.mongoid-2.5.2.lock +0 -163
  56. data/Gemfile.mongoid-2.6.0 +0 -15
  57. data/Gemfile.mongoid-2.6.0.lock +0 -163
  58. data/Gemfile.mongoid-2.7.1 +0 -15
  59. data/Gemfile.mongoid-2.7.1.lock +0 -163
  60. data/Gemfile.mongoid-2.8.1 +0 -15
  61. data/Gemfile.mongoid-2.8.1.lock +0 -166
  62. data/Gemfile.mongoid-3.0.23 +0 -15
  63. data/Gemfile.mongoid-3.0.23.lock +0 -163
  64. data/Gemfile.mongoid-3.1.5 +0 -15
  65. data/Gemfile.mongoid-3.1.5.lock +0 -163
  66. data/Gemfile.mongoid.lock +0 -167
  67. data/Gemfile.rails-3.0.20.lock +0 -147
  68. data/Gemfile.rails-3.1.12 +0 -14
  69. data/Gemfile.rails-3.1.12.lock +0 -157
  70. data/Gemfile.rails-3.2.15 +0 -14
  71. data/Gemfile.rails-3.2.15.lock +0 -155
  72. data/Gemfile.rails-4.0.1 +0 -14
  73. data/Gemfile.rails-4.0.1.lock +0 -150
data/Rakefile CHANGED
@@ -3,7 +3,6 @@ require "bundler"
3
3
  Bundler.setup
4
4
 
5
5
  require "rake"
6
- require "rdoc/task"
7
6
  require "rspec"
8
7
  require "rspec/core/rake_task"
9
8
 
@@ -35,11 +34,19 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
35
34
  spec.pattern = "spec/**/*_spec.rb"
36
35
  end
37
36
 
38
- Rake::RDocTask.new do |rdoc|
39
- rdoc.rdoc_dir = "rdoc"
40
- rdoc.title = "bullet #{Bullet::VERSION}"
41
- rdoc.rdoc_files.include("README*")
42
- rdoc.rdoc_files.include("lib/**/*.rb")
37
+
38
+ begin
39
+ require 'rdoc/task'
40
+
41
+ desc "Generate documentation for the plugin."
42
+ Rake::RDocTask.new do |rdoc|
43
+ rdoc.rdoc_dir = "rdoc"
44
+ rdoc.title = "bullet #{Bullet::VERSION}"
45
+ rdoc.rdoc_files.include("README*")
46
+ rdoc.rdoc_files.include("lib/**/*.rb")
47
+ end
48
+ rescue LoadError
49
+ puts 'RDocTask is not supported for this platform'
43
50
  end
44
51
 
45
52
  task :default => :spec
@@ -66,7 +66,7 @@ module Bullet
66
66
 
67
67
  def add_whitelist(options)
68
68
  @whitelist[options[:type]][options[:class_name].classify] ||= []
69
- @whitelist[options[:type]][options[:class_name].classify] << options[:association].to_s.tableize.to_sym
69
+ @whitelist[options[:type]][options[:class_name].classify] << options[:association]
70
70
  end
71
71
 
72
72
  def get_whitelist_associations(type, class_name)
@@ -0,0 +1,97 @@
1
+ module Bullet
2
+ module ActiveRecord
3
+ def self.enable
4
+ require 'active_record'
5
+ ::ActiveRecord::Relation.class_eval do
6
+ alias_method :origin_to_a, :to_a
7
+ # if select a collection of objects, then these objects have possible to cause N+1 query.
8
+ # if select only one object, then the only one object has impossible to cause N+1 query.
9
+ def to_a
10
+ records = origin_to_a
11
+ if records.first.class.name !~ /^HABTM_/
12
+ if records.size > 1
13
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
14
+ Bullet::Detector::CounterCache.add_possible_objects(records)
15
+ elsif records.size == 1
16
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
17
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
18
+ end
19
+ end
20
+ records
21
+ end
22
+ end
23
+
24
+ ::ActiveRecord::Associations::Preloader.class_eval do
25
+ alias_method :origin_preloaders_on, :preloaders_on
26
+
27
+ def preloaders_on(association, records, scope)
28
+ if records.first.class.name !~ /^HABTM_/
29
+ records.each do |record|
30
+ Bullet::Detector::Association.add_object_associations(record, association)
31
+ end
32
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
33
+ end
34
+ origin_preloaders_on(association, records, scope)
35
+ end
36
+ end
37
+
38
+ ::ActiveRecord::FinderMethods.class_eval do
39
+ # add includes in scope
40
+ alias_method :origin_find_with_associations, :find_with_associations
41
+ def find_with_associations
42
+ records = origin_find_with_associations
43
+ associations = (eager_load_values + includes_values).uniq
44
+ records.each do |record|
45
+ Bullet::Detector::Association.add_object_associations(record, associations)
46
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
47
+ end
48
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
49
+ records
50
+ end
51
+ end
52
+
53
+ ::ActiveRecord::Associations::JoinDependency.class_eval do
54
+ alias_method :origin_construct_model, :construct_model
55
+ # call join associations
56
+ def construct_model(record, node, row, model_cache, id, aliases)
57
+ associations = node.reflection.name
58
+ Bullet::Detector::Association.add_object_associations(record, associations)
59
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
60
+ origin_construct_model(record, node, row, model_cache, id, aliases)
61
+ end
62
+ end
63
+
64
+ ::ActiveRecord::Associations::CollectionAssociation.class_eval do
65
+ # call one to many associations
66
+ alias_method :origin_load_target, :load_target
67
+ def load_target
68
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
69
+ origin_load_target
70
+ end
71
+ end
72
+
73
+ ::ActiveRecord::Associations::SingularAssociation.class_eval do
74
+ # call has_one and belongs_to associations
75
+ alias_method :origin_reader, :reader
76
+ def reader(force_reload = false)
77
+ result = origin_reader(force_reload)
78
+ if @owner.class.name !~ /^HABTM_/
79
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
80
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
81
+ end
82
+ result
83
+ end
84
+ end
85
+
86
+ ::ActiveRecord::Associations::HasManyAssociation.class_eval do
87
+ alias_method :origin_has_cached_counter?, :has_cached_counter?
88
+
89
+ def has_cached_counter?(reflection = reflection)
90
+ result = origin_has_cached_counter?(reflection)
91
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
92
+ result
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -18,8 +18,10 @@ module Bullet
18
18
  'active_record3'
19
19
  elsif active_record31? || active_record32?
20
20
  'active_record3x'
21
- elsif active_record4?
21
+ elsif active_record40?
22
22
  'active_record4'
23
+ elsif active_record41?
24
+ 'active_record41'
23
25
  end
24
26
  end
25
27
  end
@@ -56,6 +58,14 @@ module Bullet
56
58
  active_record3? && ::ActiveRecord::VERSION::MINOR == 2
57
59
  end
58
60
 
61
+ def active_record40?
62
+ active_record4? && ::ActiveRecord::VERSION::MINOR == 0
63
+ end
64
+
65
+ def active_record41?
66
+ active_record4? && ::ActiveRecord::VERSION::MINOR == 1
67
+ end
68
+
59
69
  def mongoid2x?
60
70
  mongoid? && ::Mongoid::VERSION =~ /\A2\.[4-8]/
61
71
  end
@@ -44,7 +44,7 @@ module Bullet
44
44
  alias_method :origin_set_relation, :set_relation
45
45
 
46
46
  def set_relation(name, relation)
47
- if relation && relation.metadata.macro !~ /embed/
47
+ if relation && relation.relation_metadata.macro !~ /embed/
48
48
  Bullet::Detector::NPlusOneQuery.call_association(self, name)
49
49
  end
50
50
  origin_set_relation(name, relation)
@@ -33,7 +33,7 @@ module Bullet
33
33
  end
34
34
 
35
35
  def include?(key, value)
36
- @registry[key] && @registry[key].include?(value)
36
+ !@registry[key].nil? && @registry[key].include?(value)
37
37
  end
38
38
  end
39
39
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.7.1"
3
+ VERSION = "4.8.0"
4
4
  end
@@ -12,32 +12,32 @@ module Bullet
12
12
  context ".start_request" do
13
13
  it "should set @@checked to false" do
14
14
  Association.start_request
15
- Association.class_variable_get(:@@checked).should be_false
15
+ expect(Association.class_variable_get(:@@checked)).to eq false
16
16
  end
17
17
  end
18
18
 
19
19
  context ".clear" do
20
20
  it "should clear all class variables" do
21
21
  Association.clear
22
- Association.class_variable_get(:@@object_associations).should be_nil
23
- Association.class_variable_get(:@@possible_objects).should be_nil
24
- Association.class_variable_get(:@@impossible_objects).should be_nil
25
- Association.class_variable_get(:@@call_object_associations).should be_nil
26
- Association.class_variable_get(:@@eager_loadings).should be_nil
22
+ expect(Association.class_variable_get(:@@object_associations)).to be_nil
23
+ expect(Association.class_variable_get(:@@possible_objects)).to be_nil
24
+ expect(Association.class_variable_get(:@@impossible_objects)).to be_nil
25
+ expect(Association.class_variable_get(:@@call_object_associations)).to be_nil
26
+ expect(Association.class_variable_get(:@@eager_loadings)).to be_nil
27
27
  end
28
28
  end
29
29
 
30
30
  context ".add_object_association" do
31
31
  it "should add object, associations pair" do
32
32
  Association.add_object_associations(@post1, :associations)
33
- Association.send(:object_associations).should be_include(@post1.bullet_ar_key, :associations)
33
+ expect(Association.send(:object_associations)).to be_include(@post1.bullet_ar_key, :associations)
34
34
  end
35
35
  end
36
36
 
37
37
  context ".add_call_object_associations" do
38
38
  it "should add call object, associations pair" do
39
39
  Association.add_call_object_associations(@post1, :associations)
40
- Association.send(:call_object_associations).should be_include(@post1.bullet_ar_key, :associations)
40
+ expect(Association.send(:call_object_associations)).to be_include(@post1.bullet_ar_key, :associations)
41
41
  end
42
42
  end
43
43
  end
@@ -5,7 +5,7 @@ module Bullet
5
5
  describe Base do
6
6
  context ".end_request" do
7
7
  it "should call clear" do
8
- Base.should_receive(:clear)
8
+ expect(Base).to receive(:clear)
9
9
  Base.end_request
10
10
  end
11
11
  end
@@ -11,21 +11,21 @@ module Bullet
11
11
 
12
12
  context ".clear" do
13
13
  it "should clear all class variables" do
14
- CounterCache.class_variable_get(:@@possible_objects).should be_nil
15
- CounterCache.class_variable_get(:@@impossible_objects).should be_nil
14
+ expect(CounterCache.class_variable_get(:@@possible_objects)).to be_nil
15
+ expect(CounterCache.class_variable_get(:@@impossible_objects)).to be_nil
16
16
  end
17
17
  end
18
18
 
19
19
  context ".add_counter_cache" do
20
20
  it "should create notification if conditions met" do
21
- CounterCache.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(true)
22
- CounterCache.should_receive(:create_notification).with("Post", [:comments])
21
+ expect(CounterCache).to receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(true)
22
+ expect(CounterCache).to receive(:create_notification).with("Post", [:comments])
23
23
  CounterCache.add_counter_cache(@post1, [:comments])
24
24
  end
25
25
 
26
26
  it "should not create notification if conditions not met" do
27
- CounterCache.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(false)
28
- CounterCache.should_receive(:create_notification).never
27
+ expect(CounterCache).to receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(false)
28
+ expect(CounterCache).to receive(:create_notification).never
29
29
  CounterCache.add_counter_cache(@post1, [:comments])
30
30
  end
31
31
  end
@@ -33,30 +33,30 @@ module Bullet
33
33
  context ".add_possible_objects" do
34
34
  it "should add possible objects" do
35
35
  CounterCache.add_possible_objects([@post1, @post2])
36
- CounterCache.send(:possible_objects).should be_include(@post1.bullet_ar_key)
37
- CounterCache.send(:possible_objects).should be_include(@post2.bullet_ar_key)
36
+ expect(CounterCache.send(:possible_objects)).to be_include(@post1.bullet_ar_key)
37
+ expect(CounterCache.send(:possible_objects)).to be_include(@post2.bullet_ar_key)
38
38
  end
39
39
 
40
40
  it "should add impossible object" do
41
41
  CounterCache.add_impossible_object(@post1)
42
- CounterCache.send(:impossible_objects).should be_include(@post1.bullet_ar_key)
42
+ expect(CounterCache.send(:impossible_objects)).to be_include(@post1.bullet_ar_key)
43
43
  end
44
44
  end
45
45
 
46
46
  context ".conditions_met?" do
47
47
  it "should be true when object is possible, not impossible" do
48
48
  CounterCache.add_possible_objects(@post1)
49
- CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_true
49
+ expect(CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations)).to eq true
50
50
  end
51
51
 
52
52
  it "should be false when object is not possible" do
53
- CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
53
+ expect(CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations)).to eq false
54
54
  end
55
55
 
56
56
  it "should be true when object is possible, and impossible" do
57
57
  CounterCache.add_possible_objects(@post1)
58
58
  CounterCache.add_impossible_object(@post1)
59
- CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
59
+ expect(CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations)).to eq false
60
60
  end
61
61
  end
62
62
  end
@@ -12,11 +12,11 @@ module Bullet
12
12
  context ".call_association" do
13
13
  it "should set @@checked to true" do
14
14
  NPlusOneQuery.call_association(@post, :associations)
15
- NPlusOneQuery.class_variable_get(:@@checked).should be_true
15
+ expect(NPlusOneQuery.class_variable_get(:@@checked)).to eq true
16
16
  end
17
17
 
18
18
  it "should add call_object_associations" do
19
- NPlusOneQuery.should_receive(:add_call_object_associations).with(@post, :associations)
19
+ expect(NPlusOneQuery).to receive(:add_call_object_associations).with(@post, :associations)
20
20
  NPlusOneQuery.call_association(@post, :associations)
21
21
  end
22
22
  end
@@ -24,71 +24,71 @@ module Bullet
24
24
  context ".possible?" do
25
25
  it "should be true if possible_objects contain" do
26
26
  NPlusOneQuery.add_possible_objects(@post)
27
- NPlusOneQuery.send(:possible?, @post.bullet_ar_key).should be_true
27
+ expect(NPlusOneQuery.send(:possible?, @post.bullet_ar_key)).to eq true
28
28
  end
29
29
  end
30
30
 
31
31
  context ".impossible?" do
32
32
  it "should be true if impossible_objects contain" do
33
33
  NPlusOneQuery.add_impossible_object(@post)
34
- NPlusOneQuery.send(:impossible?, @post.bullet_ar_key).should be_true
34
+ expect(NPlusOneQuery.send(:impossible?, @post.bullet_ar_key)).to eq true
35
35
  end
36
36
  end
37
37
 
38
38
  context ".association?" do
39
39
  it "should be true if object, associations pair is already existed" do
40
40
  NPlusOneQuery.add_object_associations(@post, :association)
41
- NPlusOneQuery.send(:association?, @post.bullet_ar_key, :association).should be_true
41
+ expect(NPlusOneQuery.send(:association?, @post.bullet_ar_key, :association)).to eq true
42
42
  end
43
43
 
44
44
  it "should be false if object, association pair is not existed" do
45
45
  NPlusOneQuery.add_object_associations(@post, :association1)
46
- NPlusOneQuery.send(:association?, @post.bullet_ar_key, :associatio2).should be_false
46
+ expect(NPlusOneQuery.send(:association?, @post.bullet_ar_key, :associatio2)).to eq false
47
47
  end
48
48
  end
49
49
 
50
50
  context ".conditions_met?" do
51
51
  it "should be true if object is possible, not impossible and object, associations pair is not already existed" do
52
- NPlusOneQuery.stub(:possible?).with(@post.bullet_ar_key).and_return(true)
53
- NPlusOneQuery.stub(:impossible?).with(@post.bullet_ar_key).and_return(false)
54
- NPlusOneQuery.stub(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
55
- NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).should be_true
52
+ allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(true)
53
+ allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(false)
54
+ allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
55
+ expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq true
56
56
  end
57
57
 
58
58
  it "should be false if object is not possible, not impossible and object, associations pair is not already existed" do
59
- NPlusOneQuery.stub(:possible?).with(@post.bullet_ar_key).and_return(false)
60
- NPlusOneQuery.stub(:impossible?).with(@post.bullet_ar_key).and_return(false)
61
- NPlusOneQuery.stub(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
62
- NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).should be_false
59
+ allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(false)
60
+ allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(false)
61
+ allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
62
+ expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq false
63
63
  end
64
64
 
65
65
  it "should be false if object is possible, but impossible and object, associations pair is not already existed" do
66
- NPlusOneQuery.stub(:possible?).with(@post.bullet_ar_key).and_return(true)
67
- NPlusOneQuery.stub(:impossible?).with(@post.bullet_ar_key).and_return(true)
68
- NPlusOneQuery.stub(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
69
- NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).should be_false
66
+ allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(true)
67
+ allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(true)
68
+ allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
69
+ expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq false
70
70
  end
71
71
 
72
72
  it "should be false if object is possible, not impossible and object, associations pair is already existed" do
73
- NPlusOneQuery.stub(:possible?).with(@post.bullet_ar_key).and_return(true)
74
- NPlusOneQuery.stub(:impossible?).with(@post.bullet_ar_key).and_return(false)
75
- NPlusOneQuery.stub(:association?).with(@post.bullet_ar_key, :associations).and_return(true)
76
- NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).should be_false
73
+ allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(true)
74
+ allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(false)
75
+ allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(true)
76
+ expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq false
77
77
  end
78
78
  end
79
79
 
80
80
  context ".call_association" do
81
81
  it "should create notification if conditions met" do
82
- NPlusOneQuery.should_receive(:conditions_met?).with(@post.bullet_ar_key, :association).and_return(true)
83
- NPlusOneQuery.should_receive(:caller_in_project).and_return(["caller"])
84
- NPlusOneQuery.should_receive(:create_notification).with(["caller"], "Post", :association)
82
+ expect(NPlusOneQuery).to receive(:conditions_met?).with(@post.bullet_ar_key, :association).and_return(true)
83
+ expect(NPlusOneQuery).to receive(:caller_in_project).and_return(["caller"])
84
+ expect(NPlusOneQuery).to receive(:create_notification).with(["caller"], "Post", :association)
85
85
  NPlusOneQuery.call_association(@post, :association)
86
86
  end
87
87
 
88
88
  it "should not create notification if conditions not met" do
89
- NPlusOneQuery.should_receive(:conditions_met?).with(@post.bullet_ar_key, :association).and_return(false)
90
- NPlusOneQuery.should_not_receive(:caller_in_project!)
91
- NPlusOneQuery.should_not_receive(:create_notification).with("Post", :association)
89
+ expect(NPlusOneQuery).to receive(:conditions_met?).with(@post.bullet_ar_key, :association).and_return(false)
90
+ expect(NPlusOneQuery).not_to receive(:caller_in_project!)
91
+ expect(NPlusOneQuery).not_to receive(:create_notification).with("Post", :association)
92
92
  NPlusOneQuery.call_association(@post, :association)
93
93
  end
94
94
  end
@@ -96,19 +96,19 @@ module Bullet
96
96
  context ".add_possible_objects" do
97
97
  it "should add possible objects" do
98
98
  NPlusOneQuery.add_possible_objects([@post, @post2])
99
- NPlusOneQuery.send(:possible_objects).should be_include(@post.bullet_ar_key)
100
- NPlusOneQuery.send(:possible_objects).should be_include(@post2.bullet_ar_key)
99
+ expect(NPlusOneQuery.send(:possible_objects)).to be_include(@post.bullet_ar_key)
100
+ expect(NPlusOneQuery.send(:possible_objects)).to be_include(@post2.bullet_ar_key)
101
101
  end
102
102
 
103
103
  it "should not raise error if object is nil" do
104
- lambda { NPlusOneQuery.add_possible_objects(nil) }.should_not raise_error
104
+ expect { NPlusOneQuery.add_possible_objects(nil) }.not_to raise_error
105
105
  end
106
106
  end
107
107
 
108
108
  context ".add_impossible_object" do
109
109
  it "should add impossible object" do
110
110
  NPlusOneQuery.add_impossible_object(@post)
111
- NPlusOneQuery.send(:impossible_objects).should be_include(@post.bullet_ar_key)
111
+ expect(NPlusOneQuery.send(:impossible_objects)).to be_include(@post.bullet_ar_key)
112
112
  end
113
113
  end
114
114
  end
@@ -11,42 +11,42 @@ module Bullet
11
11
 
12
12
  context ".call_associations" do
13
13
  it "should get empty array if eager_loadings" do
14
- UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
14
+ expect(UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
15
15
  end
16
16
 
17
17
  it "should get call associations if object and association are both in eager_loadings and call_object_associations" do
18
18
  UnusedEagerLoading.add_eager_loadings([@post], :association)
19
19
  UnusedEagerLoading.add_call_object_associations(@post, :association)
20
- UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
20
+ expect(UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association]))).to eq([:association])
21
21
  end
22
22
 
23
23
  it "should not get call associations if not exist in call_object_associations" do
24
24
  UnusedEagerLoading.add_eager_loadings([@post], :association)
25
- UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
25
+ expect(UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
26
26
  end
27
27
  end
28
28
 
29
29
  context ".diff_object_associations" do
30
30
  it "should return associations not exist in call_association" do
31
- UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
31
+ expect(UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association]))).to eq([:association])
32
32
  end
33
33
 
34
34
  it "should return empty if associations exist in call_association" do
35
35
  UnusedEagerLoading.add_eager_loadings([@post], :association)
36
36
  UnusedEagerLoading.add_call_object_associations(@post, :association)
37
- UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
37
+ expect(UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
38
38
  end
39
39
  end
40
40
 
41
41
  context ".check_unused_preload_associations" do
42
42
  it "should set @@checked to true" do
43
43
  UnusedEagerLoading.check_unused_preload_associations
44
- UnusedEagerLoading.class_variable_get(:@@checked).should be_true
44
+ expect(UnusedEagerLoading.class_variable_get(:@@checked)).to eq true
45
45
  end
46
46
 
47
47
  it "should create notification if object_association_diff is not empty" do
48
48
  UnusedEagerLoading.add_object_associations(@post, :association)
49
- UnusedEagerLoading.should_receive(:create_notification).with("Post", [:association])
49
+ expect(UnusedEagerLoading).to receive(:create_notification).with("Post", [:association])
50
50
  UnusedEagerLoading.check_unused_preload_associations
51
51
  end
52
52
 
@@ -55,8 +55,8 @@ module Bullet
55
55
  UnusedEagerLoading.add_object_associations(@post, :association)
56
56
  UnusedEagerLoading.add_eager_loadings([@post], :association)
57
57
  UnusedEagerLoading.add_call_object_associations(@post, :association)
58
- UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
59
- UnusedEagerLoading.should_not_receive(:create_notification).with("Post", [:association])
58
+ expect(UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
59
+ expect(UnusedEagerLoading).not_to receive(:create_notification).with("Post", [:association])
60
60
  UnusedEagerLoading.check_unused_preload_associations
61
61
  end
62
62
  end
@@ -64,30 +64,30 @@ module Bullet
64
64
  context ".add_eager_loadings" do
65
65
  it "should add objects, associations pair when eager_loadings are empty" do
66
66
  UnusedEagerLoading.add_eager_loadings([@post, @post2], :associations)
67
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :associations)
67
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :associations)
68
68
  end
69
69
 
70
70
  it "should add objects, associations pair for existing eager_loadings" do
71
71
  UnusedEagerLoading.add_eager_loadings([@post, @post2], :association1)
72
72
  UnusedEagerLoading.add_eager_loadings([@post, @post2], :association2)
73
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association1)
74
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association2)
73
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association1)
74
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association2)
75
75
  end
76
76
 
77
77
  it "should merge objects, associations pair for existing eager_loadings" do
78
78
  UnusedEagerLoading.add_eager_loadings([@post], :association1)
79
79
  UnusedEagerLoading.add_eager_loadings([@post, @post2], :association2)
80
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key], :association1)
81
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key], :association2)
82
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association2)
80
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association1)
81
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association2)
82
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association2)
83
83
  end
84
84
 
85
85
  it "should delete objects, associations pair for existing eager_loadings" do
86
86
  UnusedEagerLoading.add_eager_loadings([@post, @post2], :association1)
87
87
  UnusedEagerLoading.add_eager_loadings([@post], :association2)
88
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key], :association1)
89
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post.bullet_ar_key], :association2)
90
- UnusedEagerLoading.send(:eager_loadings).should be_include([@post2.bullet_ar_key], :association1)
88
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association1)
89
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association2)
90
+ expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post2.bullet_ar_key], :association1)
91
91
  end
92
92
  end
93
93
  end