Skip to content

Commit c1b9fc5

Browse files
authored
Merge pull request #382 from igorkasyanchuk/364-active_storage_validations-200-causing-stack-level-too-deep
364 active storage validations 200 causing stack level too deep
2 parents f36a326 + b5c3708 commit c1b9fc5

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- 2.0.4
22
- Fix issue when updating a child record through a parent (like: parent_model.update(child_attributes: { image: file })) for Rails >= 8.0.2 (https://github.com/igorkasyanchuk/active_storage_validations/pull/378)
3+
- Fix issue causing a stack error too deep edge case (not reproductible) because of the `after: :load_config_initializers` option (https://github.com/igorkasyanchuk/active_storage_validations/pull/382)
34

45
- 2.0.3
56
- Allow to pass an Array, a splatted Array, or a single string for allowing / rejecting content_type matcher methods (https://github.com/igorkasyanchuk/active_storage_validations/pull/372)

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ group :development, :test do
2323
# To use debugger:
2424
# gem "debug", "~> 1.10", ">= 1.10.0"
2525

26+
# To test S3 services
27+
# gem "aws-sdk-s3", require: false
28+
2629
# Linters
2730
gem "rubocop", "~> 1.71", ">= 1.71.1", require: false
2831
gem "rubocop-performance", "~> 1.23", ">= 1.23.1", require: false

lib/active_storage_validations/railtie.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
module ActiveStorageValidations
44
class Railtie < ::Rails::Railtie
5-
initializer "active_storage_validations.configure", after: :load_config_initializers do
5+
# Using after: :load_config_initializers would cause a stack level too deep error
6+
# See: https://github.com/igorkasyanchuk/active_storage_validations/issues/364
7+
8+
initializer "active_storage_validations.configure" do
69
ActiveSupport.on_load(:active_record) do
7-
send :include, ActiveStorageValidations
10+
include ActiveStorageValidations
811
end
912
end
1013

1114
initializer "active_storage_validations.extend_active_storage_blob" do
1215
ActiveSupport.on_load(:active_storage_blob) do
13-
include(ActiveStorageValidations::ASVBlobMetadatable)
16+
include ActiveStorageValidations::ASVBlobMetadatable
1417
end
1518
end
1619
end

test/dummy/app/models/active_storage_validations/check.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ class ActiveStorageValidations::Check < ApplicationRecord
2020
# its own custom mime types
2121
has_one_attached :asv_test
2222
validates :asv_test, content_type: "application/asv_test"
23+
24+
# This validator is related to a test that we can download files from a
25+
# service
26+
has_one_attached :digitalocean
27+
validates :digitalocean, content_type: "image/png"
2328
end

test/dummy/config/storage.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
test:
22
service: Disk
33
root: <%= Rails.root.join('tmp/storage') %>
4+
5+
digitalocean:
6+
service: S3
7+
endpoint: https://nyc3.digitaloceanspaces.com
8+
access_key_id: xxxx
9+
secret_access_key: xxx
10+
bucket: active_storage_validations_test
11+
region: eu-west-1

test/global/active_storage_validations_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@
3030
assert_equal(Marcel::MimeType.for(declared_type: "application/asv_test"), "application/asv_test")
3131
end
3232
end
33+
34+
describe "services" do
35+
# Uncomment this after having uncommented the S3 service in test_helper.rb
36+
#
37+
# describe "digitalocean" do
38+
# subject { instance }
39+
40+
# it "works fine with the digitalocean service" do
41+
# subject.digitalocean.attach(png_file)
42+
# end
43+
# end
44+
end
3345
end

test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
Combustion.path = "test/dummy"
1414
Combustion.initialize! :active_record, :active_storage, :active_job do
1515
config.active_storage.variant_processor = ENV["IMAGE_PROCESSOR"]&.to_sym
16+
17+
# Uncomment this to test S3 services
18+
# require "aws-sdk-s3"
19+
# config.active_storage.service = :digitalocean
20+
1621
config.active_job.queue_adapter = :inline
1722
end
1823

0 commit comments

Comments
 (0)