ghazel-erubis_rails_helper 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/README.rdoc +66 -0
  2. data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
  3. data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
  4. data/lib/erubis_rails_helper.rb +20 -0
  5. data/test/abstract_unit.rb +51 -0
  6. data/test/controller/action_pack_assertions_test.rb +516 -0
  7. data/test/controller/addresses_render_test.rb +37 -0
  8. data/test/controller/assert_select_test.rb +734 -0
  9. data/test/controller/base_test.rb +217 -0
  10. data/test/controller/benchmark_test.rb +32 -0
  11. data/test/controller/caching_test.rb +690 -0
  12. data/test/controller/capture_test.rb +66 -0
  13. data/test/controller/content_type_test.rb +168 -0
  14. data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
  15. data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
  16. data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
  17. data/test/controller/cookie_test.rb +111 -0
  18. data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
  19. data/test/controller/dispatcher_test.rb +103 -0
  20. data/test/controller/fake_controllers.rb +33 -0
  21. data/test/controller/fake_models.rb +19 -0
  22. data/test/controller/filter_params_test.rb +49 -0
  23. data/test/controller/filters_test.rb +885 -0
  24. data/test/controller/flash_test.rb +142 -0
  25. data/test/controller/header_test.rb +14 -0
  26. data/test/controller/helper_test.rb +224 -0
  27. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  28. data/test/controller/html-scanner/document_test.rb +148 -0
  29. data/test/controller/html-scanner/node_test.rb +89 -0
  30. data/test/controller/html-scanner/sanitizer_test.rb +273 -0
  31. data/test/controller/html-scanner/tag_node_test.rb +238 -0
  32. data/test/controller/html-scanner/text_node_test.rb +50 -0
  33. data/test/controller/html-scanner/tokenizer_test.rb +131 -0
  34. data/test/controller/http_basic_authentication_test.rb +88 -0
  35. data/test/controller/http_digest_authentication_test.rb +178 -0
  36. data/test/controller/integration_test.rb +417 -0
  37. data/test/controller/layout_test.rb +204 -0
  38. data/test/controller/logging_test.rb +46 -0
  39. data/test/controller/middleware_stack_test.rb +90 -0
  40. data/test/controller/mime_responds_test.rb +536 -0
  41. data/test/controller/mime_type_test.rb +93 -0
  42. data/test/controller/polymorphic_routes_test.rb +293 -0
  43. data/test/controller/rack_test.rb +294 -0
  44. data/test/controller/record_identifier_test.rb +139 -0
  45. data/test/controller/redirect_test.rb +282 -0
  46. data/test/controller/render_test.rb +1752 -0
  47. data/test/controller/request/json_params_parsing_test.rb +45 -0
  48. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  49. data/test/controller/request/query_string_parsing_test.rb +120 -0
  50. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  51. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  52. data/test/controller/request_forgery_protection_test.rb +246 -0
  53. data/test/controller/request_test.rb +407 -0
  54. data/test/controller/rescue_test.rb +536 -0
  55. data/test/controller/resources_test.rb +1341 -0
  56. data/test/controller/routing_test.rb +2557 -0
  57. data/test/controller/selector_test.rb +628 -0
  58. data/test/controller/send_file_test.rb +161 -0
  59. data/test/controller/session/cookie_store_test.rb +239 -0
  60. data/test/controller/session/mem_cache_store_test.rb +127 -0
  61. data/test/controller/session/test_session_test.rb +58 -0
  62. data/test/controller/test_test.rb +692 -0
  63. data/test/controller/translation_test.rb +26 -0
  64. data/test/controller/url_rewriter_test.rb +359 -0
  65. data/test/controller/verification_test.rb +270 -0
  66. data/test/controller/view_paths_test.rb +141 -0
  67. data/test/controller/webservice_test.rb +260 -0
  68. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  69. data/test/fixtures/company.rb +10 -0
  70. data/test/fixtures/developer.rb +9 -0
  71. data/test/fixtures/helpers/abc_helper.rb +5 -0
  72. data/test/fixtures/helpers/fun/games_helper.rb +3 -0
  73. data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
  74. data/test/fixtures/mascot.rb +3 -0
  75. data/test/fixtures/project.rb +3 -0
  76. data/test/fixtures/reply.rb +7 -0
  77. data/test/fixtures/topic.rb +3 -0
  78. data/test/template/asset_tag_helper_test.rb +713 -0
  79. data/test/template/atom_feed_helper_test.rb +286 -0
  80. data/test/template/benchmark_helper_test.rb +86 -0
  81. data/test/template/compiled_templates_test.rb +203 -0
  82. data/test/template/date_helper_i18n_test.rb +120 -0
  83. data/test/template/date_helper_test.rb +2469 -0
  84. data/test/template/erb_util_test.rb +24 -0
  85. data/test/template/form_helper_test.rb +1176 -0
  86. data/test/template/form_options_helper_test.rb +751 -0
  87. data/test/template/form_tag_helper_test.rb +327 -0
  88. data/test/template/javascript_helper_test.rb +106 -0
  89. data/test/template/number_helper_i18n_test.rb +69 -0
  90. data/test/template/number_helper_test.rb +128 -0
  91. data/test/template/prototype_helper_test.rb +639 -0
  92. data/test/template/record_tag_helper_test.rb +58 -0
  93. data/test/template/render_test.rb +291 -0
  94. data/test/template/sanitize_helper_test.rb +48 -0
  95. data/test/template/scriptaculous_helper_test.rb +90 -0
  96. data/test/template/tag_helper_test.rb +97 -0
  97. data/test/template/test_test.rb +54 -0
  98. data/test/template/text_helper_test.rb +520 -0
  99. data/test/template/translation_helper_test.rb +32 -0
  100. data/test/template/url_helper_test.rb +614 -0
  101. data/test/test_erubis_rails_helper.rb +4 -0
  102. data/test/testing_sandbox.rb +15 -0
  103. data/test/view/test_case_test.rb +8 -0
  104. metadata +174 -0
