sprockets-rails 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +1 -1
- data/README.rdoc +3 -0
- data/Rakefile +15 -31
- data/lib/sprockets/rails/bootstrap.rb +41 -0
- data/lib/sprockets/rails/compressors.rb +87 -0
- data/lib/sprockets/rails/helpers/isolated_helper.rb +15 -0
- data/lib/sprockets/rails/helpers/rails_helper.rb +169 -0
- data/lib/sprockets/rails/helpers.rb +8 -0
- data/lib/sprockets/rails/railtie.rb +64 -0
- data/lib/sprockets/rails/static_compiler.rb +64 -0
- data/lib/sprockets/rails/version.rb +5 -0
- data/lib/sprockets-rails.rb +5 -6
- data/lib/tasks/assets.rake +105 -0
- data/test/abstract_unit.rb +145 -0
- data/test/assets_debugging_test.rb +65 -0
- data/test/assets_test.rb +532 -0
- data/test/fixtures/alternate/stylesheets/style.css +1 -0
- data/{generators/sprockets_rails/templates/application.js → test/fixtures/app/fonts/dir/font.ttf} +0 -0
- data/test/fixtures/app/fonts/font.ttf +0 -0
- data/test/fixtures/app/images/logo.png +0 -0
- data/test/fixtures/app/javascripts/application.js +1 -0
- data/test/fixtures/app/javascripts/dir/xmlhr.js +0 -0
- data/test/fixtures/app/javascripts/extra.js +0 -0
- data/test/fixtures/app/javascripts/xmlhr.js +0 -0
- data/test/fixtures/app/stylesheets/application.css +1 -0
- data/test/fixtures/app/stylesheets/dir/style.css +0 -0
- data/test/fixtures/app/stylesheets/extra.css +0 -0
- data/test/fixtures/app/stylesheets/style.css +0 -0
- data/test/sprockets_compressors_test.rb +27 -0
- data/test/sprockets_helper_test.rb +345 -0
- data/test/sprockets_helper_with_routes_test.rb +60 -0
- data/test/test_helper.rb +84 -0
- metadata +116 -65
- data/.gitignore +0 -5
- data/README.textile +0 -91
- data/VERSION +0 -1
- data/config/sprockets.yml +0 -10
- data/generators/sprockets_rails/sprockets_rails_generator.rb +0 -13
- data/init.rb +0 -1
- data/install.rb +0 -13
- data/lib/sprocket.rb +0 -74
- data/lib/sprockets_application.rb +0 -8
- data/lib/sprockets_controller.rb +0 -12
- data/lib/sprockets_helper.rb +0 -9
- data/recipes/sprockets_tasks.rb +0 -17
- data/sprockets-rails.gemspec +0 -60
- data/tasks/sprockets_tasks.rake +0 -27
- data/test/sprockets_test.rb +0 -8
@@ -0,0 +1,145 @@
|
|
1
|
+
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
2
|
+
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
|
3
|
+
|
4
|
+
require 'sprockets-rails'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'active_support/test_case'
|
8
|
+
require 'rails/generators'
|
9
|
+
require "active_support/testing/isolation"
|
10
|
+
require "active_support/testing/declarative"
|
11
|
+
require "active_support/core_ext/kernel/reporting"
|
12
|
+
|
13
|
+
module TestHelpers
|
14
|
+
module Paths
|
15
|
+
module_function
|
16
|
+
|
17
|
+
TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. tmp]))
|
18
|
+
|
19
|
+
def tmp_path(*args)
|
20
|
+
File.join(TMP_PATH, *args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def app_path(*args)
|
24
|
+
tmp_path(*%w[app] + args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def rails_root
|
28
|
+
app_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Rack
|
33
|
+
def app(env = "production")
|
34
|
+
old_env = ENV["RAILS_ENV"]
|
35
|
+
@app ||= begin
|
36
|
+
ENV["RAILS_ENV"] = env
|
37
|
+
require "#{app_path}/config/environment"
|
38
|
+
Rails.application
|
39
|
+
end
|
40
|
+
ensure
|
41
|
+
ENV["RAILS_ENV"] = old_env
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(path)
|
45
|
+
@app.call(::Rack::MockRequest.env_for(path))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Generation
|
50
|
+
# Build an application by invoking the generator and going through the whole stack.
|
51
|
+
def build_app(options = {})
|
52
|
+
@prev_rails_env = ENV['RAILS_ENV']
|
53
|
+
ENV['RAILS_ENV'] = 'development'
|
54
|
+
|
55
|
+
FileUtils.rm_rf(app_path)
|
56
|
+
FileUtils.cp_r(tmp_path('app_template'), app_path)
|
57
|
+
|
58
|
+
# Delete the initializers unless requested
|
59
|
+
unless options[:initializers]
|
60
|
+
Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
|
61
|
+
File.delete(initializer)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
unless options[:gemfile]
|
66
|
+
File.delete"#{app_path}/Gemfile"
|
67
|
+
end
|
68
|
+
|
69
|
+
routes = File.read("#{app_path}/config/routes.rb")
|
70
|
+
if routes =~ /(\n\s*end\s*)\Z/
|
71
|
+
File.open("#{app_path}/config/routes.rb", 'w') do |f|
|
72
|
+
f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)'\n" + $1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
add_to_config 'config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"; config.active_support.deprecation = :log'
|
77
|
+
end
|
78
|
+
|
79
|
+
def teardown_app
|
80
|
+
ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_to_config(str)
|
84
|
+
environment = File.read("#{app_path}/config/application.rb")
|
85
|
+
if environment =~ /(\n\s*end\s*end\s*)\Z/
|
86
|
+
File.open("#{app_path}/config/application.rb", 'w') do |f|
|
87
|
+
f.puts $` + "\n#{str}\n" + $1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_to_env_config(env, str)
|
93
|
+
environment = File.read("#{app_path}/config/environments/#{env}.rb")
|
94
|
+
if environment =~ /(\n\s*end\s*)\Z/
|
95
|
+
File.open("#{app_path}/config/environments/#{env}.rb", 'w') do |f|
|
96
|
+
f.puts $` + "\n#{str}\n" + $1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def app_file(path, contents)
|
102
|
+
FileUtils.mkdir_p File.dirname("#{app_path}/#{path}")
|
103
|
+
File.open("#{app_path}/#{path}", 'w') do |f|
|
104
|
+
f.puts contents
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def boot_rails
|
109
|
+
require 'rubygems' unless defined? Gem
|
110
|
+
require 'bundler'
|
111
|
+
Bundler.setup
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class ActiveSupport::TestCase
|
117
|
+
include TestHelpers::Paths
|
118
|
+
include TestHelpers::Rack
|
119
|
+
include TestHelpers::Generation
|
120
|
+
extend ActiveSupport::Testing::Declarative
|
121
|
+
end
|
122
|
+
|
123
|
+
# Create a scope and build a fixture rails app
|
124
|
+
Module.new do
|
125
|
+
extend TestHelpers::Paths
|
126
|
+
# Build a rails app
|
127
|
+
if File.exist?(tmp_path)
|
128
|
+
FileUtils.rm_rf(tmp_path)
|
129
|
+
end
|
130
|
+
FileUtils.mkdir(tmp_path)
|
131
|
+
|
132
|
+
quietly do
|
133
|
+
Rails::Generators.invoke('app', ["#{tmp_path('app_template')}", "--skip-active-record", "--skip-test-unit"])
|
134
|
+
end
|
135
|
+
|
136
|
+
File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
|
137
|
+
f.puts 'require "action_controller/railtie"'
|
138
|
+
end
|
139
|
+
|
140
|
+
# This is temporary, disable sprockets-rails railtie done in rails
|
141
|
+
file = "#{tmp_path}/app_template/config/application.rb"
|
142
|
+
contents = File.read(file)
|
143
|
+
contents.sub!(/require \"sprockets\/railtie\"/, "")
|
144
|
+
File.open(file, "w+") { |f| f.puts contents }
|
145
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/abstract_unit")
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
module ApplicationTests
|
5
|
+
class AssetsDebuggingTest < ActiveSupport::TestCase
|
6
|
+
include ActiveSupport::Testing::Isolation
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
def setup
|
10
|
+
build_app(:initializers => true)
|
11
|
+
|
12
|
+
app_file "app/assets/javascripts/application.js", "//= require_tree ."
|
13
|
+
app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
|
14
|
+
app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>"
|
15
|
+
|
16
|
+
app_file "config/routes.rb", <<-RUBY
|
17
|
+
AppTemplate::Application.routes.draw do
|
18
|
+
match '/posts', :to => "posts#index"
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
|
22
|
+
app_file "app/controllers/posts_controller.rb", <<-RUBY
|
23
|
+
class PostsController < ActionController::Base
|
24
|
+
end
|
25
|
+
RUBY
|
26
|
+
|
27
|
+
ENV["RAILS_ENV"] = "production"
|
28
|
+
|
29
|
+
boot_rails
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
teardown_app
|
34
|
+
end
|
35
|
+
|
36
|
+
test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do
|
37
|
+
# config.assets.debug and config.assets.compile are false for production environment
|
38
|
+
ENV["RAILS_ENV"] = "production"
|
39
|
+
capture(:stdout) do
|
40
|
+
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
|
41
|
+
end
|
42
|
+
require "#{app_path}/config/environment"
|
43
|
+
|
44
|
+
class ::PostsController < ActionController::Base ; end
|
45
|
+
|
46
|
+
# the debug_assets params isn't used if compile is off
|
47
|
+
get '/posts?debug_assets=true'
|
48
|
+
assert_match(/<script src="\/assets\/application-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body)
|
49
|
+
assert_no_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "assets aren't concatened when compile is true is on and debug_assets params is true" do
|
53
|
+
app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"
|
54
|
+
|
55
|
+
ENV["RAILS_ENV"] = "production"
|
56
|
+
require "#{app_path}/config/environment"
|
57
|
+
|
58
|
+
class ::PostsController < ActionController::Base ; end
|
59
|
+
|
60
|
+
get '/posts?debug_assets=true'
|
61
|
+
assert_match(/<script src="\/assets\/application-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
|
62
|
+
assert_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|