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>
35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe "CouchDB view token safety", :couchdb_only do
|
|
describe "SimplyBased.assert_safe_view_token!" do
|
|
it "passes valid class / association / property names through unchanged" do
|
|
expect {
|
|
SimplyBased.assert_safe_view_token!('User', :posts, 'Namespaced::Thing', :editor_id, nil)
|
|
}.not_to raise_error
|
|
end
|
|
|
|
it "accepts nested arrays and ignores nil/empty tokens" do
|
|
expect {
|
|
SimplyBased.assert_safe_view_token!([:locale, nil], '', :position)
|
|
}.not_to raise_error
|
|
end
|
|
|
|
it "raises on characters that could break out of the generated JavaScript" do
|
|
["a'b", 'a"b', 'a\\b', "a;b", "a)b", "a{b", "a(b", "a\nb"].each do |bad|
|
|
expect {
|
|
SimplyBased.assert_safe_view_token!(bad)
|
|
}.to raise_error(SimplyBased::Error), "expected #{bad.inspect} to be rejected"
|
|
end
|
|
end
|
|
end
|
|
|
|
it "rejects an association declared with an unsafe name at definition time" do
|
|
expect {
|
|
Class.new do
|
|
include SimplyBased::Model
|
|
belongs_to :"evil'); emit(doc,1);//"
|
|
end
|
|
}.to raise_error(SimplyBased::Error)
|
|
end
|
|
end
|