mongoa 0.1.12 → 0.1.13

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/Rakefile CHANGED
@@ -1,11 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- #
4
- # require 'rake/testtask'
5
- # require 'rake/rdoctask'
6
- #
7
- # require 'rspec'
8
- # require 'rspec/core'
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ require 'rspec'
9
6
 
10
7
  begin
11
8
  require 'jeweler'
@@ -24,28 +21,11 @@ rescue LoadError
24
21
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
22
  end
26
23
 
27
- # require 'spec/rake/spectask'
28
- # Spec::Rake::SpecTask.new(:spec) do |spec|
29
- # spec.libs << 'lib' << 'spec'
30
- # spec.spec_files = FileList['spec/**/*_spec.rb']
31
- # end
32
- #
33
- # Spec::Rake::SpecTask.new(:rcov) do |spec|
34
- # spec.libs << 'lib' << 'spec'
35
- # spec.pattern = 'spec/**/*_spec.rb'
36
- # spec.rcov = true
37
- # end
38
- #
39
- # task :spec => :check_dependencies
40
- #
41
- # task :default => :spec
42
- #
43
- # require 'rake/rdoctask'
44
- # Rake::RDocTask.new do |rdoc|
45
- # version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
- #
47
- # rdoc.rdoc_dir = 'rdoc'
48
- # rdoc.title = "mongoa #{version}"
49
- # rdoc.rdoc_files.include('README*')
50
- # rdoc.rdoc_files.include('lib/**/*.rb')
51
- # end
24
+
25
+ RSpec::Core::RakeTask.new(:spec) do |t|
26
+ t.pattern = FileList['spec/**/*_spec.rb']
27
+ t.rcov = false
28
+ end
29
+
30
+ task :spec => :check_dependencies
31
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -1,19 +1,5 @@
1
1
  module Mongoa
2
2
  module MongoMapper
3
- module Matchers
4
- def belong_to(name)
5
- MongoAssociationMatcher.new(:belongs_to, name)
6
- end
7
-
8
- def have_many(name)
9
- MongoAssociationMatcher.new(:has_many, name)
10
- end
11
-
12
- def has_one(name)
13
- MongoAssociationMatcher.new(:has_one, name)
14
- end
15
- end
16
-
17
3
  class MongoAssociationMatcher
18
4
  attr_reader :macro
19
5
  attr_reader :name
@@ -31,7 +17,7 @@ module Mongoa
31
17
  return false
32
18
  end
33
19
  @subject = subject
34
-
20
+
35
21
  result = (association_exists? && macro_correct?)
36
22
  result = foreign_key_exists? if result && macro == :belongs_to && !subject.class.embeddable?
37
23
  result
@@ -84,7 +70,7 @@ module Mongoa
84
70
  end
85
71
  true
86
72
  end
87
-
73
+
88
74
  def macro_correct?
89
75
  (association.type == :belongs_to && macro == :belongs_to) ||
90
76
  (association.type == :many && macro == :has_many) ||
@@ -104,4 +90,4 @@ module Mongoa
104
90
  end
105
91
  end
106
92
  end
107
- end
93
+ end
@@ -1,11 +1,36 @@
1
1
  require 'mongoa/mongo_mapper/improvements/mongo_mapper_associations'
2
- require 'mongoa/mongo_mapper/association_matcher'
3
- require 'mongoa/mongo_mapper/validations'
2
+ require 'mongoa/mongo_mapper/associations/all'
3
+ require 'mongoa/mongo_mapper/validations/validate_base'
4
+ require 'mongoa/mongo_mapper/validations/validate_presence_of'
5
+ require 'mongoa/mongo_mapper/validations/validate_inclusion_of'
6
+ require 'mongoa/mongo_mapper/validations/validate_length_of'
4
7
 
5
8
  module Mongoa
6
9
  module MongoMapper
7
10
  module Matchers
11
+ def belong_to(name)
12
+ MongoAssociationMatcher.new(:belongs_to, name)
13
+ end
14
+
15
+ def have_many(name)
16
+ MongoAssociationMatcher.new(:has_many, name)
17
+ end
18
+
19
+ def have_one(name)
20
+ MongoAssociationMatcher.new(:has_one, name)
21
+ end
22
+
23
+ def validate_presence_of(attr)
24
+ ValidatePresenceOfMatcher.new(attr)
25
+ end
26
+
27
+ def validate_inclusion_of(attr, within)
28
+ ValidateInclusionOfMatcher.new(attr, within)
29
+ end
30
+
31
+ def validate_length_of(attr, length_options)
32
+ ValidateLengthOfMatcher.new(attr, length_options)
33
+ end
8
34
  end
