Skip to content

Commit bd26c11

Browse files
Merge pull request #206 from Mth0158/203-validator-custom-message-error-causes-test-matcher-error
203 validator custom message error causes test matcher error
2 parents 77f797b + c82a8f9 commit bd26c11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1677
-487
lines changed

Gemfile.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
active_storage_validations (1.1.0)
4+
active_storage_validations (1.1.1)
55
activejob (>= 5.2.0)
66
activemodel (>= 5.2.0)
77
activestorage (>= 5.2.0)
@@ -46,6 +46,7 @@ GEM
4646
zeitwerk (~> 2.3)
4747
ast (2.4.1)
4848
builder (3.2.4)
49+
byebug (11.1.3)
4950
coderay (1.1.3)
5051
combustion (1.3.1)
5152
activesupport (>= 3.0.0)
@@ -72,6 +73,8 @@ GEM
7273
mini_magick (4.11.0)
7374
mini_portile2 (2.5.1)
7475
minitest (5.14.3)
76+
minitest-focus (1.4.0)
77+
minitest (>= 4, < 6)
7578
nokogiri (1.11.3)
7679
mini_portile2 (~> 2.5.0)
7780
racc (~> 1.4)
@@ -134,10 +137,12 @@ PLATFORMS
134137

135138
DEPENDENCIES
136139
active_storage_validations!
140+
byebug
137141
combustion (~> 1.3)
138142
globalid
139143
marcel
140144
mini_magick (>= 4.9.5)
145+
minitest-focus (~> 1.4)
141146
pry
142147
rubocop
143148
ruby-vips (>= 2.1.0)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ BUNDLE_GEMFILE=gemfiles/rails_7_0.gemfile bundle exec rake test
368368
BUNDLE_GEMFILE=gemfiles/rails_next.gemfile bundle exec rake test
369369
```
370370

371+
Tips:
372+
- To focus a specific test, use the `focus` class method provided by [minitest-focus](https://github.com/minitest/minitest-focus)
373+
- To focus a specific file, use the TEST option provided by minitest, e.g. to only run size_validator_test.rb file you will execute the following command: `bundle exec rake test TEST=test/validators/size_validator_test.rb``
374+
375+
371376
## Known issues
372377
373378
- There is an issue in Rails which it possible to get if you have added a validation and generating for example an image preview of attachments. It can be fixed with this:

active_storage_validations.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
2121
s.metadata['rubygems_mfa_required'] = 'true'
2222

2323
%w[activejob activemodel activestorage activesupport].each { |rails_subcomponent| s.add_dependency rails_subcomponent, '>= 5.2.0' }
24+
s.add_development_dependency 'minitest-focus', "~> 1.4"
2425
s.add_development_dependency 'combustion', "~> 1.3"
2526
s.add_development_dependency 'mini_magick', ">= 4.9.5"
2627
s.add_development_dependency 'ruby-vips', ">= 2.1.0"

gemfiles/rails_6_0.gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ GEM
7070
mini_magick (4.11.0)
7171
mini_portile2 (2.8.0)
7272
minitest (5.16.3)
73+
minitest-focus (1.4.0)
74+
minitest (>= 4, < 6)
7375
nokogiri (1.13.8)
7476
mini_portile2 (~> 2.8.0)
7577
racc (~> 1.4)
78+
nokogiri (1.13.8-x86_64-darwin)
79+
racc (~> 1.4)
80+
nokogiri (1.13.8-x86_64-linux)
81+
racc (~> 1.4)
7682
parallel (1.20.1)
7783
parser (3.0.0.0)
7884
ast (~> 2.4.1)
@@ -141,6 +147,7 @@ DEPENDENCIES
141147
globalid
142148
marcel
143149
mini_magick (>= 4.9.5)
150+
minitest-focus (~> 1.4)
144151
pry
145152
rubocop
146153
ruby-vips (>= 2.1.0)

gemfiles/rails_6_1.gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ GEM
7272
mini_magick (4.11.0)
7373
mini_portile2 (2.8.0)
7474
minitest (5.16.3)
75+
minitest-focus (1.4.0)
76+
minitest (>= 4, < 6)
7577
nokogiri (1.13.8)
7678
mini_portile2 (~> 2.8.0)
7779
racc (~> 1.4)
80+
nokogiri (1.13.8-x86_64-darwin)
81+
racc (~> 1.4)
82+
nokogiri (1.13.8-x86_64-linux)
83+
racc (~> 1.4)
7884
parallel (1.20.1)
7985
parser (3.0.0.0)
8086
ast (~> 2.4.1)
@@ -142,6 +148,7 @@ DEPENDENCIES
142148
globalid
143149
marcel
144150
mini_magick (>= 4.9.5)
151+
minitest-focus (~> 1.4)
145152
pry
146153
rubocop
147154
ruby-vips (>= 2.1.0)

gemfiles/rails_7_0.gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ GEM
6868
mini_mime (1.1.2)
6969
mini_portile2 (2.8.0)
7070
minitest (5.16.3)
71+
minitest-focus (1.4.0)
72+
minitest (>= 4, < 6)
7173
nokogiri (1.13.8)
7274
mini_portile2 (~> 2.8.0)
7375
racc (~> 1.4)
@@ -137,6 +139,7 @@ DEPENDENCIES
137139
globalid
138140
marcel
139141
mini_magick (>= 4.9.5)
142+
minitest-focus (~> 1.4)
140143
pry
141144
rubocop
142145
ruby-vips (>= 2.1.0)

gemfiles/rails_next.gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ GEM
130130
mini_mime (1.1.2)
131131
mini_portile2 (2.8.2)
132132
minitest (5.15.0)
133+
minitest-focus (1.4.0)
134+
minitest (>= 4, < 6)
133135
net-imap (0.2.3)
134136
digest
135137
net-protocol
@@ -215,6 +217,7 @@ DEPENDENCIES
215217
globalid
216218
marcel
217219
mini_magick (>= 4.9.5)
220+
minitest-focus (~> 1.4)
218221
pry
219222
rails!
220223
rubocop

lib/active_storage_validations/aspect_ratio_validator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: true
22

3+
require_relative 'concerns/symbolizable.rb'
34
require_relative 'metadata.rb'
45

56
module ActiveStorageValidations
67
class AspectRatioValidator < ActiveModel::EachValidator # :nodoc
78
include OptionProcUnfolding
89
include ErrorHandler
10+
include Symbolizable
911

1012
AVAILABLE_CHECKS = %i[with].freeze
1113
PRECISION = 3
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# frozen_string_literal: true
22

3+
require_relative 'concerns/symbolizable.rb'
4+
35
module ActiveStorageValidations
46
class AttachedValidator < ActiveModel::EachValidator # :nodoc:
57
include ErrorHandler
8+
include Symbolizable
9+
10+
ERROR_TYPES = %i[blank].freeze
611

712
def validate_each(record, attribute, _value)
813
return if record.send(attribute).attached?
914

1015
errors_options = initialize_error_options(options)
1116

12-
add_error(record, attribute, :blank, **errors_options)
17+
add_error(record, attribute, ERROR_TYPES.first, **errors_options)
1318
end
1419
end
1520
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Symbolizable
2+
extend ActiveSupport::Concern
3+
4+
class_methods do
5+
def to_sym
6+
validator_class = self.name.split("::").last
7+
validator_class.sub(/Validator/, '').underscore.to_sym
8+
end
9+
end
10+
end

0 commit comments

Comments
 (0)