<commit_before>describe('api.layers', function() {

  describe('loadLayer leaflet', function() {
    loadLayerSpecs(function() {
      return L.map($('<div>')[0]).setView([0, 0], 3);
    });
  });

  describe('loadLayer gmaps', function() {
    loadLayerSpecs(function() {
      return new google.maps.Map($('<div>')[0],{
        zoom: 3,
        center: new google.maps.LatLng(0, 0),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });
    });
  });

  //
  // shared specs for each map
  //
  function loadLayerSpecs(mapFn) {

    describe("(shared)", function() {
      var map;
      beforeEach(function() {
        map = mapFn();
      });

      it("should fecth layer when user and pass are specified", function() {
        spyOn($, 'getJSON');
        cartodb.createLayer(map, {
          user: 'development',
          table: 'clubbing',
          host: 'localhost.lan:3000',
          protocol: 'http'
        });
        expect($.getJSON).toHaveBeenCalled();
      });

      it("should fecth layer when a url is specified", function() {
        spyOn($, 'getJSON');
        cartodb.createLayer(map, 'http://test.com/layer.json');
        expect($.getJSON).toHaveBeenCalled();
      });

      it("should not fecth layer when kind and options are specified", function() {
        spyOn($, 'getJSON');
        cartodb.createLayer(map, { kind: 'plain', options: {} });
        expect($.getJSON).not.toHaveBeenCalled();
      });

      it("should create a layer", function() {
        var layer;
        runs(function() {
          cartodb.createLayer(map, { kind: 'plain', options: {} }, function(l) {
            layer = l;
          });
        });
        waits(100);
        runs(function() {
          expect(layer).not.toEqual(undefined);
          expect(layer.type).toEqual('plain');
        });
      });

      it("should create a layer with type", function() {
        var layer;
        runs(function() {
          cartodb.createLayer(map, { kind: 'cartodb', options: {} }, function(l) {
            layer = l;
          });
        });
        waits(100);
        runs(function() {
          expect(layer.type).toEqual('cartodb');
        });
      });

      it("should create a layer with options", function() {
        var layer;
        runs(function() {
          cartodb.createLayer(map, { kind: 'cartodb', options: {} }, {query: 'select test'}, function(l) {
            layer = l;
          });
        });
        waits(100);
        runs(function() {
          expect(layer.options.query).toEqual('select test');
        });
      });


      it("should manage errors", function() {
        var s = sinon.spy();
        runs(function() {
          cartodb.createLayer(map, { options: {} }).on('error', s);
        });
        waits(10);
        runs(function() {
          expect(s.called).toEqual(true);
        });
      });

      it("should call callback if the last argument is a function", function() {
        var layer;
        var s = sinon.spy();
        var s2 = sinon.spy();
        runs(function() {
          cartodb.createLayer(map, { kind: 'plain', options: {} }, s);
          cartodb.createLayer(map, layer={ kind: 'plain', options: {} }, { rambo: 'thebest'} ,s2);
        });
        waits(10);
        runs(function() {
          expect(s.called).toEqual(true);
          expect(layer.options.rambo).toEqual('thebest');
          expect(s2.called).toEqual(true);
        });

      });

      it("should load vis.json", function() {
        var layer;
        var s = sinon.spy();
        runs(function() {
          cartodb.createLayer(map, { 
            updated_at: 'jaja',
            layers: [
              null,
              {kind: 'plain', options: {} }
            ]
          }, s);
        });
        waits(10);
        runs(function() {
          expect(s.called).toEqual(true);
        });
      });
    });

  };
<commit_msg>check that cache_buster is set<commit_after>describe('api.layers', function() {

  describe('loadLayer leaflet', function() {
    loadLayerSpecs(function() {
      return L.map($('<div>')[0]).setView([0, 0], 3);
    });
  });

  describe('loadLayer gmaps', function() {
    loadLayerSpecs(function() {
      return new google.maps.Map($('<div>')[0],{
        zoom: 3,
        center: new google.maps.LatLng(0, 0),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });
    });
  });

  //
  // shared specs for each map
  //
  function loadLayerSpecs(mapFn) {

    describe("(shared)", function() {
      var map;
      beforeEach(function() {
        map = mapFn();
      });

      it("should fecth layer when user and pass are specified", function() {
        spyOn($, 'getJSON');
        cartodb.createLayer(map, {
          user: 'development',
          table: 'clubbing',
          host: 'localhost.lan:3000',
          protocol: 'http'
        });
        expect($.getJSON).toHaveBeenCalled();
      });

      it("should fecth layer when a url is specified", function() {
        spyOn($, 'getJSON');
        cartodb.createLayer(map, 'http://test.com/layer.json');
        expect($.getJSON).toHaveBeenCalled();
      });

      it("should not fecth layer when kind and options are specified", function() {
        spyOn($, 'getJSON');
        cartodb.createLayer(map, { kind: 'plain', options: {} });
        expect($.getJSON).not.toHaveBeenCalled();
      });

      it("should create a layer", function() {
        var layer;
        runs(function() {
          cartodb.createLayer(map, { kind: 'plain', options: {} }, function(l) {
            layer = l;
          });
        });
        waits(100);
        runs(function() {
          expect(layer).not.toEqual(undefined);
          expect(layer.type).toEqual('plain');
        });
      });

      it("should create a layer with type", function() {
        var layer;
        runs(function() {
          cartodb.createLayer(map, { kind: 'cartodb', options: {} }, function(l) {
            layer = l;
          });
        });
        waits(100);
        runs(function() {
          expect(layer.type).toEqual('cartodb');
        });
      });

      it("should create a layer with options", function() {
        var layer;
        runs(function() {
          cartodb.createLayer(map, { kind: 'cartodb', options: {} }, {query: 'select test'}, function(l) {
            layer = l;
          });
        });
        waits(100);
        runs(function() {
          expect(layer.options.query).toEqual('select test');
        });
      });


      it("should manage errors", function() {
        var s = sinon.spy();
        runs(function() {
          cartodb.createLayer(map, { options: {} }).on('error', s);
        });
        waits(10);
        runs(function() {
          expect(s.called).toEqual(true);
        });
      });

      it("should call callback if the last argument is a function", function() {
        var layer;
        var s = sinon.spy();
        var s2 = sinon.spy();
        runs(function() {
          cartodb.createLayer(map, { kind: 'plain', options: {} }, s);
          cartodb.createLayer(map, layer={ kind: 'plain', options: {} }, { rambo: 'thebest'} ,s2);
        });
        waits(10);
        runs(function() {
          expect(s.called).toEqual(true);
          expect(layer.options.rambo).toEqual('thebest');
          expect(s2.called).toEqual(true);
        });

      });

      it("should load vis.json", function() {
        var layer;
        var s = sinon.spy();
        runs(function() {
          cartodb.createLayer(map, { 
            updated_at: 'jaja',
            layers: [
              null,
              {kind: 'plain', options: {} }
            ]
          }, s).done(function(lyr) {
            layer = lyr;
          });
        });
        waits(10);
        runs(function() {
          expect(s.called).toEqual(true);
          expect(layer.model.attributes.extra_params.cache_buster).toEqual('jaja');
        });
      });
    });

  };

{'fraction_non_alphanumeric': 0.1696809846772168, 'fraction_numerical': 0.007535795026375283, 'mean_word_length': 1.8633585041352032, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1527506', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2372, 'n_words': 469}