premailer-rails 1.9.5 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.travis.yml +2 -9
  4. data/CHANGELOG.md +26 -0
  5. data/Gemfile +8 -4
  6. data/README.md +21 -28
  7. data/VERSION +1 -1
  8. data/lib/premailer/rails/css_helper.rb +29 -10
  9. data/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb +11 -11
  10. data/lib/premailer/rails/css_loaders/file_system_loader.rb +24 -2
  11. data/lib/premailer/rails/css_loaders/network_loader.rb +1 -1
  12. data/lib/premailer/rails/css_loaders.rb +0 -1
  13. data/lib/premailer/rails/customized_premailer.rb +4 -4
  14. data/lib/premailer/rails.rb +2 -1
  15. data/premailer-rails.gemspec +1 -2
  16. data/spec/integration/css_helper_spec.rb +170 -139
  17. data/spec/integration/delivery_spec.rb +13 -0
  18. data/spec/integration/hook_spec.rb +1 -1
  19. data/spec/rails_app/app/assets/config/manifest.js +3 -0
  20. data/spec/rails_app/app/assets/stylesheets/application.css +3 -0
  21. data/spec/rails_app/app/mailers/application_mailer.rb +4 -0
  22. data/spec/rails_app/app/mailers/welcome_mailer.rb +6 -0
  23. data/spec/rails_app/app/views/layouts/mailer.html.erb +11 -0
  24. data/spec/rails_app/app/views/welcome_mailer/welcome_email.html.erb +1 -0
  25. data/spec/rails_app/config/application.rb +13 -0
  26. data/spec/rails_app/config/boot.rb +5 -0
  27. data/spec/rails_app/config/environment.rb +2 -0
  28. data/spec/rails_app/config/environments/test.rb +10 -0
  29. data/spec/rails_app/config/initializers/assets.rb +1 -0
  30. data/spec/rails_app/config/routes.rb +3 -0
  31. data/spec/rails_app/config.ru +5 -0
  32. data/spec/spec_helper.rb +3 -4
  33. data/spec/unit/css_loaders/file_system_loader_spec.rb +37 -0
  34. data/spec/unit/css_loaders/network_loader_spec.rb +1 -1
  35. data/spec/unit/customized_premailer_spec.rb +32 -40
  36. metadata +33 -32
  37. data/lib/premailer/rails/css_loaders/cache_loader.rb +0 -29
  38. data/spec/integration/hook_registration_spec.rb +0 -11
  39. data/spec/support/stubs/action_mailer.rb +0 -5
  40. data/spec/support/stubs/rails.rb +0 -51
@@ -1,186 +1,217 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Premailer::Rails::CSSHelper do
4
- [ :Nokogiri, :Hpricot ].each do |adapter|
5
- next if adapter == :Hpricot and RUBY_PLATFORM == 'java'
4
+ # Reset the CSS cache:
5
+ after do
6
+ Premailer::Rails::CSSHelper.cache = {}
7
+ end
6
8
 
7
- context "when adapter is #{adapter}" do
8
- # Reset the CSS cache:
9
- after do
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
+
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
12
22
 
13
- def css_for_url(path)
14
- Premailer::Rails::CSSHelper.css_for_url(path)
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
- def css_for_doc(doc)
18
- Premailer::Rails::CSSHelper.css_for_doc(doc)
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
- def expect_file(path, content='file content')
22
- allow(File).to receive(:file?).with(path).and_return(true)
23
- expect(File).to receive(:read).with(path).and_return(content)
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
- describe '#css_for_doc' do
27
- let(:html) { Fixtures::HTML.with_css_links(*files) }
28
- let(:doc) { send(adapter, html) }
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
- context 'when HTML contains linked CSS files' do
31
- let(:files) { %w[ stylesheets/base.css stylesheets/font.css ] }
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
- it 'returns the content of both files concatenated' do
34
- allow(Premailer::Rails::CSSHelper).to \
35
- receive(:css_for_url)
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
- expect(css_for_doc(doc)).to eq("content of base.css\ncontent of font.css")
44
- end
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
- context 'when HTML contains ignored links' do
48
- let(:files) { ['ignore.css', 'data-premailer' => 'ignore'] }
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
- it 'ignores links' do
51
- expect(Premailer::Rails::CSSHelper).to_not receive(:css_for_url)
52
- css_for_doc(doc)
53
- end
54
- end
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
- describe '#css_for_url' do
58
- context 'when path is a url' do
59
- it 'loads the CSS at the local path' do
60
- expect_file('public/stylesheets/base.css')
99
+ context 'when Rails asset pipeline is used' do
100
+ before do
101
+ allow(Rails.configuration)
102
+ .to receive(:assets).and_return(double(prefix: '/assets'))
103
+ allow(Rails.configuration)
104
+ .to receive(:relative_url_root).and_return(nil)
105
+ end
61
106
 
