1

I have the next resource as:

angular.module('resources.venue', ['ngResource'])
  .factory('Venue', function($resource) {
    return $resource('/venue/:id', { id: '@_id' },{ update: { method: 'PUT' } });
  });

And Im testing it like this:

describe('Venue Resource', function() {
  var Venue, $httpBackend;
  var id = '123456789012345678901234';

  beforeEach(module('resources.venue'));

  beforeEach(inject(function(_Venue_, _$httpBackend_) {
    Venue = _Venue_;
    $httpBackend = _$httpBackend_;
  }));

....

  it('should get one venue', function() {
    $httpBackend.expectGET('/venue/' + id).respond();
    var obj = Venue.get({ "id": id });   // if changed to { "_id": id } it breaks
    $httpBackend.flush();
  });

  it('should put venue', function() {
    var obj = new Venue({ "_id": id });  // if changed to { "id": id } it breaks

    $httpBackend.expectPUT('/venue/' + id, { "_id": id }).respond();
    obj.$update();
    $httpBackend.flush();
  });

....

As i commented, in the get test, if i renamed the "id" property to "_id" i get the error:

Error: Unexpected request: GET /venue?_id=123456789012345678901234
Expected GET /venue/123456789012345678901234

And in the put test, if i renamed the "_id" property to "id" i get:

Error: Unexpected request: PUT /venue
Expected PUT /venue/123456789012345678901234

Im i missing something? I try to look for documentation about how angular treats parameters with underscores but i didnt find any.

roboli
  • 1,418
  • 20
  • 24

0 Answers0