<commit_before># encoding : utf-8
class AdTest < ActiveSupport::TestCase

  require 'test_helper'
 
  setup do
    @ad = FactoryGirl.create(:ad)
  end

  test "ad requires everything" do
    a = Ad.new
    a.valid?
    assert a.errors[:status].include?("no puede estar en blanco")
    assert a.errors[:body].include?("no puede estar en blanco")
    assert a.errors[:title].include?("no puede estar en blanco")
    assert a.errors[:user_owner].include?("no puede estar en blanco")
    assert a.errors[:type].include?("no puede estar en blanco")
    assert a.errors[:woeid_code].include?("no puede estar en blanco")
    assert a.errors[:ip].include?("no puede estar en blanco")
  end

  test "ad validates type" do
    # only is allowed "1 2"
    @ad.type = 1
    assert @ad.valid?
    assert_equal @ad.type, 1
    @ad.type = 2
    assert @ad.valid?
    assert_equal @ad.type, 2
    @ad.type = 3
    @ad.valid?
    assert @ad.errors[:type].include?("no es un tipo válido")
  end

  test "ad validates status" do
    # only is allowed "1 2 3"
    @ad.status = 1
    assert @ad.valid?
    assert_equal @ad.status, 1
    @ad.status = 2
    assert @ad.valid?
    assert_equal @ad.status, 2
    @ad.status = 3
    assert @ad.valid?
    assert_equal @ad.status, 3
    @ad.status = 4
    @ad.valid?
    assert @ad.errors[:status].include?("no es un estado válido")
  end

  test "ad check slug" do
    assert_equal @ad.slug, "ordenador-en-vallecas"
  end

  test "ad check type_string" do
    assert_equal @ad.type_string, "regalo"
    @ad.type = 2
    @ad.save
    assert_equal @ad.type_string, "busco"
  end

  test "ad check status_string" do
    assert_equal @ad.status_string, "disponible"
    @ad.status = 2
    @ad.save
    assert_equal @ad.status_string, "reservado"
    @ad.status = 3
    @ad.save
    assert_equal @ad.status_string, "entregado"
  end

  test "ad check status_class" do
    assert_equal @ad.status_class, "available"
    @ad.status = 2
    @ad.save
    assert_equal @ad.status_class, "booked"
    @ad.status = 3
    @ad.save
    assert_equal @ad.status_class, "delivered"
  end

  test "ad validates ip address - fail" do
    @ad.ip = '999.99.9.9'
    @ad.valid?
    assert @ad.errors[:ip].include?("No es una IP válida")
  end

  test "ad validates ip address - success" do
    @ad.ip = '2.2.2.2'
    assert @ad.valid?
  end

end
<commit_msg>[ŧests] disabling ip validation for ad model<commit_after># encoding : utf-8
class AdTest < ActiveSupport::TestCase

  require 'test_helper'
 
  setup do
    @ad = FactoryGirl.create(:ad)
  end

  test "ad requires everything" do
    a = Ad.new
    a.valid?
    assert a.errors[:status].include?("no puede estar en blanco")
    assert a.errors[:body].include?("no puede estar en blanco")
    assert a.errors[:title].include?("no puede estar en blanco")
    assert a.errors[:user_owner].include?("no puede estar en blanco")
    assert a.errors[:type].include?("no puede estar en blanco")
    assert a.errors[:woeid_code].include?("no puede estar en blanco")
    assert a.errors[:ip].include?("no puede estar en blanco")
  end

  test "ad validates type" do
    # only is allowed "1 2"
    @ad.type = 1
    assert @ad.valid?
    assert_equal @ad.type, 1
    @ad.type = 2
    assert @ad.valid?
    assert_equal @ad.type, 2
    @ad.type = 3
    @ad.valid?
    assert @ad.errors[:type].include?("no es un tipo válido")
  end

  test "ad validates status" do
    # only is allowed "1 2 3"
    @ad.status = 1
    assert @ad.valid?
    assert_equal @ad.status, 1
    @ad.status = 2
    assert @ad.valid?
    assert_equal @ad.status, 2
    @ad.status = 3
    assert @ad.valid?
    assert_equal @ad.status, 3
    @ad.status = 4
    @ad.valid?
    assert @ad.errors[:status].include?("no es un estado válido")
  end

  test "ad check slug" do
    assert_equal @ad.slug, "ordenador-en-vallecas"
  end

  test "ad check type_string" do
    assert_equal @ad.type_string, "regalo"
    @ad.type = 2
    @ad.save
    assert_equal @ad.type_string, "busco"
  end

  test "ad check status_string" do
    assert_equal @ad.status_string, "disponible"
    @ad.status = 2
    @ad.save
    assert_equal @ad.status_string, "reservado"
    @ad.status = 3
    @ad.save
    assert_equal @ad.status_string, "entregado"
  end

  test "ad check status_class" do
    assert_equal @ad.status_class, "available"
    @ad.status = 2
    @ad.save
    assert_equal @ad.status_class, "booked"
    @ad.status = 3
    @ad.save
    assert_equal @ad.status_class, "delivered"
  end

#  Disabling IP validation. Some legacy IP are bad (172.16.58.3, 172.16.17.32) 
#  test "ad validates ip address - fail" do
#    @ad.ip = '999.99.9.9'
#    @ad.valid?
#    assert @ad.errors[:ip].include?("No es una IP válida")
#  end
#
#  test "ad validates ip address - success" do
#    @ad.ip = '2.2.2.2'
#    assert @ad.valid?
#  end

end

{'fraction_non_alphanumeric': 0.1291055567031605, 'fraction_numerical': 0.01755835571162983, 'mean_word_length': 2.8398096748612214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '318848', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1746, 'n_words': 488}