diff --git a/.rubocop.yml b/.rubocop.yml index cb27cc7..6c9b620 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,7 +26,7 @@ RSpec/DescribeClass: RSpec/ExampleLength: # Default is 5 - Max: 10 + Max: 15 RSpec/MultipleExpectations: # Default is 1 diff --git a/Gemfile b/Gemfile index bbc87db..07ddc08 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,8 @@ group :development, :test do gem 'mysql2' if ENV['DB_TEST'] == 'mysql' gem 'pg' if ['postgres', 'postgresql'].include? ENV['DB_TEST'] + gem "image_processing", ">= 1.2" + gem 'simplecov' gem 'simplecov-lcov' diff --git a/gemfiles/rails_6_1_mssql.gemfile b/gemfiles/rails_6_1_mssql.gemfile index a9640c2..027d0bf 100644 --- a/gemfiles/rails_6_1_mssql.gemfile +++ b/gemfiles/rails_6_1_mssql.gemfile @@ -7,6 +7,7 @@ gem "rails", "~> 6.1.0" gem "tiny_tds" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_6_1_mssql.gemfile.lock b/gemfiles/rails_6_1_mssql.gemfile.lock index e158478..334123f 100644 --- a/gemfiles/rails_6_1_mssql.gemfile.lock +++ b/gemfiles/rails_6_1_mssql.gemfile.lock @@ -104,10 +104,14 @@ GEM fasterer (0.10.1) colorize (~> 0.7) ruby_parser (>= 3.19.1) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.21.4) @@ -121,6 +125,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) mini_portile2 (2.8.4) minitest (5.20.0) @@ -235,6 +240,8 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby_parser (3.20.3) sexp_processor (~> 4.16) rubyzip (2.3.2) @@ -283,6 +290,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) pry-rails rails (~> 6.1.0) rspec-rails diff --git a/gemfiles/rails_6_1_mysql.gemfile b/gemfiles/rails_6_1_mysql.gemfile index 556568d..7f07d2f 100644 --- a/gemfiles/rails_6_1_mysql.gemfile +++ b/gemfiles/rails_6_1_mysql.gemfile @@ -6,6 +6,7 @@ gem "mysql2" gem "rails", "~> 6.1.0" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_6_1_mysql.gemfile.lock b/gemfiles/rails_6_1_mysql.gemfile.lock index f125770..e548af9 100644 --- a/gemfiles/rails_6_1_mysql.gemfile.lock +++ b/gemfiles/rails_6_1_mysql.gemfile.lock @@ -101,10 +101,14 @@ GEM fasterer (0.9.0) colorize (~> 0.7) ruby_parser (>= 3.14.1) + ffi (1.16.3) globalid (1.0.0) activesupport (>= 5.0) i18n (1.10.0) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) loofah (2.14.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -113,6 +117,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.2) mini_portile2 (2.8.4) minitest (5.15.0) @@ -206,6 +211,8 @@ GEM rubocop-rspec (2.8.0) rubocop (~> 1.19) ruby-progressbar (1.11.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby_parser (3.18.1) sexp_processor (~> 4.16) rubyzip (2.3.2) @@ -251,6 +258,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) mysql2 pry-rails rails (~> 6.1.0) diff --git a/gemfiles/rails_6_1_postgres.gemfile b/gemfiles/rails_6_1_postgres.gemfile index 00d4388..4bade8e 100644 --- a/gemfiles/rails_6_1_postgres.gemfile +++ b/gemfiles/rails_6_1_postgres.gemfile @@ -6,6 +6,7 @@ gem "pg" gem "rails", "~> 6.1.0" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_6_1_postgres.gemfile.lock b/gemfiles/rails_6_1_postgres.gemfile.lock index f342785..eff97c7 100644 --- a/gemfiles/rails_6_1_postgres.gemfile.lock +++ b/gemfiles/rails_6_1_postgres.gemfile.lock @@ -101,10 +101,14 @@ GEM fasterer (0.9.0) colorize (~> 0.7) ruby_parser (>= 3.14.1) + ffi (1.16.3) globalid (1.0.0) activesupport (>= 5.0) i18n (1.10.0) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) loofah (2.14.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -113,6 +117,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.2) mini_portile2 (2.8.4) minitest (5.15.0) @@ -210,6 +215,8 @@ GEM rubocop-rspec (2.8.0) rubocop (~> 1.19) ruby-progressbar (1.11.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby_parser (3.18.1) sexp_processor (~> 4.16) rubyzip (2.3.2) @@ -255,6 +262,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) pg pry-rails rails (~> 6.1.0) diff --git a/gemfiles/rails_7_0_mssql.gemfile b/gemfiles/rails_7_0_mssql.gemfile index 02a1349..46dad46 100644 --- a/gemfiles/rails_7_0_mssql.gemfile +++ b/gemfiles/rails_7_0_mssql.gemfile @@ -7,6 +7,7 @@ gem "rails", "~> 7.0.0" gem "tiny_tds" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_7_0_mssql.gemfile.lock b/gemfiles/rails_7_0_mssql.gemfile.lock index 0d22060..c74d4c3 100644 --- a/gemfiles/rails_7_0_mssql.gemfile.lock +++ b/gemfiles/rails_7_0_mssql.gemfile.lock @@ -110,10 +110,14 @@ GEM fasterer (0.10.1) colorize (~> 0.7) ruby_parser (>= 3.19.1) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.21.4) @@ -127,6 +131,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.20.0) net-imap (0.4.3) @@ -239,6 +244,8 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby_parser (3.20.3) sexp_processor (~> 4.16) rubyzip (2.3.2) @@ -280,6 +287,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) pry-rails rails (~> 7.0.0) rspec-rails diff --git a/gemfiles/rails_7_0_mysql.gemfile b/gemfiles/rails_7_0_mysql.gemfile index b70d461..b1a917b 100644 --- a/gemfiles/rails_7_0_mysql.gemfile +++ b/gemfiles/rails_7_0_mysql.gemfile @@ -6,6 +6,7 @@ gem "mysql2" gem "rails", "~> 7.0.0" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_7_0_mysql.gemfile.lock b/gemfiles/rails_7_0_mysql.gemfile.lock index de9770c..72dc00d 100644 --- a/gemfiles/rails_7_0_mysql.gemfile.lock +++ b/gemfiles/rails_7_0_mysql.gemfile.lock @@ -107,10 +107,14 @@ GEM fasterer (0.10.1) colorize (~> 0.7) ruby_parser (>= 3.19.1) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.21.4) @@ -124,6 +128,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.20.0) mysql2 (0.5.5) @@ -239,6 +244,8 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby_parser (3.20.3) sexp_processor (~> 4.16) rubyzip (2.3.2) @@ -279,6 +286,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) mysql2 pry-rails rails (~> 7.0.0) diff --git a/gemfiles/rails_7_0_postgres.gemfile b/gemfiles/rails_7_0_postgres.gemfile index 0ec78af..e3779da 100644 --- a/gemfiles/rails_7_0_postgres.gemfile +++ b/gemfiles/rails_7_0_postgres.gemfile @@ -6,6 +6,7 @@ gem "pg" gem "rails", "~> 7.0.0" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_7_0_postgres.gemfile.lock b/gemfiles/rails_7_0_postgres.gemfile.lock index 43efae2..04167ed 100644 --- a/gemfiles/rails_7_0_postgres.gemfile.lock +++ b/gemfiles/rails_7_0_postgres.gemfile.lock @@ -107,10 +107,14 @@ GEM fasterer (0.10.1) colorize (~> 0.7) ruby_parser (>= 3.19.1) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.21.4) @@ -124,6 +128,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.20.0) net-imap (0.4.3) @@ -239,6 +244,8 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby_parser (3.20.3) sexp_processor (~> 4.16) rubyzip (2.3.2) @@ -279,6 +286,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) pg pry-rails rails (~> 7.0.0) diff --git a/gemfiles/rails_7_1_mysql.gemfile b/gemfiles/rails_7_1_mysql.gemfile index 999ffcf..33f538a 100644 --- a/gemfiles/rails_7_1_mysql.gemfile +++ b/gemfiles/rails_7_1_mysql.gemfile @@ -6,6 +6,7 @@ gem "mysql2" gem "rails", "~> 7.1.0" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_7_1_mysql.gemfile.lock b/gemfiles/rails_7_1_mysql.gemfile.lock index 35ba117..ac7be16 100644 --- a/gemfiles/rails_7_1_mysql.gemfile.lock +++ b/gemfiles/rails_7_1_mysql.gemfile.lock @@ -120,10 +120,14 @@ GEM fasterer (0.10.1) colorize (~> 0.7) ruby_parser (>= 3.19.1) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) io-console (0.6.0) irb (1.8.3) rdoc @@ -141,6 +145,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.20.0) mutex_m (0.1.2) @@ -267,6 +272,8 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby2_keywords (0.0.5) ruby_parser (3.20.3) sexp_processor (~> 4.16) @@ -309,6 +316,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) mysql2 pry-rails rails (~> 7.1.0) diff --git a/gemfiles/rails_7_1_postgres.gemfile b/gemfiles/rails_7_1_postgres.gemfile index 38d0afc..7243620 100644 --- a/gemfiles/rails_7_1_postgres.gemfile +++ b/gemfiles/rails_7_1_postgres.gemfile @@ -6,6 +6,7 @@ gem "pg" gem "rails", "~> 7.1.0" group :development, :test do + gem "image_processing", ">= 1.2" gem "simplecov" gem "simplecov-lcov" gem "capybara" diff --git a/gemfiles/rails_7_1_postgres.gemfile.lock b/gemfiles/rails_7_1_postgres.gemfile.lock index 49da516..ff66f1f 100644 --- a/gemfiles/rails_7_1_postgres.gemfile.lock +++ b/gemfiles/rails_7_1_postgres.gemfile.lock @@ -120,10 +120,14 @@ GEM fasterer (0.10.1) colorize (~> 0.7) ruby_parser (>= 3.19.1) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) io-console (0.6.0) irb (1.8.3) rdoc @@ -141,6 +145,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.20.0) mutex_m (0.1.2) @@ -267,6 +272,8 @@ GEM rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby2_keywords (0.0.5) ruby_parser (3.20.3) sexp_processor (~> 4.16) @@ -309,6 +316,7 @@ DEPENDENCIES capybara factory_bot_rails (~> 6.1) fasterer + image_processing (>= 1.2) pg pry-rails rails (~> 7.1.0) diff --git a/spec/dummy61/config/environments/test.rb b/spec/dummy61/config/environments/test.rb index 17d1f27..4669a8e 100644 --- a/spec/dummy61/config/environments/test.rb +++ b/spec/dummy61/config/environments/test.rb @@ -34,6 +34,7 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :db + config.active_storage.track_variants = true config.action_mailer.perform_caching = false diff --git a/spec/dummy70/config/environments/test.rb b/spec/dummy70/config/environments/test.rb index 608a860..ffade5d 100644 --- a/spec/dummy70/config/environments/test.rb +++ b/spec/dummy70/config/environments/test.rb @@ -36,6 +36,7 @@ # Store uploaded files on the local file system in a temporary directory. #config.active_storage.service = :test config.active_storage.service = :db + config.active_storage.track_variants = true config.action_mailer.perform_caching = false diff --git a/spec/dummy_base/app/models/post.rb b/spec/dummy_base/app/models/post.rb index 3e33d25..a62daca 100644 --- a/spec/dummy_base/app/models/post.rb +++ b/spec/dummy_base/app/models/post.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true class Post < ApplicationRecord - has_one_attached :some_file + has_one_attached :some_file do |attachable| + attachable.variant :thumb, resize_to_limit: [100, 100] + end validates :title, presence: true, allow_blank: false end diff --git a/spec/fixtures/files/file3.png b/spec/fixtures/files/file3.png new file mode 100644 index 0000000..c6de0c6 Binary files /dev/null and b/spec/fixtures/files/file3.png differ diff --git a/spec/integration/attachments_spec.rb b/spec/integration/attachments_spec.rb index f38a849..dcf6ed8 100644 --- a/spec/integration/attachments_spec.rb +++ b/spec/integration/attachments_spec.rb @@ -21,20 +21,27 @@ end context 'with an existing target entity' do - let(:filename) { 'file1.txt' } + let(:filename) { 'file3.png' } let!(:test_post) { Post.create!(title: 'A test post') } it 'attaches the file to the target entity', :aggregate_failures do expect { test_post.some_file.attach(io: file_fixture(filename).open, filename: filename) - }.to change(ActiveStorageDB::File, :count).by(1) + }.to change(ActiveStorageDB::File, :count).from(0).to(1) - expect(test_post.some_file).to be_attached - expect(test_post.some_file.download).to eq file_fixture(filename).read + variant = test_post.some_file.variant(:thumb) + expect { variant.process }.to change(ActiveStorageDB::File, :count).by(1) + + expect(test_post.some_file.attached?).to be true + expect(test_post.some_file.download).to eq file_fixture(filename).binread blob_path = Rails.application.routes.url_helpers.rails_blob_path(test_post.some_file, only_path: true) expect(blob_path).to match %r[/rails/active_storage/.+#{filename}] + + expect { + test_post.some_file.purge + }.to change(ActiveStorageDB::File, :count).by(-1) end end end