merb_resque_mailer 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,6 +24,8 @@ Jobs are added to "mailer" queue so you should start at least one worker listeni
24
24
 
25
25
  QUEUE=mailer rake merb_env resque:work
26
26
 
27
+ Be sure you have 'resque/tasks' required in your Rakefile (or somewhere in lib/tasks/), it's required for above task to work.
28
+
27
29
  From now on all emails will be sent asynchronously using Resque worker(s).
28
30
 
29
31
  Installation
@@ -33,7 +35,7 @@ Gem is hosted on gemcutter.org, simply install it by:
33
35
 
34
36
  gem install merb_resque_mailer
35
37
 
36
- and require it in your app (or just add it bundler's Gemfile).
38
+ and require it in your app (or just add it to bundler's Gemfile).
37
39
 
38
40
  Configuration
39
41
  -------------
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ ::Resque::Mailer.excluded_environments = []
4
+
5
+ class TestMailer < Merb::MailController
6
+ include Resque::Mailer
7
+
8
+ ACTION_PARAMS = {}
9
+ MAILER_PARAMS = { :from => "jola@example.org", :to => "misio@example.org", :subject => "Friendship established" }
10
+
11
+ def friendship_confirmation
12
+ render_mail :text => "Mail content"
13
+ end
14
+ end
15
+
16
+ delivery = lambda do
17
+ TestMailer.new(TestMailer::ACTION_PARAMS).dispatch_and_deliver(:friendship_confirmation, TestMailer::MAILER_PARAMS)
18
+ end
19
+
20
+ describe TestMailer do
21
+ describe '#dispatch_and_deliver' do
22
+ before(:each) do
23
+ Resque.stub(:enqueue)
24
+ end
25
+
26
+ it 'should not deliver the email synchronously' do
27
+ lambda { delivery.call }.should_not change(Merb::Mailer.deliveries, :count)
28
+ end
29
+
30
+ it 'should place the deliver action on the Resque "mailer" queue' do
31
+ Resque.should_receive(:enqueue).with(TestMailer, TestMailer::ACTION_PARAMS, :friendship_confirmation, TestMailer::MAILER_PARAMS)
32
+ delivery.call
33
+ end
34
+
35
+ it 'should not deliver through Resque for excluded environments' do
36
+ excluded_envs = [:test, :staging]
37
+ ::Resque::Mailer.excluded_environments = excluded_envs
38
+
39
+ excluded_envs.each do |env|
40
+ Merb.should_receive(:env).and_return(env)
41
+ Resque.should_not_receive(:enqueue)
42
+ delivery.call
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#dispatch_and_deliver!' do
48
+ it 'should deliver the mail' do
49
+ lambda { delivery.call }.should change(Merb::Mailer.deliveries, :count).by(1)
50
+ end
51
+ end
52
+
53
+ it 'should should have queue name' do
54
+ TestMailer.should respond_to(:queue)
55
+ end
56
+
57
+ describe ".perform" do
58
+ it 'should perform a queued mailer job' do
59
+ lambda do
60
+ TestMailer.perform(TestMailer::ACTION_PARAMS, :friendship_confirmation, TestMailer::MAILER_PARAMS)
61
+ end.should change(Merb::Mailer.deliveries, :count).by(1)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+
6
+ require 'merb-core'
7
+ require 'merb-mailer'
8
+
9
+ Merb::Config.use do |c|
10
+ c[:session_store] = :memory
11
+ end
12
+
13
+ # Merb.start :environment => 'test'
14
+ Merb.start_environment(:testing => true, :adapter => 'runner', :environment => 'test')
15
+ Merb::Mailer.delivery_method = :test_send
16
+
17
+ require 'merb_resque_mailer'
18
+
19
+ Spec::Runner.configure do |config|
20
+ config.include Merb::Test::RequestHelper
21
+ config.include Merb::Test::ControllerHelper
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_resque_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Kulik
@@ -33,6 +33,8 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - lib/merb_resque_mailer.rb
35
35
  - README.md
36
+ - spec/spec_helper.rb
37
+ - spec/merb_resque_mailer_spec.rb
36
38
  has_rdoc: true
37
39
  homepage: http://sickill.net
38
40
  licenses: []