dj_mailer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ branches:
5
+ only:
6
+ - master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in delayed-mailer.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,25 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
19
+
20
+
21
+ guard 'cucumber' do
22
+ watch(%r{^features/.+\.feature$})
23
+ watch(%r{^features/support/.+$}) { 'features' }
24
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
25
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 andrea longhi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # DjMailer
2
+
3
+ [![Build Status](https://secure.travis-ci.org/spaghetticode/dj_mailer.png)](http://travis-ci.org/spaghetticode/dj_mailer)
4
+
5
+ This gem allows you to send emails asyncronously via delayed_job_active_record
6
+ without modifying the existing codebase, keeping the standard action mailer
7
+ interface.
8
+
9
+ Currenlty delayed_job_active_record requires that you replace all your email
10
+ deliver calls as follows:
11
+
12
+ ```ruby
13
+ # without delayed job
14
+ Notifier.signup(@user).deliver
15
+
16
+ # with delayed job
17
+ Notifier.delay.signup(@user)
18
+ ```
19
+
20
+ By adding this gem in your gemfile all your current emails will be automatically
21
+ handled by delayed job without any interface change. At the moment you have
22
+ to setup the delayed job environment (running the migrations for the db) on your
23
+ own.
24
+
25
+
26
+ ## Note
27
+
28
+ I could not make the current version of delayed_job_active_record (0.3.2) work
29
+ with recent versions of ActionMailer, it does with 3.0.5. I will investigate
30
+ the reason of the failure ASAP.
31
+
32
+
33
+ ## Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+ ```ruby
37
+ gem 'dj_mailer'
38
+ ```
39
+ And then execute: `$ bundle`
40
+
41
+ Or install it yourself as:
42
+ ```
43
+ $ gem install dj_mailer
44
+ ```
45
+
46
+
47
+ ## Sample delay job migration
48
+
49
+ Just a reminder I have to add the generator (via rails you can simply run `rails generate delayed_job:active_record)`
50
+
51
+ ```ruby
52
+ class CreateDelayedJobs < ActiveRecord::Migration
53
+ def self.up
54
+ create_table :delayed_jobs, :force => true do |table|
55
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
56
+ table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
57
+ table.text :handler # YAML-encoded string of the object that will do work
58
+ table.text :last_error # reason for last failure (See Note below)
59
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
60
+ table.datetime :locked_at # Set when a client is working on this object
61
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
62
+ table.string :locked_by # Who is working on this object (if locked)
63
+ table.string :queue # The name of the queue this job is in
64
+ table.timestamps
65
+ end
66
+
67
+ add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
68
+ end
69
+
70
+ def self.down
71
+ drop_table :delayed_jobs
72
+ end
73
+ end
74
+ ```
75
+
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Add your feature tests to the rspec/cucumber test suite
82
+ 4. Commit your changes (`git commit -am 'Added some feature'`)
83
+ 5. Push to the branch (`git push origin my-new-feature`)
84
+ 6. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ desc 'Run those specs'
9
+ task :spec do
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ t.rspec_path = 'bundle exec rspec'
13
+ end
14
+ end
15
+
16
+ desc 'Run cucumber features'
17
+ task :cucumber do
18
+ require 'cucumber/rake/task'
19
+
20
+ Cucumber::Rake::Task.new do |t|
21
+ t.rcov = false
22
+ end
23
+ end
24
+
25
+ desc 'Runs tests on Travis CI'
26
+ task :travis do
27
+ ["rspec spec", "rake cucumber"].each do |cmd|
28
+ puts "Starting to run #{cmd}..."
29
+ system("export DISPLAY=:99.0 && bundle exec #{cmd}")
30
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
31
+ end
32
+ end
33
+
34
+ if ENV['TRAVIS']
35
+ task :default => :travis
36
+ else
37
+ task :default => :spec
38
+ end
data/dj_mailer.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dj_mailer/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["andrea longhi"]
6
+ gem.email = ["andrea@spaghetticode.it"]
7
+ gem.description = %q{send automatically all emails via delayed_job}
8
+ gem.summary = %q{Allows to send all ActionMailer 3 emails via delayed_job in a transparent way}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'dj_mailer'
15
+ gem.require_paths = ['lib']
16
+ gem.version = DjMailer::VERSION
17
+
18
+ gem.add_dependency 'delayed_job_active_record'
19
+ gem.add_dependency 'actionmailer', '3.0.5'
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'sqlite3'
23
+ gem.add_development_dependency 'cucumber'
24
+ gem.add_development_dependency 'guard-rspec'
25
+ gem.add_development_dependency 'guard-cucumber'
26
+ gem.add_development_dependency 'activerecord', '3.0.5'
27
+ end
@@ -0,0 +1,29 @@
1
+ Feature: deliver email asyncronously with delayed_job in a transparent way
2
+ In order to add asyncronous email delivery without modifing the existing codebase
3
+ As an action mailer 3 and delayed_job user
4
+ I want to deliver email asyncronously without modifying existing code
5
+
6
+ This is the current delayed job recommended syntax to run asyncronous
7
+ email delivers:
8
+ without delayed_job: Notifier.signup(@user).deliver
9
+ with delayed_job: Notifier.delay.signup(@user)
10
+ The syntax is quite different, so if you have a big codebase that doesn't use
11
+ yet delayed job it could become rather nasty to replace all the deliver calls.
12
+ This gem allows you to keep the old interface and still get the delayed job
13
+ asyncronous functionality.
14
+
15
+ Scenario: Email is enqueued successfully
16
+ Given I have the following action mailer class:
17
+ """
18
+ class TestMailer < ActionMailer::Base
19
+ def test(recipient)
20
+ mail to: recipient, from: 'test@test.com', subject: 'asyncronous email'
21
+ end
22
+ end
23
+ """
24
+ When I try to send a test email with the following code:
25
+ """
26
+ TestMailer.test('sender@test.com')
27
+ """
28
+ Then a delayed job object should be returned
29
+ And I should see a new delayed_job record in the table
File without changes
@@ -0,0 +1,15 @@
1
+ Given /^I have the following action mailer class:$/ do |class_definition|
2
+ context_module.class_eval(class_definition)
3
+ end
4
+
5
+ When /^I try to send a test email with the following code:$/ do |code|
6
+ self.result = context_module.class_eval(code)
7
+ end
8
+
9
+ Then /^a delayed job object should be returned$/ do
10
+ result.should be_a(Delayed::Backend::ActiveRecord::Job)
11
+ end
12
+
13
+ Then /^I should see a new delayed_job record in the table$/ do
14
+ Delayed::Job.count.should == 1
15
+ end
File without changes
@@ -0,0 +1,42 @@
1
+ # At the moment delayed_job_active_record is quite broken. It surely works
2
+ # fine with actionmailer 3.0.5
3
+ gem 'actionmailer', '3.0.5'
4
+ require 'action_mailer'
5
+
6
+ ActionMailer::Base.delivery_method = :test
7
+
8
+
9
+ # Forcing actionmailer to v3.0.5 requires also activerecord to have same version,
10
+ # this is to avoid dependencies conflicts (activesupport version, for example)
11
+ gem 'activerecord', '3.0.5'
12
+ require 'delayed_job_active_record'
13
+
14
+ class DjMigration < ActiveRecord::Migration
15
+ def self.up
16
+ create_table :delayed_jobs, :force => true do |table|
17
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
18
+ table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
19
+ table.text :handler # YAML-encoded string of the object that will do work
20
+ table.text :last_error # reason for last failure (See Note below)
21
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
22
+ table.datetime :locked_at # Set when a client is working on this object
23
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
24
+ table.string :locked_by # Who is working on this object (if locked)
25
+ table.string :queue # The name of the queue this job is in
26
+ table.timestamps
27
+ end
28
+
29
+ add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
30
+ end
31
+
32
+ def self.down
33
+ drop_table :delayed_jobs
34
+ end
35
+ end
36
+
37
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
38
+ ActiveRecord::Base.logger = Logger.new(StringIO.new)
39
+ DjMigration.up
40
+
41
+
42
+ require File.expand_path('../../../lib/dj_mailer', __FILE__)
@@ -0,0 +1,9 @@
1
+ module WorldExtensions
2
+ attr_accessor :result
3
+
4
+ def context_module
5
+ @context_module ||= Module.new
6
+ end
7
+ end
8
+
9
+ World(WorldExtensions)
data/lib/dj_mailer.rb ADDED
@@ -0,0 +1,28 @@
1
+ # cucumber complains with require 'dj_mailer/version'
2
+ require File.expand_path('../dj_mailer/version', __FILE__)
3
+
4
+ module DjMailer
5
+ module Delayable
6
+ module Deliverable
7
+ def deliver; self; end
8
+ end
9
+
10
+ def self.extended(base)
11
+ class << base
12
+ alias_method_chain :method_missing, :delay
13
+ end
14
+ end
15
+
16
+ def method_missing_with_delay(method, *args)
17
+ if caller[1].include?('performable_mailer.rb')
18
+ method_missing_without_delay(method, *args)
19
+ else
20
+ delay.send(method, *args).tap do |dj_instance|
21
+ dj_instance.extend Deliverable
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ ActionMailer::Base.extend DjMailer::Delayable
@@ -0,0 +1,3 @@
1
+ module DjMailer
2
+ VERSION = "0.0.1"
3
+ end
data/spec/lib/.gitkeep ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ require File.expand_path('../../lib/dj_mailer', __FILE__)
2
+
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dj_mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - andrea longhi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: delayed_job_active_record
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: actionmailer
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: cucumber
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-cucumber
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: activerecord
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - '='
148
+ - !ruby/object:Gem::Version
149
+ version: 3.0.5
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - '='
156
+ - !ruby/object:Gem::Version
157
+ version: 3.0.5
158
+ description: send automatically all emails via delayed_job
159
+ email:
160
+ - andrea@spaghetticode.it
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - .gitignore
166
+ - .rspec
167
+ - .travis.yml
168
+ - Gemfile
169
+ - Guardfile
170
+ - LICENSE
171
+ - README.md
172
+ - Rakefile
173
+ - dj_mailer.gemspec
174
+ - features/dj_mailer_deliver.feature
175
+ - features/step_definitions/.gitkeep
176
+ - features/step_definitions/dj_mailer_deliver_steps.rb
177
+ - features/support/.gitkeep
178
+ - features/support/env.rb
179
+ - features/support/world_extensions.rb
180
+ - lib/dj_mailer.rb
181
+ - lib/dj_mailer/version.rb
182
+ - spec/lib/.gitkeep
183
+ - spec/spec_helper.rb
184
+ homepage: ''
185
+ licenses: []
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 1.8.24
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: Allows to send all ActionMailer 3 emails via delayed_job in a transparent
208
+ way
209
+ test_files:
210
+ - features/dj_mailer_deliver.feature
211
+ - features/step_definitions/.gitkeep
212
+ - features/step_definitions/dj_mailer_deliver_steps.rb
213
+ - features/support/.gitkeep
214
+ - features/support/env.rb
215
+ - features/support/world_extensions.rb
216
+ - spec/lib/.gitkeep
217
+ - spec/spec_helper.rb