|
194 | 194 | ;; ============================================================================= |
195 | 195 |
|
196 | 196 | (deftest reset-with-islot-value-test |
197 | | - (testing "reset! can use ISlot values directly" |
| 197 | + (testing "reset! throws when using ISlot values from a different database" |
198 | 198 | (with-open [db1 (xdb/xit-db :memory) |
199 | 199 | db2 (xdb/xit-db :memory)] |
200 | 200 | ;; Set up first database with some data |
|
203 | 203 |
|
204 | 204 | ;; Get the value from db1 (which implements ISlot) |
205 | 205 | (let [val-from-db1 @db1] |
206 | | - ;; Reset db2 with the ISlot value |
207 | | - (reset! db2 val-from-db1) |
| 206 | + ;; Attempting to reset db2 with an ISlot from db1 should throw |
| 207 | + (is (thrown? IllegalArgumentException (reset! db2 val-from-db1)))))) |
208 | 208 |
|
209 | | - ;; db2 should now have the same data |
210 | | - (is (= (tu/materialize @db1) (tu/materialize @db2))))))) |
| 209 | + (testing "reset! works when materializing the value first" |
| 210 | + (with-open [db1 (xdb/xit-db :memory) |
| 211 | + db2 (xdb/xit-db :memory)] |
| 212 | + (reset! db1 {:users [{:name "Alice"} {:name "Bob"}] |
| 213 | + :config {:theme "dark"}}) |
| 214 | + |
| 215 | + ;; Materialize the value before passing to reset! |
| 216 | + (reset! db2 (tu/materialize @db1)) |
| 217 | + |
| 218 | + ;; db2 should now have the same data |
| 219 | + (is (= (tu/materialize @db1) (tu/materialize @db2)))))) |
211 | 220 |
|
212 | 221 | (deftest reset-with-nested-islot-value-test |
213 | | - (testing "reset! with nested ISlot values preserves structure" |
| 222 | + (testing "reset! throws when using nested ISlot values from a different database" |
214 | 223 | (with-open [db1 (xdb/xit-db :memory) |
215 | 224 | db2 (xdb/xit-db :memory)] |
216 | 225 | (reset! db1 {:data [[1 2 3] [4 5 6] [7 8 9]]}) |
217 | 226 |
|
218 | 227 | ;; Get a nested value that implements ISlot |
219 | 228 | (let [nested-val (get @db1 :data)] |
| 229 | + ;; Attempting to reset db2 with an ISlot from db1 should throw |
| 230 | + (is (thrown? IllegalArgumentException (reset! db2 nested-val)))))) |
| 231 | + |
| 232 | + (testing "reset! works with nested values when materializing first" |
| 233 | + (with-open [db1 (xdb/xit-db :memory) |
| 234 | + db2 (xdb/xit-db :memory)] |
| 235 | + (reset! db1 {:data [[1 2 3] [4 5 6] [7 8 9]]}) |
| 236 | + |
| 237 | + ;; Materialize the nested value before passing to reset! |
| 238 | + (let [nested-val (tu/materialize (get @db1 :data))] |
220 | 239 | (reset! db2 nested-val) |
221 | 240 | (is (= [[1 2 3] [4 5 6] [7 8 9]] (tu/materialize @db2))))))) |
222 | 241 |
|
|
408 | 427 | (is (= 2 (get (xdb/deref-at db 3) :value)))))) |
409 | 428 |
|
410 | 429 | (deftest reset-preserves-data-integrity-test |
411 | | - (testing "reset! with ISlot values from another database preserves data integrity" |
| 430 | + (testing "reset! with materialized values from another database preserves data integrity" |
412 | 431 | (with-open [db1 (xdb/xit-db :memory) |
413 | 432 | db2 (xdb/xit-db :memory)] |
414 | 433 | ;; Create large nested data |
415 | 434 | (reset! db1 {:data (vec (range 100)) |
416 | 435 | :nested {:more (vec (range 50))}}) |
417 | 436 |
|
418 | | - ;; Reset db2 with the value (materializes for cross-database safety) |
419 | | - (reset! db2 @db1) |
| 437 | + ;; Materialize the value before passing to reset! (required for cross-database) |
| 438 | + (reset! db2 (tu/materialize @db1)) |
420 | 439 |
|
421 | 440 | ;; Verify data integrity |
422 | 441 | (is (= (tu/materialize @db1) (tu/materialize @db2))) |
|
0 commit comments