<commit_before># encoding utf-8

require_relative '../../../spec_helper_min'
require_relative '../../../../lib/carto/named_maps/template'

module Carto
  module NamedMaps
    describe Template do
      include Carto::Factories::Visualizations

      before(:each) do
        bypass_named_maps
      end

      before(:all) do
        @user = FactoryGirl.create(:carto_user, private_tables_enabled: true)

        @map, _, _, @visualization = create_full_visualization(@user)

        @map.layers.reject(&:basemap?).each(&:destroy)
        @map.reload
      end

      describe '#name' do
        it 'should generate the template name correctly' do
          template_hash = Carto::NamedMaps::Template.new(@visualization).to_hash
          template_name = template_hash[:name]

          template_name.should match("^#{Carto::NamedMaps::Template::NAME_PREFIX}")
          template_name.should_not match(/[^a-zA-Z0-9\-\_.]/)
        end
      end

      describe '#layers' do
        describe 'carto layers' do
          before(:all) do
            @carto_layer = FactoryGirl.create(:carto_layer, kind: 'carto', maps: [@map])
            @visualization.reload

            @template_hash = Carto::NamedMaps::Template.new(@visualization).to_hash
          end

          after(:all) do
            @carto_layer.destroy
            @visualization.reload

            @template_hash = nil
          end

          it 'should generate placeholders' do
            @template_hash[:placeholders].length.should be @map.layers.reject(&:basemap?).count
          end

          it 'should have options' do
            @template_hash[:layergroup][:layers].second[:options].should_not be_nil
          end
<commit_msg>add test to check named map version as well<commit_after># encoding utf-8

require_relative '../../../spec_helper_min'
require_relative '../../../../lib/carto/named_maps/template'

module Carto
  module NamedMaps
    describe Template do
      include Carto::Factories::Visualizations

      before(:each) do
        bypass_named_maps
      end

      before(:all) do
        @user = FactoryGirl.create(:carto_user, private_tables_enabled: true)

        @map, _, _, @visualization = create_full_visualization(@user)

        @map.layers.reject(&:basemap?).each(&:destroy)
        @map.reload
      end

      describe '#name' do
        it 'should generate the template name correctly' do
          template_hash = Carto::NamedMaps::Template.new(@visualization).to_hash
          template_name = template_hash[:name]

          template_name.should match("^#{Carto::NamedMaps::Template::NAME_PREFIX}")
          template_name.should_not match(/[^a-zA-Z0-9\-\_.]/)
        end
      end

      it 'should have correct Named Maps version' do
        template_hash = Carto::NamedMaps::Template.new(@visualization).to_hash

        template_hash[:version].should eq Carto::NamedMaps::Template::NAMED_MAPS_VERSION
      end

      describe '#layers' do
        describe 'carto layers' do
          before(:all) do
            @carto_layer = FactoryGirl.create(:carto_layer, kind: 'carto', maps: [@map])
            @visualization.reload

            @template_hash = Carto::NamedMaps::Template.new(@visualization).to_hash
          end

          after(:all) do
            @carto_layer.destroy
            @visualization.reload

            @template_hash = nil
          end

          it 'should generate placeholders' do
            @template_hash[:placeholders].length.should be @map.layers.reject(&:basemap?).count
          end

          it 'should have options' do
            @template_hash[:layergroup][:layers].second[:options].should_not be_nil
          end

{'fraction_non_alphanumeric': 0.11489245848080588, 'fraction_numerical': 0.0016335420637081405, 'mean_word_length': 2.4176744186046513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4927997', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1025, 'n_words': 214}