mongoid-rspec 4.1.0 → 4.3.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 +54 -7
- data/Rakefile +3 -4
- data/lib/matchers/accept_nested_attributes.rb +2 -0
- data/lib/matchers/allow_mass_assignment.rb +2 -0
- data/lib/matchers/associations.rb +25 -8
- data/lib/matchers/be_dynamic_document.rb +2 -0
- data/lib/matchers/be_mongoid_document.rb +2 -0
- data/lib/matchers/be_stored_in.rb +2 -0
- data/lib/matchers/have_field.rb +5 -3
- data/lib/matchers/have_timestamps.rb +5 -3
- data/lib/matchers/indexes/have_index_for.rb +2 -0
- data/lib/matchers/indexes/v3/have_index_for.rb +4 -2
- data/lib/matchers/indexes/v4/have_index_for.rb +3 -1
- data/lib/matchers/validations/absence_of.rb +2 -0
- data/lib/matchers/validations/acceptance_of.rb +2 -0
- data/lib/matchers/validations/associated.rb +2 -0
- data/lib/matchers/validations/confirmation_of.rb +2 -0
- data/lib/matchers/validations/custom_validation_of.rb +4 -2
- data/lib/matchers/validations/exclusion_of.rb +5 -3
- data/lib/matchers/validations/format_of.rb +2 -0
- data/lib/matchers/validations/inclusion_of.rb +2 -0
- data/lib/matchers/validations/length_of.rb +2 -0
- data/lib/matchers/validations/numericality_of.rb +2 -0
- data/lib/matchers/validations/presence_of.rb +2 -0
- data/lib/matchers/validations/uniqueness_of.rb +2 -0
- data/lib/matchers/validations.rb +43 -7
- data/lib/mongoid/rspec/version.rb +3 -1
- data/lib/mongoid/rspec.rb +2 -0
- data/lib/mongoid-rspec.rb +2 -0
- metadata +58 -95
- data/spec/models/article.rb +0 -32
- data/spec/models/comment.rb +0 -6
- data/spec/models/log.rb +0 -9
- data/spec/models/message.rb +0 -17
- data/spec/models/movie_article.rb +0 -7
- data/spec/models/permalink.rb +0 -5
- data/spec/models/person.rb +0 -10
- data/spec/models/profile.rb +0 -16
- data/spec/models/record.rb +0 -5
- data/spec/models/site.rb +0 -13
- data/spec/models/user.rb +0 -38
- data/spec/spec_helper.rb +0 -35
- data/spec/unit/accept_nested_attributes_spec.rb +0 -12
- data/spec/unit/associations_spec.rb +0 -54
- data/spec/unit/be_dynamic_document_spec.rb +0 -21
- data/spec/unit/be_mongoid_document_spec.rb +0 -25
- data/spec/unit/be_stored_in.rb +0 -54
- data/spec/unit/document_spec.rb +0 -17
- data/spec/unit/have_index_for_spec.rb +0 -46
- data/spec/unit/have_timestamps_spec.rb +0 -71
- data/spec/unit/validations_spec.rb +0 -61
- data/spec/validators/ssn_validator.rb +0 -16
metadata
CHANGED
|
@@ -1,128 +1,134 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid-rspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Sagge
|
|
8
8
|
- Rodrigo Pinto
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-10-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
15
|
+
name: appraisal
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
requirements:
|
|
18
|
-
- - "
|
|
18
|
+
- - "~>"
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
21
|
-
type: :
|
|
20
|
+
version: '2.0'
|
|
21
|
+
type: :development
|
|
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: '2.0'
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
|
-
name:
|
|
29
|
+
name: ostruct
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
32
|
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
35
|
-
type: :
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :development
|
|
36
36
|
prerelease: false
|
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
39
|
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '
|
|
41
|
+
version: '0'
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
|
-
name:
|
|
43
|
+
name: pry
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: 0
|
|
49
|
-
type: :
|
|
48
|
+
version: '0'
|
|
49
|
+
type: :development
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
53
|
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: 0
|
|
55
|
+
version: '0'
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
|
-
name:
|
|
57
|
+
name: rails
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
|
-
- - "
|
|
60
|
+
- - ">="
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '
|
|
63
|
-
type: :
|
|
62
|
+
version: '0'
|
|
63
|
+
type: :development
|
|
64
64
|
prerelease: false
|
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements:
|
|
67
|
-
- - "
|
|
67
|
+
- - ">="
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
69
|
+
version: '0'
|
|
70
70
|
- !ruby/object:Gem::Dependency
|
|
71
|
-
name: rspec
|
|
71
|
+
name: rspec
|
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
|
74
|
-
- - "
|
|
74
|
+
- - ">="
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
|
-
version: '
|
|
77
|
-
type: :
|
|
76
|
+
version: '0'
|
|
77
|
+
type: :development
|
|
78
78
|
prerelease: false
|
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements:
|
|
81
|
-
- - "
|
|
81
|
+
- - ">="
|
|
82
82
|
- !ruby/object:Gem::Version
|
|
83
|
-
version: '
|
|
83
|
+
version: '0'
|
|
84
84
|
- !ruby/object:Gem::Dependency
|
|
85
|
-
name:
|
|
85
|
+
name: rubocop
|
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
|
87
87
|
requirements:
|
|
88
88
|
- - "~>"
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
|
-
version:
|
|
91
|
-
type: :
|
|
90
|
+
version: 1.36.0
|
|
91
|
+
type: :development
|
|
92
92
|
prerelease: false
|
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements:
|
|
95
95
|
- - "~>"
|
|
96
96
|
- !ruby/object:Gem::Version
|
|
97
|
-
version:
|
|
97
|
+
version: 1.36.0
|
|
98
98
|
- !ruby/object:Gem::Dependency
|
|
99
|
-
name:
|
|
99
|
+
name: mongoid
|
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
|
101
101
|
requirements:
|
|
102
|
-
- - "
|
|
102
|
+
- - ">="
|
|
103
103
|
- !ruby/object:Gem::Version
|
|
104
|
-
version: '
|
|
105
|
-
|
|
104
|
+
version: '3.0'
|
|
105
|
+
- - "<"
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '10.0'
|
|
108
|
+
type: :runtime
|
|
106
109
|
prerelease: false
|
|
107
110
|
version_requirements: !ruby/object:Gem::Requirement
|
|
108
111
|
requirements:
|
|
109
|
-
- - "
|
|
112
|
+
- - ">="
|
|
110
113
|
- !ruby/object:Gem::Version
|
|
111
|
-
version: '
|
|
114
|
+
version: '3.0'
|
|
115
|
+
- - "<"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '10.0'
|
|
112
118
|
- !ruby/object:Gem::Dependency
|
|
113
|
-
name:
|
|
119
|
+
name: mongoid-compatibility
|
|
114
120
|
requirement: !ruby/object:Gem::Requirement
|
|
115
121
|
requirements:
|
|
116
|
-
- - "
|
|
122
|
+
- - ">="
|
|
117
123
|
- !ruby/object:Gem::Version
|
|
118
|
-
version:
|
|
119
|
-
type: :
|
|
124
|
+
version: 0.5.1
|
|
125
|
+
type: :runtime
|
|
120
126
|
prerelease: false
|
|
121
127
|
version_requirements: !ruby/object:Gem::Requirement
|
|
122
128
|
requirements:
|
|
123
|
-
- - "
|
|
129
|
+
- - ">="
|
|
124
130
|
- !ruby/object:Gem::Version
|
|
125
|
-
version:
|
|
131
|
+
version: 0.5.1
|
|
126
132
|
description: RSpec matches for Mongoid models, including association and validation
|
|
127
133
|
matchers.
|
|
128
134
|
email: evansagge@gmail.com contato@rodrigopinto.me
|
|
@@ -160,33 +166,12 @@ files:
|
|
|
160
166
|
- lib/mongoid-rspec.rb
|
|
161
167
|
- lib/mongoid/rspec.rb
|
|
162
168
|
- lib/mongoid/rspec/version.rb
|
|
163
|
-
- spec/models/article.rb
|
|
164
|
-
- spec/models/comment.rb
|
|
165
|
-
- spec/models/log.rb
|
|
166
|
-
- spec/models/message.rb
|
|
167
|
-
- spec/models/movie_article.rb
|
|
168
|
-
- spec/models/permalink.rb
|
|
169
|
-
- spec/models/person.rb
|
|
170
|
-
- spec/models/profile.rb
|
|
171
|
-
- spec/models/record.rb
|
|
172
|
-
- spec/models/site.rb
|
|
173
|
-
- spec/models/user.rb
|
|
174
|
-
- spec/spec_helper.rb
|
|
175
|
-
- spec/unit/accept_nested_attributes_spec.rb
|
|
176
|
-
- spec/unit/associations_spec.rb
|
|
177
|
-
- spec/unit/be_dynamic_document_spec.rb
|
|
178
|
-
- spec/unit/be_mongoid_document_spec.rb
|
|
179
|
-
- spec/unit/be_stored_in.rb
|
|
180
|
-
- spec/unit/document_spec.rb
|
|
181
|
-
- spec/unit/have_index_for_spec.rb
|
|
182
|
-
- spec/unit/have_timestamps_spec.rb
|
|
183
|
-
- spec/unit/validations_spec.rb
|
|
184
|
-
- spec/validators/ssn_validator.rb
|
|
185
169
|
homepage: http://github.com/mongoid-rspec/mongoid-rspec
|
|
186
170
|
licenses:
|
|
187
171
|
- MIT
|
|
188
|
-
metadata:
|
|
189
|
-
|
|
172
|
+
metadata:
|
|
173
|
+
rubygems_mfa_required: 'true'
|
|
174
|
+
post_install_message:
|
|
190
175
|
rdoc_options: []
|
|
191
176
|
require_paths:
|
|
192
177
|
- lib
|
|
@@ -194,37 +179,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
194
179
|
requirements:
|
|
195
180
|
- - ">="
|
|
196
181
|
- !ruby/object:Gem::Version
|
|
197
|
-
version: '2.
|
|
182
|
+
version: '2.6'
|
|
198
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
184
|
requirements:
|
|
200
185
|
- - ">="
|
|
201
186
|
- !ruby/object:Gem::Version
|
|
202
187
|
version: 1.3.6
|
|
203
188
|
requirements: []
|
|
204
|
-
rubygems_version: 3.
|
|
205
|
-
signing_key:
|
|
189
|
+
rubygems_version: 3.5.16
|
|
190
|
+
signing_key:
|
|
206
191
|
specification_version: 4
|
|
207
192
|
summary: RSpec matchers for Mongoid
|
|
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
|
|
219
|
-
- spec/models/article.rb
|
|
220
|
-
- spec/models/movie_article.rb
|
|
221
|
-
- spec/models/record.rb
|
|
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
|
|
229
|
-
- spec/models/user.rb
|
|
230
|
-
- spec/validators/ssn_validator.rb
|
|
193
|
+
test_files: []
|
data/spec/models/article.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
class Article
|
|
2
|
-
include Mongoid::Document
|
|
3
|
-
include Mongoid::Timestamps
|
|
4
|
-
|
|
5
|
-
field :title, localize: true
|
|
6
|
-
field :content
|
|
7
|
-
field :published, type: Boolean, default: false
|
|
8
|
-
field :allow_comments, type: Boolean, default: true
|
|
9
|
-
field :number_of_comments, type: Integer
|
|
10
|
-
field :status, type: Symbol
|
|
11
|
-
field :deletion_date, type: DateTime, default: nil
|
|
12
|
-
|
|
13
|
-
embeds_many :comments, cascade_callbacks: true, inverse_of: :article
|
|
14
|
-
embeds_one :permalink, inverse_of: :linkable
|
|
15
|
-
belongs_to :author, class_name: 'User', inverse_of: :articles, index: true
|
|
16
|
-
|
|
17
|
-
validates :title, presence: true
|
|
18
|
-
|
|
19
|
-
validates_inclusion_of :status, in: [:pending], on: :create
|
|
20
|
-
validates_inclusion_of :status, in: %i[approved rejected], on: :update
|
|
21
|
-
|
|
22
|
-
validates_length_of :title, within: 8..16
|
|
23
|
-
validates_length_of :content, minimum: 200
|
|
24
|
-
|
|
25
|
-
validates_absence_of :deletion_date if Mongoid::Compatibility::Version.mongoid4_or_newer?
|
|
26
|
-
|
|
27
|
-
index({ title: 1 }, unique: true, background: true, drop_dups: true)
|
|
28
|
-
index(published: 1)
|
|
29
|
-
index('permalink._id' => 1)
|
|
30
|
-
|
|
31
|
-
accepts_nested_attributes_for :permalink
|
|
32
|
-
end
|
data/spec/models/comment.rb
DELETED
data/spec/models/log.rb
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
class Log
|
|
2
|
-
include Mongoid::Document
|
|
3
|
-
include Mongoid::Timestamps
|
|
4
|
-
include Mongoid::Attributes::Dynamic if Mongoid::Compatibility::Version.mongoid4_or_newer?
|
|
5
|
-
|
|
6
|
-
store_in collection: 'logs'
|
|
7
|
-
|
|
8
|
-
index({ created_at: 1 }, bucket_size: 100, expire_after_seconds: 3600)
|
|
9
|
-
end
|
data/spec/models/message.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class Message
|
|
2
|
-
include Mongoid::Document
|
|
3
|
-
|
|
4
|
-
field :identifier
|
|
5
|
-
field :from
|
|
6
|
-
field :to
|
|
7
|
-
|
|
8
|
-
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
|
9
|
-
belongs_to :user, optional: true
|
|
10
|
-
else
|
|
11
|
-
belongs_to :user
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
validates :identifier, uniqueness: { message: 'uniqueness' }
|
|
15
|
-
validates :from, presence: { message: 'required' }
|
|
16
|
-
validates :to, format: { with: /[a-z]+/, message: 'format' }
|
|
17
|
-
end
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
class MovieArticle < Article
|
|
2
|
-
field :rating, type: Float
|
|
3
|
-
field :classification, type: Integer
|
|
4
|
-
|
|
5
|
-
validates :rating, numericality: { greater_than: 0, less_than_or_equal_to: 5 }
|
|
6
|
-
validates :classification, numericality: { even: true, only_integer: true, allow_nil: false }
|
|
7
|
-
end
|
data/spec/models/permalink.rb
DELETED
data/spec/models/person.rb
DELETED
data/spec/models/profile.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class Profile
|
|
2
|
-
include Mongoid::Document
|
|
3
|
-
|
|
4
|
-
field :first_name
|
|
5
|
-
field :last_name
|
|
6
|
-
field :age
|
|
7
|
-
field :hobbies, type: Array, default: []
|
|
8
|
-
|
|
9
|
-
embedded_in :user, inverse_of: :profile
|
|
10
|
-
|
|
11
|
-
validates :age, numericality: { greater_than: 0 }
|
|
12
|
-
validates :terms_of_service, acceptance: true
|
|
13
|
-
validates :hobbies, length: { minimum: 1, message: 'requires at least one hobby' }
|
|
14
|
-
|
|
15
|
-
index(first_name: 1, last_name: 1)
|
|
16
|
-
end
|
data/spec/models/record.rb
DELETED
data/spec/models/site.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class Site
|
|
2
|
-
include Mongoid::Document
|
|
3
|
-
|
|
4
|
-
field :name
|
|
5
|
-
|
|
6
|
-
if Mongoid::Compatibility::Version.mongoid6_or_older?
|
|
7
|
-
has_many :users, inverse_of: :site, order: :email.desc, counter_cache: true
|
|
8
|
-
else
|
|
9
|
-
has_many :users, inverse_of: :site, order: :email.desc
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
validates :name, presence: true, uniqueness: true
|
|
13
|
-
end
|
data/spec/models/user.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
class User
|
|
2
|
-
include Mongoid::Document
|
|
3
|
-
include Mongoid::Timestamps::Created
|
|
4
|
-
|
|
5
|
-
field :login
|
|
6
|
-
field :email
|
|
7
|
-
field :role
|
|
8
|
-
field :age, type: Integer
|
|
9
|
-
field :password, type: String
|
|
10
|
-
field :provider_uid
|
|
11
|
-
field :locale
|
|
12
|
-
|
|
13
|
-
belongs_to :site, inverse_of: :users
|
|
14
|
-
has_many :articles, foreign_key: :author_id, order: :title
|
|
15
|
-
has_many :comments, dependent: :destroy, autosave: true
|
|
16
|
-
has_many :messages, dependent: :destroy
|
|
17
|
-
has_and_belongs_to_many :children, class_name: 'User'
|
|
18
|
-
has_one :record, autobuild: true, inverse_of: :user
|
|
19
|
-
|
|
20
|
-
embeds_one :profile, inverse_of: :user
|
|
21
|
-
|
|
22
|
-
validates :login, presence: true, uniqueness: { scope: :site }, format: { with: /\A[\w\-]+\z/ }, exclusion: { in: %w[super index edit] }
|
|
23
|
-
validates :email, uniqueness: { case_sensitive: false, scope: :site, message: 'is already taken' }, confirmation: true
|
|
24
|
-
validates :role, presence: true, inclusion: { in: %w[admin moderator member] }
|
|
25
|
-
validates :profile, presence: true, associated: true
|
|
26
|
-
validates :age, presence: true, numericality: true, inclusion: { in: 23..42 }, on: %i[create update]
|
|
27
|
-
validates :password, presence: true, on: %i[create update]
|
|
28
|
-
validates :password, exclusion: { in: ->(_user) { ['password'] } }
|
|
29
|
-
validates :password, confirmation: { message: 'Password confirmation must match given password' }
|
|
30
|
-
validates :provider_uid, presence: true
|
|
31
|
-
validates :locale, inclusion: { in: ->(_user) { %i[en ru] } }
|
|
32
|
-
|
|
33
|
-
accepts_nested_attributes_for :articles, :comments
|
|
34
|
-
|
|
35
|
-
def admin?
|
|
36
|
-
false
|
|
37
|
-
end
|
|
38
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
|
3
|
-
MODELS = File.join(File.dirname(__FILE__), 'models')
|
|
4
|
-
$LOAD_PATH.unshift(MODELS)
|
|
5
|
-
VALIDATORS = File.join(File.dirname(__FILE__), 'validators')
|
|
6
|
-
$LOAD_PATH.unshift(VALIDATORS)
|
|
7
|
-
|
|
8
|
-
require 'rubygems'
|
|
9
|
-
require 'bundler'
|
|
10
|
-
Bundler.setup
|
|
11
|
-
|
|
12
|
-
require 'mongoid'
|
|
13
|
-
require 'rspec/core'
|
|
14
|
-
require 'rspec/expectations'
|
|
15
|
-
require 'mongoid/compatibility'
|
|
16
|
-
|
|
17
|
-
Mongoid::Config.connect_to('mongoid-rspec-test') if Mongoid::Compatibility::Version.mongoid3_or_newer?
|
|
18
|
-
Mongo::Logger.logger.level = ::Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
|
19
|
-
|
|
20
|
-
Dir[File.join(MODELS, '*.rb')].sort.each { |file| require File.basename(file) }
|
|
21
|
-
|
|
22
|
-
require 'mongoid-rspec'
|
|
23
|
-
|
|
24
|
-
RSpec.configure do |config|
|
|
25
|
-
config.include RSpec::Matchers
|
|
26
|
-
config.include Mongoid::Matchers
|
|
27
|
-
config.mock_with :rspec
|
|
28
|
-
config.after :all do
|
|
29
|
-
Mongoid::Config.purge!
|
|
30
|
-
end
|
|
31
|
-
config.after :suite do
|
|
32
|
-
print "\n# Mongoid v#{Mongoid::VERSION}"
|
|
33
|
-
end
|
|
34
|
-
config.disable_monkey_patching!
|
|
35
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe 'AcceptsNestedAttributes' do
|
|
4
|
-
describe User do
|
|
5
|
-
it { is_expected.to accept_nested_attributes_for(:articles) }
|
|
6
|
-
it { is_expected.to accept_nested_attributes_for(:comments) }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe Article do
|
|
10
|
-
it { is_expected.to accept_nested_attributes_for(:permalink) }
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe 'Associations' do
|
|
4
|
-
describe User do
|
|
5
|
-
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
|
6
|
-
it { is_expected.to have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it { is_expected.to have_one(:record).as_inverse_of(:user).with_autobuild }
|
|
10
|
-
|
|
11
|
-
it { is_expected.to have_many(:comments).with_dependent(:destroy).with_autosave }
|
|
12
|
-
|
|
13
|
-
it { is_expected.to embed_one(:profile).as_inverse_of(:user) }
|
|
14
|
-
|
|
15
|
-
it { is_expected.to have_and_belong_to_many(:children).of_type(User) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe Profile do
|
|
19
|
-
it { is_expected.to be_embedded_in(:user).as_inverse_of(:profile) }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe Article do
|
|
23
|
-
it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
|
|
24
|
-
it { is_expected.to embed_many(:comments).as_inverse_of(:article).with_cascading_callbacks }
|
|
25
|
-
it { is_expected.to embed_one(:permalink).as_inverse_of(:linkable) }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe Comment do
|
|
29
|
-
it { is_expected.to be_embedded_in(:article).as_inverse_of(:comments).with_polymorphism }
|
|
30
|
-
it { is_expected.to belong_to(:user).as_inverse_of(:comments) }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe Record do
|
|
34
|
-
it { is_expected.to belong_to(:user).as_inverse_of(:record) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe Permalink do
|
|
38
|
-
it { is_expected.to be_embedded_in(:linkable).as_inverse_of(:link) }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe Site do
|
|
42
|
-
if Mongoid::Compatibility::Version.mongoid6_or_older?
|
|
43
|
-
it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.desc).with_counter_cache }
|
|
44
|
-
elsif Mongoid::Compatibility::Version.mongoid7_or_newer?
|
|
45
|
-
it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.desc) }
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe Message do
|
|
50
|
-
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
|
51
|
-
it { is_expected.to belong_to(:user).with_optional }
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Mongoid::Matchers::BeDynamicDocument do
|
|
4
|
-
context 'when model does\'t include Mongoid::Document' do
|
|
5
|
-
subject do
|
|
6
|
-
Class.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it { is_expected.not_to be_mongoid_document }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context 'when model doesn\'t include Mongoid::Document' do
|
|
13
|
-
subject do
|
|
14
|
-
Class.new do
|
|
15
|
-
include Mongoid::Document
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it { is_expected.to be_mongoid_document }
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
if Mongoid::Compatibility::Version.mongoid4_or_newer?
|
|
3
|
-
RSpec.describe Mongoid::Matchers::BeMongoidDocument do
|
|
4
|
-
context 'when model does\'t include Mongoid::Attributes::Dynamic' do
|
|
5
|
-
subject do
|
|
6
|
-
Class.new do
|
|
7
|
-
include Mongoid::Document
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it { is_expected.not_to be_dynamic_document }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
context 'when model doesn\'t include Mongoid::Attributes::Dynamic' do
|
|
15
|
-
subject do
|
|
16
|
-
Class.new do
|
|
17
|
-
include Mongoid::Document
|
|
18
|
-
include Mongoid::Attributes::Dynamic
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it { is_expected.to be_dynamic_document }
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
data/spec/unit/be_stored_in.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Mongoid::Matchers::BeStoredIn do
|
|
4
|
-
subject do
|
|
5
|
-
Class.new do
|
|
6
|
-
include Mongoid::Document
|
|
7
|
-
store_in collection: 'citizens', database: 'other', client: 'secondary'
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it 'detects storage options' do
|
|
12
|
-
is_expected.to be_stored_in(collection: 'citizens', database: 'other', client: 'secondary')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'detects even part of storage options' do
|
|
16
|
-
is_expected.to be_stored_in(database: 'other')
|
|
17
|
-
is_expected.to be_stored_in(client: 'secondary')
|
|
18
|
-
is_expected.to be_stored_in(collection: 'citizens')
|
|
19
|
-
is_expected.to be_stored_in(collection: 'citizens', database: 'other')
|
|
20
|
-
is_expected.to be_stored_in(database: 'other', client: 'secondary')
|
|
21
|
-
is_expected.to be_stored_in(collection: 'citizens', client: 'secondary')
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'detects differences' do
|
|
25
|
-
is_expected.not_to be_stored_in(collection: 'aliens')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'when models has storage options defined via blocks, procs or lambdas' do
|
|
29
|
-
subject do
|
|
30
|
-
Class.new do
|
|
31
|
-
include Mongoid::Document
|
|
32
|
-
store_in database: -> { Thread.current[:database] }
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
before do
|
|
37
|
-
Thread.current[:database] = 'db1981'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'detects storage options' do
|
|
41
|
-
is_expected.to be_stored_in(database: 'db1981')
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'reflects changes in storage options' do
|
|
45
|
-
is_expected.to be_stored_in(database: 'db1981')
|
|
46
|
-
Thread.current[:database] = 'db2200'
|
|
47
|
-
is_expected.to be_stored_in(database: 'db2200')
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'detects differences' do
|
|
51
|
-
is_expected.not_to be_stored_in(database: 'other')
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
data/spec/unit/document_spec.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe 'Document' do
|
|
4
|
-
describe User do
|
|
5
|
-
it { is_expected.to have_fields(:email, :login) }
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe Article do
|
|
9
|
-
klass_boolean = Mongoid::Compatibility::Version.mongoid4_or_newer? ? Mongoid::Boolean : Boolean
|
|
10
|
-
it { is_expected.to have_field(:published).of_type(klass_boolean).with_default_value_of(false) }
|
|
11
|
-
it { is_expected.to have_field(:allow_comments).of_type(klass_boolean).with_default_value_of(true) }
|
|
12
|
-
it { is_expected.to belong_to(:author) }
|
|
13
|
-
it { is_expected.to have_field(:title).localized }
|
|
14
|
-
it { is_expected.not_to have_field(:allow_comments).of_type(klass_boolean).with_default_value_of(false) }
|
|
15
|
-
it { is_expected.not_to have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
|
|
16
|
-
end
|
|
17
|
-
end
|