Skip to content

Commit

Permalink
Updates readme and does some cleanup for 1.0.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
baschtl committed Sep 20, 2017
1 parent c33583d commit 0f867c2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 98 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0

* Updates the readme

## 1.0.0beta

* Adds support for Rails 5
Expand Down
86 changes: 11 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,24 +22,16 @@ 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
devise :database_authenticatable, :async, :confirmable # etc ...
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

Expand All @@ -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
Expand All @@ -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

Expand Down
11 changes: 0 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/devise/async/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Devise
module Async
VERSION = '1.0.0beta'
VERSION = '1.0.0'
end
end
16 changes: 7 additions & 9 deletions spec/devise/async/model_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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([
Expand All @@ -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)]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 0f867c2

Please sign in to comment.