mongoid-rspec 1.13.0 → 2.0.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
  SHA1:
3
- metadata.gz: 9a4c1a2239f0fe2d5fa2e91f8c33d3e481700810
4
- data.tar.gz: 8c6e6f83f5a1d01d5ee9820fb56e76913f568dbd
3
+ metadata.gz: 22432282a4af9711e7ff58260bd7e9ccf7279a31
4
+ data.tar.gz: c183931632e9cdd7594ab6314678f3ca6f76f849
5
5
  SHA512:
6
- metadata.gz: 51b893ad1bf9837b1c7e5183cd4033be0397953b90169852cdad26a26388b60e193d834bc035eb274ef4c6434a02c4f2c75e8eee72534fb88cc53b035465edc2
7
- data.tar.gz: 8d35fbfdb8b35e44050330f06fa00e98cb3670a1fe444159d12e182f1f50efdc11616de71d0685dc49d6a128104964ed9c08d08d8e71a2a0653c641e1ded6c97
6
+ metadata.gz: 1b3752eba793b316c4d0ccc611c4b6d9e8b766ceb43617a92185899c90839e4e9067dabe7b9b274868e85434c2c209189bb2278cbd7e644c51c8c7ecfcb83470
7
+ data.tar.gz: 69ac5c4fe2ddf2626021c2776e311394fc8a709713f926e16bb4ca4c3e58906d1f9880510d594c5887c4645155a285c8237e44b91082da7e2b32a4745a5321d3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.0
1
+ 2.2.0
data/.travis.yml CHANGED
@@ -2,11 +2,9 @@ services: mongodb
2
2
  language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
7
- - 2.1.2
8
5
  - 2.1.3
9
6
  - 2.2.0
10
7
  - jruby-19mode
8
+
11
9
  gemfile:
12
10
  - Gemfile
data/README.md CHANGED
@@ -1,19 +1,35 @@
1
- mongoid-rspec
2
- =
1
+ # mongoid-rspec
3
2
 
4
3
  [![Build Status][travis_badge]][travis]
4
+ [![Gem Version][rubygems_badge]][rubygems]
5
+ [![Code Climate][codeclimate_badge]][codeclimate]
5
6
 
6
- RSpec matchers for Mongoid 3.x.
7
+ mongoid-rspec provides a collection of RSpec-compatible matchers that help to test mongoid documents.
7
8
 
