Make WordPress Core

Ticket #41056: 41056.2.diff

File 41056.2.diff, 3.3 KB (added by adamsilverstein, 8 years ago)
  • src/wp-includes/js/wp-api.js

    diff --git src/wp-includes/js/wp-api.js src/wp-includes/js/wp-api.js
    index 3f950a47f5..634db4357e 100644
     
    11121112                                        'PostsRevisions':  'PostRevisions',
    11131113                                        'PostsTags':       'PostTags'
    11141114                                }
    1115                         };
     1115                        },
     1116
     1117                        modelEndpoints = routeModel.get( 'modelEndpoints' ),
     1118                        modelRegex     = new RegExp( '(?:.*[+)]|\/(' + modelEndpoints.join( '|' ) + '))$' );
    11161119
    11171120                        /**
    11181121                         * Iterate thru the routes, picking up models and collections to build. Builds two arrays,
     
    11371140                                                index !== ( '/' + routeModel.get( 'versionString' ).slice( 0, -1 ) )
    11381141                                ) {
    11391142
    1140                                         // Single items end with a regex (or the special case 'me').
    1141                                         if ( /(?:.*[+)]|\/me)$/.test( index ) ) {
     1143                                        // Single items end with a regex, or a special case word.
     1144                                        if ( modelRegex.test( index ) ) {
    11421145                                                modelRoutes.push( { index: index, route: route } );
    11431146                                        } else {
    11441147
     
    13601363        wp.api.init = function( args ) {
    13611364                var endpoint, attributes = {}, deferred, promise;
    13621365
    1363                 args                     = args || {};
    1364                 attributes.apiRoot       = args.apiRoot || wpApiSettings.root || '/wp-json';
    1365                 attributes.versionString = args.versionString || wpApiSettings.versionString || 'wp/v2/';
    1366                 attributes.schema        = args.schema || null;
     1366                args                      = args || {};
     1367                attributes.apiRoot        = args.apiRoot || wpApiSettings.root || '/wp-json';
     1368                attributes.versionString  = args.versionString || wpApiSettings.versionString || 'wp/v2/';
     1369                attributes.schema         = args.schema || null;
     1370                attributes.modelEndpoints = args.modelEndpoints || [ 'me', 'settings' ];
    13671371                if ( ! attributes.schema && attributes.apiRoot === wpApiSettings.root && attributes.versionString === wpApiSettings.versionString ) {
    13681372                        attributes.schema = wpApiSettings.schema;
    13691373                }
  • tests/qunit/fixtures/wp-api.js

    diff --git tests/qunit/fixtures/wp-api.js tests/qunit/fixtures/wp-api.js
    index c28486d421..04c9dd1823 100644
    var pathToData = { 
    2424        'wp-json/wp/v2/taxonomy': mockedApiResponse.TaxonomyModel,
    2525        'wp-json/wp/v2/status': mockedApiResponse.StatusModel,
    2626        'wp-json/wp/v2/type': mockedApiResponse.TypeModel,
    27         'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema
     27        'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema,
     28        'wp-json/wp/v2/users/me': mockedApiResponse.me,
     29        'wp-json/wp/v2/settings': mockedApiResponse.settings
    2830};
    2931
    3032/**
  • tests/qunit/wp-includes/js/wp-api.js

    diff --git tests/qunit/wp-includes/js/wp-api.js tests/qunit/wp-includes/js/wp-api.js
    index 180942fbce..a64e406a49 100644
     
    115115                'Page',
    116116                'Post',
    117117                'Tag',
    118                 'User'
     118                'User',
     119                'UsersMe',
     120                'Settings'
    119121        ];
    120122
    121123        _.each( modelsWithIdsClassNames, function( className ) {
     
    130132                                assert.ok( theModel, 'We can instantiate wp.api.models.' + className );
    131133                                theModel.fetch().done( function(  ) {
    132134                                        var theModel2 = new wp.api.models[ className ]();
    133                                         theModel2.set( 'id', theModel.attributes[0].id );
     135                                        theModel2.set( 'id', theModel.attributes.id );
    134136                                        theModel2.fetch().done( function() {
    135137
    136138                                                // We were able to retrieve the model.
    137139                                                assert.equal(
    138                                                         theModel.attributes[0].id,
     140                                                        theModel.attributes.id,
    139141                                                        theModel2.get( 'id' ) ,
    140142                                                        'We should be able to get a ' + className
    141143                                                );