Files
simply_based/spec/retry_on_error_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

32 lines
1.3 KiB
Ruby

require 'spec_helper'
describe 'Retry on error' do
it 'retries the save on connection error' do
user = User.create(name: 'Mickey Mouse', title: 'Dr.', homepage: 'www.gmx.de')
error = Errno::ECONNREFUSED.new('Connection refused - connect(2)')
expect(SimplyBased.database).to receive(:save_document).once.and_raise(error).ordered
expect(SimplyBased.database).to receive(:save_document).once.and_return(true).ordered
user.name = 'bert'
expect(user.save).to be true
end
it 'retries the save! on connection error' do
error = Errno::ECONNREFUSED.new('Connection refused - connect(2)')
expect(SimplyBased.database).to receive(:save_document).once.and_raise(error).ordered
expect(SimplyBased.database).to receive(:save_document).once.and_return(true).ordered
user = User.create(name: 'Mickey Mouse', title: 'Dr.', homepage: 'www.gmx.de')
expect(user).to be_truthy
end
it 're-raises the error if retried several times' do
error = Errno::ECONNREFUSED.new('Connection refused - connect(2)')
expect(SimplyBased.database).to receive(:save_document).exactly(3).times.and_raise(error)
expect {
User.create(name: 'Mickey Mouse', title: 'Dr.', homepage: 'www.gmx.de')
}.to raise_error(Errno::ECONNREFUSED)
end
end