Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/shared/collection-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 12 additions & 16 deletions tests/unit/lib/shared/collection-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
});

});
Expand Down