Skip to content

Instantly share code, notes, and snippets.

@bcoe
Created November 15, 2010 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcoe/700542 to your computer and use it in GitHub Desktop.
Save bcoe/700542 to your computer and use it in GitHub Desktop.
describe 'CouchConnector'
describe 'loadDocument with mocked connection'
before
lastURL = ''
c = new connector.connector({
port: 5984,
host: 'localhost',
user: '',
password: '',
database: 'test'
})
c.connection = {
request: function(url) {
lastURL = url;
}
}
end
it 'should generate a restful URL based on a document id'
c.loadDocument('foobar')
lastURL.should.equal('/foobar')
end
it 'should generate a restful URL based on DB and Keys'
c.loadDocument({
keys: ['name', 'age'],
type: 'person'
})
lastURL.should.equal('/_view/person/by_name_age')
end
it 'should build a url with the get parameter descending'
c.loadDocument({
keys: ['name', 'age'],
type: 'person',
descending: true
})
lastURL.should.equal('/_view/person/by_name_age?descending=true')
end
it 'should build a URL with the get parameters descending and startkey'
c.loadDocument({
keys: ['name', 'age'],
type: 'person',
descending: true,
startkey: ['john', '13'],
endkey: 'foo'
})
lastURL.should.match('startkey=%5B%22john%22%2C%2213%22%5D')
lastURL.should.contain('descending=true')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment