uuid_it 0.1.4 → 0.1.5

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.
@@ -1,4 +1,8 @@
1
+ # 0.1.4 (2012-05-31)
2
+ * fixed the generator on Rails >= 3.1 (thanks swibs)
3
+
1
4
  # 0.1.3 (2012-05-06)
2
- * fixed a bug 'marshal data too short' issue #3 when using ruby > 1.8.7
5
+ * fixed a bug 'marshal data too short' issue #3 when using ruby > 1.8.7 (thanks t0d0r)
6
+
3
7
  # 0.1.2 (2011-08-25)
4
8
  * fixed a bug where uuid_it created multiple Uuids when an unsaved Uuidable already had created one
@@ -3,18 +3,21 @@ require File.join(File.dirname(__FILE__), "ruby-uuid", "uuid.rb")
3
3
 
4
4
  module ActiveRecord
5
5
  module Acts
6
-
6
+
7
7
  module UuidIt
8
8
  def uuid_it
9
9
  class_eval do
10
10
  send :include, InstanceMethods
11
+ send :extend, ClassMethods
11
12
  has_one :uuid_object, :as => :uuidable, :class_name => "Uuid", :dependent => :destroy
12
13
  after_create :assign_uuid
13
14
  end
14
15
  end
15
16
 
16
- def find_by_uuid uuid
17
- return Uuid.find_by_uuidable_type_and_uuid(self.name, uuid).try(:uuidable)
17
+ module ClassMethods
18
+ def find_by_uuid uuid
19
+ return Uuid.find_by_uuidable_type_and_uuid(self.name, uuid).try(:uuidable)
20
+ end
18
21
  end
19
22
 
20
23
  module InstanceMethods
@@ -1,3 +1,4 @@
1
1
  class Uuid < ::ActiveRecord::Base
2
2
  belongs_to :uuidable, :polymorphic => true
3
+ attr_accessible :uuid
3
4
  end
@@ -63,4 +63,9 @@ class UuidItTest < ActiveSupport::TestCase
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ test "find_by_uuid should only be available to classes with uuid_it" do
68
+ assert_nil Car.find_by_uuid("bla")
69
+ assert_raise(NoMethodError) { Bike.find_by_uuid("bla") }
70
+ end
66
71
  end
metadata CHANGED
@@ -1,33 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: uuid_it
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
11
6
  platform: ruby
12
- authors:
13
- - "Andr\xC3\xA9 Duffeck"
7
+ authors:
8
+ - André Duffeck
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-31 00:00:00 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
19
13
  dependencies: []
14
+ description: ! ' You need to assign UUIDs to your model? UuidIt makes it as simple
15
+ as adding one line of code to the according models.
20
16
 
21
- description: " You need to assign UUIDs to your model? UuidIt makes it as simple as adding one line of code to the according models.\n"
22
- email:
17
+ '
18
+ email:
23
19
  - aduffeck@suse.de
24
20
  executables: []
25
-
26
21
  extensions: []
27
-
28
22
  extra_rdoc_files: []
29
-
30
- files:
23
+ files:
31
24
  - lib/uuid_it.rb
32
25
  - lib/ruby-uuid/uuid.rb
33
26
  - lib/generators/uuid_it_generator.rb
@@ -39,42 +32,32 @@ files:
39
32
  - rails/init.rb
40
33
  - generators/uuid_it/templates/create_uuids.rb
41
34
  - generators/uuid_it/uuid_it_generator.rb
42
- - test/uuid_it_test.rb~
43
35
  - test/uuid_it_test.rb
44
36
  - test/test_helper.rb
45
37
  homepage: http://github.com/aduffeck/uuid_it
46
38
  licenses: []
47
-
48
39
  post_install_message:
49
40
  rdoc_options: []
50
-
51
- require_paths:
41
+ require_paths:
52
42
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
43
+ required_ruby_version: !ruby/object:Gem::Requirement
54
44
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
50
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
71
55
  requirements: []
72
-
73
56
  rubyforge_project:
74
- rubygems_version: 1.8.15
57
+ rubygems_version: 1.8.23
75
58
  signing_key:
76
59
  specification_version: 3
77
60
  summary: A Rails plugin for easily assigning UUIDs to your models..
78
- test_files:
61
+ test_files:
79
62
  - test/uuid_it_test.rb
80
63
  has_rdoc: false
@@ -1,67 +0,0 @@
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