Skip to content

Commit d75d91d

Browse files
author
Derek Dowling
committed
removing auto-pluralization
1 parent 69ccb17 commit d75d91d

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

client/client.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ envolves concatting a pluralized resource name.
5353
*/
5454
func setPath(url *url.URL, resource string) {
5555

56+
// ensure that path is "/" terminated before concatting resource
5657
if url.Path != "" && !strings.HasSuffix(url.Path, "/") {
5758
url.Path = url.Path + "/"
5859
}
5960

60-
url.Path = fmt.Sprintf("%s%ss", url.Path, resource)
61+
// don't pluralize resource automagically, JSON API spec is agnostic
62+
url.Path = fmt.Sprintf("%s%s", url.Path, resource)
6163
}
6264

6365
/*
@@ -67,6 +69,7 @@ ID specifier.
6769
func setIDPath(url *url.URL, resource string, id string) {
6870
setPath(url, resource)
6971

72+
// concat "/:id" if not empty
7073
if id != "" {
7174
url.Path = strings.Join([]string{url.Path, id}, "/")
7275
}

client/client_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ func TestClientRequest(t *testing.T) {
1919
url := &url.URL{Host: "test"}
2020

2121
Convey("should format properly", func() {
22-
setPath(url, "test")
22+
setPath(url, "tests")
2323
So(url.String(), ShouldEqual, "//test/tests")
2424
})
2525

2626
Convey("should respect an existing path", func() {
2727
url.Path = "admin"
2828
setPath(url, "test")
29-
So(url.String(), ShouldEqual, "//test/admin/tests")
29+
So(url.String(), ShouldEqual, "//test/admin/test")
3030
})
3131
})
3232

3333
Convey("->setIDPath()", func() {
3434
url := &url.URL{Host: "test"}
3535

3636
Convey("should format properly an id url", func() {
37-
setIDPath(url, "test", "1")
37+
setIDPath(url, "tests", "1")
3838
So(url.String(), ShouldEqual, "//test/tests/1")
3939
})
4040
})

client/delete_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package jsc
22

33
import (
4-
"log"
54
"net/http"
65
"net/http/httptest"
76
"testing"
@@ -20,11 +19,9 @@ func TestDelete(t *testing.T) {
2019
baseURL := server.URL
2120

2221
Convey("->Delete()", func() {
23-
resp, err := Delete(baseURL, "test", "1")
22+
resp, err := Delete(baseURL, "tests", "1")
2423

2524
So(err, ShouldBeNil)
26-
log.Printf("patchErr = %+v\n", err)
27-
log.Printf("resp = %+v\n", resp)
2825
So(resp.StatusCode, ShouldEqual, http.StatusOK)
2926
})
3027
})

client/get_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestGet(t *testing.T) {
3030
Convey("->GetList()", func() {
3131

3232
Convey("should handle an object listing request", func() {
33-
json, resp, err := List(baseURL, "test")
33+
json, resp, err := List(baseURL, "tests")
3434

3535
So(err, ShouldBeNil)
3636
So(resp.StatusCode, ShouldEqual, http.StatusOK)
@@ -42,7 +42,7 @@ func TestGet(t *testing.T) {
4242
Convey("->GetObject()", func() {
4343

4444
Convey("should handle a specific object request", func() {
45-
json, resp, err := Fetch(baseURL, "test", "1")
45+
json, resp, err := Fetch(baseURL, "tests", "1")
4646

4747
So(err, ShouldBeNil)
4848
So(resp.StatusCode, ShouldEqual, http.StatusOK)

client/patch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestPatch(t *testing.T) {
2020
baseURL := server.URL
2121

2222
Convey("->Patch()", func() {
23-
object, err := jsh.NewObject("2", "test", nil)
23+
object, err := jsh.NewObject("2", "tests", nil)
2424
So(err, ShouldBeNil)
2525

2626
json, resp, patchErr := Patch(baseURL, object)

client/post_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestPost(t *testing.T) {
2222
baseURL := server.URL
2323

2424
Convey("Post Tests", t, func() {
25-
testObject, err := jsh.NewObject("", "test", attrs)
25+
testObject, err := jsh.NewObject("", "tests", attrs)
2626
So(err, ShouldBeNil)
2727

2828
_, resp, postErr := Post(baseURL, testObject)

0 commit comments

Comments
 (0)