Sha256: 1a0aa8ffab784a4129c92f67202c1423f1233317a54b0da71912900326ad2cf7

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

# This test is just used for http://github.com/flyerhzm/bullet/issues/#issue/14
describe Bullet::Detector::Association do
  before(:each) do
    Bullet.clear
    Bullet.start_request
  end

  after(:each) do
    Bullet.end_request
  end

  describe "for chris" do
    it "should detect unpreload association from deal to hotel" do
      Deal.all.each do |deal|
        deal.hotel.location.name
      end
      Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Deal, :hotel)
    end

    it "should detect unpreload association from hotel to location" do
      Deal.includes(:hotel).each do |deal|
        deal.hotel.location.name
      end
      Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Hotel, :location)
    end

    it "should not detect unpreload association" do
      Deal.includes({:hotel => :location}).each do |deal|
        deal.hotel.location.name
      end
      Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
      Bullet::Detector::Association.should_not be_has_unused_preload_associations
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bullet-2.3.1 spec/integration/association_for_chris_spec.rb
bullet-2.3.0 spec/integration/association_for_chris_spec.rb