mongoid-rspec 2.0.0 → 2.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
2
  SHA1:
3
- metadata.gz: 22432282a4af9711e7ff58260bd7e9ccf7279a31
4
- data.tar.gz: c183931632e9cdd7594ab6314678f3ca6f76f849
3
+ metadata.gz: 644aca9f2b61c8979ce8eb90856a3d7db324e506
4
+ data.tar.gz: 8f428ac11869473c94207866056850ceb113246a
5
5
  SHA512:
6
- metadata.gz: 1b3752eba793b316c4d0ccc611c4b6d9e8b766ceb43617a92185899c90839e4e9067dabe7b9b274868e85434c2c209189bb2278cbd7e644c51c8c7ecfcb83470
7
- data.tar.gz: 69ac5c4fe2ddf2626021c2776e311394fc8a709713f926e16bb4ca4c3e58906d1f9880510d594c5887c4645155a285c8237e44b91082da7e2b32a4745a5321d3
6
+ metadata.gz: bb156c8186d891023ed5b423635aef4c673b150728372648cec95de064c72bc7fea35007ea1895d4002f880d787779dddcd9be0ce6304b68dfcdf0554a8aa8d6
7
+ data.tar.gz: 83b4e63454cc912622c081fc67b0ff0185bb4b612676ad9ec2e7c7240d39f066fa94fe023066a968ca3c848ac21df4dcfd84c6b29c595894ecb7e35dc716f2e6
data/README.md CHANGED
@@ -10,19 +10,19 @@ mongoid-rspec provides a collection of RSpec-compatible matchers that help to te
10
10
 
11
11
  ### With Mongoid 4.x
12
12
 
13
- Use mongoid-rspec [2.0.0.rc1][mongo4]
13
+ Use mongoid-rspec [2.1.0][mongoid4]
14
14
 
15
- gem 'mongoid-rspec', '~> 2.0.0.rc1'
15
+ gem 'mongoid-rspec', '~> 2.1.0'
16
16
 
17
17
  ### With Mongoid 3.x
18
18
 
19
- Use mongoid-rspec [1.11.0][mongo3].
19
+ Use mongoid-rspec [1.13.0][mongoid3].
20
20
 
21
- gem 'mongoid-rspec', '~> 1.11.0'
21
+ gem 'mongoid-rspec', '~> 1.13.0'
22
22
 
23
23
  ### With Mongoid 2.x
24
24
 
25
- Use mongoid-rspec [1.4.5][mongo2]
25
+ Use mongoid-rspec [1.4.5][mongoid2]
26
26
 
27
27
  gem 'mongoid-rspec', '1.4.5'
28
28
 
@@ -37,169 +37,177 @@ RSpec.configure do |config|
37
37
  end
38
38
  ```
39
39
 
40
+ If you aren't using rails then you don't have to specify the type.
41
+ If you want to know why visit [the rspec documentation](https://relishapp.com/rspec/rspec-rails/docs/directory-structure).
42
+
40
43
  ## Matchers
41
44
 
42
45
  ### Association Matchers
43
46
 
44
47
  ```ruby
45
- describe User do
46
- it { should have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
48
+ RSpec.describe User do
49
+ it { is_expected.to have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
47
50
 
48
- it { should have_one(:record) }
51
+ it { is_expected.to have_one(:record) }
49
52
  #can verify autobuild is set to true
50
- it { should have_one(:record).with_autobuild }
53
+ it { is_expected.to have_one(:record).with_autobuild }
51
54
 
52
- it { should have_many :comments }
55
+ it { is_expected.to have_many :comments }
53
56
 
54
57
  #can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
55
- it { should have_many(:comments).with_dependent(:destroy) }
58
+ it { is_expected.to have_many(:comments).with_dependent(:destroy) }
56
59
  #can verify autosave is set to true
57
- it { should have_many(:comments).with_autosave }
60
+ it { is_expected.to have_many(:comments).with_autosave }
58
61
 
59
- it { should embed_one :profile }
62
+ it { is_expected.to embed_one :profile }
60
63
 
61
- it { should have_and_belong_to_many(:children) }
62
- it { should have_and_belong_to_many(:children).of_type(User) }
64
+ it { is_expected.to have_and_belong_to_many(:children) }
65
+ it { is_expected.to have_and_belong_to_many(:children).of_type(User) }
63
66
  end
64
67
 
65
- describe Profile do
66
- it { should be_embedded_in(:user).as_inverse_of(:profile) }
68
+ RSpec.describe Profile do
69
+ it { is_expected.to be_embedded_in(:user).as_inverse_of(:profile) }
67
70
  end
68
71
 
69
- describe Article do
70
- it { should belong_to(:author).of_type(User).as_inverse_of(:articles) }
71
- it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
72
- it { should embed_many(:comments) }
72
+ RSpec.describe Article do
73
+ it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles) }
74
+ it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
75
+ it { is_expected.to embed_many(:comments) }
73
76
  end
