Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8470

Show
Ignore:
Timestamp:
12/21/07 12:26:51 (5 months ago)
Author:
bitsweat
Message:

Rails 1.9 compat: asset tag helper tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/test/template/asset_tag_helper_test.rb

    r8452 r8470  
    226226  def test_caching_javascript_include_tag_when_caching_on 
    227227    ENV["RAILS_ASSET_ID"] = "" 
     228    ActionController::Base.asset_host = 'http://a0.example.com' 
     229    ActionController::Base.perform_caching = true 
     230     
     231    assert_dom_equal( 
     232      %(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>), 
     233      javascript_include_tag(:all, :cache => true) 
     234    ) 
     235 
     236    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 
     237     
     238    assert_dom_equal( 
     239      %(<script src="http://a0.example.com/javascripts/money.js" type="text/javascript"></script>), 
     240      javascript_include_tag(:all, :cache => "money") 
     241    ) 
     242 
     243    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 
     244 
     245  ensure 
     246    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 
     247    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 
     248  end 
     249 
     250  def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host 
     251    ENV["RAILS_ASSET_ID"] = "" 
     252    ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } 
     253    ActionController::Base.perform_caching = true 
     254 
     255    assert_equal '/javascripts/scripts.js'.length, 23 
     256    assert_dom_equal( 
     257      %(<script src="http://a23.example.com/javascripts/scripts.js" type="text/javascript"></script>), 
     258      javascript_include_tag(:all, :cache => 'scripts') 
     259    ) 
     260 
     261    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) 
     262 
     263  ensure 
     264    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) 
     265  end 
     266 
     267  def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory 
     268    ENV["RAILS_ASSET_ID"] = "" 
    228269    ActionController::Base.asset_host = 'http://a%d.example.com' 
    229270    ActionController::Base.perform_caching = true 
    230      
    231     assert_dom_equal( 
    232       %(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>), 
     271 
     272    assert_dom_equal( 
     273      %(<script src="http://a3.example.com/javascripts/cache/money.js" type="text/javascript"></script>), 
     274      javascript_include_tag(:all, :cache => "cache/money") 
     275    ) 
     276 
     277    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) 
     278  ensure 
     279    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) 
     280  end 
     281   
     282  def test_caching_javascript_include_tag_when_caching_off 
     283    ENV["RAILS_ASSET_ID"] = "" 
     284    ActionController::Base.perform_caching = false 
     285     
     286    assert_dom_equal( 
     287      %(<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>), 
    233288      javascript_include_tag(:all, :cache => true) 
    234289    ) 
    235290 
    236     assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 
    237      
    238     assert_dom_equal( 
    239       %(<script src="http://a2.example.com/javascripts/money.js" type="text/javascript"></script>), 
     291    assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 
     292     
     293    assert_dom_equal( 
     294      %(<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>), 
    240295      javascript_include_tag(:all, :cache => "money") 
    241296    ) 
    242297 
    243     assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 
    244  
    245   ensure 
    246     File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 
    247     File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 
    248   end 
    249  
    250   def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host 
     298    assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 
     299  end 
     300 
     301  def test_caching_stylesheet_link_tag_when_caching_on 
     302    ENV["RAILS_ASSET_ID"] = "" 
     303    ActionController::Base.asset_host = 'http://a0.example.com' 
     304    ActionController::Base.perform_caching = true 
     305     
     306    assert_dom_equal( 
     307      %(<link href="http://a0.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />), 
     308      stylesheet_link_tag(:all, :cache => true) 
     309    ) 
     310 
     311    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 
     312 
     313    assert_dom_equal( 
     314      %(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />), 
     315      stylesheet_link_tag(:all, :cache => "money") 
     316    ) 
     317 
     318    assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 
     319  ensure 
     320    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 
     321    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 
     322  end 
     323 
     324  def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host 
    251325    ENV["RAILS_ASSET_ID"] = "" 
    252326    ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } 
    253327    ActionController::Base.perform_caching = true 
    254328 
    255     assert_equal '/javascripts/scripts.js'.length, 23 
    256     assert_dom_equal( 
    257       %(<script src="http://a23.example.com/javascripts/scripts.js" type="text/javascript"></script>), 
    258       javascript_include_tag(:all, :cache => 'scripts') 
    259     ) 
    260  
    261     assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) 
    262  
    263   ensure 
    264     File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) 
    265   end 
    266  
    267   def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory 
    268     ENV["RAILS_ASSET_ID"] = "" 
    269     ActionController::Base.asset_host = 'http://a%d.example.com' 
    270     ActionController::Base.perform_caching = true 
    271  
    272     assert_dom_equal( 
    273       %(<script src="http://a3.example.com/javascripts/cache/money.js" type="text/javascript"></script>), 
    274       javascript_include_tag(:all, :cache => "cache/money") 
    275     ) 
    276  
    277     assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) 
    278   ensure 
    279     File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js')) 
    280   end 
    281    
    282   def test_caching_javascript_include_tag_when_caching_off 
    283     ENV["RAILS_ASSET_ID"] = "" 
    284     ActionController::Base.perform_caching = false 
    285      
    286     assert_dom_equal( 
    287       %(<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>), 
    288       javascript_include_tag(:all, :cache => true) 
    289     ) 
    290  
    291     assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js')) 
    292      
    293     assert_dom_equal( 
    294       %(<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>), 
    295       javascript_include_tag(:all, :cache => "money") 
    296     ) 
    297  
    298     assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js')) 
    299   end 
    300  
    301   def test_caching_stylesheet_link_tag_when_caching_on 
    302     ENV["RAILS_ASSET_ID"] = "" 
    303     ActionController::Base.asset_host = 'http://a%d.example.com' 
    304     ActionController::Base.perform_caching = true 
    305      
    306     assert_dom_equal( 
    307       %(<link href="http://a3.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />), 
    308       stylesheet_link_tag(:all, :cache => true) 
    309     ) 
    310  
    311     assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 
    312  
    313     assert_dom_equal( 
    314       %(<link href="http://a3.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />), 
    315       stylesheet_link_tag(:all, :cache => "money") 
    316     ) 
    317  
    318     assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 
    319   ensure 
    320     File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css')) 
    321     File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css')) 
    322   end 
    323  
    324   def test_caching_stylesheet_link_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  
    329329    assert_equal '/stylesheets/styles.css'.length, 23 
    330330    assert_dom_equal( 
     
    336336 
    337337  ensure 
    338     File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css')) 
     338    FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css')) 
    339339  end 
    340340