riot-mongoid 2.0.0.beta.rc.7 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,51 +4,46 @@ Riot assertions for Mongoid
4
4
 
5
5
  ## Examples
6
6
 
7
- context "Photo Model" do
7
+ ```ruby
8
+ context "Photo Model" do
8
9
 
9
- context 'definition' do
10
- setup { Photo }
10
+ context 'definition' do
11
+ setup { Photo }
11
12
 
12
- # field associations
13
- asserts_topic.has_field :title, :type => String
14
- asserts_topic.has_field :caption, :type => String, :default => ""
13
+ # field associations
14
+ asserts_topic.has_field :title, :type => String
15
+ asserts_topic.has_field :caption, :type => String, :default => ""
15
16
 
16
- # association assertions
17
- asserts_topic.has_association :referenced_in, :account
18
- asserts_topic.has_association :references_many, :comments
19
- asserts_topic.has_association :embedded_in, :customer, :class_name => "Person"
17
+ # association assertions
18
+ asserts_topic.has_association :referenced_in, :account
19
+ asserts_topic.has_association :references_many, :comments
20
+ asserts_topic.has_association :embedded_in, :customer, :class_name => "Person"
20
21
 
21
- # validation assertions
22
- asserts_topic.has_validation :validates_presence_of, :caption
22
+ # validation assertions
23
+ asserts_topic.has_validation :validates_presence_of, :caption
23
24
 
24
- # support for custom validators, see the tests for a complete example
25
- validates :states, :inclusion_of_set => { :in => [1, 2, 3] }
25
+ # support for custom validators, see the tests for a complete example
26
+ validates :states, :inclusion_of_set => { :in => [1, 2, 3] }
26
27
 
27
- # key assertions
28
- asserts_topic.has_key :title, :caption
29
- end
30
- end
28
+ # key assertions
29
+ asserts_topic.has_key :title, :caption
30
+ end
31
+ end
32
+ ```
31
33
 
32
34
 
33
- ## Mongoid 1.9.1/ Mongoid2.0.0beta+ / Mongoid2.0.0.rc.7
35
+ ## Mongoid 1.9.1
34
36
 