74
77
 
75
- describe Comment do
76
- it { should be_embedded_in(:article).as_inverse_of(:comments) }
77
- it { should belong_to(:user).as_inverse_of(:comments) }
78
+ RSpec.describe Comment do
79
+ it { is_expected.to be_embedded_in(:article).as_inverse_of(:comments) }
80
+ it { is_expected.to belong_to(:user).as_inverse_of(:comments) }
78
81
  end
79
82
 
80
- describe Record do
81
- it { should belong_to(:user).as_inverse_of(:record) }
83
+ RSpec.describe Record do
84
+ it { is_expected.to belong_to(:user).as_inverse_of(:record) }
82
85
  end
83
86
 
84
- describe Site do
85
- it { should have_many(:users).as_inverse_of(:site).ordered_by(:email.asc) }
87
+ RSpec.describe Site do
88
+ it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.asc).with_counter_cache }
86
89
  end
87
90
  ```
88
91
 
89
92
  ### Mass Assignment Matcher
90
93
 
91
94
  ```ruby
92
- describe User do
93
- it { should allow_mass_assignment_of(:login) }
94
- it { should allow_mass_assignment_of(:email) }
95
- it { should allow_mass_assignment_of(:age) }
96
- it { should allow_mass_assignment_of(:password) }
97
- it { should allow_mass_assignment_of(:password) }
98
- it { should allow_mass_assignment_of(:role).as(:admin) }
95
+ RSpec.describe User do
96
+ it { is_expected.to allow_mass_assignment_of(:login) }
97
+ it { is_expected.to allow_mass_assignment_of(:email) }
98
+ it { is_expected.to allow_mass_assignment_of(:age) }
99
+ it { is_expected.to allow_mass_assignment_of(:password) }
100
+ it { is_expected.to allow_mass_assignment_of(:password) }
101
+ it { is_expected.to allow_mass_assignment_of(:role).as(:admin) }
99
102
 
100
- it { should_not allow_mass_assignment_of(:role) }
103
+ it { is_expected.not_to allow_mass_assignment_of(:role) }
101
104
  end
102
105
  ```
103
106
 
104
107
  ### Validation Matchers
105
108
 
106
109
  ```ruby
107
- describe Site do
108
- it { should validate_presence_of(:name) }
109
- it { should validate_uniqueness_of(:name) }
110
+ RSpec.describe Site do
111
+ it { is_expected.to validate_presence_of(:name) }
112
+ it { is_expected.to validate_uniqueness_of(:name) }
110
113
  end
111
114
 
