<commit_before>require 'test_helper'

class ProtokollTest < ActiveSupport::TestCase

  def setup
    time = Time.local(2011, 9, 25, 12, 0, 0)
    Timecop.travel(time)
  end

  def teardown
    reset_models
  end

  def reset_models
    ProtokollTest.send(:remove_const, 'Protocol') if defined? Protocol
    ProtokollTest.send(:remove_const, 'Call')     if defined? Call
  end

  ##
  # Tests
  ##

  test "using new number_symbol with default pattern should get 20110900001" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%Y%m$$$$$", :number_symbol => "$"
    end

    protocol = Protocol.create
    assert_equal "20110900001", protocol.number
  end

  test "should get 20110900001 (format number %Y%m#####)" do
    class Protocol < ActiveRecord::Base
      protokoll :number
    end

    protocol = Protocol.create
    assert_equal "20110900001", protocol.number
  end

  test "should get 20110900002 for second save (format number %Y%m#####)" do
    class Protocol < ActiveRecord::Base
      protokoll :number
    end

    protocol1 = Protocol.create
    protocol2 = Protocol.create

    assert_equal "20110900002", protocol2.number
  end

  test "should get 201100002 for second save (format number %Y#####)" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%Y#####"
    end

    protocol = Protocol.create

    assert_equal "201100001", protocol.number
  end

  test "second protocol on DB should have number should equals 1" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "#"
    end

    protocol = Protocol.create
    assert_equal "1", protocol.number
  end

  test "third protocol on DB should have number should equals 3" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "#"
    end

    Protocol.new.save
    Protocol.new.save
    protocol3 = Protocol.new
    protocol3.save

    assert_equal "3", protocol3.number
  end

  test "first using format A# should get A1" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A#"
    end

    protocol1 = Protocol.new
    protocol1.save

    assert_equal "A1", protocol1.number
  end

  test "first using format A## should get A01" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A##"
    end

    protocol1 = Protocol.create
    assert_equal "A01", protocol1.number
  end

  test "second using format A## should get A02" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A##"
    end

    protocol1 = Protocol.create
    protocol2 = Protocol.create
    assert_equal "A02", protocol2.number
  end

  test "third using format A## should get A03" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A##"
    end

    protocol1 = Protocol.create
    protocol2 = Protocol.create
    protocol3 = Protocol.create
    assert_equal "A03", protocol3.number
  end

  test "first use of %y# should get 111" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y#"
    end

    protocol1 = Protocol.create
    assert_equal "111", protocol1.number
  end


  test "first use of %y%m## should get 110901" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y%m##"
    end

    protocol1 = Protocol.create
    assert_equal "110901", protocol1.number
  end

  test "using %y%m## on next month after should get 111001" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y%m##"
    end

    time = Time.local(2011, 9, 25, 12, 0, 0)
    Timecop.travel(time)

    Protocol.create
    Protocol.create

    Timecop.travel(Time.now + 1.month)

    protocol = Protocol.create
    assert_equal "111001", protocol.number
  end

   test "%y%m%H#### should get 1109120001" do
     class Protocol < ActiveRecord::Base
       protokoll :number, :pattern => "%y%m%H####"
     end

     protocol1 = Protocol.create

     assert_equal "1109120001", protocol1.number
   end

   test "%y## on next year should get 1201" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y##"
    end

    time = Time.local(2011, 9, 25, 12, 3, 0) # 2011
    protocol1 = Protocol.create<commit_msg>removing unused variables<commit_after>require 'test_helper'

class ProtokollTest < ActiveSupport::TestCase

  def setup
    time = Time.local(2011, 9, 25, 12, 0, 0)
    Timecop.travel(time)
  end

  def teardown
    reset_models
  end

  def reset_models
    ProtokollTest.send(:remove_const, 'Protocol') if defined? Protocol
    ProtokollTest.send(:remove_const, 'Call')     if defined? Call
  end

  ##
  # Tests
  ##

  test "using new number_symbol with default pattern should get 20110900001" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%Y%m$$$$$", :number_symbol => "$"
    end

    protocol = Protocol.create
    assert_equal "20110900001", protocol.number
  end

  test "should get 20110900001 (format number %Y%m#####)" do
    class Protocol < ActiveRecord::Base
      protokoll :number
    end

    protocol = Protocol.create
    assert_equal "20110900001", protocol.number
  end

  test "should get 20110900002 for second save (format number %Y%m#####)" do
    class Protocol < ActiveRecord::Base
      protokoll :number
    end

    Protocol.create
    protocol2 = Protocol.create

    assert_equal "20110900002", protocol2.number
  end

  test "should get 201100002 for second save (format number %Y#####)" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%Y#####"
    end

    protocol = Protocol.create

    assert_equal "201100001", protocol.number
  end

  test "second protocol on DB should have number should equals 1" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "#"
    end

    protocol = Protocol.create
    assert_equal "1", protocol.number
  end

  test "third protocol on DB should have number should equals 3" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "#"
    end

    Protocol.new.save
    Protocol.new.save
    protocol3 = Protocol.new
    protocol3.save

    assert_equal "3", protocol3.number
  end

  test "first using format A# should get A1" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A#"
    end

    protocol1 = Protocol.new
    protocol1.save

    assert_equal "A1", protocol1.number
  end

  test "first using format A## should get A01" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A##"
    end

    protocol1 = Protocol.create
    assert_equal "A01", protocol1.number
  end

  test "second using format A## should get A02" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A##"
    end

    Protocol.create
    protocol2 = Protocol.create
    assert_equal "A02", protocol2.number
  end

  test "third using format A## should get A03" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "A##"
    end

    Protocol.create
    Protocol.create
    protocol3 = Protocol.create
    assert_equal "A03", protocol3.number
  end

  test "first use of %y# should get 111" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y#"
    end

    protocol1 = Protocol.create
    assert_equal "111", protocol1.number
  end


  test "first use of %y%m## should get 110901" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y%m##"
    end

    protocol1 = Protocol.create
    assert_equal "110901", protocol1.number
  end

  test "using %y%m## on next month after should get 111001" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y%m##"
    end

    time = Time.local(2011, 9, 25, 12, 0, 0)
    Timecop.travel(time)

    Protocol.create
    Protocol.create

    Timecop.travel(Time.now + 1.month)

    protocol = Protocol.create
    assert_equal "111001", protocol.number
  end

   test "%y%m%H#### should get 1109120001" do
     class Protocol < ActiveRecord::Base
       protokoll :number, :pattern => "%y%m%H####"
     end

     protocol1 = Protocol.create

     assert_equal "1109120001", protocol1.number
   end

   test "%y## on next year should get 1201" do
    class Protocol < ActiveRecord::Base
      protokoll :number, :pattern => "%y##"
    end

    time = Time.local(2011, 9, 25, 12, 3, 0) # 2011
    Protocol.create
{'fraction_non_alphanumeric': 0.1032736693358455, 'fraction_numerical': 0.050989166274140366, 'mean_word_length': 3.0346793349168646, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, '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': '1513994', 'n_tokens_mistral': 2919, 'n_tokens_neox': 2524, 'n_words': 820}