<commit_before># encoding: utf-8
require_relative '../spec_helper'
require_relative '../../app/models/map'
require_relative '../../app/models/visualization/member'

describe Map do
  before(:each) do
    User.any_instance.stubs(:enable_remote_db_user).returns(true)
    CartoDB::NamedMapsWrapper::NamedMaps.any_instance.stubs(:get => nil, :create => true, :update => true, :delete => true)

    @table = Table.new
    @table.user_id = $user_1.id
    @table.save
  end

  describe '#bounds' do
    it 'checks max-min bounds' do
      new_map = Map.create(user_id: $user_1.id, table_id: @table.id)

      max_value= :maxlon  # 179
      min_value= :minlon  # -179
      value1 = 5
      value2 = 179
      value3 = -179
      value4 = 180
      value5 = -180
      value6 = 0

      new_map.send(:bound_for, value1, min_value, max_value).should eq value1
      new_map.send(:bound_for, value2, min_value, max_value).should eq value2
      new_map.send(:bound_for, value2, min_value, max_value).should eq Map::DEFAULT_BOUNDS[max_value]
      new_map.send(:bound_for, value3, min_value, max_value).should eq value3
      new_map.send(:bound_for, value3, min_value, max_value).should eq Map::DEFAULT_BOUNDS[min_value]
      new_map.send(:bound_for, value4, min_value, max_value).should eq Map::DEFAULT_BOUNDS[max_value]
      new_map.send(:bound_for, value5, min_value, max_value).should eq Map::DEFAULT_BOUNDS[min_value]
      new_map.send(:bound_for, value6, min_value, max_value).should eq value6

      new_map.destroy
    end
  end

  describe '#tables' do
    it 'returns the associated tables' do
      map = Map.create(user_id: $user_1.id, table_id: @table.id)
      @table.reload
      map.reload
      map.tables.map(&:id).should include(@table.id)
      map.destroy
    end

    it 'updates associated tables/vis upon change' do<commit_msg>#4616 spec improved<commit_after># encoding: utf-8
require_relative '../spec_helper'
require_relative '../../app/models/map'
require_relative '../../app/models/visualization/member'

describe Map do
  before(:each) do
    User.any_instance.stubs(:enable_remote_db_user).returns(true)
    CartoDB::NamedMapsWrapper::NamedMaps.any_instance.stubs(:get => nil, :create => true, :update => true, :delete => true)

    @table = Table.new
    @table.user_id = $user_1.id
    @table.save
  end

  describe '#bounds' do
    it 'checks max-min bounds' do
      new_map = Map.create(user_id: $user_1.id, table_id: @table.id)

      max_value= :maxlon  # 179
      min_value= :minlon  # -179
      value1 = 5
      value2 = 179
      value3 = -179
      value4 = 180
      value5 = -180
      value6 = 0

      new_map.send(:bound_for, value1, min_value, max_value).should eq value1
      new_map.send(:bound_for, value2, min_value, max_value).should eq value2
      new_map.send(:bound_for, value2, min_value, max_value).should eq Map::DEFAULT_BOUNDS[max_value]
      new_map.send(:bound_for, value3, min_value, max_value).should eq value3
      new_map.send(:bound_for, value3, min_value, max_value).should eq Map::DEFAULT_BOUNDS[min_value]
      new_map.send(:bound_for, value4, min_value, max_value).should eq Map::DEFAULT_BOUNDS[max_value]
      new_map.send(:bound_for, value5, min_value, max_value).should eq Map::DEFAULT_BOUNDS[min_value]
      new_map.send(:bound_for, value6, min_value, max_value).should eq value6

      # As map has no geometries, bounds should still be default ones instead of zeros
      map_bounds = new_map.send(:get_map_bounds)
      default_bounds = new_map.send(:default_map_bounds)

      map_bounds[:maxx].should eq default_bounds[:max][0]
      map_bounds[:maxy].should eq default_bounds[:max][1]
      map_bounds[:minx].should eq default_bounds[:min][0]
      map_bounds[:miny].should eq default_bounds[:min][1]


      new_map.destroy
    end
  end

  describe '#tables' do
    it 'returns the associated tables' do
      map = Map.create(user_id: $user_1.id, table_id: @table.id)
      @table.reload
      map.reload
      map.tables.map(&:id).should include(@table.id)
      map.destroy
    end

    it 'updates associated tables/vis upon change' do
{'fraction_non_alphanumeric': 0.11997091614154144, 'fraction_numerical': 0.022297624818225885, 'mean_word_length': 3.4907508161044616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7185658', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1402, 'n_words': 307}