mongoa 0.1.13 → 0.1.14

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.13
1
+ 0.1.14
@@ -3,6 +3,7 @@ require 'mongoa/mongo_mapper/associations/all'
3
3
  require 'mongoa/mongo_mapper/validations/validate_base'
4
4
  require 'mongoa/mongo_mapper/validations/validate_presence_of'
5
5
  require 'mongoa/mongo_mapper/validations/validate_inclusion_of'
6
+ require 'mongoa/mongo_mapper/validations/validate_uniqueness_of'
6
7
  require 'mongoa/mongo_mapper/validations/validate_length_of'
7
8
 
8
9
  module Mongoa
@@ -28,6 +29,10 @@ module Mongoa
28
29
  ValidateInclusionOfMatcher.new(attr, within)
29
30
  end
30
31
 
32
+ def validate_uniqueness_of(attr)
33
+ # ValidateUniquenessOfMatcher.new(attr)
34
+ end
35
+
31
36
  def validate_length_of(attr, length_options)
32
37
  ValidateLengthOfMatcher.new(attr, length_options)
33
38
  end
@@ -0,0 +1,33 @@
1
+ module Mongoa
2
+ module MongoMapper
3
+ module Matchers
4
+ class ValidateUniquenessOfMatcher < ValidateBase
5
+ def initialize(attribute)
6
+ super(attribute)
7
+ end
8
+
9
+ def matches?(subject)
10
+ super(subject)
11
+ end
12
+
13
+ def description
14
+ "require #{@attribute} to be unique"
15
+ end
16
+
17
+ def failure_message
18
+ "Expected #{@attribute} to be unique but was not"
19
+ end
20
+
21
+ def negative_failure_message
22
+ "Expected #{@attribute} not to be unique but was"
23
+ end
24
+
25
+ private
26
+
27
+ def validation_type
28
+ "ValidatesUniquenessOf"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/mongoa.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoa}
8
- s.version = "0.1.13"
8
+ s.version = "0.1.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Scott J. Tamosunas"]
@@ -32,13 +32,15 @@ Gem::Specification.new do |s|
32
32
  "lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb",
33
33
  "lib/mongoa/mongo_mapper/validations/validate_length_of.rb",
34
34
  "lib/mongoa/mongo_mapper/validations/validate_presence_of.rb",
35
+ "lib/mongoa/mongo_mapper/validations/validate_uniqueness_of.rb",
35
36
  "mongoa.gemspec",
36
37
  "spec/assoications/all_spec.rb",
37
38
  "spec/matchers_spec.rb",
38
39
  "spec/spec_helper.rb",
39
40
  "spec/validations/validate_inclusion_of_spec.rb",
40
41
  "spec/validations/validate_length_of_spec.rb",
41
- "spec/validations/validate_presence_of_spec.rb"
42
+ "spec/validations/validate_presence_of_spec.rb",
43
+ "spec/validations/validate_uniqueness_of_spec.rb"
42
44
  ]
43
45
  s.homepage = %q{http://github.com/scotttam/mongoa}
44
46
  s.rdoc_options = ["--charset=UTF-8"]
@@ -51,7 +53,8 @@ Gem::Specification.new do |s|
51
53
  "spec/spec_helper.rb",
52
54
  "spec/validations/validate_inclusion_of_spec.rb",
53
55
  "spec/validations/validate_length_of_spec.rb",
54
- "spec/validations/validate_presence_of_spec.rb"
56
+ "spec/validations/validate_presence_of_spec.rb",
57
+ "spec/validations/validate_uniqueness_of_spec.rb"
55
58
  ]
56
59
 
57
60
  if s.respond_to? :specification_version then
@@ -20,9 +20,10 @@ describe Mongoa::MongoMapper::Matchers do
20
20
  end
21
21
 
22
22
  describe "validations" do
23
- it "should expose validate_presence_of, validate_inclusion_of and validate_length_of methods" do
23
+ it "should expose validate_presence_of, validate_inclusion_of, validates_uniqueness_of and validate_length_of methods" do
24
24
  @tester.methods.should include(:validate_presence_of)
25
25
  @tester.methods.should include(:validate_inclusion_of)
26
+ @tester.methods.should include(:validate_uniqueness_of)
26
27
  @tester.methods.should include(:validate_length_of)
27
28
  end
28
29
  end
data/spec/spec_helper.rb CHANGED
@@ -24,15 +24,18 @@ class Post
24
24
  include MongoMapper::Document
25
25
 
26
26
  key :name, String
27
+ key :unique_name, String
27
28
 
28
29
  validates_presence_of :name
29
30
  validates_length_of :name, :minimum => 4, :maximum => 32
31
+ validates_uniqueness_of :unique_name
30
32
  end
31
33
 
32
34
  class PostRequired
33
35
  include MongoMapper::Document
34
36
 
35
37
  key :name, String, :required => true, :length => 32
38
+ key :unique_name, String, :unique => true
36
39
  key :range_name, String, :required => true, :length => 0..56
37
40
  end
38
41
 
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mongoa::MongoMapper do
4
+ describe "validates_uniqueness_of or key required => :true" do
5
+ describe "#validates_uniqueness_of" do
6
+ it "should return true if the key has a validates_presence_of validtion" do
7
+ validation = Mongoa::MongoMapper::Matchers::ValidateUniquenessOfMatcher.new(:unique_name)
8
+ validation.should be_matches(Post.new)
9
+ end
10
+
11
+ it "should return false if the key does not have a validates_presence_of validtion" do
12
+ validation = Mongoa::MongoMapper::Matchers::ValidateUniquenessOfMatcher.new(:foo)
13
+ validation.should_not be_matches(Post.new)
14
+ end
15
+ end
16
+
17
+ describe "unique" do
18
+ it "should work the same if the key is unique rather than validates_presence_of" do
19
+ validation = Mongoa::MongoMapper::Matchers::ValidateUniquenessOfMatcher.new(:unique_name)
20
+ validation.should be_matches(PostRequired.new)
21
+
22
+ validation = Mongoa::MongoMapper::Matchers::ValidateUniquenessOfMatcher.new(:foo)
23
+ validation.should_not be_matches(PostRequired.new)
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 13
9
- version: 0.1.13
8
+ - 14
9
+ version: 0.1.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Scott J. Tamosunas
@@ -57,6 +57,7 @@ files:
57
57
  - lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb
58
58
  - lib/mongoa/mongo_mapper/validations/validate_length_of.rb
59
59
  - lib/mongoa/mongo_mapper/validations/validate_presence_of.rb
60
+ - lib/mongoa/mongo_mapper/validations/validate_uniqueness_of.rb
60
61
  - mongoa.gemspec
61
62
  - spec/assoications/all_spec.rb
62
63
  - spec/matchers_spec.rb
@@ -64,6 +65,7 @@ files:
64
65
  - spec/validations/validate_inclusion_of_spec.rb
65
66
  - spec/validations/validate_length_of_spec.rb
66
67
  - spec/validations/validate_presence_of_spec.rb
68
+ - spec/validations/validate_uniqueness_of_spec.rb
67
69
  has_rdoc: true
68
70
  homepage: http://github.com/scotttam/mongoa
69
71
  licenses: []
@@ -103,3 +105,4 @@ test_files:
103
105
  - spec/validations/validate_inclusion_of_spec.rb
104
106
  - spec/validations/validate_length_of_spec.rb
105
107
  - spec/validations/validate_presence_of_spec.rb
108
+ - spec/validations/validate_uniqueness_of_spec.rb