Code Monkey home page Code Monkey logo

Comments (3)

flyerhzm avatar flyerhzm commented on June 7, 2024

I guess there may be some issue with acts_as_tree, hope I can solve it.

from bullet.

krisleech avatar krisleech commented on June 7, 2024

From my limited investigations I couldn't work out if it was acts_as_tree or STI that was the cause. I think maybe it is a combination of both. The children of a Document, Page or Folder can be a Page or Folder and I think its not being picked up that both have the same base class and thus use the same table for the query. In which case I'm guessing you would need to look down the inheritance chain.
Great work by the way :)

from bullet.

flyerhzm avatar flyerhzm commented on June 7, 2024

Hi, I have add tests about STI in spec/bullet_association_spec.rb from line 775 to line 864. Unfortunately, they all passed. So can you check all of the tests and figure out what do I have missed? Or you can add more tests to make it failure.


describe Bullet::Association, "STI" do
  def setup_db
    ActiveRecord::Schema.define(:version => 1) do
      create_table :documents do |t|
        t.string :name
        t.string :type
        t.integer :parent_id
        t.integer :author_id
      end
      
      create_table :authors do |t|
        t.string :name
      end
    end
  end

  def teardown_db
    ActiveRecord::Base.connection.tables.each do |table|
      ActiveRecord::Base.connection.drop_table(table)
    end
  end
  
  class Document < ActiveRecord::Base
    has_many :children, :class_name => "Document", :foreign_key => 'parent_id'
    belongs_to :parent, :class_name => "Document", :foreign_key => 'parent_id' 
    belongs_to :author
  end

  class Page < Document
  end

  class Folder < Document
  end
  
  class Author < ActiveRecord::Base
    has_many :documents
  end
  
  before(:all) do
    setup_db
    author1 = Author.create(:name => 'author1')
    author2 = Author.create(:name => 'author2')
    folder1 = Folder.create(:name => 'folder1', :author_id => author1.id)
    folder2 = Folder.create(:name => 'folder2', :author_id => author2.id)
    page1 = Page.create(:name => 'page1', :parent_id => folder1.id, :author_id => author1.id)
    page2 = Page.create(:name => 'page2', :parent_id => folder1.id, :author_id => author1.id)
    page3 = Page.create(:name => 'page3', :parent_id => folder2.id, :author_id => author2.id)
    page4 = Page.create(:name => 'page4', :parent_id => folder2.id, :author_id => author2.id)
  end

  before(:each) do
    Bullet::Association.start_request
  end

  after(:each) do
    Bullet::Association.end_request
  end
  
  it "should detect unpreload associations" do
    Page.find(:all).each do |page|
      page.author.name
    end
    Bullet::Association.should be_has_unpreload_associations
    Bullet::Association.check_unused_preload_associations
    Bullet::Association.should_not be_has_unused_preload_associations
  end
  
  it "should not detect unpreload associations" do
    Page.find(:all, :include => :author).each do |page|
      page.author.name
    end
    Bullet::Association.should_not be_has_unpreload_associations
    Bullet::Association.check_unused_preload_associations
    Bullet::Association.should_not be_has_unused_preload_associations
  end
  
  it "should detect unused preload associations" do
    Page.find(:all, :include => :author).collect(&:name)
    Bullet::Association.should_not be_has_unpreload_associations
    Bullet::Association.check_unused_preload_associations
    Bullet::Association.should be_has_unused_preload_associations
  end
  
  it "should not detect unused preload associations" do
    Page.find(:all).collect(&:name)
    Bullet::Association.should_not be_has_unpreload_associations
    Bullet::Association.check_unused_preload_associations
    Bullet::Association.should_not be_has_unused_preload_associations
  end
end

from bullet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.