62
- css_for_url('http://example.com/stylesheets/base.css?test')
63
- end
107
+ context 'and a precompiled file exists' do
108
+ it 'returns that file' do
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)
64
113
  end
114
+ end
65
115
 
66
- context 'when path is a relative url' do
67
- it 'loads the CSS at the local path' do
68
- expect_file('public/stylesheets/base.css')
69
- css_for_url('/stylesheets/base.css?test')
70
- end
71
- end
116
+ context "when find_sources raises TypeError" do
117
+ let(:response) { 'content of base.css' }
118
+ let(:uri) { URI('http://example.com/assets/base.css') }
72
119
 
73
- context 'when file is cached' do
74
- it 'returns the cached value' do
75
- Premailer::Rails::CSSLoaders::CacheLoader.store(
76
- 'http://example.com/stylesheets/base.css',
77
- 'content of base.css'
78
- )
120
+ it "falls back to Net::HTTP" do
121
+ expect(Rails.application.assets_manifest).to \
122
+ receive(:find_sources)
123
+ .with('base.css')
124
+ .and_raise(TypeError)
79
125
 
80
- expect(css_for_url('http://example.com/stylesheets/base.css')).to \
81
- eq('content of base.css')
82
- end
126
+ allow(Net::HTTP).to \
127
+ receive(:get).with(uri).and_return(response)
128
+ expect(css_for_url('http://example.com/assets/base.css')).to \
129
+ eq(response)
83
130
  end
131
+ end
84
132
 
85
- context 'when in development mode' do
86
- it 'does not return cached values' do
87
- Premailer::Rails::CSSLoaders::CacheLoader.store(
88
- 'http://example.com/stylesheets/base.css',
89
- 'cached content of base.css'
90
- )
91
- content = 'new content of base.css'
92
- expect_file('public/stylesheets/base.css', content)
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
97
- end
133
+ context "when find_sources raises Errno::ENOENT" do
134
+ let(:response) { 'content of base.css' }
135
+ let(:uri) { URI('http://example.com/assets/base.css') }
98
136
 
99
- context 'when Rails asset pipeline is used' do
100
- before do
101
- allow(Rails.configuration)
102
- .to receive(:assets).and_return(double(prefix: '/assets'))
103
- allow(Rails.configuration)
104
- .to receive(:relative_url_root).and_return(nil)
105
- end
137
+ it "falls back to Net::HTTP" do
138
+ expect(Rails.application.assets_manifest).to \
139
+ receive(:find_sources)
140
+ .with('base.css')
141
+ .and_raise(Errno::ENOENT)
106
142
 
107
- context 'and a precompiled file exists' do
108
- it 'returns that file' do
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
114
- end
143
+ allow(Net::HTTP).to \
144
+ receive(:get).with(uri).and_return(response)
145
+ expect(css_for_url('http://example.com/assets/base.css')).to \
146
+ eq(response)
147
+ end
148
+ end
115
149
 
116
- it 'returns the content of the file compiled by Rails' do
117
- expect(Rails.application.assets).to \
118
- receive(:find_asset)
119
- .with('base.css')
120
- .and_return(double(to_s: 'content of base.css'))
150
+ it 'returns the content of the file compiled by Rails' do
151
+ expect(Rails.application.assets_manifest).to \
152
+ receive(:find_sources)
153
+ .with('base.css')
154
+ .and_return(['content of base.css'])
121
155
 
122
- expect(css_for_url('http://example.com/assets/base.css')).to \
123
- eq('content of base.css')
124
- end
156
+ expect(css_for_url('http://example.com/assets/base.css')).to \
157
+ eq('content of base.css')
158
+ end
125
159
 
126
- it 'returns same file when path contains file fingerprint' do
127
- expect(Rails.application.assets).to \
128
- receive(:find_asset)
129
- .with('base.css')
130
- .and_return(double(to_s: 'content of base.css'))
160
+ it 'returns same file when path contains file fingerprint' do
161
+ expect(Rails.application.assets_manifest).to \
162
+ receive(:find_sources)
163
+ .with('base.css')
164
+ .and_return(['content of base.css'])
131
165
 
132
- expect(css_for_url(
133
- 'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
134
- )).to eq('content of base.css')
135
- end
166
+ expect(css_for_url(
167
+ 'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
168
+ )).to eq('content of base.css')
169
+ end
136
170
 
137
- context 'when asset can not be found' do
138
- let(:response) { 'content of base.css' }
139
- let(:path) { '/assets/base-089e35bd5d84297b8d31ad552e433275.css' }
140
- let(:url) { "http://assets.example.com#{path}" }
141
- let(:asset_host) { 'http://assets.example.com' }
171
+ context 'when asset can not be found' do
172
+ let(:response) { 'content of base.css' }
173
+ let(:path) { '/assets/base-089e35bd5d84297b8d31ad552e433275.css' }
174
+ let(:url) { "http://assets.example.com#{path}" }
175
+ let(:asset_host) { 'http://assets.example.com' }
142
176
 
143
- before do
144
- allow(Rails.application.assets).to \
145
- receive(:find_asset).and_return(nil)
177
+ before do
178
+ allow(Rails.application.assets_manifest).to \
179
+ receive(:find_sources).and_return([])
146
180
 
147
- config = double(asset_host: asset_host)
148
- allow(Rails.configuration).to \
149
- receive(:action_controller).and_return(config)
181
+ config = double(asset_host: asset_host)
182
+ allow(Rails.configuration).to \
183
+ receive(:action_controller).and_return(config)
150
184
 
151
- uri_satisfaction = satisfy { |uri| uri.to_s == url }
152
- allow(Net::HTTP).to \
153
- receive(:get).with(uri_satisfaction).and_return(response)
154
- end
185
+ allow(Net::HTTP).to \
186
+ receive(:get).with(URI(url)).and_return(response)
187
+ end
155
188
 
156
- it 'requests the file' do
157
- expect(css_for_url(url)).to eq('content of base.css')
158
- end
189
+ it 'requests the file' do
190
+ expect(css_for_url(url)).to eq('content of base.css')
191
+ end
159
192
 
160
- context 'when file url does not include the host' do
161
- it 'requests the file using the asset host as host' do
162
- expect(css_for_url(path)).to eq('content of base.css')
163
- end
193
+ context 'when file url does not include the host' do
194
+ it 'requests the file using the asset host as host' do
195
+ expect(css_for_url(path)).to eq('content of base.css')
196
+ end
164
197
 
165
- context 'and the asset host uses protocol relative scheme' do
166
- let(:asset_host) { '//assets.example.com' }
198
+ context 'and the asset host uses protocol relative scheme' do
199
+ let(:asset_host) { '//assets.example.com' }
167
200
 
168
- it 'requests the file using http as the scheme' do
169
- expect(css_for_url(path)).to eq('content of base.css')
170
- end
171
- end
201
+ it 'requests the file using http as the scheme' do
202
+ expect(css_for_url(path)).to eq('content of base.css')
172
203
  end
173
204
  end
174
205
  end
206
+ end
207
+ end
175
208
 
176
- context 'when static stylesheets are used' do
177
- it 'returns the content of the static file' do
178
- content = 'content of base.css'
179
- expect_file('public/stylesheets/base.css', content)
180
- loaded_content = css_for_url('http://example.com/stylesheets/base.css')
181
- expect(loaded_content).to eq(content)
182
- end
183
- end
209
+ context 'when static stylesheets are used' do
210
+ it 'returns the content of the static file' do
211
+ content = 'content of base.css'
212
+ expect_file('public/stylesheets/base.css', content)
213
+ loaded_content = css_for_url('http://example.com/stylesheets/base.css')
214
+ expect(loaded_content).to eq(content)
184
215
  end
