Skip to content

Instantly share code, notes, and snippets.

@khustochka
Created August 22, 2020 18:06
Show Gist options
  • Save khustochka/591c0dee826a95a42dfbe0d0c136a1a2 to your computer and use it in GitHub Desktop.
Save khustochka/591c0dee826a95a42dfbe0d0c136a1a2 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "pg"
gem "ancestry", require: false
end
require "active_record"
require "ancestry"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "ancestry_test")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :things, force: true do |t|
t.string :name
t.string :ancestry, index: true
end
end
class Thing < ActiveRecord::Base
has_ancestry
end
class BugTest < Minitest::Test
def test_association_stuff
t = Thing.create!(name: "Parent")
t1 = Thing.create!(parent: t)
t2 = Thing.create!(parent: t)
assert_includes t.subtree_ids, t1.id
assert_includes t.subtree_ids, t2.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment