Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/Dev Environment Changes #243

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
example
raws
test/precache
Gemfile.lock
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: ruby
rvm:
- "1.8.7"
- "1.9.2"
- "1.9.3"
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ group :development, :test do
gem "yui-compressor", "0.9.6"
gem "closure-compiler", "1.1.6"
gem "uglifier", "1.2.4"
gem "sass", "3.1.7"
gem "sass", "~>3.2"
end

group :development do
gem "RedCloth", "4.2.9"
gem "redgreen", "1.2.2"
gem "yard"
end
7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ desc 'Run all tests'
task :test, [:path] do |task, args|
ENV['RAILS_ENV'] = 'test'
$LOAD_PATH.unshift(File.expand_path('test'))
require 'redgreen' unless Gem::Specification.find_all_by_name('redgreen').empty?
require 'test/unit'

if args[:path]
require args[:path]
else
Expand All @@ -26,12 +25,12 @@ namespace :gem do
desc 'Build and install the jammit gem'
task :install do
sh "gem build jammit.gemspec"
sh "sudo gem install #{Dir['*.gem'].join(' ')} --local --no-ri --no-rdoc"
sh "gem install #{Dir['*.gem'].join(' ')} --local --no-ri --no-rdoc"
end

desc 'Uninstall the jammit gem'
task :uninstall do
sh "sudo gem uninstall -x jammit"
sh "gem uninstall -x jammit"
end

end
Expand Down
5 changes: 3 additions & 2 deletions bin/jammit
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby -rrubygems
#!/usr/bin/env ruby
require 'rubygems'
require 'pathname'

APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
require File.join(APP_ROOT, '../lib/jammit/command_line.rb')

Jammit::CommandLine.new
Jammit::CommandLine.new
7 changes: 6 additions & 1 deletion jammit.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)

require 'jammit/version'

Gem::Specification.new do |s|
s.name = 'jammit'
s.version = '0.6.5' # Keep version in sync with jammit.rb
s.version = Jammit::VERSION
s.date = '2011-11-30'

s.homepage = "http://documentcloud.github.com/jammit/"
Expand Down
2 changes: 0 additions & 2 deletions lib/jammit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# to all of the configuration options.
module Jammit

VERSION = "0.6.5"

ROOT = File.expand_path(File.dirname(__FILE__) + '/..')

ASSET_ROOT = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ENV['RAILS_ROOT'] || ".") unless defined?(ASSET_ROOT)
Expand Down
2 changes: 1 addition & 1 deletion lib/jammit/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ def parse_options

end

end
end
6 changes: 6 additions & 0 deletions lib/jammit/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
require 'pathname'
require 'fileutils'

# Pretty dependent on gems
unless defined? Gem
require 'rubygems'
end

# Try Uglifier.
begin
require 'uglifier'
Expand Down Expand Up @@ -44,6 +49,7 @@
# Jammit Core:
require 'jsmin'
require 'cssmin'
require 'jammit/version'
require 'jammit/jsmin_compressor'
require 'jammit/cssmin_compressor'
require 'jammit/compressor'
Expand Down
15 changes: 11 additions & 4 deletions lib/jammit/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ def initialize
# changed since their last package build.
def precache_all(output_dir=nil, base_url=nil)
output_dir ||= File.join(Jammit.public_root, Jammit.package_path)
cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) }

mtime = @force ? Time.now : nil

cacheable(:js, output_dir).each do |p|
cache(p, 'js', pack_javascripts(p), output_dir, nil, mtime)
end

cacheable(:css, output_dir).each do |p|
cache(p, 'css', pack_stylesheets(p), output_dir)
cache(p, 'css', pack_stylesheets(p), output_dir, nil, mtime)

if Jammit.embed_assets
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri)
cache(p, 'css', pack_stylesheets(p, :datauri), output_dir, :datauri, mtime)
if Jammit.mhtml_enabled
raise MissingConfiguration, "A --base-url option is required in order to generate MHTML." unless base_url
mtime = latest_mtime package_for(p, :css)[:paths]
mtime = latest_mtime package_for(p, :css)[:paths] unless @force
asset_url = "#{base_url}#{Jammit.asset_url(p, :css, :mhtml, mtime)}"
cache(p, 'css', pack_stylesheets(p, :mhtml, asset_url), output_dir, :mhtml, mtime)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/jammit/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Jammit
VERSION = "0.6.5"
end
1 change: 1 addition & 0 deletions test/fixtures/jammed/jst_test_from_cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions test/integration/test_command_line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'
require 'zlib'

