juicer 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. data/Gemfile.lock +27 -11
  2. data/History.txt +3 -0
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/juicer.rb +1 -1
  6. data/lib/juicer/install/yui_compressor_installer.rb +2 -2
  7. metadata +29 -113
  8. data/GPATH +0 -0
  9. data/GRTAGS +0 -0
  10. data/GSYMS +0 -0
  11. data/GTAGS +0 -0
  12. data/test/bin/jslint-1.0.js +0 -523
  13. data/test/bin/jslint.js +0 -523
  14. data/test/bin/rhino1_7R1.zip +0 -0
  15. data/test/bin/rhino1_7R2-RC1.jar +0 -0
  16. data/test/bin/rhino1_7R2-RC1.zip +0 -0
  17. data/test/bin/rhino1_7R3.jar +0 -0
  18. data/test/bin/rhino1_7R3.zip +0 -0
  19. data/test/bin/yuicompressor +0 -0
  20. data/test/bin/yuicompressor-2.3.5.zip +0 -0
  21. data/test/bin/yuicompressor-2.4.2.jar +0 -0
  22. data/test/bin/yuicompressor-2.4.2.zip +0 -0
  23. data/test/data/Changelog.txt +0 -10
  24. data/test/data/a.css +0 -3
  25. data/test/data/a.js +0 -5
  26. data/test/data/a1.css +0 -5
  27. data/test/data/b.css +0 -1
  28. data/test/data/b.js +0 -5
  29. data/test/data/b1.css +0 -5
  30. data/test/data/b2.css +0 -5
  31. data/test/data/c1.css +0 -3
  32. data/test/data/css/2.gif +0 -1
  33. data/test/data/css/test.css +0 -15
  34. data/test/data/css/test2.css +0 -1
  35. data/test/data/css/test3.css +0 -12
  36. data/test/data/d1.css +0 -3
  37. data/test/data/images/1.png +0 -1
  38. data/test/data/my_app.js +0 -2
  39. data/test/data/not-ok.js +0 -2
  40. data/test/data/ok.js +0 -3
  41. data/test/data/path_test.css +0 -5
  42. data/test/data/path_test2.css +0 -14
  43. data/test/data/pkg/module/moda.js +0 -2
  44. data/test/data/pkg/module/modb.js +0 -3
  45. data/test/data/pkg/pkg.js +0 -1
  46. data/test/fixtures/rhino-download.html +0 -42
  47. data/test/fixtures/yui-download.html +0 -375
  48. data/test/test_helper.rb +0 -204
  49. data/test/unit/juicer/asset/path_resolver_test.rb +0 -76
  50. data/test/unit/juicer/asset/path_test.rb +0 -376
  51. data/test/unit/juicer/cache_buster_test.rb +0 -128
  52. data/test/unit/juicer/chainable_test.rb +0 -94
  53. data/test/unit/juicer/command/install_test.rb +0 -58
  54. data/test/unit/juicer/command/list_test.rb +0 -81
  55. data/test/unit/juicer/command/merge_test.rb +0 -162
  56. data/test/unit/juicer/command/util_test.rb +0 -58
  57. data/test/unit/juicer/command/verify_test.rb +0 -48
  58. data/test/unit/juicer/css_cache_buster_test.rb +0 -122
  59. data/test/unit/juicer/datafy_test.rb +0 -37
  60. data/test/unit/juicer/dependency_resolver/css_dependency_resolver_test.rb +0 -36
  61. data/test/unit/juicer/dependency_resolver/javascript_dependency_resolver_test.rb +0 -50
  62. data/test/unit/juicer/ext/string_test.rb +0 -59
  63. data/test/unit/juicer/ext/symbol_test.rb +0 -27
  64. data/test/unit/juicer/image_embed_test.rb +0 -339
  65. data/test/unit/juicer/install/installer_base_test.rb +0 -214
  66. data/test/unit/juicer/install/jslint_installer_test.rb +0 -54
  67. data/test/unit/juicer/install/rhino_installer_test.rb +0 -57
  68. data/test/unit/juicer/install/yui_compressor_test.rb +0 -56
  69. data/test/unit/juicer/jslint_test.rb +0 -60
  70. data/test/unit/juicer/merger/base_test.rb +0 -122
  71. data/test/unit/juicer/merger/javascript_merger_test.rb +0 -74
  72. data/test/unit/juicer/merger/stylesheet_merger_test.rb +0 -262
  73. data/test/unit/juicer/minifyer/closure_compressor_test.rb +0 -107
  74. data/test/unit/juicer/minifyer/yui_compressor_test.rb +0 -133
  75. data/test/unit/juicer_test.rb +0 -1
