Ancestry does not work at all with Rails 3.2.9 #113

ddidier opened this Issue Dec 18, 2012 · 5 comments


None yet
3 participants

ddidier commented Dec 18, 2012

is a fix planned ? thanks


StefanH commented Dec 18, 2012

I will look into it. I assume you're using ancestry 1.3.0?

The tests run for Rails 3.2.9 on master. This will become version 2.0.0.rc1 soon.

ddidier commented Dec 18, 2012

Yes I'm using 1.3.0. I did not extract a failing test case and I did not have investigated very long, but when I updated Rails from 3.2.8 to 3.2.9, all my tests using ancestor blew up... EDITED All objects are root, i.e. #roots returns all my objects.

ddidier commented Dec 18, 2012

I isolated a test case with my model. I don't know if I'm using Rails or Ancestry in a good manner. I stripped down everything to this:

  describe "#113" do

    it "should have only one root" do
      pc_root = create_product_category('PC_Root')
      pc_1 = create_product_category( 'PC_1', pc_root)

      p1 = create_product('P1', [pc_1])

      puts "roots = #{}"  #=> roots = ["PC_X", "PC_Root"]
      ProductCategory.roots.should have(1).item  #=> false


  # ----------------------------------------

  def create_product_category(code, parent=nil)
    product_category =
    # mass-assignment
    product_category.code = code
    product_category.parent = parent!

  def create_product(name, categories)
    product = name)

    # here is the problem (it simulates a bad usage of a factory (girl))
    # if I remove the next 3 lines it works
    product_category = create(:product_category, code: 'PC_X')
    product.product_categories << product_category

    product.product_categories << categories!

try this

product_category.parent_id =

ancestry also works with parent_id

ddidier commented Mar 13, 2013

that's working thanks

StefanH closed this Apr 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment