Fixing tests
This commit is contained in:
parent
29da5958f8
commit
43952efd77
2 changed files with 11 additions and 7 deletions
|
@ -377,7 +377,12 @@ func respondWithError(h *Handlers, w http.ResponseWriter, r *http.Request, err e
|
||||||
|
|
||||||
func (h *Handlers) Create(model interface{}) http.Handler {
|
func (h *Handlers) Create(model interface{}) http.Handler {
|
||||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||||
h.post(w, r, reflect.ModelNameLowerPlural(model), h.Config.CreatePattern())
|
switch r.Method {
|
||||||
|
case "GET":
|
||||||
|
h.get(w, r, reflect.ModelNameLowerPlural(model), h.Config.CreatePattern())
|
||||||
|
case "POST":
|
||||||
|
h.post(w, r, reflect.ModelNameLowerPlural(model), h.Config.CreatePattern())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.HandlerFunc(fn)
|
return http.HandlerFunc(fn)
|
||||||
|
|
|
@ -263,7 +263,7 @@ func (t *testSuite) TestReadContest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSuite) TestSchoolSubscriptionForm() {
|
func (t *testSuite) TestSchoolSubscriptionForm() {
|
||||||
req, err := handlers.NewCreateRequest(&orm.School{}, "/create/", "html", "GET", nil)
|
req, err := handlers.NewCreateRequest(&orm.School{}, "/schools/create/", "html", "GET", nil)
|
||||||
t.Nil(err)
|
t.Nil(err)
|
||||||
|
|
||||||
req, err = login(req, handlers, "subscriber", "subscribe")
|
req, err = login(req, handlers, "subscriber", "subscribe")
|
||||||
|
@ -272,7 +272,7 @@ func (t *testSuite) TestSchoolSubscriptionForm() {
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Handle("/schools/create", handlers.Create(&orm.School{}))
|
router.Handle("/schools/create/", handlers.Create(&orm.School{}))
|
||||||
router.ServeHTTP(rr, req)
|
router.ServeHTTP(rr, req)
|
||||||
|
|
||||||
t.Equal(http.StatusOK, rr.Code)
|
t.Equal(http.StatusOK, rr.Code)
|
||||||
|
@ -311,7 +311,7 @@ func (t *testSuite) TestSchoolSubscription() {
|
||||||
form.Add("Code", "123")
|
form.Add("Code", "123")
|
||||||
form.Add("Email", "foo@school.org")
|
form.Add("Email", "foo@school.org")
|
||||||
|
|
||||||
req, err := handlers.NewCreateRequest(&orm.School{}, "/create/", "html", "POST", form)
|
req, err := handlers.NewCreateRequest(&orm.School{}, "/schools/create/", "html", "POST", form)
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
t.Nil(err)
|
t.Nil(err)
|
||||||
|
|
||||||
|
@ -338,7 +338,6 @@ func (t *testSuite) TestSchoolSubscription() {
|
||||||
}
|
}
|
||||||
ok := true
|
ok := true
|
||||||
doc.Find("dd").Each(func(i int, s *goquery.Selection) {
|
doc.Find("dd").Each(func(i int, s *goquery.Selection) {
|
||||||
log.Print(s)
|
|
||||||
t.Equal(expected[i], s.Text())
|
t.Equal(expected[i], s.Text())
|
||||||
if t.Failed() {
|
if t.Failed() {
|
||||||
ok = false
|
ok = false
|
||||||
|
@ -367,7 +366,7 @@ func (t *testSuite) TestSchoolSubscription() {
|
||||||
form.Add("category_id", "1")
|
form.Add("category_id", "1")
|
||||||
form.Add("school_id", strconv.Itoa(int(school.ID)))
|
form.Add("school_id", strconv.Itoa(int(school.ID)))
|
||||||
|
|
||||||
req, err := handlers.NewCreateRequest(&orm.Participant{}, "/create/", "html", "POST", form)
|
req, err := handlers.NewCreateRequest(&orm.Participant{}, "/participants/create/", "html", "POST", form)
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
t.Nil(err)
|
t.Nil(err)
|
||||||
|
|
||||||
|
@ -377,7 +376,7 @@ func (t *testSuite) TestSchoolSubscription() {
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Handle("/create/", handlers.Create(&orm.Participant{}))
|
router.Handle("/participants/create/", handlers.Create(&orm.Participant{}))
|
||||||
router.ServeHTTP(rr, req)
|
router.ServeHTTP(rr, req)
|
||||||
|
|
||||||
t.Equal(http.StatusSeeOther, rr.Code)
|
t.Equal(http.StatusSeeOther, rr.Code)
|
||||||
|
|
Loading…
Reference in a new issue