turbo-sprockets-rails3-envaware 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +117 -0
- data/Rakefile +28 -0
- data/lib/sprockets/asset_with_dependencies.rb +134 -0
- data/lib/sprockets/static_non_digest_generator.rb +106 -0
- data/lib/sprockets/unprocessed_asset.rb +39 -0
- data/lib/turbo-sprockets-rails3.rb +15 -0
- data/lib/turbo-sprockets/helpers.rb +9 -0
- data/lib/turbo-sprockets/railtie.rb +26 -0
- data/lib/turbo-sprockets/sprockets_overrides/asset.rb +31 -0
- data/lib/turbo-sprockets/sprockets_overrides/base.rb +38 -0
- data/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb +33 -0
- data/lib/turbo-sprockets/sprockets_overrides/environment.rb +21 -0
- data/lib/turbo-sprockets/sprockets_overrides/index.rb +30 -0
- data/lib/turbo-sprockets/sprockets_overrides/processed_asset.rb +29 -0
- data/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb +94 -0
- data/lib/turbo-sprockets/tasks/assets.rake +204 -0
- data/lib/turbo-sprockets/version.rb +3 -0
- data/test/abstract_unit.rb +143 -0
- data/test/assets_debugging_test.rb +65 -0
- data/test/assets_test.rb +542 -0
- data/test/fixtures/alternate/stylesheets/style.css +1 -0
- data/test/fixtures/app/fonts/dir/font.ttf +0 -0
- data/test/fixtures/app/fonts/font.ttf +0 -0
- data/test/fixtures/app/images/logo.png +0 -0
- data/test/fixtures/app/javascripts/application.js +1 -0
- data/test/fixtures/app/javascripts/dir/xmlhr.js +0 -0
- data/test/fixtures/app/javascripts/extra.js +0 -0
- data/test/fixtures/app/javascripts/foo.min.js +0 -0
- data/test/fixtures/app/javascripts/xmlhr.js +0 -0
- data/test/fixtures/app/stylesheets/application.css +1 -0
- data/test/fixtures/app/stylesheets/dir/style.css +0 -0
- data/test/fixtures/app/stylesheets/extra.css +0 -0
- data/test/fixtures/app/stylesheets/style.css +0 -0
- data/test/fixtures/app/stylesheets/style.ext +0 -0
- data/test/fixtures/app/stylesheets/style.min.css +0 -0
- data/test/sprockets_helper_test.rb +363 -0
- data/test/sprockets_helper_with_routes_test.rb +57 -0
- data/test/sprockets_helpers_abstract_unit.rb +358 -0
- metadata +139 -0
@@ -0,0 +1 @@
|
|
1
|
+
/* Different from other style.css */
|
File without changes
|
File without changes
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require xmlhr
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
/*= require style */
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,363 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/sprockets_helpers_abstract_unit")
|
2
|
+
require 'sprockets'
|
3
|
+
require 'sprockets/helpers/rails_helper'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class SprocketsHelperTest < ActionView::TestCase
|
7
|
+
include Sprockets::Helpers::RailsHelper
|
8
|
+
|
9
|
+
attr_accessor :assets
|
10
|
+
|
11
|
+
class MockRequest
|
12
|
+
def protocol() 'http://' end
|
13
|
+
def ssl?() false end
|
14
|
+
def host_with_port() 'localhost' end
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
super
|
19
|
+
|
20
|
+
@controller = BasicController.new
|
21
|
+
@controller.request = MockRequest.new
|
22
|
+
|
23
|
+
@assets = Sprockets::Environment.new
|
24
|
+
@assets.append_path(FIXTURES.join("app/javascripts"))
|
25
|
+
@assets.append_path(FIXTURES.join("app/stylesheets"))
|
26
|
+
@assets.append_path(FIXTURES.join("app/images"))
|
27
|
+
@assets.append_path(FIXTURES.join("app/fonts"))
|
28
|
+
|
29
|
+
application = Struct.new(:config, :assets).new(config, @assets)
|
30
|
+
Rails.stubs(:application).returns(application)
|
31
|
+
@config = config
|
32
|
+
@config.perform_caching = true
|
33
|
+
@config.assets.digest = true
|
34
|
+
@config.assets.compile = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def url_for(*args)
|
38
|
+
"http://www.example.com"
|
39
|
+
end
|
40
|
+
|
41
|
+
def config
|
42
|
+
@controller ? @controller.config : @config
|
43
|
+
end
|
44
|
+
|
45
|
+
def compute_host(source, request, options = {})
|
46
|
+
raise "Should never get here"
|
47
|
+
end
|
48
|
+
|
49
|
+
test "asset_path" do
|
50
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
51
|
+
asset_path("logo.png")
|
52
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
53
|
+
asset_path("logo.png", :digest => true)
|
54
|
+
assert_match %r{/assets/logo.png},
|
55
|
+
asset_path("logo.png", :digest => false)
|
56
|
+
end
|
57
|
+
|
58
|
+
test "custom_asset_path" do
|
59
|
+
@config.assets.prefix = '/s'
|
60
|
+
assert_match %r{/s/logo-[0-9a-f]+.png},
|
61
|
+
asset_path("logo.png")
|
62
|
+
assert_match %r{/s/logo-[0-9a-f]+.png},
|
63
|
+
asset_path("logo.png", :digest => true)
|
64
|
+
assert_match %r{/s/logo.png},
|
65
|
+
asset_path("logo.png", :digest => false)
|
66
|
+
end
|
67
|
+
|
68
|
+
test "asset_path with root relative assets" do
|
69
|
+
assert_equal "/images/logo",
|
70
|
+
asset_path("/images/logo")
|
71
|
+
assert_equal "/images/logo.gif",
|
72
|
+
asset_path("/images/logo.gif")
|
73
|
+
|
74
|
+
assert_equal "/dir/audio",
|
75
|
+
asset_path("/dir/audio")
|
76
|
+
end
|
77
|
+
|
78
|
+
test "asset_path with absolute urls" do
|
79
|
+
assert_equal "http://www.example.com/video/play",
|
80
|
+
asset_path("http://www.example.com/video/play")
|
81
|
+
assert_equal "http://www.example.com/video/play.mp4",
|
82
|
+
asset_path("http://www.example.com/video/play.mp4")
|
83
|
+
end
|
84
|
+
|
85
|
+
test "with a simple asset host the url should default to protocol relative" do
|
86
|
+
@controller.config.default_asset_host_protocol = :relative
|
87
|
+
@controller.config.asset_host = "assets-%d.example.com"
|
88
|
+
assert_match %r{^//assets-\d.example.com/assets/logo-[0-9a-f]+.png},
|
89
|
+
asset_path("logo.png")
|
90
|
+
end
|
91
|
+
|
92
|
+
test "with a simple asset host the url can be changed to use the request protocol" do
|
93
|
+
@controller.config.asset_host = "assets-%d.example.com"
|
94
|
+
@controller.config.default_asset_host_protocol = :request
|
95
|
+
assert_match %r{http://assets-\d.example.com/assets/logo-[0-9a-f]+.png},
|
96
|
+
asset_path("logo.png")
|
97
|
+
end
|
98
|
+
|
99
|
+
test "With a proc asset host that returns no protocol the url should be protocol relative" do
|
100
|
+
@controller.config.default_asset_host_protocol = :relative
|
101
|
+
@controller.config.asset_host = Proc.new do |asset|
|
102
|
+
"assets-999.example.com"
|
103
|
+
end
|
104
|
+
assert_match %r{^//assets-999.example.com/assets/logo-[0-9a-f]+.png},
|
105
|
+
asset_path("logo.png")
|
106
|
+
end
|
107
|
+
|
108
|
+
test "with a proc asset host that returns a protocol the url use it" do
|
109
|
+
@controller.config.asset_host = Proc.new do |asset|
|
110
|
+
"http://assets-999.example.com"
|
111
|
+
end
|
112
|
+
assert_match %r{http://assets-999.example.com/assets/logo-[0-9a-f]+.png},
|
113
|
+
asset_path("logo.png")
|
114
|
+
end
|
115
|
+
|
116
|
+
test "stylesheets served with a controller in scope can access the request" do
|
117
|
+
config.asset_host = Proc.new do |asset, request|
|
118
|
+
assert_not_nil request
|
119
|
+
"http://assets-666.example.com"
|
120
|
+
end
|
121
|
+
assert_match %r{http://assets-666.example.com/assets/logo-[0-9a-f]+.png},
|
122
|
+
asset_path("logo.png")
|
123
|
+
end
|
124
|
+
|
125
|
+
test "stylesheets served without a controller in scope cannot access the request" do
|
126
|
+
@controller = nil
|
127
|
+
@config.asset_host = Proc.new do |asset, request|
|
128
|
+
fail "This should not have been called."
|
129
|
+
end
|
130
|
+
assert_raises ActionController::RoutingError do
|
131
|
+
asset_path("logo.png")
|
132
|
+
end
|
133
|
+
@config.asset_host = method :compute_host
|
134
|
+
assert_raises ActionController::RoutingError do
|
135
|
+
asset_path("logo.png")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
test "image_tag" do
|
140
|
+
assert_dom_equal '<img alt="Xml" src="/assets/xml.png" />', image_tag("xml.png")
|
141
|
+
end
|
142
|
+
|
143
|
+
test "image_path" do
|
144
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
145
|
+
image_path("logo.png")
|
146
|
+
|
147
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
148
|
+
path_to_image("logo.png")
|
149
|
+
end
|
150
|
+
|
151
|
+
test "font_path" do
|
152
|
+
assert_match %r{/assets/font-[0-9a-f]+.ttf},
|
153
|
+
font_path("font.ttf")
|
154
|
+
|
155
|
+
assert_match %r{/assets/font-[0-9a-f]+.ttf},
|
156
|
+
path_to_font("font.ttf")
|
157
|
+
end
|
158
|
+
|
159
|
+
test "javascript_path" do
|
160
|
+
assert_match %r{/assets/application-[0-9a-f]+.js},
|
161
|
+
javascript_path("application")
|
162
|
+
|
163
|
+
assert_match %r{/assets/application-[0-9a-f]+.js},
|
164
|
+
javascript_path("application.js")
|
165
|
+
|
166
|
+
assert_match %r{/assets/application-[0-9a-f]+.js},
|
167
|
+
path_to_javascript("application.js")
|
168
|
+
end
|
169
|
+
|
170
|
+
test "stylesheet_path" do
|
171
|
+
assert_match %r{/assets/application-[0-9a-f]+.css},
|
172
|
+
stylesheet_path("application")
|
173
|
+
|
174
|
+
assert_match %r{/assets/application-[0-9a-f]+.css},
|
175
|
+
stylesheet_path("application.css")
|
176
|
+
|
177
|
+
assert_match %r{/assets/application-[0-9a-f]+.css},
|
178
|
+
path_to_stylesheet("application.css")
|
179
|
+
end
|
180
|
+
|
181
|
+
test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do
|
182
|
+
@controller = nil
|
183
|
+
@config.asset_host = "assets-%d.example.com"
|
184
|
+
@config.default_asset_host_protocol = :request
|
185
|
+
@config.perform_caching = true
|
186
|
+
|
187
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
188
|
+
asset_path("logo.png")
|
189
|
+
end
|
190
|
+
|
191
|
+
test "asset path with relative url root" do
|
192
|
+
@controller.config.relative_url_root = "/collaboration/hieraki"
|
193
|
+
assert_equal "/collaboration/hieraki/images/logo.gif",
|
194
|
+
asset_path("/images/logo.gif")
|
195
|
+
end
|
196
|
+
|
197
|
+
test "asset path with relative url root when controller isn't present but relative_url_root is" do
|
198
|
+
@controller = nil
|
199
|
+
@config.relative_url_root = "/collaboration/hieraki"
|
200
|
+
assert_equal "/collaboration/hieraki/images/logo.gif",
|
201
|
+
asset_path("/images/logo.gif")
|
202
|
+
end
|
203
|
+
|
204
|
+
test "font path through asset_path" do
|
205
|
+
assert_match %r{/assets/font-[0-9a-f]+.ttf},
|
206
|
+
asset_path('font.ttf')
|
207
|
+
|
208
|
+
assert_match %r{/assets/dir/font-[0-9a-f]+.ttf},
|
209
|
+
asset_path("dir/font.ttf")
|
210
|
+
|
211
|
+
assert_equal "http://www.example.com/fonts/font.ttf",
|
212
|
+
asset_path("http://www.example.com/fonts/font.ttf")
|
213
|
+
end
|
214
|
+
|
215
|
+
test "javascript path through asset_path" do
|
216
|
+
assert_match %r{/assets/application-[0-9a-f]+.js},
|
217
|
+
asset_path(:application, :ext => "js")
|
218
|
+
|
219
|
+
assert_match %r{/assets/xmlhr-[0-9a-f]+.js},
|
220
|
+
asset_path("xmlhr", :ext => "js")
|
221
|
+
assert_match %r{/assets/dir/xmlhr-[0-9a-f]+.js},
|
222
|
+
asset_path("dir/xmlhr.js", :ext => "js")
|
223
|
+
|
224
|
+
assert_equal "/dir/xmlhr.js",
|
225
|
+
asset_path("/dir/xmlhr", :ext => "js")
|
226
|
+
|
227
|
+
assert_equal "http://www.example.com/js/xmlhr",
|
228
|
+
asset_path("http://www.example.com/js/xmlhr", :ext => "js")
|
229
|
+
assert_equal "http://www.example.com/js/xmlhr.js",
|
230
|
+
asset_path("http://www.example.com/js/xmlhr.js", :ext => "js")
|
231
|
+
end
|
232
|
+
|
233
|
+
test "javascript include tag" do
|
234
|
+
assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
|
235
|
+
javascript_include_tag(:application)
|
236
|
+
assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
|
237
|
+
javascript_include_tag(:application, :digest => true)
|
238
|
+
assert_match %r{<script src="/assets/application.js" type="text/javascript"></script>},
|
239
|
+
javascript_include_tag(:application, :digest => false)
|
240
|
+
|
241
|
+
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>},
|
242
|
+
javascript_include_tag("xmlhr")
|
243
|
+
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>},
|
244
|
+
javascript_include_tag("xmlhr.js")
|
245
|
+
assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>',
|
246
|
+
javascript_include_tag("http://www.example.com/xmlhr")
|
247
|
+
|
248
|
+
assert_match %r{<script src=\"/assets/xmlhr-[0-9a-f]+.js" type=\"text/javascript\"></script>\n<script src=\"/assets/extra-[0-9a-f]+.js" type=\"text/javascript\"></script>},
|
249
|
+
javascript_include_tag("xmlhr", "extra")
|
250
|
+
|
251
|
+
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
|
252
|
+
javascript_include_tag(:application, :debug => true)
|
253
|
+
|
254
|
+
assert_match %r{<script src="/assets/jquery.plugin.js" type="text/javascript"></script>},
|
255
|
+
javascript_include_tag('jquery.plugin', :digest => false)
|
256
|
+
|
257
|
+
assert_match %r{\A<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>\Z},
|
258
|
+
javascript_include_tag("xmlhr", "xmlhr")
|
259
|
+
|
260
|
+
assert_match %r{\A<script src="/assets/foo.min-[0-9a-f]+.js" type="text/javascript"></script>\Z},
|
261
|
+
javascript_include_tag("foo.min")
|
262
|
+
|
263
|
+
@config.assets.compile = true
|
264
|
+
@config.assets.debug = true
|
265
|
+
assert_match %r{<script src="/javascripts/application.js" type="text/javascript"></script>},
|
266
|
+
javascript_include_tag('/javascripts/application')
|
267
|
+
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
|
268
|
+
javascript_include_tag(:application)
|
269
|
+
end
|
270
|
+
|
271
|
+
test "stylesheet path through asset_path" do
|
272
|
+
assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, :ext => "css")
|
273
|
+
|
274
|
+
assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
|
275
|
+
assert_match %r{/assets/dir/style-[0-9a-f]+.css}, asset_path("dir/style.css", :ext => "css")
|
276
|
+
assert_equal "/dir/style.css", asset_path("/dir/style.css", :ext => "css")
|
277
|
+
|
278
|
+
assert_equal "http://www.example.com/css/style",
|
279
|
+
asset_path("http://www.example.com/css/style", :ext => "css")
|
280
|
+
assert_equal "http://www.example.com/css/style.css",
|
281
|
+
asset_path("http://www.example.com/css/style.css", :ext => "css")
|
282
|
+
end
|
283
|
+
|
284
|
+
test "stylesheet link tag" do
|
285
|
+
assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
|
286
|
+
stylesheet_link_tag(:application)
|
287
|
+
assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
|
288
|
+
stylesheet_link_tag(:application, :digest => true)
|
289
|
+
assert_match %r{<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />},
|
290
|
+
stylesheet_link_tag(:application, :digest => false)
|
291
|
+
|
292
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
|
293
|
+
stylesheet_link_tag("style")
|
294
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
|
295
|
+
stylesheet_link_tag("style.css")
|
296
|
+
|
297
|
+
assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
|
298
|
+
stylesheet_link_tag("http://www.example.com/style.css")
|
299
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="all" rel="stylesheet" type="text/css" />},
|
300
|
+
stylesheet_link_tag("style", :media => "all")
|
301
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="print" rel="stylesheet" type="text/css" />},
|
302
|
+
stylesheet_link_tag("style", :media => "print")
|
303
|
+
|
304
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/extra-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
|
305
|
+
stylesheet_link_tag("style", "extra")
|
306
|
+
|
307
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
|
308
|
+
stylesheet_link_tag(:application, :debug => true)
|
309
|
+
|
310
|
+
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
|
311
|
+
stylesheet_link_tag("style", "style")
|
312
|
+
|
313
|
+
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.ext" media="screen" rel="stylesheet" type="text/css" />\Z},
|
314
|
+
stylesheet_link_tag("style.ext")
|
315
|
+
|
316
|
+
assert_match %r{\A<link href="/assets/style.min-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
|
317
|
+
stylesheet_link_tag("style.min")
|
318
|
+
|
319
|
+
@config.assets.compile = true
|
320
|
+
@config.assets.debug = true
|
321
|
+
assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />},
|
322
|
+
stylesheet_link_tag('/stylesheets/application')
|
323
|
+
|
324
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
|
325
|
+
stylesheet_link_tag(:application)
|
326
|
+
|
327
|
+
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="print" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="print" rel="stylesheet" type="text/css" />},
|
328
|
+
stylesheet_link_tag(:application, :media => "print")
|
329
|
+
end
|
330
|
+
|
331
|
+
test "alternate asset prefix" do
|
332
|
+
stubs(:asset_prefix).returns("/themes/test")
|
333
|
+
assert_match %r{/themes/test/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
|
334
|
+
end
|
335
|
+
|
336
|
+
test "alternate asset environment" do
|
337
|
+
assets = Sprockets::Environment.new
|
338
|
+
assets.append_path(FIXTURES.join("alternate/stylesheets"))
|
339
|
+
stubs(:asset_environment).returns(assets)
|
340
|
+
assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
|
341
|
+
end
|
342
|
+
|
343
|
+
test "alternate hash based on environment" do
|
344
|
+
assets = Sprockets::Environment.new
|
345
|
+
assets.version = 'development'
|
346
|
+
assets.append_path(FIXTURES.join("alternate/stylesheets"))
|
347
|
+
stubs(:asset_environment).returns(assets)
|
348
|
+
dev_path = asset_path("style", :ext => "css")
|
349
|
+
|
350
|
+
assets.version = 'production'
|
351
|
+
prod_path = asset_path("style", :ext => "css")
|
352
|
+
|
353
|
+
assert_not_equal prod_path, dev_path
|
354
|
+
end
|
355
|
+
|
356
|
+
test "precedence of `config.digest = false` over manifest.yml asset digests" do
|
357
|
+
Rails.application.config.assets.digests = {'logo.png' => 'logo-d1g3st.png'}
|
358
|
+
@config.assets.digest = false
|
359
|
+
|
360
|
+
assert_equal '/assets/logo.png',
|
361
|
+
asset_path("logo.png")
|
362
|
+
end
|
363
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/sprockets_helpers_abstract_unit")
|
2
|
+
require 'sprockets'
|
3
|
+
require 'sprockets/helpers/rails_helper'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class SprocketsHelperWithRoutesTest < ActionView::TestCase
|
7
|
+
include Sprockets::Helpers::RailsHelper
|
8
|
+
|
9
|
+
# Let's bring in some named routes to test namespace conflicts with potential *_paths.
|
10
|
+
# We have to do this after we bring in the Sprockets RailsHelper so if there are conflicts,
|
11
|
+
# they'll fail in the way we expect in a real live Rails app.
|
12
|
+
routes = ActionDispatch::Routing::RouteSet.new
|
13
|
+
routes.draw do
|
14
|
+
resources :assets
|
15
|
+
end
|
16
|
+
include routes.url_helpers
|
17
|
+
|
18
|
+
def setup
|
19
|
+
super
|
20
|
+
@controller = BasicController.new
|
21
|
+
|
22
|
+
@assets = Sprockets::Environment.new
|
23
|
+
@assets.append_path(FIXTURES.join("app/javascripts"))
|
24
|
+
@assets.append_path(FIXTURES.join("app/stylesheets"))
|
25
|
+
@assets.append_path(FIXTURES.join("app/images"))
|
26
|
+
|
27
|
+
application = Struct.new(:config, :assets).new(config, @assets)
|
28
|
+
Rails.stubs(:application).returns(application)
|
29
|
+
@config = config
|
30
|
+
@config.perform_caching = true
|
31
|
+
@config.assets.digest = true
|
32
|
+
@config.assets.compile = true
|
33
|
+
end
|
34
|
+
|
35
|
+
test "namespace conflicts on a named route called asset_path" do
|
36
|
+
# Testing this for sanity - asset_path is now a named route!
|
37
|
+
assert_match asset_path('test_asset'), '/assets/test_asset'
|
38
|
+
|
39
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
40
|
+
path_to_asset("logo.png")
|
41
|
+
assert_match %r{/assets/logo-[0-9a-f]+.png},
|
42
|
+
path_to_asset("logo.png", :digest => true)
|
43
|
+
assert_match %r{/assets/logo.png},
|
44
|
+
path_to_asset("logo.png", :digest => false)
|
45
|
+
end
|
46
|
+
|
47
|
+
test "javascript_include_tag with a named_route named asset_path" do
|
48
|
+
assert_match %r{<script src="/assets/application-[0-9a-f]+.js" type="text/javascript"></script>},
|
49
|
+
javascript_include_tag(:application)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "stylesheet_link_tag with a named_route named asset_path" do
|
53
|
+
assert_match %r{<link href="/assets/application-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />},
|
54
|
+
stylesheet_link_tag(:application)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|