xeqi / kerodon

interaction and testing library for html based ring apps.
304 stars 22 forks source link

Kerodon redirects me to not existing URL #10

Closed jiriknesl closed 11 years ago

jiriknesl commented 11 years ago

I have a test:

(ns sprint-is.test.routes.auth
    (:use [kerodon.core]
        [kerodon.test]
        [clojure.test]
        [korma.core])
    (:require
        [sprint-is.modules.users]
        [sprint-is.handler]))

(defn setup-db [] 
    (do 
        (delete sprint-is.modules.users/users) 
        (insert sprint-is.modules.users/users (values 
            {:id 1 :email "test@example.com" :salt "salt" :password (sprint-is.modules.users/hash-password "pass" "salt")}))))

(deftest user-can-have-bad-password
    (setup-db)
    (-> 
        (session sprint-is.handler/app)
        (visit "/sign/in")
        (fill-in "E-mail" "test@example.com")
        (fill-in "Password" "bad password")
        (press "Prihlasit")
        (has (text? "Bad Password"))))

And Route:

(ns sprint-is.routes.auth
  (:use compojure.core)
  (:use sprint-is.libs.form)
  (:use flatland.ordered.map)
  (:use sprint-is.libs.errors)
  (:require [sprint-is.views.layout :as layout]
            [noir.response :as response]
            [sprint-is.modules.users :as users]
            [noir.session :as session]
            ))

(defform login-form (ordered-map
    :email {:type :text :value "" :label "E-mail" :errors []}
    :password {:type :password :value "" :label "Password" :errors []}
    :submit {:type :submit :value "Prihlasit" :label "" :errors []}))

(defn login-page
  ([] (login-page (session/flash-get :message)))
  ([message] (layout/render "login.html" {:message message :form (render-form login-form)})))

(defn process-login [email password] 
  (let-or-error (users/login email password) 
    (fn [user] (session/put! :user user) (response/redirect "/"))
    (fn [error] (login-page (error :message)))))

(defn logout-page []
  (session/clear!)
  (response/redirect "/sign/in"))

(defroutes auth-routes
  (GET "/sign/in" [] (login-page))
  (POST "/sign/in" [email password] (process-login email password))
  (GET "/sign/out" [] (logout-page)))

When I run test, Kerodon runs the code, fill in form and click login, but it goes to URL /sign/ instead of /sign/in (after submitting form) so I get "Not found" page. When I (prn) page after (visit "/sign/in"), {:request {:uri}} is "sign/in", after (press "Prihlasit"), the {:request {:uri}} is "/sign/". Form action is empty string

glenjamin commented 11 years ago

It looks like kerodon doesn't correctly handle an empty action - it only handles non-empty actions and when action is omitted entirely.

I'll try and put together a patch for this today.

glenjamin commented 11 years ago

Fixed in 56ce26559a3 - i'll leave the issue open until there's a new release from @xeqi

Apologies for messing with the history a bit there, I accidentally commited with my work email address =/

xeqi commented 11 years ago

0.2.0 has been released with this fixed.