From 92bb23d914e56bc2cf1ca3f1595de4ab05bec92e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 16 Mar 2022 16:52:22 +1100 Subject: [PATCH] Add validation gem for Active Storage We used validations with Paperclip and it would be nice to keep them. --- Gemfile | 1 + Gemfile.lock | 6 ++++++ config/locales/en.yml | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/Gemfile b/Gemfile index c45d1a6972..a6ec2e5a78 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'dotenv-rails', require: 'dotenv/rails-now' # Load ENV vars before other gem gem 'rails', '>= 6.1.4' # Active Storage +gem "active_storage_validations" gem "aws-sdk-s3", require: false gem "image_processing" diff --git a/Gemfile.lock b/Gemfile.lock index ee36cee834..13fb10770e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,6 +101,11 @@ GEM rails-html-sanitizer (~> 1.1, >= 1.2.0) active_model_serializers (0.8.4) activemodel (>= 3.0) + active_storage_validations (0.9.7) + activejob (>= 5.2.0) + activemodel (>= 5.2.0) + activestorage (>= 5.2.0) + activesupport (>= 5.2.0) activejob (6.1.4.4) activesupport (= 6.1.4.4) globalid (>= 0.3.6) @@ -706,6 +711,7 @@ PLATFORMS DEPENDENCIES actionpack-action_caching active_model_serializers (= 0.8.4) + active_storage_validations activemerchant (>= 1.78.0) activerecord-import activerecord-postgresql-adapter diff --git a/config/locales/en.yml b/config/locales/en.yml index 78a009b389..854406c54d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -82,6 +82,30 @@ en: using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings" on_demand_but_count_on_hand_set: "must be blank if on demand" limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock" + + # Used by active_storage_validations + errors: + messages: + content_type_invalid: "has an invalid content type" + file_size_out_of_range: "size %{file_size} is not between required range" + limit_out_of_range: "total number is out of range" + image_metadata_missing: "is not a valid image" + dimension_min_inclusion: "must be greater than or equal to %{width} x %{height} pixel." + dimension_max_inclusion: "must be less than or equal to %{width} x %{height} pixel." + dimension_width_inclusion: "width is not included between %{min} and %{max} pixel." + dimension_height_inclusion: "height is not included between %{min} and %{max} pixel." + dimension_width_greater_than_or_equal_to: "width must be greater than or equal to %{length} pixel." + dimension_height_greater_than_or_equal_to: "height must be greater than or equal to %{length} pixel." + dimension_width_less_than_or_equal_to: "width must be less than or equal to %{length} pixel." + dimension_height_less_than_or_equal_to: "height must be less than or equal to %{length} pixel." + dimension_width_equal_to: "width must be equal to %{length} pixel." + dimension_height_equal_to: "height must be equal to %{length} pixel." + aspect_ratio_not_square: "must be a square image" + aspect_ratio_not_portrait: "must be a portrait image" + aspect_ratio_not_landscape: "must be a landscape image" + aspect_ratio_is_not: "must have an aspect ratio of %{aspect_ratio}" + aspect_ratio_unknown: "has an unknown aspect ratio" + stripe: error_code: incorrect_number: "The card number is incorrect."