action_mailer_cache_delivery 0.3.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +1 -1
- data/action_mailer_cache_delivery.gemspec +15 -14
- data/lib/action_mailer_cache_delivery/action_mailer/base.rb +26 -9
- data/lib/action_mailer_cache_delivery/mail/cache_delivery.rb +17 -13
- data/lib/action_mailer_cache_delivery/version.rb +1 -1
- data/spec/action_mailer_cache_delivery_spec.rb +16 -13
- data/spec/cache_delivery_spec.rb +8 -6
- data/spec/spec_helper.rb +7 -0
- metadata +20 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b32f90df212b794281209543071116b5033563133727fed9136111757edee925
|
4
|
+
data.tar.gz: 4dd8d0a28b2d22fee4904d98826472fdaff49338e1e7522d9b8fb95431d7796a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c27d4453849af80f682435fddae8c738f844627da25bc46f38a55a397e42f163c40728fa138b32ca5f5e5408f7e467266483d070fdd4c1b8e38936acc6020c5e
|
7
|
+
data.tar.gz: 16c2c5ef19d1157290c3b314eded5f5ac4e99b34a4d69fcc2bfda1822e1ae611de8c293dfdd964f5e20c1a0d66007d2de321bcc828073dc2d479c4b9c0584609
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Alex Rodionov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Enhances ActionMailer to support the `:cache` delivery method, which behaves like `:test`, except that the deliveries are marshalled to a temporary cache file, thus making them available to other processes.
|
4
4
|
|
5
|
-
You'll want to use this gem if you're testing with Selenium (or any other tool which distinct processes).
|
5
|
+
You'll want to use this gem if you're testing with Selenium (or any other tool which distinct processes). Another approach would be to [share deliveries between threads](https://gist.github.com/p0deje/ffc833630ee70f2af5ff) (in this case, this gem is not needed at all).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -1,23 +1,24 @@
|
|
1
1
|
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
2
2
|
require 'action_mailer_cache_delivery/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'action_mailer_cache_delivery'
|
6
|
+
gem.homepage = 'https://github.com/p0deje/action_mailer_cache_delivery'
|
7
|
+
gem.version = ActionMailerCacheDelivery::VERSION
|
8
|
+
gem.license = 'MIT'
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
gem.authors = 'Alex Rodionov'
|
11
|
+
gem.email = 'p0deje@gmail.com'
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
gem.summary = 'Cache delivery method for ActionMailer'
|
14
|
+
gem.description = 'Cache delivery method for ActionMailer for testing emails with Selenium'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
19
|
|
19
|
-
|
20
|
+
gem.add_dependency 'actionmailer', '>= 3.0'
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
gem.add_development_dependency 'rspec' , '~> 2.8'
|
23
|
+
gem.add_development_dependency 'rake' , '~> 0.9'
|
23
24
|
end
|
@@ -8,12 +8,14 @@ module ActionMailer
|
|
8
8
|
# @return [Array] array of mails (each mail is an instance of Mail.)
|
9
9
|
#
|
10
10
|
def cached_deliveries
|
11
|
-
|
12
|
-
File.
|
13
|
-
|
11
|
+
with_cache_lock("#{cache_settings[:location]}.lock") do
|
12
|
+
if File.exist?(cache_settings[:location])
|
13
|
+
File.open(cache_settings[:location], 'r') do |file|
|
14
|
+
Marshal.load(file)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
[]
|
14
18
|
end
|
15
|
-
else
|
16
|
-
[]
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -23,15 +25,30 @@ module ActionMailer
|
|
23
25
|
# It also cleans ActionMailer::Base.deliveries
|
24
26
|
#
|
25
27
|
def clear_cache
|
26
|
-
|
28
|
+
with_cache_lock("#{cache_settings[:location]}.lock") do
|
29
|
+
deliveries.clear
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
if File.exist?(cache_settings[:location])
|
32
|
+
File.open(cache_settings[:location], 'w') do |file|
|
33
|
+
Marshal.dump(deliveries, file)
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
39
|
+
#
|
40
|
+
# Locks file to prevent concurrent mail jobs from race condition.
|
41
|
+
# @api private
|
42
|
+
#
|
43
|
+
def with_cache_lock(file)
|
44
|
+
lockfile = File.open(file, 'w')
|
45
|
+
lockfile.flock(File::LOCK_EX)
|
46
|
+
yield
|
47
|
+
ensure
|
48
|
+
lockfile.flock(File::LOCK_UN)
|
49
|
+
lockfile.close
|
50
|
+
end
|
51
|
+
|
35
52
|
end # << self
|
36
53
|
end # Base
|
37
54
|
end # ActionMailer
|
@@ -27,23 +27,27 @@ module Mail
|
|
27
27
|
|
28
28
|
# @api private
|
29
29
|
def deliver!(mail)
|
30
|
-
#
|
31
|
-
|
30
|
+
ActionMailer::Base.with_cache_lock("#{@settings[:location]}.lock") do
|
31
|
+
# write empty array to cache file if doesn't exist
|
32
|
+
unless File.exist?(@settings[:location])
|
33
|
+
File.open(@settings[:location], 'w') do |file|
|
34
|
+
Marshal.dump([], file)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# get delivered mails
|
39
|
+
mails = File.open(@settings[:location], 'r') do |file|
|
40
|
+
Marshal.load(file)
|
41
|
+
end
|
42
|
+
# append new one
|
43
|
+
mails << mail
|
44
|
+
# write all emails to cache file
|
32
45
|
File.open(@settings[:location], 'w') do |file|
|
33
|
-
Marshal.dump(
|
46
|
+
Marshal.dump(mails, file)
|
34
47
|
end
|
35
|
-
end
|
36
48
|
|
37
|
-
|
38
|
-
mails = ActionMailer::Base.cached_deliveries
|
39
|
-
# append new one
|
40
|
-
mails << mail
|
41
|
-
# write all emails to cache file
|
42
|
-
File.open(@settings[:location], 'w') do |file|
|
43
|
-
Marshal.dump(mails, file)
|
49
|
+
Mail::TestMailer.deliveries << mail
|
44
50
|
end
|
45
|
-
|
46
|
-
Mail::TestMailer.deliveries << mail
|
47
51
|
end
|
48
52
|
|
49
53
|
end # CacheDelivery
|
@@ -10,26 +10,28 @@ describe ActionMailerCacheDelivery do
|
|
10
10
|
before(:each) do
|
11
11
|
ActionMailerCacheDelivery.install
|
12
12
|
ActionMailer::Base.delivery_method = :cache
|
13
|
+
ActionMailer::Base.cache_settings[:location] = "#{Dir.tmpdir}/test.cache"
|
13
14
|
end
|
14
15
|
|
15
16
|
describe 'clear_cache' do
|
16
17
|
it 'allows clearing cache before cache file is created' do
|
17
|
-
ActionMailer::Base.cache_settings[:location] = '
|
18
|
-
|
18
|
+
ActionMailer::Base.cache_settings[:location] = ''
|
19
|
+
expect { ActionMailer::Base.clear_cache }.not_to raise_error
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'should clear cache file' do
|
22
23
|
mail.deliver
|
23
24
|
ActionMailer::Base.clear_cache
|
24
|
-
File.open(ActionMailer::Base.cache_settings[:location], 'r') do |file|
|
25
|
+
mails = File.open(ActionMailer::Base.cache_settings[:location], 'r') do |file|
|
25
26
|
Marshal.load(file)
|
26
|
-
end
|
27
|
+
end
|
28
|
+
expect(mails).to eq([])
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'should clear ActionMailer::Base.deliveries' do
|
30
32
|
mail.deliver
|
31
33
|
ActionMailer::Base.clear_cache
|
32
|
-
ActionMailer::Base.deliveries.
|
34
|
+
expect(ActionMailer::Base.deliveries).to eq([])
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -39,20 +41,19 @@ describe ActionMailerCacheDelivery do
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'returns empty array if cache has not been created yet' do
|
42
|
-
ActionMailer::Base.
|
43
|
-
ActionMailer::Base.cached_deliveries.should == []
|
44
|
+
expect(ActionMailer::Base.cached_deliveries).to eq([])
|
44
45
|
end
|
45
46
|
|
46
47
|
it 'should return array' do
|
47
48
|
mail.deliver
|
48
|
-
ActionMailer::Base.cached_deliveries.
|
49
|
+
expect(ActionMailer::Base.cached_deliveries).to be_an(Array)
|
49
50
|
end
|
50
51
|
|
51
52
|
it 'should return all the sent emails' do
|
52
53
|
5.times do
|
53
54
|
mail.deliver
|
54
55
|
end
|
55
|
-
ActionMailer::Base.cached_deliveries.length.
|
56
|
+
expect(ActionMailer::Base.cached_deliveries.length).to eq(5)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
@@ -61,25 +62,27 @@ describe ActionMailerCacheDelivery do
|
|
61
62
|
describe 'extend ActionMailer' do
|
62
63
|
it 'should add cached_deliveries method to ActionMailer' do
|
63
64
|
ActionMailerCacheDelivery.install
|
64
|
-
ActionMailer::Base.
|
65
|
+
expect(ActionMailer::Base).to respond_to(:cached_deliveries)
|
65
66
|
end
|
66
67
|
|
67
68
|
it 'should add clear_cache method to ActionMailer' do
|
68
69
|
ActionMailerCacheDelivery.install
|
69
|
-
ActionMailer::Base.
|
70
|
+
expect(ActionMailer::Base).to respond_to(:clear_cache)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
74
|
describe 'install' do
|
74
75
|
it 'should add :cache delivery method to ActionMailer' do
|
75
76
|
ActionMailerCacheDelivery.install
|
76
|
-
ActionMailer::Base.delivery_methods.
|
77
|
+
expect(ActionMailer::Base.delivery_methods).to include(:cache)
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'should set cache path to /tmp when Rails is not defined' do
|
81
|
+
hide_const('Rails')
|
80
82
|
ActionMailerCacheDelivery.install
|
81
83
|
ActionMailer::Base.delivery_method = :cache
|
82
|
-
ActionMailer::Base.cache_settings[:location]
|
84
|
+
expect(ActionMailer::Base.cache_settings[:location])
|
85
|
+
.to eq("#{Dir.tmpdir}/cache/action_mailer_cache_deliveries.cache")
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
data/spec/cache_delivery_spec.rb
CHANGED
@@ -15,30 +15,32 @@ describe Mail::CacheDelivery do
|
|
15
15
|
it 'should allow setting custom location' do
|
16
16
|
ActionMailer::Base.cache_settings = { location: '/tmp/mail.cache' }
|
17
17
|
mail.deliver
|
18
|
-
File.
|
18
|
+
expect(File.exist?('/tmp/mail.cache')).to eq(true)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'deliver!' do
|
23
23
|
it 'should write mail to cache file' do
|
24
24
|
mail.deliver
|
25
|
-
File.open(ActionMailer::Base.cache_settings[:location], 'r') do |file|
|
25
|
+
mails = File.open(ActionMailer::Base.cache_settings[:location], 'r') do |file|
|
26
26
|
Marshal.load(file)
|
27
|
-
end
|
27
|
+
end
|
28
|
+
expect(mails).to eq([mail])
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'should append mail to cache file' do
|
31
32
|
5.times do
|
32
33
|
mail.deliver
|
33
34
|
end
|
34
|
-
File.open(ActionMailer::Base.cache_settings[:location], 'r') do |file|
|
35
|
+
mails = File.open(ActionMailer::Base.cache_settings[:location], 'r') do |file|
|
35
36
|
Marshal.load(file)
|
36
|
-
end
|
37
|
+
end
|
38
|
+
expect(mails.length).to eq(5)
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'should append mail to TestMailer deliveries' do
|
40
42
|
mail.deliver
|
41
|
-
Mail::TestMailer.deliveries.
|
43
|
+
expect(Mail::TestMailer.deliveries).to eq([mail])
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end # Mail::CachedDelivery
|
data/spec/spec_helper.rb
CHANGED
@@ -9,3 +9,10 @@ class Mailer < ActionMailer::Base
|
|
9
9
|
mail(from: 'from@test.com', to: 'to@test.com', subject: 'Test email', body: 'Hello.')
|
10
10
|
end
|
11
11
|
end # Mailer
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.before(:each) do
|
15
|
+
stub_const('Rails', Module.new)
|
16
|
+
allow(Rails).to receive(:root).and_return(Dir.pwd)
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_mailer_cache_delivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alex Rodionov
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2023-05-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: actionmailer
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '2.8'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '2.8'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0.9'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0.9'
|
62
55
|
description: Cache delivery method for ActionMailer for testing emails with Selenium
|
@@ -65,8 +58,9 @@ executables: []
|
|
65
58
|
extensions: []
|
66
59
|
extra_rdoc_files: []
|
67
60
|
files:
|
68
|
-
- .travis.yml
|
61
|
+
- ".travis.yml"
|
69
62
|
- Gemfile
|
63
|
+
- LICENSE
|
70
64
|
- README.md
|
71
65
|
- Rakefile
|
72
66
|
- action_mailer_cache_delivery.gemspec
|
@@ -79,34 +73,27 @@ files:
|
|
79
73
|
- spec/cache_delivery_spec.rb
|
80
74
|
- spec/spec_helper.rb
|
81
75
|
homepage: https://github.com/p0deje/action_mailer_cache_delivery
|
82
|
-
licenses:
|
83
|
-
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
84
80
|
rdoc_options: []
|
85
81
|
require_paths:
|
86
82
|
- lib
|
87
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
84
|
requirements:
|
90
|
-
- -
|
85
|
+
- - ">="
|
91
86
|
- !ruby/object:Gem::Version
|
92
87
|
version: '0'
|
93
|
-
segments:
|
94
|
-
- 0
|
95
|
-
hash: 301364848167179803
|
96
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
89
|
requirements:
|
99
|
-
- -
|
90
|
+
- - ">="
|
100
91
|
- !ruby/object:Gem::Version
|
101
92
|
version: '0'
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
hash: 301364848167179803
|
105
93
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
specification_version: 3
|
94
|
+
rubygems_version: 3.3.25
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
110
97
|
summary: Cache delivery method for ActionMailer
|
111
98
|
test_files:
|
112
99
|
- spec/action_mailer_cache_delivery_spec.rb
|