smart_asset 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/LICENSE +2 -2
- data/Rakefile +1 -0
- data/bin/smart_asset +1 -1
- data/lib/smart_asset.rb +2 -6
- data/lib/smart_asset/adapters/stasis.rb +43 -0
- data/smart_asset.gemspec +25 -0
- data/spec/fixtures/all_frameworks/assets.yml +20 -0
- data/spec/fixtures/all_frameworks/test.html.erb +3 -0
- data/spec/fixtures/assets.yml +27 -0
- data/spec/fixtures/assets/javascripts/jquery/jquery.js +7179 -0
- data/spec/fixtures/assets/javascripts/underscore.js +722 -0
- data/spec/fixtures/assets/stylesheets/960.css +648 -0
- data/spec/fixtures/assets/stylesheets/blueprint/blueprint.css +265 -0
- data/spec/fixtures/development_output.txt +5 -0
- data/spec/fixtures/frameworks.yml +32 -0
- data/spec/fixtures/production_output.txt +3 -0
- data/spec/fixtures/rails2/application_controller.rb +17 -0
- data/spec/fixtures/rails2/environment.rb +42 -0
- data/spec/fixtures/rails2/init.rb +1 -0
- data/spec/fixtures/rails2/routes.rb +47 -0
- data/spec/fixtures/rails3/Gemfile +34 -0
- data/spec/fixtures/rails3/application.rb +47 -0
- data/spec/fixtures/rails3/application_controller.rb +11 -0
- data/spec/fixtures/rails3/routes.rb +61 -0
- data/spec/fixtures/sinatra/application.rb +19 -0
- data/spec/run +39 -0
- data/spec/smart_asset/adapters/rails2_spec.rb +46 -0
- data/spec/smart_asset/adapters/rails3_spec.rb +46 -0
- data/spec/smart_asset/adapters/sinatra_spec.rb +47 -0
- data/spec/smart_asset_spec.rb +403 -0
- data/spec/spec_helper.rb +27 -0
- metadata +113 -59
- data/lib/smart_asset/gems.rb +0 -45
- data/lib/smart_asset/version.rb +0 -3
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
# require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "active_resource/railtie"
|
8
|
+
require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
# If you have a Gemfile, require the gems listed there, including any gems
|
11
|
+
# you've limited to :test, :development, or :production.
|
12
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
13
|
+
|
14
|
+
module Rails3
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
21
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
22
|
+
|
23
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
25
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
26
|
+
|
27
|
+
# Activate observers that should always be running.
|
28
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
29
|
+
|
30
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
31
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
32
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
33
|
+
|
34
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
35
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
36
|
+
# config.i18n.default_locale = :de
|
37
|
+
|
38
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
39
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
40
|
+
|
41
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
42
|
+
config.encoding = "utf-8"
|
43
|
+
|
44
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
45
|
+
config.filter_parameters += [:password]
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Rails3::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get 'short'
|
20
|
+
# post 'toggle'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get 'sold'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get 'recent', :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
# root :to => "welcome#index"
|
52
|
+
|
53
|
+
# See how all your routes lay out with "rake routes"
|
54
|
+
|
55
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
+
# match ':controller(/:action(/:id(.:format)))'
|
58
|
+
|
59
|
+
match 'pulse' => 'application#pulse'
|
60
|
+
match 'test' => 'application#test'
|
61
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'smart_asset'
|
4
|
+
|
5
|
+
class Application < Sinatra::Base
|
6
|
+
|
7
|
+
set :app_file, __FILE__
|
8
|
+
set :views, File.dirname(__FILE__)
|
9
|
+
|
10
|
+
include SmartAsset::Adapters::Sinatra
|
11
|
+
|
12
|
+
get '/pulse' do
|
13
|
+
'1'
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/test' do
|
17
|
+
erb :'test.html'
|
18
|
+
end
|
19
|
+
end
|
data/spec/run
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
system "spec -f n -c spec"
|
4
|
+
|
5
|
+
puts "\n"
|
6
|
+
|
7
|
+
ENV['RAILS'] = '2'
|
8
|
+
ENV['RAILS_ENV'] = 'development'
|
9
|
+
system "spec -f n -c spec"
|
10
|
+
|
11
|
+
puts "\n"
|
12
|
+
|
13
|
+
ENV['RAILS_ENV'] = 'production'
|
14
|
+
system "spec -f n -c spec"
|
15
|
+
|
16
|
+
puts "\n"
|
17
|
+
|
18
|
+
ENV['RAILS'] = '3'
|
19
|
+
ENV['RAILS_ENV'] = 'development'
|
20
|
+
system "spec -f n -c spec"
|
21
|
+
|
22
|
+
puts "\n"
|
23
|
+
|
24
|
+
ENV['RAILS_ENV'] = 'production'
|
25
|
+
system "spec -f n -c spec"
|
26
|
+
|
27
|
+
ENV.delete 'RAILS'
|
28
|
+
ENV.delete 'RAILS_ENV'
|
29
|
+
|
30
|
+
puts "\n"
|
31
|
+
|
32
|
+
ENV['SINATRA'] = '1'
|
33
|
+
ENV['RACK_ENV'] = 'development'
|
34
|
+
system "spec -f n -c spec"
|
35
|
+
|
36
|
+
puts "\n"
|
37
|
+
|
38
|
+
ENV['RACK_ENV'] = 'production'
|
39
|
+
system "spec -f n -c spec"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
if FrameworkFixture.rails == '<3'
|
4
|
+
describe 'Rails 2' do
|
5
|
+
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
FrameworkFixture.app.call
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
assets = "#{$root}/spec/fixtures/assets"
|
14
|
+
pub = "#{$root}/spec/fixtures/builds/rails2/public"
|
15
|
+
FileUtils.rm_rf "#{pub}/packaged"
|
16
|
+
FileUtils.cp_r "#{assets}/compressed", "#{pub}/packaged"
|
17
|
+
FileUtils.rm_rf "#{pub}/javascripts"
|
18
|
+
FileUtils.cp_r "#{assets}/javascripts", "#{pub}/javascripts"
|
19
|
+
FileUtils.rm_rf "#{pub}/stylesheets"
|
20
|
+
FileUtils.cp_r "#{assets}/stylesheets", "#{pub}/stylesheets"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a pulse" do
|
24
|
+
get "/pulse"
|
25
|
+
last_response.body.should == '1'
|
26
|
+
end
|
27
|
+
|
28
|
+
if Rails.env == 'development'
|
29
|
+
describe :development do
|
30
|
+
it "should execute helpers correctly" do
|
31
|
+
get "/test"
|
32
|
+
last_response.body.should == File.read("#{$root}/spec/fixtures/development_output.txt")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if Rails.env == 'production'
|
38
|
+
describe :production do
|
39
|
+
it "should execute helpers correctly" do
|
40
|
+
get "/test"
|
41
|
+
last_response.body.should == File.read("#{$root}/spec/fixtures/production_output.txt")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
if FrameworkFixture.rails == '<4'
|
4
|
+
describe 'Rails 3' do
|
5
|
+
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
FrameworkFixture.app.call
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
assets = "#{$root}/spec/fixtures/assets"
|
14
|
+
pub = "#{$root}/spec/fixtures/builds/rails3/public"
|
15
|
+
FileUtils.rm_rf "#{pub}/packaged"
|
16
|
+
FileUtils.cp_r "#{assets}/compressed", "#{pub}/packaged"
|
17
|
+
FileUtils.rm_rf "#{pub}/javascripts"
|
18
|
+
FileUtils.cp_r "#{assets}/javascripts", "#{pub}/javascripts"
|
19
|
+
FileUtils.rm_rf "#{pub}/stylesheets"
|
20
|
+
FileUtils.cp_r "#{assets}/stylesheets", "#{pub}/stylesheets"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a pulse" do
|
24
|
+
get "/pulse"
|
25
|
+
last_response.body.should == '1'
|
26
|
+
end
|
27
|
+
|
28
|
+
if Rails.env == 'development'
|
29
|
+
describe :development do
|
30
|
+
it "should execute helpers correctly" do
|
31
|
+
get "/test"
|
32
|
+
last_response.body.should == File.read("#{$root}/spec/fixtures/development_output.txt")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if Rails.env == 'production'
|
38
|
+
describe :production do
|
39
|
+
it "should execute helpers correctly" do
|
40
|
+
get "/test"
|
41
|
+
last_response.body.should == File.read("#{$root}/spec/fixtures/production_output.txt")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
if FrameworkFixture.sinatra
|
4
|
+
describe 'Sinatra' do
|
5
|
+
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
FrameworkFixture.app.call
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
assets = "#{$root}/spec/fixtures/assets"
|
14
|
+
pub = "#{$root}/spec/fixtures/builds/sinatra#{FrameworkFixture.exact_version[0..0]}/public"
|
15
|
+
FileUtils.mkdir_p pub
|
16
|
+
FileUtils.rm_rf "#{pub}/packaged"
|
17
|
+
FileUtils.cp_r "#{assets}/compressed", "#{pub}/packaged"
|
18
|
+
FileUtils.rm_rf "#{pub}/javascripts"
|
19
|
+
FileUtils.cp_r "#{assets}/javascripts", "#{pub}/javascripts"
|
20
|
+
FileUtils.rm_rf "#{pub}/stylesheets"
|
21
|
+
FileUtils.cp_r "#{assets}/stylesheets", "#{pub}/stylesheets"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a pulse" do
|
25
|
+
get "/pulse"
|
26
|
+
last_response.body.should == '1'
|
27
|
+
end
|
28
|
+
|
29
|
+
if Sinatra::Base.environment == :development
|
30
|
+
describe :development do
|
31
|
+
it "should execute helpers correctly" do
|
32
|
+
get "/test"
|
33
|
+
last_response.body.should == File.read("#{$root}/spec/fixtures/development_output.txt")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if Sinatra::Base.environment == :production
|
39
|
+
describe :production do
|
40
|
+
it "should execute helpers correctly" do
|
41
|
+
get "/test"
|
42
|
+
last_response.body.should == File.read("#{$root}/spec/fixtures/production_output.txt")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,403 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
unless FrameworkFixture.framework
|
4
|
+
describe SmartAsset do
|
5
|
+
|
6
|
+
include SmartAsset::Helper
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
@config = "spec/fixtures/assets.yml"
|
10
|
+
@dest = "#{$root}/spec/fixtures/assets/compressed"
|
11
|
+
@files = %w(
|
12
|
+
package.css
|
13
|
+
package.js
|
14
|
+
)
|
15
|
+
@versions = %w(
|
16
|
+
4c0f7deb
|
17
|
+
1042e864
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe :load_config do
|
22
|
+
|
23
|
+
before(:all) do
|
24
|
+
SmartAsset.env = 'development'
|
25
|
+
SmartAsset.load_config($root, @config)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should populate @root" do
|
29
|
+
SmartAsset.root.should == $root
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should populate @config" do
|
33
|
+
SmartAsset.config.should == {
|
34
|
+
"append_random"=>{"development"=>true},
|
35
|
+
"asset_host_count"=>2,
|
36
|
+
"asset_host"=>{"production"=>"http://assets%d.host.com"},
|
37
|
+
"destination"=>{"javascripts"=>"compressed", "stylesheets"=>"compressed"},
|
38
|
+
"environments"=>["production"],
|
39
|
+
"public"=>"spec/fixtures/assets",
|
40
|
+
"sources"=>{"javascripts"=>"javascripts", "stylesheets"=>"stylesheets"},
|
41
|
+
"javascripts"=>
|
42
|
+
{"package"=>["jquery/jquery", "underscore", "does_not_exist"],
|
43
|
+
"empty_package"=>nil,
|
44
|
+
"non_existent_package"=>["does_not_exist"]},
|
45
|
+
"stylesheets"=>
|
46
|
+
{"package"=>["blueprint/blueprint", 960, "does_not_exist"],
|
47
|
+
"empty_package"=>nil,
|
48
|
+
"non_existent_package"=>["does_not_exist"]}}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should populate @append_random" do
|
52
|
+
SmartAsset.append_random.should == true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should populate @asset_host" do
|
56
|
+
SmartAsset.asset_host.should == {"production"=>"http://assets%d.host.com"}
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should populate @dest" do
|
60
|
+
SmartAsset.dest.should == {
|
61
|
+
'javascripts' => "#{$root}/spec/fixtures/assets/compressed",
|
62
|
+
'stylesheets' => "#{$root}/spec/fixtures/assets/compressed"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should populate @envs" do
|
67
|
+
SmartAsset.envs.should == ["production"]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should populate @pub" do
|
71
|
+
SmartAsset.pub.should == "#{$root}/spec/fixtures/assets"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should populate @root" do
|
75
|
+
SmartAsset.root.should == $root
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should populate @sources" do
|
79
|
+
SmartAsset.sources.should == {"javascripts"=>"javascripts", "stylesheets"=>"stylesheets"}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe :binary do
|
84
|
+
describe 'no compressed assets' do
|
85
|
+
|
86
|
+
before(:all) do
|
87
|
+
FileUtils.rm_rf(@dest) unless ENV['FAST']
|
88
|
+
@output = capture_stdout do
|
89
|
+
SmartAsset.binary $root, @config
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should generate correct filenames" do
|
94
|
+
@files.each_with_index do |file, i|
|
95
|
+
File.exists?("#{@dest}/#{@versions[i]}_#{file}").should == true
|
96
|
+
end
|
97
|
+
Dir["#{@dest}/*.{js,css}"].length.should == @files.length
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should create package files with content" do
|
101
|
+
@files.each_with_index do |file, i|
|
102
|
+
File.size(path = "#{@dest}/#{@versions[i]}_#{file}").should > 0
|
103
|
+
if i == 0
|
104
|
+
css = File.read(path)
|
105
|
+
css.index('.error').should < css.index('.container_12')
|
106
|
+
css.include?('.error').should == true
|
107
|
+
css.include?('.container_12').should == true
|
108
|
+
else
|
109
|
+
js = File.read(path)
|
110
|
+
js.index('jQuery').should < js.index('VERSION')
|
111
|
+
js.include?('jQuery').should == true
|
112
|
+
js.include?('VERSION').should == true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
unless ENV['FAST']
|
118
|
+
it "should run all files through the compressor" do
|
119
|
+
@files.each do |file|
|
120
|
+
@output.string.include?(file).should == true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should fix YUI compression issue" do
|
126
|
+
File.read("#{@dest}/#{@versions[0]}_#{@files[0]}").include?("screen and (").should == true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'one version out of date' do
|
131
|
+
|
132
|
+
before(:all) do
|
133
|
+
unless ENV['FAST']
|
134
|
+
FileUtils.mv "#{@dest}/#{@versions[0]}_#{@files[0]}", "#{@dest}/00000000_#{@files[0]}"
|
135
|
+
end
|
136
|
+
@output = capture_stdout do
|
137
|
+
SmartAsset.binary $root, @config
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should generate correct filenames" do
|
142
|
+
@files.each_with_index do |file, i|
|
143
|
+
File.exists?("#{@dest}/#{@versions[i]}_#{file}").should == true
|
144
|
+
end
|
145
|
+
Dir["#{@dest}/*.{js,css}"].length.should == @files.length
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should create package files with content" do
|
149
|
+
@files.each_with_index do |file, i|
|
150
|
+
File.size(path = "#{@dest}/#{@versions[i]}_#{file}").should > 0
|
151
|
+
if i == 0
|
152
|
+
css = File.read(path)
|
153
|
+
css.index('.error').should < css.index('.container_12')
|
154
|
+
css.include?('.error').should == true
|
155
|
+
css.include?('.container_12').should == true
|
156
|
+
else
|
157
|
+
js = File.read(path)
|
158
|
+
js.index('jQuery').should < js.index('VERSION')
|
159
|
+
js.include?('jQuery').should == true
|
160
|
+
js.include?('VERSION').should == true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should remove old version" do
|
166
|
+
Dir["#{@dest}/*.css"].length.should == 1
|
167
|
+
end
|
168
|
+
|
169
|
+
unless ENV['FAST']
|
170
|
+
it "should run updated file through the compressor" do
|
171
|
+
@files.each_with_index do |file, i|
|
172
|
+
@output.string.include?(file).should == (i == 0 ? true : false)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
unless ENV['FAST']
|
179
|
+
describe 'package changed' do
|
180
|
+
|
181
|
+
before(:all) do
|
182
|
+
@package_config = SmartAsset.config['javascripts']['package']
|
183
|
+
@old_package_path = "#{@dest}/#{@versions[1]}_#{@files[1]}"
|
184
|
+
@old_package = File.read(@old_package_path)
|
185
|
+
end
|
186
|
+
|
187
|
+
after(:all) do
|
188
|
+
File.open(@old_package_path, 'w') { |f| f.write(@old_package) }
|
189
|
+
end
|
190
|
+
|
191
|
+
after(:each) do
|
192
|
+
SmartAsset.config['javascripts']['package'] = @package_config
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'package order changed' do
|
196
|
+
|
197
|
+
before(:all) do
|
198
|
+
SmartAsset.config['javascripts']['package'].delete 'underscore'
|
199
|
+
SmartAsset.config['javascripts']['package'].unshift 'underscore'
|
200
|
+
@output = capture_stdout do
|
201
|
+
SmartAsset.compress 'javascripts'
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should rewrite javascript package with underscore code first" do
|
206
|
+
File.size(path = "#{@dest}/91d1e5c5_#{@files[1]}").should > 0
|
207
|
+
js = File.read(path)
|
208
|
+
js.index('jQuery').should > js.index('VERSION')
|
209
|
+
js.include?('jQuery').should == true
|
210
|
+
js.include?('VERSION').should == true
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should run updated file through the compressor" do
|
214
|
+
@files.each_with_index do |file, i|
|
215
|
+
@output.string.include?(file).should == (i == 1 ? true : false)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should remove old version" do
|
220
|
+
Dir["#{@dest}/*.js"].length.should == 1
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe 'package child removed' do
|
225
|
+
|
226
|
+
before(:all) do
|
227
|
+
SmartAsset.config['javascripts']['package'].delete 'underscore'
|
228
|
+
@output = capture_stdout do
|
229
|
+
SmartAsset.compress 'javascripts'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should rewrite javascript package with only jquery" do
|
234
|
+
File.size(path = "#{@dest}/b00ce510_#{@files[1]}").should > 0
|
235
|
+
js = File.read(path)
|
236
|
+
js.include?('jQuery').should == true
|
237
|
+
js.include?('VERSION').should == false
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should run updated file through the compressor" do
|
241
|
+
@files.each_with_index do |file, i|
|
242
|
+
@output.string.include?(file).should == (i == 1 ? true : false)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should remove old version" do
|
247
|
+
Dir["#{@dest}/*.js"].length.should == 1
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe 'package removed' do
|
252
|
+
|
253
|
+
before(:all) do
|
254
|
+
SmartAsset.config['javascripts'].delete 'package'
|
255
|
+
@output = capture_stdout do
|
256
|
+
SmartAsset.compress 'javascripts'
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should delete the javascript package" do
|
261
|
+
Dir["#{@dest}/*.js"].length.should == 0
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe 'untracked file' do
|
266
|
+
|
267
|
+
before(:all) do
|
268
|
+
@modified = Time.parse('12-01-2010').utc
|
269
|
+
ENV['MODIFIED'] = @modified.to_s
|
270
|
+
@package = "#{@dest}/0fabe271_#{@files[1]}"
|
271
|
+
@untracked = "#{$root}/spec/fixtures/assets/javascripts/untracked.js"
|
272
|
+
|
273
|
+
File.open(@untracked, 'w') { |f| f.write("var untracked = true;") }
|
274
|
+
SmartAsset.config['javascripts']['package'] << 'untracked'
|
275
|
+
|
276
|
+
@output = capture_stdout do
|
277
|
+
SmartAsset.compress 'javascripts'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
after(:all) do
|
282
|
+
ENV.delete 'MODIFIED'
|
283
|
+
FileUtils.rm @untracked
|
284
|
+
FileUtils.rm @package
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should create package with default modified time" do
|
288
|
+
File.exists?(@package).should == true
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should create package with untracked file" do
|
292
|
+
File.read(@package).include?('var untracked').should == true
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should remove old version" do
|
296
|
+
Dir["#{@dest}/*.js"].length.should == 1
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe :path do
|
304
|
+
|
305
|
+
describe "development" do
|
306
|
+
|
307
|
+
before(:all) do
|
308
|
+
SmartAsset.env = 'development'
|
309
|
+
SmartAsset.load_config($root, @config)
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should return development paths" do
|
313
|
+
SmartAsset.paths('javascripts', :package).should == [
|
314
|
+
"/javascripts/jquery/jquery.js",
|
315
|
+
"/javascripts/underscore.js"
|
316
|
+
]
|
317
|
+
SmartAsset.paths('stylesheets', :package).should == [
|
318
|
+
"/stylesheets/blueprint/blueprint.css",
|
319
|
+
"/stylesheets/960.css"
|
320
|
+
]
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should leave @cache empty" do
|
324
|
+
SmartAsset.cache.should == {"javascripts"=>{}, "stylesheets"=>{}}
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
describe "production" do
|
329
|
+
|
330
|
+
before(:all) do
|
331
|
+
SmartAsset.env = 'production'
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should return compressed paths" do
|
335
|
+
SmartAsset.paths('javascripts', :package).should == [
|
336
|
+
"/compressed/#{@versions[1]}_#{@files[1]}"
|
337
|
+
]
|
338
|
+
SmartAsset.paths('stylesheets', :package).should == [
|
339
|
+
"/compressed/#{@versions[0]}_#{@files[0]}"
|
340
|
+
]
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should populate @cache" do
|
344
|
+
SmartAsset.cache.should == {"javascripts"=>
|
345
|
+
{"package"=>["/compressed/#{@versions[1]}_#{@files[1]}"]},
|
346
|
+
"stylesheets"=>
|
347
|
+
{"package"=>["/compressed/#{@versions[0]}_#{@files[0]}"]}}
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe :helper do
|
353
|
+
describe "production" do
|
354
|
+
|
355
|
+
before(:all) do
|
356
|
+
SmartAsset.env = 'production'
|
357
|
+
SmartAsset.asset_counter = nil
|
358
|
+
SmartAsset.load_config($root, @config)
|
359
|
+
end
|
360
|
+
|
361
|
+
before(:each) do
|
362
|
+
SmartAsset.cache = nil
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should output correct script tags" do
|
366
|
+
javascript_include_merged(:package, :unknown).split("\n").should == [
|
367
|
+
"<script src=\"http://assets0.host.com/compressed/#{@versions[1]}_#{@files[1]}\"></script>"
|
368
|
+
]
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should output correct style tags" do
|
372
|
+
stylesheet_link_merged(:package, :unknown).split("\n").should == [
|
373
|
+
"<link href=\"http://assets1.host.com/compressed/#{@versions[0]}_#{@files[0]}\" media=\"screen\" rel=\"stylesheet\" />"
|
374
|
+
]
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
describe "development" do
|
379
|
+
|
380
|
+
before(:all) do
|
381
|
+
SmartAsset.env = 'development'
|
382
|
+
SmartAsset.load_config($root, @config)
|
383
|
+
end
|
384
|
+
|
385
|
+
before(:each) do
|
386
|
+
SmartAsset.cache = nil
|
387
|
+
end
|
388
|
+
|
389
|
+
it "should output correct script tags for a package" do
|
390
|
+
js = javascript_include_merged(:package, :unknown).split("\n")
|
391
|
+
js[0].should =~ /<script src="\/javascripts\/jquery\/jquery\.js\?\d+"><\/script>/
|
392
|
+
js[1].should =~ /<script src="\/javascripts\/underscore\.js\?\d+"><\/script>/
|
393
|
+
end
|
394
|
+
|
395
|
+
it "should output correct style tags" do
|
396
|
+
css = stylesheet_link_merged(:package, :unknown, :media => 'print').split("\n")
|
397
|
+
css[0].should =~ /<link href="\/stylesheets\/blueprint\/blueprint\.css\?\d+" media="print" rel="stylesheet" \/>/
|
398
|
+
css[1].should =~ /<link href="\/stylesheets\/960\.css\?\d+" media="print" rel="stylesheet" \/>/
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|