mongoid-rspec 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25fcea5e8cc5e8f247b099f60276d560a83c2538e47856a8063f6fae57bffa37
4
- data.tar.gz: 291d75e35f982c38b7c58787d6127a0d693e850f3ef1840f02d45963304ad2c1
3
+ metadata.gz: 6c59448b4e72ebb718332a28e7ddf77de5b792a09ea273b75959930e2c6c2918
4
+ data.tar.gz: b1818ed7a513db7a4e31bcdd5a492504a75becfc866dd95505192da1db7a56cc
5
5
  SHA512:
6
- metadata.gz: f53b92e750ceba490eecd7c492b6ffd967131566ffc228c887a35f3e202d75a337a7903cd1b35717e54243906e582306773e2b849f0aea9462448351b58e0594
7
- data.tar.gz: d4e252e36a4b77b17b081e0e58176776c6c337a871864c1f805514c9da45cb8d0607fa42e518d08c28ecb8ce419008b1b85c4d07c2ee9f5c627642926775a324
6
+ metadata.gz: 995c284d71146d52d554e8eff18e48605e76546ebce9428674d1fcefe4c560a73973651f4eb4496d21a839fb35944c37f98cc21eb78ddd1e1eea80a57d1392c4
7
+ data.tar.gz: a2e400ead572f31c614a294f1d5d10116e08fa6f152b2f58cf112da45608a3d72be2c5893ceb035c8a6f514af8ef55bcfdffd0a55a81a2e0f97ad43fd0699cf2
data/README.md CHANGED
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  ## Compatibility
20
20
 
21
- This gem is compatible with Mongoid 3, 4, 5 and 6.
21
+ This gem is compatible with Mongoid 3, 4, 5, 6 and 7.
22
22
 
23
23
  ## Configuration
24
24
 
@@ -261,6 +261,10 @@ end
261
261
  RSpec.describe Site do
262
262
  it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.asc).with_counter_cache }
263
263
  end
