Skip to content

Use last version of sprockets-rails and sync tests for assets. #7482

Merged
merged 2 commits into from Sep 19, 2012
View
3 Gemfile
@@ -27,7 +27,8 @@ end
# This needs to be with require false to avoid
# it being automatically loaded by sprockets
-gem 'uglifier', '>= 1.0.3', require: false
+gem 'uglifier', require: false
+gem 'sprockets-rails', github: 'rails/sprockets-rails'
@guilleiguaran
Ruby on Rails member
guilleiguaran added a note Sep 9, 2012

I'm getting a failure in rails test suite using sprockets-rails from rails repo, can you verify if you are getting that error also?

@route
route added a note Sep 9, 2012

Urgh, I cannot track it down, my tests are green, and I wonder why?

@guilleiguaran
Ruby on Rails member
guilleiguaran added a note Sep 9, 2012

can you test running tests with https://github.com/guilleiguaran/rails, in the remove-manifest-option branch?
I think is a problem with my machine

@route
route added a note Sep 10, 2012

Yes I have the same issue as you. Trying to find out.

@route
route added a note Sep 10, 2012

This

      images_should_compile = ["a.png", "happyface.png", "happy_face.png", "happy.face.png",
                               "happy-face.png", "happy.happy_face.png", "happy_happy.face.png",
                               "happy.happy.face.png", "happy", "happy.face", "-happyface",
                               "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png",
                               "_happy.png"]

should be replaced with

      images_should_compile = ["a.png", "happyface.png", "happy_face.png", "happy.face.png",
                               "happy-face.png", "happy.happy_face.png", "happy_happy.face.png",
                               "happy.happy.face.png", "-happy.png", "-happy.face.png",
                               "_happy.face.png", "_happy.png"]

Rake was aborted because of -happyface has no extension. I think it because of old frozen versions of sprockets-rails and sprockets, isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
group :doc do
# The current sdoc cannot generate GitHub links due
View
67 railties/test/application/assets_test.rb
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
require 'isolation/abstract_unit'
-require 'active_support/core_ext/kernel/reporting'
require 'rack/test'
module ApplicationTests
@@ -28,10 +27,18 @@ def precompile!(env = nil)
def clean_assets!
quietly do
- assert Dir.chdir(app_path){ system('bundle exec rake assets:clean') }
+ assert Dir.chdir(app_path) { system('bundle exec rake assets:clean') }
end
end
+ def assert_file_exists(filename)
+ assert File.exists?(filename), "missing #{filename}"
+ end
+
+ def assert_no_file_exists(filename)
+ assert !File.exists?(filename), "#{filename} does exist"
+ end
+
test "assets routes have higher priority" do
app_file "app/assets/javascripts/demo.js.erb", "a = <%= image_path('rails.png').inspect %>;"
@@ -92,9 +99,8 @@ def clean_assets!
images_should_compile = ["a.png", "happyface.png", "happy_face.png", "happy.face.png",
"happy-face.png", "happy.happy_face.png", "happy_happy.face.png",
- "happy.happy.face.png", "happy", "happy.face", "-happyface",
- "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png",
- "_happy.png"]
+ "happy.happy.face.png", "-happy.png", "-happy.face.png",
+ "_happy.face.png", "_happy.png"]
images_should_compile.each do |filename|
app_file "app/assets/images/#{filename}", "happy"
@@ -103,7 +109,7 @@ def clean_assets!
precompile!
images_should_compile.each do |filename|
- assert_file_exists "#{app_path}/public/assets/#{filename}"
+ assert_file_exists("#{app_path}/public/assets/#{filename}")
end
assert_file_exists("#{app_path}/public/assets/application.js")
@@ -119,12 +125,13 @@ def clean_assets!
assert_no_file_exists("#{app_path}/public/assets/something.else.css")
end
- def assert_file_exists(filename)
- assert File.exists?(filename), "missing #{filename}"
- end
+ test "precompile something.js for directory containing index file" do
+ add_to_config "config.assets.precompile = [ 'something.js' ]"
+ app_file "app/assets/javascripts/something/index.js.erb", "alert();"
- def assert_no_file_exists(filename)
- assert !File.exists?(filename), "#{filename} does exist"
+ precompile!
+
+ assert_file_exists("#{app_path}/public/assets/something.js")
end
test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do
@@ -151,21 +158,6 @@ def assert_no_file_exists(filename)
assert_match(/application-([0-z]+)\.css/, assets["application.css"])
end
- test "precompile creates a manifest file in a custom path with all the assets listed" do
@guilleiguaran
Ruby on Rails member
guilleiguaran added a note Sep 9, 2012

