Files
simply_based/spec/spec_helper.rb
bterkuileandClaude Sonnet 5 1beb8ead11 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>
2026-07-06 18:35:51 -05:00

33 lines
1.1 KiB
Ruby

require 'pry'
require 'simply_based'
require 'couchbase'
require 'fixtures/couch'
COUCHBASE_URL = ENV.fetch(
'COUCHBASE_URL',
'couchbase://Administrator:password@localhost/simply_based_test'
)
Dir.glob('spec/support/**/*.rb').each { |f| require f.sub(%r{^spec/}, '') }
RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = [:expect, :should] }
config.color = true
config.filter_run_excluding :couchdb_only # CouchDB-mechanic specs with no Couchbase equivalent
# Reverse lookups into embedded documents (querying a foreign key held
# *inside* an embedded array element) are not implemented on Couchbase —
# they would need an UNNEST-based query path. Documented gap.
config.filter_run_excluding :embedded_in_reverse_lookup
config.before(:suite) do
SimplyBased.database_url = COUCHBASE_URL
SimplyBased.database.create_database! # primary index
end
config.before(:each) do
$performed_queries = []
SimplyBased.database_url = COUCHBASE_URL
SimplyBased.database.drop_database! # clear documents between examples
end
end