summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bog-tests.el32
-rw-r--r--bog.el2
2 files changed, 33 insertions, 1 deletions
diff --git a/bog-tests.el b/bog-tests.el
index be045f8..506cd27 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -2,6 +2,15 @@
(require 'org)
(require 'bog)
+;; Modified from magit-tests.el.
+(defmacro bog-tests--with-temp-dir (&rest body)
+ (declare (indent 0) (debug t))
+ (let ((dir (gensym)))
+ `(let ((,dir (file-name-as-directory (make-temp-file "dir" t))))
+ (unwind-protect
+ (let ((default-directory ,dir)) ,@body)
+ (delete-directory ,dir t)))))
+
;;; Citekey functions
@@ -138,6 +147,29 @@
(should-error (bog-citekey-from-notes))))
+;;; PDF functions
+
+(ert-deftest bog-rename-staged-pdf-to-citekey-one-pdf ()
+ (bog-tests--with-temp-dir
+ (let ((bog-stage-directory (expand-file-name "stage"))
+ (bog-pdf-directory (expand-file-name "pdfs"))
+ (citekey "name2010word"))
+ (make-directory bog-stage-directory)
+ (make-directory bog-pdf-directory)
+ (write-region "" nil (expand-file-name "one.pdf" bog-stage-directory))
+ (with-temp-buffer
+ (insert (format "\n* top level\n\n** %s\n\nsome text\n"
+ citekey))
+ (org-mode)
+ (show-all)
+ (re-search-backward bog-citekey-format)
+ (bog-rename-staged-pdf-to-citekey))
+ (should (file-exists-p (expand-file-name
+ (concat citekey ".pdf") bog-pdf-directory)))
+ (should-not (file-exists-p (expand-file-name
+ (concat "one.pdf") bog-pdf-directory))))))
+
+
;;; BibTeX functions
;; `bog-prepare-bib-file'
diff --git a/bog.el b/bog.el
index 00354ff..40235a0 100644
--- a/bog.el
+++ b/bog.el
@@ -265,7 +265,7 @@ The citekey will be taken from the text under point if it matches
(setq staged-pdf (funcall bog-read-file-name
"Select PDF file to rename: ")))
((= 1 num-choices)
- (setq staged-pdf (car choices)))
+ (setq staged-pdf (car staged-pdfs)))
(t
(setq staged-pdf
(expand-file-name (funcall bog-completing-read