mongoid-rspec 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/lib/matchers/associations.rb +21 -0
- data/lib/matchers/validations.rb +14 -2
- data/lib/mongoid-rspec/version.rb +1 -1
- data/spec/models/article.rb +4 -0
- data/spec/models/site.rb +2 -2
- data/spec/unit/associations_spec.rb +1 -1
- data/spec/unit/validations_spec.rb +2 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -43,6 +43,12 @@ module Mongoid
|
|
43
43
|
raise "#{@association[:type].inspect} does not respond to :order" unless [HAS_MANY, HAS_AND_BELONGS_TO_MANY, EMBEDS_MANY].include?(@association[:type])
|
44
44
|
@association[:order] = association_field_name.to_s
|
45
45
|
@expectation_message << " ordered by #{@association[:order].inspect}"
|
46
|
+
|
47
|
+
if association_field_name.is_a? Origin::Key
|
48
|
+
@association[:order_operator] = association_field_name.operator
|
49
|
+
@expectation_message << " #{order_way(@association[:order_operator])}"
|
50
|
+
end
|
51
|
+
|
46
52
|
self
|
47
53
|
end
|
48
54
|
|
@@ -124,6 +130,15 @@ module Mongoid
|
|
124
130
|
end
|
125
131
|
end
|
126
132
|
|
133
|
+
if @association[:order_operator]
|
134
|
+
if @association[:order_operator] != metadata.order.operator
|
135
|
+
@negative_result_message = "#{@positive_result_message} #{order_way(@association[:order_operator] * -1)}"
|
136
|
+
return false
|
137
|
+
else
|
138
|
+
@positive_result_message = "#{@positive_result_message} #{order_way(@association[:order_operator])}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
127
142
|
if @association[:dependent]
|
128
143
|
if @association[:dependent].to_s != metadata.dependent.to_s
|
129
144
|
@negative_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
|
@@ -205,6 +220,12 @@ module Mongoid
|
|
205
220
|
raise "Unknown association type '%s'" % type
|
206
221
|
end
|
207
222
|
end
|
223
|
+
|
224
|
+
private
|
225
|
+
|
226
|
+
def order_way(operator)
|
227
|
+
[nil, "ascending", "descending"][operator]
|
228
|
+
end
|
208
229
|
end
|
209
230
|
|
210
231
|
def embed_one(association_name)
|
data/lib/matchers/validations.rb
CHANGED
@@ -13,7 +13,9 @@ module Mongoid
|
|
13
13
|
def matches?(actual)
|
14
14
|
@klass = actual.is_a?(Class) ? actual : actual.class
|
15
15
|
|
16
|
-
@validator = @klass.validators_on(@field).detect{|v|
|
16
|
+
@validator = @klass.validators_on(@field).detect{ |v|
|
17
|
+
v.kind.to_s == @type and (!v.options[:on] or on_options_matches?(v))
|
18
|
+
}
|
17
19
|
|
18
20
|
if @validator
|
19
21
|
@negative_result_message = "#{@type.inspect} validator on #{@field.inspect}"
|
@@ -52,7 +54,7 @@ module Mongoid
|
|
52
54
|
if validator_on_methods.any?
|
53
55
|
message = " on methods: #{validator_on_methods}"
|
54
56
|
|
55
|
-
if (@
|
57
|
+
if on_options_covered_by?( @validator )
|
56
58
|
@positive_result_message << message
|
57
59
|
else
|
58
60
|
@negative_result_message << message
|
@@ -60,6 +62,16 @@ module Mongoid
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def on_options_matches?(validator)
|
69
|
+
@options[:on] and validator.options[:on] and on_options_covered_by?(validator)
|
70
|
+
end
|
71
|
+
|
72
|
+
def on_options_covered_by?(validator)
|
73
|
+
([@options[:on]].flatten - [validator.options[:on]].flatten).empty?
|
74
|
+
end
|
63
75
|
end
|
64
76
|
end
|
65
77
|
end
|
data/spec/models/article.rb
CHANGED
@@ -10,6 +10,7 @@ class Article
|
|
10
10
|
field :published, :type => Boolean, :default => false
|
11
11
|
field :allow_comments, :type => Boolean, :default => true
|
12
12
|
field :number_of_comments, :type => Integer
|
13
|
+
field :status, :type => Symbol
|
13
14
|
|
14
15
|
embeds_many :comments
|
15
16
|
embeds_one :permalink
|
@@ -17,6 +18,9 @@ class Article
|
|
17
18
|
|
18
19
|
validates :title, :presence => true
|
19
20
|
|
21
|
+
validates_inclusion_of :status, :in => [:pending], :on => :create
|
22
|
+
validates_inclusion_of :status, :in => [:approved, :rejected ], :on => :update
|
23
|
+
|
20
24
|
validates_length_of :title, :within => 8..16
|
21
25
|
validates_length_of :content, :minimum => 200
|
22
26
|
|
data/spec/models/site.rb
CHANGED
@@ -33,6 +33,8 @@ describe "Validations" do
|
|
33
33
|
it { should validate_length_of(:title).within(8..16) }
|
34
34
|
it { should_not validate_length_of(:content).greater_than(200).less_than(16) }
|
35
35
|
it { should validate_length_of(:content).greater_than(200) }
|
36
|
+
it { should validate_inclusion_of(:status).to_allow([:pending]).on( :create ) }
|
37
|
+
it { should validate_inclusion_of(:status).to_allow([:approved, :rejected]).on( :update ) }
|
36
38
|
end
|
37
39
|
|
38
40
|
describe MovieArticle do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: 1210204238905216362
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
none: false
|
136
136
|
requirements:
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
segments:
|
141
141
|
- 0
|
142
|
-
hash:
|
142
|
+
hash: 1210204238905216362
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project: mongoid-rspec
|
145
145
|
rubygems_version: 1.8.25
|