mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-30 20:55:17 +01:00
Next step in upgrading Tracks to Rails 2.2. Some highlights:
* Ran rake rails:update * Added old actionwebservice framework * Updated RSpec and RSpec-Rails * Removed asset_packager plugin (not compatible, Scott no longer maintaining), and replaced with bundle_fu. See the bundle_fu README for more info. * Hacks to UJS and ARTS plugins, which are no longer supported. Probably should move off both UJS and RJS. * Hack to flashobject_helper plugin (upgrade to Rails 2.2-compatible version if/when it comes out.) * Hack to skinny-spec plugin, for Rails 2.2 compatibility. Should check for official release. * Hacks to resource_feeder plugin, for Rails 2.2 compatibility. Should check for official release (not likely) or move off it. * Addressed some deprecation warnings. More to come. * My mobile mime type hackery is no longer necessary with new Rails features. Yay! * Updated environment.rb.tmpl with changes TODO: * Restore view specs marked pending * Fix failing integration tests. * Try selenium tests. * Investigate OpenID support. * Address deprecation warnings. * Consider moving parts of environment.rb to initializers * Address annoying config.gem warning about highline gem
This commit is contained in:
parent
6d11ebd1b0
commit
35ae5fc431
394 changed files with 15184 additions and 9936 deletions
228
vendor/plugins/bundle-fu/test/functional/bundle_fu_test.rb
vendored
Normal file
228
vendor/plugins/bundle-fu/test/functional/bundle_fu_test.rb
vendored
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
||||
|
||||
require "test/unit"
|
||||
|
||||
# require "library_file_name"
|
||||
|
||||
class BundleFuTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@mock_view = MockView.new
|
||||
BundleFu.init # resets BundleFu
|
||||
end
|
||||
|
||||
def teardown
|
||||
purge_cache
|
||||
end
|
||||
|
||||
def test__bundle_js_files__should_include_js_content
|
||||
@mock_view.bundle { @@content_include_all }
|
||||
|
||||
assert_public_files_match("/javascripts/cache/bundle.js", "function js_1()")
|
||||
end
|
||||
|
||||
def test__bundle_js_files_with_asset_server_url
|
||||
@mock_view.bundle { %(<script src="https://assets.server.com/javascripts/js_1.js?1000" type="text/javascript"></script>) }
|
||||
assert_public_files_match("/javascripts/cache/bundle.js", "function js_1()")
|
||||
end
|
||||
|
||||
def test__bundle_js_files__should_use_packr
|
||||
Object.send :class_eval, <<EOF
|
||||
class ::Object::Packr
|
||||
def initialize
|
||||
end
|
||||
|
||||
def pack(content, options={})
|
||||
"PACKR!" + options.inspect
|
||||
end
|
||||
|
||||
end
|
||||
EOF
|
||||
|
||||
@mock_view.bundle() { @@content_include_all }
|
||||
assert_public_files_match("/javascripts/cache/bundle.js", "PACKR")
|
||||
purge_cache
|
||||
|
||||
@mock_view.bundle(:packr_options => {:packr_options_here => "hi_packr"}) { @@content_include_all }
|
||||
assert_public_files_match("/javascripts/cache/bundle.js", "packr_options_here", "Should include packr_options")
|
||||
|
||||
|
||||
Object.send :remove_const, "Packr"
|
||||
|
||||
end
|
||||
|
||||
def test__bundle_js_files__should_default_to_not_compressed_and_include_override_option
|
||||
@mock_view.bundle() { @@content_include_all }
|
||||
default_content = File.read(public_file("/javascripts/cache/bundle.js"))
|
||||
purge_cache
|
||||
|
||||
@mock_view.bundle(:compress => false) { @@content_include_all }
|
||||
uncompressed_content = File.read(public_file("/javascripts/cache/bundle.js"))
|
||||
purge_cache
|
||||
|
||||
@mock_view.bundle(:compress => true) { @@content_include_all }
|
||||
compressed_content = File.read(public_file("/javascripts/cache/bundle.js"))
|
||||
purge_cache
|
||||
|
||||
assert default_content.length == compressed_content.length, "Should default to compressed"
|
||||
assert uncompressed_content.length > compressed_content.length, "Didn't compress the content. (:compress => true) #{compressed_content.length}. (:compress => false) #{uncompressed_content.length}"
|
||||
end
|
||||
|
||||
def test__content_remains_same__shouldnt_refresh_cache
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
|
||||
# check to see each bundle file exists and append some text to the bottom of each file
|
||||
append_to_public_files(cache_files("bundle"), "BOGUS")
|
||||
|
||||
assert_public_files_match("/javascripts/cache/bundle.js", "BOGUS")
|
||||
assert_public_files_match("/stylesheets/cache/bundle.css", "BOGUS")
|
||||
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
|
||||
assert_public_files_match("/javascripts/cache/bundle.js", "BOGUS")
|
||||
assert_public_files_match("/stylesheets/cache/bundle.css", "BOGUS")
|
||||
end
|
||||
|
||||
def test__content_changes__should_refresh_cache
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
|
||||
# check to see each bundle file exists and append some text to the bottom of each file
|
||||
append_to_public_files(cache_files("bundle"), "BOGUS")
|
||||
assert_public_files_match(cache_files("bundle"), "BOGUS")
|
||||
|
||||
# now, pass in some new content. Make sure that the css/js files are regenerated
|
||||
@mock_view.bundle { @@content_include_all }
|
||||
assert_public_files_no_match(cache_files("bundle"), "BOGUS")
|
||||
assert_public_files_no_match(cache_files("bundle"), "BOGUS")
|
||||
end
|
||||
|
||||
def test__modified_time_differs_from_file__should_refresh_cache
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
# we're gonna hack each of them and set all the modified times to 0
|
||||
cache_files("bundle").each{|filename|
|
||||
abs_filelist_path = public_file(filename + ".filelist")
|
||||
b = BundleFu::FileList.open(abs_filelist_path)
|
||||
b.filelist.each{|entry| entry[1] = entry[1] - 100 }
|
||||
b.save_as(abs_filelist_path)
|
||||
}
|
||||
|
||||
append_to_public_files(cache_files("bundle"), "BOGUS")
|
||||
end
|
||||
|
||||
def test__content_remains_same_but_cache_files_dont_match_whats_in_content__shouldnt_refresh_cache
|
||||
# it shouldnt parse the content unless if it differed from the last request. This scenario should never exist, and if it did it would be fixed when the server reboots.
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
abs_filelist_path = public_file("/stylesheets/cache/bundle.css.filelist")
|
||||
b = BundleFu::FileList.open(abs_filelist_path)
|
||||
|
||||
@mock_view.bundle { @@content_include_all }
|
||||
b.save_as(abs_filelist_path)
|
||||
append_to_public_files(cache_files("bundle"), "BOGUS")
|
||||
|
||||
@mock_view.bundle { @@content_include_all }
|
||||
assert_public_files_match(cache_files("bundle"), "BOGUS")
|
||||
|
||||
end
|
||||
|
||||
def test__content_differs_slightly_but_cache_files_match__shouldnt_refresh_cache
|
||||
@mock_view.bundle { @@content_include_all }
|
||||
append_to_public_files(cache_files("bundle"), "BOGUS")
|
||||
@mock_view.bundle { @@content_include_all + " " }
|
||||
assert_public_files_match(cache_files("bundle"), "BOGUS")
|
||||
end
|
||||
|
||||
def test__bundle__js_only__should_output_js_include_statement
|
||||
@mock_view.bundle { @@content_include_some.split("\n").first }
|
||||
lines = @mock_view.output.split("\n")
|
||||
assert_equal(1, lines.length)
|
||||
assert_match(/javascripts/, lines.first)
|
||||
end
|
||||
|
||||
def test__bundle__css_only__should_output_css_include_statement
|
||||
@mock_view.bundle { @@content_include_some.split("\n")[2] }
|
||||
lines = @mock_view.output.split("\n")
|
||||
|
||||
assert_equal(1, lines.length)
|
||||
assert_match(/stylesheets/, lines.first)
|
||||
|
||||
end
|
||||
|
||||
def test__nonexisting_file__should_use_blank_file_created_at_0_mtime
|
||||
# dbg
|
||||
@mock_view.bundle { %q{<script src="/javascripts/non_existing_file.js?1000" type="text/javascript"></script>} }
|
||||
|
||||
assert_public_files_match(cache_files("bundle").grep(/javascripts/), "FILE READ ERROR")
|
||||
|
||||
filelist = BundleFu::FileList.open(public_file("/javascripts/cache/bundle.js.filelist"))
|
||||
assert_equal(0, filelist.filelist[0][1], "mtime for first file should be 0")
|
||||
end
|
||||
|
||||
def test__missing_cache_filelist__should_regenerate
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
append_to_public_files(cache_files("bundle"), "BOGUS")
|
||||
|
||||
# now delete the cache files
|
||||
Dir[ public_file("**/*.filelist")].each{|filename| FileUtils.rm_f filename }
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
assert_public_files_no_match(cache_files("bundle"), "BOGUS", "Should have regenerated the file, but it didn't")
|
||||
end
|
||||
|
||||
def test__bypass__should_generate_files_but_render_normal_output
|
||||
@mock_view.bundle(:bypass => true) { @@content_include_some }
|
||||
assert_public_file_exists("/stylesheets/cache/bundle.css")
|
||||
assert_public_file_exists("/stylesheets/cache/bundle.css.filelist")
|
||||
|
||||
assert_equal(@@content_include_some, @mock_view.output)
|
||||
end
|
||||
|
||||
def test__bypass_param_set__should_honor_and_store_in_session
|
||||
@mock_view.params[:bundle_fu] = "false"
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
assert_equal(@@content_include_some, @mock_view.output)
|
||||
|
||||
@mock_view.params.delete(:bundle_bypass)
|
||||
@mock_view.bundle { @@content_include_some }
|
||||
assert_equal(@@content_include_some*2, @mock_view.output)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def purge_cache
|
||||
# remove all fixtures named "bundle*"
|
||||
Dir[ public_file("**/cache") ].each{|filename| FileUtils.rm_rf filename }
|
||||
end
|
||||
|
||||
def assert_public_file_exists(filename, message=nil)
|
||||
assert_file_exists(public_file(filename), message)
|
||||
end
|
||||
|
||||
def assert_file_exists(filename, message=nil)
|
||||
assert(File.exists?(filename), message || "File #{filename} expected to exist, but didnt.")
|
||||
end
|
||||
|
||||
def assert_public_files_match(filenames, needle, message=nil)
|
||||
filenames.each{|filename|
|
||||
assert_public_file_exists(filename)
|
||||
assert_match(needle.to_regexp, File.read(public_file(filename)), message || "expected #{filename} to match #{needle}, but doesn't.")
|
||||
}
|
||||
end
|
||||
|
||||
def assert_public_files_no_match(filenames, needle, message=nil)
|
||||
filenames.each{ |filename|
|
||||
assert_public_file_exists(filename)
|
||||
assert_no_match(needle.to_regexp, File.read(public_file(filename)), message || "expected #{filename} to not match #{needle}, but does.")
|
||||
}
|
||||
end
|
||||
|
||||
def cache_files(name)
|
||||
["/javascripts/cache/#{name}.js", "/stylesheets/cache/#{name}.css"]
|
||||
end
|
||||
|
||||
def append_to_public_files(filenames, content)
|
||||
for filename in filenames
|
||||
assert_public_file_exists(filename)
|
||||
File.open(public_file(filename), "a") {|f|
|
||||
f.puts(content)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
55
vendor/plugins/bundle-fu/test/functional/css_bundle_test.rb
vendored
Normal file
55
vendor/plugins/bundle-fu/test/functional/css_bundle_test.rb
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
||||
|
||||
class CSSBundleTest < Test::Unit::TestCase
|
||||
def test__rewrite_relative_path__should_rewrite
|
||||
assert_rewrites("/stylesheets/active_scaffold/default/stylesheet.css",
|
||||
"../../../images/spinner.gif" => "/images/spinner.gif",
|
||||
"../../../images/./../images/goober/../spinner.gif" => "/images/spinner.gif"
|
||||
)
|
||||
|
||||
assert_rewrites("stylesheets/active_scaffold/default/./stylesheet.css",
|
||||
"../../../images/spinner.gif" => "/images/spinner.gif")
|
||||
|
||||
assert_rewrites("stylesheets/main.css",
|
||||
"image.gif" => "/stylesheets/image.gif")
|
||||
|
||||
assert_rewrites("/stylesheets////default/main.css",
|
||||
"..//image.gif" => "/stylesheets/image.gif")
|
||||
|
||||
assert_rewrites("/stylesheets/default/main.css",
|
||||
"/images/image.gif" => "/images/image.gif")
|
||||
end
|
||||
|
||||
def test__rewrite_relative_path__should_strip_spaces_and_quotes
|
||||
assert_rewrites("stylesheets/main.css",
|
||||
"'image.gif'" => "/stylesheets/image.gif",
|
||||
" image.gif " => "/stylesheets/image.gif"
|
||||
)
|
||||
end
|
||||
|
||||
def test__rewrite_relative_path__shouldnt_rewrite_if_absolute_url
|
||||
assert_rewrites("stylesheets/main.css",
|
||||
" 'http://www.url.com/images/image.gif' " => "http://www.url.com/images/image.gif",
|
||||
"http://www.url.com/images/image.gif" => "http://www.url.com/images/image.gif",
|
||||
"ftp://www.url.com/images/image.gif" => "ftp://www.url.com/images/image.gif"
|
||||
)
|
||||
end
|
||||
|
||||
def test__bundle_css_file__should_rewrite_relatiave_path
|
||||
bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_3.css"])
|
||||
assert_match("background-image: url(/images/background.gif)", bundled_css)
|
||||
assert_match("background-image: url(/images/groovy/background_2.gif)", bundled_css)
|
||||
end
|
||||
|
||||
def test__bundle_css_files__no_images__should_return_content
|
||||
bundled_css = BundleFu.bundle_css_files(["/stylesheets/css_1.css"])
|
||||
assert_match("css_1 { }", bundled_css)
|
||||
end
|
||||
|
||||
|
||||
def assert_rewrites(source_filename, rewrite_map)
|
||||
rewrite_map.each_pair{|source, dest|
|
||||
assert_equal(dest, BundleFu::CSSUrlRewriter.rewrite_relative_path(source_filename, source))
|
||||
}
|
||||
end
|
||||
end
|
||||
46
vendor/plugins/bundle-fu/test/functional/file_list_test.rb
vendored
Normal file
46
vendor/plugins/bundle-fu/test/functional/file_list_test.rb
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
||||
|
||||
require "test/unit"
|
||||
|
||||
# require "library_file_name"
|
||||
|
||||
class FileListTest < Test::Unit::TestCase
|
||||
def setup
|
||||
|
||||
end
|
||||
|
||||
def test__new_files__should_get_mtimes
|
||||
filename = "/javascripts/js_1.js"
|
||||
filelist = BundleFu::FileList.new([filename])
|
||||
|
||||
assert_equal(File.mtime(File.join(RAILS_ROOT, "public", filename)).to_i,filelist.filelist[0][1])
|
||||
end
|
||||
|
||||
def test__serialization
|
||||
filelist_filename = File.join(RAILS_ROOT, "public", "temp")
|
||||
filelist = BundleFu::FileList.new("/javascripts/js_1.js")
|
||||
|
||||
filelist.save_as(filelist_filename)
|
||||
filelist2 = BundleFu::FileList.open(filelist_filename)
|
||||
|
||||
assert(filelist == filelist2, "expected to be same, but differed.\n#{filelist.to_yaml}\n\n#{filelist2.to_yaml}")
|
||||
ensure
|
||||
FileUtils.rm_f(filelist_filename)
|
||||
end
|
||||
|
||||
def test__equality__same_file_and_mtime__should_equate
|
||||
filename = "/javascripts/js_1.js"
|
||||
assert BundleFu::FileList.new(filename) == BundleFu::FileList.new(filename)
|
||||
end
|
||||
|
||||
def test__equality__dif_file_and_mtime__shouldnt_equate
|
||||
filename1 = "/javascripts/js_1.js"
|
||||
filename2 = "/javascripts/js_2.js"
|
||||
assert BundleFu::FileList.new(filename1) != BundleFu::FileList.new(filename2)
|
||||
end
|
||||
|
||||
def test__clone_item
|
||||
b = BundleFu::FileList.new("/javascripts/js_1.js")
|
||||
assert b == b.clone
|
||||
end
|
||||
end
|
||||
14
vendor/plugins/bundle-fu/test/functional/js_bundle_test.rb
vendored
Normal file
14
vendor/plugins/bundle-fu/test/functional/js_bundle_test.rb
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
||||
|
||||
class JSBundleTest < Test::Unit::TestCase
|
||||
def test__bundle_js_files__bypass_bundle__should_bypass
|
||||
BundleFu.bundle_js_files
|
||||
end
|
||||
|
||||
def test__bundle_js_files__should_include_contents
|
||||
bundled_js = BundleFu.bundle_js_files(["/javascripts/js_1.js"])
|
||||
# puts bundled_js
|
||||
# function js_1
|
||||
assert_match("function js_1", bundled_js)
|
||||
end
|
||||
end
|
||||
12
vendor/plugins/bundle-fu/test/functional/js_minimizer_test.rb
vendored
Normal file
12
vendor/plugins/bundle-fu/test/functional/js_minimizer_test.rb
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
||||
|
||||
class BundleFu::JSMinimizerTest < Test::Unit::TestCase
|
||||
def test_minimize_content__should_be_less
|
||||
test_content = File.read(public_file("javascripts/js_1.js"))
|
||||
content_size = test_content.length
|
||||
minimized_size = BundleFu::JSMinimizer.minimize_content(test_content).length
|
||||
|
||||
assert(minimized_size > 0)
|
||||
assert(content_size > minimized_size)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue