Skip to content

Commit

Permalink
Do not add files in assets/ directories to Sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasveer Singh committed Jul 28, 2011
1 parent b2eaf96 commit b4ca7d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions railties/lib/rails/engine.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -538,9 +538,9 @@ def load_seed
end end


initializer :append_assets_path do |app| initializer :append_assets_path do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent) app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent) app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent) app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
end end


initializer :prepend_helpers_path do |app| initializer :prepend_helpers_path do |app|
Expand Down
4 changes: 4 additions & 0 deletions railties/lib/rails/paths.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def expanded
def existent def existent
expanded.select { |f| File.exists?(f) } expanded.select { |f| File.exists?(f) }
end end

def existent_directories
expanded.select {|d| Dir.exists?(d) }
end


def paths def paths
ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead." ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead."
Expand Down
14 changes: 14 additions & 0 deletions railties/test/application/assets_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -86,5 +86,19 @@ def index
assert_match "alert()", last_response.body assert_match "alert()", last_response.body
assert_equal nil, last_response.headers["Set-Cookie"] assert_equal nil, last_response.headers["Set-Cookie"]
end end

test "files in any assets/ directories are not added to Sprockets" do
%w[app lib vendor].each do |dir|
app_file "#{dir}/assets/#{dir}_test.erb", "testing"
end

app_file "app/assets/javascripts/demo.js", "alert();"

require "#{app_path}/config/environment"

get "/assets/demo.js"
assert_match "alert();", last_response.body
assert_equal 200, last_response.status
end
end end
end end

0 comments on commit b4ca7d3

Please sign in to comment.