mongoid-rspec 2.0.0 → 2.1.0
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.
- checksums.yaml +4 -4
- data/README.md +101 -93
- data/lib/matchers/associations.rb +15 -0
- data/lib/matchers/document.rb +10 -0
- data/lib/matchers/indexes.rb +14 -29
- data/lib/mongoid-rspec/version.rb +1 -1
- data/spec/models/log.rb +6 -1
- data/spec/models/site.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/accept_nested_attributes_spec.rb +5 -5
- data/spec/unit/associations_spec.rb +15 -15
- data/spec/unit/collections_spec.rb +3 -3
- data/spec/unit/document_spec.rb +18 -13
- data/spec/unit/indexes_spec.rb +10 -6
- data/spec/unit/validations_spec.rb +32 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 644aca9f2b61c8979ce8eb90856a3d7db324e506
|
4
|
+
data.tar.gz: 8f428ac11869473c94207866056850ceb113246a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb156c8186d891023ed5b423635aef4c673b150728372648cec95de064c72bc7fea35007ea1895d4002f880d787779dddcd9be0ce6304b68dfcdf0554a8aa8d6
|
7
|
+
data.tar.gz: 83b4e63454cc912622c081fc67b0ff0185bb4b612676ad9ec2e7c7240d39f066fa94fe023066a968ca3c848ac21df4dcfd84c6b29c595894ecb7e35dc716f2e6
|
data/README.md
CHANGED
@@ -10,19 +10,19 @@ mongoid-rspec provides a collection of RSpec-compatible matchers that help to te
|
|
10
10
|
|
11
11
|
### With Mongoid 4.x
|
12
12
|
|
13
|
-
Use mongoid-rspec [2.
|
13
|
+
Use mongoid-rspec [2.1.0][mongoid4]
|
14
14
|
|
15
|
-
gem 'mongoid-rspec', '~> 2.
|
15
|
+
gem 'mongoid-rspec', '~> 2.1.0'
|
16
16
|
|
17
17
|
### With Mongoid 3.x
|
18
18
|
|
19
|
-
Use mongoid-rspec [1.
|
19
|
+
Use mongoid-rspec [1.13.0][mongoid3].
|
20
20
|
|
21
|
-
gem 'mongoid-rspec', '~> 1.
|
21
|
+
gem 'mongoid-rspec', '~> 1.13.0'
|
22
22
|
|
23
23
|
### With Mongoid 2.x
|
24
24
|
|
25
|
-
Use mongoid-rspec [1.4.5][
|
25
|
+
Use mongoid-rspec [1.4.5][mongoid2]
|
26
26
|
|
27
27
|
gem 'mongoid-rspec', '1.4.5'
|
28
28
|
|
@@ -37,169 +37,177 @@ RSpec.configure do |config|
|
|
37
37
|
end
|
38
38
|
```
|
39
39
|
|
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
|
+
|
40
43
|
## Matchers
|
41
44
|
|
42
45
|
### Association Matchers
|
43
46
|
|
44
47
|
```ruby
|
45
|
-
describe User do
|
46
|
-
it {
|
48
|
+
RSpec.describe User do
|
49
|
+
it { is_expected.to have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
47
50
|
|
48
|
-
it {
|
51
|
+
it { is_expected.to have_one(:record) }
|
49
52
|
#can verify autobuild is set to true
|
50
|
-
it {
|
53
|
+
it { is_expected.to have_one(:record).with_autobuild }
|
51
54
|
|
52
|
-
it {
|
55
|
+
it { is_expected.to have_many :comments }
|
53
56
|
|
54
57
|
#can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
|
55
|
-
it {
|
58
|
+
it { is_expected.to have_many(:comments).with_dependent(:destroy) }
|
56
59
|
#can verify autosave is set to true
|
57
|
-
it {
|
60
|
+
it { is_expected.to have_many(:comments).with_autosave }
|
58
61
|
|
59
|
-
it {
|
62
|
+
it { is_expected.to embed_one :profile }
|
60
63
|
|
61
|
-
it {
|
62
|
-
it {
|
64
|
+
it { is_expected.to have_and_belong_to_many(:children) }
|
65
|
+
it { is_expected.to have_and_belong_to_many(:children).of_type(User) }
|
63
66
|
end
|
64
67
|
|
65
|
-
describe Profile do
|
66
|
-
it {
|
68
|
+
RSpec.describe Profile do
|
69
|
+
it { is_expected.to be_embedded_in(:user).as_inverse_of(:profile) }
|
67
70
|
end
|
68
71
|
|
69
|
-
describe Article do
|
70
|
-
it {
|
71
|
-
it {
|
72
|
-
it {
|
72
|
+
RSpec.describe Article do
|
73
|
+
it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles) }
|
74
|
+
it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
|
75
|
+
it { is_expected.to embed_many(:comments) }
|
73
76
|
end
|
74
77
|
|
75
|
-
describe Comment do
|
76
|
-
it {
|
77
|
-
it {
|
78
|
+
RSpec.describe Comment do
|
79
|
+
it { is_expected.to be_embedded_in(:article).as_inverse_of(:comments) }
|
80
|
+
it { is_expected.to belong_to(:user).as_inverse_of(:comments) }
|
78
81
|
end
|
79
82
|
|
80
|
-
describe Record do
|
81
|
-
it {
|
83
|
+
RSpec.describe Record do
|
84
|
+
it { is_expected.to belong_to(:user).as_inverse_of(:record) }
|
82
85
|
end
|
83
86
|
|
84
|
-
describe Site do
|
85
|
-
it {
|
87
|
+
RSpec.describe Site do
|
88
|
+
it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.asc).with_counter_cache }
|
86
89
|
end
|
87
90
|
```
|
88
91
|
|
89
92
|
### Mass Assignment Matcher
|
90
93
|
|
91
94
|
```ruby
|
92
|
-
describe User do
|
93
|
-
it {
|
94
|
-
it {
|
95
|
-
it {
|
96
|
-
it {
|
97
|
-
it {
|
98
|
-
it {
|
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) }
|
99
102
|
|
100
|
-
it {
|
103
|
+
it { is_expected.not_to allow_mass_assignment_of(:role) }
|
101
104
|
end
|
102
105
|
```
|
103
106
|
|
104
107
|
### Validation Matchers
|
105
108
|
|
106
109
|
```ruby
|
107
|
-
describe Site do
|
108
|
-
it {
|
109
|
-
it {
|
110
|
+
RSpec.describe Site do
|
111
|
+
it { is_expected.to validate_presence_of(:name) }
|
112
|
+
it { is_expected.to validate_uniqueness_of(:name) }
|
110
113
|
end
|
111
114
|
|
112
|
-
describe User do
|
113
|
-
it {
|
114
|
-
it {
|
115
|
-
it {
|
116
|
-
it {
|
117
|
-
it {
|
118
|
-
it {
|
119
|
-
it {
|
120
|
-
it {
|
121
|
-
it {
|
122
|
-
it {
|
123
|
-
it {
|
124
|
-
it {
|
125
|
-
it {
|
126
|
-
it {
|
115
|
+
RSpec.describe User do
|
116
|
+
it { is_expected.to validate_presence_of(:login) }
|
117
|
+
it { is_expected.to validate_uniqueness_of(:login).scoped_to(:site) }
|
118
|
+
it { is_expected.to validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
|
119
|
+
it { is_expected.to validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
|
120
|
+
it { is_expected.to validate_associated(:profile) }
|
121
|
+
it { is_expected.to validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
|
122
|
+
it { is_expected.to validate_inclusion_of(:role).to_allow("admin", "member") }
|
123
|
+
it { is_expected.to validate_confirmation_of(:email) }
|
124
|
+
it { is_expected.to validate_presence_of(:age).on(:create, :update) }
|
125
|
+
it { is_expected.to validate_numericality_of(:age).on(:create, :update) }
|
126
|
+
it { is_expected.to validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
|
127
|
+
it { is_expected.to validate_presence_of(:password).on(:create) }
|
128
|
+
it { is_expected.to validate_presence_of(:provider_uid).on(:create) }
|
129
|
+
it { is_expected.to validate_inclusion_of(:locale).to_allow([:en, :ru]) }
|
127
130
|
end
|
128
131
|
|
129
|
-
describe Article do
|
130
|
-
it {
|
132
|
+
RSpec.describe Article do
|
133
|
+
it { is_expected.to validate_length_of(:title).within(8..16) }
|
131
134
|
end
|
132
135
|
|
133
|
-
describe Profile do
|
134
|
-
it {
|
136
|
+
RSpec.describe Profile do
|
137
|
+
it { is_expected.to validate_numericality_of(:age).greater_than(0) }
|
135
138
|
end
|
136
139
|
|
137
|
-
describe MovieArticle do
|
138
|
-
it {
|
139
|
-
it {
|
140
|
+
RSpec.describe MovieArticle do
|
141
|
+
it { is_expected.to validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
|
142
|
+
it { is_expected.to validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
|
140
143
|
end
|
141
144
|
|
142
|
-
describe Person do
|
145
|
+
RSpec.describe Person do
|
143
146
|
# in order to be able to use the custom_validate matcher, the custom validator class (in this case SsnValidator)
|
144
147
|
# should redefine the kind method to return :custom, i.e. "def self.kind() :custom end"
|
145
|
-
it {
|
148
|
+
it { is_expected.to custom_validate(:ssn).with_validator(SsnValidator) }
|
146
149
|
end
|
147
150
|
```
|
148
151
|
|
149
152
|
### Accepts Nested Attributes Matcher
|
150
153
|
|
151
154
|
```ruby
|
152
|
-
describe User do
|
153
|
-
it {
|
154
|
-
it {
|
155
|
+
RSpec.describe User do
|
156
|
+
it { is_expected.to accept_nested_attributes_for(:articles) }
|
157
|
+
it { is_expected.to accept_nested_attributes_for(:comments) }
|
155
158
|
end
|
156
159
|
|
157
|
-
describe Article do
|
158
|
-
it {
|
160
|
+
RSpec.describe Article do
|
161
|
+
it { is_expected.to accept_nested_attributes_for(:permalink) }
|
159
162
|
end
|
160
163
|
```
|
161
164
|
|
162
165
|
### Index Matcher
|
163
166
|
|
164
167
|
```ruby
|
165
|
-
describe Article do
|
166
|
-
it {
|
167
|
-
it {
|
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) }
|
168
175
|
end
|
169
176
|
|
170
|
-
describe
|
171
|
-
it {
|
177
|
+
Rspec.describe Log do
|
178
|
+
it { is_expected.to have_index_for(created_at: 1).with_options(bucket_size: 100, expire_after_seconds: 3600) }
|
172
179
|
end
|
173
180
|
```
|
174
181
|
|
175
182
|
### Others
|
176
183
|
|
177
184
|
```ruby
|
178
|
-
describe User do
|
179
|
-
it {
|
180
|
-
it {
|
181
|
-
it {
|
185
|
+
RSpec.describe User do
|
186
|
+
it { is_expected.to have_fields(:email, :login) }
|
187
|
+
it { is_expected.to have_field(:s).with_alias(:status) }
|
188
|
+
it { is_expected.to have_fields(:birthdate, :registered_at).of_type(DateTime) }
|
182
189
|
|
183
190
|
# if you're declaring 'include Mongoid::Timestamps'
|
184
191
|
# or any of 'include Mongoid::Timestamps::Created' and 'Mongoid::Timestamps::Updated'
|
185
|
-
it {
|
186
|
-
it {
|
187
|
-
it {
|
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) }
|
188
195
|
|
189
|
-
it {
|
190
|
-
it {
|
191
|
-
it {
|
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`
|
192
199
|
end
|
193
200
|
|
194
|
-
describe Log do
|
195
|
-
it {
|
201
|
+
RSpec.describe Log do
|
202
|
+
it { is_expected.to be_stored_in :logs }
|
203
|
+
it { is_expected.to be_dynamic_document }
|
196
204
|
end
|
197
205
|
|
198
|
-
describe Article do
|
199
|
-
it {
|
200
|
-
it {
|
201
|
-
it {
|
202
|
-
it {
|
206
|
+
RSpec.describe Article do
|
207
|
+
it { is_expected.to have_field(:published).of_type(Boolean).with_default_value_of(false) }
|
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) }
|
203
211
|
end
|
204
212
|
```
|
205
213
|
|
@@ -214,9 +222,9 @@ this compatible with mongoid 2.0.0.rc, and for other [contributors](https://gith
|
|
214
222
|
to this project.
|
215
223
|
|
216
224
|
[durran]: https://github.com/durran
|
217
|
-
[
|
218
|
-
[
|
219
|
-
[
|
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
|
220
228
|
|
221
229
|
[travis_badge]: http://img.shields.io/travis/mongoid-rspec/mongoid-rspec.svg?style=flat
|
222
230
|
[travis]: https://travis-ci.org/mongoid-rspec/mongoid-rspec
|
@@ -101,6 +101,12 @@ module Mongoid
|
|
101
101
|
self
|
102
102
|
end
|
103
103
|
|
104
|
+
def with_counter_cache
|
105
|
+
@association[:counter_cache] = true
|
106
|
+
@expectation_message << " which specifies counter_cache as #{@association[:counter_cache].to_s}"
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
104
110
|
def matches?(actual)
|
105
111
|
@actual = actual.is_a?(Class) ? actual : actual.class
|
106
112
|
metadata = @actual.relations[@association[:name]]
|
@@ -235,6 +241,15 @@ module Mongoid
|
|
235
241
|
end
|
236
242
|
end
|
237
243
|
|
244
|
+
if @association[:counter_cache]
|
245
|
+
if metadata.counter_cached? != true
|
246
|
+
@negative_result_message = "#{@positive_result_message} which did not set counter_cache"
|
247
|
+
return false
|
248
|
+
else
|
249
|
+
@positive_result_message = "#{@positive_result_message} which set counter_cache"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
238
253
|
return true
|
239
254
|
end
|
240
255
|
|
data/lib/matchers/document.rb
CHANGED
@@ -161,3 +161,13 @@ RSpec::Matchers.define :be_multiparameted_document do
|
|
161
161
|
"be a multiparameted Mongoid document"
|
162
162
|
end
|
163
163
|
end
|
164
|
+
|
165
|
+
RSpec::Matchers.define :be_dynamic_document do |_|
|
166
|
+
match do |doc|
|
167
|
+
doc.class.included_modules.include?(Mongoid::Attributes::Dynamic)
|
168
|
+
end
|
169
|
+
|
170
|
+
description do
|
171
|
+
'be a Mongoid document with dynamic attributes'
|
172
|
+
end
|
173
|
+
end
|
data/lib/matchers/indexes.rb
CHANGED
@@ -14,33 +14,18 @@ module Mongoid
|
|
14
14
|
@klass = klass.is_a?(Class) ? klass : klass.class
|
15
15
|
@errors = []
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if denormalising_options(@klass.index_options[@index_fields])[option] != option_value
|
25
|
-
@errors.push "index for #{@index_fields.inspect} with options of #{@klass.index_options[@index_fields].inspect}"
|
26
|
-
end
|
17
|
+
index_specifications = @klass.index_specifications.find { |is| is.key == @index_fields }
|
18
|
+
if index_specifications
|
19
|
+
if !@options.nil? && !@options.empty?
|
20
|
+
index_options = normalize_options(index_specifications.options)
|
21
|
+
@options.each do |option, option_value|
|
22
|
+
if index_options[option] != option_value
|
23
|
+
@errors.push "index for #{@index_fields.inspect} with options of #{index_options.inspect}"
|
27
24
|
end
|
28
25
|
end
|
29
26
|
end
|
30
27
|
else
|
31
|
-
|
32
|
-
unless @klass.index_specifications.map(&:key).include?(@index_fields)
|
33
|
-
@errors.push "no index for #{@index_fields}"
|
34
|
-
else
|
35
|
-
if !@options.nil? && !@options.empty?
|
36
|
-
index_options = @klass.index_specifications.select { |is| is.key == @index_fields }.first.options
|
37
|
-
@options.each do |option, option_value|
|
38
|
-
if index_options[option] != option_value
|
39
|
-
@errors.push "index for #{@index_fields.inspect} with options of #{index_options.inspect}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
28
|
+
@errors.push "no index for #{@index_fields}"
|
44
29
|
end
|
45
30
|
|
46
31
|
@errors.empty?
|
@@ -65,15 +50,15 @@ module Mongoid
|
|
65
50
|
|
66
51
|
private
|
67
52
|
MAPPINGS = {
|
68
|
-
dropDups: :drop_dups
|
53
|
+
dropDups: :drop_dups,
|
54
|
+
expireAfterSeconds: :expire_after_seconds,
|
55
|
+
bucketSize: :bucket_size
|
69
56
|
}
|
70
57
|
|
71
|
-
def
|
72
|
-
options
|
73
|
-
|
74
|
-
options[MAPPINGS[option] || option] = value
|
58
|
+
def normalize_options(options)
|
59
|
+
options.transform_keys do |key|
|
60
|
+
MAPPINGS[key] || key
|
75
61
|
end
|
76
|
-
options
|
77
62
|
end
|
78
63
|
end
|
79
64
|
|
data/spec/models/log.rb
CHANGED
data/spec/models/site.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "AcceptsNestedAttributes" do
|
3
|
+
RSpec.describe "AcceptsNestedAttributes" do
|
4
4
|
describe User do
|
5
|
-
it {
|
6
|
-
it {
|
5
|
+
it { is_expected.to accept_nested_attributes_for(:articles) }
|
6
|
+
it { is_expected.to accept_nested_attributes_for(:comments) }
|
7
7
|
end
|
8
8
|
|
9
9
|
describe Article do
|
10
|
-
it {
|
10
|
+
it { is_expected.to accept_nested_attributes_for(:permalink) }
|
11
11
|
end
|
12
|
-
end
|
12
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Associations" do
|
3
|
+
RSpec.describe "Associations" do
|
4
4
|
describe User do
|
5
|
-
it {
|
5
|
+
it { is_expected.to have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
6
6
|
|
7
|
-
it {
|
7
|
+
it { is_expected.to have_one(:record).with_autobuild }
|
8
8
|
|
9
|
-
it {
|
9
|
+
it { is_expected.to have_many(:comments).with_dependent(:destroy).with_autosave }
|
10
10
|
|
11
|
-
it {
|
11
|
+
it { is_expected.to embed_one(:profile) }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to have_and_belong_to_many(:children).of_type(User) }
|
14
14
|
end
|
15
15
|
|
16
16
|
describe Profile do
|
17
|
-
it {
|
17
|
+
it { is_expected.to be_embedded_in(:user).as_inverse_of(:profile) }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe Article do
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
21
|
+
it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
|
22
|
+
it { is_expected.to embed_many(:comments).with_cascading_callbacks }
|
23
|
+
it { is_expected.to embed_one(:permalink) }
|
24
24
|
end
|
25
25
|
|
26
26
|
describe Comment do
|
27
|
-
it {
|
28
|
-
it {
|
27
|
+
it { is_expected.to be_embedded_in(:article).as_inverse_of(:comments).with_polymorphism }
|
28
|
+
it { is_expected.to belong_to(:user).as_inverse_of(:comments) }
|
29
29
|
end
|
30
30
|
|
31
31
|
describe Record do
|
32
|
-
it {
|
32
|
+
it { is_expected.to belong_to(:user).as_inverse_of(:record) }
|
33
33
|
end
|
34
34
|
|
35
35
|
describe Permalink do
|
36
|
-
it {
|
36
|
+
it { is_expected.to be_embedded_in(:linkable).as_inverse_of(:link) }
|
37
37
|
end
|
38
38
|
|
39
39
|
describe Site do
|
40
|
-
it {
|
40
|
+
it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.desc).with_counter_cache }
|
41
41
|
end
|
42
42
|
end
|
data/spec/unit/document_spec.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Document" do
|
3
|
+
RSpec.describe "Document" do
|
4
4
|
describe User do
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
8
|
-
it {
|
5
|
+
it { is_expected.to have_fields(:email, :login) }
|
6
|
+
it { is_expected.to be_timestamped_document }
|
7
|
+
it { is_expected.to be_timestamped_document.with(:created) }
|
8
|
+
it { is_expected.not_to be_timestamped_document.with(:updated) }
|
9
9
|
end
|
10
10
|
|
11
11
|
describe Article do
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
12
|
+
it { is_expected.to have_field(:published).of_type(Mongoid::Boolean).with_default_value_of(false) }
|
13
|
+
it { is_expected.to have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(true) }
|
14
|
+
it { is_expected.to belong_to(:author) }
|
15
|
+
it { is_expected.to have_field(:title).localized }
|
16
|
+
it { is_expected.not_to have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(false) }
|
17
|
+
it { is_expected.not_to have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
|
18
|
+
it { is_expected.to be_mongoid_document }
|
19
|
+
it { is_expected.to be_timestamped_document }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Log do
|
23
|
+
it { is_expected.to be_mongoid_document }
|
24
|
+
it { is_expected.to be_dynamic_document }
|
20
25
|
end
|
21
26
|
end
|
data/spec/unit/indexes_spec.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Indexes" do
|
3
|
+
RSpec.describe "Indexes" do
|
4
4
|
describe Article do
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
5
|
+
it { is_expected.to have_index_for(published: 1) }
|
6
|
+
it { is_expected.to have_index_for(title: 1).with_options(unique: true, background: true, drop_dups: true) }
|
7
|
+
it { is_expected.to have_index_for('permalink._id' => 1) }
|
8
8
|
end
|
9
9
|
|
10
10
|
describe Profile do
|
11
|
-
it {
|
11
|
+
it { is_expected.to have_index_for(first_name: 1, last_name: 1) }
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
|
+
describe Log do
|
15
|
+
it { is_expected.to have_index_for(created_at: 1).with_options(bucket_size: 100, expire_after_seconds: 3600) }
|
16
|
+
end
|
17
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Validations" do
|
3
|
+
RSpec.describe "Validations" do
|
4
4
|
describe Site do
|
5
|
-
it {
|
6
|
-
it {
|
5
|
+
it { is_expected.to validate_presence_of(:name) }
|
6
|
+
it { is_expected.to validate_uniqueness_of(:name) }
|
7
7
|
end
|
8
8
|
|
9
9
|
describe User do
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
24
|
-
it {
|
25
|
-
it {
|
10
|
+
it { is_expected.to validate_presence_of(:login) }
|
11
|
+
it { is_expected.to validate_uniqueness_of(:login).scoped_to(:site) }
|
12
|
+
it { is_expected.to validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
|
13
|
+
it { is_expected.to validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
|
14
|
+
it { is_expected.to validate_associated(:profile) }
|
15
|
+
it { is_expected.to validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
|
16
|
+
it { is_expected.to validate_exclusion_of(:password).to_not_allow("password") }
|
17
|
+
it { is_expected.to validate_inclusion_of(:role).to_allow("admin", "member") }
|
18
|
+
it { is_expected.to validate_inclusion_of(:role).to_allow(["admin", "member"]) }
|
19
|
+
it { is_expected.to validate_confirmation_of(:email) }
|
20
|
+
it { is_expected.to validate_presence_of(:age).on(:create, :update) }
|
21
|
+
it { is_expected.to validate_numericality_of(:age).on(:create, :update) }
|
22
|
+
it { is_expected.to validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
|
23
|
+
it { is_expected.to validate_presence_of(:password).on(:create) }
|
24
|
+
it { is_expected.to validate_presence_of(:provider_uid).on(:create) }
|
25
|
+
it { is_expected.to validate_inclusion_of(:locale).to_allow([:en, :ru]) }
|
26
26
|
end
|
27
27
|
|
28
28
|
describe Profile do
|
29
|
-
it {
|
30
|
-
it {
|
31
|
-
it {
|
29
|
+
it { is_expected.to validate_numericality_of(:age).greater_than(0) }
|
30
|
+
it { is_expected.to validate_acceptance_of(:terms_of_service) }
|
31
|
+
it { is_expected.to validate_length_of(:hobbies).with_minimum(1).with_message("requires at least one hobby") }
|
32
32
|
end
|
33
33
|
|
34
34
|
describe Article do
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
35
|
+
it { is_expected.to validate_length_of(:title).within(8..16) }
|
36
|
+
it { is_expected.not_to validate_length_of(:content).greater_than(200).less_than(16) }
|
37
|
+
it { is_expected.to validate_length_of(:content).greater_than(200) }
|
38
|
+
it { is_expected.to validate_inclusion_of(:status).to_allow([:pending]).on( :create ) }
|
39
|
+
it { is_expected.to validate_inclusion_of(:status).to_allow([:approved, :rejected]).on( :update ) }
|
40
40
|
end
|
41
41
|
|
42
42
|
describe MovieArticle do
|
43
|
-
it {
|
44
|
-
it {
|
45
|
-
it {
|
43
|
+
it { is_expected.to validate_numericality_of(:rating).greater_than(0) }
|
44
|
+
it { is_expected.to validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
|
45
|
+
it { is_expected.to validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
|
46
46
|
end
|
47
47
|
|
48
48
|
describe Person do
|
49
|
-
it {
|
50
|
-
it {
|
49
|
+
it { is_expected.to custom_validate(:ssn).with_validator(SsnValidator) }
|
50
|
+
it { is_expected.not_to custom_validate(:name) }
|
51
51
|
end
|
52
52
|
end
|
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Sagge
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01
|
12
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|