Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mth0158 committed Dec 30, 2024
2 parents 9a0172b + 5ed0ae7 commit da685bb
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: Mth0158
patreon: igorkasyanchuk
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
- master

- 1.4.0
- https://github.com/igorkasyanchuk/active_storage_validations/pull/324
- https://github.com/igorkasyanchuk/active_storage_validations/pull/326
- https://github.com/igorkasyanchuk/active_storage_validations/pull/332
- https://github.com/igorkasyanchuk/active_storage_validations/pull/327
- https://github.com/igorkasyanchuk/active_storage_validations/pull/325
- https://github.com/igorkasyanchuk/active_storage_validations/pull/294

- 1.3.5
- https://github.com/igorkasyanchuk/active_storage_validations/pull/322
- https://github.com/igorkasyanchuk/active_storage_validations/pull/318
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
active_storage_validations (1.3.5)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
activestorage (>= 6.1.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6_1_4.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
active_storage_validations (1.3.5)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
activestorage (>= 6.1.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
active_storage_validations (1.3.5)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
activestorage (>= 6.1.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
active_storage_validations (1.3.5)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
activestorage (>= 6.1.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
active_storage_validations (1.3.5)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
activestorage (>= 6.1.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
active_storage_validations (1.3.5)
active_storage_validations (1.4.0)
activejob (>= 6.1.4)
activemodel (>= 6.1.4)
activestorage (>= 6.1.4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def failure_message
end

def allowing(*content_types)
@allowed_content_types = content_types.flatten
@allowed_content_types = content_types.map { |content_type| normalize_content_type(content_type) }.flatten
self
end

def rejecting(*content_types)
@rejected_content_types = content_types.flatten
@rejected_content_types = content_types.map { |content_type| normalize_content_type(content_type) }.flatten
self
end

Expand Down Expand Up @@ -88,6 +88,10 @@ def pluralize(types)
end
end

def normalize_content_type(content_type)
Marcel::MimeType.for(declared_type: content_type.to_s, extension: content_type.to_s)
end

def all_allowed_content_types_allowed?
@allowed_content_types_not_allowed ||= @allowed_content_types.reject { |type| type_allowed?(type) }
@allowed_content_types_not_allowed.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/active_storage_validations/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActiveStorageValidations
VERSION = '1.3.5'
VERSION = '1.4.0'
end
2 changes: 2 additions & 0 deletions test/dummy/app/models/content_type/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ContentType::Matcher < ApplicationRecord
has_one_attached :allowing_several_through_regex
validates :allowing_several_through_regex, content_type: [/\Aimage\/.*\z/]

has_one_attached :allowing_symbol
validates :allowing_symbol, content_type: :png
has_one_attached :allowing_sneaky_edge_cases
validates :allowing_sneaky_edge_cases, content_type: ["image/svg+xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"]

Expand Down
11 changes: 11 additions & 0 deletions test/matchers/content_type_validator_matcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@
end

describe 'Edge cases' do
describe "when the passed content_type is a symbol (e.g. :png)" do
let(:model_attribute) { :allowing_symbol }
let(:allowed_type) { :png }

describe 'when provided with the exact allowed type' do
subject { matcher.allowing(allowed_type) }

it { is_expected_to_match_for(klass) }
end
end

describe "when the content_type specifier (e.g. 'svg+xml') is not strictly equal to the file extension (e.g. '.svg')" do
let(:model_attribute) { :allowing_sneaky_edge_cases }
let(:allowed_types) { ["image/svg+xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"] }
Expand Down

0 comments on commit da685bb

Please sign in to comment.