Sha256: f160e57aa93f69276f650548d3acd1f3012f4e93cd6110cb1ae7bdcf16d535ed
Contents?: true
Size: 1.58 KB
Versions: 15
Compression:
Stored size: 1.58 KB
Contents
# -*- coding: utf-8 -*- require 'test_helper' class TokenUtilTest < ActiveSupport::TestCase def setup @mod = TokenUtil end test "create_token" do assert_match(/\A[0-9a-f]{10}\z/, @mod.create_token(10)) assert_match(/\A[0-9a-f]{20}\z/, @mod.create_token(20)) assert_match(/\A[0-9a-f]{30}\z/, @mod.create_token(30)) srand(0) assert_not_equal( @mod.create_token(20), @mod.create_token(20)) end test "create_unique_token" do assert_match(/\A[0-9a-f]{10}\z/, @mod.create_unique_token(MultiAuth.user_model_class, :user_token, 10)) assert_match(/\A[0-9a-f]{20}\z/, @mod.create_unique_token(MultiAuth.user_model_class, :user_token, 20)) assert_match(/\A[0-9a-f]{30}\z/, @mod.create_unique_token(MultiAuth.user_model_class, :user_token, 30)) srand(0) assert_not_equal( @mod.create_unique_token(MultiAuth.user_model_class, :user_token, 20), @mod.create_unique_token(MultiAuth.user_model_class, :user_token, 20)) end test "create_unique_token, conflict" do [ [MultiAuth.user_model_class, :user_token], ].each { |klass, column| exist_token = klass.first[column] unique_token = "0" * exist_token.size assert_equal(true, klass.exists?(column => exist_token)) assert_equal(false, klass.exists?(column => unique_token)) tokens = [exist_token, unique_token] musha = Kagemusha.new(@mod) musha.defs(:create_token) { tokens.shift } musha.swap { assert_equal( unique_token, @mod.create_unique_token(klass, column, exist_token.size)) } } end end
Version data entries
15 entries across 15 versions & 2 rubygems