Fix embedded documents: recursion crash, .all/.count, honest spec exclusion

Live-run finding: the full suite against Couchbase was 423 examples with 17
failures — all in embedding_spec. The session report claimed embedded specs
were 'excluded by design', but the exclusion filter targeted a :embedding tag
no example carries, so the file ran (and failed) all along.

Three fixes:
- HasManyEmbedded::Property#build wired parent_object before installing the
  collection ivar on the parent; parent_object= reaches back into the parent's
  collection getter, which re-entered build -> SystemStackError on any access
  to embedded documents loaded from the database. Install the ivar first.
- EmbeddedClass.all / .count referenced raw JS views (all_documents /
  all_documents_for_count) that the N1QL port silently drops, so .all returned
  [] and .count raised NoMethodError. Rebuilt them by enumerating the parent
  documents (same work as the old view scan, client-side; an UNNEST query can
  replace it later).
- Only reverse lookups (N1QL on a foreign key inside an embedded array) remain
  unsupported: tagged :embedded_in_reverse_lookup and excluded in spec_helper
  with an explanatory comment, replacing the broken :embedding filter line.

embedding_spec.rb: 16 examples, 0 failures against live Couchbase 8.0.1 CE.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
bterkuileandClaude Sonnet 5 committed 2026-07-06 18:35:51 -05:00
1 parent d2202bda03
commit 1beb8ead11
4 files changed
+41 -11

No files matched your search

+8 -2
View File
@@ -1,5 +1,11 @@
require 'spec_helper'
RSpec.configure { |c| c.filter_run_excluding(:embedding) } if defined?(RSpec)
# NOTE: this file used to carry `filter_run_excluding(:embedding)` — but no
# example was tagged :embedding, so nothing was ever excluded and the whole
# file ran (and failed) against Couchbase. The basic embedded flows are now
# fixed and expected green; only reverse lookups (finding embedded documents
# through an N1QL query on a foreign key inside the embedded array) remain
# unimplemented, and are tagged :embedded_in_reverse_lookup below (excluded in
# spec_helper).
describe 'Embedding' do
context 'initialized comments' do
@@ -128,7 +134,7 @@ describe 'Embedding' do
end
end
context 'belongs to strict_post' do
context 'belongs to strict_post', :embedded_in_reverse_lookup do
before do
@user = User.create(name: 'embedding user')
@strict_post = StrictPost.create(user: @user)