mongoid-rspec 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +12 -13
- data/{README.markdown → README.md} +29 -5
- data/Rakefile +7 -35
- data/lib/matchers/associations.rb +16 -1
- data/lib/matchers/collections.rb +9 -0
- data/lib/matchers/validations.rb +4 -3
- data/lib/matchers/validations/numericality_of.rb +47 -14
- data/lib/mongoid-rspec.rb +1 -0
- data/lib/mongoid-rspec/version.rb +5 -0
- data/mongoid-rspec.gemspec +18 -83
- data/spec/models/log.rb +4 -0
- data/spec/models/movie_article.rb +7 -0
- data/spec/models/permalink.rb +5 -0
- data/spec/models/user.rb +1 -1
- data/spec/unit/associations_spec.rb +6 -2
- data/spec/unit/collections_spec.rb +7 -0
- data/spec/unit/validations_spec.rb +8 -2
- metadata +26 -46
- data/VERSION +0 -1
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid-rspec (1.4.
|
5
|
-
mongoid (~> 2.0
|
6
|
-
mongoid-rspec
|
4
|
+
mongoid-rspec (1.4.2)
|
5
|
+
mongoid (~> 2.0)
|
7
6
|
rspec (~> 2)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: http://rubygems.org/
|
11
10
|
specs:
|
12
|
-
activemodel (3.0.
|
13
|
-
activesupport (= 3.0.
|
11
|
+
activemodel (3.0.7)
|
12
|
+
activesupport (= 3.0.7)
|
14
13
|
builder (~> 2.1.2)
|
15
|
-
i18n (~> 0.
|
16
|
-
activesupport (3.0.
|
17
|
-
bson (1.
|
14
|
+
i18n (~> 0.5.0)
|
15
|
+
activesupport (3.0.7)
|
16
|
+
bson (1.3.0)
|
18
17
|
builder (2.1.2)
|
19
18
|
diff-lcs (1.1.2)
|
20
19
|
i18n (0.5.0)
|
21
|
-
mongo (1.
|
22
|
-
bson (>= 1.
|
23
|
-
mongoid (2.0.
|
20
|
+
mongo (1.3.0)
|
21
|
+
bson (>= 1.3.0)
|
22
|
+
mongoid (2.0.1)
|
24
23
|
activemodel (~> 3.0)
|
25
|
-
mongo (~> 1.
|
24
|
+
mongo (~> 1.3)
|
26
25
|
tzinfo (~> 0.3.22)
|
27
26
|
will_paginate (~> 3.0.pre)
|
28
27
|
rspec (2.5.0)
|
@@ -33,7 +32,7 @@ GEM
|
|
33
32
|
rspec-expectations (2.5.0)
|
34
33
|
diff-lcs (~> 1.1.2)
|
35
34
|
rspec-mocks (2.5.0)
|
36
|
-
tzinfo (0.3.
|
35
|
+
tzinfo (0.3.26)
|
37
36
|
will_paginate (3.0.pre2)
|
38
37
|
|
39
38
|
PLATFORMS
|
@@ -14,6 +14,9 @@ Association Matchers
|
|
14
14
|
|
15
15
|
it { should reference_many :comments }
|
16
16
|
it { should have_many :comments }
|
17
|
+
|
18
|
+
#can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
|
19
|
+
it { should have_many(:comments).with_dependent(:destroy) }
|
17
20
|
|
18
21
|
it { should embed_one :profile }
|
19
22
|
|
@@ -42,19 +45,32 @@ Association Matchers
|
|
42
45
|
|
43
46
|
Validation Matchers
|
44
47
|
-
|
48
|
+
describe Site do
|
49
|
+
it { should validate_presence_of(:name) }
|
50
|
+
it { should validate_uniqueness_of(:name) }
|
51
|
+
end
|
52
|
+
|
45
53
|
describe User do
|
46
54
|
it { should validate_presence_of(:login) }
|
47
|
-
it { should validate_uniqueness_of(:login) }
|
55
|
+
it { should validate_uniqueness_of(:login).scoped_to(:site) }
|
56
|
+
it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
|
48
57
|
it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
|
49
58
|
it { should validate_associated(:profile) }
|
50
59
|
it { should validate_inclusion_of(:role).to_allow("admin", "member") }
|
51
|
-
it { should validate_numericality_of(:age) }
|
52
|
-
it { should validate_length_of(:us_phone).as_exactly(7) }
|
53
60
|
it { should validate_confirmation_of(:email) }
|
54
61
|
end
|
55
|
-
|
62
|
+
|
56
63
|
describe Article do
|
57
|
-
it { should validate_length_of(:title).within(
|
64
|
+
it { should validate_length_of(:title).within(8..16) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe Profile do
|
68
|
+
it { should validate_numericality_of(:age).greater_than(0) }
|
69
|
+
end
|
70
|
+
|
71
|
+
describe MovieArticle do
|
72
|
+
it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
|
73
|
+
it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
|
58
74
|
end
|
59
75
|
|
60
76
|
Others
|
@@ -66,7 +82,15 @@ Others
|
|
66
82
|
|
67
83
|
# useful if you use factory_girl and have Factory(:user) defined for User
|
68
84
|
it { should save }
|
85
|
+
|
86
|
+
it { should be_timestamped_document } # if you're declaring `include Mongoid::Timestamps`
|
87
|
+
it { should be_versioned_document } # if you're declaring `include Mongoid::Versioning`
|
88
|
+
it { should be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
|
69
89
|
end
|
90
|
+
|
91
|
+
describe Log do
|
92
|
+
it { should be_stored_in :logs }
|
93
|
+
end
|
70
94
|
|
71
95
|
Use
|
72
96
|
-
|
data/Rakefile
CHANGED
@@ -1,47 +1,19 @@
|
|
1
|
-
|
2
|
-
require 'rake'
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "mongoid-rspec"
|
8
|
-
gem.summary = %Q{RSpec matchers for Mongoid}
|
9
|
-
gem.description = %Q{RSpec matches for Mongoid models, including association and validation matchers}
|
10
|
-
gem.email = "evansagge@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/evansagge/mongoid-rspec"
|
12
|
-
gem.authors = ["Evan Sagge"]
|
13
|
-
gem.add_dependency "mongoid", "~> 2.0.0.rc.7"
|
14
|
-
gem.add_dependency "rspec", "~> 2"
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
20
5
|
|
21
|
-
require 'rspec/core'
|
22
6
|
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
23
8
|
|
24
9
|
task :default => :spec
|
25
|
-
|
26
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
27
|
-
spec.pattern = "./spec/**/*_spec.rb"
|
28
|
-
end
|
29
|
-
|
30
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
31
|
-
spec.pattern = "./spec/**/*_spec.rb"
|
32
|
-
spec.rcov = true
|
33
|
-
end
|
34
|
-
|
35
|
-
# task :spec => :check_dependencies
|
10
|
+
task :test => :spec
|
36
11
|
|
37
12
|
require 'rake/rdoctask'
|
13
|
+
require "mongoid-rspec/version"
|
38
14
|
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
-
|
41
15
|
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "mongoid-rspec #{
|
16
|
+
rdoc.title = "mongoid-rspec #{Mongoid::Rspec::VERSION}"
|
43
17
|
rdoc.rdoc_files.include('README*')
|
44
18
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
19
|
end
|
46
|
-
|
47
|
-
|
@@ -39,6 +39,12 @@ module Mongoid
|
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
|
+
def with_dependent(method_name)
|
43
|
+
@association[:dependent] = method_name
|
44
|
+
@expectation_message << " which specifies dependent as #{@association[:dependent].to_s}"
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
42
48
|
def stored_as(store_as)
|
43
49
|
raise NotImplementedError, "`references_many #{@association[:name]} :stored_as => :array` has been removed in Mongoid 2.0.0.rc, use `references_and_referenced_in_many #{@association[:name]}` instead"
|
44
50
|
end
|
@@ -72,7 +78,7 @@ module Mongoid
|
|
72
78
|
@negative_result_message = "#{@positive_result_message} of type #{metadata.klass.inspect}"
|
73
79
|
return false
|
74
80
|
else
|
75
|
-
@positive_result_message = "#{@positive_result_message} of type #{metadata.klass.inspect}"
|
81
|
+
@positive_result_message = "#{@positive_result_message}#{" of type #{metadata.klass.inspect}" if @association[:class]}"
|
76
82
|
end
|
77
83
|
|
78
84
|
if @association[:inverse_of]
|
@@ -84,6 +90,15 @@ module Mongoid
|
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
93
|
+
if @association[:dependent]
|
94
|
+
if @association[:dependent].to_s != metadata.dependent.to_s
|
95
|
+
@negative_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
|
96
|
+
return false
|
97
|
+
else
|
98
|
+
@positive_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
87
102
|
if @association[:foreign_key]
|
88
103
|
if metadata.foreign_key != @association[:foreign_key]
|
89
104
|
@negative_result_message = "#{@positive_result_message} with foreign key #{metadata.foreign_key.inspect}"
|
data/lib/matchers/validations.rb
CHANGED
@@ -15,7 +15,8 @@ module Mongoid
|
|
15
15
|
@validator = @klass.validators_on(@field).detect{|v| v.kind.to_s == @type }
|
16
16
|
|
17
17
|
if @validator
|
18
|
-
@negative_result_message =
|
18
|
+
@negative_result_message = "#{@type.inspect} validator on #{@field.inspect}"
|
19
|
+
@positive_result_message = "#{@type.inspect} validator on #{@field.inspect}"
|
19
20
|
else
|
20
21
|
@negative_result_message = "no #{@type.inspect} validator on #{@field.inspect}"
|
21
22
|
return false
|
@@ -25,11 +26,11 @@ module Mongoid
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def failure_message_for_should
|
28
|
-
"Expected #{@klass.inspect} to #{description}
|
29
|
+
"Expected #{@klass.inspect} to #{description}; instead got #{@negative_result_message}"
|
29
30
|
end
|
30
31
|
|
31
32
|
def failure_message_for_should_not
|
32
|
-
"Expected #{@klass.inspect} to not #{description}
|
33
|
+
"Expected #{@klass.inspect} to not #{description}; instead got #{@positive_result_message}"
|
33
34
|
end
|
34
35
|
|
35
36
|
def description
|
@@ -2,34 +2,67 @@ module Mongoid
|
|
2
2
|
module Matchers
|
3
3
|
module Validations
|
4
4
|
class ValidateNumericalityOfMatcher < HaveValidationMatcher
|
5
|
+
@@allowed_options = [:equal_to, :greater_than, :greater_than_or_equal_to, :less_than, :less_than_or_equal_to,
|
6
|
+
:even, :odd, :only_integer, :allow_nil, :nil]
|
7
|
+
|
5
8
|
def initialize(field)
|
6
9
|
super(field, :numericality)
|
10
|
+
@options = {}
|
7
11
|
end
|
8
|
-
|
9
|
-
def
|
10
|
-
|
12
|
+
|
13
|
+
def to_allow(options)
|
14
|
+
options[:equal_to] = options if options.is_a?(Numeric)
|
15
|
+
options[:allow_nil] = options.delete(:nil) if options.has_key?(:nil)
|
16
|
+
raise ArgumentError, "validate_numericality_of#to_allow requires a Hash parameter containing any of the following keys: " <<
|
17
|
+
@@allowed_options.map(&:inspect).join(", ") if !options.is_a?(Hash) or options.empty? or (options.keys - @@allowed_options).any?
|
18
|
+
@options.merge!(options)
|
11
19
|
self
|
12
20
|
end
|
13
21
|
|
14
22
|
def matches?(actual)
|
15
23
|
return false unless result = super(actual)
|
16
|
-
|
17
|
-
|
18
|
-
if @
|
19
|
-
|
20
|
-
else
|
21
|
-
@negative_result_message = @negative_result_message << " checking if values are greater than #{@validator.options[:greater_than].inspect}"
|
22
|
-
result = false
|
24
|
+
|
25
|
+
@@allowed_options.each do |comparator|
|
26
|
+
if @options.has_key?(comparator) and !([:even, :odd, :only_integer].include?(comparator) and !@validator.options.include?(comparator))
|
27
|
+
result &= (@validator.options[comparator] == @options[comparator])
|
23
28
|
end
|
24
29
|
end
|
25
|
-
|
30
|
+
@positive_result_message <<= options_message(@validator.options)
|
31
|
+
@negative_result_message <<= options_message(@validator.options)
|
26
32
|
result
|
27
33
|
end
|
28
34
|
|
29
35
|
def description
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
super << options_message(@options)
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def options_message(options)
|
42
|
+
type_msg = []
|
43
|
+
comp_msg = []
|
44
|
+
options.each_pair do |key, value|
|
45
|
+
case key
|
46
|
+
when :allow_nil
|
47
|
+
when :only_integer
|
48
|
+
type_msg << "integer" if value
|
49
|
+
when :odd, :even
|
50
|
+
type_msg << "#{key.to_s}-numbered" if value
|
51
|
+
else
|
52
|
+
comp_msg << "#{key.to_s.gsub("_", " ")} #{value.inspect}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
allow_nil = (options[:allow_nil] ? "nil" : "non-nil") if options.has_key?(:allow_nil)
|
56
|
+
["", "allowing", allow_nil, type_msg.any? ? type_msg.to_sentence : nil, "values", comp_msg.any? ? comp_msg.to_sentence : nil].compact.join(" ")
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_missing(m, *args, &block)
|
60
|
+
if @@allowed_options.include?(m.to_sym)
|
61
|
+
raise ArgumentError, "wrong number of arguments (#{args.length} for 1)" if args.length > 1
|
62
|
+
send :to_allow, m.to_sym => args.first
|
63
|
+
else
|
64
|
+
super
|
65
|
+
end
|
33
66
|
end
|
34
67
|
end
|
35
68
|
|
data/lib/mongoid-rspec.rb
CHANGED
data/mongoid-rspec.gemspec
CHANGED
@@ -1,89 +1,24 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mongoid-rspec/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.name = "mongoid-rspec"
|
7
|
+
s.version = Mongoid::Rspec::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
11
9
|
s.authors = ["Evan Sagge"]
|
12
|
-
s.
|
10
|
+
s.email = %q{evansagge@gmail.com}
|
11
|
+
s.homepage = %q{http://github.com/evansagge/mongoid-rspec}
|
12
|
+
s.summary = %q{RSpec matchers for Mongoid}
|
13
13
|
s.description = %q{RSpec matches for Mongoid models, including association and validation matchers}
|
14
|
-
|
15
|
-
s.
|
16
|
-
"LICENSE",
|
17
|
-
"README.markdown"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".bundle/config",
|
21
|
-
".document",
|
22
|
-
".rvmrc",
|
23
|
-
"Gemfile",
|
24
|
-
"Gemfile.lock",
|
25
|
-
"LICENSE",
|
26
|
-
"README.markdown",
|
27
|
-
"Rakefile",
|
28
|
-
"VERSION",
|
29
|
-
"lib/matchers/associations.rb",
|
30
|
-
"lib/matchers/document.rb",
|
31
|
-
"lib/matchers/validations.rb",
|
32
|
-
"lib/matchers/validations/associated.rb",
|
33
|
-
"lib/matchers/validations/confirmation_of.rb",
|
34
|
-
"lib/matchers/validations/format_of.rb",
|
35
|
-
"lib/matchers/validations/inclusion_of.rb",
|
36
|
-
"lib/matchers/validations/length_of.rb",
|
37
|
-
"lib/matchers/validations/numericality_of.rb",
|
38
|
-
"lib/matchers/validations/presence_of.rb",
|
39
|
-
"lib/matchers/validations/uniqueness_of.rb",
|
40
|
-
"lib/mongoid-rspec.rb",
|
41
|
-
"mongoid-rspec.gemspec",
|
42
|
-
"spec/models/article.rb",
|
43
|
-
"spec/models/comment.rb",
|
44
|
-
"spec/models/profile.rb",
|
45
|
-
"spec/models/record.rb",
|
46
|
-
"spec/models/site.rb",
|
47
|
-
"spec/models/user.rb",
|
48
|
-
"spec/spec_helper.rb",
|
49
|
-
"spec/unit/associations_spec.rb",
|
50
|
-
"spec/unit/document_spec.rb",
|
51
|
-
"spec/unit/validations_spec.rb"
|
52
|
-
]
|
53
|
-
s.homepage = %q{http://github.com/evansagge/mongoid-rspec}
|
54
|
-
s.require_paths = ["lib"]
|
55
|
-
s.rubygems_version = %q{1.3.7}
|
56
|
-
s.summary = %q{RSpec matchers for Mongoid}
|
57
|
-
s.test_files = [
|
58
|
-
"spec/models/article.rb",
|
59
|
-
"spec/models/comment.rb",
|
60
|
-
"spec/models/profile.rb",
|
61
|
-
"spec/models/record.rb",
|
62
|
-
"spec/models/site.rb",
|
63
|
-
"spec/models/user.rb",
|
64
|
-
"spec/spec_helper.rb",
|
65
|
-
"spec/unit/associations_spec.rb",
|
66
|
-
"spec/unit/document_spec.rb",
|
67
|
-
"spec/unit/validations_spec.rb"
|
68
|
-
]
|
69
|
-
|
70
|
-
if s.respond_to? :specification_version then
|
71
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
72
|
-
s.specification_version = 3
|
73
|
-
|
74
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
75
|
-
s.add_runtime_dependency(%q<mongoid-rspec>, [">= 0"])
|
76
|
-
s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.rc.7"])
|
77
|
-
s.add_runtime_dependency(%q<rspec>, ["~> 2"])
|
78
|
-
else
|
79
|
-
s.add_dependency(%q<mongoid-rspec>, [">= 0"])
|
80
|
-
s.add_dependency(%q<mongoid>, ["~> 2.0.0.rc.7"])
|
81
|
-
s.add_dependency(%q<rspec>, ["~> 2"])
|
82
|
-
end
|
83
|
-
else
|
84
|
-
s.add_dependency(%q<mongoid-rspec>, [">= 0"])
|
85
|
-
s.add_dependency(%q<mongoid>, ["~> 2.0.0.rc.7"])
|
86
|
-
s.add_dependency(%q<rspec>, ["~> 2"])
|
87
|
-
end
|
88
|
-
end
|
14
|
+
|
15
|
+
s.rubyforge_project = "mongoid-rspec"
|
89
16
|
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency(%q<mongoid>, ["~> 2.0"])
|
23
|
+
s.add_runtime_dependency(%q<rspec>, ["~> 2"])
|
24
|
+
end
|
data/spec/models/log.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
class MovieArticle < Article
|
2
|
+
field :rating, :type => Numeric
|
3
|
+
field :classification, :type => Integer
|
4
|
+
|
5
|
+
validates_numericality_of :rating, :greater_than => 0, :less_than_or_equal_to => 5
|
6
|
+
validates_numericality_of :classification, :even => true, :only_integer => true, :allow_nil => false
|
7
|
+
end
|
data/spec/models/user.rb
CHANGED
@@ -7,7 +7,7 @@ class User
|
|
7
7
|
|
8
8
|
referenced_in :site, :inverse_of => :users
|
9
9
|
references_many :articles, :foreign_key => :author_id
|
10
|
-
references_many :comments
|
10
|
+
references_many :comments, :dependent => :destroy
|
11
11
|
references_and_referenced_in_many :children, :class_name => "User"
|
12
12
|
references_one :record
|
13
13
|
|
@@ -8,8 +8,8 @@ describe "Associations" do
|
|
8
8
|
it { should reference_one(:record) }
|
9
9
|
it { should have_one(:record) }
|
10
10
|
|
11
|
-
it { should reference_many
|
12
|
-
it { should have_many
|
11
|
+
it { should reference_many(:comments).with_dependent(:destroy) }
|
12
|
+
it { should have_many(:comments).with_dependent(:destroy) }
|
13
13
|
|
14
14
|
it { should embed_one :profile }
|
15
15
|
|
@@ -35,4 +35,8 @@ describe "Associations" do
|
|
35
35
|
describe Record do
|
36
36
|
it { should be_referenced_in(:user).as_inverse_of(:record) }
|
37
37
|
end
|
38
|
+
|
39
|
+
describe Permalink do
|
40
|
+
it { should be_embedded_in(:linkable).as_inverse_of(:link) }
|
41
|
+
end
|
38
42
|
end
|
@@ -5,7 +5,7 @@ describe "Validations" do
|
|
5
5
|
it { should validate_presence_of(:name) }
|
6
6
|
it { should validate_uniqueness_of(:name) }
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe User do
|
10
10
|
it { should validate_presence_of(:login) }
|
11
11
|
it { should validate_uniqueness_of(:login).scoped_to(:site) }
|
@@ -19,8 +19,14 @@ describe "Validations" do
|
|
19
19
|
describe Profile do
|
20
20
|
it { should validate_numericality_of(:age).greater_than(0) }
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe Article do
|
24
24
|
it { should validate_length_of(:title).within(8..16) }
|
25
25
|
end
|
26
|
+
|
27
|
+
describe MovieArticle do
|
28
|
+
it { should validate_numericality_of(:rating).greater_than(0) }
|
29
|
+
it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
|
30
|
+
it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
|
31
|
+
end
|
26
32
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 4
|
8
|
-
- 1
|
9
|
-
version: 1.4.1
|
4
|
+
prerelease:
|
5
|
+
version: 1.4.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Evan Sagge
|
@@ -14,72 +10,51 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-04-23 00:00:00 +08:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: mongoid-rspec
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
30
|
-
type: :runtime
|
31
|
-
prerelease: false
|
32
|
-
version_requirements: *id001
|
33
16
|
- !ruby/object:Gem::Dependency
|
34
17
|
name: mongoid
|
35
|
-
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
36
20
|
none: false
|
37
21
|
requirements:
|
38
22
|
- - ~>
|
39
23
|
- !ruby/object:Gem::Version
|
40
|
-
|
41
|
-
- 2
|
42
|
-
- 0
|
43
|
-
- 0
|
44
|
-
- rc
|
45
|
-
- 7
|
46
|
-
version: 2.0.0.rc.7
|
24
|
+
version: "2.0"
|
47
25
|
type: :runtime
|
48
|
-
|
49
|
-
version_requirements: *id002
|
26
|
+
version_requirements: *id001
|
50
27
|
- !ruby/object:Gem::Dependency
|
51
28
|
name: rspec
|
52
|
-
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
53
31
|
none: false
|
54
32
|
requirements:
|
55
33
|
- - ~>
|
56
34
|
- !ruby/object:Gem::Version
|
57
|
-
segments:
|
58
|
-
- 2
|
59
35
|
version: "2"
|
60
36
|
type: :runtime
|
61
|
-
|
62
|
-
version_requirements: *id003
|
37
|
+
version_requirements: *id002
|
63
38
|
description: RSpec matches for Mongoid models, including association and validation matchers
|
64
39
|
email: evansagge@gmail.com
|
65
40
|
executables: []
|
66
41
|
|
67
42
|
extensions: []
|
68
43
|
|
69
|
-
extra_rdoc_files:
|
70
|
-
|
71
|
-
- README.markdown
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
72
46
|
files:
|
73
47
|
- .bundle/config
|
74
48
|
- .document
|
49
|
+
- .gitignore
|
75
50
|
- .rvmrc
|
76
51
|
- Gemfile
|
77
52
|
- Gemfile.lock
|
78
53
|
- LICENSE
|
79
|
-
- README.
|
54
|
+
- README.md
|
80
55
|
- Rakefile
|
81
|
-
- VERSION
|
82
56
|
- lib/matchers/associations.rb
|
57
|
+
- lib/matchers/collections.rb
|
83
58
|
- lib/matchers/document.rb
|
84
59
|
- lib/matchers/validations.rb
|
85
60
|
- lib/matchers/validations/associated.rb
|
@@ -91,15 +66,20 @@ files:
|
|
91
66
|
- lib/matchers/validations/presence_of.rb
|
92
67
|
- lib/matchers/validations/uniqueness_of.rb
|
93
68
|
- lib/mongoid-rspec.rb
|
69
|
+
- lib/mongoid-rspec/version.rb
|
94
70
|
- mongoid-rspec.gemspec
|
95
71
|
- spec/models/article.rb
|
96
72
|
- spec/models/comment.rb
|
73
|
+
- spec/models/log.rb
|
74
|
+
- spec/models/movie_article.rb
|
75
|
+
- spec/models/permalink.rb
|
97
76
|
- spec/models/profile.rb
|
98
77
|
- spec/models/record.rb
|
99
78
|
- spec/models/site.rb
|
100
79
|
- spec/models/user.rb
|
101
80
|
- spec/spec_helper.rb
|
102
81
|
- spec/unit/associations_spec.rb
|
82
|
+
- spec/unit/collections_spec.rb
|
103
83
|
- spec/unit/document_spec.rb
|
104
84
|
- spec/unit/validations_spec.rb
|
105
85
|
has_rdoc: true
|
@@ -116,32 +96,32 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
96
|
requirements:
|
117
97
|
- - ">="
|
118
98
|
- !ruby/object:Gem::Version
|
119
|
-
segments:
|
120
|
-
- 0
|
121
99
|
version: "0"
|
122
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
101
|
none: false
|
124
102
|
requirements:
|
125
103
|
- - ">="
|
126
104
|
- !ruby/object:Gem::Version
|
127
|
-
segments:
|
128
|
-
- 0
|
129
105
|
version: "0"
|
130
106
|
requirements: []
|
131
107
|
|
132
|
-
rubyforge_project:
|
133
|
-
rubygems_version: 1.
|
108
|
+
rubyforge_project: mongoid-rspec
|
109
|
+
rubygems_version: 1.5.2
|
134
110
|
signing_key:
|
135
111
|
specification_version: 3
|
136
112
|
summary: RSpec matchers for Mongoid
|
137
113
|
test_files:
|
138
114
|
- spec/models/article.rb
|
139
115
|
- spec/models/comment.rb
|
116
|
+
- spec/models/log.rb
|
117
|
+
- spec/models/movie_article.rb
|
118
|
+
- spec/models/permalink.rb
|
140
119
|
- spec/models/profile.rb
|
141
120
|
- spec/models/record.rb
|
142
121
|
- spec/models/site.rb
|
143
122
|
- spec/models/user.rb
|
144
123
|
- spec/spec_helper.rb
|
145
124
|
- spec/unit/associations_spec.rb
|
125
|
+
- spec/unit/collections_spec.rb
|
146
126
|
- spec/unit/document_spec.rb
|
147
127
|
- spec/unit/validations_spec.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.4.1
|