shoulda-matchers 2.8.0.rc1 → 2.8.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/.hound_config/ruby.yml +5 -0
- data/.travis.yml +4 -0
- data/.yardopts +1 -1
- data/Appraisals +5 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -5
- data/NEWS.md +24 -0
- data/README.md +9 -0
- data/gemfiles/3.0.gemfile +1 -1
- data/gemfiles/3.0.gemfile.lock +7 -5
- data/gemfiles/3.1.gemfile +1 -1
- data/gemfiles/3.1.gemfile.lock +7 -5
- data/gemfiles/3.1_1.9.2.gemfile +1 -3
- data/gemfiles/3.1_1.9.2.gemfile.lock +7 -12
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/3.2.gemfile.lock +7 -5
- data/gemfiles/3.2_1.9.2.gemfile +1 -3
- data/gemfiles/3.2_1.9.2.gemfile.lock +5 -10
- data/gemfiles/4.0.0.gemfile +1 -1
- data/gemfiles/4.0.0.gemfile.lock +7 -5
- data/gemfiles/4.0.1.gemfile +1 -1
- data/gemfiles/4.0.1.gemfile.lock +7 -5
- data/gemfiles/4.1.gemfile +1 -1
- data/gemfiles/4.1.gemfile.lock +7 -5
- data/gemfiles/4.2.gemfile +5 -3
- data/gemfiles/4.2.gemfile.lock +26 -8
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +2 -0
- data/lib/shoulda/matchers/active_model.rb +3 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +44 -32
- data/lib/shoulda/matchers/active_model/helpers.rb +8 -22
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +66 -19
- data/lib/shoulda/matchers/active_model/strict_validator.rb +51 -0
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +14 -13
- data/lib/shoulda/matchers/active_model/validator.rb +113 -0
- data/lib/shoulda/matchers/active_model/validator_with_captured_range_error.rb +12 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +19 -1
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +23 -2
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +14 -11
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +1 -0
- data/lib/shoulda/matchers/active_record/uniqueness/model.rb +1 -0
- data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +1 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +1 -0
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +22 -15
- data/lib/shoulda/matchers/matcher_context.rb +1 -0
- data/lib/shoulda/matchers/rails_shim.rb +22 -0
- data/lib/shoulda/matchers/util.rb +5 -0
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/update_gem_in_all_appraisals +15 -0
- data/shoulda-matchers.gemspec +1 -1
- data/spec/support/unit/helpers/active_model_helpers.rb +3 -1
- data/spec/support/unit/helpers/active_model_versions.rb +8 -0
- data/spec/support/unit/helpers/active_record_versions.rb +16 -0
- data/spec/support/unit/helpers/rails_versions.rb +4 -4
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +9 -8
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +74 -0
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +75 -0
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +24 -0
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +78 -5
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +31 -2
- data/spec/unit_spec_helper.rb +2 -0
- metadata +11 -8
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +0 -58
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +0 -69
- data/spec/unit/shoulda/matchers/active_model/exception_message_finder_spec.rb +0 -111
- data/spec/unit/shoulda/matchers/active_model/validation_message_finder_spec.rb +0 -129
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
4
|
-
context '#allow_description' do
|
5
|
-
it 'describes its attribute' do
|
6
|
-
finder = build_finder(attribute: :attr)
|
7
|
-
|
8
|
-
description = finder.allow_description('allowed values')
|
9
|
-
|
10
|
-
expect(description).to eq 'allow attr to be set to allowed values'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context '#expected_message_from' do
|
15
|
-
it 'returns the message as-is' do
|
16
|
-
finder = build_finder
|
17
|
-
|
18
|
-
message = finder.expected_message_from('some message')
|
19
|
-
|
20
|
-
expect(message).to eq 'some message'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context '#has_messages?' do
|
25
|
-
it 'has messages when some validations fail' do
|
26
|
-
finder = build_finder(format: /abc/, value: 'xyz')
|
27
|
-
|
28
|
-
result = finder.has_messages?
|
29
|
-
|
30
|
-
expect(result).to eq true
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'has no messages when all validations pass' do
|
34
|
-
finder = build_finder(format: /abc/, value: 'abc')
|
35
|
-
|
36
|
-
result = finder.has_messages?
|
37
|
-
|
38
|
-
expect(result).to eq false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context '#messages' do
|
43
|
-
it 'returns errors for the given attribute' do
|
44
|
-
finder = build_finder(format: /abc/, value: 'xyz')
|
45
|
-
|
46
|
-
messages = finder.messages
|
47
|
-
|
48
|
-
expect(messages).to 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
|
-
expect(messages).to eq([])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context '#messages_description' do
|
61
|
-
it 'describes errors for the given attribute' do
|
62
|
-
finder = build_finder(
|
63
|
-
attribute: :attr,
|
64
|
-
format: /abc/,
|
65
|
-
value: 'xyz'
|
66
|
-
)
|
67
|
-
|
68
|
-
description = finder.messages_description
|
69
|
-
|
70
|
-
expect(description).to eq(
|
71
|
-
%{ errors:\n* "is invalid" (attribute: attr, value: "xyz")}
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'describes errors when there are none' do
|
76
|
-
finder = build_finder(format: /abc/, value: 'abc')
|
77
|
-
|
78
|
-
description = finder.messages_description
|
79
|
-
|
80
|
-
expect(description).to eq ' no errors'
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should not fetch attribute values for errors that were copied from an autosaved belongs_to association' do
|
84
|
-
instance = define_model(:example) do
|
85
|
-
validate do |record|
|
86
|
-
record.errors.add('association.association_attribute', 'is invalid')
|
87
|
-
end
|
88
|
-
end.new
|
89
|
-
finder = Shoulda::Matchers::ActiveModel::ValidationMessageFinder.new(instance, :attribute)
|
90
|
-
|
91
|
-
expect(finder.messages_description).to eq(
|
92
|
-
%{ errors:\n* "is invalid" (attribute: association.association_attribute)}
|
93
|
-
)
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
context '#source_description' do
|
99
|
-
it 'describes the source of its messages' do
|
100
|
-
finder = build_finder
|
101
|
-
|
102
|
-
description = finder.source_description
|
103
|
-
|
104
|
-
expect(description).to eq 'errors'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def build_finder(arguments = {})
|
109
|
-
arguments[:attribute] ||= :attr
|
110
|
-
instance = build_instance_validating(
|
111
|
-
arguments[:attribute],
|
112
|
-
arguments[:format] || /abc/,
|
113
|
-
arguments[:value] || 'abc'
|
114
|
-
)
|
115
|
-
Shoulda::Matchers::ActiveModel::ValidationMessageFinder.new(
|
116
|
-
instance,
|
117
|
-
arguments[:attribute]
|
118
|
-
)
|
119
|
-
end
|
120
|
-
|
121
|
-
def build_instance_validating(attribute, format, value)
|
122
|
-
model_class = define_model(:example, attribute => :string) do
|
123
|
-
attr_accessible attribute
|
124
|
-
validates_format_of attribute, with: format
|
125
|
-
end
|
126
|
-
|
127
|
-
model_class.new(attribute => value)
|
128
|
-
end
|
129
|
-
end
|