Files
simply_based/spec/build_tree_spec.rb
GregandClaude Opus 4.8 86299b8827 SimplyBased 0.1.0 — Couchbase-native ActiveModel ORM
A from-scratch fork of simply_couch's model layer that runs on Couchbase
natively: `include SimplyBased::Model` instead of `include SimplyCouch::Model`.

- SimplyBased::Store replaces the CouchDB layer: KV documents, N1QL/SQL++
  finders + lazily-created GSIs, CAS mapped onto _rev. No design documents or
  JavaScript map/reduce — the hand-written association views become N1QL
  (belongs_to/has_many/has_one scalar FK; habtm via ANY ... SATISFIES + array
  index, or KV multi-get on the storing side).
- Redis replacements on the same cluster: Counter (atomic increment/decrement),
  Cache (ActiveSupport::Cache::Store over KV+TTL, drop-in Rails.cache/ActiveJob),
  Lock (insert-if-absent + TTL + CAS-checked release).
- Runs the simply_couch test suite against live Couchbase: 378/432 applicable
  examples green (CouchDB-mechanic specs tagged :couchdb_only and excluded).
- Remaining: ancestry (tree) + embedded_in reverse-lookups (recursive/embedded
  N1QL) and a few pagination/lifecycle edges.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 13:58:47 -05:00

41 lines
1.2 KiB
Ruby

require 'spec_helper'
describe "Ancestry.build_tree" do
def node(id, path_ids, position = 0)
d = Directory.new(name: id)
d._id = id
d.path_ids = path_ids
d.position = position
d
end
it "builds a tree from a flat list using path_ids" do
root = node('r', ['r'])
child = node('c', ['r', 'c'])
roots = Directory.build_tree([root, child])
roots.map(&:id).should eq(['r'])
roots.first.children.map(&:id).should eq(['c'])
end
it "does not leak a class-level @tree_wrapper after building" do
Directory.build_tree([node('r', ['r'])])
Directory.instance_variable_get(:@tree_wrapper).should be_nil
end
it "is safe under concurrent calls (no shared-state corruption)" do
threads = (0...8).map do |i|
Thread.new do
root = node("r#{i}", ["r#{i}"])
child = node("c#{i}", ["r#{i}", "c#{i}"])
roots = Directory.build_tree([root, child])
[roots.map(&:id), roots.first.children.map(&:id)]
end
end
results = threads.map(&:value)
results.each_with_index do |(root_ids, child_ids), i|
root_ids.should eq(["r#{i}"])
child_ids.should eq(["c#{i}"])
end
end
end