mongoid-rspec 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 801c33ba9bd350eeb1595c57509601084b983ae5
4
- data.tar.gz: 1f47a9a328b9d58e5cdaaebf7dbfd91420ed4ca7
2
+ SHA256:
3
+ metadata.gz: 6c59448b4e72ebb718332a28e7ddf77de5b792a09ea273b75959930e2c6c2918
4
+ data.tar.gz: b1818ed7a513db7a4e31bcdd5a492504a75becfc866dd95505192da1db7a56cc
5
5
  SHA512:
6
- metadata.gz: 91cf1c6e8b0d356bbece0657fe9f5cf1df218f8ec5fa9171a96dd2cef02781654390bcd47f6bea9e62192564d144c1489541dcb54bcc016c596e73578f1b4d18
7
- data.tar.gz: af5c81412000da22a464b6982dab00e652b34c052ca46cc3fb596439c3e7dde204851b769dbd28b788ffcd67e2331dc847455b613b226ae2cf2a7e2f2a4a0d82
6
+ metadata.gz: 995c284d71146d52d554e8eff18e48605e76546ebce9428674d1fcefe4c560a73973651f4eb4496d21a839fb35944c37f98cc21eb78ddd1e1eea80a57d1392c4
7
+ data.tar.gz: a2e400ead572f31c614a294f1d5d10116e08fa6f152b2f58cf112da45608a3d72be2c5893ceb035c8a6f514af8ef55bcfdffd0a55a81a2e0f97ad43fd0699cf2
data/README.md CHANGED
@@ -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
@@ -51,7 +51,7 @@ module Mongoid
51
51
  @association[:order] = association_field_name.to_s
52
52
  @expectation_message << " ordered by #{@association[:order].inspect}"
53
53
 
54
- if association_field_name.is_a? Mongoid::Criteria::Queryable::Key
54
+ if association_field_name.is_a? association_kind_of
55
55
  @association[:order_operator] = association_field_name.operator
56
56
  @expectation_message << " #{order_way(@association[:order_operator])}"
57
57
  end
@@ -119,6 +119,12 @@ module Mongoid
119
119
  self
120
120
  end
121
121
 
122
+ def with_optional
123
+ @association[:optional] = true
124
+ @expectation_message << " which specifies optional as #{@association[:optional]}"
125
+ self
126
+ end
127
+
122
128
  def matches?(actual)
123
129
  @actual = actual.is_a?(Class) ? actual : actual.class
124
130
  metadata = @actual.relations[@association[:name]]
@@ -266,6 +272,15 @@ module Mongoid
266
272
  end
267
273
  end
268
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
+
269
284
  true
270
285
  end
271
286
 
@@ -311,6 +326,10 @@ module Mongoid
311
326
  def order_way(operator)
312
327
  [nil, 'ascending', 'descending'][operator]
313
328
  end
329
+
330
+ def association_kind_of
331
+ Mongoid::Compatibility::Version.mongoid5_or_older? ? Origin::Key : Mongoid::Criteria::Queryable::Key
332
+ end
314
333
  end
315
334
 
316
335
  def embed_one(association_name)
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module RSpec
3
- VERSION = '4.0.1'.freeze
3
+ VERSION = '4.1.0'.freeze
4
4
  end
5
5
  end
@@ -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' }
@@ -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
 
@@ -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,10 +39,16 @@ RSpec.describe 'Associations' do
39
39
  end
40
40
 
41
41
  describe Site do
42
- if Mongoid::Compatibility::Version.mongoid6?
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
44
  elsif Mongoid::Compatibility::Version.mongoid7_or_newer?
45
45
  it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.desc) }
46
46
  end
47
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
48
54
  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: 4.0.1
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-06-18 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
@@ -40,7 +40,21 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
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.5.1
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
+ - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: 0.5.1
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'
84
126
  description: RSpec matches for Mongoid models, including association and validation
85
127
  matchers.
86
128
  email: evansagge@gmail.com contato@rodrigopinto.me
@@ -159,31 +201,30 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
201
  - !ruby/object:Gem::Version
160
202
  version: 1.3.6
161
203
  requirements: []
162
- rubyforge_project: mongoid-rspec
163
- rubygems_version: 2.6.13
204
+ rubygems_version: 3.1.3
164
205
  signing_key:
165
206
  specification_version: 4
166
207
  summary: RSpec matchers for Mongoid
167
208
  test_files:
168
- - spec/models/article.rb
169
- - spec/models/comment.rb
170
- - spec/models/log.rb
171
- - spec/models/message.rb
172
- - spec/models/movie_article.rb
173
- - spec/models/permalink.rb
174
- - spec/models/person.rb
175
- - spec/models/profile.rb
176
- - spec/models/record.rb
177
- - spec/models/site.rb
178
- - spec/models/user.rb
179
209
  - spec/spec_helper.rb
180
- - spec/unit/accept_nested_attributes_spec.rb
181
210
  - spec/unit/associations_spec.rb
182
211
  - spec/unit/be_dynamic_document_spec.rb
183
- - spec/unit/be_mongoid_document_spec.rb
212
+ - spec/unit/validations_spec.rb
184
213
  - spec/unit/be_stored_in.rb
185
- - spec/unit/document_spec.rb
186
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
187
218
  - spec/unit/have_timestamps_spec.rb
188
- - 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
189
230
  - spec/validators/ssn_validator.rb