All editors now work on a server document at the same time instead of taking turns behind an edit lock. - The document's content is a sequence of Yjs updates (document_updates); DocumentChannel stores and relays them immediately, checks access on subscribe and again whenever links or memberships change. - app/frontend/collab/: the store stays position-based; a binding maps it to a Yjs form with stable row/column ids, so a row inserted by one person doesn't misplace what another is typing. Remote changes are applied only after pending local ones went into Yjs. - Per-person undo (Y.UndoManager), presence via awareness: the others' selections as coloured boxes with names, avatars in the toolbar. - Existing JSON documents convert on first open, deterministically, so two people opening one at once end up with the same Yjs state. - Editors compact the stored updates after 200 and keep a JSON snapshot current for export and duplicating. Edit lock and polling are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.1 KiB
Ruby
53 lines
2.1 KiB
Ruby
require "test_helper"
|
|
|
|
class DocumentTest < ActiveSupport::TestCase
|
|
setup do
|
|
@owner = create_user("owner@example.com")
|
|
@doc = create_document(@owner)
|
|
end
|
|
|
|
test "rejects content that is not a numolus document" do
|
|
doc = @owner.owned_documents.build(title: "x", content: "[1,2]")
|
|
assert_not doc.valid?
|
|
doc.content = "{nope"
|
|
assert_not doc.valid?
|
|
end
|
|
|
|
test "role_for: owner, member, link token, and the strongest grant wins" do
|
|
bob = create_user("bob@example.com")
|
|
assert_equal :owner, @doc.role_for(user: @owner)
|
|
assert_nil @doc.role_for(user: bob)
|
|
|
|
viewer_link = @doc.share_links.create!(role: :viewer, created_by: @owner)
|
|
editor_link = @doc.share_links.create!(role: :editor, created_by: @owner)
|
|
assert_equal :viewer, @doc.role_for(token: viewer_link.token)
|
|
|
|
DocumentMembership.grant!(document: @doc, user: bob, role: :viewer, source: :invite)
|
|
assert_equal :viewer, @doc.role_for(user: bob)
|
|
assert_equal :editor, @doc.role_for(user: bob, token: editor_link.token)
|
|
|
|
editor_link.revoke!
|
|
assert_nil @doc.role_for(token: editor_link.token)
|
|
end
|
|
|
|
test "revoking a link removes access gained through it, but not invitations" do
|
|
carl = create_user("carl@example.com")
|
|
dora = create_user("dora@example.com")
|
|
link = @doc.share_links.create!(role: :editor, created_by: @owner)
|
|
DocumentMembership.grant!(document: @doc, user: carl, role: :editor, source: :link, share_link: link)
|
|
DocumentMembership.grant!(document: @doc, user: dora, role: :editor, source: :link, share_link: link)
|
|
DocumentMembership.grant!(document: @doc, user: dora, role: :viewer, source: :invite)
|
|
|
|
link.revoke!
|
|
assert_nil @doc.role_for(user: carl)
|
|
assert_equal :viewer, @doc.role_for(user: dora)
|
|
end
|
|
|
|
test "a link never weakens a membership" do
|
|
bob = create_user("bob@example.com")
|
|
DocumentMembership.grant!(document: @doc, user: bob, role: :editor, source: :invite)
|
|
DocumentMembership.grant!(document: @doc, user: bob, role: :viewer, source: :link)
|
|
assert_equal :editor, @doc.role_for(user: bob)
|
|
end
|
|
end
|