diff --git a/.travis.yml b/.travis.yml index a4012dd..bb0155a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,38 @@ language: ruby + rvm: - - 2.2.5 - - 2.3.1 - - 2.4.1 + - 2.2.10 + - 2.5.9 + - 2.7.4 + - 3.0.0 + +env: + - RAILS_VERSION=4.2 + - RAILS_VERSION=5.2 + - RAILS_VERSION=6.0 + - RAILS_VERSION=6.1 + +jobs: + exclude: + - rvm: 2.2.10 + env: RAILS_VERSION=5.2 + - rvm: 2.2.10 + env: RAILS_VERSION=6.0 + - rvm: 2.2.10 + env: RAILS_VERSION=6.1 + + - rvm: 2.5.9 + env: RAILS_VERSION=4.2 + + - rvm: 2.7.4 + env: RAILS_VERSION=4.2 + + - rvm: 3.0.0 + env: RAILS_VERSION=4.2 + - rvm: 3.0.0 + env: RAILS_VERSION=5.2 + - rvm: 3.0.0 + env: RAILS_VERSION=6.0 before_install: - gem install bundler -v 1.15 diff --git a/Gemfile b/Gemfile index 5018971..fa1af8d 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,17 @@ source 'https://rubygems.org' # Specify your gem's dependencies in devise-async.gemspec gemspec + +version = ENV['RAILS_VERSION'] || "~> 6.1" + +gem "activerecord", version +gem "actionpack", version +gem "actionmailer", version + +if version =~ /^4/ + gem 'sqlite3', '~> 1.3.6' +elsif version =~ /^5.2/ + gem 'sqlite3', '~> 1.3.6' +else + gem 'sqlite3', '~> 1.4' +end diff --git a/README.md b/README.md index 5c4d77c..7528adb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Devise Async -[![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) +[![Build Status](https://app.travis-ci.com/joe1chen/devise-async.svg?branch=master)](https://app.travis-ci.com/github/joe1chen/devise-async) Devise Async provides an easy way to configure Devise to send its emails asynchronously using ActiveJob. diff --git a/devise-async.gemspec b/devise-async.gemspec index d36d7f9..e8a551e 100644 --- a/devise-async.gemspec +++ b/devise-async.gemspec @@ -19,13 +19,10 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'devise', '>= 4.0' - gem.add_runtime_dependency 'activejob', '>= 5.0' + gem.add_runtime_dependency 'activejob', '>= 4.2' - gem.add_development_dependency 'activerecord', '>= 5.0' - gem.add_development_dependency 'actionpack', '>= 5.0' - gem.add_development_dependency 'actionmailer', '>= 5.0' gem.add_development_dependency 'rspec', '~> 3.6' gem.add_development_dependency 'rspec-rails', '~> 3.6' - gem.add_development_dependency 'sqlite3', '~> 1.3' + gem.add_development_dependency 'sqlite3' gem.add_development_dependency 'pry' end diff --git a/lib/devise/async.rb b/lib/devise/async.rb index 55dc51a..b268aa5 100644 --- a/lib/devise/async.rb +++ b/lib/devise/async.rb @@ -8,6 +8,10 @@ module Async mattr_accessor :enabled @@enabled = true + # Defines the queue in which the background job will be enqueued. + mattr_accessor :queue + @@queue = nil + # Allow configuring Devise::Async with a block # # Example: diff --git a/lib/devise/async/model.rb b/lib/devise/async/model.rb index 0d7c208..6c6038d 100644 --- a/lib/devise/async/model.rb +++ b/lib/devise/async/model.rb @@ -1,3 +1,5 @@ +require 'action_mailer' + module Devise module Models module Async @@ -50,7 +52,12 @@ def devise_pending_notifications private def deliver_mail_later(notification, model, args) - devise_mailer.send(notification, model, *args).deliver_later + if ActionMailer::Base.method_defined?(:deliver_later_queue_name) + # Rails 5 introduced the option of setting the mailer queue name. + devise_mailer.send(notification, model, *args).deliver_later(queue: Devise::Async.queue || ActionMailer::Base.deliver_later_queue_name) + else + devise_mailer.send(notification, model, *args).deliver_later + end end end end diff --git a/spec/devise/async_spec.rb b/spec/devise/async_spec.rb index 54d89e8..cdc0cfc 100644 --- a/spec/devise/async_spec.rb +++ b/spec/devise/async_spec.rb @@ -10,4 +10,12 @@ expect(described_class.enabled).to eq(false) described_class.enabled = initial_enabled end + + it 'stores queue config' do + initial_queue = described_class.queue + + described_class.queue = :critical + expect(described_class.queue).to eq(:critical) + described_class.queue = initial_queue + end end