Skip to content

Commit

Permalink
Added user name to observers response.
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Feb 23, 2016
1 parent 60f0bb5 commit bcf4787
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ User.findByLogin = function( login, callback ) {
User.assignToObject = function( object, callback ) {
var ids = _.keys( object );
if( ids.length == 0 ) { return callback( null, object ); }
pgClient.connection.query("SELECT id, login, icon_content_type, icon_file_name FROM users WHERE id IN (" + ids.join(",") + ")",
pgClient.connection.query("SELECT id, login, name, icon_content_type, icon_file_name FROM users WHERE id IN (" + ids.join(",") + ")",
function( err, result ) {
if( err ) { return callback( err ); }
_.each( result.rows, function( r ) {
Expand Down
11 changes: 9 additions & 2 deletions test/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe( "routes", function( ) {
before( function( done ) {
pgClient.connection.query( "TRUNCATE TABLE users", function( err, result ) {
pgClient.connection.query( "TRUNCATE TABLE projects", function( err, result ) {
pgClient.connection.query( "INSERT INTO users (id, login, icon_content_type) VALUES ($1, $2, $3)",
[ 123, "a-user", "jpeg" ], function( err, result ) {
pgClient.connection.query( "INSERT INTO users (id, login, name, icon_content_type) VALUES ($1, $2, $3, $4)",
[ 123, "a-user", "A User", "jpeg" ], function( err, result ) {
pgClient.connection.query( "INSERT INTO projects (id, slug, title) VALUES ($1, $2, $3)",
[ 543, "a-project", "A Project" ], function( err, result ) {
done( );
Expand Down Expand Up @@ -129,6 +129,7 @@ describe( "routes", function( ) {
expect( res.body.results[ 1 ].user.id ).to.eq( 123 );
// login comes from the DB
expect( res.body.results[ 1 ].user.login ).to.eq( "a-user" );
expect( res.body.results[ 1 ].user.name ).to.eq( "A User" );
}).expect( 200, done );
});

Expand Down Expand Up @@ -201,6 +202,12 @@ describe( "routes", function( ) {
request( app ).get( "/observations/observers?order_by=species_count" ).
expect( "Content-Type", /json/ ).expect( 200, done );
});

it( "includes user name field", function( ) {
request( app ).get( "/observations/observers" ).expect( function( res ) {
expect( res.results[0].user.name ).to.eq( "A User" );
});
});
});

describe( "observationsSpeciesCounts", function( ) {
Expand Down

0 comments on commit bcf4787

Please sign in to comment.