vidibus-uuid 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gem.email = "andre@vidibus.com"
14
14
  gem.homepage = "http://github.com/vidibus/vidibus-uuid"
15
15
  gem.authors = ["Andre Pankratz"]
16
- gem.add_dependency "mongoid", "~> 2.0.0.beta.17"
16
+ gem.add_dependency "mongoid", "~> 2.0.0.beta.20"
17
17
  gem.add_dependency "uuid", "~> 2.3.1"
18
18
  end
19
19
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
@@ -2,21 +2,21 @@ module Vidibus
2
2
  module Uuid
3
3
  module Mongoid
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  included do
7
7
  field :uuid
8
8
  index :uuid, :unique => true
9
9
  before_validation :generate_uuid
10
10
  validates :uuid, :uniqueness => true, :uuid => true
11
11
  end
12
-
12
+
13
13
  # Returns UUID as param for URLs.
14
14
  def to_param
15
15
  uuid
16
16
  end
17
-
17
+
18
18
  private
19
-
19
+
20
20
  # Sets unique UUID unless uuid is present.
21
21
  def generate_uuid
22
22
  self.uuid ||= Vidibus::Uuid.generate
data/lib/vidibus/uuid.rb CHANGED
@@ -2,12 +2,12 @@ require "uuid"
2
2
 
3
3
  module Vidibus
4
4
  module Uuid
5
-
5
+
6
6
  # Returns a new compact UUID.
7
7
  def self.generate
8
8
  UUID.new.generate(:compact)
9
9
  end
10
-
10
+
11
11
  # Returns true if given UUID is valid.
12
12
  def self.validate(uuid)
13
13
  uuid = uuid.to_s
@@ -1,7 +1,7 @@
1
1
  module Vidibus
2
2
  module ValidateUuid
3
3
  class UuidValidator < ActiveModel::EachValidator
4
-
4
+
5
5
  # Ensures that every value is of a valid compact UUID format.
6
6
  def validate_each(record, attribute, value)
7
7
  unless Vidibus::Uuid.validate(value)
@@ -16,42 +16,42 @@ describe "Vidibus::Uuid::Mongoid" do
16
16
  let(:model) { Model.create }
17
17
  let(:new_model) { Model.new }
18
18
  let(:uuid) { Vidibus::Uuid.generate }
19
-
19
+
20
20
  it "should add an uuid field to model" do
21
21
  model.should respond_to(:uuid)
22
22
  end
23
-
23
+
24
24
  it "should generate a valid UUID before creation" do
25
25
  model.uuid.length.should eql(32)
26
26
  end
27
-
27
+
28
28
  it "should keep the UUID persistent" do
29
29
  uuid = model.uuid
30
30
  model.save!
31
31
  model.uuid.should eql(uuid)
32
32
  end
33
-
33
+
34
34
  it "should allow assignment of UUID" do
35
35
  new_model.uuid = uuid
36
36
  new_model.save
37
37
  new_model.uuid.should eql(uuid)
38
38
  end
39
-
39
+
40
40
  it "should allow changes to UUID" do
41
41
  model.update_attributes(:uuid => uuid)
42
42
  model.uuid.should eql(uuid)
43
43
  end
44
-
44
+
45
45
  it "should verify format of UUID" do
46
46
  model.update_attributes(:uuid => "as")
47
47
  model.errors[:uuid].length.should eql(1)
48
48
  end
49
-
49
+
50
50
  it "should verify uniqueness of UUID in class" do
51
51
  another_model = Model.create(:uuid => model.uuid)
52
52
  another_model.errors[:uuid].should have(1).error
53
53
  end
54
-
54
+
55
55
  it "should verify uniqueness of UUID in embedded documents" do
56
56
  first_child = model.children.create!
57
57
  second_child = model.children.create!
@@ -60,7 +60,7 @@ describe "Vidibus::Uuid::Mongoid" do
60
60
  model.reload
61
61
  model.children[0].uuid.should_not eql(model.children[1].uuid)
62
62
  end
63
-
63
+
64
64
  it "should set UUID as default param" do
65
65
  model.should respond_to(:to_param)
66
66
  model.to_param.should eql(model.uuid)
@@ -2,46 +2,46 @@ require "spec_helper"
2
2
 
3
3
  describe "Vidibus::Uuid" do
4
4
  describe ".generate" do
5
-
5
+
6
6
  end
7
7
  it "should return a compact UUID" do
8
8
  uuid = Vidibus::Uuid.generate
9
9
  uuid.length.should eql(32)
10
10
  end
11
-
11
+
12
12
  describe ".validate" do
13
13
  it "should validate a valid compact UUID" do
14
14
  Vidibus::Uuid.validate("ddeb4500668e012d47bb58b035f038ab").should be_true
