uuid_it 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +2 -0
- data/lib/uuid_it.rb +4 -5
- data/test/uuid_it_test.rb +16 -0
- data/test/uuid_it_test.rb~ +67 -0
- metadata +15 -8
data/Changelog.md
ADDED
data/lib/uuid_it.rb
CHANGED
@@ -24,11 +24,10 @@ module ActiveRecord
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def assign_uuid
|
27
|
-
return if
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
self.reload
|
27
|
+
return if self.uuid_object.present?
|
28
|
+
|
29
|
+
self.build_uuid_object(:uuid => UUID.create.to_s)
|
30
|
+
self.save unless self.new_record?
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
data/test/uuid_it_test.rb
CHANGED
@@ -47,4 +47,20 @@ class UuidItTest < ActiveSupport::TestCase
|
|
47
47
|
assert_equal car, Car.find_by_uuid(car.uuid)
|
48
48
|
assert_nil Car.find_by_uuid(scooter.uuid)
|
49
49
|
end
|
50
|
+
|
51
|
+
test "should only create one uuid object when a new object with a uuid is saved" do
|
52
|
+
assert_difference "Uuid.count", 1 do
|
53
|
+
c = Car.new
|
54
|
+
assert c.uuid
|
55
|
+
c.save!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "should not leak Uuid objects on unsaved uuidables" do
|
60
|
+
assert_difference "Uuid.count", 0 do
|
61
|
+
1..3.times do
|
62
|
+
Car.new.uuid
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
50
66
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Car < ActiveRecord::Base
|
4
|
+
uuid_it
|
5
|
+
end
|
6
|
+
|
7
|
+
class Bike < ActiveRecord::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
class Scooter < ActiveRecord::Base
|
11
|
+
uuid_it
|
12
|
+
end
|
13
|
+
|
14
|
+
class UuidItTest < ActiveSupport::TestCase
|
15
|
+
test "should assing Uuids to new objects" do
|
16
|
+
c = Car.create
|
17
|
+
assert c.uuid_object
|
18
|
+
assert c.uuid.present?
|
19
|
+
|
20
|
+
c2 = Car.create
|
21
|
+
assert_not_equal c.uuid, c2.uuid
|
22
|
+
end
|
23
|
+
|
24
|
+
test "should assing Uuid to already existing objects on first access" do
|
25
|
+
b1 = nil
|
26
|
+
assert_difference "Uuid.count", 0 do
|
27
|
+
b1 = Bike.create
|
28
|
+
end
|
29
|
+
Bike.class_eval do
|
30
|
+
uuid_it
|
31
|
+
end
|
32
|
+
assert_nil b1.uuid_object
|
33
|
+
b1.uuid
|
34
|
+
assert b1.uuid_object
|
35
|
+
assert b1.uuid.present?
|
36
|
+
|
37
|
+
b2 = Bike.create
|
38
|
+
assert b2.uuid_object
|
39
|
+
assert b2.uuid.present?
|
40
|
+
end
|
41
|
+
|
42
|
+
test "find_by_uuid" do
|
43
|
+
car = Car.create
|
44
|
+
scooter = Scooter.create
|
45
|
+
|
46
|
+
assert_nil Car.find_by_uuid("bla")
|
47
|
+
assert_equal car, Car.find_by_uuid(car.uuid)
|
48
|
+
assert_nil Car.find_by_uuid(scooter.uuid)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "should only create one uuid object when a new object with a uuid is saved" do
|
52
|
+
assert_difference "Uuid.count", 1 do
|
53
|
+
c = Car.new
|
54
|
+
assert c.uuid
|
55
|
+
c.uuid
|
56
|
+
c.save!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test "should not leak Uuid objects on unsaved uuidables" do
|
61
|
+
assert_difference "Uuid.count", 0 do
|
62
|
+
1..3.times do
|
63
|
+
Car.new.uuid
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuid_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- "Andr\xC3\xA9 Duffeck"
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-08-25 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -28,18 +29,20 @@ extensions: []
|
|
28
29
|
extra_rdoc_files: []
|
29
30
|
|
30
31
|
files:
|
31
|
-
- lib/uuid_it
|
32
|
+
- lib/uuid_it.rb
|
32
33
|
- lib/ruby-uuid/uuid.rb
|
33
34
|
- lib/generators/uuid_it_generator.rb
|
34
|
-
- lib/uuid_it.rb
|
35
|
+
- lib/uuid_it/uuid.rb
|
35
36
|
- lib/tasks/uuid_it_tasks.rake
|
37
|
+
- Changelog.md
|
36
38
|
- README.md
|
37
39
|
- Rakefile
|
38
40
|
- rails/init.rb
|
39
41
|
- generators/uuid_it/templates/create_uuids.rb
|
40
42
|
- generators/uuid_it/uuid_it_generator.rb
|
41
|
-
- test/
|
43
|
+
- test/uuid_it_test.rb~
|
42
44
|
- test/uuid_it_test.rb
|
45
|
+
- test/test_helper.rb
|
43
46
|
has_rdoc: true
|
44
47
|
homepage: http://github.com/aduffeck/uuid_it
|
45
48
|
licenses: []
|
@@ -50,23 +53,27 @@ rdoc_options: []
|
|
50
53
|
require_paths:
|
51
54
|
- lib
|
52
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
53
57
|
requirements:
|
54
58
|
- - ">="
|
55
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
56
61
|
segments:
|
57
62
|
- 0
|
58
63
|
version: "0"
|
59
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
60
66
|
requirements:
|
61
67
|
- - ">="
|
62
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
63
70
|
segments:
|
64
71
|
- 0
|
65
72
|
version: "0"
|
66
73
|
requirements: []
|
67
74
|
|
68
75
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.
|
76
|
+
rubygems_version: 1.5.2
|
70
77
|
signing_key:
|
71
78
|
specification_version: 3
|
72
79
|
summary: A Rails plugin for easily assigning UUIDs to your models..
|