action_mailer_cache_delivery 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,8 @@ module ActionMailerCacheDelivery
8
8
 
9
9
  def install
10
10
  default_path = 'cache/action_mailer_cache_deliveries.cache'
11
- ActionMailer::Base.add_delivery_method :cache, Mail::CacheDelivery,
12
- location: defined?(Rails) ? "#{Rails.root}/tmp/#{default_path}" : "#{Dir.tmpdir}/#{default_path}"
11
+ location = defined?(Rails) ? "#{Rails.root}/tmp/#{default_path}" : "#{Dir.tmpdir}/#{default_path}"
12
+ ActionMailer::Base.add_delivery_method :cache, Mail::CacheDelivery, location: location
13
13
  end
14
14
 
15
15
  end # << self
@@ -8,8 +8,12 @@ module ActionMailer
8
8
  # @return [Array] array of mails (each mail is an instance of Mail.)
9
9
  #
10
10
  def cached_deliveries
11
- File.open(cache_settings[:location], 'r') do |file|
12
- Marshal.load(file)
11
+ if File.exists?(cache_settings[:location])
12
+ File.open(cache_settings[:location], 'r') do |file|
13
+ Marshal.load(file)
14
+ end
15
+ else
16
+ []
13
17
  end
14
18
  end
15
19
 
@@ -21,8 +25,10 @@ module ActionMailer
21
25
  def clear_cache
22
26
  deliveries.clear
23
27
 
24
- File.open(cache_settings[:location], 'w') do |file|
25
- Marshal.dump(deliveries, file)
28
+ if File.exists?(cache_settings[:location])
29
+ File.open(cache_settings[:location], 'w') do |file|
30
+ Marshal.dump(deliveries, file)
31
+ end
26
32
  end
27
33
  end
28
34
 
@@ -21,7 +21,6 @@ module Mail
21
21
  def initialize(settings)
22
22
  @settings = settings
23
23
 
24
- # create the cache directory if it doesn't exist
25
24
  cache_dir = File.dirname(@settings[:location])
26
25
  FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
27
26
  end
@@ -1,3 +1,3 @@
1
1
  module ActionMailerCacheDelivery
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end # ActionMailerCacheDelivery
@@ -13,6 +13,11 @@ describe ActionMailerCacheDelivery do
13
13
  end
14
14
 
15
15
  describe 'clear_cache' do
16
+ it 'allows clearing cache before cache file is created' do
17
+ ActionMailer::Base.cache_settings[:location] = 'test_dir/test_dir/test.cache'
18
+ lambda { ActionMailer::Base.clear_cache }.should_not raise_error
19
+ end
20
+
16
21
  it 'should clear cache file' do
17
22
  mail.deliver
18
23
  ActionMailer::Base.clear_cache
@@ -33,6 +38,11 @@ describe ActionMailerCacheDelivery do
33
38
  ActionMailer::Base.clear_cache
34
39
  end
35
40
 
41
+ it 'returns empty array if cache has not been created yet' do
42
+ ActionMailer::Base.cache_settings[:location] = 'test_dir/test_dir/test.cache'
43
+ ActionMailer::Base.cached_deliveries.should == []
44
+ end
45
+
36
46
  it 'should return array' do
37
47
  mail.deliver
38
48
  ActionMailer::Base.cached_deliveries.should be_an(Array)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_mailer_cache_delivery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: -1272042940984442377
95
+ hash: 357817960204666014
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  segments:
103
103
  - 0
104
- hash: -1272042940984442377
104
+ hash: 357817960204666014
105
105
  requirements: []
106
106
  rubyforge_project:
107
107
  rubygems_version: 1.8.24