typed_uuid 4.0 → 4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +33 -12
- data/Gemfile +1 -1
- data/README.md +11 -5
- data/db/migrate/20191222234546_add_typed_uuid_function.rb +2 -2
- data/lib/typed_uuid/active_record.rb +1 -4
- data/lib/typed_uuid/psql_column_methods.rb +0 -1
- data/lib/typed_uuid/psql_schema_dumper.rb +2 -2
- data/lib/typed_uuid/railtie.rb +1 -1
- data/lib/typed_uuid/version.rb +1 -1
- data/lib/typed_uuid.rb +28 -2
- data/test/database_function_test.rb +116 -0
- data/test/test_helper.rb +11 -15
- data/test/typed_uuid_test.rb +46 -0
- data/typed_uuid.gemspec +3 -3
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f970db2e5a0edffaa90e664113f7cc9ecde9a1c217301cb53f132994e74a18d
|
4
|
+
data.tar.gz: 8762a572a7b9ade2cecdb282a90b6fe030ad547305207c7c616674dd4772ace3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 662ddc5ed10e7a43eff50ff0aadf4ada9d43490f2c5370045aa2e4f41a64ef5d58cb8cc33cb8452104106de51a30abf6d950766a8bf8d019fa329e4716bbd689
|
7
|
+
data.tar.gz: 6ba7853a8853d37479d5eba8e11ca48d3b64e0c98ff7b1dd05ad9c1c635d2c3d34be06da4219ff76ca68d232d93ed88b4b01428b3e570342096d27961024307d
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,28 +1,49 @@
|
|
1
1
|
name: CI
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
4
|
push:
|
5
|
-
branches: [ master ]
|
6
5
|
pull_request:
|
7
|
-
|
6
|
+
types: [opened]
|
8
7
|
|
9
8
|
jobs:
|
10
9
|
test:
|
11
10
|
name: TypedUUID Test
|
12
|
-
runs-on: ubuntu-
|
11
|
+
runs-on: ubuntu-22.04
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
rails-version:
|
15
|
+
- 7.0.8
|
16
|
+
- 7.1.2
|
17
|
+
ruby-version:
|
18
|
+
- 3.0
|
19
|
+
- 3.1
|
20
|
+
- 3.2
|
21
|
+
postgres-version:
|
22
|
+
- 15
|
13
23
|
|
14
24
|
steps:
|
15
|
-
-
|
16
|
-
|
17
|
-
|
25
|
+
- name: Install Postgresql
|
26
|
+
run: |
|
27
|
+
sudo apt-get -y --purge remove $(sudo apt list --installed | grep postgresql | awk '{print $1}')
|
28
|
+
sudo apt-get install curl ca-certificates gnupg
|
29
|
+
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
30
|
+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
31
|
+
sudo apt-get update
|
32
|
+
sudo apt-get -y install postgresql-${{ matrix.postgres-version }}-postgis-3
|
33
|
+
sudo systemctl start postgresql@${{ matrix.postgres-version }}-main.service
|
34
|
+
sudo systemctl status postgresql@${{ matrix.postgres-version }}-main.service
|
35
|
+
sudo pg_lsclusters
|
36
|
+
sudo -u postgres createuser runner --superuser
|
37
|
+
sudo -u postgres psql -c "ALTER USER runner WITH PASSWORD 'runner';"
|
18
38
|
|
19
|
-
- uses: actions/checkout@
|
39
|
+
- uses: actions/checkout@v4
|
20
40
|
|
21
41
|
- run: |
|
22
|
-
|
23
|
-
sudo -u postgres createuser runner --superuser
|
24
|
-
sudo -u postgres createdb uuid-types-test
|
42
|
+
echo 'gem "rails", "${{ matrix.rails-version }}"' >> Gemfile
|
25
43
|
|
26
|
-
-
|
44
|
+
- uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
ruby-version: ${{ matrix.ruby-version }}
|
47
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
27
48
|
|
28
49
|
- run: bundle exec rake test
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -31,9 +31,9 @@ Typed UUID will give us back the ENUM and Version of the Type using soley the UU
|
|
31
31
|
As with regular UUID Typed UUIDs come in multiple version. The current versions are:
|
32
32
|
|
33
33
|
- Version 1: A timebased UUID where the first 56 bits are an unsigned integer
|
34
|
-
representing the microseconds since epoch. Followed by
|
35
|
-
bits or a sequence counter.
|
36
|
-
|
34
|
+
representing the microseconds since epoch. Followed by 56 random
|
35
|
+
bits or a sequence counter. Followed by 16 bits which are the UUID
|
36
|
+
type.
|
37
37
|
|
38
38
|
- Version 3: A name-based UUID where the first 112 bits are based off the MD5
|
39
39
|
digest of the namespace and name. The following 16 bits are the
|
@@ -70,7 +70,7 @@ ActiveRecord::Base.register_uuid_types({
|
|
70
70
|
ActiveRecord::Base.register_uuid_types({
|
71
71
|
0 => :Listing,
|
72
72
|
512 => :Building,
|
73
|
-
8_191
|
73
|
+
8_191 => 'Building::SkyScrpaer'
|
74
74
|
})
|
75
75
|
```
|
76
76
|
|
@@ -83,7 +83,7 @@ a table.
|
|
83
83
|
```ruby
|
84
84
|
class CreateProperties < ActiveRecord::Migration[5.2]
|
85
85
|
def change
|
86
|
-
|
86
|
+
create_table :properties, id: :typed_uuid do |t|
|
87
87
|
t.string "name", limit: 255
|
88
88
|
end
|
89
89
|
end
|
@@ -116,6 +116,12 @@ class UpdateProperties < ActiveRecord::Migration[6.1]
|
|
116
116
|
end
|
117
117
|
```
|
118
118
|
|
119
|
+
When you need to lookup they class of a TypedUUID:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
ActiveRecord::Base.class_from_uuid(my_uuid) #=> MyClass
|
123
|
+
```
|
124
|
+
|
119
125
|
## STI Models
|
120
126
|
When using STI Model Rails will generate the UUID to be inserted. This UUID will
|
121
127
|
be calculated of the STI Model class and not the base class.
|
@@ -12,8 +12,8 @@ class AddTypedUuidFunction < ActiveRecord::Migration[6.0]
|
|
12
12
|
BEGIN
|
13
13
|
IF version = 1 THEN
|
14
14
|
bytes := decode(concat(
|
15
|
-
lpad(right(to_hex((extract(epoch from clock_timestamp())*1000000)::bigint),
|
16
|
-
encode(gen_random_bytes(
|
15
|
+
lpad(right(to_hex((extract(epoch from clock_timestamp())*1000000)::bigint), 14), 14, '0'),
|
16
|
+
encode(gen_random_bytes(9), 'hex')
|
17
17
|
), 'hex');
|
18
18
|
ELSE
|
19
19
|
bytes := gen_random_bytes(16);
|
@@ -117,10 +117,7 @@ module TypedUUID::ActiveRecord
|
|
117
117
|
Rails.application.eager_load! if !Rails.application.config.eager_load
|
118
118
|
|
119
119
|
::ActiveRecord::Base.descendants.find do |klass|
|
120
|
-
|
121
|
-
next if klass.table_name.nil?
|
122
|
-
|
123
|
-
klass.table_name == table
|
120
|
+
(klass.table_name || klass.send(:compute_table_name)) == table
|
124
121
|
end
|
125
122
|
end
|
126
123
|
|
@@ -4,7 +4,6 @@ module TypedUUID::PsqlColumnMethods
|
|
4
4
|
if type == :typed_uuid
|
5
5
|
klass_type_enum = ::ActiveRecord::Base.uuid_enum_from_table_name(self.name)
|
6
6
|
klass_type_version = ::ActiveRecord::Base.uuid_version_from_table_name(self.name)
|
7
|
-
options[:id] = :uuid
|
8
7
|
options[:default] ||= -> { "typed_uuid(#{klass_type_enum}, #{klass_type_version})" }
|
9
8
|
super(name, :uuid, **options)
|
10
9
|
else
|
@@ -14,8 +14,8 @@ module TypedUUID::PsqlSchemaDumper
|
|
14
14
|
BEGIN
|
15
15
|
IF version = 1 THEN
|
16
16
|
bytes := decode(concat(
|
17
|
-
lpad(right(to_hex((extract(epoch from clock_timestamp())*1000000)::bigint),
|
18
|
-
encode(gen_random_bytes(
|
17
|
+
lpad(right(to_hex((extract(epoch from clock_timestamp())*1000000)::bigint), 14), 14, '0'),
|
18
|
+
encode(gen_random_bytes(9), 'hex')
|
19
19
|
), 'hex');
|
20
20
|
ELSE
|
21
21
|
bytes := gen_random_bytes(16);
|
data/lib/typed_uuid/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class TypedUUID::Railtie < Rails::Railtie
|
2
2
|
|
3
3
|
initializer :typed_uuid do |app|
|
4
|
-
ActiveRecord::Tasks::DatabaseTasks.migrations_paths <<
|
4
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths << TypedUUID::MIGRATIONS_PATH
|
5
5
|
|
6
6
|
ActiveSupport.on_load(:active_record) do
|
7
7
|
ActiveRecord::Base.include TypedUUID::ActiveRecord
|
data/lib/typed_uuid/version.rb
CHANGED
data/lib/typed_uuid.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'digest/sha1'
|
2
2
|
|
3
3
|
module TypedUUID
|
4
|
+
MIGRATIONS_PATH = File.expand_path('../../db/migrate', __FILE__)
|
5
|
+
|
4
6
|
autoload :ActiveRecord, 'typed_uuid/active_record'
|
5
7
|
autoload :PsqlColumnMethods, 'typed_uuid/psql_column_methods'
|
6
8
|
autoload :PsqlSchemaDumper, 'typed_uuid/psql_schema_dumper'
|
@@ -35,10 +37,25 @@ module TypedUUID
|
|
35
37
|
timestamp ||= Time.now
|
36
38
|
|
37
39
|
uuid = [timestamp.to_i * 1_000_000 + timestamp.usec].pack('Q>')[1..-1]
|
38
|
-
uuid <<
|
40
|
+
uuid << if sequence.nil?
|
41
|
+
SecureRandom.random_bytes(8)
|
42
|
+
elsif sequence.is_a?(Integer)
|
43
|
+
sequence = [sequence].pack("Q>")
|
44
|
+
if sequence.bytesize == 8 && sequence[0] == "\x00"
|
45
|
+
sequence[1..]
|
46
|
+
else
|
47
|
+
raise ArgumentError, 'Sequence must be less than 8 bytes'
|
48
|
+
end
|
49
|
+
elsif sequence.is_a?(String)
|
50
|
+
raise ArgumentError, 'Sequence must be less than 8 bytes' if sequence.bytesize > 7
|
51
|
+
sequence.b
|
52
|
+
else
|
53
|
+
raise ArgumentError, 'Unable to convert sequence to binary'
|
54
|
+
end
|
55
|
+
uuid << "\x00\x00"
|
39
56
|
|
40
57
|
uuid = uuid.unpack("nnnnnnnn")
|
41
|
-
uuid[7] = (uuid[2] ^ uuid[6]) ^ ((enum << 3) | 1)
|
58
|
+
uuid[7] = ((uuid[2] ^ uuid[6]) ^ ((enum << 3) | 1))
|
42
59
|
"%04x%04x-%04x-%04x-%04x-%04x%04x%04x" % uuid
|
43
60
|
end
|
44
61
|
|
@@ -63,6 +80,15 @@ module TypedUUID
|
|
63
80
|
Time.at(*uuid[0..13].to_i(16).divmod(1_000_000), :usec)
|
64
81
|
end
|
65
82
|
|
83
|
+
def sequence_b(uuid)
|
84
|
+
uuid = uuid.gsub('-', '')
|
85
|
+
uuid[14..30].scan(/.{4}/).map{|i| i.to_i(16) }.pack('n*').b[0..-2]
|
86
|
+
end
|
87
|
+
|
88
|
+
def sequence(uuid)
|
89
|
+
("\x00" + sequence_b(uuid)).unpack1('Q>')
|
90
|
+
end
|
91
|
+
|
66
92
|
end
|
67
93
|
end
|
68
94
|
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DatabaseFunctionTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
schema do
|
6
|
+
ActiveRecord::Base.register_uuid_types({
|
7
|
+
'DatabaseFunctionTest::Ship' => {enum: 13, version: 1}
|
8
|
+
})
|
9
|
+
|
10
|
+
create_table :ships, id: :typed_uuid do |t|
|
11
|
+
t.string "name", limit: 255
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Ship < ActiveRecord::Base
|
16
|
+
end
|
17
|
+
|
18
|
+
class Sailor < ActiveRecord::Base
|
19
|
+
end
|
20
|
+
|
21
|
+
class Sea < ActiveRecord::Base
|
22
|
+
end
|
23
|
+
|
24
|
+
class ApplicationRecord < ActiveRecord::Base
|
25
|
+
primary_abstract_class
|
26
|
+
end
|
27
|
+
|
28
|
+
class Bird < ApplicationRecord
|
29
|
+
self.abstract_class = true
|
30
|
+
end
|
31
|
+
|
32
|
+
class Emu < Bird
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'adding primary key as a typed_uuid in a migration' do
|
36
|
+
ActiveRecord::Base.register_uuid_types({
|
37
|
+
1 => 'DatabaseFunctionTest::Sailor'
|
38
|
+
})
|
39
|
+
|
40
|
+
exprexted_sql = <<-SQL
|
41
|
+
CREATE TABLE "sailors" ("id" uuid DEFAULT typed_uuid(1, 4) NOT NULL PRIMARY KEY, "name" character varying(255))
|
42
|
+
SQL
|
43
|
+
|
44
|
+
assert_sql exprexted_sql do
|
45
|
+
ActiveRecord::Migration.suppress_messages do
|
46
|
+
ActiveRecord::Migration.create_table :sailors, id: :typed_uuid do |t|
|
47
|
+
t.string "name", limit: 255
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'adding primary key as a typed_uuid in a migration with a version' do
|
54
|
+
ActiveRecord::Base.register_uuid_types({
|
55
|
+
'DatabaseFunctionTest::Sea' => {version: 1, enum: 512}
|
56
|
+
})
|
57
|
+
|
58
|
+
exprexted_sql = <<-SQL
|
59
|
+
CREATE TABLE "seas" ("id" uuid DEFAULT typed_uuid(512, 1) NOT NULL PRIMARY KEY, "name" character varying(255))
|
60
|
+
SQL
|
61
|
+
|
62
|
+
assert_sql exprexted_sql do
|
63
|
+
ActiveRecord::Migration.suppress_messages do
|
64
|
+
ActiveRecord::Migration.create_table :seas, id: :typed_uuid do |t|
|
65
|
+
t.string "name", limit: 255
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'adding primary key as a typed_uuid in a migration to a STI table' do
|
72
|
+
ActiveRecord::Base.register_uuid_types({
|
73
|
+
30 => 'DatabaseFunctionTest::Bird',
|
74
|
+
31 => 'DatabaseFunctionTest::Emu'
|
75
|
+
})
|
76
|
+
|
77
|
+
exprexted_sql = <<-SQL
|
78
|
+
CREATE TABLE "birds" ("id" uuid DEFAULT typed_uuid(30, 4) NOT NULL PRIMARY KEY, "name" character varying(255))
|
79
|
+
SQL
|
80
|
+
|
81
|
+
assert_sql exprexted_sql do
|
82
|
+
ActiveRecord::Migration.suppress_messages do
|
83
|
+
ActiveRecord::Migration.create_table :birds, id: :typed_uuid do |t|
|
84
|
+
t.string "name", limit: 255
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'typed_uuid(enum)' do
|
91
|
+
uuid = ActiveRecord::Base.connection.execute('SELECT typed_uuid(13) AS uuid')[0]['uuid']
|
92
|
+
|
93
|
+
assert_equal 13, TypedUUID.enum(uuid)
|
94
|
+
assert_equal 4, TypedUUID.version(uuid)
|
95
|
+
assert_equal DatabaseFunctionTest::Ship, ::ActiveRecord::Base.class_from_uuid(uuid)
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'typed_uuid(enum, 4)' do
|
99
|
+
uuid = ActiveRecord::Base.connection.execute('SELECT typed_uuid(13, 4) AS uuid')[0]['uuid']
|
100
|
+
|
101
|
+
assert_equal 13, TypedUUID.enum(uuid)
|
102
|
+
assert_equal 4, TypedUUID.version(uuid)
|
103
|
+
assert_equal DatabaseFunctionTest::Ship, ::ActiveRecord::Base.class_from_uuid(uuid)
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'typed_uuid(enum, 1)' do
|
107
|
+
time = Time.now
|
108
|
+
uuid = ActiveRecord::Base.connection.execute('SELECT typed_uuid(13, 1) AS uuid')[0]['uuid']
|
109
|
+
|
110
|
+
assert_equal 13, TypedUUID.enum(uuid)
|
111
|
+
assert_equal 1, TypedUUID.version(uuid)
|
112
|
+
assert (time.ceil(0) - TypedUUID.timestamp(uuid).ceil(0)).abs <= 1
|
113
|
+
assert_equal DatabaseFunctionTest::Ship, ::ActiveRecord::Base.class_from_uuid(uuid)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -28,9 +28,7 @@ module ActiveRecord::Tasks::DatabaseTasks
|
|
28
28
|
end
|
29
29
|
TypedUUID::Railtie.initializers.each(&:run)
|
30
30
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
31
|
-
|
32
|
-
bt
|
33
|
-
end
|
31
|
+
|
34
32
|
class ActiveSupport::TestCase
|
35
33
|
|
36
34
|
# File 'lib/active_support/testing/declarative.rb'
|
@@ -67,7 +65,8 @@ class ActiveSupport::TestCase
|
|
67
65
|
ActiveRecord::Base.establish_connection(configuration)
|
68
66
|
|
69
67
|
db_tasks = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(ActiveRecord::Base.connection_db_config)
|
70
|
-
db_tasks.
|
68
|
+
db_tasks.drop
|
69
|
+
db_tasks.create
|
71
70
|
|
72
71
|
ActiveRecord::Migration.suppress_messages do
|
73
72
|
AddTypedUuidFunction.migrate :up
|
@@ -103,18 +102,15 @@ class ActiveSupport::TestCase
|
|
103
102
|
if patterns_to_match.all? { |s| s.is_a?(String) } && patterns_to_match.size > 1
|
104
103
|
assert_equal(*patterns_to_match.take(2).map { |sql| sql.gsub(/( +|\n\s*|\s+)/, ' ').strip })
|
105
104
|
else
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
failed_patterns = []
|
113
|
-
patterns_to_match.each do |pattern|
|
114
|
-
failed_patterns << pattern unless SQLLogger.log_all.any?{ |sql| pattern === sql.gsub(/( +|\n\s*|\s+)/, ' ').strip }
|
115
|
-
end
|
116
|
-
assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found.#{SQLLogger.log.size == 0 ? '' : "\nQueries:\n#{SQLLogger.log.join("\n")}"}"
|
105
|
+
ret_value = nil
|
106
|
+
capture_sql { ret_value = yield }
|
107
|
+
patterns_to_match.map! {|p| p.is_a?(String) ? p.gsub(/( +|\n\s*|\s+)/, ' ').strip : p }
|
108
|
+
failed_patterns = []
|
109
|
+
patterns_to_match.each do |pattern|
|
110
|
+
failed_patterns << pattern unless SQLLogger.log_all.any?{ |sql| pattern === sql.gsub(/( +|\n\s*|\s+)/, ' ').strip }
|
117
111
|
end
|
112
|
+
assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found.#{SQLLogger.log.size == 0 ? '' : "\nQueries:\n#{SQLLogger.log.join("\n")}"}"
|
113
|
+
ret_value
|
118
114
|
end
|
119
115
|
end
|
120
116
|
|
data/test/typed_uuid_test.rb
CHANGED
@@ -103,6 +103,52 @@ class UUIDTest < ActiveSupport::TestCase
|
|
103
103
|
assert_equal Listing, ::ActiveRecord::Base.class_from_uuid(Listing.typed_uuid)
|
104
104
|
end
|
105
105
|
|
106
|
+
test 'typed_uuid v1 with a timestamp' do
|
107
|
+
time = Time.at(1606612254, 370979, :usec)
|
108
|
+
uuid = TypedUUID.uuid(592, 1, timestamp: time)
|
109
|
+
|
110
|
+
assert_equal 1, TypedUUID.version(uuid)
|
111
|
+
assert_equal 592, TypedUUID.enum(uuid)
|
112
|
+
|
113
|
+
assert_equal time, TypedUUID.timestamp(uuid)
|
114
|
+
assert_equal time.to_i, TypedUUID.timestamp(uuid).to_i
|
115
|
+
assert_equal time.nsec, TypedUUID.timestamp(uuid).nsec
|
116
|
+
|
117
|
+
assert_equal Listing, ::ActiveRecord::Base.class_from_uuid(Listing.typed_uuid)
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'typed_uuid v1 with sequence as a string' do
|
121
|
+
uuid = TypedUUID.uuid(592, 1, sequence: '1234567')
|
122
|
+
|
123
|
+
assert_equal 1, TypedUUID.version(uuid)
|
124
|
+
assert_equal 592, TypedUUID.enum(uuid)
|
125
|
+
assert_equal '1234567', TypedUUID.sequence_b(uuid)
|
126
|
+
assert_equal 13847469359445559, TypedUUID.sequence(uuid)
|
127
|
+
|
128
|
+
|
129
|
+
assert_equal Listing, ::ActiveRecord::Base.class_from_uuid(Listing.typed_uuid)
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'typed_uuid v1 with sequence as a integer' do
|
133
|
+
uuid = TypedUUID.uuid(592, 1, sequence: 123456)
|
134
|
+
|
135
|
+
assert_equal 1, TypedUUID.version(uuid)
|
136
|
+
assert_equal 592, TypedUUID.enum(uuid)
|
137
|
+
assert_equal 123456, TypedUUID.sequence(uuid)
|
138
|
+
assert_equal "\x00\x00\x00\x00\x01\xE2@".b, TypedUUID.sequence_b(uuid)
|
139
|
+
|
140
|
+
assert_equal Listing, ::ActiveRecord::Base.class_from_uuid(Listing.typed_uuid)
|
141
|
+
|
142
|
+
[0, 1, 72057594037927935].each do |seq|
|
143
|
+
uuid = TypedUUID.uuid(592, 1, sequence: seq)
|
144
|
+
assert_equal seq, TypedUUID.sequence(uuid)
|
145
|
+
end
|
146
|
+
|
147
|
+
assert_raises ArgumentError do
|
148
|
+
TypedUUID.uuid(592, 1, sequence: 72057594037927936)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
106
152
|
test 'class_from uuid generated bye PostgresQL' do
|
107
153
|
listing = Listing.create
|
108
154
|
building = Building.create
|
data/typed_uuid.gemspec
CHANGED
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency 'simplecov'
|
23
23
|
s.add_development_dependency 'mocha'
|
24
24
|
s.add_development_dependency 'byebug'
|
25
|
-
s.add_development_dependency 'activesupport', '>=
|
26
|
-
s.add_development_dependency 'rails', '>=
|
25
|
+
s.add_development_dependency 'activesupport', '>= 7.0.0'
|
26
|
+
s.add_development_dependency 'rails', '>= 7.0.0'
|
27
27
|
s.add_development_dependency 'pg'
|
28
28
|
|
29
29
|
# Runtime
|
30
|
-
s.add_runtime_dependency 'activerecord', '>=
|
30
|
+
s.add_runtime_dependency 'activerecord', '>= 7.0.0'
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed_uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '4.
|
4
|
+
version: '4.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -114,28 +114,28 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 7.0.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 7.0.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: 7.0.0
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: 7.0.0
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: pg
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 7.0.0
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 7.0.0
|
167
167
|
description: Typed UUIDs 2 bytes are reserved in the UUID for the class enum
|
168
168
|
email:
|
169
169
|
- jonbracy@gmail.com
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/typed_uuid/psql_schema_dumper.rb
|
186
186
|
- lib/typed_uuid/railtie.rb
|
187
187
|
- lib/typed_uuid/version.rb
|
188
|
+
- test/database_function_test.rb
|
188
189
|
- test/test_helper.rb
|
189
190
|
- test/typed_uuid_test.rb
|
190
191
|
- typed_uuid.gemspec
|
@@ -206,10 +207,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
207
|
- !ruby/object:Gem::Version
|
207
208
|
version: '0'
|
208
209
|
requirements: []
|
209
|
-
rubygems_version: 3.
|
210
|
+
rubygems_version: 3.4.13
|
210
211
|
signing_key:
|
211
212
|
specification_version: 4
|
212
213
|
summary: Typed UUIDs for ActiveRecord
|
213
214
|
test_files:
|
215
|
+
- test/database_function_test.rb
|
214
216
|
- test/test_helper.rb
|
215
217
|
- test/typed_uuid_test.rb
|