I'm surprised, this is passing in Rails master? Probably the last version of sprockets-rails isn't being used

@guilleiguaran
Ruby on Rails member
guilleiguaran added a note Sep 9, 2012

Ah, I see, we aren't using sprockets-rails from git in Rails, so the change in Gemfile in this PR is fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
- app_file "app/assets/javascripts/application.js", "alert();"
- # digest is default in false, we must enable it for test environment
- add_to_config "config.assets.digest = true"
- add_to_config "config.assets.manifest = '#{app_path}/shared'"
-
- precompile!
- manifest = "#{app_path}/shared/manifest.yml"
-
- assets = YAML.load_file(manifest)
- assert_match(/application-([0-z]+)\.js/, assets["application.js"])
- assert_match(/application-([0-z]+)\.css/, assets["application.css"])
- end
-
test "the manifest file should be saved by default in the same assets folder" do
app_file "app/assets/javascripts/application.js", "alert();"
# digest is default in false, we must enable it for test environment
@@ -186,8 +178,8 @@ def assert_no_file_exists(filename)
precompile!
- assert File.exists?("#{app_path}/public/assets/application.js")
- assert File.exists?("#{app_path}/public/assets/application.css")
+ assert_file_exists("#{app_path}/public/assets/application.js")
+ assert_file_exists("#{app_path}/public/assets/application.css")
manifest = "#{app_path}/public/assets/manifest.yml"
@@ -238,7 +230,7 @@ def show_detailed_exceptions?() true end
get '/posts'
assert_match(/AssetNotPrecompiledError/, last_response.body)
- assert_match(/app.js isn&#39;t precompiled/, last_response.body)
+ assert_match(/app\.js isn&#39;t precompiled/, last_response.body)
end
test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do
@@ -262,7 +254,7 @@ class ::PostsController < ActionController::Base ; end
get '/posts'
assert_match(/AssetNotPrecompiledError/, last_response.body)
- assert_match(/app.js isn&#39;t precompiled/, last_response.body)
+ assert_match(/app\.js isn&#39;t precompiled/, last_response.body)
end
test "precompile properly refers files referenced with asset_path and and run in the provided RAILS_ENV" do
@@ -318,7 +310,7 @@ class ::PostsController < ActionController::Base ; end
get "/assets/#{URI.parser.escape(filename)}"
assert_match "not a image really", last_response.body
- assert File.exists?("#{app_path}/public/assets/#{filename}")
+ assert_file_exists("#{app_path}/public/assets/#{filename}")
end
test "assets are cleaned up properly" do
@@ -454,7 +446,6 @@ class ::PostsController < ActionController::Base ; end
add_to_config "config.assets.compile = true"
add_to_config "config.assets.digest = true"
- clean_assets!
precompile!
files = Dir["#{app_path}/public/assets/application-*.js"]
@@ -504,6 +495,18 @@ class ::PostsController < ActionController::Base; end
assert_match 'src="/sub/uri/assets/rails.png"', File.read("#{app_path}/public/assets/app.js")
end
+ test "html assets are compiled when executing precompile" do
+ app_file "app/assets/pages/page.html.erb", "<%= javascript_include_tag :application %>"
+ ENV["RAILS_ENV"] = "production"
+ ENV["RAILS_GROUP"] = "assets"
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
+ end
+
+ assert_file_exists("#{app_path}/public/assets/page.html")
+ end
+
test "assets:cache:clean should clean cache" do
ENV["RAILS_ENV"] = "production"
precompile!
Something went wrong with that request. Please try again.