mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Respect rails' generators test_framework
option and gracefully handle extra worker
suffix on generator
This commit is contained in:
parent
626f0bba3b
commit
9aed617749
3 changed files with 52 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
HEAD
|
||||
---------
|
||||
|
||||
- Respect rails' generators `test_framework` option and gracefully handle extra `worker` suffix on generator [#4256]
|
||||
- Add ability to sort 'Enqueued' page on Web UI by position in the queue [#4248]
|
||||
- Support `Client.push_bulk` with different delays [#4243]
|
||||
```ruby
|
||||
|
|
|
@ -16,6 +16,8 @@ module Sidekiq
|
|||
end
|
||||
|
||||
def create_test_file
|
||||
return unless test_framework
|
||||
|
||||
if defined?(RSpec)
|
||||
create_worker_spec
|
||||
else
|
||||
|
@ -42,6 +44,14 @@ module Sidekiq
|
|||
)
|
||||
template "worker_test.rb.erb", template_file
|
||||
end
|
||||
|
||||
def file_name
|
||||
@_file_name ||= super.sub(/_?worker\z/i, "")
|
||||
end
|
||||
|
||||
def test_framework
|
||||
::Rails.application.config.generators.options[:rails][:test_framework]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
41
test/test_worker_generator.rb
Normal file
41
test/test_worker_generator.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
require_relative 'helper'
|
||||
require_relative 'dummy/config/environment'
|
||||
require 'rails/generators/test_case'
|
||||
require 'generators/sidekiq/worker_generator'
|
||||
|
||||
class WorkerGeneratorTest < Rails::Generators::TestCase
|
||||
tests Sidekiq::Generators::WorkerGenerator
|
||||
destination File.expand_path('../../tmp', __FILE__)
|
||||
setup :prepare_destination
|
||||
|
||||
test 'all files are properly created' do
|
||||
run_generator ['foo']
|
||||
assert_file 'app/workers/foo_worker.rb'
|
||||
assert_file 'test/workers/foo_worker_test.rb'
|
||||
end
|
||||
|
||||
test 'gracefully handles extra worker suffix' do
|
||||
run_generator ['foo_worker']
|
||||
assert_no_file 'app/workers/foo_worker_worker.rb'
|
||||
assert_no_file 'test/workers/foo_worker_worker_test.rb'
|
||||
|
||||
assert_file 'app/workers/foo_worker.rb'
|
||||
assert_file 'test/workers/foo_worker_test.rb'
|
||||
end
|
||||
|
||||
test 'respects rails config test_framework option' do
|
||||
Rails.application.config.generators do |g|
|
||||
g.test_framework false
|
||||
end
|
||||
|
||||
run_generator ['foo']
|
||||
|
||||
assert_file 'app/workers/foo_worker.rb'
|
||||
assert_no_file 'test/workers/foo_worker_test.rb'
|
||||
ensure
|
||||
Rails.application.config.generators do |g|
|
||||
g.test_framework :test_case
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue