Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References Marcel::TYPES only for Rails < 6.1 #138

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions active_storage_validations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def matches?(subject)
def failure_message
<<~MESSAGE
Expected #{@attribute_name}

Accept content types: #{allowed_types.join(", ")}
#{accepted_types_and_failures}

Expand All @@ -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?
Expand Down Expand Up @@ -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