185
216
  end
186
217
  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
@@ -91,7 +91,7 @@ describe Premailer::Rails::Hook do
91
91
 
92
92
  it 'does not replace any message part' do
93
93
  expect { run_hook(message) }.to_not \
94
- change { message.all_parts.map(&:content_type) }
94
+ change { message.all_parts.map(&:content_type).sort }
95
95
  end
96
96
  end
97
97
 
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,3 @@
1
+ p {
2
+ font-size: 12px;
3
+ }
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,6 @@
1
+ class WelcomeMailer < ApplicationMailer
2
+ def welcome_email(greeting)
3
+ @greeting = greeting
4
+ mail to: "example@example.com"
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <link rel="stylesheet" href="/assets/application.css"/>
6
+ </head>
7
+
8
+ <body>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1 @@
1
+ <p>Hello <%= @greeting %></p>
@@ -0,0 +1,13 @@
1
+ require_relative 'boot'
2
+
3
+ require "action_mailer/railtie"
4
+ require "action_view/railtie"
5
+ require "sprockets/railtie"
6
+ require "rails/test_unit/railtie"
7
+
8
+ Bundler.require(*Rails.groups)
9
+
10
+ module Dummy
11
+ class Application < Rails::Application
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,2 @@
1
+ require_relative 'application'
2
+ Rails.application.initialize!
@@ -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'
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ root 'application#main'
3
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
data/spec/spec_helper.rb CHANGED
@@ -11,12 +11,11 @@ if RUBY_ENGINE == 'ruby'
11
11
  end
12
12
  end
13
13
 
14
- require 'premailer/rails'
14
+ # Configure Rails Environment
15
+ ENV["RAILS_ENV"] = "test"
16
+ require File.expand_path("../../spec/rails_app/config/environment.rb", __FILE__)
15
17
 
16
- require 'support/stubs/action_mailer'
17
- require 'support/stubs/rails'
18
18
  require 'support/fixtures/message'
19
19
  require 'support/fixtures/html'
20
20
 
21
- require 'hpricot' unless RUBY_PLATFORM == 'java'
22
21
  require 'nokogiri'
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Premailer::Rails::CSSLoaders::FileSystemLoader do
4
+ before do
5
+ allow(Rails.configuration)
6
+ .to receive(:assets).and_return(double(prefix: '/assets'))
7
+ allow(Rails)
8
+ .to receive(:root).and_return(Pathname.new('/rails_root'))
9
+ end
10
+
11
+ describe '#file_name' do
12
+ subject { described_class.file_name(asset) }
13
+ let(:relative_url_root) { nil }
14
+
15
+ before do
16
+ config = double(relative_url_root: relative_url_root)
17
+ allow(Rails).to receive(:configuration).and_return(config)
18
+ end
19
+
20
+ context 'when relative_url_root is not set' do
21
+ let(:asset) { '/assets/application.css' }
22
+ it { is_expected.to eq(File.join(Rails.root, 'public/assets/application.css')) }
23
+ end
24
+
25
+ context 'when relative_url_root is set' do
26
+ let(:relative_url_root) { '/foo' }
27
+ let(:asset) { '/foo/assets/application.css' }
28
+ it { is_expected.to eq(File.join(Rails.root, 'public/assets/application.css')) }
29
+ end
30
+
31
+ context 'when relative_url_root has a trailing slash' do
32
+ let(:relative_url_root) { '/foo/' }
33
+ let(:asset) { '/foo/assets/application.css' }
34
+ it { is_expected.to eq(File.join(Rails.root, 'public/assets/application.css')) }
35
+ end
36
+ end
37
+ end
@@ -18,7 +18,7 @@ describe Premailer::Rails::CSSLoaders::NetworkLoader do
18
18
 
19
19
  context 'with a protocol relative URL' do
20
20
  let(:url) { '//example.com/test.css' }
