aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-01-04 12:56:57 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-01-04 12:56:57 -0200
commitebe40543241c902d6e9af12c783ffbcd9b000833 (patch)
tree22435c5654af34159cc6c88c98b15d65e361c85e
parent3d35ecfbf78bb862eb70c3166f6eb35fd4cb9cce (diff)
parent5332946380610d5166c2d7b517a817e021130edd (diff)
Merge pull request #184 from vermiculus/fix-mark-read-logic
Fix mark read logic
-rw-r--r--sx-question.el3
-rw-r--r--test/test-state.el22
2 files changed, 24 insertions, 1 deletions
diff --git a/sx-question.el b/sx-question.el
index 85d3cc5..44dad07 100644
--- a/sx-question.el
+++ b/sx-question.el
@@ -118,7 +118,8 @@ See `sx-question--user-read-list'."
;; Question already present.
((setq cell (assoc .question_id site-cell))
;; Current version is newer than cached version.
- (when (> .last_activity_date (cdr cell))
+ (when (or (not (numberp (cdr cell)))
+ (> .last_activity_date (cdr cell)))
(setcdr cell .last_activity_date)))
;; Question wasn't present.
(t
diff --git a/test/test-state.el b/test/test-state.el
new file mode 100644
index 0000000..7af4a64
--- /dev/null
+++ b/test/test-state.el
@@ -0,0 +1,22 @@
+(defmacro with-question-data (cell id &rest body)
+ (declare (indent 2))
+ `(let ((,cell '((question_id . ,id)
+ (site_par . "emacs")
+ (last_activity_date . 1234123456))))
+ ,@body))
+
+(ert-deftest test-question-mark-read ()
+ "00ccd139248e782cd8316eff65c26aed838c7e46"
+ (with-question-data q 10
+ ;; Check basic logic.
+ (should (sx-question--mark-read q))
+ (should (sx-question--read-p q))
+ (should (not (setcdr (assq 10 (cdr (assoc "emacs" sx-question--user-read-list))) nil)))
+ ;; Don't freak out because the cdr was nil.
+ (should (not (sx-question--read-p q)))
+ (should (sx-question--mark-read q)))
+ (should
+ (with-question-data q nil
+ ;; Don't freak out because question_id was nil.
+ (sx-question--mark-read q))))
+