File: token_generator_test.rb

package info (click to toggle)
ruby-model-tokenizer 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 180 kB
  • sloc: ruby: 245; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require "helper"

class Car < ActiveRecord::Base
  extend ModelTokenizer
  has_token
end

class Truck < ActiveRecord::Base
  extend ModelTokenizer
  has_token :length => 16
end

class TokenGenerator < Minitest::Test
  include ModelTokenizer::Test

  def setup
    Car.all.each(&:destroy)
    Truck.all.each(&:destroy)
  end

  def test_that_tokens_are_created_for_models
    with_instance_of(Car) do |record|
      assert record.token, "Token is nil"
      assert record.token.length == Car::model_tokenizer_token_length,
      "Token length is not #{Car::model_tokenizer_token_length}"
      
      record.token.split("").each do |c|
        assert ModelTokenizer::Base::CHARSET.include?(c), "#{c} doesn't belong in the acceptable character set"
      end
    end

    with_instance_of(Truck) do |record|
      assert record.token, "Token is nil"
      assert record.token.length == Truck::model_tokenizer_token_length,
      "Token length is not #{Truck::model_tokenizer_token_length}"
      
      record.token.split("").each do |c|
        assert ModelTokenizer::Base::CHARSET.include?(c), "#{c} doesn't belong in the acceptable character set"
      end
    end
  end
end