8
- For Mongoid 2.x, use [mongoid-rspec 1.4.5](http://rubygems.org/gems/mongoid-rspec/versions/1.4.5)
9
+ ## Installation
9
10
 
10
- Installation
11
- -
12
- Add to your Gemfile
11
+ ### With Mongoid 4.x
13
12
 
14
- gem 'mongoid-rspec'
13
+ Use mongoid-rspec [2.0.0.rc1][mongo4]
15
14
 
16
- Drop in existing or dedicated support file in spec/support (spec/support/mongoid.rb)
15
+ gem 'mongoid-rspec', '~> 2.0.0.rc1'
16
+
17
+ ### With Mongoid 3.x
18
+
19
+ Use mongoid-rspec [1.11.0][mongo3].
20
+
21
+ gem 'mongoid-rspec', '~> 1.11.0'
22
+
23
+ ### With Mongoid 2.x
24
+
25
+ Use mongoid-rspec [1.4.5][mongo2]
26
+
27
+ gem 'mongoid-rspec', '1.4.5'
28
+
29
+ ### Configuring
30
+
31
+ Drop in existing or dedicated support file in spec/support.
32
+ i.e: `spec/support/mongoid.rb`
17
33
 
18
34
  ```ruby
19
35
  RSpec.configure do |config|
@@ -21,8 +37,9 @@ RSpec.configure do |config|
21
37
  end
22
38
  ```
23
39
 
24
- Association Matchers
25
- -
40
+ ## Matchers
41
+
42
+ ### Association Matchers
26
43
 
27
44
  ```ruby
28
45
  describe User do
@@ -69,8 +86,7 @@ describe Site do
69
86
  end
70
87
  ```
71
88
 
72
- Mass Assignment Matcher
73
- -
89
+ ### Mass Assignment Matcher
74
90
 
75
91
  ```ruby
76
92
  describe User do
@@ -85,8 +101,7 @@ describe User do
85
101
  end
86
102
  ```
87
103
 
88
- Validation Matchers
89
- -
104
+ ### Validation Matchers
90
105
 
91
106
  ```ruby
92
107
  describe Site do
@@ -131,8 +146,7 @@ describe Person do
131
146
  end
132
147
  ```
133
148
 
134
- Accepts Nested Attributes Matcher
135
- -
149
+ ### Accepts Nested Attributes Matcher
136
150
 
137
151
  ```ruby
138
152
  describe User do
@@ -145,8 +159,7 @@ describe Article do
145
159
  end
146
160
  ```
147
161
 
148
- Index Matcher
149
- -
162
+ ### Index Matcher
150
163
 
151
164
  ```ruby
152
165
  describe Article do
@@ -159,8 +172,7 @@ describe Profile do
159
172
  end
160
173
  ```
161
174
 
162
- Others
163
- -
175
+ ### Others
164
176
 
165
177
  ```ruby
166
178
  describe User do
@@ -191,17 +203,26 @@ describe Article do
191
203
  end
192
204
  ```
193
205
 
194
- Known issues
195
- -
206
+ ## Known issues
196
207
 
197
- accept_nested_attributes_for matcher must test options [issue 91](https://github.com/evansagge/mongoid-rspec/issues/91).
208
+ accept_nested_attributes_for matcher must test options [issue 91](https://github.com/mongoid-rspec/mongoid-rspec/issues/91).
198
209
 
199
- Acknowledgement
200
- -
201
- Thanks to [Durran Jordan](https://github.com/durran) for providing the changes necessary to make
202
- this compatible with mongoid 2.0.0.rc, and for other [contributors](https://github.com/evansagge/mongoid-rspec/contributors)
210
+ ## Acknowledgement
211
+
212
+ Thanks to [Durran Jordan][durran] for providing the changes necessary to make
213
+ this compatible with mongoid 2.0.0.rc, and for other [contributors](https://github.com/mongoid-rspec/mongoid-rspec/contributors)
203
214
  to this project.
204
215
 
216
+ [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
205
220
 
206
- [travis_badge]: https://travis-ci.org/mongoid-rspec/mongoid-rspec.svg?branch=mongoid-3-1
221
+ [travis_badge]: http://img.shields.io/travis/mongoid-rspec/mongoid-rspec.svg?style=flat
207
222
  [travis]: https://travis-ci.org/mongoid-rspec/mongoid-rspec
223
+
224
+ [rubygems_badge]: http://img.shields.io/gem/v/mongoid-rspec.svg?style=flat
225
+ [rubygems]: http://rubygems.org/gems/mongoid-rspec
226
+
227
+ [codeclimate_badge]: http://img.shields.io/codeclimate/github/mongoid-rspec/mongoid-rspec.svg?style=flat
228
+ [codeclimate]: https://codeclimate.com/github/mongoid-rspec/mongoid-rspec
@@ -13,13 +13,31 @@ module Mongoid
13
13
  def matches?(klass)
14
14
  @klass = klass.is_a?(Class) ? klass : klass.class
15
15
  @errors = []
16
- unless @klass.index_options[@index_fields]
17
- @errors.push "no index for #{@index_fields}"
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
27
+ end
28
+ end
29
+ end
18
30
  else
19
- if !@options.nil? && !@options.empty?
20
- @options.each do |option, option_value|
21
- if denormalising_options(@klass.index_options[@index_fields])[option] != option_value
22
- @errors.push "index for #{@index_fields.inspect} with options of #{@klass.index_options[@index_fields].inspect}"
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
23
41
  end
24
42
  end
25
43
  end
@@ -7,7 +7,7 @@ module Mongoid
7
7
  end
8
8
 
9
9
  def to_allow(*values)
10
- @allowed_values = values.map(&:to_a).flatten
10
+ @allowed_values = values.map { |v| v.respond_to?(:to_a) ? v.to_a : v }.flatten
11
11
  self
12
12
  end
13
13
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Rspec
3
- VERSION = "1.13.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "mongoid-rspec"
7
7
  s.version = Mongoid::Rspec::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Evan Sagge"]
10
- s.email = %q{evansagge@gmail.com}
11
- s.homepage = %q{http://github.com/evansagge/mongoid-rspec}
9
+ s.authors = ["Evan Sagge", "Rodrigo Pinto"]
10
+ s.email = %q{evansagge@gmail.com contato@rodrigopinto.me}
11
+ s.homepage = %q{http://github.com/mongoid-rspec/mongoid-rspec}
12
12
  s.summary = %q{RSpec matchers for Mongoid}
13
13
  s.description = %q{RSpec matches for Mongoid models, including association and validation matchers}
14
14
 
@@ -20,6 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency 'rake'
23
- s.add_dependency 'mongoid', '~> 3.1'
23
+ s.add_dependency 'mongoid', '~> 4.0.0'
24
24
  s.add_dependency 'rspec', '~> 3.1'
25
25
  end
@@ -1,9 +1,6 @@
1
1
  class Article
2
2
  include Mongoid::Document
3
3
  include Mongoid::Timestamps
4
- include Mongoid::Paranoia
5
- include Mongoid::Versioning
6
- include Mongoid::MultiParameterAttributes
7
4
 
8
5
  field :title, localize: true
9
6
  field :content
data/spec/models/user.rb CHANGED
@@ -18,7 +18,7 @@ class User
18
18
 
19
19
  embeds_one :profile
20
20
 
21
- validates :login, presence: true, uniqueness: { scope: :site }, format: { with: /^[\w\-]+$/ }, exclusion: { in: ["super", "index", "edit"] }
21
+ validates :login, presence: true, uniqueness: { scope: :site }, format: { with: /\A[\w\-]+\z/ }, exclusion: { in: ["super", "index", "edit"] }
22
22
  validates :email, uniqueness: { case_sensitive: false, scope: :site, message: "is already taken" }, confirmation: true
23
23
  validates :role, presence: true, inclusion: { in: ["admin", "moderator", "member"] }
24
24
  validates :profile, presence: true, associated: true
@@ -28,9 +28,6 @@ class User
28
28
  validates :provider_uid, presence: true
29
29
  validates :locale, inclusion: { in: ->(user) { [:en, :ru] } }
30
30
 
31
- attr_accessible :login, :email, :age, :password
32
- attr_accessible :role, as: :admin
33
-
34
31
  accepts_nested_attributes_for :articles, :comments
35
32
 
36
33
  def admin?
@@ -9,16 +9,13 @@ describe "Document" do
9
9
  end
10
10
 
11
11
  describe Article do
12
- it { should have_field(:published).of_type(Boolean).with_default_value_of(false) }
13
- it { should have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
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
14
  it { should belong_to(:author) }
15
15
  it { should have_field(:title).localized }
16
- it { should_not have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
16
+ it { should_not have_field(:allow_comments).of_type(Mongoid::Boolean).with_default_value_of(false) }
17
17
  it { should_not have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
18
18
  it { should be_mongoid_document }
19
- it { should be_versioned_document }
20
19
  it { should be_timestamped_document }
21
- it { should be_paranoid_document }
22
- it { should be_multiparameted_document }
23
20
  end
24
21
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Indexes" do
4
4
  describe Article do
5
5
  it { should have_index_for(published: 1) }
6
- it { should have_index_for(title: 1).with_options(unique: true, background: true, drop_dups: true) }
6
+ it { should have_index_for(title: 1).with_options(unique: true, background: true, dropDups: true) }
7
7
  it { should have_index_for('permalink._id' => 1) }
8
8
  end
9
9
 
@@ -15,6 +15,7 @@ describe "Validations" do
15
15
  it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
16
16
  it { should validate_exclusion_of(:password).to_not_allow("password") }
17
17
  it { should validate_inclusion_of(:role).to_allow("admin", "member") }
18
+ it { should validate_inclusion_of(:role).to_allow(["admin", "member"]) }
18
19
  it { should validate_confirmation_of(:email) }
19
20
  it { should validate_presence_of(:age).on(:create, :update) }
20
21
  it { should validate_numericality_of(:age).on(:create, :update) }
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Sagge
8
+ - Rodrigo Pinto
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
@@ -30,14 +31,14 @@ dependencies:
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '3.1'
34
+ version: 4.0.0
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '3.1'
41
+ version: 4.0.0
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rspec
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +55,7 @@ dependencies:
54
55
  version: '3.1'
55
56
  description: RSpec matches for Mongoid models, including association and validation
56
57
  matchers
57
- email: evansagge@gmail.com
58
+ email: evansagge@gmail.com contato@rodrigopinto.me
58
59
  executables: []
59
60
  extensions: []
60
61
  extra_rdoc_files: []
@@ -103,14 +104,13 @@ files:
103
104
  - spec/models/user.rb
104
105
  - spec/spec_helper.rb
105
106
  - spec/unit/accept_nested_attributes_spec.rb
106
- - spec/unit/allow_mass_assignment_spec.rb
107
107
  - spec/unit/associations_spec.rb
108
108
  - spec/unit/collections_spec.rb
109
109
  - spec/unit/document_spec.rb
110
110
  - spec/unit/indexes_spec.rb
111
111
  - spec/unit/validations_spec.rb
112
112
  - spec/validators/ssn_validator.rb
113
- homepage: http://github.com/evansagge/mongoid-rspec
113
+ homepage: http://github.com/mongoid-rspec/mongoid-rspec
114
114
  licenses: []
115
115
  metadata: {}
116
116
  post_install_message:
@@ -146,7 +146,6 @@ test_files:
146
146
  - spec/models/user.rb
147
147
  - spec/spec_helper.rb
148
148
  - spec/unit/accept_nested_attributes_spec.rb
149
- - spec/unit/allow_mass_assignment_spec.rb
150
149
  - spec/unit/associations_spec.rb
151
150
  - spec/unit/collections_spec.rb
152
151
  - spec/unit/document_spec.rb
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "AllowMassAssignment" do
4
- describe User do
5
- it { should allow_mass_assignment_of(:login) }
6
- it { should allow_mass_assignment_of(:email) }
7
- it { should allow_mass_assignment_of(:age) }
8
- it { should allow_mass_assignment_of(:password) }
9
- it { should allow_mass_assignment_of(:password) }
10
- it { should allow_mass_assignment_of(:role).as(:admin) }
11
-
12
- it { should_not allow_mass_assignment_of(:role) }
13
- end
14
- end