@@ -0,0 +1,713 @@
1
+ require 'abstract_unit'
2
+
3
+ class AssetTagHelperTest < ActionView::TestCase
4
+ tests ActionView::Helpers::AssetTagHelper
5
+
6
+ def setup
7
+ silence_warnings do
8
+ ActionView::Helpers::AssetTagHelper.send(
9
+ :const_set,
10
+ :JAVASCRIPTS_DIR,
11
+ File.dirname(__FILE__) + "/../fixtures/public/javascripts"
12
+ )
13
+
14
+ ActionView::Helpers::AssetTagHelper.send(
15
+ :const_set,
16
+ :STYLESHEETS_DIR,
17
+ File.dirname(__FILE__) + "/../fixtures/public/stylesheets"
18
+ )
19
+
20
+ ActionView::Helpers::AssetTagHelper.send(
21
+ :const_set,
22
+ :ASSETS_DIR,
23
+ File.dirname(__FILE__) + "/../fixtures/public"
24
+ )
25
+ end
26
+
27
+ @controller = Class.new do
28
+ attr_accessor :request
29
+ def url_for(*args) "http://www.example.com" end
30
+ end.new
31
+
32
+ @request = Class.new do
33
+ def protocol() 'http://' end
34
+ def ssl?() false end
35
+ def host_with_port() 'localhost' end
36
+ end.new
37
+
38
+ @controller.request = @request
39
+
40
+ ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
41
+ end
42
+
43
+ def teardown
44
+ ActionController::Base.perform_caching = false
45
+ ActionController::Base.asset_host = nil
46
+ ENV.delete('RAILS_ASSET_ID')
47
+ end
48
+
49
+ AutoDiscoveryToTag = {
50
+ %(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
51
+ %(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
52
+ %(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
53
+ %(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />),
54
+ %(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
55
+ %(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
56
+ %(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
57
+ %(auto_discovery_link_tag(:rss, {}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
58
+ %(auto_discovery_link_tag(nil, {}, {:type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="" type="text/html" />),
59
+ %(auto_discovery_link_tag(nil, {}, {:title => "No stream.. really", :type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="No stream.. really" type="text/html" />),
60
+ %(auto_discovery_link_tag(:rss, {}, {:title => "My RSS", :type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="text/html" />),
61
+ %(auto_discovery_link_tag(:atom, {}, {:rel => "Not so alternate"})) => %(<link href="http://www.example.com" rel="Not so alternate" title="ATOM" type="application/atom+xml" />),
62
+ }
63
+
64
+ JavascriptPathToTag = {
65
+ %(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js),
66
+ %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
67
+ %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
68
+ }
69
+
70
+ PathToJavascriptToTag = {
71
+ %(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js),
72
+ %(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
73
+ %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js)
74
+ }
75
+
76
+ JavascriptIncludeToTag = {
77
+ %(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
78
+ %(javascript_include_tag("xmlhr.js")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
79
+ %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
80
+ %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
81
+ %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
82
+ %(javascript_include_tag(:all)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
83
+ %(javascript_include_tag(:all, :recursive => true)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
84
+ %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
85
+ %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
86
+ }
87
+
88
+ StylePathToTag = {
89
+ %(stylesheet_path("style")) => %(/stylesheets/style.css),
90
+ %(stylesheet_path("style.css")) => %(/stylesheets/style.css),
91
+ %(stylesheet_path('dir/file')) => %(/stylesheets/dir/file.css),
92
+ %(stylesheet_path('/dir/file.rcss')) => %(/dir/file.rcss)
93
+ }
94
+
95
+ PathToStyleToTag = {
96
+ %(path_to_stylesheet("style")) => %(/stylesheets/style.css),
97
+ %(path_to_stylesheet("style.css")) => %(/stylesheets/style.css),
98
+ %(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css),
99
+ %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss)
100
+ }
101
+
102
+ StyleLinkToTag = {
103
+ %(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
104
+ %(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
105
+ %(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
106
+ %(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
107
+ %(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />),
108
+ %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
109
+ %(stylesheet_link_tag(:all, :recursive => true)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
110
+ %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="all" rel="stylesheet" type="text/css" />),
111
+ %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />),
112
+ %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
113
+ }
114
+
115
+ ImagePathToTag = {
116
+ %(image_path("xml")) => %(/images/xml),
117
+ %(image_path("xml.png")) => %(/images/xml.png),
118
+ %(image_path("dir/xml.png")) => %(/images/dir/xml.png),
119
+ %(image_path("/dir/xml.png")) => %(/dir/xml.png)
120
+ }
121
+
122
+ PathToImageToTag = {
123
+ %(path_to_image("xml")) => %(/images/xml),
124
+ %(path_to_image("xml.png")) => %(/images/xml.png),
125
+ %(path_to_image("dir/xml.png")) => %(/images/dir/xml.png),
126
+ %(path_to_image("/dir/xml.png")) => %(/dir/xml.png)
127
+ }
128
+
129
+ ImageLinkToTag = {
130
+ %(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
131
+ %(image_tag("..jpg")) => %(<img alt="" src="/images/..jpg" />),
132
+ %(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
133
+ %(image_tag("gold.png", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
134
+ %(image_tag("gold.png", "size" => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
135
+ %(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />),
136
+ %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />),
137
+ %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />),
138
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
139
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
140
+ %(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
141
+ %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />)
142
+ }
143
+
144
+
145
+ def test_auto_discovery_link_tag
146
+ AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
147
+ end
148
+
149
+ def test_javascript_path
150
+ JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
151
+ end
152
+
153
+ def test_path_to_javascript_alias_for_javascript_path
154
+ PathToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
155
+ end
156
+
157
+ def test_javascript_include_tag_with_blank_asset_id
158
+ ENV["RAILS_ASSET_ID"] = ""
159
+ JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
160
+ end
161
+
162
+ def test_javascript_include_tag_with_given_asset_id
163
+ ENV["RAILS_ASSET_ID"] = "1"
164
+ assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>), javascript_include_tag(:defaults))
165
+ end
166
+
167
+ def test_register_javascript_include_default
168
+ ENV["RAILS_ASSET_ID"] = ""
169
+ ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'slider'
170
+ assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
171
+ end
172
+
173
+ def test_register_javascript_include_default_mixed_defaults
174
+ ENV["RAILS_ASSET_ID"] = ""
175
+ ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'slider'
176
+ ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2'
177
+ assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
178
+ end
179
+
180
+ def test_custom_javascript_expansions
181
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"]
182
+ assert_dom_equal %(<script src="/javascripts/first.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>), javascript_include_tag('first', :monkey, 'last')
183
+ end
184
+
185
+ def test_custom_javascript_expansions_and_defaults_puts_application_js_at_the_end
186
+ ENV["RAILS_ASSET_ID"] = ""
187
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"]
188
+ assert_dom_equal %(<script src="/javascripts/first.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag('first', :defaults, :monkey, 'last')
189
+ end
190
+
191
+ def test_custom_javascript_expansions_with_undefined_symbol
192
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => nil
193
+ assert_raise(ArgumentError) { javascript_include_tag('first', :monkey, 'last') }
194
+ end
195
+
196
+ def test_stylesheet_path
197
+ StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
198
+ end
199
+
200
+ def test_path_to_stylesheet_alias_for_stylesheet_path
201
+ PathToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
202
+ end
203
+
204
+ def test_stylesheet_link_tag
205
+ ENV["RAILS_ASSET_ID"] = ""
206
+ StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
207
+ end
208
+
209
+ def test_custom_stylesheet_expansions
210
+ ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => ["head", "body", "tail"]
211
+ assert_dom_equal %(<link href="/stylesheets/first.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/head.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/body.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/tail.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/last.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag('first', :monkey, 'last')
212
+ end
213
+
214
+ def test_custom_stylesheet_expansions_with_undefined_symbol
215
+ ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => nil
216
+ assert_raise(ArgumentError) { stylesheet_link_tag('first', :monkey, 'last') }
217
+ end
218
+
219
+ def test_image_path
220
+ ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
221
+ end
222
+
223
+ def test_path_to_image_alias_for_image_path
224
+ PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
225
+ end
226
+
227
+ def test_image_tag
228
+ ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
229
+ end
230
+
231
+ def test_image_tag_windows_behaviour
232
+ old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1"
233
+ # This simulates the behaviour of File#exist? on windows when testing a file ending in "."
234
+ # If the file "rails.png" exists, windows will return true when asked if "rails.png." exists (notice trailing ".")
235
+ # OS X, linux etc will return false in this case.
236
+ File.stubs(:exist?).with('template/../fixtures/public/images/rails.png.').returns(true)
237
+ assert_equal '<img alt="Rails" src="/images/rails.png?1" />', image_tag('rails.png')
238
+ ensure
239
+ if old_asset_id
240
+ ENV["RAILS_ASSET_ID"] = old_asset_id
241
+ else
242
+ ENV.delete("RAILS_ASSET_ID")
243
+ end
244
+ end
245
+
246
+ def test_timebased_asset_id
247
+ expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
248
+ assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
249
+ end
250
+
251
+ def test_timebased_asset_id_with_relative_url_root
252
+ ActionController::Base.relative_url_root = "/collaboration/hieraki"
253
+ expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
254
+ assert_equal %(<img alt="Rails" src="#{ActionController::Base.relative_url_root}/images/rails.png?#{expected_time}" />), image_tag("rails.png")
255
+ ensure
256
+ ActionController::Base.relative_url_root = ""
257
+ end
258
+
259
+ def test_should_skip_asset_id_on_complete_url
260
+ assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
261
+ end
262
+
263
+ def test_should_use_preset_asset_id
264
+ ENV["RAILS_ASSET_ID"] = "4500"
265
+ assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
266
+ end
267
+
268
+ def test_preset_empty_asset_id
269
+ ENV["RAILS_ASSET_ID"] = ""
270
+ assert_equal %(<img alt="Rails" src="/images/rails.png" />), image_tag("rails.png")
271
+ end
272
+
273
+ def test_should_not_modify_source_string
274
+ source = '/images/rails.png'
275
+ copy = source.dup
276
+ image_tag(source)
277
+ assert_equal copy, source
278
+ end
279
+
280
+ def test_caching_image_path_with_caching_and_proc_asset_host_using_request
281
+ ENV['RAILS_ASSET_ID'] = ''
282
+ ActionController::Base.asset_host = Proc.new do |source, request|
283
+ if request.ssl?
284
+ "#{request.protocol}#{request.host_with_port}"
285
+ else
286
+ "#{request.protocol}assets#{source.length}.example.com"
287
+ end
288
+ end
289
+
290
+ ActionController::Base.perform_caching = true
291
+
292
+
293
+ @controller.request.stubs(:ssl?).returns(false)
294
+ assert_equal "http://assets15.example.com/images/xml.png", image_path("xml.png")
295
+
296
+ @controller.request.stubs(:ssl?).returns(true)
297
+ assert_equal "http://localhost/images/xml.png", image_path("xml.png")
298
+ end
299
+
300
+ def test_caching_javascript_include_tag_when_caching_on
301
+ ENV["RAILS_ASSET_ID"] = ""
302
+ ActionController::Base.asset_host = 'http://a0.example.com'
303
+ ActionController::Base.perform_caching = true
304
+
305
+ assert_dom_equal(
306
+ %(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>),
307
+ javascript_include_tag(:all, :cache => true)
308
+ )
309
+
310
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
311
+
312
+ assert_dom_equal(
313
+ %(<script src="http://a0.example.com/javascripts/money.js" type="text/javascript"></script>),
314
+ javascript_include_tag(:all, :cache => "money")
315
+ )
316
+
317
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
318
+
319
+ ensure
320
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
321
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
322
+ end
323
+
324
+ def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host
325
+ ENV['RAILS_ASSET_ID'] = ''
326
+ ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" }
327
+ ActionController::Base.perform_caching = true
328
+
329
+ assert_equal '/javascripts/scripts.js'.length, 23
330
+ assert_dom_equal(
331
+ %(<script src="http://a23.example.com/javascripts/scripts.js" type="text/javascript"></script>),
332
+ javascript_include_tag(:all, :cache => 'scripts')
333
+ )
334
+
335
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js'))
336
+
337
+ ensure
338
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js'))
339
+ end
340
+
341
+ def test_caching_javascript_include_tag_when_caching_on_with_2_argument_proc_asset_host
342
+ ENV['RAILS_ASSET_ID'] = ''
343
+ ActionController::Base.asset_host = Proc.new { |source, request|
344
+ if request.ssl?
345
+ "#{request.protocol}#{request.host_with_port}"
346
+ else
347
+ "#{request.protocol}assets#{source.length}.example.com"
348
+ end
349
+ }
350
+ ActionController::Base.perform_caching = true
351
+
352
+ assert_equal '/javascripts/vanilla.js'.length, 23
353
+ assert_dom_equal(
354
+ %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>),
355
+ javascript_include_tag(:all, :cache => 'vanilla')
356
+ )
357
+
358
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
359
+
360
+ class << @controller.request
361
+ def protocol() 'https://' end
362
+ def ssl?() true end
363
+ end
364
+
365
+ assert_equal '/javascripts/secure.js'.length, 22
366
+ assert_dom_equal(
367
+ %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>),
368
+ javascript_include_tag(:all, :cache => 'secure')
369
+ )
370
+
371
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
372
+
373
+ ensure
374
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
375
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
376
+ end
377
+
378
+ def test_caching_javascript_include_tag_when_caching_on_with_2_argument_object_asset_host
379
+ ENV['RAILS_ASSET_ID'] = ''
380
+ ActionController::Base.asset_host = Class.new do
381
+ def call(source, request)
382
+ if request.ssl?
383
+ "#{request.protocol}#{request.host_with_port}"
384
+ else
385
+ "#{request.protocol}assets#{source.length}.example.com"
386
+ end
387
+ end
388
+ end.new
389
+
390
+ ActionController::Base.perform_caching = true
391
+
392
+ assert_equal '/javascripts/vanilla.js'.length, 23
393
+ assert_dom_equal(
394
+ %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>),
395
+ javascript_include_tag(:all, :cache => 'vanilla')
396
+ )
397
+
398
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
399
+
400
+ class << @controller.request
401
+ def protocol() 'https://' end
402
+ def ssl?() true end
403
+ end
404
+
405
+ assert_equal '/javascripts/secure.js'.length, 22
406
+ assert_dom_equal(
407
+ %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>),
408
+ javascript_include_tag(:all, :cache => 'secure')
409
+ )
410
+
411
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
412
+
413
+ ensure
414
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
415
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
416
+ end
417
+
418
+ def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
419
+ ENV["RAILS_ASSET_ID"] = ""
420
+ ActionController::Base.asset_host = 'http://a%d.example.com'
421
+ ActionController::Base.perform_caching = true
422
+
423
+ hash = '/javascripts/cache/money.js'.hash % 4
424
+ assert_dom_equal(
425
+ %(<script src="http://a#{hash}.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
426
+ javascript_include_tag(:all, :cache => "cache/money")
427
+ )
428
+
429
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
430
+ ensure
431
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
432
+ end
433
+
434
+ def test_caching_javascript_include_tag_with_all_and_recursive_puts_defaults_at_the_start_of_the_file
435
+ ENV["RAILS_ASSET_ID"] = ""
436
+ ActionController::Base.asset_host = 'http://a0.example.com'
437
+ ActionController::Base.perform_caching = true
438
+
439
+ assert_dom_equal(
440
+ %(<script src="http://a0.example.com/javascripts/combined.js" type="text/javascript"></script>),
441
+ javascript_include_tag(:all, :cache => "combined", :recursive => true)
442
+ )
443
+
444
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
445
+
446
+ assert_equal(
447
+ %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js\n\n// subdir js\n\n\n// version.1.0 js),
448
+ IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
449
+ )
450
+
451
+ ensure
452
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
453
+ end
454
+
455
+ def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_the_file
456
+ ENV["RAILS_ASSET_ID"] = ""
457
+ ActionController::Base.asset_host = 'http://a0.example.com'
458
+ ActionController::Base.perform_caching = true
459
+
460
+ assert_dom_equal(
461
+ %(<script src="http://a0.example.com/javascripts/combined.js" type="text/javascript"></script>),
462
+ javascript_include_tag(:all, :cache => "combined")
463
+ )
464
+
465
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
466
+
467
+ assert_equal(
468
+ %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js\n\n// version.1.0 js),
469
+ IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
470
+ )
471
+
472
+ ensure
473
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
474
+ end
475
+
476
+ def test_caching_javascript_include_tag_with_relative_url_root
477
+ ENV["RAILS_ASSET_ID"] = ""
478
+ ActionController::Base.relative_url_root = "/collaboration/hieraki"
479
+ ActionController::Base.perform_caching = true
480
+
481
+ assert_dom_equal(
482
+ %(<script src="/collaboration/hieraki/javascripts/all.js" type="text/javascript"></script>),
483
+ javascript_include_tag(:all, :cache => true)
484
+ )
485
+
486
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
487
+
488
+ assert_dom_equal(
489
+ %(<script src="/collaboration/hieraki/javascripts/money.js" type="text/javascript"></script>),
490
+ javascript_include_tag(:all, :cache => "money")
491
+ )
492
+
493
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
494
+
495
+ ensure
496
+ ActionController::Base.relative_url_root = nil
497
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
498
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
499
+ end
500
+
501
+ def test_caching_javascript_include_tag_when_caching_off
502
+ ENV["RAILS_ASSET_ID"] = ""
503
+ ActionController::Base.perform_caching = false
504
+
505
+ assert_dom_equal(
506
+ %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
507
+ javascript_include_tag(:all, :cache => true)
508
+ )
509
+
510
+ assert_dom_equal(
511
+ %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
512
+ javascript_include_tag(:all, :cache => true, :recursive => true)
513
+ )
514
+
515
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
516
+
517
+ assert_dom_equal(
518
+ %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
519
+ javascript_include_tag(:all, :cache => "money")
520
+ )
521
+
522
+ assert_dom_equal(
523
+ %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/subdir/subdir.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
524
+ javascript_include_tag(:all, :cache => "money", :recursive => true)
525
+ )
526
+
527
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
528
+ end
529
+
530
+ def test_caching_stylesheet_link_tag_when_caching_on
531
+ ENV["RAILS_ASSET_ID"] = ""
532
+ ActionController::Base.asset_host = 'http://a0.example.com'
533
+ ActionController::Base.perform_caching = true
534
+
535
+ assert_dom_equal(
536
+ %(<link href="http://a0.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
537
+ stylesheet_link_tag(:all, :cache => true)
538
+ )
539
+
540
+ expected = Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/*.css"].map { |p| File.mtime(p) }.max
541
+ assert_equal expected, File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
542
+
543
+ assert_dom_equal(
544
+ %(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
545
+ stylesheet_link_tag(:all, :cache => "money")
546
+ )
547
+
548
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
549
+ ensure
550
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
551
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
552
+ end
553
+
554
+ def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
555
+ ENV["RAILS_ASSET_ID"] = ""
556
+ ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" }
557
+ ActionController::Base.perform_caching = true
558
+
559
+ assert_equal '/stylesheets/styles.css'.length, 23
560
+ assert_dom_equal(
561
+ %(<link href="http://a23.example.com/stylesheets/styles.css" media="screen" rel="stylesheet" type="text/css" />),
562
+ stylesheet_link_tag(:all, :cache => 'styles')
563
+ )
564
+
565
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
566
+
567
+ ensure
568
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
569
+ end
570
+
571
+ def test_caching_stylesheet_link_tag_with_relative_url_root
572
+ ENV["RAILS_ASSET_ID"] = ""
573
+ ActionController::Base.relative_url_root = "/collaboration/hieraki"
574
+ ActionController::Base.perform_caching = true
575
+
576
+ assert_dom_equal(
577
+ %(<link href="/collaboration/hieraki/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
578
+ stylesheet_link_tag(:all, :cache => true)
579
+ )
580
+
581
+ expected = Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/*.css"].map { |p| File.mtime(p) }.max
582
+ assert_equal expected, File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
583
+
584
+ assert_dom_equal(
585
+ %(<link href="/collaboration/hieraki/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
586
+ stylesheet_link_tag(:all, :cache => "money")
587
+ )
588
+
589
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
590
+ ensure
591
+ ActionController::Base.relative_url_root = nil
592
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
593
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
594
+ end
595
+
596
+ def test_caching_stylesheet_include_tag_when_caching_off
597
+ ENV["RAILS_ASSET_ID"] = ""
598
+ ActionController::Base.perform_caching = false
599
+
600
+ assert_dom_equal(
601
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
602
+ stylesheet_link_tag(:all, :cache => true)
603
+ )
604
+
605
+ assert_dom_equal(
606
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
607
+ stylesheet_link_tag(:all, :cache => true, :recursive => true)
608
+ )
609
+
610
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
611
+
612
+ assert_dom_equal(
613
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
614
+ stylesheet_link_tag(:all, :cache => "money")
615
+ )
616
+
617
+ assert_dom_equal(
618
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
619
+ stylesheet_link_tag(:all, :cache => "money", :recursive => true)
620
+ )
621
+
622
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
623
+ end
624
+ end
625
+
626
+ class AssetTagHelperNonVhostTest < ActionView::TestCase
627
+ tests ActionView::Helpers::AssetTagHelper
628
+
629
+ def setup
630
+ ActionController::Base.relative_url_root = "/collaboration/hieraki"
631
+
632
+ @controller = Class.new do
633
+ attr_accessor :request
634
+
635
+ def url_for(options)
636
+ "http://www.example.com/collaboration/hieraki"
637
+ end
638
+ end.new
639
+
640
+ @request = Class.new do
641
+ def protocol
642
+ 'gopher://'
643
+ end
644
+ end.new
645
+
646
+ @controller.request = @request
647
+
648
+ ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
649
+ end
650
+
651
+ def teardown
652
+ ActionController::Base.relative_url_root = nil
653
+ end
654
+
655
+ def test_should_compute_proper_path
656
+ assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag)
657
+ assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
658
+ assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
659
+ assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png"))
660
+ assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse.png'" src="/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
661
+ assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse2.png'" src="/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
662
+ end
663
+
664
+ def test_should_ignore_relative_root_path_on_complete_url
665
+ assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png"))
666
+ end
667
+
668
+ def test_should_compute_proper_path_with_asset_host
669
+ ActionController::Base.asset_host = "http://assets.example.com"
670
+ assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag)
671
+ assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
672
+ assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
673
+ assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
674
+ assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
675
+ assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse2.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
676
+ ensure
677
+ ActionController::Base.asset_host = ""
678
+ end
679
+
680
+ def test_should_ignore_asset_host_on_complete_url
681
+ ActionController::Base.asset_host = "http://assets.example.com"
682
+ assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
683
+ ensure
684
+ ActionController::Base.asset_host = ""
685
+ end
686
+
687
+ def test_should_wildcard_asset_host_between_zero_and_four
688
+ ActionController::Base.asset_host = 'http://a%d.example.com'
689
+ assert_match %r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')
690
+ ensure
691
+ ActionController::Base.asset_host = nil
692
+ end
693
+
694
+ def test_asset_host_without_protocol_should_use_request_protocol
695
+ ActionController::Base.asset_host = 'a.example.com'
696
+ assert_equal 'gopher://a.example.com/collaboration/hieraki/images/xml.png', image_path('xml.png')
697
+ ensure
698
+ ActionController::Base.asset_host = nil
699
+ end
700
+
701
+ def test_asset_host_without_protocol_should_use_request_protocol_even_if_path_present
702
+ ActionController::Base.asset_host = 'a.example.com/files/go/here'
703
+ assert_equal 'gopher://a.example.com/files/go/here/collaboration/hieraki/images/xml.png', image_path('xml.png')
704
+ ensure
705
+ ActionController::Base.asset_host = nil
706
+ end
707
+
708
+ def test_assert_css_and_js_of_the_same_name_return_correct_extension
709
+ assert_dom_equal(%(/collaboration/hieraki/javascripts/foo.js), javascript_path("foo"))
710
+ assert_dom_equal(%(/collaboration/hieraki/stylesheets/foo.css), stylesheet_path("foo"))
711
+
712
+ end
713
+ end