On Jul 23, 9:33 am, Shantanu Kumar <
kumar.shant...@gmail.com> wrote:
> It is likely that the session object is not the correct one. You may like to
> use the get-http-session function from code at the URL below to extract the
> HttpSession object from Compojure's request object. (Compojure request is
> NOT HttpServletRequest object -- it is what you pass on from the route.)
http://bitbucket.org/kumarshantanu/blogjure/src/tip/src/blogjure/mvc/...
>
Using the linked code you lose two of Compojure's biggest advantages:
easily testable code, and server abstraction. You're now forced to be
running your server (which now must be a Servlet container) whenever
you call any of your methods.
Using the gist I posted above you can call anything in your app from
the repl without even starting a webserver.
user> (home-controller {:username "lrenn"})
"<html><body><h2>Home<p>Hello lrenn.</p></h2></body></
html>"
user> (home-controller {})
[302 {:headers {"Location" "/
login"}}]
user> (login-view {:message "Some flash message."})
"<html><body><h2>Login</h2><h4>Some flash message.</h4><form action=\"/
login\" \
method=\"POST\"><input id=\"username\" name=\"username\" type=\"text
\" /><input\
id=\"password\" name=\"password\" type=\"password\" value=\"\" /
><input type=\\
"submit\" value=\"Login\" /></form></body></html>"
Testing if home-controller redirects to the login page if the user
isn't logged in is just a:
(deftest login-redirects
(is (= (home-controller {})
[302 {:headers {"Location" "/login"}}])))
Which could also be run at the repl without the server running.
Luke