@@ -32,6 +32,7 @@ var _ = Describe("api2go with gingonic router adapter", func() {
3232 contextKey = "userID"
3333 contextValue * string
3434 apiContext api2go.APIContext
35+ userStorage * storage.UserStorage
3536 )
3637
3738 BeforeSuite (func () {
@@ -50,7 +51,7 @@ var _ = Describe("api2go with gingonic router adapter", func() {
5051 return & apiContext
5152 })
5253
53- userStorage : = storage .NewUserStorage ()
54+ userStorage = storage .NewUserStorage ()
5455 chocStorage := storage .NewChocolateStorage ()
5556 api .AddResource (model.User {}, resource.UserResource {ChocStorage : chocStorage , UserStorage : userStorage })
5657
@@ -164,6 +165,53 @@ var _ = Describe("api2go with gingonic router adapter", func() {
164165 })
165166 })
166167
168+ Context ("PaginatedFindAll Test" , func () {
169+ It ("will create links data without double slashes" , func () {
170+
171+ userStorage .Insert (model.User {ID : "1" , Username : "Bender Bending Rodriguez" })
172+ userStorage .Insert (model.User {ID : "2" , Username : "Calculon" })
173+
174+ req , err := http .NewRequest ("GET" , "/api/users?page[offset]=0&page[limit]=1" , nil )
175+
176+ Expect (err ).To (BeNil ())
177+
178+ gg .ServeHTTP (rec , req )
179+
180+ expectedResult := `
181+ {
182+ "links": {
183+ "last": "/api/users?page[limit]=1\u0026page[offset]=1",
184+ "next": "/api/users?page[limit]=1\u0026page[offset]=1"
185+ },
186+ "data": [
187+ {
188+ "type": "users",
189+ "id": "2",
190+ "attributes": {
191+ "user-name": "Bender Bending Rodriguez"
192+ },
193+ "relationships": {
194+ "sweets": {
195+ "links": {
196+ "related": "/api/users/2/sweets",
197+ "self": "/api/users/2/relationships/sweets"
198+ },
199+ "data": []
200+ }
201+ }
202+ }
203+ ],
204+ "meta": {
205+ "author": "The api2go examples crew",
206+ "license": "wtfpl",
207+ "license-url": "http://www.wtfpl.net"
208+ }
209+ }`
210+
211+ Expect (string (rec .Body .Bytes ())).To (MatchJSON (expectedResult ))
212+ })
213+ })
214+
167215 Context ("Gin Context Key Copy Tests" , func () {
168216 BeforeEach (func () {
169217 contextValue = nil
0 commit comments