aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-14 07:18:11 -0500
committerCraig Jennings <c@cjennings.net>2026-05-14 07:18:11 -0500
commit266a660cb8db190e0418c5f7062af95e1a31270f (patch)
treea85005ade5f7dc5cb2f288ef003e16d878f78106 /tests
parent0842e18735bb1c47f5d8c20504dd54b895d83f24 (diff)
downloaddotemacs-266a660cb8db190e0418c5f7062af95e1a31270f.tar.gz
dotemacs-266a660cb8db190e0418c5f7062af95e1a31270f.zip
fix(org-roam-config): save journal buffer after copying DONE task
`cj/org-roam-copy-todo-to-today' tried to save the target journal buffer via `org-after-refile-insert-hook' bound to `#'save-buffer', but that value is the wrong shape (single function instead of a hook list), and the only other save mechanism -- the `:after' advice on `org-refile' that calls `org-save-all-org-buffers' -- doesn't attach until `:defer .5' elapses, so the very first DONE transition after startup leaves the journal unsaved. Drop the broken hook binding and save the target buffer explicitly after the refile call. New ERT test asserts `buffer-modified-p' on the journal buffer is nil after the function returns.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-roam-config-copy-and-move.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test-org-roam-config-copy-and-move.el b/tests/test-org-roam-config-copy-and-move.el
index 7925da2b..729afaa8 100644
--- a/tests/test-org-roam-config-copy-and-move.el
+++ b/tests/test-org-roam-config-copy-and-move.el
@@ -57,6 +57,34 @@ when today-file differs from the current buffer file."
(delete-file source)
(delete-file today))))
+(ert-deftest test-org-roam-copy-todo-saves-target-buffer ()
+ "Normal: after the refile into today's journal, the target buffer
+must not be left modified. An unsaved journal buffer is what causes
+Emacs to prompt about unsaved buffers at shutdown."
+ (let ((source (make-temp-file "cj-roam-source-" nil ".org"))
+ (today (make-temp-file "cj-roam-today-" nil ".org")))
+ (unwind-protect
+ (with-temp-buffer
+ (setq buffer-file-name source)
+ (cl-letf (((symbol-function 'org-roam-dailies--capture)
+ (lambda (&rest _)
+ (set-buffer (find-file-noselect today))
+ (goto-char (point-max))))
+ ((symbol-function 'org-refile)
+ (lambda (&rest _)
+ ;; Simulate org-refile inserting into the
+ ;; target buffer (which marks it modified).
+ (with-current-buffer (find-file-noselect today)
+ (goto-char (point-max))
+ (insert "* refiled content\n")))))
+ (cj/org-roam-copy-todo-to-today))
+ (let ((target-buffer (find-buffer-visiting today)))
+ (should target-buffer)
+ (should-not (buffer-modified-p target-buffer))))
+ (when (get-file-buffer today) (kill-buffer (get-file-buffer today)))
+ (delete-file source)
+ (delete-file today))))
+
(ert-deftest test-org-roam-copy-todo-skips-when-already-today ()
"Boundary: when the current buffer already visits today's file, no
refile is issued (same source and target)."