class CommandLineTest < Test::Unit::TestCase
JAMMIT = "bundle exec bin/jammit"

def setup
ENV['RAILS_ROOT'] = 'test'
end

def teardown
begin
FileUtils.rm_r('test/precache')
rescue Errno::ENOENT
end
end

def test_version_and_help_can_run
assert system("#{ JAMMIT } -v > /dev/null")
assert system("#{ JAMMIT } -h > /dev/null")
end

def test_jammit_precaching
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
assert_equal PRECACHED_FILES, glob('test/precache/*')

assert_equal zlib_read('test/precache/css_test-datauri.css.gz'),
File.read('test/fixtures/jammed/css_test-datauri.css')

assert_equal zlib_read('test/precache/jst_test.js.gz'),
File.read('test/fixtures/jammed/jst_test_from_cli.js')

assert_equal zlib_read('test/precache/js_test_with_templates.js.gz'),
File.read('test/fixtures/jammed/js_test_with_templates.js')
end

def test_lazy_precaching
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
assert_equal PRECACHED_FILES, glob('test/precache/*')
mtime = File.mtime(PRECACHED_FILES.first)
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
assert_equal File.mtime(PRECACHED_FILES.first), mtime
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com --force")
new_mtime = File.mtime(PRECACHED_FILES.first)
assert new_mtime > mtime,
"#{ PRECACHED_FILES.first } mtime - #{ new_mtime } - greater than #{ mtime }"
end

def zlib_read(filename)
Zlib::GzipReader.open(filename) {|f| f.read }
end

end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Encoding.default_external = 'ascii' if defined? Encoding

require 'test/unit'
require 'logger'

ASSET_ROOT = File.expand_path(File.dirname(__FILE__))
Expand Down
35 changes: 0 additions & 35 deletions test/unit/command_line_test.rb

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/test_closure_compressor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'

class ClosureCompressorTest < Test::Unit::TestCase

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_compressor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'

class CompressorTest < Test::Unit::TestCase

Expand Down
11 changes: 9 additions & 2 deletions test/unit/test_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'

class BrokenConfigurationTest < Test::Unit::TestCase

Expand Down Expand Up @@ -26,8 +26,15 @@ def test_disabled_compression
# Nothing should change with jst.
packed = @compressor.compile_jst(glob('test/fixtures/src/*.jst'))
assert_equal packed, File.read('test/fixtures/jammed/jst_test.js')
# CSS
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
assert_equal packed, File.open('test/fixtures/jammed/css_test-uncompressed.css', 'rb') {|f| f.read }
uncompressed_css = File.read('test/fixtures/jammed/css_test-uncompressed.css')

# fun with unicode
if uncompressed_css.respond_to?(:encoding)
uncompressed_css.force_encoding("UTF-8")
end
assert_equal packed, uncompressed_css
end

def test_css_compression
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_in_the_wrong_directory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'

class WrongDirectoryTest < Test::Unit::TestCase

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_jammit_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'
require 'active_support'
require 'action_pack'
require 'action_controller'
Expand Down
6 changes: 5 additions & 1 deletion test/unit/test_jammit_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'
require 'action_pack'
require 'action_view'
require 'action_view/base'
require 'action_controller'
require 'action_controller/base'

# fix for ruby 1.9.3 compatibility with rails 2.3.14
MissingSourceFile::REGEXPS << [/^cannot load such file -- (.+)$/i, 1]

require 'action_view/test_case'
require 'jammit/controller'
require 'jammit/helper'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_packager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'
require 'zlib'

class PackagerTest < Test::Unit::TestCase
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_sass_compressor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'

class SassCompressorTest < Test::Unit::TestCase
def test_css_compression
Expand All @@ -7,4 +7,4 @@ def test_css_compression
assert_equal File.read('test/fixtures/jammed/css_test-sass.css'), packed
end

end
end
4 changes: 2 additions & 2 deletions test/unit/test_uglifier.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'

class UglifierText < Test::Unit::TestCase

Expand All @@ -21,4 +21,4 @@ def test_jst_compilation
assert packed == File.read('test/fixtures/jammed/jst_test.js')
end

end
end