Skip to content

Commit

Permalink
Test railtie
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Oct 18, 2012
1 parent 3babd03 commit 884c3db
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
Gemfile.lock
tmp/
5 changes: 2 additions & 3 deletions .travis.yml
Expand Up @@ -2,9 +2,8 @@ rvm:
- 1.9.3

env:
- ACTIONPACK_VERSION=2.3.14
- ACTIONPACK_VERSION=3.0.17
- ACTIONPACK_VERSION=master
- RAILS_VERSION=3.0.17
- RAILS_VERSION=master

notifications:
email: false
6 changes: 4 additions & 2 deletions Gemfile
@@ -1,14 +1,16 @@
source :rubygems
gemspec

ENV['ACTIONPACK_VERSION'] ||= 'master'
ENV['RAILS_VERSION'] ||= 'master'

if version = ENV['ACTIONPACK_VERSION']
if version = ENV['RAILS_VERSION']
if version == 'master'
gem 'actionpack', :github => 'rails/rails'
gem 'activemodel', :github => 'rails/rails'
gem 'journey', :github => 'rails/journey'
gem 'railties', :github => 'rails/rails'
else
gem "actionpack", "~> #{version}"
gem "railties", "~> #{version}"
end
end
23 changes: 21 additions & 2 deletions lib/sprockets/railtie.rb
Expand Up @@ -41,6 +41,19 @@ def assets

module Sprockets
class Railtie < ::Rails::Railtie
LOOSE_APP_ASSETS = lambda do |path, filename|
filename =~ /app\/assets/ && !%w(.js .css).include?(File.extname(path))
end

config.assets = ActiveSupport::OrderedOptions.new
config.assets.paths = []
config.assets.prefix = "/assets"
config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
config.assets.version = ''
config.assets.debug = false
config.assets.compile = true
config.assets.digest = false

rake_tasks do |app|
require 'sprockets/rails/task'

Expand Down Expand Up @@ -71,8 +84,14 @@ class Railtie < ::Rails::Railtie
end

if app.config.assets.compile
app.routes.prepend do
mount app.assets => app.config.assets.prefix
if app.routes.respond_to?(:prepend)
app.routes.prepend do
mount app.assets => app.config.assets.prefix
end
else
app.routes.draw do
mount app.assets => app.config.assets.prefix
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sprockets-rails.gemspec
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.files = Dir["README.md", "lib/**/*.rb"]

s.add_dependency "sprockets", "~> 2.8"
s.add_dependency "actionpack", ">= 2.3"
s.add_dependency "actionpack", ">= 3.0"
s.add_development_dependency "rake"

s.author = "Joshua Peek"
Expand Down
61 changes: 61 additions & 0 deletions test/test_railtie.rb
@@ -0,0 +1,61 @@
require 'test/unit'
require 'active_support'
require 'active_support/testing/isolation'

require 'rails'
# Rails initializers depends on AC and doesn't bother requiring it
require 'action_controller/railtie'
require 'active_support/dependencies'

require 'sprockets'
require 'sprockets/railtie'

class TestRailtie < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation

ROOT = File.expand_path("../../tmp/app", __FILE__)

attr_reader :app

def setup
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_boot
app.initialize!
end

def test_defaults
app.initialize!

assert env = app.assets
assert_kind_of Sprockets::Environment, env

assert_equal ROOT, env.root
assert_equal "development-", env.version
assert env.cache
assert_equal [], env.paths
assert_nil env.js_compressor
assert_nil env.css_compressor
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
end

0 comments on commit 884c3db

Please sign in to comment.