active_storage_validations 0.9.3 → 0.9.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d75309ae07f32e9107683721c2a700dea9a435cdc5801c8488a0bf2df18e6162
4
- data.tar.gz: 3f14dc96d9d8fff1fb309460c896d631db5777d663b6d7b00f47d08b5e8dc034
3
+ metadata.gz: 58ef7bbaa01aafa835921f0ad446b86e5b5c49a73a6f08e42feb97ff9bd3c7fd
4
+ data.tar.gz: e4f18d0de97ffa2adfe59e2d5d841706a8de3e6e575390aafb5b75dbf82a37a2
5
5
  SHA512:
6
- metadata.gz: a04233bd7b37c89c45fa9d7fe3ef32be5b50ed40181a2b29fa8711049958d8b2bcacceb7f8e4aa7fd7c9714fb506387c7f26050eeecb623f0ceb3d361b501cf7
7
- data.tar.gz: 0e43d6b501c8c8d45f1c99110d7504a8ca124353dbe26819f6c9febe34f1c4710c842f5c42945584a7e64bac10ad1efcc18a97afa5ea4987e04024b2f6cdf8d4
6
+ metadata.gz: 5b29620eb2a65e73c9f7c1c9d2bf143ba20aed0e460fdd763d415651b80463821f5dea26d2b28834dae7dc90ad035d6bbaa47bc7e89161365bfb154485a12c8b
7
+ data.tar.gz: ee7ef332175aca338df8d46de13ac0487f1aa4b5a3d7aa220bd14826b0f73f55377a6475c2b2eb9133d06aae456a2d18bdc4fbec07b7caaf9cd9fa3b8f1dcf5b
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Active Storage Validations
2
2
 
3
- ![MiniTest](https://github.com/igorkasyanchuk/active_storage_validations/workflows/MiniTest/badge.svg)
3
+ [![MiniTest](https://github.com/igorkasyanchuk/active_storage_validations/workflows/MiniTest/badge.svg)](https://github.com/igorkasyanchuk/active_storage_validations/actions)
4
4
  [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)
5
5
  [![https://www.patreon.com/igorkasyanchuk](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/patron.svg?raw=true)](https://www.patreon.com/igorkasyanchuk)
6
6
 
@@ -220,6 +220,7 @@ describe User do
220
220
 
221
221
  it { is_expected.to validate_dimensions_of(:avatar).width(250) }
222
222
  it { is_expected.to validate_dimensions_of(:avatar).height(200) }
223
+ it { is_expected.to validate_dimensions_of(:avatar).width(250).height(200).with_message('Invalid dimensions.') }
223
224
  it { is_expected.to validate_dimensions_of(:avatar).width_min(200) }
224
225
  it { is_expected.to validate_dimensions_of(:avatar).width_max(500) }
225
226
  it { is_expected.to validate_dimensions_of(:avatar).height_min(100) }
@@ -261,6 +262,7 @@ class UserTest < ActiveSupport::TestCase
261
262
 
262
263
  should validate_dimensions_of(:avatar).width(250)
263
264
  should validate_dimensions_of(:avatar).height(200)
265
+ should validate_dimensions_of(:avatar).width(250).height(200).with_message('Invalid dimensions.')
264
266
  should validate_dimensions_of(:avatar).width_min(200)
265
267
  should validate_dimensions_of(:avatar).width_max(500)
266
268
  should validate_dimensions_of(:avatar).height_min(100)
@@ -339,6 +341,9 @@ You are welcome to contribute.
339
341
  - https://github.com/fongfan999
340
342
  - https://github.com/cooperka
341
343
  - https://github.com/dolarsrg
344
+ - https://github.com/jayshepherd
345
+ - https://github.com/ohbarye
346
+ - https://github.com/...
342
347
 
343
348
  ## License
344
349
 
@@ -5,7 +5,10 @@ module ActiveStorageValidations
5
5
  def validate_each(record, attribute, _value)
6
6
  return if record.send(attribute).attached?
7
7
 
8
- record.errors.add(attribute, :blank)
8
+ errors_options = {}
9
+ errors_options[:message] = options[:message] if options[:message].present?
10
+
11
+ record.errors.add(attribute, :blank, **errors_options)
9
12
  end
10
13
  end
11
14
  end
@@ -21,7 +21,14 @@ module ActiveStorageValidations
21
21
 
22
22
  def types
23
23
  (Array.wrap(options[:with]) + Array.wrap(options[:in])).compact.map do |type|
24
- Mime[type] || type
24
+ if type.is_a?(Regexp)
25
+ type
26
+ elsif type.is_a?(String) && type =~ %r{\A\w+/[-+.\w]+\z} # mime-type-ish string
27
+ type
28
+ else
29
+ Mime[type] || raise(ArgumentError, "content_type must be one of Regxep,"\
30
+ " supported mime types (e.g. :png, 'jpg'), or mime type String ('image/jpeg')")
31
+ end
25
32
  end
26
33
  end
27
34
 
@@ -10,6 +10,7 @@ module ActiveStorageValidations
10
10
  def initialize(attribute_name)
11
11
  @attribute_name = attribute_name
12
12
  @width_min = @width_max = @height_min = @height_max = nil
13
+ @custom_message = nil
13
14
  end
14
15
 
15
16
  def description
@@ -26,6 +27,11 @@ module ActiveStorageValidations
26
27
  self
27
28
  end
28
29
 
30
+ def with_message(message)
31
+ @custom_message = message
32
+ self
33
+ end
34
+
29
35
  def width(width)
30
36
  @width_min = @width_max = width
31
37
  self
@@ -133,7 +139,8 @@ module ActiveStorageValidations
133
139
  attachment = @subject.public_send(@attribute_name)
134
140
  Matchers.mock_metadata(attachment, width, height) do
135
141
  @subject.validate
136
- @subject.errors.details[@attribute_name].all? { |error| error[:error].to_s.exclude?("dimension_#{check}") }
142
+ exclude_error_message = @custom_message || "dimension_#{check}"
143
+ @subject.errors.details[@attribute_name].all? { |error| error[:error].to_s.exclude?(exclude_error_message) }
137
144
  end
138
145
  end
139
146
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveStorageValidations
4
- VERSION = '0.9.3'
4
+ VERSION = '0.9.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubygems_version: 3.1.4
156
+ rubygems_version: 3.0.3
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Validations for Active Storage