112
- describe User do
113
- it { should validate_presence_of(:login) }
114
- it { should validate_uniqueness_of(:login).scoped_to(:site) }
115
- it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
116
- it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
117
- it { should validate_associated(:profile) }
118
- it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
119
- it { should validate_inclusion_of(:role).to_allow("admin", "member") }
120
- it { should validate_confirmation_of(:email) }
121
- it { should validate_presence_of(:age).on(:create, :update) }
122
- it { should validate_numericality_of(:age).on(:create, :update) }
123
- it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
124
- it { should validate_presence_of(:password).on(:create) }
125
- it { should validate_presence_of(:provider_uid).on(:create) }
126
- it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
115
+ RSpec.describe User do
116
+ it { is_expected.to validate_presence_of(:login) }
117
+ it { is_expected.to validate_uniqueness_of(:login).scoped_to(:site) }
118
+ it { is_expected.to validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
119
+ it { is_expected.to validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
120
+ it { is_expected.to validate_associated(:profile) }
121
+ it { is_expected.to validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
122
+ it { is_expected.to validate_inclusion_of(:role).to_allow("admin", "member") }
123
+ it { is_expected.to validate_confirmation_of(:email) }
124
+ it { is_expected.to validate_presence_of(:age).on(:create, :update) }
125
+ it { is_expected.to validate_numericality_of(:age).on(:create, :update) }
126
+ it { is_expected.to validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
127
+ it { is_expected.to validate_presence_of(:password).on(:create) }
128
+ it { is_expected.to validate_presence_of(:provider_uid).on(:create) }
129
+ it { is_expected.to validate_inclusion_of(:locale).to_allow([:en, :ru]) }
127
130
  end
128
131
 
129
- describe Article do
130
- it { should validate_length_of(:title).within(8..16) }
132
+ RSpec.describe Article do
133
+ it { is_expected.to validate_length_of(:title).within(8..16) }
131
134
  end
132
135
 
133
- describe Profile do
134
- it { should validate_numericality_of(:age).greater_than(0) }
136
+ RSpec.describe Profile do
137
+ it { is_expected.to validate_numericality_of(:age).greater_than(0) }
135
138
  end
136
139
 
137
- describe MovieArticle do
138
- it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
139
- it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
140
+ RSpec.describe MovieArticle do
141
+ it { is_expected.to validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
142
+ it { is_expected.to validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
140
143
  end
141
144
 
142
- describe Person do
145
+ RSpec.describe Person do
143
146
  # in order to be able to use the custom_validate matcher, the custom validator class (in this case SsnValidator)
144
147
  # should redefine the kind method to return :custom, i.e. "def self.kind() :custom end"
145
- it { should custom_validate(:ssn).with_validator(SsnValidator) }
148
+ it { is_expected.to custom_validate(:ssn).with_validator(SsnValidator) }
146
149
  end
147
150
  ```
148
151
 
149
152
  ### Accepts Nested Attributes Matcher
150
153
 
151
154
  ```ruby
152
- describe User do
153
- it { should accept_nested_attributes_for(:articles) }
154
- it { should accept_nested_attributes_for(:comments) }
155
+ RSpec.describe User do
156
+ it { is_expected.to accept_nested_attributes_for(:articles) }
157
+ it { is_expected.to accept_nested_attributes_for(:comments) }
155
158
  end
156
159
 
157
- describe Article do
158
- it { should accept_nested_attributes_for(:permalink) }
160
+ RSpec.describe Article do
161
+ it { is_expected.to accept_nested_attributes_for(:permalink) }
159
162
  end
160
163
  ```
161
164
 
162
165
  ### Index Matcher
163
166
 
164
167
  ```ruby
165
- describe Article do
166
- it { should have_index_for(published: 1) }
167
- it { should have_index_for(title: 1).with_options(unique: true, background: true) }
168
+ RSpec.describe Article do
169
+ it { is_expected.to have_index_for(published: 1) }
170
+ it { is_expected.to have_index_for(title: 1).with_options(unique: true, background: true) }
171
+ end
172
+
173
+ RSpec.describe Profile do
174
+ it { is_expected.to have_index_for(first_name: 1, last_name: 1) }
168
175
  end
169
176
 
170
- describe Profile do
171
- it { should have_index_for(first_name: 1, last_name: 1) }
177
+ Rspec.describe Log do
178
+ it { is_expected.to have_index_for(created_at: 1).with_options(bucket_size: 100, expire_after_seconds: 3600) }
172
179
  end
173
180
  ```
174
181
 
175
182
  ### Others
176
183
 
177
184
  ```ruby
178
- describe User do
179
- it { should have_fields(:email, :login) }
180
- it { should have_field(:s).with_alias(:status) }
181
- it { should have_fields(:birthdate, :registered_at).of_type(DateTime) }
185
+ RSpec.describe User do
186
+ it { is_expected.to have_fields(:email, :login) }
187
+ it { is_expected.to have_field(:s).with_alias(:status) }
188
+ it { is_expected.to have_fields(:birthdate, :registered_at).of_type(DateTime) }
182
189
 
183
190
  # if you're declaring 'include Mongoid::Timestamps'
184
191
  # or any of 'include Mongoid::Timestamps::Created' and 'Mongoid::Timestamps::Updated'
185
- it { should be_timestamped_document }
186
- it { should be_timestamped_document.with(:created) }
187
- it { should_not be_timestamped_document.with(:updated) }
192
+ it { is_expected.to be_timestamped_document }
193
+ it { is_expected.to be_timestamped_document.with(:created) }
194
+ it { is_expected.not_to be_timestamped_document.with(:updated) }
188
195
 
189
- it { should be_versioned_document } # if you're declaring `include Mongoid::Versioning`
190
- it { should be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
191
- it { should be_multiparameted_document } # if you're declaring `include Mongoid::MultiParameterAttributes`
196
+ it { is_expected.to be_versioned_document } # if you're declaring `include Mongoid::Versioning`
197
+ it { is_expected.to be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
198
+ it { is_expected.to be_multiparameted_document } # if you're declaring `include Mongoid::MultiParameterAttributes`
192
199
  end
193
200
 
194
- describe Log do
195
- it { should be_stored_in :logs }
201
+ RSpec.describe Log do
202
+ it { is_expected.to be_stored_in :logs }
203
+ it { is_expected.to be_dynamic_document }
196
204
  end
197
205
 
198
- describe Article do
199
- it { should have_field(:published).of_type(Boolean).with_default_value_of(false) }
200
- it { should have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
201
- it { should_not have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
202
- it { should_not have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
206
+ RSpec.describe Article do
207
+ it { is_expected.to have_field(:published).of_type(Boolean).with_default_value_of(false) }
208
+ it { is_expected.to have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
209
+ it { is_expected.not_to have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
210
+ it { is_expected.not_to have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
203
211
  end
204
212
  ```
205
213
 
@@ -214,9 +222,9 @@ this compatible with mongoid 2.0.0.rc, and for other [contributors](https://gith
214
222
  to this project.
215
223
 
216
224
  [durran]: https://github.com/durran
217
- [mongo2]: http://rubygems.org/gems/mongoid-rspec/versions/1.4.5
218
- [mongo3]: http://rubygems.org/gems/mongoid-rspec/versions/1.11.0
219
- [mongo4]: http://rubygems.org/gems/mongoid-rspec/versions/2.0.0.rc1
225
+ [mongoid2]: http://rubygems.org/gems/mongoid-rspec/versions/1.4.5
226
+ [mongoid3]: http://rubygems.org/gems/mongoid-rspec/versions/1.13.0
227
+ [mongoid4]: http://rubygems.org/gems/mongoid-rspec/versions/2.0.0
220
228
 
221
229
  [travis_badge]: http://img.shields.io/travis/mongoid-rspec/mongoid-rspec.svg?style=flat
222
230
  [travis]: https://travis-ci.org/mongoid-rspec/mongoid-rspec
@@ -101,6 +101,12 @@ module Mongoid
101
101
  self
102
102
  end
103
103
 
104
+ def with_counter_cache
105
+ @association[:counter_cache] = true
106
+ @expectation_message << " which specifies counter_cache as #{@association[:counter_cache].to_s}"
107
+ self
108
+ end
109
+
104
110
  def matches?(actual)
105
111
  @actual = actual.is_a?(Class) ? actual : actual.class
106
112
  metadata = @actual.relations[@association[:name]]
@@ -235,6 +241,15 @@ module Mongoid
235
241
  end
236
242
  end
237
243
 
244
+ if @association[:counter_cache]
245
+ if metadata.counter_cached? != true
246
+ @negative_result_message = "#{@positive_result_message} which did not set counter_cache"
247
+ return false
248
+ else
249
+ @positive_result_message = "#{@positive_result_message} which set counter_cache"
250
+ end
251
+ end
252
+
238
253
  return true
239
254
  end
240
255
 
@@ -161,3 +161,13 @@ RSpec::Matchers.define :be_multiparameted_document do
161
161
  "be a multiparameted Mongoid document"
162
162
  end
163
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
@@ -14,33 +14,18 @@ module Mongoid
14
14
  @klass = klass.is_a?(Class) ? klass : klass.class
15
15
  @errors = []
16
16
 
17
- if @klass.respond_to?(:index_options)
18
- # Mongoid 3
19
- unless @klass.index_options[@index_fields]
20
- @errors.push "no index for #{@index_fields}"
21
- else
22
- if !@options.nil? && !@options.empty?
23
- @options.each do |option, option_value|
24
- if denormalising_options(@klass.index_options[@index_fields])[option] != option_value
25
- @errors.push "index for #{@index_fields.inspect} with options of #{@klass.index_options[@index_fields].inspect}"
26
- end
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}"
27
24
  end
28
25
  end
29
26
  end
30
27
  else
31
- # Mongoid 4
32
- unless @klass.index_specifications.map(&:key).include?(@index_fields)
33
- @errors.push "no index for #{@index_fields}"
34
- else
35
- if !@options.nil? && !@options.empty?
36
- index_options = @klass.index_specifications.select { |is| is.key == @index_fields }.first.options
37
- @options.each do |option, option_value|
38
- if index_options[option] != option_value
39
- @errors.push "index for #{@index_fields.inspect} with options of #{index_options.inspect}"
40
- end
41
- end
42
- end
43
- end
28
+ @errors.push "no index for #{@index_fields}"
44
29
  end
45
30
 
46
31
  @errors.empty?
@@ -65,15 +50,15 @@ module Mongoid
65
50
 
66
51
  private
67
52
  MAPPINGS = {
68
- dropDups: :drop_dups
53
+ dropDups: :drop_dups,
54
+ expireAfterSeconds: :expire_after_seconds,
55
+ bucketSize: :bucket_size
69
56
  }
70
57
 
71
- def denormalising_options(opts)
72
- options = {}
73
- opts.each_pair do |option, value|
74
- options[MAPPINGS[option] || option] = value
58
+ def normalize_options(options)
59
+ options.transform_keys do |key|
60
+ MAPPINGS[key] || key
75
61
  end
76
- options
77
62
  end
78
63
  end
79
64
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Rspec
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -1,4 +1,9 @@
1
1
  class Log
2
2
  include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Attributes::Dynamic
5
+
3
6
  store_in collection: "logs"
4
- end
7
+
8
+ index({ created_at: 1 }, { bucket_size: 100, expire_after_seconds: 3600 } )
9
+ end
@@ -3,7 +3,7 @@ class Site
3
3
 
4
4
  field :name
5
5
 
6
- has_many :users, inverse_of: :site, order: :email.desc
6
+ has_many :users, inverse_of: :site, order: :email.desc, counter_cache: true
7
7
 
8
8
  validates :name, presence: true, uniqueness: true
9
- end
9
+ end
@@ -29,4 +29,5 @@ RSpec.configure do |config|
29
29
  config.after :all do
30
30
  Mongoid::Config.purge!
31
31
  end
32
+ config.disable_monkey_patching!
32
33
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "AcceptsNestedAttributes" do
3
+ RSpec.describe "AcceptsNestedAttributes" do
4
4
  describe User do
5
- it { should accept_nested_attributes_for(:articles) }
6
- it { should accept_nested_attributes_for(:comments) }
5
+ it { is_expected.to accept_nested_attributes_for(:articles) }
6
+ it { is_expected.to accept_nested_attributes_for(:comments) }
7
7
  end
8
8
 
9
9
  describe Article do
10
- it { should accept_nested_attributes_for(:permalink) }
10
+ it { is_expected.to accept_nested_attributes_for(:permalink) }
11
11
  end
12
- end
12
+ end
@@ -1,42 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Associations" do
3
+ RSpec.describe "Associations" do
4
4
  describe User do
5
- it { should have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
5
+ it { is_expected.to have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
6
6
 
7
- it { should have_one(:record).with_autobuild }
7
+ it { is_expected.to have_one(:record).with_autobuild }
8
8
 
9
- it { should have_many(:comments).with_dependent(:destroy).with_autosave }
9
+ it { is_expected.to have_many(:comments).with_dependent(:destroy).with_autosave }
10
10
 
11
- it { should embed_one(:profile) }
11
+ it { is_expected.to embed_one(:profile) }
12
12
 
13
- it { should have_and_belong_to_many(:children).of_type(User) }
13
+ it { is_expected.to have_and_belong_to_many(:children).of_type(User) }
14
14
  end
15
15
 
16
16
  describe Profile do
17
- it { should be_embedded_in(:user).as_inverse_of(:profile) }
17
+ it { is_expected.to be_embedded_in(:user).as_inverse_of(:profile) }
18
18
  end
19
19
 
20
20
  describe Article do
21
- it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
22
- it { should embed_many(:comments).with_cascading_callbacks }
23
- it { should embed_one(:permalink) }
21
+ it { is_expected.to belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
22
+ it { is_expected.to embed_many(:comments).with_cascading_callbacks }
23
+ it { is_expected.to embed_one(:permalink) }
24
24
  end
25
25
 
26
26
  describe Comment do
27
- it { should be_embedded_in(:article).as_inverse_of(:comments).with_polymorphism }
28
- it { should belong_to(:user).as_inverse_of(:comments) }
27
+ it { is_expected.to be_embedded_in(:article).as_inverse_of(:comments).with_polymorphism }
28
+ it { is_expected.to belong_to(:user).as_inverse_of(:comments) }
29
29
  end
30
30
 
31
31
  describe Record do
32
- it { should belong_to(:user).as_inverse_of(:record) }
32
+ it { is_expected.to belong_to(:user).as_inverse_of(:record) }
33
33
  end
34
34
 
35
35
  describe Permalink do
36
- it { should be_embedded_in(:linkable).as_inverse_of(:link) }
36
+ it { is_expected.to be_embedded_in(:linkable).as_inverse_of(:link) }
37
37
  end
38
38
 
39
39
  describe Site do
40
- it { should have_many(:users).as_inverse_of(:site).ordered_by(:email.desc) }
40
+ it { is_expected.to have_many(:users).as_inverse_of(:site).ordered_by(:email.desc).with_counter_cache }
41
41
  end
42
42
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Collections" do
3
+ RSpec.describe "Collections" do
4
4
  describe Log do
5
- it { should be_stored_in :logs }
5
+ it { is_expected.to be_stored_in :logs }
6
6
  end
7
- end
7
+ end
@@ -1,21 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Document" do
3
+ RSpec.describe "Document" do
4
4
  describe User do
5
- it { should have_fields(:email, :login) }
6
- it { should be_timestamped_document }
7
- it { should be_timestamped_document.with(:created) }
8
- it { should_not be_timestamped_document.with(:updated) }
5
+ it { is_expected.to have_fields(:email, :login) }
6
+ it { is_expected.to be_timestamped_document }
7
+ it { is_expected.to be_timestamped_document.with(:created) }
8
+ it { is_expected.not_to be_timestamped_document.with(:updated) }
9
9
  end
10
10
 
11
11
  describe Article do
12
- it { should have_field(:published).of_type(Mongoid::Boolean).with_default_value_of(false) }
13
- it { should have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(true) }
14
- it { should belong_to(:author) }
15
- it { should have_field(:title).localized }
16
- it { should_not have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(false) }
17
- it { should_not have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
18
- it { should be_mongoid_document }
19
- it { should be_timestamped_document }
12
+ it { is_expected.to have_field(:published).of_type(Mongoid::Boolean).with_default_value_of(false) }
13
+ it { is_expected.to have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(true) }
14
+ it { is_expected.to belong_to(:author) }
15
+ it { is_expected.to have_field(:title).localized }
16
+ it { is_expected.not_to have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(false) }
17
+ it { is_expected.not_to have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
18
+ it { is_expected.to be_mongoid_document }
19
+ it { is_expected.to be_timestamped_document }
20
+ end
21
+
22
+ describe Log do
23
+ it { is_expected.to be_mongoid_document }
24
+ it { is_expected.to be_dynamic_document }
20
25
  end
21
26
  end
@@ -1,13 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Indexes" do
3
+ RSpec.describe "Indexes" do
4
4
  describe Article do
5
- it { should have_index_for(published: 1) }
6
- it { should have_index_for(title: 1).with_options(unique: true, background: true, dropDups: true) }
7
- it { should have_index_for('permalink._id' => 1) }
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
8
  end
9
9
 
10
10
  describe Profile do
11
- it { should have_index_for(first_name: 1, last_name: 1) }
11
+ it { is_expected.to have_index_for(first_name: 1, last_name: 1) }
12
12
  end
13
- 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
@@ -1,52 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Validations" do
3
+ RSpec.describe "Validations" do
4
4
  describe Site do
5
- it { should validate_presence_of(:name) }
6
- it { should validate_uniqueness_of(:name) }
5
+ it { is_expected.to validate_presence_of(:name) }
6
+ it { is_expected.to validate_uniqueness_of(:name) }
7
7
  end
8
8
 
9
9
  describe User do
10
- it { should validate_presence_of(:login) }
11
- it { should validate_uniqueness_of(:login).scoped_to(:site) }
12
- it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
13
- it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
14
- it { should validate_associated(:profile) }
15
- it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
16
- it { should validate_exclusion_of(:password).to_not_allow("password") }
17
- it { should validate_inclusion_of(:role).to_allow("admin", "member") }
18
- it { should validate_inclusion_of(:role).to_allow(["admin", "member"]) }
19
- it { should validate_confirmation_of(:email) }
20
- it { should validate_presence_of(:age).on(:create, :update) }
21
- it { should validate_numericality_of(:age).on(:create, :update) }
22
- it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
23
- it { should validate_presence_of(:password).on(:create) }
24
- it { should validate_presence_of(:provider_uid).on(:create) }
25
- it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
10
+ it { is_expected.to validate_presence_of(:login) }
11
+ it { is_expected.to validate_uniqueness_of(:login).scoped_to(:site) }
12
+ it { is_expected.to validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
13
+ it { is_expected.to validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
14
+ it { is_expected.to validate_associated(:profile) }
15
+ it { is_expected.to validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
16
+ it { is_expected.to validate_exclusion_of(:password).to_not_allow("password") }
17
+ it { is_expected.to validate_inclusion_of(:role).to_allow("admin", "member") }
18
+ it { is_expected.to validate_inclusion_of(:role).to_allow(["admin", "member"]) }
19
+ it { is_expected.to validate_confirmation_of(:email) }
20
+ it { is_expected.to validate_presence_of(:age).on(:create, :update) }
21
+ it { is_expected.to validate_numericality_of(:age).on(:create, :update) }
22
+ it { is_expected.to validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
23
+ it { is_expected.to validate_presence_of(:password).on(:create) }
24
+ it { is_expected.to validate_presence_of(:provider_uid).on(:create) }
25
+ it { is_expected.to validate_inclusion_of(:locale).to_allow([:en, :ru]) }
26
26
  end
27
27
 
28
28
  describe Profile do
29
- it { should validate_numericality_of(:age).greater_than(0) }
30
- it { should validate_acceptance_of(:terms_of_service) }
31
- it { should validate_length_of(:hobbies).with_minimum(1).with_message("requires at least one hobby") }
29
+ it { is_expected.to validate_numericality_of(:age).greater_than(0) }
30
+ it { is_expected.to validate_acceptance_of(:terms_of_service) }
31
+ it { is_expected.to validate_length_of(:hobbies).with_minimum(1).with_message("requires at least one hobby") }
32
32
  end
33
33
 
34
34
  describe Article do
35
- it { should validate_length_of(:title).within(8..16) }
36
- it { should_not validate_length_of(:content).greater_than(200).less_than(16) }
37
- it { should validate_length_of(:content).greater_than(200) }
38
- it { should validate_inclusion_of(:status).to_allow([:pending]).on( :create ) }
39
- it { should validate_inclusion_of(:status).to_allow([:approved, :rejected]).on( :update ) }
35
+ it { is_expected.to validate_length_of(:title).within(8..16) }
36
+ it { is_expected.not_to validate_length_of(:content).greater_than(200).less_than(16) }
37
+ it { is_expected.to validate_length_of(:content).greater_than(200) }
38
+ it { is_expected.to validate_inclusion_of(:status).to_allow([:pending]).on( :create ) }
39
+ it { is_expected.to validate_inclusion_of(:status).to_allow([:approved, :rejected]).on( :update ) }
40
40
  end
41
41
 
42
42
  describe MovieArticle do
43
- it { should validate_numericality_of(:rating).greater_than(0) }
44
- it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
45
- it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
43
+ it { is_expected.to validate_numericality_of(:rating).greater_than(0) }
44
+ it { is_expected.to validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
45
+ it { is_expected.to validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
46
46
  end
47
47
 
48
48
  describe Person do
49
- it { should custom_validate(:ssn).with_validator(SsnValidator) }
50
- it { should_not custom_validate(:name) }
49
+ it { is_expected.to custom_validate(:ssn).with_validator(SsnValidator) }
50
+ it { is_expected.not_to custom_validate(:name) }
51
51
  end
52
52
  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: 2.0.0
4
+ version: 2.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: 2015-01-05 00:00:00.000000000 Z
12
+ date: 2015-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake