spec/server/rack/asset_files_spec.rb in volt-0.9.4 vs spec/server/rack/asset_files_spec.rb in volt-0.9.5.pre1

- old
+ new

@@ -1,8 +1,10 @@ if RUBY_PLATFORM != 'opal' require 'spec_helper' require 'volt/server/rack/asset_files' + require 'volt/server/template_handlers/sprockets_component_handler' + describe Volt::AssetFiles do before do spec_app_root = File.join(File.dirname(__FILE__), '../../apps/file_loading') @component_paths = Volt::ComponentPaths.new(spec_app_root) @@ -17,34 +19,34 @@ describe 'js files' do context "when the component's dependencies.rb does not contain .disable_auto_import" do it 'should list all JS files' do main = Volt::AssetFiles.new('main', @component_paths) - expect(main.javascript_files(nil)).to eq([ - '/assets/js/jquery-2.0.3.js', - '/assets/js/volt_js_polyfills.js', - '/assets/js/volt_watch.js', - '/assets/js/bootstrap.js', - '/assets/js/test2.js', - '/assets/js/test3.js', - '/assets/js/test1.js', - '/assets/volt/volt/app.js', - '/components/main.js' + expect(main.javascript(volt_app)).to eq([ + [:src, '/assets/js/jquery-2.0.3.js'], + [:src, '/assets/js/volt_js_polyfills.js'], + [:src, '/assets/js/volt_watch.js'], + [:src, '/assets/js/bootstrap.js'], + [:src, '/assets/js/test2.js'], + [:src, '/assets/js/test3.js'], + [:src, '/assets/js/test1.js'], + [:src, '/assets/volt/volt/app.js'], + [:src, '/assets/components/main.js'] ]) end end - + context "when the component's dependencies.rb contains .disable_auto_import" do it 'should list only the files included via the css_file helpers' do disabled_auto = Volt::AssetFiles.new('disable_auto', @component_paths) - expect(disabled_auto.javascript_files(nil)).to eq([ - '/assets/js/jquery-2.0.3.js', - '/assets/js/volt_js_polyfills.js', - '/assets/js/volt_watch.js', - '/assets/disable_auto/assets/js/test1.js', - '/assets/volt/volt/app.js', - '/components/main.js' + expect(disabled_auto.javascript(volt_app)).to eq([ + [:src, '/assets/js/jquery-2.0.3.js'], + [:src, '/assets/js/volt_js_polyfills.js'], + [:src, '/assets/js/volt_watch.js'], + [:src, '/assets/disable_auto/assets/js/test1.js'], + [:src, '/assets/volt/volt/app.js'], + [:src, '/assets/components/main.js'] ]) end end end @@ -52,11 +54,11 @@ context "when the component's dependencies.rb does not contain .disable_auto_import" do it 'should list all the asset files in that component' do main = Volt::AssetFiles.new('main', @component_paths) - expect(main.css_files).to eq([ + expect(main.css).to eq([ '/assets/css/notices.css', '/assets/css/01-bootstrap.css', '/assets/css/test3.css' ]) end @@ -64,43 +66,43 @@ context "when the component's dependencies.rb contains .disable_auto_import" do it 'should list only the files included via the css_file helpers' do disabled_auto = Volt::AssetFiles.new('disable_auto', @component_paths) - expect(disabled_auto.css_files).to eq([ + expect(disabled_auto.css).to eq([ '/assets/css/notices.css', '/assets/disable_auto/assets/css/test1.css' ]) end end end - + describe '.is_url?' do it 'should return true for URIs like //something.com/something.js' do main = Volt::AssetFiles.new('main', @component_paths) expect(main.url_or_path? '//something.com/a-folder/something.js').to eq(true) end - + it 'should return true for HTTP and HTTPS urls' do main = Volt::AssetFiles.new('main', @component_paths) expect(main.url_or_path? 'http://something.com/a-folder/something.js').to eq(true) expect(main.url_or_path? 'https://something.com/a-folder/something.js').to eq(true) end - + it 'should return true for paths' do main = Volt::AssetFiles.new('main', @component_paths) expect(main.url_or_path? 'something.js').to eq(false) expect(main.url_or_path? '/assets/something.js').to eq(true) expect(main.url_or_path? '/assets/something/something.js').to eq(true) end - + it 'should return false for file names' do main = Volt::AssetFiles.new('main', @component_paths) expect(main.url_or_path? 'something.js').to eq(false) expect(main.url_or_path? 'assets/something/something.js').to eq(false) end - + end it 'should raise an exception for a missing component gem' do main = Volt::AssetFiles.new('main', @component_paths) @@ -118,8 +120,16 @@ path_to_main = File.join(File.dirname(__FILE__), '../../apps/file_loading/app/main') path_to_missing_deps = File.join(File.dirname(__FILE__), path_to_main) expect do main.load_dependencies(path_to_missing_deps, 'component_name') end.to_not raise_error + end + + it 'should parse javascript src/body from the javascript tags' do + main = Volt::AssetFiles.new('main', @component_paths) + + expect(main).to receive(:javascript_tags).and_return("<script src='/someurl.js'></script><script>var inlinejs = true;</script>") + + expect(main.javascript(nil)).to eq([[:src, "/someurl.js"], [:body, "var inlinejs = true;"]]) end end end