Fix precompile bug when disabling fallback #8

Merged
merged 4 commits into from Nov 15, 2016
View
@@ -2,13 +2,19 @@ language: ruby
sudo: false
rvm:
- 2.0
- - 2.1
- - 2.2
- - 2.3.0
+ - 2.1.9
+ - 2.2.5
+ - 2.3.1
gemfile:
- - gemfiles/rails40x.gemfile
- - gemfiles/rails41x.gemfile
- - gemfiles/rails42x.gemfile
+ - gemfiles/sprockets_rails_2_with_sprockets_2.gemfile
+ - gemfiles/sprockets_rails_2_with_sprockets_3.gemfile
+ - gemfiles/sprockets_rails_3_with_sprockets_3.gemfile
+matrix:
+ exclude:
+ - rvm: 2.0
+ gemfile: gemfiles/sprockets_rails_3_with_sprockets_3.gemfile
+ - rvm: 2.1.9
+ gemfile: gemfiles/sprockets_rails_3_with_sprockets_3.gemfile
branches:
only:
- master
View
@@ -1,14 +1,16 @@
-appraise 'rails40x' do
- gem 'railties', '~> 4.0.0'
- gem 'sprockets-rails', '~> 2.0'
+appraise "sprockets-rails 2 with sprockets 2" do
+ gem "railties", "~> 4.0"
+ gem "sprockets-rails", "~> 2.0"
+ gem "sprockets", "~> 2.0"
end
-appraise 'rails41x' do
- gem 'railties', '~> 4.1.0'
- gem 'sprockets-rails', '~> 2.0'
+appraise "sprockets-rails 2 with sprockets 3" do
+ gem "railties", "~> 4.0"
+ gem "sprockets-rails", "~> 2.0"
+ gem "sprockets", "~> 3.0"
end
-appraise 'rails42x' do
- gem 'railties', '~> 4.2.0'
- gem 'sprockets-rails', '>= 3.0.0'
+appraise "sprockets-rails 3 with sprockets 3" do
+ gem "sprockets-rails", "~> 3.0"
+ gem "sprockets", "~> 3.0"
end
@@ -2,8 +2,9 @@
source "https://rubygems.org"
-gem "railties", "~> 4.0.0"
+gem "railties", "~> 4.0"
gem "sprockets-rails", "~> 2.0"
+gem "sprockets", "~> 2.0"
group :development, :test do
gem "pry-byebug"
@@ -2,8 +2,9 @@
source "https://rubygems.org"
-gem "railties", "~> 4.1.0"
+gem "railties", "~> 4.0"
gem "sprockets-rails", "~> 2.0"
+gem "sprockets", "~> 3.0"
group :development, :test do
gem "pry-byebug"
@@ -2,8 +2,8 @@
source "https://rubygems.org"
-gem "railties", "~> 4.2.0"
-gem "sprockets-rails", ">= 3.0.0"
+gem "sprockets-rails", "~> 3.0"
+gem "sprockets", "~> 3.0"
group :development, :test do
gem "pry-byebug"
@@ -8,7 +8,10 @@ def register(target, engine)
klass = constantize(engine)
return false if !klass.instance_of?(::Class) || registered?(target)
- @env.register_engine(target, klass)
+ args = [target, klass]
+ args << { silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
+
+ @env.register_engine(*args)
true
end
@@ -39,10 +39,10 @@ def destination_path
end
def digest_path
- resolved_path = view_context.asset_digest_path(logical_path.to_s)
- return if resolved_path.nil?
+ asset = assets.find_asset(logical_path)
+ return if asset.nil?
- ::Pathname.new(::File.join(::Rails.public_path, view_context.assets_prefix, resolved_path))
+ ::Pathname.new(::File.join(::Rails.public_path, app.config.assets.prefix, asset.digest_path))
end
def logical_path
@@ -52,13 +52,23 @@ def logical_path
private
+ def app
+ ::Rails.application
+ end
+
+ # TODO: Cache @assets by Gakubuchi::Task instance because to call #find_asset
+ # for the first time takes much time and would cause performance problem.
+ def assets
+ return @assets if @assets
+
+ @assets = app.assets || ::Sprockets::Railtie.build_environment(app)
+ @assets = @assets.cached if @assets.respond_to?(:cached)
+ @assets
+ end
+
def extract_extname(path)
extname = path.extname
extname.empty? ? extname : "#{extract_extname(path.basename(extname))}#{extname}"
end
-
- def view_context
- @view_context ||= ::ActionView::Base.new
- end
end
end
@@ -16,6 +16,9 @@
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
@@ -23,8 +23,8 @@
end
context "when specified target is already registered" do
- let(:target) { :coffee }
- let(:engine) { "Sprockets::ERBProcessor" }
+ let(:target) { :sass }
+ let(:engine) { "Sprockets::SassTemplate" }
describe "env.engines" do
subject { -> { env.engines } }
@@ -39,11 +39,11 @@
context "when specified target is not registered" do
let(:target) { :foo }
- let(:engine) { "Sprockets::ERBProcessor" }
+ let(:engine) { "Sprockets::SassTemplate" }
describe "env.engines" do
subject { -> { env.engines } }
- let(:expectation) { a_hash_including(".foo" => Sprockets::ERBProcessor) }
+ let(:expectation) { a_hash_including(".foo" => Sprockets::SassTemplate) }
it { expect(&described_method).to change(&subject).to(expectation) }
end