riot-mongoid 1.1.5 → 2.0.0.beta
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/README.md +15 -0
- data/lib/riot-mongoid/has_association.rb +1 -1
- data/lib/riot-mongoid/has_validation.rb +21 -9
- data/riot-mongoid.gemspec +3 -3
- data/test/has_association_test.rb +4 -9
- data/test/has_validation_test.rb +8 -2
- metadata +8 -9
- data/.document +0 -5
- data/.gitignore +0 -21
data/README.md
CHANGED
@@ -27,6 +27,21 @@ Riot assertions for Mongoid
|
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
|
+
## Mongoid 1.9.1/ Mongoid2.0.0beta+
|
31
|
+
|
32
|
+
To use riot-mongoid with Mongoid 1.9.1 do:
|
33
|
+
|
34
|
+
gem install riot-mongoid
|
35
|
+
|
36
|
+
or check out the [legacy branch](http://github.com/thumblemonks/riot-mongoid/tree/legacy)
|
37
|
+
|
38
|
+
To use riot-mongoid with Mongoid 2.0.0.beta+ do:
|
39
|
+
|
40
|
+
gem install riot-mongoid --pre
|
41
|
+
|
42
|
+
or check out the [master branch](http://github.com/thumblemonks/riot-mongoid)
|
43
|
+
|
44
|
+
|
30
45
|
## Note on Patches/Pull Requests
|
31
46
|
|
32
47
|
* Fork the project.
|
@@ -11,7 +11,7 @@ module RiotMongoid
|
|
11
11
|
elsif assoc.nil? || assoc.macro != assoc_type.to_sym
|
12
12
|
fail("expected #{model} to have association #{assoc_name} of type #{assoc_type}")
|
13
13
|
else
|
14
|
-
options_valid = options.all? { |key,value| assoc.
|
14
|
+
options_valid = options.all? { |key,value| assoc.send(key) == value }
|
15
15
|
options_valid ? pass("#{model} has '#{assoc_type}' association '#{assoc_name}' with options #{options.inspect}") :
|
16
16
|
fail("expected model to have options #{options.inspect} on association #{assoc_name}")
|
17
17
|
end
|
@@ -3,20 +3,32 @@ module RiotMongoid
|
|
3
3
|
register :has_validation
|
4
4
|
|
5
5
|
def evaluate(model, *validation_macro_info)
|
6
|
-
validation_type,
|
7
|
-
|
8
|
-
|
6
|
+
validation_type, validation_field, options = validation_macro_info
|
7
|
+
type = validation_type.to_s
|
8
|
+
%w{validates_ _of}.each { |part| type.gsub!(%r{#{part}},'') }
|
9
|
+
validation = model.validators_on(validation_field).detect do |valid|
|
10
|
+
valid.class.name =~ %r{#{type.capitalize}}
|
9
11
|
end
|
10
12
|
options ||= {}
|
11
13
|
case
|
12
|
-
when
|
13
|
-
fail("validation
|
14
|
+
when validation_field.nil? || validation_type.nil?
|
15
|
+
fail("validation field, type and potential options must be specified with this assertion macro")
|
14
16
|
when validation.nil?
|
15
|
-
fail("expected #{model} to have validation on #{
|
17
|
+
fail("expected #{model} to have validation on #{validation_field} of type #{validation_type}")
|
18
|
+
when (validation.class.name =~ %r{Length} and options.any?)
|
19
|
+
range = options[:within].to_a
|
20
|
+
if (validation.options[:minimum] == range.first) and (validation.options[:maximum] == range.last)
|
21
|
+
pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
|
22
|
+
else
|
23
|
+
fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
|
24
|
+
end
|
16
25
|
else
|
17
|
-
options_valid = options.all? { |key,value| validation.
|
18
|
-
options_valid
|
19
|
-
|
26
|
+
options_valid = options.all? { |key,value| validation.options[key] == value }
|
27
|
+
if options_valid
|
28
|
+
pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
|
29
|
+
else
|
30
|
+
fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
data/riot-mongoid.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{riot-mongoid}
|
3
|
-
s.version = "
|
3
|
+
s.version = "2.0.0.beta"
|
4
4
|
s.required_rubygems_version = ">= 1.3.6"
|
5
|
-
s.authors = ["gabrielg","Arthur Chiu"]
|
5
|
+
s.authors = ["gabrielg", "Arthur Chiu"]
|
6
6
|
s.date = Time.now.strftime("%Y-%m-%d")
|
7
7
|
s.description = %q{A collection of assertion macros for testing Mongoid with Riot}
|
8
8
|
s.email = %q{gabriel.gironda@gmail.com}
|
9
9
|
s.extra_rdoc_files = ["README.md"]
|
10
|
-
s.files = %w{
|
10
|
+
s.files = %w{LICENSE README.md Rakefile riot-mongoid.gemspec} + Dir.glob("{lib,test}/**/*")
|
11
11
|
s.homepage = %q{http://github.com/thumblemonks/riot-mongoid}
|
12
12
|
s.rdoc_options = ["--charset=UTF-8"]
|
13
13
|
s.require_paths = ["lib"]
|
@@ -5,8 +5,7 @@ context "has_association macro" do
|
|
5
5
|
test = mock_model do
|
6
6
|
embeds_many :things
|
7
7
|
embedded_in :another_thing, :inverse_of => :word
|
8
|
-
|
9
|
-
has_many_related :reporters, :klass => 'Person'
|
8
|
+
references_many :relations
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -22,16 +21,12 @@ context "has_association macro" do
|
|
22
21
|
RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :embedded_in, :another_thing, :inverse_of => :word).last
|
23
22
|
end.matches(/has 'embedded_in' association 'another_thing' with options \{:inverse_of=>:word\}/)
|
24
23
|
|
25
|
-
asserts "passes when the no association options are specified for a has_many_related" do
|
26
|
-
RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :has_many_related, :relations).first
|
27
|
-
end.equals(:pass)
|
28
|
-
|
29
24
|
asserts "passes when the association options are specified for a has_many_related" do
|
30
|
-
RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :
|
25
|
+
RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :references_many, :relations).first
|
31
26
|
end.equals(:pass)
|
32
|
-
|
27
|
+
|
33
28
|
asserts "fails when no association name is specified" do
|
34
|
-
RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :
|
29
|
+
RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :has_many_related).first
|
35
30
|
end.equals(:fail)
|
36
31
|
|
37
32
|
end
|
data/test/has_validation_test.rb
CHANGED
@@ -6,9 +6,11 @@ context "has_validation macro" do
|
|
6
6
|
field :name, :type => String
|
7
7
|
field :rad, :type => Boolean, :default => false
|
8
8
|
field :surname, :type => String
|
9
|
+
field :role, :with => /[A-Za-z]/
|
9
10
|
|
10
11
|
validates_presence_of :name, :surname
|
11
12
|
validates_length_of :surname, :within => 4..40
|
13
|
+
validates_format_of :role, :with => /[A-Za-z]/
|
12
14
|
validates_uniqueness_of :rad
|
13
15
|
end
|
14
16
|
end
|
@@ -25,12 +27,16 @@ context "has_validation macro" do
|
|
25
27
|
RiotMongoid::HasValidationAssertion.new.evaluate(topic, :validates_presence_of, :name).last
|
26
28
|
end.matches(/has 'validates_presence_of' validation 'name'/)
|
27
29
|
|
28
|
-
asserts "passes when the validation options is specified" do
|
30
|
+
asserts "passes when the validation options is specified using within" do
|
29
31
|
RiotMongoid::HasValidationAssertion.new.evaluate(topic, :validates_length_of, :surname, :within => 4..40).first
|
30
32
|
end.equals(:pass)
|
31
33
|
|
34
|
+
asserts "passes when the validation options is specified" do
|
35
|
+
RiotMongoid::HasValidationAssertion.new.evaluate(topic, :validates_format_of, :role, :with => /[A-Za-z]/).first
|
36
|
+
end.equals(:pass)
|
37
|
+
|
32
38
|
asserts "passes when the validation options is specified and doesn't match" do
|
33
|
-
RiotMongoid::HasValidationAssertion.new.evaluate(topic, :
|
39
|
+
RiotMongoid::HasValidationAssertion.new.evaluate(topic, :validates_format_of, :role, :with => //).first
|
34
40
|
end.equals(:fail)
|
35
41
|
|
36
42
|
asserts "fails when invalid field options are specified" do
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31098209
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
version: 2.0.0.beta
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- gabrielg
|
@@ -16,7 +17,7 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2010-08-
|
20
|
+
date: 2010-08-29 00:00:00 -07:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
@@ -88,8 +89,6 @@ extensions: []
|
|
88
89
|
extra_rdoc_files:
|
89
90
|
- README.md
|
90
91
|
files:
|
91
|
-
- .document
|
92
|
-
- .gitignore
|
93
92
|
- LICENSE
|
94
93
|
- README.md
|
95
94
|
- Rakefile
|
data/.document
DELETED