21
- it { is_expected.to eq(URI("http://#{url}")) }
21
+ it { is_expected.to eq(URI("http:#{url}")) }
22
22
  end
23
23
 
24
24
  context 'with a file path' do
@@ -1,51 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Premailer::Rails::CustomizedPremailer do
4
- [ :nokogiri, :hpricot ].each do |adapter|
5
- next if adapter == :hpricot and RUBY_PLATFORM == 'java'
4
+ describe '#to_plain_text' do
5
+ it 'includes the text from the HTML part' do
6
+ premailer =
7
+ Premailer::Rails::CustomizedPremailer
8
+ .new(Fixtures::Message::HTML_PART)
9
+ expect(premailer.to_plain_text.gsub(/\s/, ' ').strip).to \
10
+ eq(Fixtures::Message::TEXT_PART.gsub(/\s/, ' ').strip)
11
+ end
12
+ end
6
13
 
7
- context "when adapter is #{adapter}" do
8
- before { allow(Premailer::Adapter).to receive(:use).and_return(adapter) }
14
+ describe '#to_inline_css' do
15
+ let(:regex) { %r{<p style=("|')color: ?red;?\1>} }
9
16
 
10
- describe '#to_plain_text' do
11
- it 'includes the text from the HTML part' do
12
- premailer =
13
- Premailer::Rails::CustomizedPremailer
14
- .new(Fixtures::Message::HTML_PART)
15
- expect(premailer.to_plain_text.gsub(/\s/, ' ').strip).to \
16
- eq(Fixtures::Message::TEXT_PART.gsub(/\s/, ' ').strip)
17
- end
17
+ context 'when inline CSS block present' do
18
+ it 'returns the HTML with the CSS inlined' do
19
+ allow(Premailer::Rails::CSSHelper).to \
20
+ receive(:css_for_doc).and_return('p { color: red; }')
21
+ html = Fixtures::Message::HTML_PART
22
+ premailer = Premailer::Rails::CustomizedPremailer.new(html)
23
+ expect(premailer.to_inline_css).to match(regex)
18
24
  end
25
+ end
19
26
 
20
- describe '#to_inline_css' do
21
- let(:regex) { %r{<p style=("|')color: ?red;?\1>} }
22
-
23
- context 'when inline CSS block present' do
24
- it 'returns the HTML with the CSS inlined' do
25
- allow(Premailer::Rails::CSSHelper).to \
26
- receive(:css_for_doc).and_return('p { color: red; }')
27
- html = Fixtures::Message::HTML_PART
28
- premailer = Premailer::Rails::CustomizedPremailer.new(html)
29
- expect(premailer.to_inline_css).to match(regex)
30
- end
31
- end
32
-
33
- context 'when CSS is loaded externally' do
34
- it 'returns the HTML with the CSS inlined' do
35
- html = Fixtures::Message::HTML_PART_WITH_CSS
36
- premailer = Premailer::Rails::CustomizedPremailer.new(html)
37
- expect(premailer.to_inline_css).to match(regex)
38
- end
39
- end
27
+ context 'when CSS is loaded externally' do
28
+ it 'returns the HTML with the CSS inlined' do
29
+ html = Fixtures::Message::HTML_PART_WITH_CSS
30
+ premailer = Premailer::Rails::CustomizedPremailer.new(html)
31
+ expect(premailer.to_inline_css).to match(regex)
32
+ end
33
+ end
40
34
 
41
- context 'when HTML contains unicode' do
42
- it 'does not mess those up' do
43
- html = Fixtures::Message::HTML_PART_WITH_UNICODE
44
- premailer = Premailer::Rails::CustomizedPremailer.new(html)
45
- expect(premailer.to_inline_css).to \
46
- include(Fixtures::Message::UNICODE_STRING)
47
- end
48
- end
35
+ context 'when HTML contains unicode' do
36
+ it 'does not mess those up' do
37
+ html = Fixtures::Message::HTML_PART_WITH_UNICODE
38
+ premailer = Premailer::Rails::CustomizedPremailer.new(html)
39
+ expect(premailer.to_inline_css).to \
40
+ include(Fixtures::Message::UNICODE_STRING)
49
41
  end
50
42
  end
51
43
  end