264
+
265
+ RSpec.describe Message do
266
+ it { is_expected.to belong_to(:user).with_optional }
267
+ end
264
268
  ```
265
269
 
266
270
  ### Validation Matchers
@@ -290,6 +294,7 @@ end
290
294
 
291
295
  RSpec.describe Article do
292
296
  it { is_expected.to validate_length_of(:title).within(8..16) }
297
+ it { is_expected.to validate_absence_of(:deletion_date) }
293
298
  end
294
299
 
295
300
  RSpec.describe Visitor do
@@ -1,15 +1,29 @@
1
- require 'mongoid/relations'
1
+ if Mongoid::Compatibility::Version.mongoid7_or_newer?
2
+ require 'mongoid/association'
3
+ else
4
+ require 'mongoid/relations'
5
+ end
2
6
 
3
7
  module Mongoid
4
8
  module Matchers
5
9
  module Associations
6
- HAS_MANY = Mongoid::Relations::Referenced::Many
7
- HAS_AND_BELONGS_TO_MANY = Mongoid::Relations::Referenced::ManyToMany
8
- HAS_ONE = Mongoid::Relations::Referenced::One
9
- BELONGS_TO = Mongoid::Relations::Referenced::In
10
- EMBEDS_MANY = Mongoid::Relations::Embedded::Many
11
- EMBEDS_ONE = Mongoid::Relations::Embedded::One
12
- EMBEDDED_IN = Mongoid::Relations::Embedded::In
10
+ if Mongoid::Compatibility::Version.mongoid7_or_newer?
11
+ HAS_MANY = Mongoid::Association::Referenced::HasMany
12
+ HAS_AND_BELONGS_TO_MANY = Mongoid::Association::Referenced::HasAndBelongsToMany
13
+ HAS_ONE = Mongoid::Association::Referenced::HasOne
14
+ BELONGS_TO = Mongoid::Association::Referenced::BelongsTo
15
+ EMBEDS_MANY = Mongoid::Association::Embedded::EmbedsMany
16
+ EMBEDS_ONE = Mongoid::Association::Embedded::EmbedsOne
17
+ EMBEDDED_IN = Mongoid::Association::Embedded::EmbeddedIn
18
+ else
19
+ HAS_MANY = Mongoid::Relations::Referenced::Many
20
+ HAS_AND_BELONGS_TO_MANY = Mongoid::Relations::Referenced::ManyToMany
21
+ HAS_ONE = Mongoid::Relations::Referenced::One
22
+ BELONGS_TO = Mongoid::Relations::Referenced::In
23
+ EMBEDS_MANY = Mongoid::Relations::Embedded::Many
24
+ EMBEDS_ONE = Mongoid::Relations::Embedded::One
25
+ EMBEDDED_IN = Mongoid::Relations::Embedded::In
26
+ end
13
27
 
14
28
  class HaveAssociationMatcher
15
29
  def initialize(name, association_type)
@@ -37,7 +51,7 @@ module Mongoid
37
51
  @association[:order] = association_field_name.to_s
38
52
  @expectation_message << " ordered by #{@association[:order].inspect}"
39
53
 
40
- if association_field_name.is_a? Mongoid::Criteria::Queryable::Key
54
+ if association_field_name.is_a? association_kind_of
41
55
  @association[:order_operator] = association_field_name.operator
42
56
  @expectation_message << " #{order_way(@association[:order_operator])}"
43
57
  end
@@ -105,6 +119,12 @@ module Mongoid
105
119
  self
106
120
  end
107
121
 
122
+ def with_optional
123
+ @association[:optional] = true
124
+ @expectation_message << " which specifies optional as #{@association[:optional]}"
125
+ self
126
+ end
127
+
108
128
  def matches?(actual)
109
129
  @actual = actual.is_a?(Class) ? actual : actual.class
110
130
  metadata = @actual.relations[@association[:name]]
@@ -116,7 +136,11 @@ module Mongoid
116
136
  @positive_result_message = "association named #{@association[:name]}"
117
137
  end
118
138
 
119
- relation = metadata.relation
139
+ relation = if Mongoid::Compatibility::Version.mongoid7_or_newer?
140
+ metadata.class
141
+ else
142
+ metadata.relation
143
+ end
120
144
  if relation != @association[:type]
121
145
  @negative_result_message = "#{@actual.inspect} #{type_description(relation, false)} #{@association[:name]}"
122
146
  return false
@@ -222,11 +246,11 @@ module Mongoid
222
246
  end
223
247
 
224
248
  if @association[:index]
225
- if metadata.index != true
249
+ if metadata.indexed?
250
+ @positive_result_message = "#{@positive_result_message} which set index"
251
+ else
226
252
  @negative_result_message = "#{@positive_result_message} which did not set index"
227
253
  return false
228
- else
229
- @positive_result_message = "#{@positive_result_message} which set index"
230
254
  end
231
255
  end
232
256
 
@@ -248,6 +272,15 @@ module Mongoid
248
272
  end
249
273
  end
250
274
 
275
+ if @association[:optional]
276
+ if metadata.options[:optional] != true
277
+ @negative_result_message = "#{@positive_result_message} which did not set optional"
278
+ return false
279
+ else
280
+ @positive_result_message = "#{@positive_result_message} which set optional"
281
+ end
282
+ end
283
+
251
284
  true
252
285
  end
253
286
 
@@ -293,6 +326,10 @@ module Mongoid
293
326
  def order_way(operator)
294
327
  [nil, 'ascending', 'descending'][operator]
295
328
  end
329
+
330
+ def association_kind_of
331
+ Mongoid::Compatibility::Version.mongoid5_or_older? ? Origin::Key : Mongoid::Criteria::Queryable::Key
332
+ end
296
333
  end
297
334
 
298
335
  def embed_one(association_name)
@@ -0,0 +1,11 @@
1
+ if Mongoid::Compatibility::Version.mongoid4_or_newer?
2
+ module Mongoid
3
+ module Matchers
4
+ module Validations
5
+ def validate_absence_of(field)
6
+ HaveValidationMatcher.new(field, :absence)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module RSpec
3
- VERSION = '4.0.0'.freeze
3
+ VERSION = '4.1.0'.freeze
4
4
  end
5
5
  end
data/lib/mongoid/rspec.rb CHANGED
@@ -6,7 +6,7 @@ require 'rspec/core'
6
6
  require 'rspec/expectations'
7
7
  require 'rspec/mocks'
8
8
  require 'active_support/core_ext/hash/keys'
9
- require 'active_support/core_ext/hash/transform_values' if Mongoid::Compatibility::Version.mongoid4_or_newer?
9
+ require 'active_support/core_ext/hash/transform_values' if Mongoid::Compatibility::Version.mongoid4_or_newer? && ActiveSupport.version < Gem::Version.new('6')
10
10
  require 'active_support/core_ext/object/blank'
11
11
  require 'active_support/core_ext/string/inflections'
12
12
 
@@ -25,6 +25,7 @@ require 'matchers/validations/presence_of'
25
25
  require 'matchers/validations/uniqueness_of'
26
26
  require 'matchers/validations/acceptance_of'
27
27
  require 'matchers/validations/custom_validation_of'
28
+ require 'matchers/validations/absence_of'
28
29
  require 'matchers/be_mongoid_document'
29
30
  require 'matchers/be_dynamic_document'
30
31
  require 'matchers/be_stored_in'
@@ -8,6 +8,7 @@ class Article
8
8
  field :allow_comments, type: Boolean, default: true
9
9
  field :number_of_comments, type: Integer
10
10
  field :status, type: Symbol
11
+ field :deletion_date, type: DateTime, default: nil
11
12
 
12
13
  embeds_many :comments, cascade_callbacks: true, inverse_of: :article
13
14
  embeds_one :permalink, inverse_of: :linkable
@@ -21,6 +22,8 @@ class Article
21
22
  validates_length_of :title, within: 8..16
22
23
  validates_length_of :content, minimum: 200
23
24
 
25
+ validates_absence_of :deletion_date if Mongoid::Compatibility::Version.mongoid4_or_newer?
26
+
24
27
  index({ title: 1 }, unique: true, background: true, drop_dups: true)
25
28
  index(published: 1)
26
29
  index('permalink._id' => 1)
@@ -5,6 +5,12 @@ class Message
5
5
  field :from
6
6
  field :to
7
7
 
8
+ if Mongoid::Compatibility::Version.mongoid6_or_newer?
9
+ belongs_to :user, optional: true
10
+ else
11
+ belongs_to :user
12
+ end
13
+
8
14
  validates :identifier, uniqueness: { message: 'uniqueness' }
9
15
  validates :from, presence: { message: 'required' }
10
16
  validates :to, format: { with: /[a-z]+/, message: 'format' }
data/spec/models/site.rb CHANGED
@@ -3,7 +3,11 @@ class Site
3
3
 
4
4
  field :name
5
5
 
6
- has_many :users, inverse_of: :site, order: :email.desc, counter_cache: true
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
7
11
 
8
12
  validates :name, presence: true, uniqueness: true
9
13
  end
data/spec/models/user.rb CHANGED
@@ -13,6 +13,7 @@ class User
13
13
  belongs_to :site, inverse_of: :users
14
14
  has_many :articles, foreign_key: :author_id, order: :title
15
15
  has_many :comments, dependent: :destroy, autosave: true
16
+ has_many :messages, dependent: :destroy
16
17
  has_and_belongs_to_many :children, class_name: 'User'
17
18
  has_one :record, autobuild: true, inverse_of: :user
18
19
 
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,6 @@ require 'bundler'
10
10
  Bundler.setup
11
11
 
12
12
  require 'mongoid'
13
- require 'rspec'
14
13
  require 'rspec/core'
15
14
  require 'rspec/expectations'
16
15
  require 'mongoid/compatibility'
@@ -39,8 +39,16 @@ RSpec.describe 'Associations' do
39
39
  end
40
40
 
41
41
  describe Site do
42
- if Mongoid::Compatibility::Version.mongoid6_or_newer?
42
+ if Mongoid::Compatibility::Version.mongoid6_or_older?
43
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 }
44
52
  end
45
53
  end
46
54
  end
@@ -39,6 +39,7 @@ RSpec.describe 'Validations' do
39
39
  it { is_expected.to validate_length_of(:content).greater_than(200) }
40
40
  it { is_expected.to validate_inclusion_of(:status).to_allow([:pending]).on(:create) }
41
41
  it { is_expected.to validate_inclusion_of(:status).to_allow(%i[approved rejected]).on(:update) }
42
+ it { is_expected.to validate_absence_of(:deletion_date) } if Mongoid::Compatibility::Version.mongoid4_or_newer?
42
43
  end
43
44
 
44
45
  describe MovieArticle do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.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: 2018-01-29 00:00:00.000000000 Z
12
+ date: 2020-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -31,16 +31,30 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '2.0'
34
+ version: '3.1'
35
35
  type: :runtime
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: '2.0'
41
+ version: '3.1'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rspec
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
44
58
  requirement: !ruby/object:Gem::Requirement
45
59
  requirements:
46
60
  - - "~>"
@@ -54,33 +68,61 @@ dependencies:
54
68
  - !ruby/object:Gem::Version
55
69
  version: '3.3'
56
70
  - !ruby/object:Gem::Dependency
57
- name: rake
71
+ name: rspec-expectations
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
74
  - - "~>"
61
75
  - !ruby/object:Gem::Version
62
- version: '10.0'
63
- type: :development
76
+ version: '3.3'
77
+ type: :runtime
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - "~>"
68
82
  - !ruby/object:Gem::Version
69
- version: '10.0'
83
+ version: '3.3'
70
84
  - !ruby/object:Gem::Dependency
71
- name: mongoid-compatibility
85
+ name: rspec-mocks
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - ">="
88
+ - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '0'
90
+ version: '3.3'
77
91
  type: :runtime
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - ">="
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.3'
98
+ - !ruby/object:Gem::Dependency
99
+ name: appraisal
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
82
103
  - !ruby/object:Gem::Version
83
- version: '0'
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'
84
126
  description: RSpec matches for Mongoid models, including association and validation
85
127
  matchers.
86
128
  email: evansagge@gmail.com contato@rodrigopinto.me
@@ -103,6 +145,7 @@ files:
103
145
  - lib/matchers/indexes/v3/have_index_for.rb
104
146
  - lib/matchers/indexes/v4/have_index_for.rb
105
147
  - lib/matchers/validations.rb
148
+ - lib/matchers/validations/absence_of.rb
106
149
  - lib/matchers/validations/acceptance_of.rb
107
150
  - lib/matchers/validations/associated.rb
108
151
  - lib/matchers/validations/confirmation_of.rb
@@ -158,31 +201,30 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
201
  - !ruby/object:Gem::Version
159
202
  version: 1.3.6
160
203
  requirements: []
161
- rubyforge_project: mongoid-rspec
162
- rubygems_version: 2.7.3
204
+ rubygems_version: 3.1.3
163
205
  signing_key:
164
206
  specification_version: 4
165
207
  summary: RSpec matchers for Mongoid
166
208
  test_files:
167
- - spec/models/article.rb
168
- - spec/models/comment.rb
169
- - spec/models/log.rb
170
- - spec/models/message.rb
171
- - spec/models/movie_article.rb
172
- - spec/models/permalink.rb
173
- - spec/models/person.rb
174
- - spec/models/profile.rb
175
- - spec/models/record.rb
176
- - spec/models/site.rb
177
- - spec/models/user.rb
178
209
  - spec/spec_helper.rb
179
- - spec/unit/accept_nested_attributes_spec.rb
180
210
  - spec/unit/associations_spec.rb
181
211
  - spec/unit/be_dynamic_document_spec.rb
182
- - spec/unit/be_mongoid_document_spec.rb
212
+ - spec/unit/validations_spec.rb
183
213
  - spec/unit/be_stored_in.rb
184
- - spec/unit/document_spec.rb
185
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
186
218
  - spec/unit/have_timestamps_spec.rb
187
- - spec/unit/validations_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
188
230
  - spec/validators/ssn_validator.rb