mongoid-rspec 3.0.0 → 4.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 +5 -5
- data/LICENSE +1 -1
- data/README.md +220 -109
- 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/absence_of.rb +11 -0
- data/lib/matchers/validations/associated.rb +1 -1
- data/lib/matchers/validations/confirmation_of.rb +0 -7
- 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/matchers/validations.rb +30 -11
- data/lib/mongoid/rspec/version.rb +2 -2
- data/lib/mongoid/rspec.rb +18 -5
- 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 -11
- data/spec/spec_helper.rb +9 -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 -15
- data/spec/validators/ssn_validator.rb +6 -6
- metadata +115 -39
- 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/mongoid-rspec.gemspec +0 -26
- data/spec/unit/collections_spec.rb +0 -7
- data/spec/unit/indexes_spec.rb +0 -17
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:
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Sagge
|
|
@@ -9,38 +9,80 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
15
|
+
name: activesupport
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 3.0.0
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 3.0.0
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: mongoid
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '3.1'
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '3.1'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: mongoid-compatibility
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: 0.5.1
|
|
49
|
+
type: :runtime
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 0.5.1
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rspec-core
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - "~>"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '3.3'
|
|
63
|
+
type: :runtime
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '3.3'
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: rspec-expectations
|
|
30
72
|
requirement: !ruby/object:Gem::Requirement
|
|
31
73
|
requirements:
|
|
32
74
|
- - "~>"
|
|
33
75
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
76
|
+
version: '3.3'
|
|
35
77
|
type: :runtime
|
|
36
78
|
prerelease: false
|
|
37
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
80
|
requirements:
|
|
39
81
|
- - "~>"
|
|
40
82
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '
|
|
83
|
+
version: '3.3'
|
|
42
84
|
- !ruby/object:Gem::Dependency
|
|
43
|
-
name: rspec
|
|
85
|
+
name: rspec-mocks
|
|
44
86
|
requirement: !ruby/object:Gem::Requirement
|
|
45
87
|
requirements:
|
|
46
88
|
- - "~>"
|
|
@@ -53,29 +95,57 @@ dependencies:
|
|
|
53
95
|
- - "~>"
|
|
54
96
|
- !ruby/object:Gem::Version
|
|
55
97
|
version: '3.3'
|
|
98
|
+
- !ruby/object:Gem::Dependency
|
|
99
|
+
name: appraisal
|
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - "~>"
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '2.2'
|
|
105
|
+
type: :development
|
|
106
|
+
prerelease: false
|
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - "~>"
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '2.2'
|
|
112
|
+
- !ruby/object:Gem::Dependency
|
|
113
|
+
name: rake
|
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - "~>"
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '10.0'
|
|
119
|
+
type: :development
|
|
120
|
+
prerelease: false
|
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - "~>"
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '10.0'
|
|
56
126
|
description: RSpec matches for Mongoid models, including association and validation
|
|
57
|
-
matchers
|
|
127
|
+
matchers.
|
|
58
128
|
email: evansagge@gmail.com contato@rodrigopinto.me
|
|
59
129
|
executables: []
|
|
60
130
|
extensions: []
|
|
61
131
|
extra_rdoc_files: []
|
|
62
132
|
files:
|
|
63
|
-
- ".document"
|
|
64
|
-
- ".gitignore"
|
|
65
|
-
- ".ruby-gemset"
|
|
66
|
-
- ".ruby-version"
|
|
67
|
-
- ".travis.yml"
|
|
68
|
-
- Gemfile
|
|
69
133
|
- LICENSE
|
|
70
134
|
- README.md
|
|
71
135
|
- Rakefile
|
|
72
136
|
- lib/matchers/accept_nested_attributes.rb
|
|
73
137
|
- lib/matchers/allow_mass_assignment.rb
|
|
74
138
|
- lib/matchers/associations.rb
|
|
75
|
-
- lib/matchers/
|
|
76
|
-
- lib/matchers/
|
|
77
|
-
- lib/matchers/
|
|
139
|
+
- lib/matchers/be_dynamic_document.rb
|
|
140
|
+
- lib/matchers/be_mongoid_document.rb
|
|
141
|
+
- lib/matchers/be_stored_in.rb
|
|
142
|
+
- lib/matchers/have_field.rb
|
|
143
|
+
- lib/matchers/have_timestamps.rb
|
|
144
|
+
- lib/matchers/indexes/have_index_for.rb
|
|
145
|
+
- lib/matchers/indexes/v3/have_index_for.rb
|
|
146
|
+
- lib/matchers/indexes/v4/have_index_for.rb
|
|
78
147
|
- lib/matchers/validations.rb
|
|
148
|
+
- lib/matchers/validations/absence_of.rb
|
|
79
149
|
- lib/matchers/validations/acceptance_of.rb
|
|
80
150
|
- lib/matchers/validations/associated.rb
|
|
81
151
|
- lib/matchers/validations/confirmation_of.rb
|
|
@@ -87,14 +157,13 @@ files:
|
|
|
87
157
|
- lib/matchers/validations/numericality_of.rb
|
|
88
158
|
- lib/matchers/validations/presence_of.rb
|
|
89
159
|
- lib/matchers/validations/uniqueness_of.rb
|
|
90
|
-
- lib/matchers/validations/with_message.rb
|
|
91
160
|
- lib/mongoid-rspec.rb
|
|
92
161
|
- lib/mongoid/rspec.rb
|
|
93
162
|
- lib/mongoid/rspec/version.rb
|
|
94
|
-
- mongoid-rspec.gemspec
|
|
95
163
|
- spec/models/article.rb
|
|
96
164
|
- spec/models/comment.rb
|
|
97
165
|
- spec/models/log.rb
|
|
166
|
+
- spec/models/message.rb
|
|
98
167
|
- spec/models/movie_article.rb
|
|
99
168
|
- spec/models/permalink.rb
|
|
100
169
|
- spec/models/person.rb
|
|
@@ -105,13 +174,17 @@ files:
|
|
|
105
174
|
- spec/spec_helper.rb
|
|
106
175
|
- spec/unit/accept_nested_attributes_spec.rb
|
|
107
176
|
- spec/unit/associations_spec.rb
|
|
108
|
-
- spec/unit/
|
|
177
|
+
- spec/unit/be_dynamic_document_spec.rb
|
|
178
|
+
- spec/unit/be_mongoid_document_spec.rb
|
|
179
|
+
- spec/unit/be_stored_in.rb
|
|
109
180
|
- spec/unit/document_spec.rb
|
|
110
|
-
- spec/unit/
|
|
181
|
+
- spec/unit/have_index_for_spec.rb
|
|
182
|
+
- spec/unit/have_timestamps_spec.rb
|
|
111
183
|
- spec/unit/validations_spec.rb
|
|
112
184
|
- spec/validators/ssn_validator.rb
|
|
113
185
|
homepage: http://github.com/mongoid-rspec/mongoid-rspec
|
|
114
|
-
licenses:
|
|
186
|
+
licenses:
|
|
187
|
+
- MIT
|
|
115
188
|
metadata: {}
|
|
116
189
|
post_install_message:
|
|
117
190
|
rdoc_options: []
|
|
@@ -121,34 +194,37 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
121
194
|
requirements:
|
|
122
195
|
- - ">="
|
|
123
196
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '
|
|
197
|
+
version: '2.2'
|
|
125
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
199
|
requirements:
|
|
127
200
|
- - ">="
|
|
128
201
|
- !ruby/object:Gem::Version
|
|
129
|
-
version:
|
|
202
|
+
version: 1.3.6
|
|
130
203
|
requirements: []
|
|
131
|
-
|
|
132
|
-
rubygems_version: 2.4.5.1
|
|
204
|
+
rubygems_version: 3.1.3
|
|
133
205
|
signing_key:
|
|
134
206
|
specification_version: 4
|
|
135
207
|
summary: RSpec matchers for Mongoid
|
|
136
208
|
test_files:
|
|
209
|
+
- spec/spec_helper.rb
|
|
210
|
+
- spec/unit/associations_spec.rb
|
|
211
|
+
- spec/unit/be_dynamic_document_spec.rb
|
|
212
|
+
- spec/unit/validations_spec.rb
|
|
213
|
+
- spec/unit/be_stored_in.rb
|
|
214
|
+
- spec/unit/have_index_for_spec.rb
|
|
215
|
+
- spec/unit/accept_nested_attributes_spec.rb
|
|
216
|
+
- spec/unit/document_spec.rb
|
|
217
|
+
- spec/unit/be_mongoid_document_spec.rb
|
|
218
|
+
- spec/unit/have_timestamps_spec.rb
|
|
137
219
|
- spec/models/article.rb
|
|
138
|
-
- spec/models/comment.rb
|
|
139
|
-
- spec/models/log.rb
|
|
140
220
|
- spec/models/movie_article.rb
|
|
141
|
-
- spec/models/permalink.rb
|
|
142
|
-
- spec/models/person.rb
|
|
143
|
-
- spec/models/profile.rb
|
|
144
221
|
- spec/models/record.rb
|
|
145
222
|
- spec/models/site.rb
|
|
223
|
+
- spec/models/message.rb
|
|
224
|
+
- spec/models/permalink.rb
|
|
225
|
+
- spec/models/profile.rb
|
|
226
|
+
- spec/models/comment.rb
|
|
227
|
+
- spec/models/person.rb
|
|
228
|
+
- spec/models/log.rb
|
|
146
229
|
- spec/models/user.rb
|
|
147
|
-
- spec/spec_helper.rb
|
|
148
|
-
- spec/unit/accept_nested_attributes_spec.rb
|
|
149
|
-
- spec/unit/associations_spec.rb
|
|
150
|
-
- spec/unit/collections_spec.rb
|
|
151
|
-
- spec/unit/document_spec.rb
|
|
152
|
-
- spec/unit/indexes_spec.rb
|
|
153
|
-
- spec/unit/validations_spec.rb
|
|
154
230
|
- spec/validators/ssn_validator.rb
|
data/.document
DELETED
data/.gitignore
DELETED
data/.ruby-gemset
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
mongoid-rspec
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.2.3
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/lib/matchers/collections.rb
DELETED
data/lib/matchers/document.rb
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
module Mongoid
|
|
2
|
-
module Matchers
|
|
3
|
-
class HaveFieldMatcher # :nodoc:
|
|
4
|
-
def initialize(*attrs)
|
|
5
|
-
@attributes = attrs.collect(&:to_s)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def localized
|
|
9
|
-
@localized = true
|
|
10
|
-
self
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def of_type(type)
|
|
14
|
-
@type = type
|
|
15
|
-
self
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def with_alias(field_alias)
|
|
19
|
-
@field_alias = field_alias
|
|
20
|
-
self
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def with_default_value_of(default)
|
|
24
|
-
@default = default
|
|
25
|
-
self
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def matches?(klass)
|
|
29
|
-
@klass = klass.is_a?(Class) ? klass : klass.class
|
|
30
|
-
@errors = []
|
|
31
|
-
@attributes.each do |attr|
|
|
32
|
-
if @klass.fields.include?(attr)
|
|
33
|
-
error = ""
|
|
34
|
-
if @type and @klass.fields[attr].type != @type
|
|
35
|
-
error << " of type #{@klass.fields[attr].type}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
if !@default.nil?
|
|
39
|
-
if @klass.fields[attr].default_val.nil?
|
|
40
|
-
error << " with default not set"
|
|
41
|
-
elsif @klass.fields[attr].default_val != @default
|
|
42
|
-
error << " with default value of #{@klass.fields[attr].default_val}"
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
if @field_alias and @klass.fields[attr].options[:as] != @field_alias
|
|
47
|
-
error << " with alias #{@klass.fields[attr].options[:as]}"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
@errors.push("field #{attr.inspect}" << error) unless error.blank?
|
|
51
|
-
|
|
52
|
-
if @localized
|
|
53
|
-
unless @klass.fields[attr].localized?
|
|
54
|
-
@errors.push "is not localized #{attr.inspect}"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
else
|
|
59
|
-
@errors.push "no field named #{attr.inspect}"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
@errors.empty?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def failure_message_for_should
|
|
66
|
-
"Expected #{@klass.inspect} to #{description}, got #{@errors.to_sentence}"
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def failure_message_for_should_not
|
|
70
|
-
"Expected #{@klass.inspect} to not #{description}, got #{@klass.inspect} to #{description}"
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
alias :failure_message :failure_message_for_should
|
|
74
|
-
alias :failure_message_when_negated :failure_message_for_should_not
|
|
75
|
-
|
|
76
|
-
def description
|
|
77
|
-
desc = "have #{@attributes.size > 1 ? 'fields' : 'field'} named #{@attributes.collect(&:inspect).to_sentence}"
|
|
78
|
-
desc << " of type #{@type.inspect}" if @type
|
|
79
|
-
desc << " with alias #{@field_alias}" if @field_alias
|
|
80
|
-
desc << " with default value of #{@default.inspect}" if !@default.nil?
|
|
81
|
-
desc
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def have_field(*args)
|
|
86
|
-
HaveFieldMatcher.new(*args)
|
|
87
|
-
end
|
|
88
|
-
alias_method :have_fields, :have_field
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
RSpec::Matchers.define :have_instance_method do |name|
|
|
93
|
-
match do |klass|
|
|
94
|
-
klass.instance_methods.include?(name.to_sym)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
description do
|
|
98
|
-
"have instance method #{name.to_s}"
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
RSpec::Matchers.define :be_mongoid_document do
|
|
103
|
-
match do |doc|
|
|
104
|
-
doc.class.included_modules.include?(Mongoid::Document)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
description do
|
|
108
|
-
"be a Mongoid document"
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
RSpec::Matchers.define :be_versioned_document do
|
|
113
|
-
match do |doc|
|
|
114
|
-
doc.class.included_modules.include?(Mongoid::Versioning)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
description do
|
|
118
|
-
"be a versioned Mongoid document"
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
RSpec::Matchers.define :be_timestamped_document do
|
|
123
|
-
match do |doc|
|
|
124
|
-
if [*@timestamped_module].any?
|
|
125
|
-
modules = [*@timestamped_module].map{|m| "Mongoid::Timestamps::#{m.to_s.classify}".constantize }
|
|
126
|
-
(modules - doc.class.included_modules).empty?
|
|
127
|
-
else
|
|
128
|
-
doc.class.included_modules.include?(Mongoid::Timestamps) or
|
|
129
|
-
doc.class.included_modules.include?(Mongoid::Timestamps::Created) or
|
|
130
|
-
doc.class.included_modules.include?(Mongoid::Timestamps::Updated)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
chain :with do |timestamped_module|
|
|
135
|
-
@timestamped_module = timestamped_module
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
description do
|
|
139
|
-
desc = "be a timestamped Mongoid document"
|
|
140
|
-
desc << " with #{@timestamped_module}" if @timestamped_module
|
|
141
|
-
desc
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
RSpec::Matchers.define :be_paranoid_document do
|
|
146
|
-
match do |doc|
|
|
147
|
-
doc.class.included_modules.include?(Mongoid::Paranoia)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
description do
|
|
151
|
-
"be a paranoid Mongoid document"
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
RSpec::Matchers.define :be_multiparameted_document do
|
|
156
|
-
match do |doc|
|
|
157
|
-
doc.class.included_modules.include?(Mongoid::MultiParameterAttributes)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
description do
|
|
161
|
-
"be a multiparameted Mongoid document"
|
|
162
|
-
end
|
|
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
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
module Mongoid
|
|
2
|
-
module Matchers
|
|
3
|
-
class HaveIndexForMatcher # :nodoc:
|
|
4
|
-
def initialize(index_fields)
|
|
5
|
-
@index_fields = index_fields.symbolize_keys!
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def with_options(options = { })
|
|
9
|
-
@options = options
|
|
10
|
-
self
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def matches?(klass)
|
|
14
|
-
@klass = klass.is_a?(Class) ? klass : klass.class
|
|
15
|
-
@errors = []
|
|
16
|
-
|
|
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}"
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
else
|
|
28
|
-
@errors.push "no index for #{@index_fields}"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
@errors.empty?
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def failure_message_for_should
|
|
35
|
-
"Expected #{@klass.inspect} to #{description}, got #{@errors.to_sentence}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def failure_message_for_should_not
|
|
39
|
-
"Expected #{@klass.inspect} to not #{description}, got #{@klass.inspect} to #{description}"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
alias :failure_message :failure_message_for_should
|
|
43
|
-
alias :failure_message_when_negated :failure_message_for_should_not
|
|
44
|
-
|
|
45
|
-
def description
|
|
46
|
-
desc = "have an index for #{@index_fields.inspect}"
|
|
47
|
-
desc << " with options of #{@options.inspect}" if @options
|
|
48
|
-
desc
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
private
|
|
52
|
-
MAPPINGS = {
|
|
53
|
-
dropDups: :drop_dups,
|
|
54
|
-
expireAfterSeconds: :expire_after_seconds,
|
|
55
|
-
bucketSize: :bucket_size
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
def normalize_options(options)
|
|
59
|
-
options.transform_keys do |key|
|
|
60
|
-
MAPPINGS[key] || key
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def have_index_for(index_fields)
|
|
66
|
-
HaveIndexForMatcher.new(index_fields)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Mongoid
|
|
2
|
-
module Matchers
|
|
3
|
-
module Validations
|
|
4
|
-
module WithMessage
|
|
5
|
-
def with_message(message)
|
|
6
|
-
@expected_message = message
|
|
7
|
-
self
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
def check_expected_message
|
|
13
|
-
actual_message = @validator.options[:message]
|
|
14
|
-
if actual_message.nil?
|
|
15
|
-
@negative_result_message << " with no custom message"
|
|
16
|
-
@result = false
|
|
17
|
-
elsif actual_message == @expected_message
|
|
18
|
-
@positive_result_message << " with custom message '#{@expected_message}'"
|
|
19
|
-
else
|
|
20
|
-
@negative_result_message << " got message '#{actual_message}'"
|
|
21
|
-
@result = false
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/mongoid-rspec.gemspec
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
-
|
|
4
|
-
require 'mongoid/rspec/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |s|
|
|
7
|
-
s.name = "mongoid-rspec"
|
|
8
|
-
s.version = Mongoid::Rspec::VERSION
|
|
9
|
-
s.platform = Gem::Platform::RUBY
|
|
10
|
-
s.authors = ["Evan Sagge", "Rodrigo Pinto"]
|
|
11
|
-
s.email = %q{evansagge@gmail.com contato@rodrigopinto.me}
|
|
12
|
-
s.homepage = %q{http://github.com/mongoid-rspec/mongoid-rspec}
|
|
13
|
-
s.summary = %q{RSpec matchers for Mongoid}
|
|
14
|
-
s.description = %q{RSpec matches for Mongoid models, including association and validation matchers}
|
|
15
|
-
|
|
16
|
-
s.rubyforge_project = "mongoid-rspec"
|
|
17
|
-
|
|
18
|
-
s.files = `git ls-files`.split("\n")
|
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
21
|
-
s.require_paths = ["lib"]
|
|
22
|
-
|
|
23
|
-
s.add_dependency 'rake'
|
|
24
|
-
s.add_dependency 'mongoid', '~> 5.0'
|
|
25
|
-
s.add_dependency 'rspec', '~> 3.3'
|
|
26
|
-
end
|
data/spec/unit/indexes_spec.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe "Indexes" do
|
|
4
|
-
describe Article do
|
|
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
|
-
end
|
|
9
|
-
|
|
10
|
-
describe Profile do
|
|
11
|
-
it { is_expected.to have_index_for(first_name: 1, last_name: 1) }
|
|
12
|
-
end
|
|
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
|