redis_cache_mailer_delivery 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README.md +8 -0
- data/lib/redis_cache_mailer_delivery/mail/cache_delivery.rb +3 -1
- data/lib/redis_cache_mailer_delivery/mail/sequel_marshallable_mail_message.rb +11 -0
- data/lib/redis_cache_mailer_delivery/version.rb +1 -1
- data/lib/redis_cache_mailer_delivery.rb +1 -0
- data/spec/redis_cache_mailer_delivery/mail/cache_delivery_spec.rb +18 -0
- data/spec/redis_cache_mailer_delivery/mail/sequel_marshallable_mail_message_spec.rb +38 -0
- metadata +8 -4
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -48,6 +48,14 @@ RedisCacheMailerDelivery::Deliveries.all
|
|
48
48
|
|
49
49
|
to access all the mails
|
50
50
|
|
51
|
+
## Sequel
|
52
|
+
|
53
|
+
If you use Sequel and you set a sequel record into the Mail::Message (```mail.record = record```), the chances are you will encounter an error where you cannot serialize the message since the record might be a singleton. The gem has a builtin fix for this by using marshallable! method provied by Sequel since 3.6.0
|
54
|
+
|
55
|
+
## Other unmarshallable objects
|
56
|
+
|
57
|
+
The code will find if the mail being passed in responds to ```marshallable``` method, if it does, the code will call ```marshallable``` method before send it to the redis store
|
58
|
+
|
51
59
|
## Contributing
|
52
60
|
|
53
61
|
1. Fork it
|
@@ -17,7 +17,9 @@ module Mail
|
|
17
17
|
# @api private
|
18
18
|
def deliver!(mail)
|
19
19
|
list = Redis::List.new settings[:redis_key_name], :marshal => true
|
20
|
-
|
20
|
+
mail = SequelMarshallableMailMessage.marshallable mail
|
21
|
+
object = mail.respond_to?(:marshallable) ? mail.marshallable : mail
|
22
|
+
list << object
|
21
23
|
end
|
22
24
|
|
23
25
|
end # CacheDelivery
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'action_mailer'
|
2
2
|
require 'redis_cache_mailer_delivery/version'
|
3
3
|
require 'redis_cache_mailer_delivery/mail/cache_delivery'
|
4
|
+
require 'redis_cache_mailer_delivery/mail/sequel_marshallable_mail_message'
|
4
5
|
require 'redis_cache_mailer_delivery/deliveries'
|
5
6
|
|
6
7
|
module RedisCacheMailerDelivery
|
@@ -13,6 +13,24 @@ module Mail
|
|
13
13
|
subject.deliver!(object)
|
14
14
|
Redis::List.new("a-name", :marshal => true).values[0].should eq(object)
|
15
15
|
end
|
16
|
+
|
17
|
+
it "tries to make it marshallable first by passing it through SequelMarshallableMailMessage" do
|
18
|
+
SequelMarshallableMailMessage.should_receive(:marshallable).with(object).and_return object
|
19
|
+
subject.deliver!(object)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when the object respond to marshallable" do
|
23
|
+
before(:each) do
|
24
|
+
def object.marshallable
|
25
|
+
Mail::Message.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "calls the method before send to redis" do
|
30
|
+
object.should_receive(:marshallable).and_return Mail::Message.new
|
31
|
+
subject.deliver!(object)
|
32
|
+
end
|
33
|
+
end
|
16
34
|
end
|
17
35
|
end
|
18
36
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mail::SequelMarshallableMailMessage do
|
4
|
+
let(:object) {Class.new.new}
|
5
|
+
describe "#marshallable" do
|
6
|
+
context "when the message responds to the record message" do
|
7
|
+
let(:record) {double :sequel_record, :marshallable! => nil}
|
8
|
+
before(:each) do
|
9
|
+
object.stub(:record).and_return record
|
10
|
+
end
|
11
|
+
|
12
|
+
it "calls the record's marshallable! method" do
|
13
|
+
record.should_receive(:marshallable!).and_return record
|
14
|
+
described_class.marshallable object
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the mail" do
|
18
|
+
described_class.marshallable(object).should eq(object)
|
19
|
+
end
|
20
|
+
|
21
|
+
context "and the record is nil" do
|
22
|
+
before(:each) do
|
23
|
+
object.stub(:record).and_return nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns itself" do
|
27
|
+
described_class.marshallable(object).should eq(object)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when the message does not respond to the record message" do
|
33
|
+
it "returns itself" do
|
34
|
+
described_class.marshallable(object).should eq(object)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_cache_mailer_delivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yi Wen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: redis
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- .rspec
|
144
144
|
- .rvmrc
|
145
145
|
- .travis.yml
|
146
|
+
- CHANGELOG
|
146
147
|
- Gemfile
|
147
148
|
- Guardfile
|
148
149
|
- LICENSE
|
@@ -151,11 +152,13 @@ files:
|
|
151
152
|
- lib/redis_cache_mailer_delivery.rb
|
152
153
|
- lib/redis_cache_mailer_delivery/deliveries.rb
|
153
154
|
- lib/redis_cache_mailer_delivery/mail/cache_delivery.rb
|
155
|
+
- lib/redis_cache_mailer_delivery/mail/sequel_marshallable_mail_message.rb
|
154
156
|
- lib/redis_cache_mailer_delivery/railtie.rb
|
155
157
|
- lib/redis_cache_mailer_delivery/version.rb
|
156
158
|
- redis_cache_mailer_delivery.gemspec
|
157
159
|
- spec/redis_cache_mailer_delivery/deliveries_spec.rb
|
158
160
|
- spec/redis_cache_mailer_delivery/mail/cache_delivery_spec.rb
|
161
|
+
- spec/redis_cache_mailer_delivery/mail/sequel_marshallable_mail_message_spec.rb
|
159
162
|
- spec/redis_cache_mailer_delivery_spec.rb
|
160
163
|
- spec/spec_helper.rb
|
161
164
|
- spec/support/faked_rails.rb
|
@@ -196,6 +199,7 @@ summary: Use Redis to store the Mail::Message when using in Rails
|
|
196
199
|
test_files:
|
197
200
|
- spec/redis_cache_mailer_delivery/deliveries_spec.rb
|
198
201
|
- spec/redis_cache_mailer_delivery/mail/cache_delivery_spec.rb
|
202
|
+
- spec/redis_cache_mailer_delivery/mail/sequel_marshallable_mail_message_spec.rb
|
199
203
|
- spec/redis_cache_mailer_delivery_spec.rb
|
200
204
|
- spec/spec_helper.rb
|
201
205
|
- spec/support/faked_rails.rb
|