shoulda-matchers 2.0.0 → 2.1.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 +8 -8
- data/.travis.yml +9 -15
- data/Appraisals +10 -8
- data/Gemfile.lock +1 -1
- data/NEWS.md +62 -32
- data/gemfiles/3.0.gemfile.lock +2 -2
- data/gemfiles/3.1.gemfile.lock +2 -2
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/3.2.gemfile.lock +3 -3
- data/lib/shoulda/matchers/active_model.rb +1 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +7 -2
- data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +2 -0
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +3 -2
- data/lib/shoulda/matchers/active_model/helpers.rb +5 -2
- data/lib/shoulda/matchers/active_model/odd_even_number_matcher.rb +47 -0
- data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +4 -0
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +26 -3
- data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +68 -16
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +5 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matcher.rb +29 -4
- data/lib/shoulda/matchers/version.rb +1 -1
- data/shoulda-matchers.gemspec +1 -0
- data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +195 -0
- data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +18 -0
- data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +21 -0
- data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +23 -0
- data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +46 -0
- data/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb +93 -0
- data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +4 -4
- data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +60 -0
- data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +16 -0
- data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +45 -8
- data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +13 -0
- data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +50 -2
- data/spec/support/i18n_faker.rb +10 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzVkMDJkYmRiNjE2ODM0MDMzMzQxODQwZTBjMWEzM2RmYTMyZTIzYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTExOTlmMTUyOGU1NjVlZjM0YzVhN2FiNDVjYTE3NmI0ZDU0ZjNiMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWI5ZTA2ZGJjMTJmNjgxYjI0Mjk1NGZhYjZkYzUyMmIwNjJjZmJhYjRjZGRh
|
10
|
+
NTA2MjIwZDMzZjQ3YmIxMTNjNGUwMjEzYzg1ZjkzZDA2ZThlY2UyZWY5OGNm
|
11
|
+
OTY0ZTg4ZjM2ODQxZTU0OTg4MDhmMTA0ZDU3YjEyNTcxZmVlNDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2FkMWNjZTgzOTgwZjcwOWE2YjE2NzU1ZDNmMDQwZDEzNjQzMjVhMTAxYjQy
|
14
|
+
NjJjYmI0NmFlN2E3OTZkOGU0ODIzNDllMDgwZjlhNjRmNTRmMWQ3YWU5ZGNk
|
15
|
+
NzA0NmE5MzVkM2JhODAzNjMyNDU3NzBlYzIyZWUwYmRiNzEwMjI=
|
data/.travis.yml
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
script: "bundle exec rake spec cucumber"
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 1.8.7
|
5
4
|
- 1.9.2
|
6
5
|
- 1.9.3
|
7
|
-
- rbx-18mode
|
8
|
-
- jruby
|
9
6
|
|
10
7
|
gemfile:
|
11
8
|
- gemfiles/3.0.gemfile
|
@@ -14,15 +11,12 @@ gemfile:
|
|
14
11
|
|
15
12
|
matrix:
|
16
13
|
allow_failures:
|
17
|
-
- rvm:
|
18
|
-
- rvm:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
gemfile: gemfiles/3.0.gemfile
|
27
|
-
- rvm: jruby
|
28
|
-
gemfile: gemfiles/3.1.gemfile
|
14
|
+
- rvm: rbx-19mode
|
15
|
+
- rvm: jruby-19mode
|
16
|
+
include:
|
17
|
+
- rvm: 2.0.0
|
18
|
+
gemfile: gemfiles/3.2.gemfile
|
19
|
+
- rvm: rbx-19mode
|
20
|
+
gemfile: gemfiles/3.2.gemfile
|
21
|
+
- rvm: jruby-19mode
|
22
|
+
gemfile: gemfiles/3.2.gemfile
|
data/Appraisals
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
if RUBY_VERSION < '2.0'
|
2
|
+
appraise '3.0' do
|
3
|
+
gem 'rails', '~> 3.0.17'
|
4
|
+
end
|
4
5
|
|
5
|
-
appraise '3.1' do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
appraise '3.1' do
|
7
|
+
gem 'rails', '~> 3.1.8'
|
8
|
+
gem 'jquery-rails'
|
9
|
+
gem 'sass-rails'
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
appraise '3.2' do
|
12
|
-
gem 'rails', '~> 3.2.
|
14
|
+
gem 'rails', '~> 3.2.13'
|
13
15
|
gem 'jquery-rails'
|
14
16
|
gem 'sass-rails'
|
15
17
|
end
|
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# HEAD
|
2
2
|
|
3
|
+
# v 2.1.0
|
4
|
+
|
5
|
+
* Add missing `failure_message_for_should_not` implementations to
|
6
|
+
`validate_numericality_of` and its submatchers
|
7
|
+
|
8
|
+
* Support validation contexts for testing validations `on: :create` and when using custom contexts like `model.valid?(:my_context)`.
|
9
|
+
|
10
|
+
* Fix a bug in validations with autosaved models.
|
11
|
+
|
12
|
+
* Fix maximum value detection for the `ensure_inclusion_of` and
|
13
|
+
`ensure_exclusion_of` matchers.
|
14
|
+
|
15
|
+
* Add `:odd` and `:even` options to the `validate_numericality_of` matcher.
|
16
|
+
|
17
|
+
* Add `:touch` option to AssociationMatcher.
|
18
|
+
|
19
|
+
* Ruby 2.0.0 is now officially supported.
|
20
|
+
|
21
|
+
* Fix the issue where using `%{attribute}` or `%{model}` in I18n translations
|
22
|
+
raised exceptions.
|
23
|
+
|
24
|
+
* Support datetime columns in `validate_uniqueness_of.scoped_to`.
|
25
|
+
|
26
|
+
* Add `allow_nil` option to the `validate_uniqueness_of` matcher.
|
27
|
+
|
3
28
|
# v 2.0.0
|
4
29
|
* Remove the following matchers:
|
5
30
|
* `assign_to`
|
@@ -9,60 +34,65 @@
|
|
9
34
|
* `have_sent_email`
|
10
35
|
* `permit` (strong parameters matcher)
|
11
36
|
* `delegate_method`
|
37
|
+
|
12
38
|
* For more information about 2.0 changes, see:
|
13
|
-
http://robots.thoughtbot.com/post/47031676783/shoulda-matchers-2-0
|
39
|
+
http://robots.thoughtbot.com/post/47031676783/shoulda-matchers-2-0.
|
14
40
|
|
15
41
|
# v 1.5.6
|
16
|
-
* Revert previous change in
|
42
|
+
* Revert previous change in AllowValueMatcher that added a check for a
|
17
43
|
properly-set attribute.
|
18
44
|
|
19
45
|
# v 1.5.5
|
20
|
-
*
|
21
|
-
setting the attribute with it
|
46
|
+
* AllowValueMatcher checks that the right value is used for attempts at
|
47
|
+
setting the attribute with it.
|
22
48
|
* Please note that previously-passing tests might now fail. It is likely that
|
23
49
|
it's not a bug, but please make sure that the code you're testing is written
|
24
50
|
properly before submitting an issue.
|
25
|
-
|
26
|
-
*
|
27
|
-
|
51
|
+
|
52
|
+
* Use DisallowValueMatcher for `disallows_value_of` method.
|
53
|
+
|
54
|
+
* Assert `class_name` value on real class name for AssociationMatcher.
|
55
|
+
|
56
|
+
* Correct the variable used for `validate_confirmation_of` matcher description.
|
28
57
|
|
29
58
|
# v 1.5.4
|
30
|
-
* Properly-released version of 1.5.3
|
59
|
+
* Properly-released version of 1.5.3.
|
31
60
|
|
32
61
|
# v 1.5.3 - yanked due to mis-release
|
33
|
-
* Alleviate the need to add `rspec` gem to your app
|
62
|
+
* Alleviate the need to add `rspec` gem to your app.
|
34
63
|
|
35
64
|
# v 1.5.1
|
36
|
-
* Bump version
|
37
|
-
|
65
|
+
* Bump version dependency of Bourne to allow for Mocha upgrade.
|
66
|
+
|
67
|
+
* Should fix incompatibility with MiniTest.
|
38
68
|
|
39
69
|
# v 1.5.0
|
40
70
|
* Deprecate the following matchers:
|
41
|
-
* assign_to
|
42
|
-
* respond_with_content_type
|
43
|
-
* query_the_database
|
44
|
-
* validate_format_of
|
45
|
-
* have_sent_email
|
46
|
-
*
|
47
|
-
* delegate_method
|
71
|
+
* `assign_to`
|
72
|
+
* `respond_with_content_type`
|
73
|
+
* `query_the_database`
|
74
|
+
* `validate_format_of`
|
75
|
+
* `have_sent_email`
|
76
|
+
* `permit` (strong parameters matcher)
|
77
|
+
* `delegate_method`
|
48
78
|
|
49
79
|
* Use RSpec's native `configure.include` syntax for including matchers into
|
50
|
-
RSpec (#204)
|
80
|
+
RSpec (#204).
|
51
81
|
|
52
|
-
* Do not force
|
53
|
-
before 1.3.0 then reverted in 1.3.0)
|
82
|
+
* Do not force MiniTest loading when test-unit is available (this was fixed
|
83
|
+
before 1.3.0 then reverted in 1.3.0).
|
54
84
|
|
55
85
|
# v1.4.2
|
56
|
-
*
|
86
|
+
* Add a new `delegate_method` matcher.
|
57
87
|
|
58
88
|
# v1.4.1
|
59
|
-
*
|
89
|
+
* Fix an issue when used with Test::Unit on the allow value matcher.
|
60
90
|
|
61
|
-
*
|
91
|
+
* Fix an issue with using `ensure_inclusion_of(:attr)` given an array of true or false values.
|
62
92
|
|
63
93
|
# v1.4.0
|
64
94
|
|
65
|
-
*
|
95
|
+
* Add `strict` option to validation matchers.
|
66
96
|
|
67
97
|
* Verify that arguments to `set_the_flash` matcher are valid.
|
68
98
|
|
@@ -78,13 +108,13 @@ setting the attribute with it
|
|
78
108
|
|
79
109
|
* Test outside values for `ensure_inclusion_of` when given an array.
|
80
110
|
|
81
|
-
*
|
111
|
+
* Fix the output of the `set_the_flash` matcher.
|
82
112
|
|
83
113
|
# v1.3.0
|
84
114
|
|
85
|
-
* `validate_format_of` will accept `allow_blank(bool)` and `allow_nil(bool)
|
115
|
+
* `validate_format_of` will accept `allow_blank(bool)` and `allow_nil(bool)`.
|
86
116
|
|
87
|
-
* Prefer Test::Unit to
|
117
|
+
* Prefer Test::Unit to MiniTest when loading integrations so that RubyMine is
|
88
118
|
happy (#88).
|
89
119
|
|
90
120
|
* `validates_uniqueness_of` will now create a record if one does not exist.
|
@@ -119,10 +149,10 @@ setting the attribute with it
|
|
119
149
|
|
120
150
|
# v1.1.0
|
121
151
|
|
122
|
-
*
|
152
|
+
* Add `only_integer` option to `validate_numericality_of`:
|
123
153
|
`should validate_numericality_of(:attribute).only_integer`
|
124
154
|
|
125
|
-
*
|
155
|
+
* Add a `query_the_database` matcher:
|
126
156
|
|
127
157
|
`it { should query_the_database(4.times).when_calling(:complicated_method) }`
|
128
158
|
`it { should query_the_database(4.times).or_less.when_calling(:complicated_method) }`
|
@@ -137,10 +167,10 @@ setting the attribute with it
|
|
137
167
|
* The `have_sent_email` matcher can check `reply_to`:
|
138
168
|
` it { should have_sent_email.reply_to([user, other]) }`
|
139
169
|
|
140
|
-
*
|
170
|
+
* Add `validates_confirmation_of` matcher:
|
141
171
|
`it { should validate_confirmation_of(:password) }`
|
142
172
|
|
143
|
-
*
|
173
|
+
* Add `serialize` matcher:
|
144
174
|
`it { should serialize(:details).as(Hash).as_instance_of(Hash) }`
|
145
175
|
|
146
176
|
* shoulda-matchers checks for all possible I18n keys, instead of just
|
data/gemfiles/3.0.gemfile.lock
CHANGED
data/gemfiles/3.1.gemfile.lock
CHANGED
data/gemfiles/3.2.gemfile
CHANGED
@@ -9,7 +9,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
|
9
9
|
gem "jdbc-sqlite3", :platform=>:jruby
|
10
10
|
gem "jruby-openssl", :platform=>:jruby
|
11
11
|
gem "therubyrhino", :platform=>:jruby
|
12
|
-
gem "rails", "~> 3.2.
|
12
|
+
gem "rails", "~> 3.2.13"
|
13
13
|
gem "jquery-rails"
|
14
14
|
gem "sass-rails"
|
15
15
|
|
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../
|
3
3
|
specs:
|
4
|
-
shoulda-matchers (2.
|
4
|
+
shoulda-matchers (2.1.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -147,7 +147,7 @@ DEPENDENCIES
|
|
147
147
|
jdbc-sqlite3
|
148
148
|
jquery-rails
|
149
149
|
jruby-openssl
|
150
|
-
rails (~> 3.2.
|
150
|
+
rails (~> 3.2.13)
|
151
151
|
rake (>= 0.9.2)
|
152
152
|
rspec-rails (~> 2.13)
|
153
153
|
sass-rails
|
@@ -5,6 +5,7 @@ require 'shoulda/matchers/active_model/exception_message_finder'
|
|
5
5
|
require 'shoulda/matchers/active_model/allow_value_matcher'
|
6
6
|
require 'shoulda/matchers/active_model/disallow_value_matcher'
|
7
7
|
require 'shoulda/matchers/active_model/only_integer_matcher'
|
8
|
+
require 'shoulda/matchers/active_model/odd_even_number_matcher'
|
8
9
|
require 'shoulda/matchers/active_model/ensure_length_of_matcher'
|
9
10
|
require 'shoulda/matchers/active_model/ensure_inclusion_of_matcher'
|
10
11
|
require 'shoulda/matchers/active_model/ensure_exclusion_of_matcher'
|
@@ -43,6 +43,11 @@ module Shoulda # :nodoc:
|
|
43
43
|
self
|
44
44
|
end
|
45
45
|
|
46
|
+
def on(context)
|
47
|
+
@context = context
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
46
51
|
def with_message(message)
|
47
52
|
self.options[:expected_message] = message
|
48
53
|
self
|
@@ -78,7 +83,7 @@ module Shoulda # :nodoc:
|
|
78
83
|
private
|
79
84
|
|
80
85
|
attr_accessor :values_to_match, :message_finder_factory,
|
81
|
-
:instance, :attribute, :value, :matched_error
|
86
|
+
:instance, :attribute, :context, :value, :matched_error
|
82
87
|
|
83
88
|
def errors_match?
|
84
89
|
has_messages? && errors_for_attribute_match?
|
@@ -161,7 +166,7 @@ module Shoulda # :nodoc:
|
|
161
166
|
end
|
162
167
|
|
163
168
|
def message_finder
|
164
|
-
message_finder_factory.new(instance, attribute)
|
169
|
+
message_finder_factory.new(instance, attribute, context)
|
165
170
|
end
|
166
171
|
end
|
167
172
|
end
|
@@ -104,6 +104,7 @@ module Shoulda # :nodoc:
|
|
104
104
|
if Symbol === @short_message
|
105
105
|
@short_message = default_error_message(@short_message,
|
106
106
|
:model_name => @subject.class.to_s.underscore,
|
107
|
+
:instance => @subject,
|
107
108
|
:attribute => @attribute,
|
108
109
|
:count => @options[:minimum])
|
109
110
|
end
|
@@ -111,6 +112,7 @@ module Shoulda # :nodoc:
|
|
111
112
|
if Symbol === @long_message
|
112
113
|
@long_message = default_error_message(@long_message,
|
113
114
|
:model_name => @subject.class.to_s.underscore,
|
115
|
+
:instance => @subject,
|
114
116
|
:attribute => @attribute,
|
115
117
|
:count => @options[:maximum])
|
116
118
|
end
|
@@ -3,9 +3,10 @@ module Shoulda
|
|
3
3
|
module ActiveModel
|
4
4
|
# Finds message information from exceptions thrown by #valid?
|
5
5
|
class ExceptionMessageFinder
|
6
|
-
def initialize(instance, attribute)
|
6
|
+
def initialize(instance, attribute, context=nil)
|
7
7
|
@instance = instance
|
8
8
|
@attribute = attribute
|
9
|
+
@context = context
|
9
10
|
end
|
10
11
|
|
11
12
|
def allow_description(allowed_values)
|
@@ -39,7 +40,7 @@ module Shoulda
|
|
39
40
|
private
|
40
41
|
|
41
42
|
def validate_and_rescue
|
42
|
-
@instance.valid?
|
43
|
+
@instance.valid?(@context)
|
43
44
|
[]
|
44
45
|
rescue ::ActiveModel::StrictValidationFailed => exception
|
45
46
|
[exception.message]
|
@@ -5,7 +5,10 @@ module Shoulda # :nodoc:
|
|
5
5
|
def pretty_error_messages(obj) # :nodoc:
|
6
6
|
obj.errors.map do |attribute, model|
|
7
7
|
msg = "#{attribute} #{model}"
|
8
|
-
|
8
|
+
if attribute.to_sym != :base && obj.respond_to?(attribute)
|
9
|
+
msg << " (#{obj.send(attribute).inspect})"
|
10
|
+
end
|
11
|
+
msg
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
@@ -26,7 +29,7 @@ module Shoulda # :nodoc:
|
|
26
29
|
instance = options.delete(:instance)
|
27
30
|
|
28
31
|
if instance && instance.errors.respond_to?(:generate_message)
|
29
|
-
instance.errors.generate_message(attribute.to_sym, key,
|
32
|
+
instance.errors.generate_message(attribute.to_sym, key, options)
|
30
33
|
else
|
31
34
|
default_translation = [ :"activerecord.errors.models.#{model_name}.#{key}",
|
32
35
|
:"activerecord.errors.messages.#{key}",
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module Matchers
|
3
|
+
module ActiveModel # :nodoc:
|
4
|
+
class OddEvenNumberMatcher # :nodoc:
|
5
|
+
NON_EVEN_NUMBER_VALUE = 1
|
6
|
+
NON_ODD_NUMBER_VALUE = 2
|
7
|
+
|
8
|
+
def initialize(attribute, options = {})
|
9
|
+
@attribute = attribute
|
10
|
+
options[:odd] ||= true
|
11
|
+
options[:even] ||= false
|
12
|
+
|
13
|
+
if options[:odd] && !options[:even]
|
14
|
+
@disallow_value_matcher = DisallowValueMatcher.new(NON_ODD_NUMBER_VALUE).
|
15
|
+
for(@attribute).
|
16
|
+
with_message(:odd)
|
17
|
+
else
|
18
|
+
@disallow_value_matcher = DisallowValueMatcher.new(NON_EVEN_NUMBER_VALUE).
|
19
|
+
for(@attribute).
|
20
|
+
with_message(:even)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def matches?(subject)
|
25
|
+
@disallow_value_matcher.matches?(subject)
|
26
|
+
end
|
27
|
+
|
28
|
+
def with_message(message)
|
29
|
+
@disallow_value_matcher.with_message(message)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def allowed_types
|
34
|
+
'integer'
|
35
|
+
end
|
36
|
+
|
37
|
+
def failure_message_for_should
|
38
|
+
@disallow_value_matcher.failure_message_for_should
|
39
|
+
end
|
40
|
+
|
41
|
+
def failure_message_for_should_not
|
42
|
+
@disallow_value_matcher.failure_message_for_should_not
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|