Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Mar 12, 2014
2 parents 065ec42 + 33762e2 commit 0b474d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/github.com/couchbaselabs/sync_gateway/rest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,21 @@ func TestLogin(t *testing.T) {
assert.True(t, response.Header().Get("Set-Cookie") != "")
}

func TestReadChangesOptionsFromJSON(t *testing.T) {
optStr := `{"feed":"longpoll", "since": 123456, "limit":123, "style": "all_docs",
"include_docs": true, "filter": "Melitta", "channels": ["ABC", "BBC"]}`
feed, options, filter, channelsArray, err := readChangesOptionsFromJSON([]byte(optStr))
assert.Equals(t, err, nil)
assert.Equals(t, feed, "longpoll")
assert.DeepEquals(t, options, db.ChangesOptions{
Since: 123456,
Limit: 123,
Conflicts: true,
IncludeDocs: true})
assert.Equals(t, filter, "Melitta")
assert.DeepEquals(t, channelsArray, []string{"ABC", "BBC"})
}

func TestAccessControl(t *testing.T) {
type viewRow struct {
ID string `json:"id"`
Expand Down
17 changes: 9 additions & 8 deletions src/github.com/couchbaselabs/sync_gateway/rest/changes_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,20 @@ func (h *handler) sendContinuousChangesByWebSocket(inChannels base.Set, options

func readChangesOptionsFromJSON(jsonData []byte) (feed string, options db.ChangesOptions, filter string, channelsArray []string, err error) {
var input struct {
Feed string `json:"feed"`
Since uint64 `json:"since"`
Limit int `json:"limit"`
Style string `json:"style"`
IncludeDocs bool `json:"include_docs"`
Filter string `json:"filter"`
Channels []string `json:"channels"`
Feed string `json:"feed"`
Since interface{} `json:"since"`
Limit int `json:"limit"`
Style string `json:"style"`
IncludeDocs bool `json:"include_docs"`
Filter string `json:"filter"`
Channels []string `json:"channels"`
}
if err = json.Unmarshal(jsonData, &input); err != nil {
return
}
feed = input.Feed
options.Since = input.Since
since, _ := input.Since.(float64) // Unmarshal parses numbers to float64
options.Since = uint64(since)
options.Limit = input.Limit
options.Conflicts = (input.Style == "all_docs")
options.IncludeDocs = input.IncludeDocs
Expand Down

0 comments on commit 0b474d0

Please sign in to comment.