diff --git a/CHANGELOG.md b/CHANGELOG.md index ab27543..0cfd899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0 + +* Updates the readme + ## 1.0.0beta * Adds support for Rails 5 diff --git a/README.md b/README.md index a311ce7..5c4d77c 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,7 @@ [![Tag](https://img.shields.io/github/tag/mhfs/devise-async.svg?style=flat-square)](https://github.com/mhfs/devise-async/releases) [![Build Status](https://img.shields.io/travis/mhfs/devise-async.svg?style=flat-square)](https://travis-ci.org/mhfs/devise-async) [![Code Climate](https://img.shields.io/codeclimate/github/mhfs/devise-async.svg?style=flat-square)](https://codeclimate.com/github/mhfs/devise-async) -Devise Async provides an easy way to configure Devise to send its emails asynchronously using your preferred queuing backend. - -Supported backends: - -* Resque -* Sidekiq -* Delayed::Job -* QueueClassic -* Torquebox -* Backburner -* Que -* SuckerPunch +Devise Async provides an easy way to configure Devise to send its emails asynchronously using ActiveJob. ## Installation @@ -33,7 +22,8 @@ Or install it yourself as: ## Usage -Add `:async` to the `devise` call in your model: +1. Setup [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html), +2. Add `:async` to the `devise` call in your model: ```ruby class User < ActiveRecord::Base @@ -41,16 +31,7 @@ class User < ActiveRecord::Base end ``` -Set your queuing backend by creating `config/initializers/devise_async.rb`: - -```ruby -# Supported options: :resque, :sidekiq, :delayed_job, :queue_classic, :torquebox, :backburner, :que, :sucker_punch -Devise::Async.backend = :resque -``` - -Tip: it defaults to Resque. You don't need to create the initializer if using it. - -## Advanced Options +## Options ### Enabling via config @@ -61,33 +42,6 @@ The gem can be enabled/disabled easily via config, for example based on environm Devise::Async.enabled = true # | false ``` -### Custom mailer class - -Customize `Devise.mailer` at will and `devise-async` will honor it. - -Upgrade note: if you're upgrading from any version < 0.6 and getting errors -trying to set `Devise::Async.mailer` just use `Devise.mailer` instead. - -### Custom queue - -Let you specify a custom queue where to enqueue your background Devise jobs. -Defaults to :mailer. - -```ruby -# config/initializers/devise_async.rb -Devise::Async.queue = :my_custom_queue -``` - -### Custom priority - -You can specify a custom priority for created background jobs in Devise or Backburner. -If no value is specified, jobs will be enqueued with whatever default priority is configured in Devise or Backburner. - -```ruby -# config/initializers/devise_async.rb -Devise::Async.priority = 10 -``` - ### Setup via block To avoid repeating `Devise::Async` in the initializer file you can use the block syntax @@ -97,40 +51,22 @@ similar to what `Devise` offers. # config/initializers/devise_async.rb Devise::Async.setup do |config| config.enabled = true - config.backend = :resque - config.queue = :my_custom_queue -end -``` - -## Troubleshooting - -If you are using Sidekiq and your jobs are enqueued but not processed you might need to set a queue explicitly: - -```ruby -# config/initializers/devise_async.rb -Devise::Async.setup do |config| - config.backend = :sidekiq - config.queue = :default end ``` -## Testing - -Be aware that since version 0.3.0 devise-async enqueues the background job in active -record's `after_commit` hook. If you're using rspec's `use_transactional_fixtures` the jobs -might not be enqueued as you'd expect. +### Custom mailer class -More details in this stackoverflow [thread](http://stackoverflow.com/questions/13406248/how-do-i-get-devise-async-working-with-cucumber/13465089#13465089). +Customize `Devise.mailer` at will and `devise-async` will honor it. -## Devise < 2.2 +## Older versions of Rails and devise -Older versions of Devise are supported in the [devise_2_1](https://github.com/mhfs/devise-async/tree/devise_2_1) branch and in the 0.5 series of devise-async. +If you want to use this gem with Rails < 5 and/or devise < 4 check out older releases, please. -Please refer to that branch README for further info. +## Testing -## Devise >= 4.0 +RSpec is used for testing. The following should be enough for running the test: -The current state of this gem does not support Devise 4.0 and up. Have a look into [the Github issue](https://github.com/mhfs/devise-async/issues/94) addressing this. If you are in need for a solution to send Devise messages delayed [a switch to ActiveJob](https://github.com/plataformatec/devise#activejob-integration) is strongly advised. + $ bundle exec rspec ## Contributing diff --git a/Rakefile b/Rakefile index bdb8a08..05a927f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,3 @@ #!/usr/bin/env rake require "bundler/gem_tasks" -require "rake/testtask" - -task :default => :test - -Rake::TestTask.new do |t| - t.libs << "lib" - t.libs << "test" - t.test_files = FileList["test/**/*_test.rb"] - t.verbose = true - t.warning = false -end diff --git a/lib/devise/async/version.rb b/lib/devise/async/version.rb index 2222f84..766a20b 100644 --- a/lib/devise/async/version.rb +++ b/lib/devise/async/version.rb @@ -1,5 +1,5 @@ module Devise module Async - VERSION = '1.0.0beta' + VERSION = '1.0.0' end end diff --git a/spec/devise/async/model_spec.rb b/spec/devise/async/model_spec.rb index 3405788..dfc32c1 100644 --- a/spec/devise/async/model_spec.rb +++ b/spec/devise/async/model_spec.rb @@ -1,14 +1,12 @@ RSpec.describe Devise::Models::Async do - before :each do + before do ActiveJob::Base.queue_adapter = :test end context 'with unchanged model' do - subject { create_admin } + subject { admin } - before :each do - subject - end + let!(:admin) { create_admin } it 'enqueues notifications immediately when the model did not change' do expect(ActionMailer::DeliveryJob).to have_been_enqueued @@ -47,7 +45,7 @@ end context 'with saving the model' do - let(:save_admin) { admin.save } + let(:saved_admin) { admin.save } it 'accumulates a pending notification to be sent after commit' do expect(subject).to eq([ @@ -59,13 +57,13 @@ subject expect { - save_admin + saved_admin }.to have_enqueued_job(ActionMailer::DeliveryJob) end it 'forwards the correct data to the job' do subject - save_admin + saved_admin job_data = ActiveJob::Base.queue_adapter.enqueued_jobs.first[:args] expected_job_data = ['Devise::Mailer', 'confirmation_instructions', admin.send(:confirmation_token)] @@ -76,7 +74,7 @@ end context 'when devise async is disabled' do - around :each do |example| + around do |example| Devise::Async.enabled = false example.run Devise::Async.enabled = true diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 30f19a1..6dd9593 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -18,6 +18,6 @@ config.include TestHelpers config.before :each do - load File.dirname(__FILE__) + '/support/rails_app/db/schema.rb' + load "#{File.dirname(__FILE__)}/support/rails_app/db/schema.rb" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5a5cc48..5167a5d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,7 @@ config.filter_run_when_matching :focus config.example_status_persistence_file_path = "spec/examples.txt" config.disable_monkey_patching! - config.warnings = true + config.warnings = false config.order = :random if config.files_to_run.one?