diff --git a/lib/shared/collection-request.js b/lib/shared/collection-request.js index bba6a068..9dc89e58 100644 --- a/lib/shared/collection-request.js +++ b/lib/shared/collection-request.js @@ -292,27 +292,29 @@ CollectionRequest.prototype.author = function( author ) { }; /** - * Query a collection of posts for a post with a specific slug. + * Query a collection for members with a specific slug. * - * @method name + * @method slug * @chainable - * @param {String} slug A post name (slug), e.g. "hello-world" + * @param {String} slug A post slug (slug), e.g. "hello-world" * @return {CollectionRequest} The CollectionRequest instance (for chaining) */ -CollectionRequest.prototype.name = function( slug ) { - return this.filter( 'name', slug ); +CollectionRequest.prototype.slug = function( slug ) { + return this.param( 'slug', slug ); }; /** - * Alias for `.name()`. + * Alias for .slug() * - * @method slug - * @alias name + * @method name + * @alias slug * @chainable - * @param {String} slug A post slug, e.g. "hello-world" + * @param {String} slug A post name (slug), e.g. "hello-world" * @return {CollectionRequest} The CollectionRequest instance (for chaining) */ -CollectionRequest.prototype.slug = CollectionRequest.prototype.name; +CollectionRequest.prototype.name = function( slug ) { + return this.slug( slug ); +}; /** * Query for posts published in a given year. diff --git a/tests/unit/lib/shared/collection-request.js b/tests/unit/lib/shared/collection-request.js index 39807854..0f4b6ff5 100644 --- a/tests/unit/lib/shared/collection-request.js +++ b/tests/unit/lib/shared/collection-request.js @@ -382,34 +382,30 @@ describe( 'CollectionRequest', function() { }); - describe( 'name()', function() { + describe( 'slug()', function() { - it( 'should set the "name" filter property on the request object', function() { - request.name( 'greatest-post-in-the-world' ); - expect( request._filters.name ).to.equal( 'greatest-post-in-the-world' ); + it( 'should set the "slug" parameter on the request', function() { + request.slug( 'greatest-post-in-the-world' ); + expect( request._renderURI() ).to.equal( '/?slug=greatest-post-in-the-world' ); }); it( 'should be chainable, and replace values', function() { - expect( request.name( 'post-slug-1' ).name( 'hello-world' ) ).to.equal( request ); - expect( request._filters.name ).to.equal( 'hello-world' ); + expect( request.slug( 'post-slug-1' ).slug( 'hello-world' ) ).to.equal( request ); + expect( request._renderURI() ).to.equal( '/?slug=hello-world' ); }); }); - describe( 'slug()', function() { - - it( 'should be an alias for name()', function() { - expect( request.slug ).to.equal( request.name ); - }); + describe( 'name()', function() { - it( 'should set the "name" filter property on the request object', function() { - request.slug( 'greatest-post-in-the-world' ); - expect( request._filters.name ).to.equal( 'greatest-post-in-the-world' ); + it( 'should alias through to set the "slug" parameter on the request', function() { + request.name( 'greatest-post-in-the-world' ); + expect( request._renderURI() ).to.equal( '/?slug=greatest-post-in-the-world' ); }); it( 'should be chainable, and replace values', function() { - expect( request.slug( 'post-slug-1' ).slug( 'hello-world' ) ).to.equal( request ); - expect( request._filters.name ).to.equal( 'hello-world' ); + expect( request.name( 'post-slug-1' ).name( 'hello-world' ) ).to.equal( request ); + expect( request._renderURI() ).to.equal( '/?slug=hello-world' ); }); });