From 7b37e21d2ffc7704557c04f649c933ab5b9337ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Eug=C3=AAnio?= Date: Tue, 7 Dec 2021 14:14:15 +0000 Subject: [PATCH 1/2] References `Marcel::TYPES` only for Rails < 6.1 --- .../matchers/content_type_validator_matcher.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/active_storage_validations/matchers/content_type_validator_matcher.rb b/lib/active_storage_validations/matchers/content_type_validator_matcher.rb index 95a6fd42..4867ea24 100644 --- a/lib/active_storage_validations/matchers/content_type_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/content_type_validator_matcher.rb @@ -35,7 +35,7 @@ def matches?(subject) def failure_message <<~MESSAGE Expected #{@attribute_name} - + Accept content types: #{allowed_types.join(", ")} #{accepted_types_and_failures} @@ -57,7 +57,7 @@ def allowed_types end def rejected_types - @rejected_types || (Marcel::TYPES.keys - allowed_types) + @rejected_types || (content_type_keys - allowed_types) end def allowed_types_allowed? @@ -96,6 +96,16 @@ def attachment_for(type) suffix = type.to_s.split('/').last { io: Tempfile.new('.'), filename: "test.#{suffix}", content_type: type } end + + private + + def content_type_keys + if Rails.gem_version < Gem::Version.new('6.1.0') + Mime::LOOKUP.keys + else + Marcel::TYPES.keys + end + end end end end From f096a18f04bbee64014423450c191cd49b51ad04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Eug=C3=AAnio?= Date: Tue, 7 Dec 2021 15:30:47 +0000 Subject: [PATCH 2/2] Add `Marcel` as development dependency --- active_storage_validations.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/active_storage_validations.gemspec b/active_storage_validations.gemspec index b6a89957..2e2afb8e 100644 --- a/active_storage_validations.gemspec +++ b/active_storage_validations.gemspec @@ -24,4 +24,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry' s.add_development_dependency 'rubocop' s.add_development_dependency 'sqlite3' + s.add_development_dependency 'marcel' end