premailer-rails 1.11.0 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +64 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +13 -13
- data/README.md +11 -9
- data/VERSION +1 -1
- data/{example → examples/rails5}/.gitignore +0 -0
- data/examples/rails5/Gemfile +4 -0
- data/{example → examples/rails5}/README.md +0 -0
- data/{example → examples/rails5}/Rakefile +1 -1
- 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}/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/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}/config.ru +2 -1
- data/{example → examples/rails5}/test/mailers/previews/example_mailer_preview.rb +0 -0
- 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 +2 -0
- data/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb +5 -4
- data/lib/premailer/rails/css_loaders/network_loader.rb +1 -1
- data/lib/premailer/rails/css_loaders/propshaft_loader.rb +38 -0
- data/lib/premailer/rails/css_loaders.rb +1 -0
- data/lib/premailer/rails/railtie.rb +1 -1
- data/lib/premailer/rails.rb +1 -1
- data/premailer-rails.gemspec +3 -1
- data/spec/integration/css_helper_spec.rb +173 -71
- data/spec/rails_app/config/application.rb +7 -1
- data/spec/spec_helper.rb +0 -13
- data/spec/unit/css_loaders/asset_pipeline_loader_spec.rb +44 -32
- data/spec/unit/css_loaders/propshaft_loader_spec.rb +57 -0
- metadata +91 -56
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -16
- data/example/Gemfile +0 -10
- data/example/config/boot.rb +0 -3
- data/example/config/secrets.yml +0 -2
@@ -0,0 +1,16 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link email.css
|
@@ -0,0 +1,32 @@
|
|
1
|
+
body {
|
2
|
+
background: #efefef;
|
3
|
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
4
|
+
}
|
5
|
+
|
6
|
+
p {
|
7
|
+
line-height: 1.4;
|
8
|
+
}
|
9
|
+
|
10
|
+
.wrap {
|
11
|
+
max-width: 40em;
|
12
|
+
margin: 0 auto;
|
13
|
+
padding: 1em;
|
14
|
+
background: white;
|
15
|
+
}
|
16
|
+
|
17
|
+
.greeting {
|
18
|
+
text-align: center;
|
19
|
+
font-weight: bold;
|
20
|
+
font-size: 110%;
|
21
|
+
}
|
22
|
+
|
23
|
+
.footer {
|
24
|
+
font-size: 90%;
|
25
|
+
color: #666;
|
26
|
+
}
|
27
|
+
|
28
|
+
a {
|
29
|
+
color: green;
|
30
|
+
text-decoration: none;
|
31
|
+
border-bottom: 2px solid green;
|
32
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset='utf-8'>
|
5
|
+
<%= stylesheet_link_tag :email %>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<div class='wrap'>
|
9
|
+
<p class='greeting'>Hi, John Doe</p>
|
10
|
+
<p>
|
11
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
12
|
+
</p>
|
13
|
+
<div class='footer'>
|
14
|
+
To unsubscribe, <a href='http://www.google.com/'>click here</a>.
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require 'action_mailer/railtie'
|
5
|
+
|
6
|
+
# Require the gems listed in Gemfile, including any gems
|
7
|
+
# you've limited to :test, :development, or :production.
|
8
|
+
Bundler.require(*Rails.groups)
|
9
|
+
|
10
|
+
module Example
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.load_defaults 7.0
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = false
|
3
|
+
config.eager_load = false
|
4
|
+
config.consider_all_requests_local = true
|
5
|
+
config.action_controller.perform_caching = false
|
6
|
+
config.assets.debug = true
|
7
|
+
config.assets.digest = true
|
8
|
+
config.assets.raise_runtime_errors = true
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
config.eager_load = true
|
4
|
+
config.consider_all_requests_local = false
|
5
|
+
config.action_controller.perform_caching = true
|
6
|
+
config.assets.compile = false
|
7
|
+
config.assets.digest = true
|
8
|
+
config.log_level = :info
|
9
|
+
end
|
@@ -13,11 +13,11 @@ class Premailer
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def file_name(url)
|
16
|
-
prefix =
|
17
|
-
::Rails.configuration.relative_url_root,
|
18
|
-
::Rails.configuration.assets.prefix,
|
16
|
+
prefix = File.join(
|
17
|
+
::Rails.configuration.relative_url_root.to_s,
|
18
|
+
::Rails.configuration.assets.prefix.to_s,
|
19
19
|
'/'
|
20
|
-
|
20
|
+
)
|
21
21
|
URI(url).path
|
22
22
|
.sub(/\A#{prefix}/, '')
|
23
23
|
.sub(/-(\h{32}|\h{64})\.css\z/, '.css')
|
@@ -25,6 +25,7 @@ class Premailer
|
|
25
25
|
|
26
26
|
def asset_pipeline_present?
|
27
27
|
defined?(::Rails) &&
|
28
|
+
::Rails.respond_to?(:application) &&
|
28
29
|
::Rails.application &&
|
29
30
|
::Rails.application.respond_to?(:assets_manifest) &&
|
30
31
|
::Rails.application.assets_manifest
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Premailer
|
2
|
+
module Rails
|
3
|
+
module CSSLoaders
|
4
|
+
module PropshaftLoader
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def load(url)
|
8
|
+
return unless propshaft_present?
|
9
|
+
|
10
|
+
file = file_name(url)
|
11
|
+
asset = ::Rails.application.assets.load_path.find(file)
|
12
|
+
|
13
|
+
::Rails.application.assets.compilers.compile(asset) if asset
|
14
|
+
end
|
15
|
+
|
16
|
+
def file_name(url)
|
17
|
+
prefix = File.join(
|
18
|
+
::Rails.configuration.relative_url_root.to_s,
|
19
|
+
::Rails.configuration.assets.prefix.to_s,
|
20
|
+
'/'
|
21
|
+
)
|
22
|
+
|
23
|
+
# Path extraction logic from Propshaft.
|
24
|
+
# See https://github.com/rails/propshaft/blob/390381548b125e8721c8aef1b9d894b7cc8bd868/lib/propshaft/server.rb#L35-L41
|
25
|
+
full_path = URI(url).path.sub(/\A#{prefix}/, '')
|
26
|
+
digest = full_path[/-([0-9a-zA-Z]{7,128}(?:\.digested)?)\.[^.]+\z/, 1]
|
27
|
+
path = digest ? full_path.sub("-#{digest}", "") : full_path
|
28
|
+
|
29
|
+
path
|
30
|
+
end
|
31
|
+
|
32
|
+
def propshaft_present?
|
33
|
+
defined?(::Propshaft) && defined?(::Rails)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/premailer/rails.rb
CHANGED
data/premailer-rails.gemspec
CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
include a CSS file as you do in a normal HTML document and
|
17
17
|
premailer will inline the included CSS.}
|
18
18
|
|
19
|
+
s.metadata["changelog_uri"] = "https://github.com/fphilipe/premailer-rails/blob/v#{Premailer::Rails::VERSION}/CHANGELOG.md"
|
20
|
+
|
19
21
|
s.files = `git ls-files`.split("\n")
|
20
22
|
s.test_files = `git ls-files -- {example,spec}/*`.split("\n")
|
21
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -23,8 +25,8 @@ Gem::Specification.new do |s|
|
|
23
25
|
|
24
26
|
s.add_dependency 'premailer', '~> 1.7', '>= 1.7.9'
|
25
27
|
s.add_dependency 'actionmailer', '>= 3'
|
28
|
+
s.add_dependency 'net-smtp' if RUBY_VERSION >= '3'
|
26
29
|
|
27
30
|
s.add_development_dependency 'rspec', '~> 3.3'
|
28
31
|
s.add_development_dependency 'nokogiri'
|
29
|
-
s.add_development_dependency 'coveralls' if RUBY_ENGINE == 'ruby'
|
30
32
|
end
|
@@ -96,111 +96,213 @@ describe Premailer::Rails::CSSHelper do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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)
|
114
|
+
end
|
113
115
|
end
|
114
|
-
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
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)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
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)
|
145
|
+
|
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)
|
152
|
+
end
|
153
|
+
end
|
119
154
|
|
120
|
-
it
|
155
|
+
it 'returns the content of the file compiled by Rails' do
|
121
156
|
expect(Rails.application.assets_manifest).to \
|
122
157
|
receive(:find_sources)
|
123
158
|
.with('base.css')
|
124
|
-
.
|
159
|
+
.and_return(['content of base.css'])
|
125
160
|
|
126
|
-
allow(Net::HTTP).to \
|
127
|
-
receive(:get).with(uri).and_return(response)
|
128
161
|
expect(css_for_url('http://example.com/assets/base.css')).to \
|
129
|
-
eq(
|
162
|
+
eq('content of base.css')
|
130
163
|
end
|
131
|
-
end
|
132
|
-
|
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') }
|
136
164
|
|
137
|
-
it
|
165
|
+
it 'returns same file when path contains file fingerprint' do
|
138
166
|
expect(Rails.application.assets_manifest).to \
|
139
167
|
receive(:find_sources)
|
140
168
|
.with('base.css')
|
141
|
-
.
|
169
|
+
.and_return(['content of base.css'])
|
142
170
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
eq(response)
|
171
|
+
expect(css_for_url(
|
172
|
+
'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
|
173
|
+
)).to eq('content of base.css')
|
147
174
|
end
|
148
|
-
end
|
149
175
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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' }
|
155
181
|
|
156
|
-
|
157
|
-
|
158
|
-
|
182
|
+
before do
|
183
|
+
allow(Rails.application.assets_manifest).to \
|
184
|
+
receive(:find_sources).and_return([])
|
159
185
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
.with('base.css')
|
164
|
-
.and_return(['content of base.css'])
|
186
|
+
config = double(asset_host: asset_host)
|
187
|
+
allow(Rails.configuration).to \
|
188
|
+
receive(:action_controller).and_return(config)
|
165
189
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
190
|
+
allow(Net::HTTP).to \
|
191
|
+
receive(:get)
|
192
|
+
.with(URI(url), { 'Accept' => 'text/css' })
|
193
|
+
.and_return(response)
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'requests the file' do
|
197
|
+
expect(css_for_url(url)).to eq('content of base.css')
|
198
|
+
end
|
170
199
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
let(:asset_host) { 'http://assets.example.com' }
|
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
|
176
204
|
|
205
|
+
context 'and the asset host uses protocol relative scheme' do
|
206
|
+
let(:asset_host) { '//assets.example.com' }
|
207
|
+
|
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
|
177
217
|
before do
|
178
|
-
allow(Rails.
|
179
|
-
receive(:
|
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
|
223
|
+
|
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)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'returns the content of the file compiled by Propshaft' do
|
234
|
+
asset = double()
|
235
|
+
|
236
|
+
expect(Rails.application.assets.load_path).to \
|
237
|
+
receive(:find)
|
238
|
+
.with('base.css')
|
239
|
+
.and_return(asset)
|
180
240
|
|
181
|
-
|
182
|
-
|
183
|
-
|
241
|
+
expect(Rails.application.assets.compilers).to \
|
242
|
+
receive(:compile)
|
243
|
+
.with(asset)
|
244
|
+
.and_return('content of base.css')
|
184
245
|
|
185
|
-
|
186
|
-
|
246
|
+
expect(css_for_url('http://example.com/assets/base.css')).to \
|
247
|
+
eq('content of base.css')
|
187
248
|
end
|
188
249
|
|
189
|
-
it '
|
190
|
-
|
250
|
+
it 'returns same file when path contains file fingerprint' do
|
251
|
+
asset = double()
|
252
|
+
|
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')
|
191
266
|
end
|
192
267
|
|
193
|
-
context 'when
|
194
|
-
|
195
|
-
|
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)
|
196
288
|
end
|
197
289
|
|
198
|
-
|
199
|
-
|
290
|
+
it 'requests the file' do
|
291
|
+
expect(css_for_url(url)).to eq('content of base.css')
|
292
|
+
end
|
200
293
|
|
201
|
-
|
294
|
+
context 'when file url does not include the host' do
|
295
|
+
it 'requests the file using the asset host as host' do
|
202
296
|
expect(css_for_url(path)).to eq('content of base.css')
|
203
297
|
end
|
298
|
+
|
299
|
+
context 'and the asset host uses protocol relative scheme' do
|
300
|
+
let(:asset_host) { '//assets.example.com' }
|
301
|
+
|
302
|
+
it 'requests the file using http as the scheme' do
|
303
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
304
|
+
end
|
305
|
+
end
|
204
306
|
end
|
205
307
|
end
|
206
308
|
end
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require_relative 'boot'
|
2
2
|
|
3
|
+
require "action_controller/railtie"
|
3
4
|
require "action_mailer/railtie"
|
4
5
|
require "action_view/railtie"
|
5
|
-
|
6
|
+
|
7
|
+
begin
|
8
|
+
require "sprockets/railtie"
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
|
6
12
|
require "rails/test_unit/railtie"
|
7
13
|
|
8
14
|
Bundler.require(*Rails.groups)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
if RUBY_ENGINE == 'ruby'
|
2
|
-
if ENV['CI']
|
3
|
-
require 'coveralls'
|
4
|
-
Coveralls::Output.silent = true
|
5
|
-
Coveralls.wear! do
|
6
|
-
add_filter 'spec/'
|
7
|
-
end
|
8
|
-
else
|
9
|
-
require 'simplecov'
|
10
|
-
SimpleCov.start
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
1
|
# Configure Rails Environment
|
15
2
|
ENV["RAILS_ENV"] = "test"
|
16
3
|
require File.expand_path("../../spec/rails_app/config/environment.rb", __FILE__)
|