Added a test case for unsetting slugs (and fixed related bug)

This commit is contained in:
Ruben Vereecken 2014-07-10 18:24:02 +02:00
parent 94210fc461
commit 9e296b7c3d
2 changed files with 17 additions and 2 deletions

View file

@ -46,6 +46,7 @@ module.exports.NamedPlugin = (schema) ->
@checkSlugConflicts(next)
else if newSlug is '' and @get 'slug'
@set 'slug', undefined
next()
else
next()
)

View file

@ -209,6 +209,7 @@ ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl
expect(err).toBeNull()
expect(response.statusCode).toBe 409
# Restore Sam
sam.set 'name', samsName
done()
@ -234,6 +235,21 @@ ghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghlfarghlarghl
form = req.form()
form.append('name', 'admin')
it 'should be able to unset a slug by setting an empty name', (done) ->
loginSam (sam) ->
samsName = sam.get 'name'
sam.set 'name', ''
request.put {uri:getURL(urlUser + '/' + sam.id), json: sam.toObject()}, (err, response) ->
expect(err).toBeNull()
expect(response.statusCode).toBe 200
newSam = response.body
# Restore Sam
sam.set 'name', samsName
request.put {uri:getURL(urlUser + '/' + sam.id), json: sam.toObject()}, (err, response) ->
expect(err).toBeNull()
done()
describe 'GET /db/user', ->
it 'logs in as admin', (done) ->
@ -309,8 +325,6 @@ describe 'GET /db/user', ->
# TODO Ruben should be able to fetch other users but probably with restricted data access
# Add to the test case above an extra data check
xit 'can unset name and undefine slug'
xit 'can fetch another user with restricted fields'