[DRE-commits] [ruby-sprockets-rails] 01/04: Imported Upstream version 2.0.1
Christian Hofstaedtler
zeha at moszumanska.debian.org
Thu Jan 16 10:50:25 UTC 2014
This is an automated email from the git hooks/post-receive script.
zeha pushed a commit to branch master
in repository ruby-sprockets-rails.
commit b550806b40c7fb00505c8bceb6e8d6fce15071ff
Author: Christian Hofstaedtler <zeha at debian.org>
Date: Thu Jan 16 11:42:12 2014 +0100
Imported Upstream version 2.0.1
---
.gitignore | 3 +
.travis.yml | 12 ++
CHANGELOG.md | 16 ++
Gemfile | 6 +
LICENSE | 20 ++
README.md | 4 +-
Rakefile | 9 +
checksums.yaml.gz | Bin 269 -> 0 bytes
lib/sprockets/rails/helper.rb | 9 +-
lib/sprockets/rails/task.rb | 3 +-
lib/sprockets/railtie.rb | 4 +-
metadata.yml | 105 -----------
sprockets-rails.gemspec | 18 ++
test/fixtures/bar.css | 1 +
test/fixtures/bar.js | 1 +
test/fixtures/dependency.css | 1 +
test/fixtures/dependency.js | 1 +
test/fixtures/file1.css | 2 +
test/fixtures/file1.js | 1 +
test/fixtures/file2.css | 2 +
test/fixtures/file2.js | 1 +
test/fixtures/foo.css | 1 +
test/fixtures/foo.js | 1 +
test/fixtures/url.css.erb | 1 +
test/fixtures/url.js.erb | 1 +
test/gemfiles/Gemfile.rails-3.0.x | 5 +
test/gemfiles/Gemfile.rails-3.1.x | 7 +
test/gemfiles/Gemfile.rails-3.2.x | 7 +
test/gemfiles/Gemfile.rails-4.0.x | 5 +
test/test_helper.rb | 383 ++++++++++++++++++++++++++++++++++++++
test/test_railtie.rb | 165 ++++++++++++++++
test/test_task.rb | 114 ++++++++++++
32 files changed, 796 insertions(+), 113 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0fe058a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+Gemfile*.lock
+tmp/
+*.gem
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..e860455
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+rvm:
+ - 1.9.3
+ - 2.0.0
+
+gemfile:
+ - test/gemfiles/Gemfile.rails-3.0.x
+ - test/gemfiles/Gemfile.rails-3.1.x
+ - test/gemfiles/Gemfile.rails-3.2.x
+ - test/gemfiles/Gemfile.rails-4.0.x
+
+notifications:
+ email: false
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..63ea178
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,16 @@
+### 2.0.1
+
+* Allow keep value to be specified for `assets:clean` run with args
+ for example `assets:clean[0]` will keep no old asset copies
+
+ *Richard Schneeman*
+
+* Fix `javascript_include_tag`/`stylesheet_include_tag` helpers when `debug: => false` is used.
+
+ *Guillermo Iguaran*
+
+* Fix issue when precompiling html.erb files.
+
+ Fixes #45.
+
+ *Zach Ohlgren*
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..18bde84
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,6 @@
+source 'https://rubygems.org'
+gemspec
+
+# Roll w/ branch until 4.0 is cut
+gem 'actionpack', :github => 'rails/rails', branch: '4-0-stable'
+gem 'railties', :github => 'rails/rails', branch: '4-0-stable'
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..3e97500
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Joshua Peek
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
index b8f4cb5..353ea0f 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ end
Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.
-Also see [Sprockest::Rails::Task](https://github.com/josh/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb).
+Also see [Sprockets::Rails::Task](https://github.com/josh/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb).
### Initializer options
@@ -83,7 +83,7 @@ Enable expanded asset debugging mode. Individual files will be served to make re
**`config.assets.compile`**
-Enables Sprockest compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`.
+Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`.
**`config.assets.configure`**
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..ff3d2d8
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,9 @@
+require 'rake/testtask'
+
+require 'bundler/gem_tasks'
+
+task :default => :test
+
+task :test do
+ exec "testrb test/test_*.rb"
+end
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
deleted file mode 100644
index c8c40ee..0000000
Binary files a/checksums.yaml.gz and /dev/null differ
diff --git a/lib/sprockets/rails/helper.rb b/lib/sprockets/rails/helper.rb
index 571cd7d..e4be18e 100644
--- a/lib/sprockets/rails/helper.rb
+++ b/lib/sprockets/rails/helper.rb
@@ -7,6 +7,7 @@ module Sprockets
module Helper
if defined? ActionView::Helpers::AssetUrlHelper
include ActionView::Helpers::AssetUrlHelper
+ include ActionView::Helpers::AssetTagHelper
else
require 'sprockets/rails/legacy_asset_tag_helper'
require 'sprockets/rails/legacy_asset_url_helper'
@@ -22,7 +23,7 @@ module Sprockets
klass.class_eval do
alias_method :assets_environment, :environment
def assets_manifest; end
- class_attribute :config, :assets_prefix, :digest_assets
+ class_attribute :config, :assets_prefix, :digest_assets, :debug_assets
end
else
klass.class_attribute(*VIEW_ACCESSORS)
@@ -85,7 +86,7 @@ module Sprockets
def javascript_include_tag(*sources)
options = sources.extract_options!.stringify_keys
- if request_debug_assets?
+ if options["debug"] != false && request_debug_assets?
sources.map { |source|
if asset = lookup_asset_for_path(source, :type => :javascript)
asset.to_a.map do |a|
@@ -107,7 +108,7 @@ module Sprockets
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
- if request_debug_assets?
+ if options["debug"] != false && request_debug_assets?
sources.map { |source|
if asset = lookup_asset_for_path(source, :type => :stylesheet)
asset.to_a.map do |a|
@@ -128,6 +129,8 @@ module Sprockets
# and replaced by source maps in Sprockets 3.x.
def request_debug_assets?
debug_assets || (defined?(controller) && controller && params[:debug_assets])
+ rescue
+ return false
end
# Internal method to support multifile debugging. Will
diff --git a/lib/sprockets/rails/task.rb b/lib/sprockets/rails/task.rb
index cf397ca..033bc00 100644
--- a/lib/sprockets/rails/task.rb
+++ b/lib/sprockets/rails/task.rb
@@ -62,7 +62,8 @@ module Sprockets
end
desc "Remove old compiled assets"
- task :clean => :environment do
+ task :clean, [:keep] => :environment do |t, args|
+ keep = Integer(args.keep || 2)
with_logger do
manifest.clean(keep)
end
diff --git a/lib/sprockets/railtie.rb b/lib/sprockets/railtie.rb
index 07669a7..fc49b37 100644
--- a/lib/sprockets/railtie.rb
+++ b/lib/sprockets/railtie.rb
@@ -36,8 +36,8 @@ end
module Sprockets
class Railtie < ::Rails::Railtie
- LOOSE_APP_ASSETS = lambda do |path, filename|
- filename =~ /app\/assets/ && !%w(.js .css).include?(File.extname(path))
+ LOOSE_APP_ASSETS = lambda do |filename, path|
+ path =~ /app\/assets/ && !%w(.js .css).include?(File.extname(filename))
end
class OrderedOptions < ActiveSupport::OrderedOptions
diff --git a/metadata.yml b/metadata.yml
deleted file mode 100644
index 02e0cce..0000000
--- a/metadata.yml
+++ /dev/null
@@ -1,105 +0,0 @@
---- !ruby/object:Gem::Specification
-name: sprockets-rails
-version: !ruby/object:Gem::Version
- version: 2.0.0
-platform: ruby
-authors:
-- Joshua Peek
-autorequire:
-bindir: bin
-cert_chain: []
-date: 2013-06-11 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
- name: sprockets
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: '2.8'
- type: :runtime
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: '2.8'
-- !ruby/object:Gem::Dependency
- name: actionpack
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '3.0'
- type: :runtime
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '3.0'
-- !ruby/object:Gem::Dependency
- name: activesupport
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '3.0'
- type: :runtime
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '3.0'
-- !ruby/object:Gem::Dependency
- name: rake
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '0'
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '0'
-description:
-email: josh at joshpeek.com
-executables: []
-extensions: []
-extra_rdoc_files: []
-files:
-- README.md
-- lib/sprockets/rails/helper.rb
-- lib/sprockets/rails/legacy_asset_tag_helper.rb
-- lib/sprockets/rails/legacy_asset_url_helper.rb
-- lib/sprockets/rails/task.rb
-- lib/sprockets/rails.rb
-- lib/sprockets/railtie.rb
-homepage: https://github.com/rails/sprockets-rails
-licenses: []
-metadata: {}
-post_install_message:
-rdoc_options: []
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '0'
-required_rubygems_version: !ruby/object:Gem::Requirement
- requirements:
- - - '>='
- - !ruby/object:Gem::Version
- version: '0'
-requirements: []
-rubyforge_project:
-rubygems_version: 2.0.2
-signing_key:
-specification_version: 4
-summary: Sprockets Rails integration
-test_files: []
diff --git a/sprockets-rails.gemspec b/sprockets-rails.gemspec
new file mode 100644
index 0000000..abaeb04
--- /dev/null
+++ b/sprockets-rails.gemspec
@@ -0,0 +1,18 @@
+Gem::Specification.new do |s|
+ s.name = "sprockets-rails"
+ s.version = "2.0.1"
+
+ s.homepage = "https://github.com/rails/sprockets-rails"
+ s.summary = "Sprockets Rails integration"
+ s.license = "MIT"
+
+ s.files = Dir["README.md", "lib/**/*.rb", "LICENSE"]
+
+ s.add_dependency "sprockets", "~> 2.8"
+ s.add_dependency "actionpack", ">= 3.0"
+ s.add_dependency "activesupport", ">= 3.0"
+ s.add_development_dependency "rake"
+
+ s.author = "Joshua Peek"
+ s.email = "josh at joshpeek.com"
+end
diff --git a/test/fixtures/bar.css b/test/fixtures/bar.css
new file mode 100644
index 0000000..7112e1a
--- /dev/null
+++ b/test/fixtures/bar.css
@@ -0,0 +1 @@
+/*= require foo */
diff --git a/test/fixtures/bar.js b/test/fixtures/bar.js
new file mode 100644
index 0000000..862ddf7
--- /dev/null
+++ b/test/fixtures/bar.js
@@ -0,0 +1 @@
+//= require foo
diff --git a/test/fixtures/dependency.css b/test/fixtures/dependency.css
new file mode 100644
index 0000000..5692954
--- /dev/null
+++ b/test/fixtures/dependency.css
@@ -0,0 +1 @@
+/* dependency */
diff --git a/test/fixtures/dependency.js b/test/fixtures/dependency.js
new file mode 100644
index 0000000..56c62e7
--- /dev/null
+++ b/test/fixtures/dependency.js
@@ -0,0 +1 @@
+// dependency
diff --git a/test/fixtures/file1.css b/test/fixtures/file1.css
new file mode 100644
index 0000000..7a886d5
--- /dev/null
+++ b/test/fixtures/file1.css
@@ -0,0 +1,2 @@
+/*= require dependency
+ */
diff --git a/test/fixtures/file1.js b/test/fixtures/file1.js
new file mode 100644
index 0000000..6f8f76c
--- /dev/null
+++ b/test/fixtures/file1.js
@@ -0,0 +1 @@
+//= require dependency
diff --git a/test/fixtures/file2.css b/test/fixtures/file2.css
new file mode 100644
index 0000000..7a886d5
--- /dev/null
+++ b/test/fixtures/file2.css
@@ -0,0 +1,2 @@
+/*= require dependency
+ */
diff --git a/test/fixtures/file2.js b/test/fixtures/file2.js
new file mode 100644
index 0000000..6f8f76c
--- /dev/null
+++ b/test/fixtures/file2.js
@@ -0,0 +1 @@
+//= require dependency
diff --git a/test/fixtures/foo.css b/test/fixtures/foo.css
new file mode 100644
index 0000000..33afbeb
--- /dev/null
+++ b/test/fixtures/foo.css
@@ -0,0 +1 @@
+.foo {}
diff --git a/test/fixtures/foo.js b/test/fixtures/foo.js
new file mode 100644
index 0000000..be40f8a
--- /dev/null
+++ b/test/fixtures/foo.js
@@ -0,0 +1 @@
+var Foo;
\ No newline at end of file
diff --git a/test/fixtures/url.css.erb b/test/fixtures/url.css.erb
new file mode 100644
index 0000000..e9b8e46
--- /dev/null
+++ b/test/fixtures/url.css.erb
@@ -0,0 +1 @@
+p { background: url(<%= image_path "logo.png" %>); }
diff --git a/test/fixtures/url.js.erb b/test/fixtures/url.js.erb
new file mode 100644
index 0000000..c551834
--- /dev/null
+++ b/test/fixtures/url.js.erb
@@ -0,0 +1 @@
+var url = '<%= javascript_path :foo %>';
diff --git a/test/gemfiles/Gemfile.rails-3.0.x b/test/gemfiles/Gemfile.rails-3.0.x
new file mode 100644
index 0000000..b54225e
--- /dev/null
+++ b/test/gemfiles/Gemfile.rails-3.0.x
@@ -0,0 +1,5 @@
+source 'https://rubygems.org'
+gemspec :path => "./../.."
+
+gem "actionpack", "~> 3.0.0"
+gem "railties", "~> 3.0.0"
diff --git a/test/gemfiles/Gemfile.rails-3.1.x b/test/gemfiles/Gemfile.rails-3.1.x
new file mode 100644
index 0000000..1ee643c
--- /dev/null
+++ b/test/gemfiles/Gemfile.rails-3.1.x
@@ -0,0 +1,7 @@
+source 'https://rubygems.org'
+gemspec :path => "./../.."
+
+# Patch 3-1-stable to allow new sprockets
+gem "actionpack", "~> 3.1.0", :github => "josh/rails", :branch => "3-1-stable-sprockets"
+gem "railties", "~> 3.1.0", :github => "josh/rails", :branch => "3-1-stable-sprockets"
+gem "tzinfo"
diff --git a/test/gemfiles/Gemfile.rails-3.2.x b/test/gemfiles/Gemfile.rails-3.2.x
new file mode 100644
index 0000000..030d1b4
--- /dev/null
+++ b/test/gemfiles/Gemfile.rails-3.2.x
@@ -0,0 +1,7 @@
+source 'https://rubygems.org'
+gemspec :path => "./../.."
+
+# Patch 3-2-stable to allow new sprockets
+gem "actionpack", "~> 3.2.0", :github => "josh/rails", :branch => "3-2-stable-sprockets"
+gem "railties", "~> 3.2.0", :github => "josh/rails", :branch => "3-2-stable-sprockets"
+gem "tzinfo"
diff --git a/test/gemfiles/Gemfile.rails-4.0.x b/test/gemfiles/Gemfile.rails-4.0.x
new file mode 100644
index 0000000..e16d6be
--- /dev/null
+++ b/test/gemfiles/Gemfile.rails-4.0.x
@@ -0,0 +1,5 @@
+source 'https://rubygems.org'
+gemspec :path => "./../.."
+
+gem "actionpack", "~> 4.0.0"
+gem "railties", "~> 4.0.0"
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000..296c6e7
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,383 @@
+require 'test/unit'
+
+require 'action_view'
+require 'sprockets'
+require 'sprockets/rails/helper'
+
+class HelperTest < Test::Unit::TestCase
+ FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
+
+ # class ActionView::Base
+ # include ::Sprockets::Rails::Helper
+ # end
+
+ def setup
+ assets = @assets = Sprockets::Environment.new
+ @assets.append_path FIXTURES_PATH
+ @assets.context_class.class_eval do
+ include ::Sprockets::Rails::Helper
+ end
+
+ @view = ActionView::Base.new
+ @view.extend ::Sprockets::Rails::Helper
+ @view.assets_environment = @assets
+ @view.assets_prefix = "/assets"
+
+ # Rails 2.x
+ unless @view.respond_to?(:config)
+ @view.class_eval { attr_accessor :config }
+ @view.config = Struct.new(:asset_host).new
+ end
+
+ @assets.context_class.assets_prefix = @view.assets_prefix
+ @assets.context_class.config = @view.config
+
+ @foo_js_digest = @assets['foo.js'].digest
+ @foo_css_digest = @assets['foo.css'].digest
+ end
+
+ def test_truth
+ end
+end
+
+class NoHostHelperTest < HelperTest
+ def test_javascript_include_tag
+ assert_equal %(<script src="/javascripts/static.js"></script>),
+ @view.javascript_include_tag("static")
+ assert_equal %(<script src="/javascripts/static.js"></script>),
+ @view.javascript_include_tag("static.js")
+ assert_equal %(<script src="/javascripts/static.js"></script>),
+ @view.javascript_include_tag(:static)
+
+ assert_equal %(<script src="/elsewhere.js"></script>),
+ @view.javascript_include_tag("/elsewhere.js")
+ assert_equal %(<script src="/script1.js"></script>\n<script src="/javascripts/script2.js"></script>),
+ @view.javascript_include_tag("/script1.js", "script2.js")
+
+ assert_equal %(<script src="http://example.com/script"></script>),
+ @view.javascript_include_tag("http://example.com/script")
+ assert_equal %(<script src="http://example.com/script.js"></script>),
+ @view.javascript_include_tag("http://example.com/script.js")
+ assert_equal %(<script src="//example.com/script.js"></script>),
+ @view.javascript_include_tag("//example.com/script.js")
+
+ assert_equal %(<script defer="defer" src="/javascripts/static.js"></script>),
+ @view.javascript_include_tag("static", :defer => "defer")
+ assert_equal %(<script async="async" src="/javascripts/static.js"></script>),
+ @view.javascript_include_tag("static", :async => "async")
+ end
+
+ def test_stylesheet_link_tag
+ assert_equal %(<link href="/stylesheets/static.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("static")
+ assert_equal %(<link href="/stylesheets/static.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("static.css")
+ assert_equal %(<link href="/stylesheets/static.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:static)
+
+ assert_equal %(<link href="/elsewhere.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("/elsewhere.css")
+ assert_equal %(<link href="/style1.css" media="screen" rel="stylesheet" />\n<link href="/stylesheets/style2.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("/style1.css", "style2.css")
+
+ assert_equal %(<link href="http://www.example.com/styles/style" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("http://www.example.com/styles/style")
+ assert_equal %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("http://www.example.com/styles/style.css")
+ assert_equal %(<link href="//www.example.com/styles/style.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("//www.example.com/styles/style.css")
+
+ assert_equal %(<link href="/stylesheets/print.css" media="print" rel="stylesheet" />),
+ @view.stylesheet_link_tag("print", :media => "print")
+ assert_equal %(<link href="/stylesheets/print.css" media="<hax>" rel="stylesheet" />),
+ @view.stylesheet_link_tag("print", :media => "<hax>")
+ end
+
+ def test_javascript_path
+ assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
+ assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js")
+ assert_equal "/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr")
+ assert_equal "/super/xmlhr.js", @view.javascript_path("/super/xmlhr")
+
+ assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1")
+ assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1")
+ assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash")
+ assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash")
+ assert_equal "/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash")
+ end
+
+ def test_stylesheet_path
+ assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank")
+ assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank.css")
+ assert_equal "/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir")
+ assert_equal "/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css")
+
+ assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1")
+ assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1")
+ assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash")
+ assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash")
+ assert_equal "/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash")
+ end
+end
+
+class RelativeHostHelperTest < HelperTest
+ def setup
+ super
+
+ @view.config.asset_host = "assets.example.com"
+ end
+
+ def test_javascript_path
+ assert_equal "//assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
+ assert_equal "//assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js")
+ assert_equal "//assets.example.com/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr")
+ assert_equal "//assets.example.com/super/xmlhr.js", @view.javascript_path("/super/xmlhr")
+
+ assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1")
+ assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1")
+ assert_equal "//assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash")
+ assert_equal "//assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash")
+ assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash")
+
+ assert_equal %(<script src="//assets.example.com/assets/foo.js"></script>),
+ @view.javascript_include_tag("foo")
+ assert_equal %(<script src="//assets.example.com/assets/foo.js"></script>),
+ @view.javascript_include_tag("foo.js")
+ assert_equal %(<script src="//assets.example.com/assets/foo.js"></script>),
+ @view.javascript_include_tag(:foo)
+ end
+
+ def test_stylesheet_path
+ assert_equal "//assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank")
+ assert_equal "//assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank.css")
+ assert_equal "//assets.example.com/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir")
+ assert_equal "//assets.example.com/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css")
+
+ assert_equal "//assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1")
+ assert_equal "//assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1")
+ assert_equal "//assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash")
+ assert_equal "//assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash")
+ assert_equal "//assets.example.com/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash")
+
+ assert_equal %(<link href="//assets.example.com/assets/foo.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo")
+ assert_equal %(<link href="//assets.example.com/assets/foo.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo.css")
+ assert_equal %(<link href="//assets.example.com/assets/foo.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:foo)
+ end
+
+ def test_asset_url
+ assert_equal "var url = '//assets.example.com/assets/foo.js';\n", @assets["url.js"].to_s
+ assert_equal "p { background: url(//assets.example.com/images/logo.png); }\n", @assets["url.css"].to_s
+ end
+end
+
+
+class NoDigestHelperTest < NoHostHelperTest
+ def setup
+ super
+ @view.digest_assets = false
+ @assets.context_class.digest_assets = false
+ end
+
+ def test_javascript_include_tag
+ super
+
+ assert_equal %(<script src="/assets/foo.js"></script>),
+ @view.javascript_include_tag("foo")
+ assert_equal %(<script src="/assets/foo.js"></script>),
+ @view.javascript_include_tag("foo.js")
+ assert_equal %(<script src="/assets/foo.js"></script>),
+ @view.javascript_include_tag(:foo)
+ end
+
+ def test_stylesheet_link_tag
+ super
+
+ assert_equal %(<link href="/assets/foo.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo")
+ assert_equal %(<link href="/assets/foo.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo.css")
+ assert_equal %(<link href="/assets/foo.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:foo)
+ end
+
+ def test_javascript_path
+ super
+
+ assert_equal "/assets/foo.js", @view.javascript_path("foo")
+ end
+
+ def test_stylesheet_path
+ super
+
+ assert_equal "/assets/foo.css", @view.stylesheet_path("foo")
+ end
+
+ def test_asset_digest
+ assert_equal nil, @view.asset_digest("foo.js")
+ assert_equal nil, @view.asset_digest("foo.css")
+ end
+
+ def test_asset_url
+ assert_equal "var url = '/assets/foo.js';\n", @assets["url.js"].to_s
+ assert_equal "p { background: url(/images/logo.png); }\n", @assets["url.css"].to_s
+ end
+end
+
+class DigestHelperTest < NoHostHelperTest
+ def setup
+ super
+ @view.digest_assets = true
+ @assets.context_class.digest_assets = true
+ end
+
+ def test_javascript_include_tag
+ super
+
+ assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>),
+ @view.javascript_include_tag("foo")
+ assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>),
+ @view.javascript_include_tag("foo.js")
+ assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>),
+ @view.javascript_include_tag(:foo)
+ end
+
+ def test_stylesheet_link_tag
+ super
+
+ assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo")
+ assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo.css")
+ assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:foo)
+ end
+
+ def test_javascript_path
+ super
+
+ assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo")
+ end
+
+ def test_stylesheet_path
+ super
+
+ assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo")
+ end
+
+ def test_asset_digest
+ assert_equal @foo_js_digest, @view.asset_digest("foo.js")
+ assert_equal @foo_css_digest, @view.asset_digest("foo.css")
+ end
+
+ def test_asset_digest_path
+ assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js")
+ assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css")
+ end
+
+ def test_asset_url
+ assert_equal "var url = '/assets/foo-#{@foo_js_digest}.js';\n", @assets["url.js"].to_s
+ assert_equal "p { background: url(/images/logo.png); }\n", @assets["url.css"].to_s
+ end
+end
+
+class DebugHelperTest < NoHostHelperTest
+ def setup
+ super
+ @view.debug_assets = true
+ end
+
+ def test_javascript_include_tag
+ super
+
+ assert_equal %(<script src="/assets/foo.js?body=1"></script>),
+ @view.javascript_include_tag(:foo)
+ assert_equal %(<script src="/assets/foo.js?body=1"></script>\n<script src="/assets/bar.js?body=1"></script>),
+ @view.javascript_include_tag(:bar)
+ assert_equal %(<script src="/assets/dependency.js?body=1"></script>\n<script src="/assets/file1.js?body=1"></script>\n<script src="/assets/file2.js?body=1"></script>),
+ @view.javascript_include_tag(:file1, :file2)
+ end
+
+ def test_stylesheet_link_tag
+ super
+
+ assert_equal %(<link href="/assets/foo.css?body=1" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:foo)
+ assert_equal %(<link href="/assets/foo.css?body=1" media="screen" rel="stylesheet" />\n<link href="/assets/bar.css?body=1" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:bar)
+ assert_equal %(<link href="/assets/dependency.css?body=1" media="screen" rel="stylesheet" />\n<link href="/assets/file1.css?body=1" media="screen" rel="stylesheet" />\n<link href="/assets/file2.css?body=1" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:file1, :file2)
+ end
+
+ def test_javascript_path
+ super
+
+ assert_equal "/assets/foo.js", @view.javascript_path("foo")
+ end
+
+ def test_stylesheet_path
+ super
+
+ assert_equal "/assets/foo.css", @view.stylesheet_path("foo")
+ end
+end
+
+class ManifestHelperTest < NoHostHelperTest
+ def setup
+ super
+
+ @manifest = Sprockets::Manifest.new(@assets, FIXTURES_PATH)
+ @manifest.assets["foo.js"] = "foo-#{@foo_js_digest}.js"
+ @manifest.assets["foo.css"] = "foo-#{@foo_css_digest}.css"
+
+ @view.digest_assets = true
+ @view.assets_environment = nil
+ @view.assets_manifest = @manifest
+ end
+
+ def test_javascript_include_tag
+ super
+
+ assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>),
+ @view.javascript_include_tag("foo")
+ assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>),
+ @view.javascript_include_tag("foo.js")
+ assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>),
+ @view.javascript_include_tag(:foo)
+ end
+
+ def test_stylesheet_link_tag
+ super
+
+ assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo")
+ assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag("foo.css")
+ assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />),
+ @view.stylesheet_link_tag(:foo)
+ end
+
+ def test_javascript_path
+ super
+
+ assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo")
+ end
+
+ def test_stylesheet_path
+ super
+
+ assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo")
+ end
+
+ def test_asset_digest_path
+ assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js")
+ assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css")
+ end
+
+ def test_asset_digest
+ assert_equal @foo_js_digest, @view.asset_digest("foo.js")
+ assert_equal @foo_css_digest, @view.asset_digest("foo.css")
+ end
+end
diff --git a/test/test_railtie.rb b/test/test_railtie.rb
new file mode 100644
index 0000000..e94ac38
--- /dev/null
+++ b/test/test_railtie.rb
@@ -0,0 +1,165 @@
+require 'test/unit'
+require 'active_support'
+require 'active_support/testing/isolation'
+
+class TestBoot < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ ROOT = File.expand_path("../../tmp/app", __FILE__)
+ FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
+
+ attr_reader :app
+
+ def setup
+ require 'rails'
+ # Can't seem to get initialize to run w/o this
+ require 'action_controller/railtie'
+ require 'active_support/dependencies'
+ require 'tzinfo'
+
+ ENV['RAILS_ENV'] = 'test'
+
+ FileUtils.mkdir_p ROOT
+ Dir.chdir ROOT
+
+ @app = Class.new(Rails::Application)
+ # Get bitched at if you don't set these
+ @app.config.eager_load = false
+ @app.config.time_zone = 'UTC'
+ @app.config.middleware ||= Rails::Configuration::MiddlewareStackProxy.new
+ @app.config.active_support.deprecation = :notify
+ end
+
+ def test_initialize
+ app.initialize!
+ end
+end
+
+class TestRailtie < TestBoot
+ def setup
+ require 'sprockets/railtie'
+ super
+ end
+
+ def test_defaults
+ app.initialize!
+
+ assert env = app.assets
+ assert_kind_of Sprockets::Environment, env
+
+ assert_equal ROOT, env.root
+ assert_equal "test", env.version
+ assert env.cache
+ assert_equal [], env.paths
+ assert_nil env.js_compressor
+ assert_nil env.css_compressor
+ end
+
+ def test_app_asset_available_when_compile
+ assert_equal true, app.config.assets.compile
+
+ app.initialize!
+
+ assert env = app.assets
+ end
+
+ def test_app_asset_available_when_no_compile
+ app.configure do
+ config.assets.compile = false
+ end
+
+ assert_equal false, app.config.assets.compile
+
+ app.initialize!
+
+ assert env = app.assets
+ end
+
+ def test_copies_paths
+ app.configure do
+ config.assets.paths << "javascripts"
+ config.assets.paths << "stylesheets"
+ end
+ app.initialize!
+
+ assert env = app.assets
+ assert_equal ["#{ROOT}/javascripts", "#{ROOT}/stylesheets"],
+ env.paths.sort
+ end
+
+ def test_compressors
+ app.configure do
+ config.assets.js_compressor = :uglifier
+ config.assets.css_compressor = :sass
+ end
+ app.initialize!
+
+ assert env = app.assets
+ assert_equal Sprockets::UglifierCompressor, env.js_compressor
+ assert_equal Sprockets::SassCompressor, env.css_compressor
+ end
+
+ def test_version
+ app.configure do
+ config.assets.version = 'v2'
+ end
+ app.initialize!
+
+ assert env = app.assets
+ assert_equal "test-v2", env.version
+ end
+
+ def test_configure
+ app.configure do
+ config.assets.configure do |env|
+ env.append_path "javascripts"
+ end
+ config.assets.configure do |env|
+ env.append_path "stylesheets"
+ end
+ end
+ app.initialize!
+
+ assert env = app.assets
+ assert_equal ["#{ROOT}/javascripts", "#{ROOT}/stylesheets"],
+ env.paths.sort
+ end
+
+ def test_environment_is_frozen_if_caching_classes
+ app.configure do
+ config.cache_classes = true
+ end
+ app.initialize!
+
+ assert env = app.assets
+ assert_kind_of Sprockets::Index, env
+ end
+
+ def test_action_view_helper
+ app.configure do
+ config.assets.paths << FIXTURES_PATH
+ end
+ app.initialize!
+
+ assert app.assets.paths.include?(FIXTURES_PATH)
+
+ assert_equal false, ActionView::Base.debug_assets
+ assert_equal false, ActionView::Base.digest_assets
+ assert_equal "/assets", ActionView::Base.assets_prefix
+ assert_equal app.assets, ActionView::Base.assets_environment
+ assert_match %r{public/assets/manifest-.*.json}, ActionView::Base.assets_manifest.path
+
+ @view = ActionView::Base.new
+ assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
+ assert_equal "/assets/foo.js", @view.javascript_path("foo")
+ end
+
+ def test_sprockets_context_helper
+ app.initialize!
+
+ assert env = app.assets
+ assert_equal "/assets", env.context_class.assets_prefix
+ assert_equal false, env.context_class.digest_assets
+ assert_equal nil, env.context_class.config.asset_host
+ end
+end
diff --git a/test/test_task.rb b/test/test_task.rb
new file mode 100644
index 0000000..4dc53c8
--- /dev/null
+++ b/test/test_task.rb
@@ -0,0 +1,114 @@
+require 'test/unit'
+require 'tmpdir'
+
+require 'sprockets'
+require 'sprockets/rails/task'
+
+class TestTask < Test::Unit::TestCase
+ FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
+
+ def setup
+ @rake = Rake::Application.new
+ Rake.application = @rake
+
+ @assets = Sprockets::Environment.new
+ @assets.append_path FIXTURES_PATH
+
+ @dir = File.join(Dir::tmpdir, 'rails/task')
+
+ @manifest = Sprockets::Manifest.new(@assets, @dir)
+
+ @environment_ran = false
+ # Stub Rails environment task
+ @rake.define_task Rake::Task, :environment do
+ @environment_ran = true
+ end
+
+ Sprockets::Rails::Task.new do |t|
+ t.environment = @assets
+ t.manifest = @manifest
+ t.assets = ['foo.js', 'foo-modified.js']
+ t.log_level = :fatal
+ end
+ end
+
+ def teardown
+ Rake.application = nil
+
+ FileUtils.rm_rf(@dir)
+ assert Dir["#{@dir}/*"].empty?
+ end
+
+ def test_precompile
+ assert !@environment_ran
+
+ digest_path = @assets['foo.js'].digest_path
+ assert !File.exist?("#{@dir}/#{digest_path}")
+
+ @rake['assets:precompile'].invoke
+
+ assert @environment_ran
+ assert Dir["#{@dir}/manifest-*.json"].first
+ assert File.exist?("#{@dir}/#{digest_path}")
+ end
+
+ def test_clobber
+ assert !@environment_ran
+ digest_path = @assets['foo.js'].digest_path
+
+ @rake['assets:precompile'].invoke
+ assert File.exist?("#{@dir}/#{digest_path}")
+
+ assert @environment_ran
+
+ @rake['assets:clobber'].invoke
+ assert !File.exist?("#{@dir}/#{digest_path}")
+ end
+
+ def test_clean
+ assert !@environment_ran
+ digest_path = @assets['foo.js'].digest_path
+
+ @rake['assets:precompile'].invoke
+ assert File.exist?("#{@dir}/#{digest_path}")
+
+ assert @environment_ran
+
+ @rake['assets:clean'].invoke
+ assert File.exist?("#{@dir}/#{digest_path}")
+ end
+
+ def test_clean_with_keep_specified
+ assert !@environment_ran
+ path = @assets['foo.js'].pathname
+ new_path = path.join("../foo-modified.js")
+
+ FileUtils.cp(path, new_path)
+
+ assert File.exist?(new_path)
+ digest_path = @assets['foo-modified.js'].digest_path
+
+ @rake['assets:precompile'].invoke
+ assert File.exist?("#{@dir}/#{digest_path}")
+ assert @environment_ran
+
+ # clean environment
+ setup
+
+ # modify file
+ File.open(new_path, "a") {|f| f.write("var Bar;") }
+ @rake['assets:precompile'].invoke
+ old_digest_path = digest_path
+ digest_path = @assets['foo-modified.js'].digest_path
+
+ refute_equal old_digest_path, digest_path
+ assert File.exist?("#{@dir}/#{old_digest_path}")
+ assert File.exist?("#{@dir}/#{digest_path}")
+
+ @rake['assets:clean'].invoke(0)
+ assert File.exist?("#{@dir}/#{digest_path}")
+ refute File.exist?("#{@dir}/#{old_digest_path}")
+ ensure
+ FileUtils.rm(new_path) if new_path
+ end
+end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-sprockets-rails.git
More information about the Pkg-ruby-extras-commits
mailing list