Sha256: 8b0f1a9fbd8ccb52ea95b454e323295b4484606974302e4985b02592a5650feb

Contents?: true

Size: 1.77 KB

Versions: 22

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

if !mongoid? && active_record?
  describe Bullet::Detector::CounterCache do
    before(:each) do
      Bullet.start_request
    end

    after(:each) do
      Bullet.end_request
    end

    it "should need counter cache with all cities" do
      Country.all.each do |country|
        country.cities.size
      end
      expect(Bullet.collected_counter_cache_notifications).not_to be_empty
    end

    it "should not need counter cache if already define counter_cache" do
      Person.all.each do |person|
        person.pets.size
      end
      expect(Bullet.collected_counter_cache_notifications).to be_empty
    end

    it "should not need counter cache with only one object" do
      Country.first.cities.size
      expect(Bullet.collected_counter_cache_notifications).to be_empty
    end

    it "should not need counter cache with part of cities" do
      Country.all.each do |country|
        country.cities.where(:name => 'first').size
      end
      expect(Bullet.collected_counter_cache_notifications).to be_empty
    end

    context "disable" do
      before { Bullet.counter_cache_enable = false }
      after { Bullet.counter_cache_enable = true }

      it "should not detect counter cache" do
        Country.all.each do |country|
          country.cities.size
        end
        expect(Bullet.collected_counter_cache_notifications).to be_empty
      end
    end

    context "whitelist" do
      before { Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities }
      after { Bullet.reset_whitelist }

      it "should not detect counter cache" do
        Country.all.each do |country|
          country.cities.size
        end
        expect(Bullet.collected_counter_cache_notifications).to be_empty
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
bullet-4.14.8 spec/integration/counter_cache_spec.rb
bullet_instructure-4.14.8 spec/integration/counter_cache_spec.rb
bullet-4.14.7 spec/integration/counter_cache_spec.rb
bullet_instructure-4.14.7 spec/integration/counter_cache_spec.rb
bullet-4.14.6 spec/integration/counter_cache_spec.rb
bullet-4.14.5 spec/integration/counter_cache_spec.rb
bullet_instructure-4.0.5 spec/integration/counter_cache_spec.rb
bullet-4.14.4 spec/integration/counter_cache_spec.rb
bullet-4.14.3 spec/integration/counter_cache_spec.rb
bullet-4.14.2 spec/integration/counter_cache_spec.rb
bullet-4.14.0 spec/integration/counter_cache_spec.rb
bullet-4.13.2 spec/integration/counter_cache_spec.rb
bullet-4.13.1 spec/integration/counter_cache_spec.rb
bullet_instructure-4.0.3 spec/integration/counter_cache_spec.rb
bullet-4.13.0 spec/integration/counter_cache_spec.rb
bullet-4.12.0 spec/integration/counter_cache_spec.rb
bullet_instructure-4.0.2 spec/integration/counter_cache_spec.rb
bullet-4.11.3 spec/integration/counter_cache_spec.rb
bullet-4.11.2 spec/integration/counter_cache_spec.rb
bullet-4.11.1 spec/integration/counter_cache_spec.rb