carrierwave_backgrounder 1.0.2 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-ci.yml +43 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +15 -0
- data/README.md +5 -12
- data/carrierwave_backgrounder.gemspec +5 -2
- data/lib/backgrounder/support/backends.rb +17 -5
- data/lib/backgrounder/version.rb +1 -1
- data/lib/backgrounder/workers/base.rb +2 -1
- data/lib/backgrounder/workers/process_asset_mixin.rb +3 -0
- data/lib/carrierwave_backgrounder.rb +7 -13
- data/lib/generators/carrierwave_backgrounder/templates/config/initializers/carrierwave_backgrounder.rb +3 -0
- data/spec/backgrounder/orm/activemodel_spec.rb +1 -2
- data/spec/backgrounder/support/backends_spec.rb +3 -1
- data/spec/integrations/process_in_background_spec.rb +29 -0
- data/spec/integrations/queue_name_spec.rb +68 -0
- data/spec/integrations/store_in_background_spec.rb +34 -0
- data/spec/rails_helper.rb +13 -0
- data/spec/support/dummy_app/Gemfile +3 -4
- data/spec/support/dummy_app/app/jobs/portrait_process_job.rb +5 -0
- data/spec/support/dummy_app/app/models/admin.rb +1 -1
- data/spec/support/dummy_app/app/models/user.rb +4 -1
- data/spec/support/dummy_app/app/uploaders/avatar_uploader.rb +1 -0
- data/spec/support/dummy_app/bin/ci +6 -0
- data/spec/support/dummy_app/bin/dev +2 -0
- data/spec/support/dummy_app/bin/setup +7 -5
- data/spec/support/dummy_app/config/application.rb +6 -1
- data/spec/support/dummy_app/config/ci.rb +14 -0
- data/spec/support/dummy_app/config/environments/development.rb +19 -29
- data/spec/support/dummy_app/config/environments/production.rb +35 -54
- data/spec/support/dummy_app/config/environments/test.rb +16 -36
- data/spec/support/dummy_app/config/initializers/carrierwave_backgrounder.rb +3 -0
- data/spec/support/dummy_app/config/initializers/cors.rb +1 -1
- data/spec/support/dummy_app/config/initializers/filter_parameter_logging.rb +4 -4
- data/spec/support/dummy_app/config/initializers/new_framework_defaults_8_0.rb +30 -0
- data/spec/support/dummy_app/config/initializers/new_framework_defaults_8_1.rb +74 -0
- data/spec/support/dummy_app/config/puma.rb +42 -0
- data/spec/support/dummy_app/db/migrate/20250926184915_add_columns_for_portrait.rb +7 -0
- data/spec/support/dummy_app/db/schema.rb +4 -2
- data/spec/support/mock_worker.rb +6 -0
- metadata +26 -12
- data/.travis.yml +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5261f9e14c16c978b41ba71d0074359b5ec321d0ee7e3b410685e770f246fb87
|
|
4
|
+
data.tar.gz: 105e8b097e25d084f33d75e1556c3227aa6b758e5045315ce893fe2f0cda086b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c9a5084377b753246a7be2c3d5f087c24b524c0f821b8a3375047512f766d0c0ca8a876e826a93bec2a389394e9e892c6e727ef11854c2e247721b4640ae8e0
|
|
7
|
+
data.tar.gz: 3d1d565d67a68c651b56a5eed01e10fa5a50e69a5b6b8880ee88daaa2507eda01eba2015732455ab64de8e5cb267d8f7640048e96649586c28fe04058f51cb2e
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Ruby CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
ruby: ['3.2', '3.4', 'ruby-head']
|
|
16
|
+
queue_adapter: ['sidekiq', 'active_job']
|
|
17
|
+
continue-on-error: ${{ matrix.ruby == 'ruby-head' }}
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install ImageMagick
|
|
22
|
+
run: sudo apt-get update && sudo apt-get install -y imagemagick
|
|
23
|
+
|
|
24
|
+
- name: Set up Ruby
|
|
25
|
+
uses: ruby/setup-ruby@v1
|
|
26
|
+
with:
|
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
|
28
|
+
bundler-cache: true
|
|
29
|
+
|
|
30
|
+
- name: Update RubyGems
|
|
31
|
+
run: yes | gem update --system --force
|
|
32
|
+
|
|
33
|
+
- name: Install Bundler
|
|
34
|
+
run: gem install bundler
|
|
35
|
+
|
|
36
|
+
- name: Set QUEUE_ADAPTER env
|
|
37
|
+
run: echo "QUEUE_ADAPTER=${{ matrix.queue_adapter }}" >> $GITHUB_ENV
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: bundle install --jobs 4 --retry 3
|
|
41
|
+
|
|
42
|
+
- name: Run tests
|
|
43
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## 1.1.2
|
|
2
|
+
|
|
3
|
+
### enhancements
|
|
4
|
+
* Add support for Rails 8.1 [gstokkink]
|
|
5
|
+
|
|
6
|
+
## 1.1.0
|
|
7
|
+
|
|
8
|
+
### enhancements
|
|
9
|
+
* Suppress NotFoundError if a record gets deleted before it is processed. This is configurable and defaults to true. [lardawge]
|
|
10
|
+
|
|
11
|
+
## 1.0.3
|
|
12
|
+
|
|
13
|
+
### enhancements
|
|
14
|
+
* Add support for Rails 8.0 [damisul]
|
|
15
|
+
|
|
1
16
|
## 1.0.2
|
|
2
17
|
|
|
3
18
|
### bugfixes
|
data/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# CarrierWave Backgrounder
|
|
2
2
|
|
|
3
|
-
[](https://github.com/lardawge/carrierwave_backgrounder/actions/workflows/ruby-ci.yml)
|
|
4
|
+
[](https://qlty.sh/gh/lardawge/projects/carrierwave_backgrounder)
|
|
5
|
+
---
|
|
6
|
+
NOTICE: Version 1.1.0 contains a change in behavior from previous version. When a record is deleted before the job is picked up, it will no longer raise an error. Prior to this change, when using `process_in_background`, if a record was missing, an error was raised. Some users might have relied on that. By default, this will no longer happen. If you want to maintain that behavior, you must set the `suppress_record_not_found_errors` configuration to `false`. This will raise a RecordNotFound error.
|
|
10
7
|
|
|
8
|
+
---
|
|
11
9
|
I am a fan of CarrierWave. That being said, I don't like tying up requests waiting for images to process.
|
|
12
10
|
|
|
13
11
|
This gem addresses that by offloading processing or storaging/processing to a background task.
|
|
@@ -190,11 +188,6 @@ class MyActiveJobWorker < ::CarrierWave::Workers::ActiveJob::StoreAsset
|
|
|
190
188
|
end
|
|
191
189
|
```
|
|
192
190
|
|
|
193
|
-
### Testing with Rspec
|
|
194
|
-
We use the after_commit hook when using active_record. This creates a problem when testing with Rspec because after_commit never gets fired
|
|
195
|
-
if you're using transactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
|
|
196
|
-
There are various other solutions in which case google is your friend.
|
|
197
|
-
|
|
198
191
|
## License
|
|
199
192
|
|
|
200
193
|
Copyright (c) 2011 Larry Sprock
|
|
@@ -6,19 +6,22 @@ Gem::Specification.new do |s|
|
|
|
6
6
|
s.name = "carrierwave_backgrounder"
|
|
7
7
|
s.version = CarrierWave::Backgrounder::VERSION
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
|
+
|
|
9
10
|
s.authors = ["Larry Sprock"]
|
|
10
11
|
s.email = ["larry@lucidbleu.com"]
|
|
11
12
|
s.homepage = "https://github.com/lardawge/carrierwave_backgrounder"
|
|
12
13
|
s.licenses = ["MIT"]
|
|
13
|
-
s.summary = %q{Offload CarrierWave's image processing and storage to a background process using
|
|
14
|
+
s.summary = %q{Offload CarrierWave's image processing and storage to a background process using ActiveJob or Sidekiq.}
|
|
14
15
|
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
|
16
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
17
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
19
|
s.require_paths = ["lib"]
|
|
19
20
|
|
|
21
|
+
s.required_ruby_version = '>= 3.0'
|
|
22
|
+
|
|
20
23
|
s.add_dependency "carrierwave", ["> 2.0", "< 4.0"]
|
|
21
|
-
s.add_dependency "rails", ["> 6.0", "< 8.
|
|
24
|
+
s.add_dependency "rails", ["> 6.0", "< 8.2"]
|
|
22
25
|
|
|
23
26
|
s.add_development_dependency "rspec", ["~> 3.12"]
|
|
24
27
|
s.add_development_dependency "rake"
|
|
@@ -10,10 +10,10 @@ module CarrierWave
|
|
|
10
10
|
module ClassMethods
|
|
11
11
|
attr_reader :queue_options
|
|
12
12
|
|
|
13
|
-
def backend(
|
|
13
|
+
def backend(backend_name=nil, args={})
|
|
14
14
|
return @backend if @backend
|
|
15
|
-
@queue_options = args
|
|
16
|
-
@backend =
|
|
15
|
+
@queue_options = set_queue_name_default(args)
|
|
16
|
+
@backend = backend_name
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
|
|
@@ -23,17 +23,29 @@ module CarrierWave
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
def enqueue_active_job(worker, *args)
|
|
26
|
-
worker.
|
|
26
|
+
options = if worker.new.queue_name != 'default'
|
|
27
|
+
queue_options.except(:queue)
|
|
28
|
+
else
|
|
29
|
+
queue_options
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
worker.set(options).perform_later(*args.map(&:to_s))
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
def enqueue_sidekiq(worker, *args)
|
|
30
|
-
override_queue_name = worker.sidekiq_options['queue'] == 'default'
|
|
36
|
+
override_queue_name = worker.sidekiq_options['queue'] == 'default'
|
|
31
37
|
args = sidekiq_queue_options(override_queue_name, 'class' => worker, 'args' => args.map(&:to_s))
|
|
32
38
|
worker.client_push(args)
|
|
33
39
|
end
|
|
34
40
|
|
|
35
41
|
private
|
|
36
42
|
|
|
43
|
+
def set_queue_name_default(options)
|
|
44
|
+
options.tap do |opts|
|
|
45
|
+
opts[:queue] ||= :carrierwave
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
37
49
|
def sidekiq_queue_options(override_queue_name, args)
|
|
38
50
|
if override_queue_name && queue_options[:queue]
|
|
39
51
|
args['queue'] = queue_options[:queue]
|
data/lib/backgrounder/version.rb
CHANGED
|
@@ -14,12 +14,13 @@ module CarrierWave
|
|
|
14
14
|
set_args(*args) if args.present?
|
|
15
15
|
self.record = constantized_resource.find id
|
|
16
16
|
rescue *not_found_errors
|
|
17
|
+
raise not_found_errors.first unless CarrierWave::Backgrounder.suppress_not_found_errors
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
private
|
|
20
21
|
|
|
21
22
|
def not_found_errors
|
|
22
|
-
[].tap do |errors|
|
|
23
|
+
@not_found_errors ||= [].tap do |errors|
|
|
23
24
|
errors << ::ActiveRecord::RecordNotFound if defined?(::ActiveRecord)
|
|
24
25
|
errors << ::Mongoid::Errors::DocumentNotFound if defined?(::Mongoid)
|
|
25
26
|
end
|
|
@@ -9,32 +9,22 @@ module CarrierWave
|
|
|
9
9
|
include Support::Backends
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
attr_reader :worker_klass
|
|
12
|
+
attr_reader :worker_klass, :suppress_not_found_errors
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.configure
|
|
16
16
|
yield self
|
|
17
17
|
|
|
18
|
+
@suppress_not_found_errors ||= true
|
|
19
|
+
|
|
18
20
|
case backend
|
|
19
21
|
when :active_job
|
|
20
22
|
@worker_klass = 'CarrierWave::Workers::ActiveJob'
|
|
21
|
-
|
|
22
|
-
require 'active_job'
|
|
23
23
|
require 'backgrounder/workers/active_job/process_asset'
|
|
24
24
|
require 'backgrounder/workers/active_job/store_asset'
|
|
25
|
-
|
|
26
|
-
queue_name = queue_options[:queue] || 'carrierwave'
|
|
27
|
-
|
|
28
|
-
::CarrierWave::Workers::ActiveJob::ProcessAsset.class_eval do
|
|
29
|
-
queue_as queue_name
|
|
30
|
-
end
|
|
31
|
-
::CarrierWave::Workers::ActiveJob::StoreAsset.class_eval do
|
|
32
|
-
queue_as queue_name
|
|
33
|
-
end
|
|
34
25
|
when :sidekiq
|
|
35
26
|
@worker_klass = 'CarrierWave::Workers'
|
|
36
27
|
|
|
37
|
-
require 'sidekiq'
|
|
38
28
|
::CarrierWave::Workers::ProcessAsset.class_eval do
|
|
39
29
|
include ::Sidekiq::Worker
|
|
40
30
|
end
|
|
@@ -43,6 +33,10 @@ module CarrierWave
|
|
|
43
33
|
end
|
|
44
34
|
end
|
|
45
35
|
end
|
|
36
|
+
|
|
37
|
+
def self.suppress_record_not_found_errors(suppress_errors = true)
|
|
38
|
+
@suppress_not_found_errors = suppress_errors
|
|
39
|
+
end
|
|
46
40
|
end
|
|
47
41
|
end
|
|
48
42
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
CarrierWave::Backgrounder.configure do |c|
|
|
2
2
|
c.backend :active_job, queue: :carrierwave
|
|
3
3
|
# c.backend :sidekiq, queue: :carrierwave
|
|
4
|
+
|
|
5
|
+
## Uncomment if you would like a NotFoundError raised if a record is deleted before processing
|
|
6
|
+
# c.suppress_record_not_found_errors false
|
|
4
7
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'ostruct'
|
|
3
2
|
require 'backgrounder/orm/activemodel'
|
|
4
3
|
|
|
5
4
|
RSpec.describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
@@ -9,7 +8,7 @@ RSpec.describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
|
9
8
|
def self.after_commit(method, opts); nil; end
|
|
10
9
|
def avatar_changed?; nil; end
|
|
11
10
|
def avatar_present?; true; end
|
|
12
|
-
def remote_avatar_url;
|
|
11
|
+
def remote_avatar_url; true; end
|
|
13
12
|
def remove_avatar?; false; end
|
|
14
13
|
def previous_changes; {}; end
|
|
15
14
|
def self.uploader_options; {}; end
|
|
@@ -44,7 +44,9 @@ module CarrierWave::Backgrounder
|
|
|
44
44
|
let(:args) { ['FakeClass', 1, :image] }
|
|
45
45
|
|
|
46
46
|
it 'invokes client_push on the class with passed args' do
|
|
47
|
-
expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker,
|
|
47
|
+
expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker,
|
|
48
|
+
'args' => args.map(&:to_s),
|
|
49
|
+
'queue' => :carrierwave })
|
|
48
50
|
mock_module.backend :sidekiq
|
|
49
51
|
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
|
50
52
|
end
|
|
@@ -22,6 +22,35 @@ RSpec.describe '::process_in_background', clear_images: true do
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
context 'when a record gets deleted before it is processed' do
|
|
26
|
+
context 'and suppress_record_not_found_errors is set to true' do
|
|
27
|
+
before do
|
|
28
|
+
admin.update(avatar: load_file('test-1.jpg'))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'does not raise an error' do
|
|
32
|
+
admin.delete
|
|
33
|
+
expect { process_latest_sidekiq_job }.not_to raise_error
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'and suppress_record_not_found_errors is set to false' do
|
|
38
|
+
before do
|
|
39
|
+
admin.update(avatar: load_file('test-1.jpg'))
|
|
40
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(false)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
after do
|
|
44
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(true)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'raises an error' do
|
|
48
|
+
admin.delete
|
|
49
|
+
expect { process_latest_sidekiq_job }.to raise_error(ActiveRecord::RecordNotFound)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
25
54
|
context 'when processing the worker' do
|
|
26
55
|
before do
|
|
27
56
|
admin.update(avatar: load_file('test-1.jpg'))
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe 'Queue Name', clear_images: true do
|
|
4
|
+
let(:user) { User.new }
|
|
5
|
+
|
|
6
|
+
context 'when using built in worker' do
|
|
7
|
+
context 'when queue name is passed in via config' do
|
|
8
|
+
before do
|
|
9
|
+
CarrierWave::Backgrounder.instance_variable_set(:@queue_options, queue: 'carrierwaver')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after do
|
|
13
|
+
CarrierWave::Backgrounder.instance_variable_set(:@queue_options, queue: 'carrierwave')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'uses the config queue name' do
|
|
17
|
+
user.update(avatar: load_file('test-1.jpg'))
|
|
18
|
+
expect(Sidekiq::Queues["carrierwaver"].size).to eql(1)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when not queue name is not set' do
|
|
23
|
+
it 'uses the default name carrierwave' do
|
|
24
|
+
user.update(avatar: load_file('test-1.jpg'))
|
|
25
|
+
expect(Sidekiq::Queues["carrierwave"].size).to eql(1)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'when using a subclassed worker' do
|
|
31
|
+
context 'when queue name is passed in via config' do
|
|
32
|
+
before do
|
|
33
|
+
CarrierWave::Backgrounder.instance_variable_set(:@queue_options, queue: 'carrierwaver')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
after do
|
|
37
|
+
CarrierWave::Backgrounder.instance_variable_set(:@queue_options, queue: 'carrierwave')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'uses the config queue name' do
|
|
41
|
+
user.update(portrait: load_file('test-1.jpg'))
|
|
42
|
+
expect(Sidekiq::Queues["carrierwaver"].size).to eql(1)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'when not queue name is not set' do
|
|
47
|
+
it 'uses the default name carrierwave' do
|
|
48
|
+
user.update(portrait: load_file('test-1.jpg'))
|
|
49
|
+
expect(Sidekiq::Queues["carrierwave"].size).to eql(1)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context 'when overridden via subclassed worker' do
|
|
54
|
+
before do
|
|
55
|
+
PortraitProcessJob.queue_as :custom_queue
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
after do
|
|
59
|
+
PortraitProcessJob.queue_as :carrierwave
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'uses the queue name passed in' do
|
|
63
|
+
user.update(portrait: load_file('test-1.jpg'))
|
|
64
|
+
expect(Sidekiq::Queues["custom_queue"].size).to eql(1)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -31,6 +31,11 @@ RSpec.describe '::store_in_background', clear_images: true do
|
|
|
31
31
|
user.reload
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
it 'processes the original image' do
|
|
35
|
+
image = MiniMagick::Image.open(user.avatar.path)
|
|
36
|
+
expect(image.width).to eql(1960)
|
|
37
|
+
end
|
|
38
|
+
|
|
34
39
|
it 'creates the versions' do
|
|
35
40
|
version_paths = user.avatar.versions.keys.map { |key| user.avatar.send(key).current_path }
|
|
36
41
|
version_paths.each { |path| expect(File.exist?(path)).to be(true) }
|
|
@@ -63,6 +68,35 @@ RSpec.describe '::store_in_background', clear_images: true do
|
|
|
63
68
|
end
|
|
64
69
|
end
|
|
65
70
|
|
|
71
|
+
context 'when a record gets deleted before it is processed' do
|
|
72
|
+
context 'and suppress_record_not_found_errors is set to true' do
|
|
73
|
+
before do
|
|
74
|
+
user.update(avatar: load_file('test-1.jpg'))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'does not raise an error' do
|
|
78
|
+
user.delete
|
|
79
|
+
expect { process_latest_sidekiq_job }.not_to raise_error
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context 'and suppress_record_not_found_errors is set to false' do
|
|
84
|
+
before do
|
|
85
|
+
user.update(avatar: load_file('test-1.jpg'))
|
|
86
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(false)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
after do
|
|
90
|
+
CarrierWave::Backgrounder.suppress_record_not_found_errors(true)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'raises an error' do
|
|
94
|
+
user.delete
|
|
95
|
+
expect { process_latest_sidekiq_job }.to raise_error(ActiveRecord::RecordNotFound)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
66
100
|
context 'when setting a column for removal' do
|
|
67
101
|
let!(:user) {
|
|
68
102
|
Sidekiq::Testing.inline! do
|
data/spec/rails_helper.rb
CHANGED
|
@@ -7,6 +7,19 @@ require 'sidekiq/testing'
|
|
|
7
7
|
require 'rspec/rails'
|
|
8
8
|
require 'backgrounder/railtie'
|
|
9
9
|
|
|
10
|
+
if ENV['QUEUE_ADAPTER'] == 'sidekiq'
|
|
11
|
+
Object.send(:remove_const, :PortraitProcessJob) if defined?(PortraitProcessJob)
|
|
12
|
+
class PortraitProcessJob
|
|
13
|
+
include CarrierWave::Workers::ProcessAssetMixin
|
|
14
|
+
include Sidekiq::Worker
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
Object.send(:remove_const, :PortraitProcessJob) if defined?(PortraitProcessJob)
|
|
18
|
+
class PortraitProcessJob < ::ActiveJob::Base
|
|
19
|
+
include CarrierWave::Workers::ProcessAssetMixin
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
10
23
|
begin
|
|
11
24
|
ActiveRecord::Migration.maintain_test_schema!
|
|
12
25
|
rescue ActiveRecord::PendingMigrationError => e
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
3
3
|
|
|
4
|
-
ruby "3.
|
|
4
|
+
ruby "3.4.5"
|
|
5
5
|
|
|
6
6
|
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
|
7
|
-
gem "rails", "~>
|
|
7
|
+
gem "rails", "~> 8.1.1"
|
|
8
8
|
|
|
9
9
|
# Use sqlite3 as the database for Active Record
|
|
10
|
-
gem "sqlite3", "~>
|
|
10
|
+
gem "sqlite3", "~> 2.7"
|
|
11
11
|
|
|
12
12
|
# Use the Puma web server [https://github.com/puma/puma]
|
|
13
13
|
# gem "puma", "~> 5.0"
|
|
@@ -46,4 +46,3 @@ group :development do
|
|
|
46
46
|
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
|
47
47
|
# gem "spring"
|
|
48
48
|
end
|
|
49
|
-
|
|
@@ -6,5 +6,8 @@ class User < ApplicationRecord
|
|
|
6
6
|
# Multi attachment support
|
|
7
7
|
mount_uploaders :images, AvatarUploader
|
|
8
8
|
store_in_background :images
|
|
9
|
-
serialize :images, JSON
|
|
9
|
+
serialize :images, coder: JSON
|
|
10
|
+
|
|
11
|
+
mount_uploader :portrait, AvatarUploader
|
|
12
|
+
store_in_background :portrait, PortraitProcessJob
|
|
10
13
|
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require "fileutils"
|
|
3
3
|
|
|
4
|
-
# path to your application root.
|
|
5
4
|
APP_ROOT = File.expand_path("..", __dir__)
|
|
6
5
|
|
|
7
6
|
def system!(*args)
|
|
8
|
-
system(*args
|
|
7
|
+
system(*args, exception: true)
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
FileUtils.chdir APP_ROOT do
|
|
@@ -14,7 +13,6 @@ FileUtils.chdir APP_ROOT do
|
|
|
14
13
|
# Add necessary setup steps to this file.
|
|
15
14
|
|
|
16
15
|
puts "== Installing dependencies =="
|
|
17
|
-
system! "gem install bundler --conservative"
|
|
18
16
|
system("bundle check") || system!("bundle install")
|
|
19
17
|
|
|
20
18
|
# puts "\n== Copying sample files =="
|
|
@@ -24,10 +22,14 @@ FileUtils.chdir APP_ROOT do
|
|
|
24
22
|
|
|
25
23
|
puts "\n== Preparing database =="
|
|
26
24
|
system! "bin/rails db:prepare"
|
|
25
|
+
system! "bin/rails db:reset" if ARGV.include?("--reset")
|
|
27
26
|
|
|
28
27
|
puts "\n== Removing old logs and tempfiles =="
|
|
29
28
|
system! "bin/rails log:clear tmp:clear"
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
unless ARGV.include?("--skip-server")
|
|
31
|
+
puts "\n== Starting development server =="
|
|
32
|
+
STDOUT.flush # flush the output before exec(2) so that it displays
|
|
33
|
+
exec "bin/dev"
|
|
34
|
+
end
|
|
33
35
|
end
|
|
@@ -21,7 +21,12 @@ Bundler.require(*Rails.groups)
|
|
|
21
21
|
module DummyApp
|
|
22
22
|
class Application < Rails::Application
|
|
23
23
|
# Initialize configuration defaults for originally generated Rails version.
|
|
24
|
-
config.load_defaults
|
|
24
|
+
config.load_defaults 8.0
|
|
25
|
+
|
|
26
|
+
# Please, add to the `ignore` list any other `lib` subdirectories that do
|
|
27
|
+
# not contain `.rb` files, or that should not be reloaded or eager loaded.
|
|
28
|
+
# Common ones are `templates`, `generators`, or `middleware`, for example.
|
|
29
|
+
config.autoload_lib(ignore: %w[assets tasks])
|
|
25
30
|
|
|
26
31
|
# Configuration for the application, engines, and railties goes here.
|
|
27
32
|
#
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Run using bin/ci
|
|
2
|
+
|
|
3
|
+
CI.run do
|
|
4
|
+
step "Setup", "bin/setup --skip-server"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Optional: set a green GitHub commit status to unblock PR merge.
|
|
8
|
+
# Requires the `gh` CLI and `gh extension install basecamp/gh-signoff`.
|
|
9
|
+
# if success?
|
|
10
|
+
# step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff"
|
|
11
|
+
# else
|
|
12
|
+
# failure "Signoff: CI failed. Do not merge or deploy.", "Fix the issues and try again."
|
|
13
|
+
# end
|
|
14
|
+
end
|