forked from rails/globalid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal_identification_test.rb
40 lines (33 loc) · 1.45 KB
/
global_identification_test.rb
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
require 'helper'
class GlobalIdentificationTest < ActiveSupport::TestCase
setup do
@model = PersonModel.new id: 1
end
test 'creates a Global ID from self' do
assert_equal GlobalID.create(@model), @model.to_global_id
assert_equal GlobalID.create(@model), @model.to_gid
end
test 'creates a Global ID with custom params' do
assert_equal GlobalID.create(@model, some: 'param'), @model.to_global_id(some: 'param')
assert_equal GlobalID.create(@model, some: 'param'), @model.to_gid(some: 'param')
end
test 'creates a signed Global ID from self' do
assert_equal SignedGlobalID.create(@model), @model.to_signed_global_id
assert_equal SignedGlobalID.create(@model), @model.to_sgid
end
test 'creates a signed Global ID with purpose ' do
assert_equal SignedGlobalID.create(@model, for: 'login'), @model.to_signed_global_id(for: 'login')
assert_equal SignedGlobalID.create(@model, for: 'login'), @model.to_sgid(for: 'login')
end
test 'creates a signed Global ID with custom params' do
assert_equal SignedGlobalID.create(@model, some: 'param'), @model.to_signed_global_id(some: 'param')
assert_equal SignedGlobalID.create(@model, some: 'param'), @model.to_sgid(some: 'param')
end
test 'dup should clear memoized to_global_id' do
global_id = @model.to_global_id
dup_model = @model.dup
dup_model.id = @model.id + 1
dup_global_id = dup_model.to_global_id
assert_not_equal global_id, dup_global_id
end
end