active_record_uuid 0.0.1 → 0.1.0
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.
- data/.rvmrc +1 -1
- data/README.md +126 -22
- data/active_record_uuid.gemspec +4 -3
- data/lib/active_record_uuid.rb +10 -4
- data/lib/active_record_uuid/association_methods.rb +52 -0
- data/lib/active_record_uuid/config.rb +37 -0
- data/lib/active_record_uuid/extensions/quoting_extension.rb +31 -0
- data/lib/active_record_uuid/model.rb +66 -0
- data/lib/active_record_uuid/rails/db.rake +25 -0
- data/lib/active_record_uuid/rails/railtie.rb +19 -0
- data/lib/active_record_uuid/serializer.rb +50 -0
- data/lib/active_record_uuid/uuid_base.rb +12 -4
- data/lib/active_record_uuid/uuid_base_helper.rb +6 -83
- data/lib/active_record_uuid/version.rb +1 -1
- data/spec/lib/association_spec.rb +1 -1
- data/spec/lib/base64_uuid_spec.rb +57 -0
- data/spec/lib/binary_uuid_spec.rb +69 -0
- data/spec/lib/config_spec.rb +41 -0
- data/spec/lib/deprecation_spec.rb +17 -0
- data/spec/lib/hexdigest_uuid_spec.rb +57 -0
- data/spec/lib/serializer_spec.rb +11 -0
- data/spec/lib/string_uuid_spec.rb +57 -0
- data/spec/lib/uuid_config_spec.rb +100 -0
- data/spec/spec_helper.rb +24 -5
- data/spec/support/models.rb +60 -8
- data/spec/support/schema.rb +30 -0
- metadata +48 -12
- data/lib/active_record_uuid/railtie.rb +0 -7
- data/lib/active_record_uuid/tasks/db.rake +0 -26
- data/spec/lib/uuid_base_helper_spec.rb +0 -69
- data/spec/lib/uuid_base_spec.rb +0 -68
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "UuidBaseHelper" do
|
4
|
-
context "uuid as primary key" do
|
5
|
-
it "should have uuid as primary key for new models" do
|
6
|
-
class NewPostInclude < ActiveRecord::Base
|
7
|
-
include UuidBaseHelper
|
8
|
-
self.table_name = "posts"
|
9
|
-
end
|
10
|
-
NewPostInclude.primary_key.should eq('uuid')
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should have uuid as primary key for existing models" do
|
14
|
-
PostInclude.primary_key.should eq('uuid')
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should assign uuid automatically when create new record" do
|
18
|
-
post = PostInclude.create(:text => "Auto Generate uuid")
|
19
|
-
post.reload
|
20
|
-
|
21
|
-
post.uuid.should be_present
|
22
|
-
post.uuid.should be_instance_of(String)
|
23
|
-
post.uuid.length.should eq(36)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should assign uuid manually" do
|
27
|
-
post = PostInclude.new(:text => "Manual uuid")
|
28
|
-
post.uuid = "79f8a42e-ae60-11e1-9aa9-0026b90faf3c"
|
29
|
-
post.save
|
30
|
-
post.reload
|
31
|
-
|
32
|
-
post.uuid.should eq("79f8a42e-ae60-11e1-9aa9-0026b90faf3c")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should assign uuid if blank" do
|
36
|
-
post = PostInclude.new(:text => "Manual uuid 2")
|
37
|
-
post.assign_uuid
|
38
|
-
|
39
|
-
post.uuid.should be_present
|
40
|
-
post.uuid.should be_instance_of(String)
|
41
|
-
post.uuid.length.should eq(36)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should assign uuid if blank and save immediately" do
|
45
|
-
post = PostInclude.new(:text => "Manual uuid 3")
|
46
|
-
post.assign_uuid!
|
47
|
-
|
48
|
-
post.uuid.should be_present
|
49
|
-
post.uuid.should be_instance_of(String)
|
50
|
-
post.uuid.length.should eq(36)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should have valid uuid" do
|
54
|
-
post = PostInclude.new(:text => "Invalid uuid")
|
55
|
-
post.uuid = "invalid"
|
56
|
-
|
57
|
-
post.valid?.should eq(false)
|
58
|
-
post.errors[:uuid].first.should eq("is invalid")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should generate uuid" do
|
62
|
-
uuid = PostInclude.generate_uuid
|
63
|
-
|
64
|
-
uuid.should be_present
|
65
|
-
uuid.should be_instance_of(String)
|
66
|
-
uuid.length.should eq(36)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/spec/lib/uuid_base_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "UuidBase" do
|
4
|
-
context "uuid as primary key" do
|
5
|
-
it "should have uuid as primary key for new models" do
|
6
|
-
class NewPostInherit < ActiveRecord::UuidBase
|
7
|
-
self.table_name = "posts"
|
8
|
-
end
|
9
|
-
NewPostInherit.primary_key.should eq('uuid')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have uuid as primary key for existing models" do
|
13
|
-
PostInherit.primary_key.should eq('uuid')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should assign uuid automatically when create new record" do
|
17
|
-
post = PostInherit.create(:text => "Auto Generate uuid")
|
18
|
-
post.reload
|
19
|
-
|
20
|
-
post.uuid.should be_present
|
21
|
-
post.uuid.should be_instance_of(String)
|
22
|
-
post.uuid.length.should eq(36)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should assign uuid manually" do
|
26
|
-
post = PostInherit.new(:text => "Manual uuid")
|
27
|
-
post.uuid = "79f8a42e-ae60-11e1-9aa9-0026b90faf3c"
|
28
|
-
post.save
|
29
|
-
post.reload
|
30
|
-
|
31
|
-
post.uuid.should eq("79f8a42e-ae60-11e1-9aa9-0026b90faf3c")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should assign uuid if blank" do
|
35
|
-
post = PostInherit.new(:text => "Manual uuid 2")
|
36
|
-
post.assign_uuid
|
37
|
-
|
38
|
-
post.uuid.should be_present
|
39
|
-
post.uuid.should be_instance_of(String)
|
40
|
-
post.uuid.length.should eq(36)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should assign uuid if blank and save immediately" do
|
44
|
-
post = PostInherit.new(:text => "Manual uuid 3")
|
45
|
-
post.assign_uuid!
|
46
|
-
|
47
|
-
post.uuid.should be_present
|
48
|
-
post.uuid.should be_instance_of(String)
|
49
|
-
post.uuid.length.should eq(36)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should have valid uuid" do
|
53
|
-
post = PostInherit.new(:text => "Invalid uuid")
|
54
|
-
post.uuid = "invalid"
|
55
|
-
|
56
|
-
post.valid?.should eq(false)
|
57
|
-
post.errors[:uuid].first.should eq("is invalid")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should generate uuid" do
|
61
|
-
uuid = PostInherit.generate_uuid
|
62
|
-
|
63
|
-
uuid.should be_present
|
64
|
-
uuid.should be_instance_of(String)
|
65
|
-
uuid.length.should eq(36)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|