mongoid-rspec 2.1.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +222 -102
- data/Rakefile +8 -5
- data/lib/matchers/accept_nested_attributes.rb +22 -23
- data/lib/matchers/allow_mass_assignment.rb +12 -12
- data/lib/matchers/associations.rb +85 -49
- data/lib/matchers/be_dynamic_document.rb +26 -0
- data/lib/matchers/be_mongoid_document.rb +26 -0
- data/lib/matchers/be_stored_in.rb +55 -0
- data/lib/matchers/have_field.rb +90 -0
- data/lib/matchers/have_timestamps.rb +61 -0
- data/lib/matchers/indexes/have_index_for.rb +16 -0
- data/lib/matchers/indexes/v3/have_index_for.rb +59 -0
- data/lib/matchers/indexes/v4/have_index_for.rb +54 -0
- data/lib/matchers/validations.rb +30 -11
- data/lib/matchers/validations/absence_of.rb +11 -0
- data/lib/matchers/validations/associated.rb +1 -1
- data/lib/matchers/validations/confirmation_of.rb +7 -1
- data/lib/matchers/validations/custom_validation_of.rb +1 -4
- data/lib/matchers/validations/exclusion_of.rb +5 -5
- data/lib/matchers/validations/format_of.rb +2 -2
- data/lib/matchers/validations/inclusion_of.rb +5 -5
- data/lib/matchers/validations/length_of.rb +13 -35
- data/lib/matchers/validations/numericality_of.rb +32 -16
- data/lib/matchers/validations/presence_of.rb +1 -1
- data/lib/matchers/validations/uniqueness_of.rb +7 -10
- data/lib/mongoid-rspec.rb +1 -33
- data/lib/mongoid/rspec.rb +46 -0
- data/lib/mongoid/rspec/version.rb +5 -0
- data/spec/models/article.rb +9 -6
- data/spec/models/comment.rb +1 -1
- data/spec/models/log.rb +3 -3
- data/spec/models/message.rb +17 -0
- data/spec/models/movie_article.rb +1 -2
- data/spec/models/person.rb +1 -1
- data/spec/models/profile.rb +2 -2
- data/spec/models/record.rb +1 -1
- data/spec/models/site.rb +5 -1
- data/spec/models/user.rb +12 -10
- data/spec/spec_helper.rb +12 -10
- data/spec/unit/accept_nested_attributes_spec.rb +1 -1
- data/spec/unit/associations_spec.rb +19 -7
- data/spec/unit/be_dynamic_document_spec.rb +21 -0
- data/spec/unit/be_mongoid_document_spec.rb +25 -0
- data/spec/unit/be_stored_in.rb +54 -0
- data/spec/unit/document_spec.rb +5 -14
- data/spec/unit/have_index_for_spec.rb +46 -0
- data/spec/unit/have_timestamps_spec.rb +71 -0
- data/spec/unit/validations_spec.rb +23 -14
- data/spec/validators/ssn_validator.rb +6 -6
- metadata +119 -43
- data/.document +0 -5
- data/.gitignore +0 -6
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -10
- data/Gemfile +0 -4
- data/lib/matchers/collections.rb +0 -9
- data/lib/matchers/document.rb +0 -173
- data/lib/matchers/indexes.rb +0 -69
- data/lib/matchers/validations/with_message.rb +0 -27
- data/lib/mongoid-rspec/version.rb +0 -5
- data/mongoid-rspec.gemspec +0 -25
- data/spec/unit/collections_spec.rb +0 -7
- data/spec/unit/indexes_spec.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c59448b4e72ebb718332a28e7ddf77de5b792a09ea273b75959930e2c6c2918
|
4
|
+
data.tar.gz: b1818ed7a513db7a4e31bcdd5a492504a75becfc866dd95505192da1db7a56cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 995c284d71146d52d554e8eff18e48605e76546ebce9428674d1fcefe4c560a73973651f4eb4496d21a839fb35944c37f98cc21eb78ddd1e1eea80a57d1392c4
|
7
|
+
data.tar.gz: a2e400ead572f31c614a294f1d5d10116e08fa6f152b2f58cf112da45608a3d72be2c5893ceb035c8a6f514af8ef55bcfdffd0a55a81a2e0f97ad43fd0699cf2
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,47 +1,219 @@
|
|
1
|
-
# mongoid-rspec
|
1
|
+
# [mongoid-rspec](https://github.com/mongoid/mongoid-rspec "A collection of RSpec-compatible matchers that help to test Mongoid documents.")
|
2
2
|
|
3
|
-
[![Build Status]
|
4
|
-
[![Gem Version]
|
5
|
-
[![Code Climate][codeclimate_badge]][codeclimate]
|
3
|
+
[![Build Status](https://travis-ci.org/mongoid/mongoid-rspec.svg?branch=master)](https://travis-ci.org/mongoid/mongoid-rspec)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/mongoid-rspec.svg)](https://badge.fury.io/rb/mongoid-rspec)
|
6
5
|
|
7
|
-
mongoid-rspec provides a collection of RSpec-compatible matchers that help to test
|
6
|
+
The mongoid-rspec library provides a collection of RSpec-compatible matchers that help to test Mongoid documents.
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
11
|
-
|
10
|
+
Drop this line into your Gemfile:
|
12
11
|
|
13
|
-
|
12
|
+
```ruby
|
13
|
+
group :test do
|
14
|
+
gem 'mongoid-rspec'
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
```
|
16
18
|
|
17
|
-
|
19
|
+
## Compatibility
|
18
20
|
|
19
|
-
|
21
|
+
This gem is compatible with Mongoid 3, 4, 5, 6 and 7.
|
20
22
|
|
21
|
-
|
23
|
+
## Configuration
|
22
24
|
|
23
|
-
###
|
25
|
+
### Rails
|
24
26
|
|
25
|
-
|
27
|
+
Add to your `rails_helper.rb` file
|
26
28
|
|
27
|
-
|
29
|
+
```ruby
|
30
|
+
require 'mongoid-rspec'
|
28
31
|
|
29
|
-
|
32
|
+
RSpec.configure do |config|
|
33
|
+
config.include Mongoid::Matchers, type: :model
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
### Other
|
30
38
|
|
31
|
-
|
32
|
-
i.e: `spec/support/mongoid.rb`
|
39
|
+
Add to your `spec_helper.rb` file.
|
33
40
|
|
34
41
|
```ruby
|
42
|
+
require 'mongoid-rspec'
|
43
|
+
|
35
44
|
RSpec.configure do |config|
|
36
|
-
config.include Mongoid::Matchers
|
45
|
+
config.include Mongoid::Matchers
|
37
46
|
end
|
38
47
|
```
|
39
48
|
|
40
|
-
If you aren't using rails then you don't have to specify the type.
|
41
|
-
If you want to know why visit [the rspec documentation](https://relishapp.com/rspec/rspec-rails/docs/directory-structure).
|
42
|
-
|
43
49
|
## Matchers
|
44
50
|
|
51
|
+
### be_mongoid_document
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class Post
|
55
|
+
include Mongoid::Document
|
56
|
+
end
|
57
|
+
|
58
|
+
RSpec.describe Post, type: :model do
|
59
|
+
it { is_expected.to be_mongoid_document }
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
### be_dynamic_document
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class User
|
67
|
+
include Mongoid::Document
|
68
|
+
include Mongoid::Attributes::Dynamic
|
69
|
+
end
|
70
|
+
|
71
|
+
RSpec.describe User, type: :model do
|
72
|
+
it { is_expected.to be_dynamic_document }
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
### have_timestamps
|
77
|
+
|
78
|
+
With full timestamps.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class Log
|
82
|
+
include Mongoid::Document
|
83
|
+
include Mongoid::Timestamps
|
84
|
+
end
|
85
|
+
|
86
|
+
RSpec.describe Log, type: :model do
|
87
|
+
it { is_expected.to have_timestamps }
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
With short timestamps.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class User
|
95
|
+
include Mongoid::Document
|
96
|
+
include Mongoid::Timestamps::Short
|
97
|
+
end
|
98
|
+
|
99
|
+
RSpec.describe User, type: :model do
|
100
|
+
it { is_expected.to have_timestamps.shortened }
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
With only creating or updating timestamps.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
class Admin
|
108
|
+
include Mongoid::Document
|
109
|
+
include Mongoid::Timestamps::Create
|
110
|
+
include Mongoid::Timestamps::Update
|
111
|
+
end
|
112
|
+
|
113
|
+
RSpec.describe Admin, type: :model do
|
114
|
+
it { is_expected.to have_timestamps.for(:creating) }
|
115
|
+
it { is_expected.to have_timestamps.for(:updating) }
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
With short creating or updating timestamps.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
class Post
|
123
|
+
include Mongoid::Document
|
124
|
+
include Mongoid::Timestamps::Create::Short
|
125
|
+
end
|
126
|
+
|
127
|
+
RSpec.describe Short, type: :model do
|
128
|
+
it { is_expected.to have_timestamps.for(:creating).shortened }
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
### be_stored_in
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
class Post
|
136
|
+
include Mongoid::Document
|
137
|
+
|
138
|
+
store_in database: 'db1', collection: 'messages', client: 'secondary'
|
139
|
+
end
|
140
|
+
|
141
|
+
RSpec.describe Post, type: :model do
|
142
|
+
it { is_expected.to be_stored_in(database: 'db1', collection: 'messages', client: 'secondary') }
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
It checks only those options, that you specify. For instance, test in example below will pass, even though expectation contains only `database` option.
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
class Comment
|
150
|
+
include Mongoid::Document
|
151
|
+
|
152
|
+
store_in database: 'db2', collection: 'messages'
|
153
|
+
end
|
154
|
+
|
155
|
+
RSpec.describe Comment, type: :model do
|
156
|
+
it { is_expected.to be_stored_in(database: 'db2') }
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
It works fine with lambdas and procs.
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
class User
|
164
|
+
include Mongoid::Document
|
165
|
+
|
166
|
+
store_in database: ->{ Thread.current[:database] }
|
167
|
+
end
|
168
|
+
|
169
|
+
RSpec.describe Post, type: :model do
|
170
|
+
it do
|
171
|
+
Thread.current[:database] = 'db3'
|
172
|
+
is_expected.to be_stored_in(database: 'db3')
|
173
|
+
|
174
|
+
Thread.current[:database] = 'db4'
|
175
|
+
is_expected.to be_stored_in(database: 'db4')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
```
|
179
|
+
|
180
|
+
### have_index_for
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
class Article
|
184
|
+
index({ title: 1 }, { unique: true, background: true, drop_dups: true })
|
185
|
+
index({ title: 1, created_at: -1 })
|
186
|
+
index({ category: 1 })
|
187
|
+
end
|
188
|
+
|
189
|
+
RSpec.describe Article, type: :model do
|
190
|
+
it do
|
191
|
+
is_expected
|
192
|
+
.to have_index_for(title: 1)
|
193
|
+
.with_options(unique: true, background: true, drop_dups: true)
|
194
|
+
end
|
195
|
+
it { is_expected.to have_index_for(title: 1, created_at: -1) }
|
196
|
+
it { is_expected.to have_index_for(category: 1) }
|
197
|
+
end
|
198
|
+
```
|
199
|
+
|
200
|
+
### Field Matchers
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
RSpec.describe Article do
|
204
|
+
it { is_expected.to have_field(:published).of_type(Boolean).with_default_value_of(false) }
|
205
|
+
it { is_expected.to have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
|
206
|
+
it { is_expected.not_to have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
|
207
|
+
it { is_expected.not_to have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
|
208
|
+
end
|
209
|
+
|
210
|
+
RSpec.describe User do
|
211
|
+
it { is_expected.to have_fields(:email, :login) }
|
212
|
+
it { is_expected.to have_field(:s).with_alias(:status) }
|
213
|
+
it { is_expected.to have_fields(:birthdate, :registered_at).of_type(DateTime) }
|
214
|
+
end
|
215
|
+
```
|
216
|
+
|
45
217
|
### Association Matchers
|
46
218
|
|
47
219
|
```ruby
|
@@ -49,14 +221,16 @@ RSpec.describe User do
|
|
49
221
|
it { is_expected.to have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
50
222
|
|
51
223
|
it { is_expected.to have_one(:record) }
|
52
|
-
|
224
|
+
|
225
|
+
# can verify autobuild is set to true
|
53
226
|
it { is_expected.to have_one(:record).with_autobuild }
|
54
227
|
|
55
228
|
it { is_expected.to have_many :comments }
|
56
229
|
|
57
|
-
#can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
|
230
|
+
# can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
|
58
231
|
it { is_expected.to have_many(:comments).with_dependent(:destroy) }
|
59
|
-
|
232
|
+
|
233
|
+
# can verify autosave is set to true
|
60
234
|
it { is_expected.to have_many(:comments).with_autosave }
|
61
235
|
|
62
236
|
it { is_expected.to embed_one :profile }
|
@@ -87,20 +261,9 @@ end
|
|
87
261
|
RSpec.describe Site do
|
88
262
|
it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.asc).with_counter_cache }
|
89
263
|
end
|
90
|
-
```
|
91
|
-
|
92
|
-
### Mass Assignment Matcher
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
RSpec.describe User do
|
96
|
-
it { is_expected.to allow_mass_assignment_of(:login) }
|
97
|
-
it { is_expected.to allow_mass_assignment_of(:email) }
|
98
|
-
it { is_expected.to allow_mass_assignment_of(:age) }
|
99
|
-
it { is_expected.to allow_mass_assignment_of(:password) }
|
100
|
-
it { is_expected.to allow_mass_assignment_of(:password) }
|
101
|
-
it { is_expected.to allow_mass_assignment_of(:role).as(:admin) }
|
102
264
|
|
103
|
-
|
265
|
+
RSpec.describe Message do
|
266
|
+
it { is_expected.to belong_to(:user).with_optional }
|
104
267
|
end
|
105
268
|
```
|
106
269
|
|
@@ -131,6 +294,11 @@ end
|
|
131
294
|
|
132
295
|
RSpec.describe Article do
|
133
296
|
it { is_expected.to validate_length_of(:title).within(8..16) }
|
297
|
+
it { is_expected.to validate_absence_of(:deletion_date) }
|
298
|
+
end
|
299
|
+
|
300
|
+
RSpec.describe Visitor do
|
301
|
+
it { is_expected.to validate_length_of(:name).with_maximum(160).with_minimum(1) }
|
134
302
|
end
|
135
303
|
|
136
304
|
RSpec.describe Profile do
|
@@ -149,88 +317,40 @@ RSpec.describe Person do
|
|
149
317
|
end
|
150
318
|
```
|
151
319
|
|
152
|
-
###
|
320
|
+
### Mass Assignment Matcher
|
153
321
|
|
154
322
|
```ruby
|
155
323
|
RSpec.describe User do
|
156
|
-
it { is_expected.to
|
157
|
-
it { is_expected.to
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
it { is_expected.to
|
162
|
-
end
|
163
|
-
```
|
164
|
-
|
165
|
-
### Index Matcher
|
166
|
-
|
167
|
-
```ruby
|
168
|
-
RSpec.describe Article do
|
169
|
-
it { is_expected.to have_index_for(published: 1) }
|
170
|
-
it { is_expected.to have_index_for(title: 1).with_options(unique: true, background: true) }
|
171
|
-
end
|
172
|
-
|
173
|
-
RSpec.describe Profile do
|
174
|
-
it { is_expected.to have_index_for(first_name: 1, last_name: 1) }
|
175
|
-
end
|
324
|
+
it { is_expected.to allow_mass_assignment_of(:login) }
|
325
|
+
it { is_expected.to allow_mass_assignment_of(:email) }
|
326
|
+
it { is_expected.to allow_mass_assignment_of(:age) }
|
327
|
+
it { is_expected.to allow_mass_assignment_of(:password) }
|
328
|
+
it { is_expected.to allow_mass_assignment_of(:password) }
|
329
|
+
it { is_expected.to allow_mass_assignment_of(:role).as(:admin) }
|
176
330
|
|
177
|
-
|
178
|
-
it { is_expected.to have_index_for(created_at: 1).with_options(bucket_size: 100, expire_after_seconds: 3600) }
|
331
|
+
it { is_expected.not_to allow_mass_assignment_of(:role) }
|
179
332
|
end
|
180
333
|
```
|
181
334
|
|
182
|
-
###
|
335
|
+
### Accepts Nested Attributes Matcher
|
183
336
|
|
184
337
|
```ruby
|
185
338
|
RSpec.describe User do
|
186
|
-
it { is_expected.to
|
187
|
-
it { is_expected.to
|
188
|
-
it { is_expected.to have_fields(:birthdate, :registered_at).of_type(DateTime) }
|
189
|
-
|
190
|
-
# if you're declaring 'include Mongoid::Timestamps'
|
191
|
-
# or any of 'include Mongoid::Timestamps::Created' and 'Mongoid::Timestamps::Updated'
|
192
|
-
it { is_expected.to be_timestamped_document }
|
193
|
-
it { is_expected.to be_timestamped_document.with(:created) }
|
194
|
-
it { is_expected.not_to be_timestamped_document.with(:updated) }
|
195
|
-
|
196
|
-
it { is_expected.to be_versioned_document } # if you're declaring `include Mongoid::Versioning`
|
197
|
-
it { is_expected.to be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
|
198
|
-
it { is_expected.to be_multiparameted_document } # if you're declaring `include Mongoid::MultiParameterAttributes`
|
199
|
-
end
|
200
|
-
|
201
|
-
RSpec.describe Log do
|
202
|
-
it { is_expected.to be_stored_in :logs }
|
203
|
-
it { is_expected.to be_dynamic_document }
|
339
|
+
it { is_expected.to accept_nested_attributes_for(:articles) }
|
340
|
+
it { is_expected.to accept_nested_attributes_for(:comments) }
|
204
341
|
end
|
205
342
|
|
206
343
|
RSpec.describe Article do
|
207
|
-
it { is_expected.to
|
208
|
-
it { is_expected.to have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
|
209
|
-
it { is_expected.not_to have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
|
210
|
-
it { is_expected.not_to have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
|
344
|
+
it { is_expected.to accept_nested_attributes_for(:permalink) }
|
211
345
|
end
|
212
346
|
```
|
213
347
|
|
214
|
-
##
|
215
|
-
|
216
|
-
accept_nested_attributes_for matcher must test options [issue 91](https://github.com/mongoid-rspec/mongoid-rspec/issues/91).
|
217
|
-
|
218
|
-
## Acknowledgement
|
219
|
-
|
220
|
-
Thanks to [Durran Jordan][durran] for providing the changes necessary to make
|
221
|
-
this compatible with mongoid 2.0.0.rc, and for other [contributors](https://github.com/mongoid-rspec/mongoid-rspec/contributors)
|
222
|
-
to this project.
|
348
|
+
## Contributing
|
223
349
|
|
224
|
-
[
|
225
|
-
[mongoid2]: http://rubygems.org/gems/mongoid-rspec/versions/1.4.5
|
226
|
-
[mongoid3]: http://rubygems.org/gems/mongoid-rspec/versions/1.13.0
|
227
|
-
[mongoid4]: http://rubygems.org/gems/mongoid-rspec/versions/2.0.0
|
350
|
+
You're encouraged to contribute to this library. See [CONTRIBUTING](CONTRIBUTING.md) for details.
|
228
351
|
|
229
|
-
|
230
|
-
[travis]: https://travis-ci.org/mongoid-rspec/mongoid-rspec
|
352
|
+
## Copyright and License
|
231
353
|
|
232
|
-
|
233
|
-
[rubygems]: http://rubygems.org/gems/mongoid-rspec
|
354
|
+
Copyright (c) 2009-2018 Evan Sagge and Contributors.
|
234
355
|
|
235
|
-
[
|
236
|
-
[codeclimate]: https://codeclimate.com/github/mongoid-rspec/mongoid-rspec
|
356
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
data/Rakefile
CHANGED
@@ -1,17 +1,20 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
2
|
|
3
3
|
require 'bundler'
|
4
4
|
Bundler::GemHelper.install_tasks
|
5
5
|
|
6
6
|
require 'rspec/core/rake_task'
|
7
7
|
|
8
|
-
task :default => :spec
|
9
|
-
|
10
8
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
-
spec.pattern =
|
9
|
+
spec.pattern = './spec/**/*_spec.rb'
|
12
10
|
end
|
13
11
|
|
14
12
|
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
15
|
-
spec.pattern =
|
13
|
+
spec.pattern = './spec/**/*_spec.rb'
|
16
14
|
spec.rcov = true
|
17
15
|
end
|
16
|
+
|
17
|
+
require 'rubocop/rake_task'
|
18
|
+
RuboCop::RakeTask.new(:rubocop)
|
19
|
+
|
20
|
+
task default: %i[rubocop spec]
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Matchers # :nodoc:
|
3
|
-
|
4
3
|
# Ensures that the model can accept nested attributes for the specified
|
5
4
|
# association.
|
6
5
|
#
|
@@ -12,7 +11,6 @@ module Mongoid
|
|
12
11
|
end
|
13
12
|
|
14
13
|
class AcceptNestedAttributesForMatcher
|
15
|
-
|
16
14
|
def initialize(attribute)
|
17
15
|
@attribute = attribute.to_s
|
18
16
|
@options = {}
|
@@ -31,37 +29,38 @@ module Mongoid
|
|
31
29
|
"Did not expect #{expectation}"
|
32
30
|
end
|
33
31
|
|
34
|
-
alias
|
32
|
+
alias failure_message_when_negated negative_failure_message
|
35
33
|
|
36
34
|
def description
|
37
35
|
description = "accepts_nested_attributes_for :#{@attribute}"
|
38
36
|
end
|
39
37
|
|
40
38
|
protected
|
41
|
-
def match?
|
42
|
-
exists?
|
43
|
-
end
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
else
|
49
|
-
@problem = 'is not declared'
|
50
|
-
false
|
51
|
-
end
|
52
|
-
end
|
40
|
+
def match?
|
41
|
+
exists?
|
42
|
+
end
|
53
43
|
|
54
|
-
|
55
|
-
|
44
|
+
def exists?
|
45
|
+
if config
|
46
|
+
true
|
47
|
+
else
|
48
|
+
@problem = 'is not declared'
|
49
|
+
false
|
56
50
|
end
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
def config
|
54
|
+
model_class.nested_attributes["#{@attribute}_attributes"]
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
def model_class
|
58
|
+
@subject.class
|
59
|
+
end
|
60
|
+
|
61
|
+
def expectation
|
62
|
+
"#{model_class.name} to accept nested attributes for #{@attribute}"
|
63
|
+
end
|
65
64
|
end
|
66
65
|
end
|
67
|
-
end
|
66
|
+
end
|