mongoid-minitest 0.1.5 → 1.0.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: fbba88296751c989d9b415ed8657092048c4ac51
4
- data.tar.gz: 812b20db8de722f9fe3d650b4eb242c7a01ab345
3
+ metadata.gz: 8eebdad8b5b9c67d775c9a7b274d277c04685f29
4
+ data.tar.gz: edc782fd5cea7937ffaff2a0eb1458934dab5015
5
5
  SHA512:
6
- metadata.gz: a41749d8ad83925d6ccf311f9d2c318d9f4270c506ebd71146472551bce0d3b0808460351c4d965a0b2ed120d4c1127f6c36c4838422cda0449a268d2cf91c38
7
- data.tar.gz: 364a09c71d33a04baf6d2247900007bac3eabb02e70a4b1fb147a60836f614e9239c3f481544640d9b892443ab4130f0b4ce6fa546d2106cdc6c1175bcb4e4bf
6
+ metadata.gz: 8ca707f22905c2e26a37bbf768a6ba0700df1ba2186470db9187fd555ebf877e1310385a46a9bd498edb54526e0c0b7e29e5dfcc7a35261df827007d90e67196
7
+ data.tar.gz: 36c28d586589aaa40dad9a230b890cd71de33d6dde6c11f4c8af753b85c0399509bbdee21abf97fc95b6f956b3b914e22a764b603eaece40f52be57f3090b070
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem install bundler
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - ruby-head
8
+ - rbx-19mode
9
+ - jruby-19mode
10
+ gemfile:
11
+ - Gemfile
12
+ - Gemfile.edge
data/CHANGELOG.md CHANGED
@@ -1,23 +1,49 @@
1
+ ## 1.0.0 - February 27, 2013
2
+
3
+ + Extract Validation Matchers to [minitest-activemodel](https://github.com/frodsan/minitest-activemodel) gem.
4
+
5
+ Breaking changes:
6
+
7
+ + `validate_format_of(:email).to_allow(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/)` is not supported.
8
+ Use `validate_format_of(:email).to_allow('frodsan@me.com')` instead.
9
+
10
+ *Francesco Rodriguez*
11
+
12
+ + Add support for JRuby 1.9 mode - *Francesco Rodriguez*.
13
+
14
+ + Add support for Ruby 2.0.0, ruby-head and rbx-19mode - *Francesco Rodriguez*.
15
+
16
+ + Add support for Mongoid 4 edge - *Francesco Rodriguez*.
17
+
18
+ + Remove instance variable warnings.
19
+ Pull Request [#17](https://github.com/frodsan/mongoid-minitest/pull/17) - *Ryan McGeary*.
20
+
1
21
  ## 0.1.5 - February 26, 2013
2
22
 
3
23
  + Add Ruby 2.0.0 support - *Francesco Rodriguez*.
24
+
4
25
  + Make mongoid version more flexible in gemspec.
5
26
  Pull Request [#16](https://github.com/frodsan/mongoid-minitest/pull/16) - *Ryan McGeary*.
27
+
6
28
  + Add compound indexes support for `have_index` matcher.
7
29
  Pull Request [#15](https://github.com/frodsan/mongoid-minitest/pull/15) - *Ryan McGeary*.
30
+
8
31
  + Remove support for automatically appending `_id` to fields passed to
9
32
  `have_index` matcher. See <https://github.com/frodsan/mongoid-minitest/pull/15#issuecomment-11851098>
10
- form more information - *Ryan McGeary*.
33
+ for more information - *Ryan McGeary*.
11
34
 
12
35
  ## 0.1.4 - October 10, 2012
13
36
 
14
37
  + Bump mongoid version to 3.0.6 - *Francesco Rodriguez*.
38
+
15
39
  + Bump minitest version to >= 4.0.0 - *Francesco Rodriguez*.
16
40
 
17
41
  ## 0.1.3 - September 8, 2012
18
42
 
19
43
  + Bump mongoid version to 3.0.5 - *Francesco Rodriguez*.
44
+
20
45
  + Bump minitest version to 3.4.0 - *Francesco Rodriguez*.
46
+
21
47
  + Added on option for validation matchers.
22
48
  Pull Request [#14](https://github.com/frodsan/mongoid-minitest/pull/14) - *Godfrey Chan*.
23
49
 
@@ -25,12 +51,16 @@
25
51
 
26
52
  + Allow passing in a Regex to the validate_format_of matcher.
27
53
  Pull Request [#12](https://github.com/frodsan/mongoid-minitest/pull/12) - *Godfrey Chan*.
54
+
28
55
  + Allow non-array values for inclusion/exclusion matchers.
29
56
  Pull Request [#11](https://github.com/frodsan/mongoid-minitest/pull/11) - *Godfrey Chan*.
57
+
30
58
  + Added as_inverse_of for association matchers.
31
59
  Pull Request [#10](https://frodsan/mongoid-minitest/pull/10) - *Godfrey Chan*.
60
+
32
61
  + Use [minitest-matchers](https://github.com/zenspider/minitest-matchers) gem
33
62
  instead of our matchers implementation - *Francesco Rodriguez*.
63
+
34
64
  + Bump mongoid version to 3.0.4 - *Francesco Rodriguez*.
35
65
 
36
66
  ## 0.1.1 - August 09, 2012
@@ -40,6 +70,7 @@
40
70
  ## 0.1.0 - August 09, 2012
41
71
 
42
72
  + Change support to only Ruby 1.9.3.
73
+
43
74
  + Bump mongoid version to 3.0.2 and minitest version to 3.3.0 and minitest version
44
75
  to 3.3.0 - *Sascha Wessel*.
45
76
 
@@ -51,57 +82,103 @@
51
82
  ## 0.0.3 - April 15, 2012
52
83
 
53
84
  + Add `have_index_for(indexed_field)` document matcher.
85
+
54
86
  + Add `embedded_in(association_name)` association matcher.
87
+
55
88
  + Add `embed_many(association_name)` association matcher.
89
+
56
90
  + Fix issue check `association_type` if metadata is not nil.
91
+
57
92
  + Add `embed_one(association_name)` association matcher.
93
+
58
94
  + Add `have_and_belong_to_many(association_name)` association matcher.
95
+
59
96
  + Add `validate_associated(association_name)` validation matcher.
97
+
60
98
  + Add `accept_with(value)` chain matcher to `validate_acceptance_of`.
99
+
61
100
  + Add `validate_acceptance_of(field)` validation matcher.
101
+
62
102
  + Add `validate_confirmation_of(field)` validation matcher.
63
103
 
64
- ## 0.0.2 - April 13, 2012
104
+ ## 0.0.2 - April 13, 2012
65
105
 
66
106
  + Add `have_one(association_name)` association matcher.
107
+
67
108
  + Add `in(range)` alias to `within` matcher.
109
+
68
110
  + Add `within(range)` chain matcher to `validate_length_of`.
111
+
69
112
  + Add `scoped_to(*scope)` chain matcher to `validate_uniqueness_of`
113
+
70
114
  + Add `with_message(custom_message)` chain matcher for validation matchers to test
71
115
  custom messages.
116
+
72
117
  + Add `DocumentModuleMatcher` class to simplify document matchers.
118
+
73
119
  + Add `be_stored_in(collection_name)` document matcher.
120
+
74
121
  + Add `to_allow(values)` chain matcher to `validate_inclusion_of`.
122
+
75
123
  + Add `validate_inclusion_of(field)` validation matcher.
124
+
76
125
  + Add `belong_to(association_name)` association matcher.
77
126
 
127
+
78
128
  ## 0.0.1 - April 12, 2012
79
129
 
80
130
  + Add `of_type(type)` chain matcher to association matcher.
131
+
81
132
  + Add `have_many(association_name)` association matcher.
133
+
82
134
  + Add `Mongoid::Matchers::Associations` module.
135
+
83
136
  + Add `to_not_allow(*values)` chain matcher to `validate_exclusion_of`.
137
+
84
138
  + Add `validate_exclusion_of(field)` validation matcher.
139
+
85
140
  + Add `to_not_allow(*values)` matcher to `validate_format_of`.
141
+
86
142
  + Add `to_allow(*values)` matcher to `validate_format_of`.
143
+
87
144
  + Add `validate_format_of(field)` validation matcher.
145
+
88
146
  + Add `with_max(value)` alias to `with_maximum` matcher.
147
+
89
148
  + Add `with_maximum(value)` chain matcher to `validate_length_of`
149
+
90
150
  + Add `with_min(value)` alias to `with_minimum` matcher.
151
+
91
152
  + Add `with_minimum(value)` matcher to `validate_length_of`.
153
+
92
154
  + Add `validate_length_of(field)` validation matcher.
155
+
93
156
  + Add `case_sensitive` chain matcher to `validate_uniqueness_of`.
157
+
94
158
  + Add `validate_uniqueness_of(field)` validation matcher.
159
+
95
160
  + Add `validate_presence_of(field)` validation matcher.
161
+
96
162
  + Add `have_fields(*fields)` document matcher.
163
+
97
164
  + Add `be_timestamped` document matcher.
165
+
98
166
  + Add `be_versioned` document matcher.
167
+
99
168
  + Add `be_paranoid` document matcher.
169
+
100
170
  + Add `be_document` document matcher.
171
+
101
172
  + Add `with_default_value(default)` chain matcher to `have_field`.
173
+
102
174
  + Add `of_type(type)` chain matcher to `have_field`.
175
+
103
176
  + Add `must` and `wont` methods to `MiniTest::Spec`.
177
+
104
178
  + Add `have_field(field)` document matcher.
179
+
105
180
  + Add default failure messages based on description matcher.
181
+
106
182
  + Add `must` and `wont` expectations.
183
+
107
184
  + Add `assert_must` and `assert_wont` to `MiniTest::Assertions`.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.edge ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'mongoid', github: 'mongoid/mongoid'
6
+ gem 'minitest-activemodel', github: 'frodsan/minitest-activemodel'
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,24 +1,29 @@
1
- # mongoid-minitest
1
+ mongoid-minitest
2
+ ================
2
3
 
3
4
  MiniTest matchers for Mongoid.
4
5
 
5
6
  [![Build Status](https://secure.travis-ci.org/frodsan/mongoid-minitest.png?branch=master&.png)](http://travis-ci.org/frodsan/mongoid-minitest)
7
+ [![Dependency Status](https://gemnasium.com/frodsan/mongoid-minitest.png)](https://gemnasium.com/frodsan/mongoid-minitest)
8
+ [![Code Climate](https://codeclimate.com/github/frodsan/mongoid-minitest.png)](https://codeclimate.com/github/frodsan/mongoid-minitest)
6
9
 
7
- ## Support
10
+ Support
11
+ -------
8
12
 
9
13
  This gem supports:
10
14
 
11
- * Ruby 1.9.3, 2.0.0
12
- * Mongoid ~>3.0
13
- * MiniTest ~>4.1
15
+ * Ruby 1.9.3, 2.0.0, ruby-head, rbx-19mode, jruby-19mode.
16
+ * Mongoid ~>3.0, Mongoid 4.0 edge (Use mongoid/mongoid Github repository).
17
+ * MiniTest ~>4.1.
14
18
 
15
- If you're using Mongoid 2.4.x, you should use [0.0.3.1 version](https://github.com/frodsan/mongoid-minitest/tree/274976e8814cc9bfb3f1c83eba1bed21fa3cf26b).
19
+ **NOTE:** Version 2.0.x will remove support for Mongoid 3.x.
16
20
 
17
- ## Installation
21
+ Installation
22
+ ------------
18
23
 
19
24
  Add this line to your application's Gemfile:
20
25
 
21
- gem 'mongoid-minitest'
26
+ gem 'mongoid-minitest', group: :test
22
27
 
23
28
  And then execute:
24
29
 
@@ -28,7 +33,15 @@ Or install it yourself as:
28
33
 
29
34
  $ gem install mongoid-minitest
30
35
 
31
- ## Usage
36
+ Usage
37
+ -----
38
+
39
+ Require `mongoid-minitest` in your `test_helper.rb` or
40
+ `spec_helper.rb` file:
41
+
42
+ require 'minitest/autorun'
43
+ require 'mongoid'
44
+ require 'mongoid-minitest'
32
45
 
33
46
  Matchers are available at `Mongoid::Matchers` module.
34
47
  Setup matchers according to your testing preference:
@@ -69,29 +82,33 @@ See the following examples:
69
82
  it { wont have_field(:none) }
70
83
  end
71
84
 
72
- ## Matchers
85
+ Matchers
86
+ --------
73
87
 
74
88
  `Mongoid::Matchers` include the following modules:
75
89
 
76
90
  Module Mongoid
77
91
  Module Matchers
78
92
  include Document
79
- include Validations
80
93
  include Associations
94
+ include MiniTest::Matchers::ActiveModel
81
95
  end
82
96
  end
83
97
 
98
+ **NOTE:** [minitest-activemodel](https://github.com/frodsan/minitest-activemodel)
99
+ gem is a dependency of this gem.
100
+
84
101
  ### Document Matchers
85
102
 
86
103
  describe Mongoid::Matchers::Document do
87
104
  subject { Person }
88
105
 
89
106
  it { must be_document } # if model includes Mongoid::Document
90
- it { must be_paranoid } # if model includes Mongoid::Paranoia
91
- it { must be_versioned } # if model includes Mongoid::Versioning
107
+ it { must be_paranoid } # if model includes Mongoid::Paranoia (Only in Mongoid <= 4.0.0)
108
+ it { must be_versioned } # if model includes Mongoid::Versioning (Only in Mongoid <= 4.0.0)
92
109
  it { must be_timestamped } # if model includes Mongoid::Timestamps
93
110
 
94
- it { must be_stored_in(:people) } # checks the collection for model's document
111
+ it { must be_stored_in(:people) } # checks the collection for model's document
95
112
 
96
113
  it { must have_field(:name) }
97
114
  it { must have_field(:name).of_type(String) }
@@ -107,40 +124,6 @@ See the following examples:
107
124
  it { must have_index_for(:account_id, :email) }
108
125
  end
109
126
 
110
- ### Validation Matchers
111
-
112
- describe Mongoid::Matchers::Validations do
113
- subject { Person }
114
-
115
- it { must validate_presence_of(:name) }
116
-
117
- it { must validate_uniqueness_of(:login).case_insensitive }
118
- it { must validate_uniqueness_of(:login).scoped_to(:site) }
119
-
120
- it { must validate_length_of(:login).in(5..12) }
121
- it { must validate_length_of(:login).within(5..12) }
122
-
123
- it { must validate_length_of(:password).with_min(8) }
124
- it { must validate_length_of(:password).with_minimum(8) }
125
- it { must validate_length_of(:password).with_max(16) }
126
- it { must validate_length_of(:password).with_maximum(16) }
127
-
128
- it { must validate_format_of(:email).to_allow("foo@bar.com") }
129
- it { must validate_format_of(:email).to_not_allow("foo_bar_com") }
130
-
131
- it { must validate_inclusion_of(:role).to_allow("user", "admin") }
132
- it { must validate_exclusion_of(:email).to_not_allow("foo@bar.com", "fizz@buzz.com") }
133
-
134
- it { must validate_confirmation_of(:password) }
135
- it { must validate_acceptance_of(:terms_of_use).accept_with("1") }
136
-
137
- it { must validate_associated(:pets) }
138
-
139
- # Testing validators custom messages
140
- it { must validate_presence_of(:role).with_message("no role") }
141
- it { must validate_length_of(:password).with_min(8).with_message("len >= 8") }
142
- end
143
-
144
127
  ### Association Matchers
145
128
 
146
129
  describe Mongoid::Matchers::Associations do
@@ -168,7 +151,13 @@ See the following examples:
168
151
  end
169
152
  end
170
153
 
171
- ## Contributing
154
+ ### Validation Matchers
155
+
156
+ Check [minitest-activemodel](https://github.com/frodsan/minitest-activemodel)
157
+ gem for more information.
158
+
159
+ Contributing
160
+ ------------
172
161
 
173
162
  1. Fork it.
174
163
  2. Create your feature branch (`git checkout -b my-new-feature`).
@@ -176,17 +165,21 @@ See the following examples:
176
165
  4. Push to the branch (`git push origin my-new-feature`).
177
166
  5. Create new Pull Request.
178
167
 
179
- ## Unit Tests
168
+ Unit Tests
169
+ ----------
180
170
 
181
- To run unit tests, run `bundle exec rake`.
171
+ To run unit tests, run `rake test`.
182
172
 
183
- ## Maintainers
173
+ Maintainers
174
+ -----------
184
175
 
185
176
  * Francesco Rodriguez (https://github.com/frodsan/).
186
177
  * Sascha Wessel (https://github.com/gr4y).
187
178
  * Godfrey Chan (https://github.com/chancancode).
179
+ * Ryan McGeary (https://github.com/rmm5t).
188
180
 
189
- ## License
181
+ License
182
+ -------
190
183
 
191
184
  MIT License. Copyright 2012 Francesco Rodriguez. See [LICENSE](https://github.com/frodsan/lego/blob/master/LICENSE)
192
185
  for more information.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.pattern = 'test/*/*_test.rb'
9
+ t.warning = true
10
+ t.verbose = true
11
+ end
12
+
13
+ task default: :test
@@ -10,27 +10,27 @@ module Mongoid
10
10
  EMBEDDED_IN = Mongoid::Relations::Embedded::In
11
11
 
12
12
  class HaveAssociationMatcher < Matcher
13
- def initialize(name, type)
13
+ def initialize name, type
14
14
  @association = {}
15
15
  @association[:name] = name.to_s
16
16
  @association[:type] = type
17
17
  @description = "#{type_description} #{@association[:name].inspect}"
18
18
  end
19
19
 
20
- def of_type(klass)
20
+ def of_type klass
21
21
  @association[:class] = klass
22
22
  @description << " of type #{@association[:class].inspect}"
23
23
  self
24
24
  end
25
25
 
26
- def as_inverse_of(inverse_of)
26
+ def as_inverse_of inverse_of
27
27
  @association[:inverse_of] = inverse_of
28
28
  @description << " as the inverse of #{@association[:inverse_of].inspect}"
29
29
  self
30
30
  end
31
31
 
32
- def matches?(subject)
33
- @klass = class_of(subject)
32
+ def matches? subject
33
+ @klass = class_of subject
34
34
  @metadata = @klass.relations[@association[:name]]
35
35
  @result = true
36
36
 
@@ -96,7 +96,7 @@ module Mongoid
96
96
  end
97
97
  end
98
98
 
99
- def type_description(type = nil, passive = true)
99
+ def type_description type = nil, passive = true
100
100
  type ||= @association[:type]
101
101
  case type.name
102
102
  when HAS_ONE.name
@@ -119,32 +119,32 @@ module Mongoid
119
119
  end
120
120
  end
121
121
 
122
- def have_one(association_name)
123
- HaveAssociationMatcher.new(association_name, HAS_ONE)
122
+ def have_one association_name
123
+ HaveAssociationMatcher.new association_name, HAS_ONE
124
124
  end
125
125
 
126
- def have_many(association_name)
127
- HaveAssociationMatcher.new(association_name, HAS_MANY)
126
+ def have_many association_name
127
+ HaveAssociationMatcher.new association_name, HAS_MANY
128
128
  end
129
129
 
130
- def have_and_belong_to_many(association_name)
131
- HaveAssociationMatcher.new(association_name, HAS_AND_BELONGS_TO_MANY)
130
+ def have_and_belong_to_many association_name
131
+ HaveAssociationMatcher.new association_name, HAS_AND_BELONGS_TO_MANY
132
132
  end
133
133
 
134
- def belong_to(association_name)
135
- HaveAssociationMatcher.new(association_name, BELONGS_TO)
134
+ def belong_to association_name
135
+ HaveAssociationMatcher.new association_name, BELONGS_TO
136
136
  end
137
137
 
138
- def embed_one(association_name)
139
- HaveAssociationMatcher.new(association_name, EMBEDS_ONE)
138
+ def embed_one association_name
139
+ HaveAssociationMatcher.new association_name, EMBEDS_ONE
140
140
  end
141
141
 
142
- def embed_many(association_name)
143
- HaveAssociationMatcher.new(association_name, EMBEDS_MANY)
142
+ def embed_many association_name
143
+ HaveAssociationMatcher.new association_name, EMBEDS_MANY
144
144
  end
145
145
 
146
- def embedded_in(association_name)
147
- HaveAssociationMatcher.new(association_name, EMBEDDED_IN)
146
+ def embedded_in association_name
147
+ HaveAssociationMatcher.new association_name, EMBEDDED_IN
148
148
  end
149
149
  end
150
150
  end