@@ -1,204 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- begin
5
- require 'turn'
6
- rescue LoadError => err
7
- puts "Protip: Install turn gem for better test reports. #{err.message}"
8
- end
9
-
10
- Bundler.setup
11
-
12
- require 'fileutils'
13
- require 'test/unit'
14
- require 'shoulda'
15
- require 'mocha'
16
- require 'open-uri'
17
- require 'juicer'
18
-
19
- if RUBY_VERSION < "1.9"
20
- require 'redgreen' if ENV['TM_DIRECTORY'].nil?
21
- end
22
-
23
- $data_dir = File.join(File.expand_path(File.dirname(__FILE__)), "data")
24
- Juicer.send(:remove_const, :LOGGER)
25
- Juicer::LOGGER = Logger.new(StringIO.new)
26
-
27
- # Prefixes paths with the data dir
28
- def path(path)
29
- File.join($data_dir, path)
30
- end
31
-
32
- # Allow for testing of private methods inside a block:
33
- #
34
- # MyClass.publicize_methods do
35
- # assert MyClass.some_private_method
36
- # end
37
- class Class
38
- def publicize_methods
39
- saved_private_instance_methods = self.private_instance_methods
40
- self.class_eval { public(*saved_private_instance_methods) }
41
- yield
42
- self.class_eval { private(*saved_private_instance_methods) }
43
- end
44
- end
45
-
46
- #
47
- # Intercept calls to open, and return local files
48
- #
49
- module Kernel
50
- private
51
- alias juicer_original_open open # :nodoc:
52
-
53
- def open(name, *rest, &block)
54
- if name =~ /yui\.zenfs\.com/
55
- name = File.join($data_dir, "..", "bin", "yuicompressor-2.4.2.zip")
56
- elsif name =~ /http:\/\/yuilibrary\.com\/download/
57
- name = File.join($data_dir, "../fixtures/yui-download.html")
58
- elsif name =~ /http.+yuicompressor/
59
- name = File.join($data_dir, "..", "bin", "yuicompressor")
60
- elsif name =~ /http.+jslint/
61
- name = File.join($data_dir, "..", "bin", "jslint.js")
62
- elsif name =~ /ftp.+rhino(.+)\.zip/
63
- name = File.join($data_dir, "..", "bin", "rhino#{$1}.zip")
64
- elsif name =~ /ftp\.mozilla.+/
65
- name = File.join($data_dir, "../fixtures/rhino-download.html")
66
- end
67
-
68
- juicer_original_open(File.expand_path(name), *rest, &block)
69
- end
70
-
71
- module_function :open
72
- end
73
-
74
- module Juicer
75
- module Test
76
-
77
- # Alot of Juicer functionality are filesystem operations. This class sets up files
78
- # to work on
79
- class FileSetup
80
- attr_reader :file_count
81
-
82
- def initialize(dir = $data_dir)
83
- @dir = dir
84
- @file_count = 0
85
- end
86
-
87
- # Recursively deletes the data directory
88
- def delete
89
- res = FileUtils.rm_rf(@dir) if File.exist?(@dir)
90
- end
91
-
92
- # Set up files for unit tests
93
- def create(force = false)
94
- return if File.exist?(@dir) && !force
95
-
96
- delete if File.exist?(@dir)
97
- mkdir @dir
98
- mkfile(@dir, 'a.css', "@import 'b.css';\n\n/* Dette er a.css */")
99
- mkfile(@dir, 'a.js', "/**\n * @depend b.js\n */\n\n/* Dette er a.js */")
100
- mkfile(@dir, 'b.css', "/* Dette er b.css */")
101
- mkfile(@dir, 'b.js', "/**\n * @depends a.js\n */\n\n/* Dette er b.css */")
102
- mkfile(@dir, 'a1.css', "@import\t'b1.css';\n@import 'c1.css';\nbody {\n width: 800px;\n}\n")
103
- mkfile(@dir, 'b1.css', "@import url('d1.css');\n\nhtml {\n background: red;\n}\n")
104
- mkfile(@dir, 'b2.css', "@import url(\"d1.css\");\n\nhtml {\n background: red;\n}\n")
105
- mkfile(@dir, 'c1.css', "h1 {\n font-size: 12px;\n}\n")
106
- mkfile(@dir, 'd1.css', "h2 {\n font-size: 10px;\n}\n")
107
- mkfile(@dir, 'ok.js', "function hey() {\n return \"Hey\";\n}\n")
108
- mkfile(@dir, 'not-ok.js', "var a = 34\nb = 78;\n")
109
-
110
- images = mkdir File.join(@dir, "images")
111
- mkfile(images, '1.png', "")
112
-
113
- css_dir = mkdir File.join(@dir, "css")
114
- mkfile(css_dir, '2.gif', "")
115
-
116
- css = <<-CSS
117
- body {
118
- background: url(../images/1.png);
119
- }
120
-
121
- h1 {
122
- background: url('../a1.css') 0 0 no-repeat;
123
- }
124
-
125
- h2 {
126
- background: url("2.gif") no-repeat;
127
- }
128
-
129
- p {
130
- background: url(2.gif) no-repeat;
131
- }
132
- CSS
133
-
134
- mkfile(css_dir, 'test.css', css)
135
- mkfile(css_dir, 'test2.css', "body { background: url(/images/1.png); }")
136
- mkfile(@dir, 'path_test.css', "@import 'css/test.css';\n\nbody {\n background: url(css/2.gif) no-repeat;\n}\n")
137
-
138
- css = <<-CSS
139
- body {
140
- background: url(/images/1.png);
141
- }
142
-
143
- h1 {
144
- background: url(/css/2.gif);
145
- background: url(/a1.css) 0 0 no-repeat;
146
- }
147
-
148
- h2 {
149
- background: url(/css/2.gif) no-repeat;
150
- }
151
-
152
- p { background: url(/a2.css); }
153
- CSS
154
-
155
- mkfile(@dir, 'path_test2.css', css)
156
-
157
- css = <<-CSS
158
- body {
159
- background: url(http://assets1/images/1.png);
160
- }
161
-
162
- h1 {
163
- background: url(http://assets2/css/2.gif);
164
- background: url(http://assets3/a1.css) 0 0 no-repeat;
165
- }
166
-
167
- h2 {
168
- background: url(http://assets2/css/2.gif) no-repeat;
169
- }
170
- CSS
171
-
172
- mkfile(css_dir, 'test3.css', css)
173
-
174
- mkfile(@dir, 'Changelog.txt', "2008.02.09 | stb-base 1.29\n\nFEATURE: Core | Bla bla bla bla bla\nFEATURE: UI: | Bla bla bla bla bla\n\n\n2008.02.09 | stb-base 1.29\n\nFEATURE: Core | Bla bla bla bla bla\nFEATURE: UI: | Bla bla bla bla bla\n")
175
-
176
- # my_app.js depends on the pkg directory
177
- mkfile(@dir, "my_app.js", "// @depend pkg\n var myApp = pkg.a;")
178
-
179
- # package directory contains pkg.js, module/moda.js, and module/modb.js
180
- # moda.js depends on ../pkg.js
181
- # modb.js depends on moda.js and ../pkg.js
182
- pkg_dir = mkdir File.join(@dir, "pkg")
183
- module_dir = mkdir File.join(pkg_dir, "module")
184
- mkfile(pkg_dir, "pkg.js", "var pkg = {};")
185
- mkfile(module_dir, "moda.js", "// @depend ../pkg.js\npkg.a = '';")
186
- mkfile(module_dir, "modb.js", "// @depend ../pkg.js\n// @depend moda.js\npkg.b = '';")
187
-
188
- end
189
-
190
- private
191
- # Create a file
192
- def mkfile(parent, name, content)
193
- file = File.open(File.join(parent, name), 'w+') { |f| f.puts content }
194
- @file_count += 1
195
- end
196
-
197
- def mkdir(dir)
198
- FileUtils.mkdir(dir)
199
- @file_count += 1
200
- dir
201
- end
202
- end
203
- end
204
- end
@@ -1,76 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require "test_helper"
4
- require "juicer/asset/path_resolver"
5
-
6
- class AssetPathResolverTest < Test::Unit::TestCase
7
- context "initializing path resolver" do
8
- should "use current directory as base" do
9
- resolver = Juicer::Asset::PathResolver.new
10
-
11
- assert_equal Dir.pwd, resolver.base
12
- end
13
-
14
- should "ensure all hosts are complete with scheme" do
15
- resolver = Juicer::Asset::PathResolver.new :hosts => %w[localhost my.project]
16
-
17
- assert_equal %w[http://localhost http://my.project], resolver.hosts
18
- end
19
-
20
- should "set document root" do
21
- resolver = Juicer::Asset::PathResolver.new :document_root => Dir.pwd
22
-
23
- assert_equal Dir.pwd, resolver.document_root
24
- end
25
- end
26
-
27
- context "resolving path" do
28
- should "return asset object with the same options as the resolver" do
29
- resolver = Juicer::Asset::PathResolver.new :document_root => "/var/www", :hosts => ["localhost", "mysite.com"]
30
- asset = resolver.resolve("../images/logo.png")
31
-
32
- assert_equal resolver.base, asset.base
33
- assert_equal resolver.document_root, asset.document_root
34
- assert_equal resolver.hosts, asset.hosts
35
- end
36
- end
37
-
38
- context "cycling hosts" do
39
- should "return one host at a time" do
40
- resolver = Juicer::Asset::PathResolver.new :hosts => %w[localhost my.project]
41
-
42
- assert_equal "http://localhost", resolver.cycle_hosts
43
- assert_equal "http://my.project", resolver.cycle_hosts
44
- assert_equal "http://localhost", resolver.cycle_hosts
45
- end
46
-
47
- should "be aliased through host" do
48
- resolver = Juicer::Asset::PathResolver.new :hosts => %w[localhost my.project]
49
-
50
- assert_equal "http://localhost", resolver.host
51
- assert_equal "http://my.project", resolver.host
52
- assert_equal "http://localhost", resolver.host
53
- end
54
- end
55
-
56
- context "setting base" do
57
- should "update property" do
58
- resolver = Juicer::Asset::PathResolver.new
59
- new_base = "/var/www/test"
60
- resolver.base = new_base
61
-
62
- assert_equal new_base, resolver.base
63
- end
64
-
65
- should "update base option for new assets" do
66
- resolver = Juicer::Asset::PathResolver.new
67
- asset1 = resolver.resolve "css/1.css"
68
- resolver.base = "/var/www/test"
69
- asset2 = resolver.resolve "css/1.css"
70
-
71
- assert_not_equal asset1.base, asset2.base
72
- assert_not_equal asset1.base, resolver.base
73
- assert_equal asset2.base, resolver.base
74
- end
75
- end
76
- end
@@ -1,376 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require "test_helper"
4
- require "juicer/asset/path"
5
-
6
- class AssetPathTest < Test::Unit::TestCase
7
- context "initializing asset" do
8
- should "use default options" do
9
- asset = Juicer::Asset::Path.new "../images/logo.png"
10
-
11
- assert_equal Dir.pwd, asset.base
12
- assert_equal [], asset.hosts
13
- assert_nil asset.document_root
14
- end
15
-
16
- should "override options" do
17
- base = "/home/me/project/awesome-site/public/stylesheets"
18
- asset = Juicer::Asset::Path.new "../images/logo.png", :base => base
19
-
20
- assert_equal base, asset.base
21
- end
22
-
23
- should "not nil base option" do
24
- asset = Juicer::Asset::Path.new "../images/logo.png", :base => nil
25
-
26
- assert_equal Dir.pwd, asset.base
27
- end
28
-
29
- should "accept a single host" do
30
- asset = Juicer::Asset::Path.new "../images/logo.png", :hosts => "http://localhost"
31
-
32
- assert_equal ["http://localhost"], asset.hosts
33
- end
34
-
35
- should "accept array of hosts" do
36
- asset = Juicer::Asset::Path.new "../images/logo.png", :hosts => ["http://localhost", "http://dev.server"]
37
-
38
- assert_equal ["http://localhost", "http://dev.server"], asset.hosts
39
- end
40
-
41
- should "strip trailing slash in hosts" do
42
- asset = Juicer::Asset::Path.new "../images/logo.png", :hosts => ["http://localhost/", "http://dev.server"]
43
-
44
- assert_equal ["http://localhost", "http://dev.server"], asset.hosts
45
- end
46
-
47
- should "strip add scheme for hosts if missing" do
48
- asset = Juicer::Asset::Path.new "../images/logo.png", :hosts => ["localhost", "http://dev.server"]
49
-
50
- assert_equal ["http://localhost", "http://dev.server"], asset.hosts
51
- end
52
-
53
- should "strip trailing slash and add scheme in hosts" do
54
- asset = Juicer::Asset::Path.new "../images/logo.png", :hosts => ["localhost/", "http://dev.server", "some.server/"]
55
-
56
- assert_equal ["http://localhost", "http://dev.server", "http://some.server"], asset.hosts
57
- end
58
-
59
- should "accept protocol-less hosts" do
60
- asset = Juicer::Asset::Path.new "../images/logo.png", :hosts => ["localhost/", "//dev.server", "some.server/"]
61
-
62
- assert_equal ["http://localhost", "//dev.server", "http://some.server"], asset.hosts
63
- end
64
- end
65
-
66
- context "asset absolute path" do
67
- should "raise exception without document root" do
68
- asset = Juicer::Asset::Path.new "../images/logo.png"
69
-
70
- assert_raise ArgumentError do
71
- asset.absolute_path
72
- end
73
- end
74
-
75
- should "return absolute path from relative path and document root" do
76
- base = "/var/www/public/stylesheets"
77
- document_root = "/var/www/public"
78
- asset = Juicer::Asset::Path.new "../images/logo.png", :base => base, :document_root => document_root
79
-
80
- assert_equal "/images/logo.png", asset.absolute_path
81
- end
82
-
83
- should "return absolute path from absolute path" do
84
- base = "/var/www/public/stylesheets"
85
- document_root = "/var/www/public"
86
- path = "/images/logo.png"
87
- asset = Juicer::Asset::Path.new path, { :base => base, :document_root => document_root }
88
-
89
- assert_equal path, asset.absolute_path
90
- end
91
-
92
- context "with host" do
93
- setup do
94
- base = "/var/www/public/stylesheets"
95
- document_root = "/var/www/public"
96
- options = { :base => base, :document_root => document_root }
97
- @asset = Juicer::Asset::Path.new "../images/logo.png", options
98
- end
99
-
100
- should "return absolute path with host" do
101
- assert_equal "http://localhost/images/logo.png", @asset.absolute_path(:host => "http://localhost")
102
- end
103
-
104
- should "strip trailing slash from absolute path host" do
105
- assert_equal "http://localhost/images/logo.png", @asset.absolute_path(:host => "http://localhost/")
106
- end
107
-
108
- should "ensure scheme in absolute path host" do
109
- assert_equal "http://localhost/images/logo.png", @asset.absolute_path(:host => "localhost")
110
- end
111
-
112
- should "strip trailing slash and ensure scheme in absolute path host" do
113
- assert_equal "http://localhost/images/logo.png", @asset.absolute_path(:host => "localhost/")
114
- end
115
- end
116
-
117
- context "with cache buster" do
118
- setup do
119
- @filename = "tmp.asset.txt"
120
- file = File.open(@filename, "w") { |f| f.puts "Testing" }
121
- @asset = Juicer::Asset::Path.new @filename, :document_root => Dir.pwd
122
- end
123
-
124
- teardown do
125
- File.delete(@filename)
126
- end
127
-
128
- should "return URL with mtime query parameter and default parameter name" do
129
- mtime = File.mtime(@filename).to_i
130
- assert_equal "/#@filename?jcb=#{mtime}", @asset.absolute_path(:cache_buster_type => :soft)
131
- end
132
-
133
- should "return URL with mtime query parameter" do
134
- mtime = File.mtime(@filename).to_i
135
- assert_equal "/#@filename?#{mtime}", @asset.absolute_path(:cache_buster => nil)
136
- end
137
-
138
- should "return URL with mtime embedded" do
139
- mtime = File.mtime(@filename).to_i
140
- assert_equal "/#{@filename.sub(/\.txt/, '')}-jcb#{mtime}.txt", @asset.absolute_path(:cache_buster => :jcb, :cache_buster_type => :hard)
141
- end
142
- end
143
- end
144
-
145
- context "relative path" do
146
- should "return relative path from relative path" do
147
- path = "../images/logo.png"
148
- asset = Juicer::Asset::Path.new path, :base => "/var/www/public/stylesheets"
149
-
150
- assert_equal path, asset.relative_path
151
- end
152
-
153
- should "return relative path from absolute path" do
154
- path = "/images/logo.png"
155
- asset = Juicer::Asset::Path.new path, :document_root => "/var/www/public", :base => "/var/www/public/stylesheets"
156
-
157
- assert_equal "..#{path}", asset.relative_path
158
- end
159
-
160
- context "with cache buster" do
161
- setup do
162
- @filename = "tmp.asset.txt"
163
- file = File.open(@filename, "w") { |f| f.puts "Testing" }
164
- @asset = Juicer::Asset::Path.new @filename, :document_root => Dir.pwd
165
- end
166
-
167
- teardown do
168
- File.delete(@filename)
169
- end
170
-
171
- should "return URL with mtime query parameter and default parameter name" do
172
- mtime = File.mtime(@filename).to_i
173
- result = "#@filename?jcb=#{mtime}"
174
- Juicer::CacheBuster.stubs(:soft).with(File.expand_path(@filename)).returns(result)
175
-
176
- assert_equal result, @asset.relative_path(:cache_buster_type => :soft)
177
- end
178
-
179
- should "return URL with mtime query parameter" do
180
- mtime = File.mtime(@filename).to_i
181
- assert_equal "#@filename?#{mtime}", @asset.relative_path(:cache_buster => nil)
182
- end
183
-
184
- should "return URL with mtime embedded" do
185
- mtime = File.mtime(@filename).to_i
186
- assert_equal "#{@filename.sub(/\.txt/, '')}-jcb#{mtime}.txt", @asset.relative_path(:cache_buster => :jcb, :cache_buster_type => :hard)
187
- end
188
- end
189
- end
190
-
191
- context "original path" do
192
- should "preserve relative path" do
193
- path = "../images/logo.png"
194
- asset = Juicer::Asset::Path.new path
195
-
196
- assert_equal path, asset.path
197
- end
198
-
199
- should "preserve absolute path" do
200
- path = "/images/logo.png"
201
- asset = Juicer::Asset::Path.new path
202
-
203
- assert_equal path, asset.path
204
- end
205
-
206
- should "preserve absolute path with host" do
207
- path = "http://localhost/images/logo.png"
208
- asset = Juicer::Asset::Path.new path
209
-
210
- assert_equal path, asset.path
211
- end
212
-
213
- context "with cache buster" do
214
- setup do
215
- @filename = "tmp.asset.txt"
216
- file = File.open(@filename, "w") { |f| f.puts "Testing" }
217
- end
218
-
219
- teardown do
220
- File.delete(@filename)
221
- end
222
-
223
- should "return original relative path with mtime query parameter and default parameter name" do
224
- asset = Juicer::Asset::Path.new @filename, :document_root => Dir.pwd
225
- mtime = File.mtime(@filename).to_i
226
- assert_equal "#@filename?jcb=#{mtime}", asset.path(:cache_buster_type => :soft)
227
- end
228
-
229
- should "return original absolute path with mtime query parameter and default parameter name" do
230
- asset = Juicer::Asset::Path.new "/#@filename", :document_root => Dir.pwd
231
- mtime = File.mtime(@filename).to_i
232
- assert_equal "/#@filename?jcb=#{mtime}", asset.path(:cache_buster_type => :soft)
233
- end
234
- end
235
- end
236
-
237
- context "asset filename" do
238
- should "raise exception with absolute path without document root" do
239
- asset = Juicer::Asset::Path.new "/images/logo.png", :document_root => nil
240
-
241
- assert_raise ArgumentError do
242
- asset.filename
243
- end
244
- end
245
-
246
- should "raise exception with absolute path with host without document root" do
247
- asset = Juicer::Asset::Path.new "http://localhost/images/logo.png", :document_root => nil
248
-
249
- assert_raise ArgumentError do
250
- asset.filename
251
- end
252
- end
253
-
254
- should "raise exception with absolute path with host without hosts" do
255
- options = { :document_root => "/var/project" }
256
- asset = Juicer::Asset::Path.new "http://localhost/images/logo.png", options
257
-
258
- assert_raise ArgumentError do
259
- begin
260
- asset.filename
261
- rescue ArgumentError => err
262
- assert_match /No hosts served/, err.message
263
- raise err
264
- end
265
- end
266
- end
267
-
268
- should "raise exception with mismatching hosts" do
269
- options = { :document_root => "/var/project", :hosts => %w[example.com site.com] }
270
- asset = Juicer::Asset::Path.new "http://localhost/images/logo.png", options
271
-
272
- assert_raise ArgumentError do
273
- begin
274
- asset.filename
275
- rescue ArgumentError => err
276
- assert_match /No matching host/, err.message
277
- raise err
278
- end
279
- end
280
- end
281
-
282
- should "return filename from relative path and base" do
283
- asset = Juicer::Asset::Path.new "../images/logo.png", :base => "/var/www/public/stylesheets"
284
-
285
- assert_equal "/var/www/public/images/logo.png", asset.filename
286
- end
287
-
288
- should "return filename from absolute path and document root" do
289
- asset = Juicer::Asset::Path.new "/images/logo.png", :document_root => "/var/www/public"
290
-
291
- assert_equal "/var/www/public/images/logo.png", asset.filename
292
- end
293
-
294
- should "return filename from absolute path with host and document root" do
295
- asset = Juicer::Asset::Path.new "http://localhost/images/logo.png", :document_root => "/var/www/public", :hosts => "localhost"
296
-
297
- assert_equal "/var/www/public/images/logo.png", asset.filename
298
- end
299
-
300
- should "raise exception when hosts match but schemes don't" do
301
- options = { :document_root => "/var/www/public", :hosts => "http://localhost" }
302
- asset = Juicer::Asset::Path.new "https://localhost/images/logo.png", options
303
-
304
- assert_raise(ArgumentError) { asset.filename }
305
- end
306
-
307
- should "return filename from absolute path with hosts and document root" do
308
- options = { :document_root => "/var/www/public", :hosts => %w[example.com localhost https://localhost] }
309
- asset = Juicer::Asset::Path.new "https://localhost/images/logo.png", options
310
-
311
- assert_equal "/var/www/public/images/logo.png", asset.filename
312
- end
313
- end
314
-
315
- context "file helpers" do
316
- should "return file basename" do
317
- base = "/var/www/public/"
318
- asset = Juicer::Asset::Path.new "images/logo.png", :base => base
319
-
320
- assert_equal "logo.png", asset.basename
321
- end
322
-
323
- should "return file dirname" do
324
- base = "/var/www/public/"
325
- asset = Juicer::Asset::Path.new "images/logo.png", :base => base
326
-
327
- assert_equal "#{base}images", asset.dirname
328
- end
329
-
330
- should "verify that file does not exist" do
331
- base = "/var/www/public/"
332
- asset = Juicer::Asset::Path.new "images/logo.png", :base => base
333
-
334
- assert !asset.exists?
335
- end
336
-
337
- context "existing file" do
338
- setup { File.open("somefile.css", "w") { |f| f.puts "/* Test */" } }
339
- teardown { File.delete("somefile.css") }
340
-
341
- should "verify that file exists" do
342
- asset = Juicer::Asset::Path.new "somefile.css"
343
-
344
- assert asset.exists?
345
- end
346
- end
347
- end
348
-
349
- context "rebase path" do
350
- should "return new asset with shifted base" do
351
- base = "/var/www/project/public"
352
- asset = Juicer::Asset::Path.new "../images/logo.png", :base => "#{base}/stylesheets"
353
- rebased_asset = asset.rebase(base)
354
-
355
- assert_equal "images/logo.png", rebased_asset.relative_path
356
- end
357
-
358
- should "preserve all options but base context" do
359
- base = "/var/www/project/public"
360
- options = { :base => "#{base}/stylesheets", :hosts => ["localhost"], :document_root => base }
361
- asset = Juicer::Asset::Path.new "../images/logo.png", options
362
- rebased_asset = asset.rebase(base)
363
-
364
- assert_equal asset.document_root, rebased_asset.document_root
365
- assert_equal asset.hosts, rebased_asset.hosts
366
- end
367
-
368
- should "return same absolute path" do
369
- base = "/var/www/project/public"
370
- asset = Juicer::Asset::Path.new "../images/logo.png", :base => "#{base}/stylesheets", :document_root => base
371
- rebased_asset = asset.rebase(base)
372
-
373
- assert_equal asset.absolute_path, rebased_asset.absolute_path
374
- end
375
- end
376
- end