9
35
  end
10
- end
11
-
36
+ end
data/mongoa.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoa}
8
- s.version = "0.1.12"
8
+ s.version = "0.1.13"
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"]
12
- s.date = %q{2010-08-20}
12
+ s.date = %q{2010-08-24}
13
13
  s.description = %q{Adds the association and validation macros for Rspec in the same way Shoulda does for ActiveRecord.}
14
14
  s.email = %q{tamosunas@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,19 +25,20 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/mongoa.rb",
27
27
  "lib/mongoa/integrations/rspec2.rb",
28
- "lib/mongoa/mongo_mapper/association_matcher.rb",
28
+ "lib/mongoa/mongo_mapper/associations/all.rb",
29
29
  "lib/mongoa/mongo_mapper/improvements/mongo_mapper_associations.rb",
30
30
  "lib/mongoa/mongo_mapper/matchers.rb",
31
- "lib/mongoa/mongo_mapper/validations.rb",
32
31
  "lib/mongoa/mongo_mapper/validations/validate_base.rb",
33
32
  "lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb",
34
33
  "lib/mongoa/mongo_mapper/validations/validate_length_of.rb",
35
34
  "lib/mongoa/mongo_mapper/validations/validate_presence_of.rb",
36
35
  "mongoa.gemspec",
37
- "spec/association_matcher_spec.rb",
38
- "spec/spec.opts",
36
+ "spec/assoications/all_spec.rb",
37
+ "spec/matchers_spec.rb",
39
38
  "spec/spec_helper.rb",
40
- "spec/validation_matcher_spec.rb"
39
+ "spec/validations/validate_inclusion_of_spec.rb",
40
+ "spec/validations/validate_length_of_spec.rb",
41
+ "spec/validations/validate_presence_of_spec.rb"
41
42
  ]
