premailer-rails 1.9.5 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +64 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +40 -0
- data/Gemfile +15 -11
- data/README.md +32 -37
- data/VERSION +1 -1
- data/examples/rails5/Gemfile +4 -0
- data/{example → examples/rails5}/Rakefile +1 -1
- data/{example → examples/rails5}/bin/rails +1 -1
- data/{example → examples/rails5}/config/application.rb +4 -1
- data/examples/rails5/config/boot.rb +3 -0
- data/{example → examples/rails5}/config/environment.rb +1 -1
- data/{example → examples/rails5}/config.ru +2 -1
- data/examples/rails6/.gitignore +16 -0
- data/examples/rails6/Gemfile +5 -0
- data/examples/rails6/README.md +10 -0
- data/examples/rails6/Rakefile +6 -0
- data/examples/rails6/app/assets/config/manifest.js +1 -0
- data/examples/rails6/app/assets/stylesheets/email.css +32 -0
- data/examples/rails6/app/mailers/example_mailer.rb +7 -0
- data/examples/rails6/app/views/example_mailer/test_message.html.erb +18 -0
- data/examples/rails6/bin/rails +4 -0
- data/examples/rails6/config/application.rb +15 -0
- data/examples/rails6/config/boot.rb +3 -0
- data/examples/rails6/config/environment.rb +5 -0
- data/examples/rails6/config/environments/development.rb +9 -0
- data/examples/rails6/config/environments/production.rb +9 -0
- data/examples/rails6/config/routes.rb +3 -0
- data/examples/rails6/config.ru +6 -0
- data/examples/rails6/test/mailers/previews/example_mailer_preview.rb +5 -0
- data/examples/rails7-propshaft/.gitignore +16 -0
- data/examples/rails7-propshaft/Gemfile +6 -0
- data/examples/rails7-propshaft/README.md +10 -0
- data/examples/rails7-propshaft/Rakefile +6 -0
- data/examples/rails7-propshaft/app/assets/stylesheets/email.css +32 -0
- data/examples/rails7-propshaft/app/mailers/example_mailer.rb +7 -0
- data/examples/rails7-propshaft/app/views/example_mailer/test_message.html.erb +18 -0
- data/examples/rails7-propshaft/bin/rails +4 -0
- data/examples/rails7-propshaft/config/application.rb +14 -0
- data/examples/rails7-propshaft/config/boot.rb +3 -0
- data/examples/rails7-propshaft/config/environment.rb +5 -0
- data/examples/rails7-propshaft/config/environments/development.rb +9 -0
- data/examples/rails7-propshaft/config/environments/production.rb +9 -0
- data/examples/rails7-propshaft/config/routes.rb +3 -0
- data/examples/rails7-propshaft/config.ru +6 -0
- data/examples/rails7-propshaft/test/mailers/previews/example_mailer_preview.rb +5 -0
- data/examples/rails7-sprockets/.gitignore +16 -0
- data/examples/rails7-sprockets/Gemfile +6 -0
- data/examples/rails7-sprockets/README.md +10 -0
- data/examples/rails7-sprockets/Rakefile +6 -0
- data/examples/rails7-sprockets/app/assets/config/manifest.js +1 -0
- data/examples/rails7-sprockets/app/assets/stylesheets/email.css +32 -0
- data/examples/rails7-sprockets/app/mailers/example_mailer.rb +7 -0
- data/examples/rails7-sprockets/app/views/example_mailer/test_message.html.erb +18 -0
- data/examples/rails7-sprockets/bin/rails +4 -0
- data/examples/rails7-sprockets/config/application.rb +14 -0
- data/examples/rails7-sprockets/config/boot.rb +3 -0
- data/examples/rails7-sprockets/config/environment.rb +5 -0
- data/examples/rails7-sprockets/config/environments/development.rb +9 -0
- data/examples/rails7-sprockets/config/environments/production.rb +9 -0
- data/examples/rails7-sprockets/config/routes.rb +3 -0
- data/examples/rails7-sprockets/config.ru +6 -0
- data/examples/rails7-sprockets/test/mailers/previews/example_mailer_preview.rb +5 -0
- data/lib/premailer/rails/css_helper.rb +32 -11
- data/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb +16 -15
- data/lib/premailer/rails/css_loaders/file_system_loader.rb +24 -2
- data/lib/premailer/rails/css_loaders/network_loader.rb +2 -2
- data/lib/premailer/rails/css_loaders/propshaft_loader.rb +38 -0
- data/lib/premailer/rails/css_loaders.rb +1 -1
- data/lib/premailer/rails/customized_premailer.rb +4 -4
- data/lib/premailer/rails/hook.rb +2 -6
- data/lib/premailer/rails/railtie.rb +1 -1
- data/lib/premailer/rails.rb +2 -1
- data/premailer-rails.gemspec +4 -3
- data/spec/integration/css_helper_spec.rb +262 -129
- data/spec/integration/delivery_spec.rb +13 -0
- data/spec/integration/hook_spec.rb +36 -11
- data/spec/rails_app/app/assets/config/manifest.js +3 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +3 -0
- data/spec/rails_app/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_app/app/mailers/welcome_mailer.rb +6 -0
- data/spec/rails_app/app/views/layouts/mailer.html.erb +11 -0
- data/spec/rails_app/app/views/welcome_mailer/welcome_email.html.erb +1 -0
- data/spec/rails_app/config/application.rb +19 -0
- data/spec/rails_app/config/boot.rb +5 -0
- data/spec/rails_app/config/environment.rb +2 -0
- data/spec/rails_app/config/environments/test.rb +10 -0
- data/spec/rails_app/config/initializers/assets.rb +1 -0
- data/spec/rails_app/config/routes.rb +3 -0
- data/spec/rails_app/config.ru +5 -0
- data/spec/rails_app/log/.keep +0 -0
- data/spec/rails_app/tmp/.keep +0 -0
- data/spec/spec_helper.rb +3 -17
- data/spec/support/fixtures/message.rb +40 -0
- data/spec/unit/css_loaders/asset_pipeline_loader_spec.rb +44 -32
- data/spec/unit/css_loaders/file_system_loader_spec.rb +37 -0
- data/spec/unit/css_loaders/network_loader_spec.rb +1 -1
- data/spec/unit/css_loaders/propshaft_loader_spec.rb +57 -0
- data/spec/unit/customized_premailer_spec.rb +32 -40
- metadata +121 -81
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -22
- data/example/Gemfile +0 -10
- data/example/config/boot.rb +0 -3
- data/example/config/secrets.yml +0 -2
- data/lib/premailer/rails/css_loaders/cache_loader.rb +0 -29
- data/spec/integration/hook_registration_spec.rb +0 -11
- data/spec/support/stubs/action_mailer.rb +0 -5
- data/spec/support/stubs/rails.rb +0 -51
- /data/{example → examples/rails5}/.gitignore +0 -0
- /data/{example → examples/rails5}/README.md +0 -0
- /data/{example → examples/rails5}/app/assets/stylesheets/email.css +0 -0
- /data/{example → examples/rails5}/app/mailers/example_mailer.rb +0 -0
- /data/{example → examples/rails5}/app/views/example_mailer/test_message.html.erb +0 -0
- /data/{example → examples/rails5}/config/environments/development.rb +0 -0
- /data/{example → examples/rails5}/config/environments/production.rb +0 -0
- /data/{example → examples/rails5}/config/initializers/assets.rb +0 -0
- /data/{example → examples/rails5}/config/routes.rb +0 -0
- /data/{example → examples/rails5}/test/mailers/previews/example_mailer_preview.rb +0 -0
@@ -1,186 +1,319 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Premailer::Rails::CSSHelper do
|
4
|
-
|
5
|
-
|
4
|
+
# Reset the CSS cache:
|
5
|
+
after do
|
6
|
+
Premailer::Rails::CSSHelper.cache = {}
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Premailer::Rails::CSSLoaders::CacheLoader.clear!
|
11
|
-
end
|
9
|
+
def css_for_url(path)
|
10
|
+
Premailer::Rails::CSSHelper.css_for_url(path)
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
def css_for_doc(doc)
|
14
|
+
Premailer::Rails::CSSHelper.css_for_doc(doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def expect_file(path, content='file content')
|
18
|
+
path = "#{Rails.root}/#{path}"
|
19
|
+
allow(File).to receive(:file?).with(path).and_return(true)
|
20
|
+
expect(File).to receive(:read).with(path).and_return(content)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#css_for_doc' do
|
24
|
+
let(:html) { Fixtures::HTML.with_css_links(*files) }
|
25
|
+
let(:doc) { Nokogiri(html) }
|
26
|
+
|
27
|
+
context 'when HTML contains linked CSS files' do
|
28
|
+
let(:files) { %w[ stylesheets/base.css stylesheets/font.css ] }
|
29
|
+
|
30
|
+
it 'returns the content of both files concatenated' do
|
31
|
+
allow(Premailer::Rails::CSSHelper).to \
|
32
|
+
receive(:css_for_url)
|
33
|
+
.with('http://example.com/stylesheets/base.css')
|
34
|
+
.and_return('content of base.css')
|
35
|
+
allow(Premailer::Rails::CSSHelper).to \
|
36
|
+
receive(:css_for_url)
|
37
|
+
.with('http://example.com/stylesheets/font.css')
|
38
|
+
.and_return('content of font.css')
|
39
|
+
|
40
|
+
expect(css_for_doc(doc)).to eq("content of base.css\ncontent of font.css")
|
15
41
|
end
|
42
|
+
end
|
16
43
|
|
17
|
-
|
18
|
-
|
44
|
+
context 'when HTML contains ignored links' do
|
45
|
+
let(:files) { ['ignore.css', 'data-premailer' => 'ignore'] }
|
46
|
+
|
47
|
+
it 'ignores links' do
|
48
|
+
expect(Premailer::Rails::CSSHelper).to_not receive(:css_for_url)
|
49
|
+
css_for_doc(doc)
|
19
50
|
end
|
51
|
+
end
|
52
|
+
end
|
20
53
|
|
21
|
-
|
22
|
-
|
23
|
-
|
54
|
+
describe '#css_for_url' do
|
55
|
+
context 'when path is a url' do
|
56
|
+
it 'loads the CSS at the local path' do
|
57
|
+
expect_file('public/stylesheets/base.css')
|
58
|
+
|
59
|
+
css_for_url('http://example.com/stylesheets/base.css?test')
|
24
60
|
end
|
61
|
+
end
|
25
62
|
|
26
|
-
|
27
|
-
|
28
|
-
|
63
|
+
context 'when path is a relative url' do
|
64
|
+
it 'loads the CSS at the local path' do
|
65
|
+
expect_file('public/stylesheets/base.css')
|
66
|
+
css_for_url('/stylesheets/base.css?test')
|
67
|
+
end
|
68
|
+
end
|
29
69
|
|
30
|
-
|
31
|
-
|
70
|
+
context 'when cache is enabled' do
|
71
|
+
before do
|
72
|
+
allow(Premailer::Rails::CSSHelper).to receive(:cache_enabled?).and_return(true)
|
73
|
+
end
|
32
74
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
.with('http://example.com/stylesheets/base.css')
|
37
|
-
.and_return('content of base.css')
|
38
|
-
allow(Premailer::Rails::CSSHelper).to \
|
39
|
-
receive(:css_for_url)
|
40
|
-
.with('http://example.com/stylesheets/font.css')
|
41
|
-
.and_return('content of font.css')
|
75
|
+
context 'when file is cached' do
|
76
|
+
it 'returns the cached value' do
|
77
|
+
Premailer::Rails::CSSHelper.cache['http://example.com/stylesheets/base.css'] = 'content of base.css'
|
42
78
|
|
43
|
-
|
44
|
-
|
79
|
+
expect(css_for_url('http://example.com/stylesheets/base.css')).to \
|
80
|
+
eq('content of base.css')
|
45
81
|
end
|
82
|
+
end
|
83
|
+
end
|
46
84
|
|
47
|
-
|
48
|
-
|
85
|
+
context 'when cache is disabled' do
|
86
|
+
before do
|
87
|
+
allow(Premailer::Rails::CSSHelper).to receive(:cache_enabled?).and_return(false)
|
88
|
+
end
|
49
89
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
90
|
+
it 'does not return cached values' do
|
91
|
+
Premailer::Rails::CSSHelper.cache['http://example.com/stylesheets/base.css'] = 'cached content'
|
92
|
+
content = 'new content of base.css'
|
93
|
+
expect_file('public/stylesheets/base.css', content)
|
94
|
+
|
95
|
+
expect(css_for_url('http://example.com/stylesheets/base.css')).to eq(content)
|
55
96
|
end
|
97
|
+
end
|
56
98
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
99
|
+
if defined?(::Sprockets)
|
100
|
+
context 'when Rails asset pipeline is used' do
|
101
|
+
before do
|
102
|
+
allow(Rails.configuration)
|
103
|
+
.to receive(:assets).and_return(double(prefix: '/assets'))
|
104
|
+
allow(Rails.configuration)
|
105
|
+
.to receive(:relative_url_root).and_return(nil)
|
106
|
+
end
|
61
107
|
|
62
|
-
|
108
|
+
context 'and a precompiled file exists' do
|
109
|
+
it 'returns that file' do
|
110
|
+
path = '/assets/email-digest.css'
|
111
|
+
content = 'read from file'
|
112
|
+
expect_file("public#{path}", content)
|
113
|
+
expect(css_for_url(path)).to eq(content)
|
63
114
|
end
|
64
115
|
end
|
65
116
|
|
66
|
-
context
|
67
|
-
|
68
|
-
|
69
|
-
|
117
|
+
context "when find_sources raises TypeError" do
|
118
|
+
let(:response) { 'content of base.css' }
|
119
|
+
let(:uri) { URI('http://example.com/assets/base.css') }
|
120
|
+
|
121
|
+
it "falls back to Net::HTTP" do
|
122
|
+
expect(Rails.application.assets_manifest).to \
|
123
|
+
receive(:find_sources)
|
124
|
+
.with('base.css')
|
125
|
+
.and_raise(TypeError)
|
126
|
+
|
127
|
+
allow(Net::HTTP).to \
|
128
|
+
receive(:get)
|
129
|
+
.with(uri, { 'Accept' => 'text/css' })
|
130
|
+
.and_return(response)
|
131
|
+
expect(css_for_url('http://example.com/assets/base.css')).to \
|
132
|
+
eq(response)
|
70
133
|
end
|
71
134
|
end
|
72
135
|
|
73
|
-
context
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
)
|
136
|
+
context "when find_sources raises Errno::ENOENT" do
|
137
|
+
let(:response) { 'content of base.css' }
|
138
|
+
let(:uri) { URI('http://example.com/assets/base.css') }
|
139
|
+
|
140
|
+
it "falls back to Net::HTTP" do
|
141
|
+
expect(Rails.application.assets_manifest).to \
|
142
|
+
receive(:find_sources)
|
143
|
+
.with('base.css')
|
144
|
+
.and_raise(Errno::ENOENT)
|
79
145
|
|
80
|
-
|
81
|
-
|
146
|
+
allow(Net::HTTP).to \
|
147
|
+
receive(:get)
|
148
|
+
.with(uri, { 'Accept' => 'text/css' })
|
149
|
+
.and_return(response)
|
150
|
+
expect(css_for_url('http://example.com/assets/base.css')).to \
|
151
|
+
eq(response)
|
82
152
|
end
|
83
153
|
end
|
84
154
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
'
|
89
|
-
'
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
allow(Rails.env).to receive(:development?).and_return(true)
|
94
|
-
|
95
|
-
expect(css_for_url('http://example.com/stylesheets/base.css')).to eq(content)
|
96
|
-
end
|
155
|
+
it 'returns the content of the file compiled by Rails' do
|
156
|
+
expect(Rails.application.assets_manifest).to \
|
157
|
+
receive(:find_sources)
|
158
|
+
.with('base.css')
|
159
|
+
.and_return(['content of base.css'])
|
160
|
+
|
161
|
+
expect(css_for_url('http://example.com/assets/base.css')).to \
|
162
|
+
eq('content of base.css')
|
97
163
|
end
|
98
164
|
|
99
|
-
|
165
|
+
it 'returns same file when path contains file fingerprint' do
|
166
|
+
expect(Rails.application.assets_manifest).to \
|
167
|
+
receive(:find_sources)
|
168
|
+
.with('base.css')
|
169
|
+
.and_return(['content of base.css'])
|
170
|
+
|
171
|
+
expect(css_for_url(
|
172
|
+
'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
|
173
|
+
)).to eq('content of base.css')
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when asset can not be found' do
|
177
|
+
let(:response) { 'content of base.css' }
|
178
|
+
let(:path) { '/assets/base-089e35bd5d84297b8d31ad552e433275.css' }
|
179
|
+
let(:url) { "http://assets.example.com#{path}" }
|
180
|
+
let(:asset_host) { 'http://assets.example.com' }
|
181
|
+
|
100
182
|
before do
|
101
|
-
allow(Rails.
|
102
|
-
|
103
|
-
|
104
|
-
|
183
|
+
allow(Rails.application.assets_manifest).to \
|
184
|
+
receive(:find_sources).and_return([])
|
185
|
+
|
186
|
+
config = double(asset_host: asset_host)
|
187
|
+
allow(Rails.configuration).to \
|
188
|
+
receive(:action_controller).and_return(config)
|
189
|
+
|
190
|
+
allow(Net::HTTP).to \
|
191
|
+
receive(:get)
|
192
|
+
.with(URI(url), { 'Accept' => 'text/css' })
|
193
|
+
.and_return(response)
|
105
194
|
end
|
106
195
|
|
107
|
-
|
108
|
-
|
109
|
-
path = '/assets/email-digest.css'
|
110
|
-
content = 'read from file'
|
111
|
-
expect_file("public#{path}", content)
|
112
|
-
expect(css_for_url(path)).to eq(content)
|
113
|
-
end
|
196
|
+
it 'requests the file' do
|
197
|
+
expect(css_for_url(url)).to eq('content of base.css')
|
114
198
|
end
|
115
199
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
.and_return(double(to_s: 'content of base.css'))
|
200
|
+
context 'when file url does not include the host' do
|
201
|
+
it 'requests the file using the asset host as host' do
|
202
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
203
|
+
end
|
121
204
|
|
122
|
-
|
123
|
-
|
124
|
-
end
|
205
|
+
context 'and the asset host uses protocol relative scheme' do
|
206
|
+
let(:asset_host) { '//assets.example.com' }
|
125
207
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
208
|
+
it 'requests the file using http as the scheme' do
|
209
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
elsif defined?(::Propshaft)
|
216
|
+
context 'when Propshaft is used' do
|
217
|
+
before do
|
218
|
+
allow(Rails.configuration)
|
219
|
+
.to receive(:assets).and_return(double(prefix: '/assets'))
|
220
|
+
allow(Rails.configuration)
|
221
|
+
.to receive(:relative_url_root).and_return(nil)
|
222
|
+
end
|
131
223
|
|
132
|
-
|
133
|
-
|
134
|
-
|
224
|
+
context 'and a precompiled file exists' do
|
225
|
+
it 'returns that file' do
|
226
|
+
path = '/assets/email-digest.css'
|
227
|
+
content = 'read from file'
|
228
|
+
expect_file("public#{path}", content)
|
229
|
+
expect(css_for_url(path)).to eq(content)
|
135
230
|
end
|
231
|
+
end
|
136
232
|
|
137
|
-
|
138
|
-
|
139
|
-
let(:path) { '/assets/base-089e35bd5d84297b8d31ad552e433275.css' }
|
140
|
-
let(:url) { "http://assets.example.com#{path}" }
|
141
|
-
let(:asset_host) { 'http://assets.example.com' }
|
233
|
+
it 'returns the content of the file compiled by Propshaft' do
|
234
|
+
asset = double()
|
142
235
|
|
143
|
-
|
144
|
-
|
145
|
-
|
236
|
+
expect(Rails.application.assets.load_path).to \
|
237
|
+
receive(:find)
|
238
|
+
.with('base.css')
|
239
|
+
.and_return(asset)
|
146
240
|
|
147
|
-
|
148
|
-
|
149
|
-
|
241
|
+
expect(Rails.application.assets.compilers).to \
|
242
|
+
receive(:compile)
|
243
|
+
.with(asset)
|
244
|
+
.and_return('content of base.css')
|
150
245
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
246
|
+
expect(css_for_url('http://example.com/assets/base.css')).to \
|
247
|
+
eq('content of base.css')
|
248
|
+
end
|
155
249
|
|
156
|
-
|
157
|
-
|
158
|
-
end
|
250
|
+
it 'returns same file when path contains file fingerprint' do
|
251
|
+
asset = double()
|
159
252
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
253
|
+
expect(Rails.application.assets.load_path).to \
|
254
|
+
receive(:find)
|
255
|
+
.with('base.css')
|
256
|
+
.and_return(asset)
|
257
|
+
|
258
|
+
expect(Rails.application.assets.compilers).to \
|
259
|
+
receive(:compile)
|
260
|
+
.with(asset)
|
261
|
+
.and_return('content of base.css')
|
262
|
+
|
263
|
+
expect(css_for_url(
|
264
|
+
'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
|
265
|
+
)).to eq('content of base.css')
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'when asset can not be found' do
|
269
|
+
let(:response) { 'content of base.css' }
|
270
|
+
let(:path) { '/assets/base-089e35bd5d84297b8d31ad552e433275.css' }
|
271
|
+
let(:url) { "http://assets.example.com#{path}" }
|
272
|
+
let(:asset_host) { 'http://assets.example.com' }
|
273
|
+
|
274
|
+
before do
|
275
|
+
expect(Rails.application.assets.load_path).to \
|
276
|
+
receive(:find)
|
277
|
+
.with('base.css')
|
278
|
+
.and_return(nil)
|
279
|
+
|
280
|
+
config = double(asset_host: asset_host)
|
281
|
+
allow(Rails.configuration).to \
|
282
|
+
receive(:action_controller).and_return(config)
|
283
|
+
|
284
|
+
allow(Net::HTTP).to \
|
285
|
+
receive(:get)
|
286
|
+
.with(URI(url), { 'Accept' => 'text/css' })
|
287
|
+
.and_return(response)
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'requests the file' do
|
291
|
+
expect(css_for_url(url)).to eq('content of base.css')
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when file url does not include the host' do
|
295
|
+
it 'requests the file using the asset host as host' do
|
296
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
297
|
+
end
|
164
298
|
|
165
|
-
|
166
|
-
|
299
|
+
context 'and the asset host uses protocol relative scheme' do
|
300
|
+
let(:asset_host) { '//assets.example.com' }
|
167
301
|
|
168
|
-
|
169
|
-
|
170
|
-
end
|
302
|
+
it 'requests the file using http as the scheme' do
|
303
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
171
304
|
end
|
172
305
|
end
|
173
306
|
end
|
174
307
|
end
|
308
|
+
end
|
309
|
+
end
|
175
310
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
end
|
311
|
+
context 'when static stylesheets are used' do
|
312
|
+
it 'returns the content of the static file' do
|
313
|
+
content = 'content of base.css'
|
314
|
+
expect_file('public/stylesheets/base.css', content)
|
315
|
+
loaded_content = css_for_url('http://example.com/stylesheets/base.css')
|
316
|
+
expect(loaded_content).to eq(content)
|
184
317
|
end
|
185
318
|
end
|
186
319
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ActionMailer::Base delivery' do
|
4
|
+
it 'delivers email with inlined CSS' do
|
5
|
+
WelcomeMailer.welcome_email("world").deliver_now
|
6
|
+
|
7
|
+
mail = ActionMailer::Base.deliveries.last
|
8
|
+
expect(mail).to be_present
|
9
|
+
body = mail.html_part.body.to_s
|
10
|
+
expect(body).to be_present
|
11
|
+
expect(body).to include(%{<p style="font-size: 12px;">Hello world</p>})
|
12
|
+
end
|
13
|
+
end
|
@@ -6,7 +6,7 @@ describe Premailer::Rails::Hook do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def body_content(message)
|
9
|
-
Nokogiri::HTML(message.html_string).at('body').content
|
9
|
+
Nokogiri::HTML(message.html_string).at('body').content.gsub("\r\n", "\n")
|
10
10
|
end
|
11
11
|
|
12
12
|
class Mail::Message
|
@@ -47,18 +47,31 @@ describe Premailer::Rails::Hook do
|
|
47
47
|
expect(processed_message.parts).to match_array(expected_parts)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
it 'does not screw up the text by maintaining the original body encoding' do
|
51
|
+
raw_msg = Fixtures::Message.latin_message
|
52
|
+
processed_msg = Fixtures::Message.latin_message
|
53
|
+
run_hook(processed_msg)
|
54
|
+
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
raw_msg = Fixtures::Message.non_latin_message
|
57
|
+
processed_msg = Fixtures::Message.non_latin_message
|
58
|
+
run_hook(processed_msg)
|
59
|
+
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
60
|
+
|
61
|
+
raw_msg = Fixtures::Message.greek_message
|
62
|
+
processed_msg = Fixtures::Message.greek_message
|
63
|
+
run_hook(processed_msg)
|
64
|
+
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
65
|
+
|
66
|
+
raw_msg = Fixtures::Message.dash_message
|
67
|
+
processed_msg = Fixtures::Message.dash_message
|
68
|
+
run_hook(processed_msg)
|
69
|
+
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
59
70
|
end
|
60
71
|
|
61
|
-
it '
|
72
|
+
it 'supports US-ASCII output' do
|
73
|
+
Premailer::Rails.config.merge!(output_encoding: 'US-ASCII')
|
74
|
+
|
62
75
|
raw_msg = Fixtures::Message.latin_message
|
63
76
|
processed_msg = Fixtures::Message.latin_message
|
64
77
|
run_hook(processed_msg)
|
@@ -68,6 +81,18 @@ describe Premailer::Rails::Hook do
|
|
68
81
|
processed_msg = Fixtures::Message.non_latin_message
|
69
82
|
run_hook(processed_msg)
|
70
83
|
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
84
|
+
|
85
|
+
raw_msg = Fixtures::Message.greek_message
|
86
|
+
processed_msg = Fixtures::Message.greek_message
|
87
|
+
run_hook(processed_msg)
|
88
|
+
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
89
|
+
|
90
|
+
raw_msg = Fixtures::Message.dash_message
|
91
|
+
processed_msg = Fixtures::Message.dash_message
|
92
|
+
run_hook(processed_msg)
|
93
|
+
expect(body_content(processed_msg)).to eq(body_content(raw_msg))
|
94
|
+
ensure
|
95
|
+
Premailer::Rails.config.delete(:output_encoding)
|
71
96
|
end
|
72
97
|
|
73
98
|
it 'generates a text part from the html' do
|
@@ -91,7 +116,7 @@ describe Premailer::Rails::Hook do
|
|
91
116
|
|
92
117
|
it 'does not replace any message part' do
|
93
118
|
expect { run_hook(message) }.to_not \
|
94
|
-
change { message.all_parts.map(&:content_type) }
|
119
|
+
change { message.all_parts.map(&:content_type).sort }
|
95
120
|
end
|
96
121
|
end
|
97
122
|
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Hello <%= @greeting %></p>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
require "action_controller/railtie"
|
4
|
+
require "action_mailer/railtie"
|
5
|
+
require "action_view/railtie"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require "sprockets/railtie"
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rails/test_unit/railtie"
|
13
|
+
|
14
|
+
Bundler.require(*Rails.groups)
|
15
|
+
|
16
|
+
module Dummy
|
17
|
+
class Application < Rails::Application
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
config.eager_load = false
|
4
|
+
config.consider_all_requests_local = true
|
5
|
+
config.action_controller.perform_caching = false
|
6
|
+
config.action_dispatch.show_exceptions = false
|
7
|
+
config.action_controller.allow_forgery_protection = false
|
8
|
+
config.action_mailer.delivery_method = :test
|
9
|
+
config.active_support.deprecation = :stderr
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.assets.version = '1.0'
|
File without changes
|
File without changes
|