has_uuid 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1 +1,11 @@
1
+ ### Not released yet:
2
+
3
+ * (no changes)
4
+
5
+ ### 0.0.9 (2012-05-14)
6
+
7
+ * (exviva) Make sure uuid is assigned before validation
8
+
9
+ ### 0.0.8 (2012-04-27):
10
+
1
11
  * (troessner) Refactor the whole gem and use `class_attribute`.
data/README.markdown CHANGED
@@ -7,6 +7,8 @@ It depends on the [uuidtools](http://uuidtools.rubyforge.org/) gem.
7
7
 
8
8
  Initial credits go to [has_uuid](http://github.com/norbert/has_uuid).
9
9
 
10
+ Travis build status: ![Travis build status](http://travis-ci.org/troessner/has_uuid.png)
11
+
10
12
  Installation
11
13
  ------------
12
14
 
@@ -21,6 +23,7 @@ to your Gemfile and run
21
23
  Usage
22
24
  -----
23
25
 
26
+ ```Ruby
24
27
  class Post < ActiveRecord::Base
25
28
  # automatically assign a UUID to the "uuid" column on create
26
29
  has_uuid
@@ -50,4 +53,4 @@ end
50
53
 
51
54
  # Generate a UUID to use it later
52
55
  Post.generate_uuid
53
-
56
+ ```
@@ -1,3 +1,3 @@
1
1
  module HasUuid
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/has_uuid.rb CHANGED
@@ -20,6 +20,7 @@ module ActiveRecord
20
20
  include InstanceMethods
21
21
 
22
22
  if options[:auto]
23
+ before_validation(:on => :create) { assign_uuid }
23
24
  before_save(:on => :create) { assign_uuid }
24
25
  end
25
26
 
@@ -8,6 +8,11 @@ class Thingy < ActiveRecord::Base
8
8
  has_uuid :auto => false
9
9
  end
10
10
 
11
+ class ParanoidWidget < Widget
12
+ set_table_name 'widgets'
13
+ validates_presence_of :uuid
14
+ end
15
+
11
16
  class HasUuidTest < Test::Unit::TestCase
12
17
  def test_should_generate_a_valid_uuid
13
18
  uuid = Widget.generate_uuid
@@ -86,11 +91,18 @@ class HasUuidTest < Test::Unit::TestCase
86
91
  assert_nil @thingy.uuid
87
92
  end
88
93
 
89
- def should_assign_an_uuid_if_we_do_not_validate_the_overall_record
94
+ def test_should_assign_an_uuid_if_we_do_not_validate_the_overall_record
90
95
  @widget = Widget.new
91
96
  assert_nil @widget.uuid
92
97
  @widget.save :validate => false
93
98
  @widget.reload
94
99
  assert @widget.uuid_valid?
95
100
  end
101
+
102
+ def test_assign_uuid_before_validation
103
+ paranoid_widget = ParanoidWidget.new
104
+ assert !paranoid_widget.uuid_valid?
105
+ assert paranoid_widget.valid?
106
+ assert paranoid_widget.uuid_valid?
107
+ end
96
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000Z
12
+ date: 2012-05-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &77501590 !ruby/object:Gem::Requirement
16
+ requirement: &82127850 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *77501590
24
+ version_requirements: *82127850
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: uuidtools
27
- requirement: &77501200 !ruby/object:Gem::Requirement
27
+ requirement: &82127580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *77501200
35
+ version_requirements: *82127580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &77500880 !ruby/object:Gem::Requirement
38
+ requirement: &82127150 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *77500880
46
+ version_requirements: *82127150
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &77500450 !ruby/object:Gem::Requirement
49
+ requirement: &82126740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *77500450
57
+ version_requirements: *82126740
58
58
  description: The has_uuid gem adds a UUID to your AR models. See the README for details.
59
59
  email:
60
60
  - timo.roessner@googlemail.com