mongoid-rspec 4.0.0 → 4.0.1

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
- SHA256:
3
- metadata.gz: 25fcea5e8cc5e8f247b099f60276d560a83c2538e47856a8063f6fae57bffa37
4
- data.tar.gz: 291d75e35f982c38b7c58787d6127a0d693e850f3ef1840f02d45963304ad2c1
2
+ SHA1:
3
+ metadata.gz: 801c33ba9bd350eeb1595c57509601084b983ae5
4
+ data.tar.gz: 1f47a9a328b9d58e5cdaaebf7dbfd91420ed4ca7
5
5
  SHA512:
6
- metadata.gz: f53b92e750ceba490eecd7c492b6ffd967131566ffc228c887a35f3e202d75a337a7903cd1b35717e54243906e582306773e2b849f0aea9462448351b58e0594
7
- data.tar.gz: d4e252e36a4b77b17b081e0e58176776c6c337a871864c1f805514c9da45cb8d0607fa42e518d08c28ecb8ce419008b1b85c4d07c2ee9f5c627642926775a324
6
+ metadata.gz: 91cf1c6e8b0d356bbece0657fe9f5cf1df218f8ec5fa9171a96dd2cef02781654390bcd47f6bea9e62192564d144c1489541dcb54bcc016c596e73578f1b4d18
7
+ data.tar.gz: af5c81412000da22a464b6982dab00e652b34c052ca46cc3fb596439c3e7dde204851b769dbd28b788ffcd67e2331dc847455b613b226ae2cf2a7e2f2a4a0d82
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
 
@@ -290,6 +290,7 @@ end
290
290
 
291
291
  RSpec.describe Article do
292
292
  it { is_expected.to validate_length_of(:title).within(8..16) }
293
+ it { is_expected.to validate_absence_of(:deletion_date) }
293
294
  end
294
295
 
295
296
  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)
@@ -116,7 +130,11 @@ module Mongoid
116
130
  @positive_result_message = "association named #{@association[:name]}"
117
131
  end
118
132
 
119
- relation = metadata.relation
133
+ relation = if Mongoid::Compatibility::Version.mongoid7_or_newer?
134
+ metadata.class
135
+ else
136
+ metadata.relation
137
+ end
120
138
  if relation != @association[:type]
121
139
  @negative_result_message = "#{@actual.inspect} #{type_description(relation, false)} #{@association[:name]}"
122
140
  return false
@@ -222,11 +240,11 @@ module Mongoid
222
240
  end
223
241
 
224
242
  if @association[:index]
225
- if metadata.index != true
243
+ if metadata.indexed?
244
+ @positive_result_message = "#{@positive_result_message} which set index"
245
+ else
226
246
  @negative_result_message = "#{@positive_result_message} which did not set index"
227
247
  return false
228
- else
229
- @positive_result_message = "#{@positive_result_message} which set index"
230
248
  end
231
249
  end
232
250
 
@@ -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
@@ -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'
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module RSpec
3
- VERSION = '4.0.0'.freeze
3
+ VERSION = '4.0.1'.freeze
4
4
  end
5
5
  end
@@ -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)
@@ -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
@@ -39,8 +39,10 @@ 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?
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) }
44
46
  end
45
47
  end
46
48
  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.0.1
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: 2018-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -31,14 +31,14 @@ 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
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: 0.5.1
77
77
  type: :runtime
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: '0'
83
+ version: 0.5.1
84
84
  description: RSpec matches for Mongoid models, including association and validation
85
85
  matchers.
86
86
  email: evansagge@gmail.com contato@rodrigopinto.me
@@ -103,6 +103,7 @@ files:
103
103
  - lib/matchers/indexes/v3/have_index_for.rb
104
104
  - lib/matchers/indexes/v4/have_index_for.rb
105
105
  - lib/matchers/validations.rb
106
+ - lib/matchers/validations/absence_of.rb
106
107
  - lib/matchers/validations/acceptance_of.rb
107
108
  - lib/matchers/validations/associated.rb
108
109
  - lib/matchers/validations/confirmation_of.rb
@@ -159,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
160
  version: 1.3.6
160
161
  requirements: []
161
162
  rubyforge_project: mongoid-rspec
162
- rubygems_version: 2.7.3
163
+ rubygems_version: 2.6.13
163
164
  signing_key:
164
165
  specification_version: 4
165
166
  summary: RSpec matchers for Mongoid