shoulda-matchers 2.4.0.rc1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Appraisals +4 -0
- data/Gemfile.lock +1 -1
- data/NEWS.md +6 -0
- data/README.md +1 -0
- data/gemfiles/3.1.gemfile +1 -0
- data/gemfiles/3.1.gemfile.lock +2 -0
- data/gemfiles/3.2.gemfile +1 -0
- data/gemfiles/3.2.gemfile.lock +3 -1
- data/gemfiles/4.0.gemfile +2 -0
- data/gemfiles/4.0.gemfile.lock +10 -1
- data/lib/shoulda/matchers/active_model.rb +1 -0
- data/lib/shoulda/matchers/active_model/comparison_matcher.rb +6 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +71 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
- data/lib/shoulda/matchers/version.rb +1 -1
- data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +4 -4
- data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +5 -5
- data/spec/shoulda/matchers/active_model/comparison_matcher_spec.rb +18 -7
- data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +2 -2
- data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +6 -7
- data/spec/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +20 -0
- data/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb +7 -3
- data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +6 -2
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +1 -1
- 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 +46 -1
- data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +15 -7
- data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -1
- data/spec/support/active_resource_builder.rb +27 -0
- data/spec/support/shared_examples/numerical_submatcher_spec.rb +23 -0
- metadata +12 -7
- data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +0 -195
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d6e59e41d93f44812d45789d56c5b7dfee4b7fd
|
4
|
+
data.tar.gz: a5d9a41130c16ac1f68735ccdf8070f0de86432a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d776d5f7772c8330f3f4b3164b7e6131841e437dbe938cb453cc38a7cf63196cb92689d567bc5a51ef17f2f0a675e3b55941c851c1d2489f33ab1af8baa95387
|
7
|
+
data.tar.gz: 4eccb03b31c410dc981f85e3af53743a186844d381c0d7408f50c7526d9715398733acd9062476c98a362f81146c27dd7a182d0afc4bf6e15e0bc4eebc9d2179
|
data/.travis.yml
CHANGED
@@ -17,8 +17,12 @@ matrix:
|
|
17
17
|
- rvm: rbx-19mode
|
18
18
|
- rvm: jruby-19mode
|
19
19
|
include:
|
20
|
+
- rvm: 1.9.3
|
21
|
+
gemfile: gemfiles/4.0.gemfile
|
20
22
|
- rvm: 2.0.0
|
21
23
|
gemfile: gemfiles/3.2.gemfile
|
24
|
+
- rvm: 2.0.0
|
25
|
+
gemfile: gemfiles/4.0.gemfile
|
22
26
|
- rvm: rbx-19mode
|
23
27
|
gemfile: gemfiles/3.2.gemfile
|
24
28
|
- rvm: jruby-19mode
|
data/Appraisals
CHANGED
@@ -6,6 +6,7 @@ if RUBY_VERSION < '2.0'
|
|
6
6
|
|
7
7
|
appraise '3.1' do
|
8
8
|
gem 'rails', '~> 3.1.8'
|
9
|
+
gem 'bcrypt-ruby', '~> 3.0.0'
|
9
10
|
gem 'jquery-rails'
|
10
11
|
gem 'sass-rails'
|
11
12
|
gem 'strong_parameters'
|
@@ -14,6 +15,7 @@ end
|
|
14
15
|
|
15
16
|
appraise '3.2' do
|
16
17
|
gem 'rails', '~> 3.2.13'
|
18
|
+
gem 'bcrypt-ruby', '~> 3.0.0'
|
17
19
|
gem 'jquery-rails'
|
18
20
|
gem 'sass-rails'
|
19
21
|
gem 'strong_parameters'
|
@@ -21,8 +23,10 @@ end
|
|
21
23
|
|
22
24
|
appraise '4.0' do
|
23
25
|
gem 'rails', '4.0.0'
|
26
|
+
gem 'bcrypt-ruby', '~> 3.0.0' #FIXME: This should be ~> 3.1.0 for Rails 4.0
|
24
27
|
gem 'jquery-rails'
|
25
28
|
gem 'sass-rails', '~> 4.0.0'
|
29
|
+
gem 'activeresource', require: 'active_resource'
|
26
30
|
|
27
31
|
# Test suite makes heavy use of attr_accessible
|
28
32
|
gem 'protected_attributes'
|
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# HEAD
|
2
2
|
|
3
|
+
# v 2.4.0
|
4
|
+
* Fix a bug with the `validate_numericality_of` matcher that would not allow the
|
5
|
+
`with_message` option on certain submatchers.
|
6
|
+
|
7
|
+
* Fix a regression with context-dependent validations in ActiveResource
|
8
|
+
|
3
9
|
* shoulda-matchers is now fully compatible with Rails 4.
|
4
10
|
|
5
11
|
* When not using RSpec, shoulda-matchers is now auto-included into
|
data/README.md
CHANGED
data/gemfiles/3.1.gemfile
CHANGED
data/gemfiles/3.1.gemfile.lock
CHANGED
@@ -43,6 +43,7 @@ GEM
|
|
43
43
|
childprocess (~> 0.3.6)
|
44
44
|
cucumber (>= 1.1.1)
|
45
45
|
rspec-expectations (>= 2.7.0)
|
46
|
+
bcrypt-ruby (3.0.1)
|
46
47
|
bourne (1.4.0)
|
47
48
|
mocha (~> 0.13.2)
|
48
49
|
builder (3.0.4)
|
@@ -143,6 +144,7 @@ DEPENDENCIES
|
|
143
144
|
activerecord-jdbcsqlite3-adapter
|
144
145
|
appraisal (~> 0.4)
|
145
146
|
aruba
|
147
|
+
bcrypt-ruby (~> 3.0.0)
|
146
148
|
bourne (~> 1.3)
|
147
149
|
bundler (~> 1.1)
|
148
150
|
cucumber (~> 1.1)
|
data/gemfiles/3.2.gemfile
CHANGED
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
shoulda-matchers (2.4.0
|
4
|
+
shoulda-matchers (2.4.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -42,6 +42,7 @@ GEM
|
|
42
42
|
childprocess (~> 0.3.6)
|
43
43
|
cucumber (>= 1.1.1)
|
44
44
|
rspec-expectations (>= 2.7.0)
|
45
|
+
bcrypt-ruby (3.0.1)
|
45
46
|
bourne (1.4.0)
|
46
47
|
mocha (~> 0.13.2)
|
47
48
|
builder (3.0.4)
|
@@ -141,6 +142,7 @@ DEPENDENCIES
|
|
141
142
|
activerecord-jdbcsqlite3-adapter
|
142
143
|
appraisal (~> 0.4)
|
143
144
|
aruba
|
145
|
+
bcrypt-ruby (~> 3.0.0)
|
144
146
|
bourne (~> 1.3)
|
145
147
|
bundler (~> 1.1)
|
146
148
|
cucumber (~> 1.1)
|
data/gemfiles/4.0.gemfile
CHANGED
@@ -10,8 +10,10 @@ gem "jdbc-sqlite3", :platform=>:jruby
|
|
10
10
|
gem "jruby-openssl", :platform=>:jruby
|
11
11
|
gem "therubyrhino", :platform=>:jruby
|
12
12
|
gem "rails", "4.0.0"
|
13
|
+
gem "bcrypt-ruby", "~> 3.0.0"
|
13
14
|
gem "jquery-rails"
|
14
15
|
gem "sass-rails", "~> 4.0.0"
|
16
|
+
gem "activeresource", :require=>"active_resource"
|
15
17
|
gem "protected_attributes"
|
16
18
|
|
17
19
|
gemspec :path=>"../"
|
data/gemfiles/4.0.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
shoulda-matchers (2.4.0
|
4
|
+
shoulda-matchers (2.4.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -25,6 +25,10 @@ GEM
|
|
25
25
|
activesupport (= 4.0.0)
|
26
26
|
arel (~> 4.0.0)
|
27
27
|
activerecord-deprecated_finders (1.0.3)
|
28
|
+
activeresource (4.0.0)
|
29
|
+
activemodel (~> 4.0)
|
30
|
+
activesupport (~> 4.0)
|
31
|
+
rails-observers (~> 0.1.1)
|
28
32
|
activesupport (4.0.0)
|
29
33
|
i18n (~> 0.6, >= 0.6.4)
|
30
34
|
minitest (~> 4.2)
|
@@ -40,6 +44,7 @@ GEM
|
|
40
44
|
cucumber (>= 1.1.1)
|
41
45
|
rspec-expectations (>= 2.7.0)
|
42
46
|
atomic (1.1.13)
|
47
|
+
bcrypt-ruby (3.0.1)
|
43
48
|
bourne (1.5.0)
|
44
49
|
mocha (>= 0.13.2, < 0.15)
|
45
50
|
builder (3.1.4)
|
@@ -85,6 +90,8 @@ GEM
|
|
85
90
|
bundler (>= 1.3.0, < 2.0)
|
86
91
|
railties (= 4.0.0)
|
87
92
|
sprockets-rails (~> 2.0.0)
|
93
|
+
rails-observers (0.1.2)
|
94
|
+
activemodel (~> 4.0)
|
88
95
|
railties (4.0.0)
|
89
96
|
actionpack (= 4.0.0)
|
90
97
|
activesupport (= 4.0.0)
|
@@ -133,8 +140,10 @@ PLATFORMS
|
|
133
140
|
DEPENDENCIES
|
134
141
|
activerecord-jdbc-adapter
|
135
142
|
activerecord-jdbcsqlite3-adapter
|
143
|
+
activeresource
|
136
144
|
appraisal (~> 0.4)
|
137
145
|
aruba
|
146
|
+
bcrypt-ruby (~> 3.0.0)
|
138
147
|
bourne (~> 1.3)
|
139
148
|
bundler (~> 1.1)
|
140
149
|
cucumber (~> 1.1)
|
@@ -17,6 +17,7 @@ require 'shoulda/matchers/active_model/validate_confirmation_of_matcher'
|
|
17
17
|
require 'shoulda/matchers/active_model/validate_numericality_of_matcher'
|
18
18
|
require 'shoulda/matchers/active_model/allow_mass_assignment_of_matcher'
|
19
19
|
require 'shoulda/matchers/active_model/errors'
|
20
|
+
require 'shoulda/matchers/active_model/have_secure_password_matcher'
|
20
21
|
|
21
22
|
|
22
23
|
module Shoulda
|
@@ -9,6 +9,7 @@ module Shoulda # :nodoc:
|
|
9
9
|
def initialize(value, operator)
|
10
10
|
@value = value
|
11
11
|
@operator = operator
|
12
|
+
@message = nil
|
12
13
|
end
|
13
14
|
|
14
15
|
def for(attribute)
|
@@ -18,13 +19,17 @@ module Shoulda # :nodoc:
|
|
18
19
|
|
19
20
|
def matches?(subject)
|
20
21
|
@subject = subject
|
21
|
-
disallows_value_of(value_to_compare)
|
22
|
+
disallows_value_of(value_to_compare, @message)
|
22
23
|
end
|
23
24
|
|
24
25
|
def allowed_types
|
25
26
|
'integer'
|
26
27
|
end
|
27
28
|
|
29
|
+
def with_message(message)
|
30
|
+
@message = message
|
31
|
+
end
|
32
|
+
|
28
33
|
private
|
29
34
|
|
30
35
|
def value_to_compare
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Shoulda # :nodoc:
|
2
|
+
module Matchers
|
3
|
+
module ActiveModel # :nodoc:
|
4
|
+
|
5
|
+
# Ensures that the model exhibits behavior added by has_secure_password.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# it { should have_secure_password }
|
9
|
+
def have_secure_password
|
10
|
+
HaveSecurePasswordMatcher.new
|
11
|
+
end
|
12
|
+
|
13
|
+
class HaveSecurePasswordMatcher # :nodoc:
|
14
|
+
attr_reader :failure_message_for_should
|
15
|
+
|
16
|
+
CORRECT_PASSWORD = "aBcDe12345"
|
17
|
+
INCORRECT_PASSWORD = "password"
|
18
|
+
|
19
|
+
EXPECTED_METHODS = [
|
20
|
+
:authenticate,
|
21
|
+
:password=,
|
22
|
+
:password_confirmation=,
|
23
|
+
:password_digest,
|
24
|
+
:password_digest=,
|
25
|
+
]
|
26
|
+
|
27
|
+
MESSAGES = {
|
28
|
+
authenticated_incorrect_password: "expected %{subject} to not authenticate an incorrect password",
|
29
|
+
did_not_authenticate_correct_password: "expected %{subject} to authenticate the correct password",
|
30
|
+
method_not_found: "expected %{subject} to respond to %{methods}"
|
31
|
+
}
|
32
|
+
|
33
|
+
def description
|
34
|
+
"have a secure password"
|
35
|
+
end
|
36
|
+
|
37
|
+
def matches?(subject)
|
38
|
+
@subject = subject
|
39
|
+
|
40
|
+
if failure = validate
|
41
|
+
key, params = failure
|
42
|
+
@failure_message_for_should = MESSAGES[key] % { subject: subject.class }.merge(params)
|
43
|
+
end
|
44
|
+
|
45
|
+
failure.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :subject
|
51
|
+
|
52
|
+
def validate
|
53
|
+
missing_methods = EXPECTED_METHODS.select {|m| !subject.respond_to?(m) }
|
54
|
+
|
55
|
+
if missing_methods.present?
|
56
|
+
[:method_not_found, { methods: missing_methods.to_sentence }]
|
57
|
+
else
|
58
|
+
subject.password = CORRECT_PASSWORD
|
59
|
+
subject.password_confirmation = CORRECT_PASSWORD
|
60
|
+
|
61
|
+
if not subject.authenticate(CORRECT_PASSWORD)
|
62
|
+
[:did_not_authenticate_correct_password, {}]
|
63
|
+
elsif subject.authenticate(INCORRECT_PASSWORD)
|
64
|
+
[:authenticated_incorrect_password, {}]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -37,7 +37,7 @@ module Shoulda
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def messages
|
40
|
-
Array
|
40
|
+
Array(messages_for_attribute)
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
@@ -59,7 +59,7 @@ module Shoulda
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def validate_instance
|
62
|
-
@instance.valid?(
|
62
|
+
@instance.valid?(*@context)
|
63
63
|
@instance
|
64
64
|
end
|
65
65
|
end
|
@@ -37,6 +37,6 @@ describe Shoulda::Matchers::ActionController::RedirectToMatcher do
|
|
37
37
|
it 'provides the correct description when provided a block' do
|
38
38
|
matcher = redirect_to('somewhere else') { '/some/other/url' }
|
39
39
|
|
40
|
-
matcher.description.should
|
40
|
+
matcher.description.should eq 'redirect to somewhere else'
|
41
41
|
end
|
42
42
|
end
|
@@ -4,16 +4,16 @@ describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do
|
|
4
4
|
context '#description' do
|
5
5
|
context 'without a role' do
|
6
6
|
it 'includes the attribute name' do
|
7
|
-
described_class.new(:attr).description.
|
8
|
-
'allow mass assignment of attr'
|
7
|
+
described_class.new(:attr).description.
|
8
|
+
should eq 'allow mass assignment of attr'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
if active_model_3_1?
|
13
13
|
context 'with a role' do
|
14
14
|
it 'includes the attribute name and the role' do
|
15
|
-
described_class.new(:attr).as(:admin).description.
|
16
|
-
'allow mass assignment of attr as admin'
|
15
|
+
described_class.new(:attr).as(:admin).description.
|
16
|
+
should eq 'allow mass assignment of attr as admin'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -5,21 +5,21 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
|
|
5
5
|
it 'describes itself with multiple values' do
|
6
6
|
matcher = allow_value('foo', 'bar').for(:baz)
|
7
7
|
|
8
|
-
matcher.description.should
|
8
|
+
matcher.description.should eq 'allow baz to be set to any of ["foo", "bar"]'
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'describes itself with a single value' do
|
12
12
|
matcher = allow_value('foo').for(:baz)
|
13
13
|
|
14
|
-
matcher.description.should
|
14
|
+
matcher.description.should eq 'allow baz to be set to "foo"'
|
15
15
|
end
|
16
16
|
|
17
17
|
if active_model_3_2?
|
18
18
|
it 'describes itself with a strict validation' do
|
19
19
|
strict_matcher = allow_value('xyz').for(:attr).strict
|
20
20
|
|
21
|
-
strict_matcher.description.
|
22
|
-
%q(doesn't raise when attr is set to "xyz")
|
21
|
+
strict_matcher.description.
|
22
|
+
should eq %q(doesn't raise when attr is set to "xyz")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -162,7 +162,7 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
|
|
162
162
|
|
163
163
|
matcher.matches?(validating_format(:with => /abc/, :strict => true))
|
164
164
|
|
165
|
-
matcher.failure_message_for_should_not.should
|
165
|
+
matcher.failure_message_for_should_not.should eq 'Expected exception to include /abc/ ' +
|
166
166
|
'when attr is set to "xyz", got Attr is invalid'
|
167
167
|
end
|
168
168
|
end
|
@@ -1,40 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Shoulda::Matchers::ActiveModel::ComparisonMatcher do
|
4
|
+
it_behaves_like 'a numerical submatcher' do
|
5
|
+
subject { Shoulda::Matchers::ActiveModel::ComparisonMatcher.new(0, :>) }
|
6
|
+
end
|
7
|
+
|
4
8
|
context 'is_greater_than' do
|
5
|
-
it { instance_with_validations(:
|
9
|
+
it { instance_with_validations(greater_than: 2).should matcher.is_greater_than(2) }
|
6
10
|
it { instance_without_validations.should_not matcher.is_greater_than(2) }
|
7
11
|
end
|
8
12
|
|
9
13
|
context 'greater_than_or_equal_to' do
|
10
|
-
it { instance_with_validations(:
|
14
|
+
it { instance_with_validations(greater_than_or_equal_to: 2).should matcher.is_greater_than_or_equal_to(2) }
|
11
15
|
it { instance_without_validations.should_not matcher.is_greater_than_or_equal_to(2) }
|
12
16
|
end
|
13
17
|
|
14
18
|
context 'less_than' do
|
15
|
-
it { instance_with_validations(:
|
19
|
+
it { instance_with_validations(less_than: 2).should matcher.is_less_than(2) }
|
16
20
|
it { instance_without_validations.should_not matcher.is_less_than(2) }
|
17
21
|
end
|
18
22
|
|
19
23
|
context 'less_than_or_equal_to' do
|
20
|
-
it { instance_with_validations(:
|
24
|
+
it { instance_with_validations(less_than_or_equal_to: 2).should matcher.is_less_than_or_equal_to(2) }
|
21
25
|
it { instance_without_validations.should_not matcher.is_less_than_or_equal_to(2) }
|
22
26
|
end
|
23
27
|
|
24
28
|
context 'is_equal_to' do
|
25
|
-
it { instance_with_validations(:
|
29
|
+
it { instance_with_validations(equal_to: 0).should matcher.is_equal_to(0) }
|
26
30
|
it { instance_without_validations.should_not matcher.is_equal_to(0) }
|
27
31
|
end
|
28
32
|
|
33
|
+
context 'with_message' do
|
34
|
+
it 'verifies the message for the validation' do
|
35
|
+
instance = instance_with_validations(equal_to: 0, message: 'Must be zero')
|
36
|
+
instance.should matcher.is_equal_to(0).with_message('Must be zero')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
29
40
|
def instance_with_validations(options = {})
|
30
|
-
define_model :example, :
|
41
|
+
define_model :example, attr: :string do
|
31
42
|
validates_numericality_of :attr, options
|
32
43
|
attr_accessible :attr
|
33
44
|
end.new
|
34
45
|
end
|
35
46
|
|
36
47
|
def instance_without_validations
|
37
|
-
define_model :example, :
|
48
|
+
define_model :example, attr: :string do
|
38
49
|
attr_accessible :attr
|
39
50
|
end.new
|
40
51
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
|
4
4
|
it 'does not allow any types' do
|
5
|
-
matcher('abcde').allowed_types.should
|
5
|
+
matcher('abcde').allowed_types.should eq ''
|
6
6
|
end
|
7
7
|
|
8
8
|
context 'an attribute with a format validation' do
|
@@ -46,7 +46,7 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
|
|
46
46
|
matcher = matcher('abcde').for(:attr).with_message('good message')
|
47
47
|
matcher.matches?(validating_format(:with => /abc/, :message => 'good message'))
|
48
48
|
|
49
|
-
matcher.failure_message_for_should.should
|
49
|
+
matcher.failure_message_for_should.should eq 'allow matcher failure'
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'matches if the message is correct but the value is not' do
|
@@ -77,7 +77,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureExclusionOfMatcher do
|
|
77
77
|
|
78
78
|
it 'has correct description' do
|
79
79
|
ensure_exclusion_of(:attr).in_array([true, 'dog']).description.
|
80
|
-
should
|
80
|
+
should eq 'ensure exclusion of attr in [true, "dog"]'
|
81
81
|
end
|
82
82
|
|
83
83
|
def validating_exclusion(options)
|
@@ -129,7 +129,7 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
|
|
129
129
|
|
130
130
|
it 'has correct description' do
|
131
131
|
ensure_inclusion_of(:attr).in_array([true, "dog"]).description.
|
132
|
-
should
|
132
|
+
should eq 'ensure inclusion of attr in [true, "dog"]'
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'rejects allow_blank' do
|
@@ -8,7 +8,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
8
8
|
|
9
9
|
description = finder.allow_description('allowed values')
|
10
10
|
|
11
|
-
description.should
|
11
|
+
description.should eq %q(doesn't raise when attr is set to allowed values)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -18,7 +18,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
18
18
|
|
19
19
|
message = finder.expected_message_from('some message')
|
20
20
|
|
21
|
-
message.should
|
21
|
+
message.should eq 'Attr some message'
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -50,7 +50,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
50
50
|
|
51
51
|
messages = finder.messages
|
52
52
|
|
53
|
-
messages.should
|
53
|
+
messages.should eq ['Attr is invalid']
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -64,7 +64,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
64
64
|
|
65
65
|
description = finder.messages_description
|
66
66
|
|
67
|
-
description.should
|
67
|
+
description.should eq 'Attr is invalid'
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'describes errors when there are none' do
|
@@ -72,7 +72,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
72
72
|
|
73
73
|
description = finder.messages_description
|
74
74
|
|
75
|
-
description.should
|
75
|
+
description.should eq 'no exception'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -82,7 +82,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
82
82
|
|
83
83
|
description = finder.source_description
|
84
84
|
|
85
|
-
description.should
|
85
|
+
description.should eq 'exception'
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -109,4 +109,3 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
109
109
|
model_class.new(attribute => value)
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher do
|
4
|
+
if active_model_3_1?
|
5
|
+
it 'matches when the subject configures has_secure_password with default options' do
|
6
|
+
working_model = define_model(:example, password_digest: :string) { has_secure_password }
|
7
|
+
expect(working_model.new).to have_secure_password
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'does not match when the subject does not authenticate a password' do
|
11
|
+
no_secure_password = define_model(:example)
|
12
|
+
expect(no_secure_password.new).not_to have_secure_password
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not match when the subject is missing the password_digest attribute' do
|
16
|
+
no_digest_column = define_model(:example) { has_secure_password }
|
17
|
+
expect(no_digest_column.new).not_to have_secure_password
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher do
|
4
|
+
it_behaves_like 'a numerical submatcher' do
|
5
|
+
subject { Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher.new(:attr) }
|
6
|
+
end
|
7
|
+
|
4
8
|
context 'given an attribute that only allows odd number values' do
|
5
9
|
it 'matches' do
|
6
10
|
validating_odd_number.should new_odd_matcher
|
@@ -8,7 +12,7 @@ describe Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher do
|
|
8
12
|
|
9
13
|
it 'returns itself when given a message' do
|
10
14
|
matcher = new_odd_matcher
|
11
|
-
matcher.with_message('some message').should
|
15
|
+
matcher.with_message('some message').should eq matcher
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -19,7 +23,7 @@ describe Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher do
|
|
19
23
|
|
20
24
|
it 'returns itself when given a message' do
|
21
25
|
matcher = new_even_matcher
|
22
|
-
matcher.with_message('some message').should
|
26
|
+
matcher.with_message('some message').should eq matcher
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -85,7 +89,7 @@ describe Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher do
|
|
85
89
|
end.new
|
86
90
|
end
|
87
91
|
|
88
|
-
|
92
|
+
def validating_even_number(options = {})
|
89
93
|
define_model :example, :attr => :string do
|
90
94
|
validates_numericality_of :attr, { :even => true }.merge(options)
|
91
95
|
end.new
|
@@ -1,18 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Shoulda::Matchers::ActiveModel::OnlyIntegerMatcher do
|
4
|
+
it_behaves_like 'a numerical submatcher' do
|
5
|
+
subject { Shoulda::Matchers::ActiveModel::OnlyIntegerMatcher.new(:attr) }
|
6
|
+
end
|
7
|
+
|
4
8
|
context 'given an attribute that only allows integer values' do
|
5
9
|
it 'matches' do
|
6
10
|
validating_only_integer.should new_matcher
|
7
11
|
end
|
8
12
|
|
9
13
|
it 'allows integer types' do
|
10
|
-
new_matcher.allowed_types.should
|
14
|
+
new_matcher.allowed_types.should eq 'integer'
|
11
15
|
end
|
12
16
|
|
13
17
|
it 'returns itself when given a message' do
|
14
18
|
matcher = new_matcher
|
15
|
-
matcher.with_message('some message').should
|
19
|
+
matcher.with_message('some message').should eq matcher
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher do
|
4
4
|
context '#description' do
|
5
5
|
it 'states that the confirmation must match its base attribute' do
|
6
|
-
matcher.description.should
|
6
|
+
matcher.description.should eq 'require attr_confirmation to match attr'
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
|
4
4
|
context '#description' do
|
5
5
|
it 'states that it allows only numeric values' do
|
6
|
-
matcher.description.should
|
6
|
+
matcher.description.should eq 'only allow numeric values for attr'
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -134,6 +134,16 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
context 'an active_resource model' do
|
138
|
+
context 'with the validation context' do
|
139
|
+
it 'does not raise an exception' do
|
140
|
+
expect {
|
141
|
+
active_resource_model.should validate_presence_of(:attr)
|
142
|
+
}.to_not raise_exception
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
137
147
|
def matcher
|
138
148
|
validate_presence_of(:attr)
|
139
149
|
end
|
@@ -161,4 +171,10 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
|
|
161
171
|
end
|
162
172
|
end.new
|
163
173
|
end
|
174
|
+
|
175
|
+
def active_resource_model
|
176
|
+
define_active_resource_class :foo, :attr => :string do
|
177
|
+
validates_presence_of :attr
|
178
|
+
end.new
|
179
|
+
end
|
164
180
|
end
|
@@ -34,7 +34,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
|
|
34
34
|
context 'without an existing record' do
|
35
35
|
it 'does not require a created instance' do
|
36
36
|
define_model_with_other
|
37
|
-
Example.count.should
|
37
|
+
Example.count.should eq 0
|
38
38
|
validating_uniqueness_with_other.should matcher
|
39
39
|
end
|
40
40
|
end
|
@@ -274,6 +274,51 @@ describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
|
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
|
+
context "when the validation allows nil" do
|
278
|
+
context "when there is an existing entry with a nil" do
|
279
|
+
it "should allow_nil" do
|
280
|
+
model = define_model_with_allow_nil
|
281
|
+
Example.create!(:attr => nil)
|
282
|
+
model.should matcher.allow_nil
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should create a nil and verify that it is allowed" do
|
287
|
+
model = define_model_with_allow_nil
|
288
|
+
model.should matcher.allow_nil
|
289
|
+
Example.all.any?{ |instance| instance.attr.nil? }
|
290
|
+
end
|
291
|
+
|
292
|
+
def define_model_with_allow_nil
|
293
|
+
define_model(:example, :attr => :integer) do
|
294
|
+
attr_accessible :attr
|
295
|
+
validates_uniqueness_of :attr, :allow_nil => true
|
296
|
+
end.new
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
context "when the validation does not allow a nil" do
|
301
|
+
context "when there is an existing entry with a nil" do
|
302
|
+
it "should not allow_nil" do
|
303
|
+
model = define_model_without_allow_nil
|
304
|
+
Example.create!(:attr => nil)
|
305
|
+
model.should_not matcher.allow_nil
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should not allow_nil" do
|
310
|
+
model = define_model_without_allow_nil
|
311
|
+
model.should_not matcher.allow_nil
|
312
|
+
end
|
313
|
+
|
314
|
+
def define_model_without_allow_nil
|
315
|
+
define_model(:example, :attr => :integer) do
|
316
|
+
attr_accessible :attr
|
317
|
+
validates_uniqueness_of :attr
|
318
|
+
end.new
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
277
322
|
def case_sensitive_validation_with_existing_value(attr_type)
|
278
323
|
model = define_model(:example, :attr => attr_type) do
|
279
324
|
attr_accessible :attr
|
@@ -7,7 +7,7 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
7
7
|
|
8
8
|
description = finder.allow_description('allowed values')
|
9
9
|
|
10
|
-
description.should
|
10
|
+
description.should eq 'allow attr to be set to allowed values'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
17
17
|
|
18
18
|
message = finder.expected_message_from('some message')
|
19
19
|
|
20
|
-
message.should
|
20
|
+
message.should eq 'some message'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -45,7 +45,15 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
45
45
|
|
46
46
|
messages = finder.messages
|
47
47
|
|
48
|
-
messages.should
|
48
|
+
messages.should eq ['is invalid']
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns an empty array if there are no errors for the given attribute' do
|
52
|
+
finder = build_finder
|
53
|
+
|
54
|
+
messages = finder.messages
|
55
|
+
|
56
|
+
messages.should == []
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
@@ -60,7 +68,7 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
60
68
|
description = finder.messages_description
|
61
69
|
|
62
70
|
expected_messages = ['attr is invalid ("xyz")']
|
63
|
-
description.should
|
71
|
+
description.should eq "errors: #{expected_messages}"
|
64
72
|
end
|
65
73
|
|
66
74
|
it 'describes errors when there are none' do
|
@@ -68,7 +76,7 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
68
76
|
|
69
77
|
description = finder.messages_description
|
70
78
|
|
71
|
-
description.should
|
79
|
+
description.should eq 'no errors'
|
72
80
|
end
|
73
81
|
|
74
82
|
it 'should not fetch attribute values for errors that were copied from an autosaved belongs_to association' do
|
@@ -80,7 +88,7 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
80
88
|
finder = Shoulda::Matchers::ActiveModel::ValidationMessageFinder.new(instance, :attribute)
|
81
89
|
|
82
90
|
expected_messages = ['association.association_attribute is invalid']
|
83
|
-
finder.messages_description.should
|
91
|
+
finder.messages_description.should eq "errors: #{expected_messages}"
|
84
92
|
end
|
85
93
|
|
86
94
|
end
|
@@ -91,7 +99,7 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|
91
99
|
|
92
100
|
description = finder.source_description
|
93
101
|
|
94
|
-
description.should
|
102
|
+
description.should eq 'errors'
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
@@ -10,7 +10,8 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
10
10
|
|
11
11
|
matcher.matches?(rejecting_children).should be_false
|
12
12
|
|
13
|
-
matcher.failure_message_for_should.
|
13
|
+
matcher.failure_message_for_should.
|
14
|
+
should eq 'Expected Parent to accept nested attributes for children (is not declared)'
|
14
15
|
end
|
15
16
|
|
16
17
|
context 'allow_destroy' do
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveResourceBuilder
|
2
|
+
def self.included(example_group)
|
3
|
+
example_group.class_eval do
|
4
|
+
after do
|
5
|
+
ActiveSupport::Dependencies.clear
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_active_resource_class(class_name, attributes = {}, &block)
|
11
|
+
define_class(class_name, ActiveResource::Base) do
|
12
|
+
schema do
|
13
|
+
attributes.each do |attr, type|
|
14
|
+
attribute attr, type
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if block_given?
|
19
|
+
class_eval(&block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.include ActiveResourceBuilder
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'a numerical submatcher' do
|
4
|
+
it 'implements the with_message method' do
|
5
|
+
subject.should respond_to(:with_message).with(1).arguments
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'implements the allowed_types method' do
|
9
|
+
subject.should respond_to(:allowed_types).with(0).arguments
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'implements the matches? method' do
|
13
|
+
subject.should respond_to(:matches?).with(1).arguments
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'implements the failure_message_for_should method' do
|
17
|
+
subject.should respond_to(:failure_message_for_should).with(0).arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'implements the failure_message_for_should_not method' do
|
21
|
+
subject.should respond_to(:failure_message_for_should_not).with(0).arguments
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.0
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tammer Saleh
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-
|
16
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activesupport
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb
|
197
197
|
- lib/shoulda/matchers/active_model/errors.rb
|
198
198
|
- lib/shoulda/matchers/active_model/exception_message_finder.rb
|
199
|
+
- lib/shoulda/matchers/active_model/have_secure_password_matcher.rb
|
199
200
|
- lib/shoulda/matchers/active_model/helpers.rb
|
200
201
|
- lib/shoulda/matchers/active_model/odd_even_number_matcher.rb
|
201
202
|
- lib/shoulda/matchers/active_model/only_integer_matcher.rb
|
@@ -225,7 +226,6 @@ files:
|
|
225
226
|
- lib/shoulda/matchers/rails_shim.rb
|
226
227
|
- lib/shoulda/matchers/version.rb
|
227
228
|
- shoulda-matchers.gemspec
|
228
|
-
- spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
|
229
229
|
- spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
|
230
230
|
- spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
|
231
231
|
- spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
|
@@ -243,6 +243,7 @@ files:
|
|
243
243
|
- spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb
|
244
244
|
- spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
|
245
245
|
- spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
|
246
|
+
- spec/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb
|
246
247
|
- spec/shoulda/matchers/active_model/helpers_spec.rb
|
247
248
|
- spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb
|
248
249
|
- spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb
|
@@ -260,6 +261,7 @@ files:
|
|
260
261
|
- spec/shoulda/matchers/active_record/serialize_matcher_spec.rb
|
261
262
|
- spec/spec_helper.rb
|
262
263
|
- spec/support/active_model_versions.rb
|
264
|
+
- spec/support/active_resource_builder.rb
|
263
265
|
- spec/support/activemodel_helpers.rb
|
264
266
|
- spec/support/class_builder.rb
|
265
267
|
- spec/support/controller_builder.rb
|
@@ -267,6 +269,7 @@ files:
|
|
267
269
|
- spec/support/i18n_faker.rb
|
268
270
|
- spec/support/mailer_builder.rb
|
269
271
|
- spec/support/model_builder.rb
|
272
|
+
- spec/support/shared_examples/numerical_submatcher_spec.rb
|
270
273
|
homepage: http://thoughtbot.com/community/
|
271
274
|
licenses:
|
272
275
|
- MIT
|
@@ -282,12 +285,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
282
285
|
version: 1.9.2
|
283
286
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
284
287
|
requirements:
|
285
|
-
- - '
|
288
|
+
- - '>='
|
286
289
|
- !ruby/object:Gem::Version
|
287
|
-
version:
|
290
|
+
version: '0'
|
288
291
|
requirements: []
|
289
292
|
rubyforge_project:
|
290
|
-
rubygems_version: 2.0.
|
293
|
+
rubygems_version: 2.0.0
|
291
294
|
signing_key:
|
292
295
|
specification_version: 4
|
293
296
|
summary: Making tests easy on the fingers and eyes
|
@@ -295,7 +298,6 @@ test_files:
|
|
295
298
|
- features/rails_integration.feature
|
296
299
|
- features/step_definitions/rails_steps.rb
|
297
300
|
- features/support/env.rb
|
298
|
-
- spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
|
299
301
|
- spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
|
300
302
|
- spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
|
301
303
|
- spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
|
@@ -313,6 +315,7 @@ test_files:
|
|
313
315
|
- spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb
|
314
316
|
- spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
|
315
317
|
- spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
|
318
|
+
- spec/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb
|
316
319
|
- spec/shoulda/matchers/active_model/helpers_spec.rb
|
317
320
|
- spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb
|
318
321
|
- spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb
|
@@ -330,6 +333,7 @@ test_files:
|
|
330
333
|
- spec/shoulda/matchers/active_record/serialize_matcher_spec.rb
|
331
334
|
- spec/spec_helper.rb
|
332
335
|
- spec/support/active_model_versions.rb
|
336
|
+
- spec/support/active_resource_builder.rb
|
333
337
|
- spec/support/activemodel_helpers.rb
|
334
338
|
- spec/support/class_builder.rb
|
335
339
|
- spec/support/controller_builder.rb
|
@@ -337,3 +341,4 @@ test_files:
|
|
337
341
|
- spec/support/i18n_faker.rb
|
338
342
|
- spec/support/mailer_builder.rb
|
339
343
|
- spec/support/model_builder.rb
|
344
|
+
- spec/support/shared_examples/numerical_submatcher_spec.rb
|
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidateUniquenessOfMatcher do
|
4
|
-
context "a unique attribute" do
|
5
|
-
before do
|
6
|
-
@model = define_model(:example, :attr => :string,
|
7
|
-
:other => :integer) do
|
8
|
-
attr_accessible :attr, :other
|
9
|
-
validates_uniqueness_of :attr
|
10
|
-
end.new
|
11
|
-
end
|
12
|
-
|
13
|
-
context "with an existing value" do
|
14
|
-
before do
|
15
|
-
@existing = Example.create!(:attr => 'value', :other => 1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should require a unique value for that attribute" do
|
19
|
-
@model.should validate_uniqueness_of(:attr)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should pass when the subject is an existing record" do
|
23
|
-
@existing.should validate_uniqueness_of(:attr)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should fail when a scope is specified" do
|
27
|
-
@model.should_not validate_uniqueness_of(:attr).scoped_to(:other)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "without an existing value" do
|
32
|
-
before do
|
33
|
-
Example.first.should be_nil
|
34
|
-
@matcher = validate_uniqueness_of(:attr)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "does not not require a created instance" do
|
38
|
-
@model.should @matcher
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "a unique attribute with a custom error and an existing value" do
|
44
|
-
before do
|
45
|
-
@model = define_model(:example, :attr => :string) do
|
46
|
-
attr_accessible :attr
|
47
|
-
validates_uniqueness_of :attr, :message => 'Bad value'
|
48
|
-
end.new
|
49
|
-
Example.create!(:attr => 'value')
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should fail when checking the default message" do
|
53
|
-
@model.should_not validate_uniqueness_of(:attr)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should fail when checking a message that doesn't match" do
|
57
|
-
@model.should_not validate_uniqueness_of(:attr).with_message(/abc/i)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should pass when checking a message that matches" do
|
61
|
-
@model.should validate_uniqueness_of(:attr).with_message(/bad/i)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "a scoped unique attribute with an existing value" do
|
66
|
-
before do
|
67
|
-
@model = define_model(:example, :attr => :string,
|
68
|
-
:scope1 => :integer,
|
69
|
-
:scope2 => :integer,
|
70
|
-
:other => :integer) do
|
71
|
-
attr_accessible :attr, :scope1, :scope2, :other
|
72
|
-
validates_uniqueness_of :attr, :scope => [:scope1, :scope2]
|
73
|
-
end.new
|
74
|
-
@existing = Example.create!(:attr => 'value', :scope1 => 1, :scope2 => 2, :other => 3)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should pass when the correct scope is specified" do
|
78
|
-
@model.should validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should pass when the subject is an existing record" do
|
82
|
-
@existing.should validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should fail when too narrow of a scope is specified" do
|
86
|
-
@model.should_not validate_uniqueness_of(:attr).scoped_to(:scope1, :scope2, :other)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should fail when too broad of a scope is specified" do
|
90
|
-
@model.should_not validate_uniqueness_of(:attr).scoped_to(:scope1)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should fail when a different scope is specified" do
|
94
|
-
@model.should_not validate_uniqueness_of(:attr).scoped_to(:other)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should fail when no scope is specified" do
|
98
|
-
@model.should_not validate_uniqueness_of(:attr)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should fail when a non-existent attribute is specified as a scope" do
|
102
|
-
@model.should_not validate_uniqueness_of(:attr).scoped_to(:fake)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "a non-unique attribute with an existing value" do
|
107
|
-
before do
|
108
|
-
@model = define_model(:example, :attr => :string) do
|
109
|
-
attr_accessible :attr
|
110
|
-
end.new
|
111
|
-
Example.create!(:attr => 'value')
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should not require a unique value for that attribute" do
|
115
|
-
@model.should_not validate_uniqueness_of(:attr)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "a case sensitive unique attribute with an existing value" do
|
120
|
-
before do
|
121
|
-
@model = define_model(:example, :attr => :string) do
|
122
|
-
attr_accessible :attr
|
123
|
-
validates_uniqueness_of :attr, :case_sensitive => true
|
124
|
-
end.new
|
125
|
-
Example.create!(:attr => 'value')
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should not require a unique, case-insensitive value for that attribute" do
|
129
|
-
@model.should_not validate_uniqueness_of(:attr).case_insensitive
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should require a unique, case-sensitive value for that attribute" do
|
133
|
-
@model.should validate_uniqueness_of(:attr)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "a case sensitive unique integer attribute with an existing value" do
|
138
|
-
before do
|
139
|
-
@model = define_model(:example, :attr => :integer) do
|
140
|
-
attr_accessible :attr
|
141
|
-
validates_uniqueness_of :attr, :case_sensitive => true
|
142
|
-
end.new
|
143
|
-
Example.create!(:attr => 'value')
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should require a unique, case-insensitive value for that attribute" do
|
147
|
-
@model.should validate_uniqueness_of(:attr).case_insensitive
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should require a unique, case-sensitive value for that attribute" do
|
151
|
-
@model.should validate_uniqueness_of(:attr)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "when the validation allows nil" do
|
156
|
-
before do
|
157
|
-
@model = define_model(:example, :attr => :integer) do
|
158
|
-
attr_accessible :attr
|
159
|
-
validates_uniqueness_of :attr, :allow_nil => true
|
160
|
-
end.new
|
161
|
-
end
|
162
|
-
|
163
|
-
context "when there is an existing entry with a nil" do
|
164
|
-
it "should allow_nil" do
|
165
|
-
Example.create!(:attr => nil)
|
166
|
-
@model.should validate_uniqueness_of(:attr).allow_nil
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should create a nil and verify that it is allowed" do
|
171
|
-
@model.should validate_uniqueness_of(:attr).allow_nil
|
172
|
-
Example.all.any?{ |instance| instance.attr.nil? }
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "when the validation does not allow a nil" do
|
177
|
-
before do
|
178
|
-
@model = define_model(:example, :attr => :integer) do
|
179
|
-
attr_accessible :attr
|
180
|
-
validates_uniqueness_of :attr
|
181
|
-
end.new
|
182
|
-
end
|
183
|
-
|
184
|
-
context "when there is an existing entry with a nil" do
|
185
|
-
it "should not allow_nil" do
|
186
|
-
Example.create!(:attr => nil)
|
187
|
-
@model.should_not validate_uniqueness_of(:attr).allow_nil
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should not allow_nil" do
|
192
|
-
@model.should_not validate_uniqueness_of(:attr).allow_nil
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|