42
43
  s.homepage = %q{http://github.com/scotttam/mongoa}
43
44
  s.rdoc_options = ["--charset=UTF-8"]
@@ -45,9 +46,12 @@ Gem::Specification.new do |s|
45
46
  s.rubygems_version = %q{1.3.7}
46
47
  s.summary = %q{Like Shoulda but for MongoMapper.}
47
48
  s.test_files = [
48
- "spec/association_matcher_spec.rb",
49
+ "spec/assoications/all_spec.rb",
50
+ "spec/matchers_spec.rb",
49
51
  "spec/spec_helper.rb",
50
- "spec/validation_matcher_spec.rb"
52
+ "spec/validations/validate_inclusion_of_spec.rb",
53
+ "spec/validations/validate_length_of_spec.rb",
54
+ "spec/validations/validate_presence_of_spec.rb"
51
55
  ]
52
56
 
53
57
  if s.respond_to? :specification_version then
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  class Post
4
4
  include MongoMapper::Document
@@ -60,7 +60,7 @@ class Office
60
60
  belongs_to :employee
61
61
  end
62
62
 
63
- describe Mongoa::MongoMapper::Matchers do
63
+ describe Mongoa::MongoMapper do
64
64
  describe "#belongs_to" do
65
65
  describe "document" do
66
66
  it "should return true of the belongs_to relationship is specified and the foreign key is present" do
@@ -99,7 +99,7 @@ describe Mongoa::MongoMapper::Matchers do
99
99
  end
100
100
  end
101
101
 
102
- describe "#has_one" do
102
+ describe "#have_one" do
103
103
  it "should return true if the has_one relationship is specified" do
104
104
  matcher = Mongoa::MongoMapper::MongoAssociationMatcher.new(:has_one, :office)
105
105
  matcher.should be_matches(Employee.new)
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Mongoa::MongoMapper::Matchers do
4
+ before(:all) do
5
+ class TesterClass
6
+ include Mongoa::MongoMapper::Matchers
7
+ end
8
+ end
9
+
10
+ before(:each) do
11
+ @tester = TesterClass.new
12
+ end
13
+
14
+ describe "associations" do
15
+ it "should expose a belong_to, have_many and have_one methods" do
16
+ @tester.methods.should include(:belong_to)
17
+ @tester.methods.should include(:have_many)
18
+ @tester.methods.should include(:have_one)
19
+ end
20
+ end
21
+
22
+ describe "validations" do
23
+ it "should expose validate_presence_of, validate_inclusion_of and validate_length_of methods" do
24
+ @tester.methods.should include(:validate_presence_of)
25
+ @tester.methods.should include(:validate_inclusion_of)
26
+ @tester.methods.should include(:validate_length_of)
27
+ end
28
+ end
29
+ end
data/spec/spec_helper.rb CHANGED
@@ -15,9 +15,37 @@ MongoMapper.connect("test")
15
15
  require 'rspec'
16
16
 
17
17
  Rspec.configure do |config|
18
-
19
18
  end
20
19
 
21
20
  require 'mongoa'
22
- require File.expand_path(File.dirname(__FILE__) + '/../lib/mongoa/mongo_mapper/association_matcher')
21
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/mongoa/mongo_mapper/matchers')
23
22
 
23
+ class Post
24
+ include MongoMapper::Document
25
+
26
+ key :name, String
27
+
28
+ validates_presence_of :name
29
+ validates_length_of :name, :minimum => 4, :maximum => 32
30
+ end
31
+
32
+ class PostRequired
33
+ include MongoMapper::Document
34
+
35
+ key :name, String, :required => true, :length => 32
36
+ key :range_name, String, :required => true, :length => 0..56
37
+ end
38
+
39
+ class Within
40
+ include MongoMapper::Document
41
+
42
+ key :state, String
43
+
44
+ validates_inclusion_of :state, :within => ["new", "uploaded"]
45
+ end
46
+
47
+ class WithinIn
48
+ include MongoMapper::Document
49
+
50
+ key :state, String, :in => ["new", "uploaded"]
51
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mongoa::MongoMapper do
4
+ describe "#validates_inclusion_of or key :in => []" do
5
+ describe "validates_inclusion_of" do
6
+ it "should return true if the key has a validate_inclusion_of with the specified within" do
7
+ validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["new", "uploaded"])
8
+ validation.should be_matches(Within.new)
9
+ end
10
+
11
+ it "should return false if the key has a validate_inclusion_of but the within doesn't match" do
12
+ validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["goo", "gaa"])
13
+ validation.should_not be_matches(Within.new)
14
+ end
15
+
16
+ it "should return false if the key does not have a validate_inclusion_of set" do
17
+ validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:foo, ["new", "uploaded"])
18
+ validation.should_not be_matches(Within.new)
19
+ end
20
+ end
21
+
22
+ describe "in" do
23
+ it "should work the same as validates_inclusion_of" do
24
+ validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["new", "uploaded"])
25
+ validation.should be_matches(WithinIn.new)
26
+
27
+ validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["goo", "gaa"])
28
+ validation.should_not be_matches(WithinIn.new)
29
+
30
+ validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:foo, ["new", "uploaded"])
31
+ validation.should_not be_matches(WithinIn.new)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mongoa::MongoMapper do
4
+ describe "#validates_length_of or key :length => <length_options>" do
5
+ describe "validates_length_of" do
6
+ describe "maximum" do
7
+ it "should return true if the key has a validates_length of with the specified :maximum" do
8
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :maximum => 32)
9
+ validation.should be_matches(Post.new)
10
+ end
11
+
12
+ it "should return false if the key has a validates_length but the maximum's don't match" do
13
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :maximum => 25)
14
+ validation.should_not be_matches(Post.new)
15
+ end
16
+
17
+ it "should return false if the key does not have a validates_length of" do
18
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:foo, :maximum => 32)
19
+ validation.should_not be_matches(Post.new)
20
+ end
21
+ end
22
+
23
+ describe "minimum" do
24
+ it "should return true if the key has a validates_length of with the specified :minimum" do
25
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :minimum => 4)
26
+ validation.should be_matches(Post.new)
27
+ end
28
+
29
+ it "should return false if the key has a validates_length of but the minimum's don't match" do
30
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :minimum => 2)
31
+ validation.should_not be_matches(Post.new)
32
+ end
33
+
34
+ it "should return false if the key does not have a validates_length" do
35
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:foo, :minimum => 32)
36
+ validation.should_not be_matches(Post.new)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "length" do
42
+ it "should work the same as validates_length_of" do
43
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :length => 32)
44
+ validation.should be_matches(PostRequired.new)
45
+
46
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :length => 25)
47
+ validation.should_not be_matches(PostRequired.new)
48
+
49
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:foo, :length => 32)
50
+ validation.should_not be_matches(PostRequired.new)
51
+
52
+ validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:range_name, :length => 0..56)
53
+ validation.should be_matches(PostRequired.new)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mongoa::MongoMapper do
4
+ describe "validates_presence_of or key required => :true" do
5
+ describe "#validates_presence_of" do
6
+ it "should return true if the key has a validates_presence_of validtion" do
7
+ validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.new(: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::ValidatePresenceOfMatcher.new(:foo)
13
+ validation.should_not be_matches(Post.new)
14
+ end
15
+ end
16
+
17
+ describe "required" do
18
+ it "should work the same if the key is required rather than validates_presence_of" do
19
+ validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.new(:name)
20
+ validation.should be_matches(PostRequired.new)
21
+
22
+ validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.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
- - 12
9
- version: 0.1.12
8
+ - 13
9
+ version: 0.1.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Scott J. Tamosunas
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-20 00:00:00 -04:00
17
+ date: 2010-08-24 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,19 +50,20 @@ files:
50
50
  - VERSION
51
51
  - lib/mongoa.rb
52
52
  - lib/mongoa/integrations/rspec2.rb
53
- - lib/mongoa/mongo_mapper/association_matcher.rb
53
+ - lib/mongoa/mongo_mapper/associations/all.rb
54
54
  - lib/mongoa/mongo_mapper/improvements/mongo_mapper_associations.rb
55
55
  - lib/mongoa/mongo_mapper/matchers.rb
56
- - lib/mongoa/mongo_mapper/validations.rb
57
56
  - lib/mongoa/mongo_mapper/validations/validate_base.rb
58
57
  - lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb
59
58
  - lib/mongoa/mongo_mapper/validations/validate_length_of.rb
60
59
  - lib/mongoa/mongo_mapper/validations/validate_presence_of.rb
61
60
  - mongoa.gemspec
62
- - spec/association_matcher_spec.rb
63
- - spec/spec.opts
61
+ - spec/assoications/all_spec.rb
62
+ - spec/matchers_spec.rb
64
63
  - spec/spec_helper.rb
65
- - spec/validation_matcher_spec.rb
64
+ - spec/validations/validate_inclusion_of_spec.rb
65
+ - spec/validations/validate_length_of_spec.rb
66
+ - spec/validations/validate_presence_of_spec.rb
66
67
  has_rdoc: true
67
68
  homepage: http://github.com/scotttam/mongoa
68
69
  licenses: []
@@ -96,6 +97,9 @@ signing_key:
96
97
  specification_version: 3
97
98
  summary: Like Shoulda but for MongoMapper.
98
99
  test_files:
99
- - spec/association_matcher_spec.rb
100
+ - spec/assoications/all_spec.rb
101
+ - spec/matchers_spec.rb
100
102
  - spec/spec_helper.rb
101
- - spec/validation_matcher_spec.rb
103
+ - spec/validations/validate_inclusion_of_spec.rb
104
+ - spec/validations/validate_length_of_spec.rb
105
+ - spec/validations/validate_presence_of_spec.rb
@@ -1,22 +0,0 @@
1
- require 'mongoa/mongo_mapper/validations/validate_base'
2
- require 'mongoa/mongo_mapper/validations/validate_presence_of'
3
- require 'mongoa/mongo_mapper/validations/validate_inclusion_of'
4
- require 'mongoa/mongo_mapper/validations/validate_length_of'
5
-
6
- module Mongoa
7
- module MongoMapper
8
- module Matchers
9
- def validate_presence_of(attr)
10
- ValidatePresenceOfMatcher.new(attr)
11
- end
12
-
13
- def validate_inclusion_of(attr, within)
14
- ValidateInclusionOfMatcher.new(attr, within)
15
- end
16
-
17
- def validate_length_of(attr, length_options)
18
- ValidateLengthOfMatcher.new(attr, length_options)
19
- end
20
- end
21
- end
22
- end
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,143 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- class Post
4
- include MongoMapper::Document
5
-
6
- key :name, String
7
-
8
- validates_presence_of :name
9
- validates_length_of :name, :minimum => 4, :maximum => 32
10
- end
11
-
12
- class PostRequired
13
- include MongoMapper::Document
14
-
15
- key :name, String, :required => true, :length => 32
16
- key :range_name, String, :required => true, :length => 0..56
17
- end
18
-
19
- class Within
20
- include MongoMapper::Document
21
-
22
- key :state, String
23
-
24
- validates_inclusion_of :state, :within => ["new", "uploaded"]
25
- end
26
-
27
- class WithinIn
28
- include MongoMapper::Document
29
-
30
- key :state, String, :in => ["new", "uploaded"]
31
- end
32
-
33
- describe Mongoa::MongoMapper::Matchers do
34
- describe "validates_presence_of or key required => :true" do
35
- describe "#validates_presence_of" do
36
- it "should return true if the key has a validates_presence_of validtion" do
37
- validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.new(:name)
38
- validation.should be_matches(Post.new)
39
- end
40
-
41
- it "should return false if the key does not have a validates_presence_of validtion" do
42
- validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.new(:foo)
43
- validation.should_not be_matches(Post.new)
44
- end
45
- end
46
-
47
- describe "required" do
48
- it "should work the same if the key is required rather than validates_presence_of" do
49
- validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.new(:name)
50
- validation.should be_matches(PostRequired.new)
51
-
52
- validation = Mongoa::MongoMapper::Matchers::ValidatePresenceOfMatcher.new(:foo)
53
- validation.should_not be_matches(PostRequired.new)
54
- end
55
- end
56
- end
57
-
58
- describe "#validates_inclusion_of or key :in => []" do
59
- describe "validates_inclusion_of" do
60
- it "should return true if the key has a validate_inclusion_of with the specified within" do
61
- validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["new", "uploaded"])
62
- validation.should be_matches(Within.new)
63
- end
64
-
65
- it "should return false if the key has a validate_inclusion_of but the within doesn't match" do
66
- validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["goo", "gaa"])
67
- validation.should_not be_matches(Within.new)
68
- end
69
-
70
- it "should return false if the key does not have a validate_inclusion_of set" do
71
- validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:foo, ["new", "uploaded"])
72
- validation.should_not be_matches(Within.new)
73
- end
74
- end
75
-
76
- describe "in" do
77
- it "should work the same as validates_inclusion_of" do
78
- validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["new", "uploaded"])
79
- validation.should be_matches(WithinIn.new)
80
-
81
- validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:state, ["goo", "gaa"])
82
- validation.should_not be_matches(WithinIn.new)
83
-
84
- validation = Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher.new(:foo, ["new", "uploaded"])
85
- validation.should_not be_matches(WithinIn.new)
86
- end
87
- end
88
- end
89
-
90
- describe "#validates_length_of or key :length => <length_options>" do
91
- describe "validates_length_of" do
92
- describe "maximum" do
93
- it "should return true if the key has a validates_length of with the specified :maximum" do
94
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :maximum => 32)
95
- validation.should be_matches(Post.new)
96
- end
97
-
98
- it "should return false if the key has a validates_length but the maximum's don't match" do
99
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :maximum => 25)
100
- validation.should_not be_matches(Post.new)
101
- end
102
-
103
- it "should return false if the key does not have a validates_length of" do
104
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:foo, :maximum => 32)
105
- validation.should_not be_matches(Post.new)
106
- end
107
- end
108
-
109
- describe "minimum" do
110
- it "should return true if the key has a validates_length of with the specified :minimum" do
111
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :minimum => 4)
112
- validation.should be_matches(Post.new)
113
- end
114
-
115
- it "should return false if the key has a validates_length of but the minimum's don't match" do
116
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :minimum => 2)
117
- validation.should_not be_matches(Post.new)
118
- end
119
-
120
- it "should return false if the key does not have a validates_length" do
121
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:foo, :minimum => 32)
122
- validation.should_not be_matches(Post.new)
123
- end
124
- end
125
- end
126
-
127
- describe "length" do
128
- it "should work the same as validates_length_of" do
129
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :length => 32)
130
- validation.should be_matches(PostRequired.new)
131
-
132
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:name, :length => 25)
133
- validation.should_not be_matches(PostRequired.new)
134
-
135
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:foo, :length => 32)
136
- validation.should_not be_matches(PostRequired.new)
137
-
138
- validation = Mongoa::MongoMapper::Matchers::ValidateLengthOfMatcher.new(:range_name, :length => 0..56)
139
- validation.should be_matches(PostRequired.new)
140
- end
141
- end
142
- end
143
- end