35
- To use riot-mongoid with Mongoid 1.9.1 do:
37
+ To use riot-mongoid with Mongoid 1.9.1 check out the [legacy branch](http://github.com/thumblemonks/riot-mongoid/tree/legacy)
36
38
 
37
- gem install riot-mongoid
38
-
39
- or check out the [legacy branch](http://github.com/thumblemonks/riot-mongoid/tree/legacy)
40
-
41
- To use riot-mongoid with Mongoid 2.0.0.beta+ do:
39
+ ## Mongoid 2.1.x
42
40
 
43
- gem install riot-mongoid -v 2.0.0.beta.2
41
+ To use riot-mongoid with Mongoid 2.1.x do:
44
42
 
45
- or check out the [beta20 branch](http://github.com/thumblemonks/riot-mongoid/tree/beta20)
46
-
47
- For Mongoid 2.0.0.rc.7 do:
43
+ gem install riot-mongoid
48
44
 
49
- gem install riot-mongoid --pre
45
+ or check out the [master branch](http://github.com/thumblemonks/riot-mongoid/tree/beta20)
50
46
 
51
- or check out the [master branch](http://github.com/thumblemonks/riot-mongoid)
52
47
 
53
48
  ## Note on Patches/Pull Requests
54
49
 
@@ -2,19 +2,20 @@ module RiotMongoid
2
2
  class HasAssociationAssertion < Riot::AssertionMacro
3
3
  register :has_association
4
4
 
5
- def evaluate(model, *association_macro_info)
6
- assoc_type, assoc_name, options = association_macro_info
7
- assoc = model.relations[assoc_name.to_s]
8
- options ||= {}
9
- if assoc_name.nil?
10
- fail("association name and potential options must be specified with this assertion macro")
11
- elsif assoc.nil? || assoc.macro != assoc_type.to_sym
12
- fail("expected #{model} to have association #{assoc_name} of type #{assoc_type}")
13
- else
14
- options_valid = options.all? { |key,value| assoc.send(key) == value }
15
- options_valid ? pass("#{model} has '#{assoc_type}' association '#{assoc_name}' with options #{options.inspect}") :
16
- fail("expected model to have options #{options.inspect} on association #{assoc_name}")
5
+ def evaluate(model, type, field, options = {})
6
+ fail_msg = "expected #{model.class.to_s} to have assocation '#{type} :#{field}'"
7
+ pass_msg = "#{model.class.to_s} has association '#{type} :#{field}'"
8
+ opt_msg = " with options #{options.inspect}"
9
+ assoc = model.relations[field.to_s]
10
+
11
+ return fail(fail_msg) if assoc.nil? || assoc.macro != type.to_sym
12
+
13
+ unless options.empty?
14
+ return fail(fail_msg + opt_msg) unless options.all? { |k, v| assoc.send(k) == v }
15
+ return pass(pass_msg + opt_msg)
17
16
  end
17
+
18
+ pass pass_msg
18
19
  end
19
20
  end
20
21
  end
@@ -2,18 +2,20 @@ module RiotMongoid
2
2
  class HasFieldAssertion < Riot::AssertionMacro
3
3
  register :has_field
4
4
 
5
- def evaluate(model, *macro_info)
6
- field_name, options = macro_info
7
- field = model.fields[field_name.to_s]
8
- # if options.nil? || options.empty?
9
- # fail("field options must be specified with this assertion macro")
10
- if field.nil?
11
- fail("expected #{model} to have field #{field_name}")
12
- else
13
- options_valid = options.all? { |key,value| field.send(key) == value }
14
- options_valid ? pass("#{model} has field '#{field_name}' with options #{options.inspect}") :
15
- fail("expected model to have options #{options.inspect} on field #{field_name}")
5
+ def evaluate(model, field_name, options = {})
6
+ fail_msg = "expected #{model.class.to_s} to have field :#{field_name}"
7
+ pass_msg = "#{model.class.to_s} has field :#{field_name}"
8
+ opt_msg = " with options #{options.inspect}"
9
+ field = model.fields[field_name.to_s]
10
+
11
+ return fail(fail_msg) if field.nil?
12
+
13
+ unless options.empty?
14
+ return fail(fail_msg + opt_msg) unless options.all? { |k,v| field.send(k) == v }
15
+ return pass(pass_msg + opt_msg)
16
16
  end
17
+
18
+ pass pass_msg
17
19
  end
18
20
  end
19
- end
21
+ end
@@ -2,41 +2,33 @@ module RiotMongoid
2
2
  class HasValidationAssertion < Riot::AssertionMacro
3
3
  register :has_validation
4
4
 
5
- def evaluate(model, *validation_macro_info)
6
- validation_type, validation_field, options = validation_macro_info
7
- type = validation_type.to_s
5
+ def evaluate(model, type, field, options = {})
6
+ fail_msg = "expected #{model.class.to_s} to have validation '#{type} :#{field}'"
7
+ pass_msg = "#{model.class.to_s} has validation '#{type} :#{field}'"
8
+ opt_msg = " with options #{options.inspect}"
8
9
 
9
- %w{validates_ _of}.each { |part| type.gsub!(%r{#{part}},'') }
10
+ type = type.to_s.match(/validates_(.*)_of/)[1] rescue type.to_s
10
11
 
11
- validation = model._validators[validation_field].detect do |valid|
12
- valid.class.name =~ /#{type.camelize}/
13
- end
14
-
15
- options ||= {}
16
-
17
- case
18
- when validation_field.nil? || validation_type.nil?
19
- fail("validation field, type and potential options must be specified with this assertion macro")
20
-
21
- when validation.nil?
22
- fail("expected #{model} to have validation on #{validation_field} of type #{validation_type}")
12
+ validation = model._validators[field].detect { |v| v.class.name =~ /#{type.camelize}/ }
23
13
 
24
- when (validation.class.name =~ %r{Length} and options[:within])
25
- range = options[:within].to_a
26
- if (validation.options[:minimum] == range.first) and (validation.options[:maximum] == range.last)
27
- pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
28
- else
29
- fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
30
- end
14
+ return fail(fail_msg) if validation.nil?
31
15
 
16
+ # special case to check for validates_length_of :within option
17
+ if validation.class.name =~ %r{Length} and options[:within]
18
+ range = options[:within].to_a
19
+ if (validation.options[:minimum] == range.first) and (validation.options[:maximum] == range.last)
20
+ return pass(pass_msg + opt_msg)
32
21
  else
33
- options_valid = options.all? { |key,value| validation.options[key] == value }
34
- if options_valid
35
- pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
36
- else
37
- fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
38
- end
22
+ return fail(fail_msg + opt_msg)
23
+ end
39
24
  end
25
+
26
+ unless options.empty?
27
+ return fail(fail_msg + opt_msg) unless options.all? { |k,v| validation.options[k] == v }
28
+ return pass(pass_msg + opt_msg)
29
+ end
30
+
31
+ pass pass_msg
40
32
  end
41
33
  end
42
34
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{riot-mongoid}
3
- s.version = "2.0.0.beta.rc.7"
3
+ s.version = "2.1.0"
4
4
  s.required_rubygems_version = ">= 1.3.6"
5
5
  s.authors = ["gabrielg", "Arthur Chiu"]
6
6
  s.date = Time.now.strftime("%Y-%m-%d")
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.rdoc_options = ["--charset=UTF-8"]
13
13
  s.require_paths = ["lib"]
14
14
  s.summary = %q{Riot assertions for Mongoid}
15
- s.add_dependency "mongoid", "~> 2.0.0.beta.rc.7"
15
+ s.add_dependency "mongoid", "~> 2.1.0"
16
16
  s.add_dependency "riot", "~> 0.12.3"
17
17
  s.add_development_dependency "yard", ">= 0"
18
18
  end
@@ -19,14 +19,9 @@ context "has_association macro" do
19
19
 
20
20
  asserts "returns useful message" do
21
21
  RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :embedded_in, :another_thing, :inverse_of => :word).last
22
- end.matches(/has 'embedded_in' association 'another_thing' with options \{:inverse_of=>:word\}/)
22
+ end.matches(/Class has association 'embedded_in :another_thing' with options \{:inverse_of=>:word\}/)
23
23
 
24
24
  asserts "passes when the association options are specified for a references_many" do
25
25
  RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :references_many, :relations, :class_name => "Relation").first
26
26
  end.equals(:pass)
27
-
28
- asserts "fails when no association name is specified" do
29
- RiotMongoid::HasAssociationAssertion.new.evaluate(topic, :has_many_related).first
30
- end.equals(:fail)
31
-
32
27
  end
@@ -13,7 +13,7 @@ context "has_field macro" do
13
13
 
14
14
  asserts "returns useful message" do
15
15
  RiotMongoid::HasFieldAssertion.new.evaluate(topic, :name, :type => String).last
16
- end.matches(/has field 'name' with options \{:type=>String\}/)
16
+ end.matches(/Class has field :name with options \{:type=>String\}/)
17
17
 
18
18
  asserts "fails when invalid field options are specified" do
19
19
  RiotMongoid::HasFieldAssertion.new.evaluate(topic, :name, :type => Date).first
@@ -41,7 +41,7 @@ context "has_validation macro" do
41
41
 
42
42
  asserts "returns useful message" do
43
43
  RiotMongoid::HasValidationAssertion.new.evaluate(topic, :validates_presence_of, :name).last
44
- end.matches(/has 'validates_presence_of' validation 'name'/)
44
+ end.matches(/Class has validation 'validates_presence_of :name'/)
45
45
 
46
46
  asserts "passes when the validation options is specified using within" do
47
47
  RiotMongoid::HasValidationAssertion.new.evaluate(topic, :validates_length_of, :surname, :within => 4..40).first
metadata CHANGED
@@ -1,85 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: riot-mongoid
3
- version: !ruby/object:Gem::Version
4
- hash: 125915043
5
- prerelease: 6
6
- segments:
7
- - 2
8
- - 0
9
- - 0
10
- - beta
11
- - rc
12
- - 7
13
- version: 2.0.0.beta.rc.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ prerelease:
14
6
  platform: ruby
15
- authors:
7
+ authors:
16
8
  - gabrielg
17
9
  - Arthur Chiu
18
10
  autorequire:
19
11
  bindir: bin
20
12
  cert_chain: []
21
-
22
- date: 2011-03-17 00:00:00 -07:00
23
- default_executable:
24
- dependencies:
25
- - !ruby/object:Gem::Dependency
13
+ date: 2011-08-18 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
26
16
  name: mongoid
27
- prerelease: false
28
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2153377560 !ruby/object:Gem::Requirement
29
18
  none: false
30
- requirements:
19
+ requirements:
31
20
  - - ~>
32
- - !ruby/object:Gem::Version
33
- hash: 125915043
34
- segments:
35
- - 2
36
- - 0
37
- - 0
38
- - beta
39
- - rc
40
- - 7
41
- version: 2.0.0.beta.rc.7
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.0
42
23
  type: :runtime
43
- version_requirements: *id001
44
- - !ruby/object:Gem::Dependency
45
- name: riot
46
24
  prerelease: false
47
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2153377560
26
+ - !ruby/object:Gem::Dependency
27
+ name: riot
28
+ requirement: &2153377100 !ruby/object:Gem::Requirement
48
29
  none: false
49
- requirements:
30
+ requirements:
50
31
  - - ~>
51
- - !ruby/object:Gem::Version
52
- hash: 41
53
- segments:
54
- - 0
55
- - 12
56
- - 3
32
+ - !ruby/object:Gem::Version
57
33
  version: 0.12.3
58
34
  type: :runtime
59
- version_requirements: *id002
60
- - !ruby/object:Gem::Dependency
61
- name: yard
62
35
  prerelease: false
63
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2153377100
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ requirement: &2153376640 !ruby/object:Gem::Requirement
64
40
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
72
45
  type: :development
73
- version_requirements: *id003
46
+ prerelease: false
47
+ version_requirements: *2153376640
74
48
  description: A collection of assertion macros for testing Mongoid with Riot
75
49
  email: gabriel.gironda@gmail.com
76
50
  executables: []
77
-
78
51
  extensions: []
79
-
80
- extra_rdoc_files:
52
+ extra_rdoc_files:
81
53
  - README.md
82
- files:
54
+ files:
83
55
  - LICENSE
84
56
  - README.md
85
57
  - Rakefile
@@ -94,41 +66,29 @@ files:
94
66
  - test/has_key_test.rb
95
67
  - test/has_validation_test.rb
96
68
  - test/teststrap.rb
97
- has_rdoc: true
98
69
  homepage: http://github.com/thumblemonks/riot-mongoid
99
70
  licenses: []
100
-
101
71
  post_install_message:
102
- rdoc_options:
72
+ rdoc_options:
103
73
  - --charset=UTF-8
104
- require_paths:
74
+ require_paths:
105
75
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
76
+ required_ruby_version: !ruby/object:Gem::Requirement
107
77
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
83
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 23
121
- segments:
122
- - 1
123
- - 3
124
- - 6
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
125
87
  version: 1.3.6
126
88
  requirements: []
127
-
128
89
  rubyforge_project:
129
- rubygems_version: 1.6.1
90
+ rubygems_version: 1.8.6
130
91
  signing_key:
131
92
  specification_version: 3
132
93
  summary: Riot assertions for Mongoid
133
94
  test_files: []
134
-