15
15
  end
16
-
16
+
17
17
  it "should validate a valid compact UUID that is given as symbol" do
18
18
  Vidibus::Uuid.validate(:ddeb4500668e012d47bb58b035f038ab).should be_true
19
19
  end
20
-
20
+
21
21
  it "should not validate an UUID that is not compact" do
22
22
  Vidibus::Uuid.validate("87a96db0-9a91-012d-59e4-58b035f038ab").should be_false
23
23
  end
24
-
24
+
25
25
  it "should not validate a string that looks like an UUID, but is too short" do
26
26
  Vidibus::Uuid.validate("dbeb4500668e0f839aefg928930efcca").should be_false
27
27
  end
28
-
28
+
29
29
  it "should not validate a random symbol" do
30
30
  Vidibus::Uuid.validate(:something).should be_false
31
31
  end
32
-
32
+
33
33
  it "should not validate a random string with 32 characters" do
34
34
  Vidibus::Uuid.validate("somerandomstringwith32characters").should be_false
35
35
  end
36
-
36
+
37
37
  it "should not validate a string containing non-hex characters" do
38
38
  Vidibus::Uuid.validate("xdeb4500668e012d47bb58b035f038ab").should be_false
39
39
  end
40
-
40
+
41
41
  it "should not validate nil" do
42
42
  Vidibus::Uuid.validate(nil).should be_false
43
43
  end
44
-
44
+
45
45
  it "should not validate an empty string" do
46
46
  Vidibus::Uuid.validate("").should be_false
47
47
  end
@@ -9,33 +9,33 @@ end
9
9
 
10
10
  describe "Vidibus::ValidateUuid::UuidValidator" do
11
11
  let(:model) { ModelWithValidations.new }
12
-
12
+
13
13
  it "should be available as uuid validator for attribute required_uuid" do
14
14
  ModelWithValidations.validators_on(:required_uuid).first.should be_a_kind_of(Vidibus::ValidateUuid::UuidValidator)
15
15
  end
16
-
16
+
17
17
  it "should be available as uuid validator for attribute optional_uuid" do
18
18
  ModelWithValidations.validators_on(:optional_uuid).first.should be_a_kind_of(Vidibus::ValidateUuid::UuidValidator)
19
19
  end
20
-
20
+
21
21
  it "should validate valid UUIDs" do
22
22
  model.required_uuid = "ddeb4500668e012d47bb58b035f038ab"
23
23
  model.should be_valid
24
24
  end
25
-
25
+
26
26
  it "should add an error for invalid UUIDs" do
27
27
  model.required_uuid = "ddeb4500668e0"
28
28
  model.should be_invalid
29
29
  model.errors[:required_uuid].should have(1).error
30
30
  model.errors[:required_uuid].first.should eql("is not a valid UUID")
31
31
  end
32
-
32
+
33
33
  it "should add an error on required_uuid, if empty" do
34
34
  model.required_uuid = ''
35
35
  model.should be_invalid
36
36
  model.errors[:required_uuid].should have(1).error
37
37
  end
38
-
38
+
39
39
  it "should allow emtpy optional_uuid" do
40
40
  model.required_uuid = "ddeb4500668e012d47bb58b035f038ab"
41
41
  model.optional_uuid = ""
data/vidibus-uuid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vidibus-uuid}
8
- s.version = "0.3.7"
8
+ s.version = "0.3.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andre Pankratz"]
12
- s.date = %q{2010-09-08}
12
+ s.date = %q{2010-09-23}
13
13
  s.description = %q{Provides UUID generation for Mongoid models. It includes a validator for UUIDs.}
14
14
  s.email = %q{andre@vidibus.com}
15
15
  s.extra_rdoc_files = [
@@ -54,14 +54,14 @@ Gem::Specification.new do |s|
54
54
  s.specification_version = 3
55
55
 
56
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
57
+ s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.20"])
58
58
  s.add_runtime_dependency(%q<uuid>, ["~> 2.3.1"])
59
59
  else
60
- s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
60
+ s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.20"])
61
61
  s.add_dependency(%q<uuid>, ["~> 2.3.1"])
62
62
  end
63
63
  else
64
- s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
64
+ s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.20"])
65
65
  s.add_dependency(%q<uuid>, ["~> 2.3.1"])
66
66
  end
67
67
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-uuid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-08 00:00:00 +02:00
18
+ date: 2010-09-23 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,14 +26,14 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 62196417
29
+ hash: 62196427
30
30
  segments:
31
31
  - 2
32
32
  - 0
33
33
  - 0
34
34
  - beta
35
- - 17
36
- version: 2.0.0.beta.17
35
+ - 20
36
+ version: 2.0.0.beta.20
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency