Permalink
Browse files

Third time's the charm for fixing flash middleware

  • Loading branch information...
1 parent 4e0ecb7 commit 0e01b2000283997b9e0e5e5637af9c386a1cbfb4 @weavejester weavejester committed Jul 6, 2010
Showing with 8 additions and 4 deletions.
  1. +6 −2 ring-core/src/ring/middleware/flash.clj
  2. +2 −2 ring-core/test/ring/middleware/flash_test.clj
View
8 ring-core/src/ring/middleware/flash.clj
@@ -14,8 +14,12 @@
:session session
:flash flash)
response (handler request)
+ session (if (contains? response :session)
+ (response :session)
+ session)
session (if-let [flash (response :flash)]
- (assoc (response :session session) :_flash flash))]
- (if (or session (contains? response :session))
+ (assoc (response :session session) :_flash flash)
+ session)]
+ (if (or flash (response :flash) (contains? response :session))
(assoc response :session session)
response))))
View
4 ring-core/test/ring/middleware/flash_test.clj
@@ -18,10 +18,10 @@
(deftest flash-is-removed-after-read
(let [message {:error "Could not save"}
- handler (wrap-flash (constantly {}))
+ handler (wrap-flash (constantly {:session {:foo "bar"}}))
response (handler {:session {:_flash message}})]
(is (nil? (:flash response)))
- (is (nil? (-> response :session :_flash)))))
+ (is (= (:session response) {:foo "bar"}))))
(deftest flash-doesnt-wipe-session
(let [message {:error "Could not save"}

0 comments on commit 0e01b20

Please sign in to comment.