Skip to content
This repository
Browse code

Backport e767cda (move assets tests to assets_test file)

  • Loading branch information...
commit 3d042fa78dcedbca8c71f6e0dfc02a3b26008396 1 parent f79fac5
Guillermo Iguaran authored September 13, 2011
31  railties/test/application/assets_test.rb
... ...
@@ -1,3 +1,4 @@
  1
+# -*- coding: utf-8 -*-
1 2
 require 'isolation/abstract_unit'
2 3
 require 'active_support/core_ext/kernel/reporting'
3 4
 require 'rack/test'
@@ -268,6 +269,36 @@ class ::PostsController < ActionController::Base ; end
268 269
       assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
269 270
     end
270 271
 
  272
+    test "precompile ignore asset_host" do
  273
+      app_file "app/assets/javascripts/application.css.erb", "<%= asset_path 'rails.png' %>"
  274
+      add_to_config "config.action_controller.asset_host = Proc.new { |source, request| 'http://www.example.com/' }"
  275
+
  276
+      capture(:stdout) do
  277
+        Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
  278
+      end
  279
+
  280
+      file = Dir["#{app_path}/public/assets/application.css"].first
  281
+      content = File.read(file)
  282
+      assert_match(/\/assets\/rails-([0-z]+)\.png/, content)
  283
+      assert_no_match(/www\.example\.com/, content)
  284
+    end
  285
+
  286
+    test "precompile should handle utf8 filenames" do
  287
+      app_file "app/assets/images/レイルズ.png", "not a image really"
  288
+      add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]"
  289
+
  290
+      capture(:stdout) do
  291
+        Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
  292
+      end
  293
+
  294
+      assert File.exists?("#{app_path}/public/assets/レイルズ.png")
  295
+
  296
+      manifest = "#{app_path}/public/assets/manifest.yml"
  297
+
  298
+      assets = YAML.load_file(manifest)
  299
+      assert_equal "レイルズ.png", assets["レイルズ.png"]
  300
+    end
  301
+
271 302
     test "assets are cleaned up properly" do
272 303
       app_file "public/assets/application.js", "alert();"
273 304
       app_file "public/assets/application.css", "a { color: green; }"
32  railties/test/application/rake_test.rb
@@ -176,35 +176,13 @@ def test_loading_specific_fixtures
176 176
       assert_equal 0, ::AppTemplate::Application::User.count
177 177
     end
178 178
 
179  
-    def test_assets_precompile_with_utf8_filename
180  
-      add_to_config <<-RUBY
181  
-        config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]
182  
-      RUBY
183  
-
184  
-      Dir.chdir(app_path) do
185  
-        `cp app/assets/images/rails.png app/assets/images/レイルズ.png`
186  
-        `rake assets:precompile`
187  
-        open("public/assets/manifest.yml") do |f|
188  
-          assert_match(/レイルズ.png/, f.read)
189  
-        end
  179
+    def test_scaffold_tests_pass_by_default
  180
+      content = Dir.chdir(app_path) do
  181
+        `rails generate scaffold user username:string password:string`
  182
+        `bundle exec rake db:migrate db:test:clone test`
190 183
       end
191  
-    end
192  
-
193  
-    def test_assets_precompile_ignore_asset_host
194  
-      add_to_config <<-RUBY
195  
-        config.action_controller.asset_host = Proc.new { |source, request| "http://www.example.com/" }
196  
-      RUBY
197  
-
198  
-      app_file "app/assets/javascripts/test.js.erb", <<-RUBY
199  
-        alert("<%= asset_path "rails.png" %>");
200  
-      RUBY
201 184
 
202  
-      Dir.chdir(app_path) do
203  
-        `rake assets:precompile`
204  
-        open("public/assets/application.js") do |f|
205  
-          assert_match(/\"\/assets\/rails.png\"/, f.read)
206  
-        end
207  
-      end
  185
+      assert_match(/7 tests, 10 assertions, 0 failures, 0 errors/, content)
208 186
     end
209 187
   end
210 188
 end

0 notes on commit 3d042fa

Please sign in to comment.
Something went wrong with that request. Please try again.