dj_mailer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,15 +19,8 @@ deliver calls as follows:
19
19
 
20
20
  By adding this gem in your gemfile all your current emails will be automatically
21
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.
22
+ to setup the delayed job environment on your own running the migrations for the
23
+ db.
31
24
 
32
25
 
33
26
  ## Installation
@@ -36,11 +29,23 @@ Add this line to your application's Gemfile:
36
29
  ```ruby
37
30
  gem 'dj_mailer'
38
31
  ```
39
- And then execute: `$ bundle`
32
+ And then execute: `bundle`
40
33
 
41
34
  Or install it yourself as:
35
+ ```bash
36
+ gem install dj_mailer
37
+ ```
38
+
39
+
40
+ ## Tests
41
+
42
+ to run the specs:
43
+ ```bash
44
+ bundle exec rake spec
42
45
  ```
43
- $ gem install dj_mailer
46
+ to run the cucumber features:
47
+ ```bash
48
+ bundle exec rake cucumber
44
49
  ```
45
50
 
46
51
 
data/dj_mailer.gemspec CHANGED
@@ -15,13 +15,14 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ['lib']
16
16
  gem.version = DjMailer::VERSION
17
17
 
18
+ gem.add_dependency 'actionmailer'
18
19
  gem.add_dependency 'delayed_job_active_record'
19
- gem.add_dependency 'actionmailer', '3.0.5'
20
+
20
21
  gem.add_development_dependency 'rake'
21
22
  gem.add_development_dependency 'rspec'
22
23
  gem.add_development_dependency 'sqlite3'
23
24
  gem.add_development_dependency 'cucumber'
24
25
  gem.add_development_dependency 'guard-rspec'
26
+ gem.add_development_dependency 'activerecord'
25
27
  gem.add_development_dependency 'guard-cucumber'
26
- gem.add_development_dependency 'activerecord', '3.0.5'
27
28
  end
@@ -27,3 +27,4 @@ Scenario: Email is enqueued successfully
27
27
  """
28
28
  Then a delayed job object should be returned
29
29
  And I should see a new delayed_job record in the table
30
+ And the email queue should be empty
@@ -13,3 +13,7 @@ end
13
13
  Then /^I should see a new delayed_job record in the table$/ do
14
14
  Delayed::Job.count.should == 1
15
15
  end
16
+
17
+ Then /^the email queue should be empty$/ do
18
+ ActionMailer::Base.deliveries.should be_empty
19
+ end
@@ -1,6 +1,5 @@
1
1
  # At the moment delayed_job_active_record is quite broken. It surely works
2
2
  # fine with actionmailer 3.0.5
3
- gem 'actionmailer', '3.0.5'
4
3
  require 'action_mailer'
5
4
 
6
5
  ActionMailer::Base.delivery_method = :test
@@ -8,7 +7,6 @@ ActionMailer::Base.delivery_method = :test
8
7
 
9
8
  # Forcing actionmailer to v3.0.5 requires also activerecord to have same version,
10
9
  # this is to avoid dependencies conflicts (activesupport version, for example)
11
- gem 'activerecord', '3.0.5'
12
10
  require 'delayed_job_active_record'
13
11
 
14
12
  class DjMigration < ActiveRecord::Migration
@@ -0,0 +1,3 @@
1
+ Before do
2
+ ActionMailer::Base.deliveries.clear
3
+ end
data/lib/dj_mailer.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'action_mailer'
1
2
  # cucumber complains with require 'dj_mailer/version'
2
3
  require File.expand_path('../dj_mailer/version', __FILE__)
3
4
 
@@ -14,12 +15,16 @@ module DjMailer
14
15
  end
15
16
 
16
17
  def method_missing_with_delay(method, *args)
17
- if caller[1].include?('performable_mailer.rb')
18
- method_missing_without_delay(method, *args)
18
+ if respond_to?(method) and !caller.grep('delayed_job').present?
19
+ enqueue_with_delayed_job(method, *args)
19
20
  else
20
- delay.send(method, *args).tap do |dj_instance|
21
- dj_instance.extend Deliverable
22
- end
21
+ method_missing_without_delay(method, *args)
22
+ end
23
+ end
24
+
25
+ def enqueue_with_delayed_job(method, *args)
26
+ delay.send(method, *args).tap do |dj_instance|
27
+ dj_instance.extend Deliverable
23
28
  end
24
29
  end
25
30
  end
@@ -1,3 +1,3 @@
1
1
  module DjMailer
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module DjMailer
4
+ describe Delayable do
5
+ describe 'the extended class' do
6
+ subject {Class.new {extend Delayable}}
7
+
8
+ it 'responds to method_missing_with_delay' do
9
+ subject.should respond_to(:method_missing_with_delay)
10
+ end
11
+
12
+ describe 'method_missing_with_delay' do
13
+ context 'when the class does not respond to the method' do
14
+ it 'delegates to the original method_missing' do
15
+ subject.should_receive(:method_missing_without_delay)
16
+ subject.method_missing_with_delay(:not_responding)
17
+ end
18
+ end
19
+
20
+ context 'when the class respond to the method' do
21
+ before {subject.should_receive(:respond_to?).and_return(true)}
22
+
23
+ context 'when the caller is delayed_job' do
24
+ it 'should delegate to the original method_missing' do
25
+ subject.stub(:caller => ['delayed_job'])
26
+ subject.should_receive(:method_missing_without_delay)
27
+ subject.method_missing_with_delay(:responding)
28
+ end
29
+ end
30
+
31
+ context 'when the caller is not delayed_job' do
32
+ it 'should equeue the email for late delivery' do
33
+ subject.stub(:caller => [])
34
+ subject.should_receive(:enqueue_with_delayed_job)
35
+ subject.method_missing_with_delay(:responding)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dj_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ cert_chain: []
12
12
  date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: delayed_job_active_record
15
+ name: actionmailer
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -28,21 +28,21 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: actionmailer
31
+ name: delayed_job_active_record
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 3.0.5
37
+ version: '0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - '='
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 3.0.5
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,7 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: guard-cucumber
127
+ name: activerecord
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -140,21 +140,21 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: activerecord
143
+ name: guard-cucumber
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
147
- - - '='
147
+ - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
- version: 3.0.5
149
+ version: '0'
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
155
- - - '='
155
+ - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
- version: 3.0.5
157
+ version: '0'
158
158
  description: send automatically all emails via delayed_job
159
159
  email:
160
160
  - andrea@spaghetticode.it
@@ -176,10 +176,12 @@ files:
176
176
  - features/step_definitions/dj_mailer_deliver_steps.rb
177
177
  - features/support/.gitkeep
178
178
  - features/support/env.rb
179
+ - features/support/hooks.rb
179
180
  - features/support/world_extensions.rb
180
181
  - lib/dj_mailer.rb
181
182
  - lib/dj_mailer/version.rb
182
183
  - spec/lib/.gitkeep
184
+ - spec/lib/deliverable_spec.rb
183
185
  - spec/spec_helper.rb
184
186
  homepage: ''
185
187
  licenses: []
@@ -212,6 +214,8 @@ test_files:
212
214
  - features/step_definitions/dj_mailer_deliver_steps.rb
213
215
  - features/support/.gitkeep
214
216
  - features/support/env.rb
217
+ - features/support/hooks.rb
215
218
  - features/support/world_extensions.rb
216
219
  - spec/lib/.gitkeep
220
+ - spec/lib/deliverable_spec.rb
217
221
  - spec/spec_helper.rb