dassets 0.14.5 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.ruby-version +1 -0
- data/Gemfile +3 -1
- data/README.md +15 -17
- data/dassets.gemspec +7 -6
- data/lib/dassets.rb +20 -18
- data/lib/dassets/asset_file.rb +14 -12
- data/lib/dassets/cache.rb +27 -33
- data/lib/dassets/config.rb +55 -51
- data/lib/dassets/engine.rb +11 -23
- data/lib/dassets/file_store.rb +27 -28
- data/lib/dassets/server.rb +27 -28
- data/lib/dassets/server/request.rb +43 -41
- data/lib/dassets/server/response.rb +93 -81
- data/lib/dassets/source.rb +13 -8
- data/lib/dassets/source_file.rb +100 -82
- data/lib/dassets/source_proxy.rb +32 -16
- data/lib/dassets/version.rb +3 -1
- data/test/helper.rb +18 -24
- data/test/support/app.rb +3 -5
- data/test/support/factory.rb +1 -2
- data/test/support/linked_source_files/linked_file.txt +0 -0
- data/test/support/source_files/linked +1 -0
- data/test/support/source_files/linked_file2.txt +1 -0
- data/test/system/rack_tests.rb +55 -59
- data/test/unit/asset_file_tests.rb +63 -59
- data/test/unit/cache_tests.rb +14 -35
- data/test/unit/config_tests.rb +53 -49
- data/test/unit/dassets_tests.rb +25 -40
- data/test/unit/engine_tests.rb +7 -43
- data/test/unit/file_store_tests.rb +33 -25
- data/test/unit/server/request_tests.rb +43 -48
- data/test/unit/server/response_tests.rb +79 -81
- data/test/unit/server_tests.rb +3 -9
- data/test/unit/source_file_tests.rb +73 -72
- data/test/unit/source_proxy_tests.rb +78 -89
- data/test/unit/source_tests.rb +58 -50
- metadata +78 -62
@@ -1,140 +1,144 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "dassets/asset_file"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require "fileutils"
|
5
|
+
require "dassets/file_store"
|
6
|
+
require "dassets/source_proxy"
|
7
7
|
|
8
8
|
class Dassets::AssetFile
|
9
|
-
|
10
9
|
class UnitTests < Assert::Context
|
11
10
|
desc "Dassets::AssetFile"
|
11
|
+
subject { @asset_file }
|
12
|
+
|
12
13
|
setup do
|
13
|
-
@asset_file = Dassets::AssetFile.new(
|
14
|
+
@asset_file = Dassets::AssetFile.new("file1.txt")
|
14
15
|
end
|
15
|
-
subject{ @asset_file }
|
16
16
|
|
17
17
|
should have_readers :digest_path, :dirname, :extname, :basename, :source_proxy
|
18
18
|
should have_imeths :digest!, :url, :href, :fingerprint, :content
|
19
19
|
should have_imeths :mtime, :size, :mime_type, :exists?, :==
|
20
20
|
|
21
21
|
should "know its digest path, dirname, extname, and basename" do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
assert_that(subject.digest_path).equals("file1.txt")
|
23
|
+
assert_that(subject.dirname).equals(".")
|
24
|
+
assert_that(subject.extname).equals(".txt")
|
25
|
+
assert_that(subject.basename).equals("file1")
|
26
26
|
end
|
27
27
|
|
28
28
|
should "use its source proxy attrs as its own" do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
assert_that(subject.mtime).equals(subject.source_proxy.mtime.httpdate)
|
30
|
+
assert_that(subject.size).equals(subject.content.bytesize)
|
31
|
+
assert_that(subject.mime_type).equals("text/plain")
|
32
|
+
assert_that(subject.response_headers)
|
33
|
+
.equals(subject.source_proxy.response_headers)
|
34
|
+
assert_that(subject.exists?).is_true
|
35
|
+
|
36
|
+
null_file = Dassets::AssetFile.new("")
|
37
|
+
assert_that(null_file.mtime).is_nil
|
38
|
+
assert_that(null_file.size).is_nil
|
39
|
+
assert_that(null_file.mime_type).is_nil
|
40
|
+
assert_that(null_file.exists?).is_false
|
41
|
+
assert_that(null_file.response_headers)
|
42
|
+
.equals(null_file.source_proxy.response_headers)
|
41
43
|
end
|
42
44
|
|
43
45
|
should "know its source proxy" do
|
44
46
|
source_proxy = subject.source_proxy
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
assert_that(source_proxy).is_not_nil
|
48
|
+
assert_that(source_proxy).is_kind_of(Dassets::SourceProxy)
|
49
|
+
assert_that(source_proxy.digest_path).equals(subject.digest_path)
|
50
|
+
assert_that(source_proxy.content_cache)
|
51
|
+
.equals(Dassets.config.content_cache)
|
52
|
+
assert_that(source_proxy.fingerprint_cache)
|
53
|
+
.equals(Dassets.config.fingerprint_cache)
|
50
54
|
end
|
51
55
|
|
52
56
|
should "have a fingerprint" do
|
53
|
-
|
57
|
+
assert_that(subject.fingerprint).is_not_nil
|
54
58
|
end
|
55
59
|
|
56
60
|
should "get its fingerprint from its source proxy if none is given" do
|
57
|
-
af = Dassets::AssetFile.new(
|
58
|
-
|
61
|
+
af = Dassets::AssetFile.new("file1.txt")
|
62
|
+
assert_that(af.fingerprint).equals(af.source_proxy.fingerprint)
|
59
63
|
end
|
60
64
|
|
61
65
|
should "know it's content" do
|
62
|
-
|
66
|
+
assert_that(subject.content).equals("file1.txt\n")
|
63
67
|
|
64
|
-
null_file = Dassets::AssetFile.new(
|
65
|
-
|
68
|
+
null_file = Dassets::AssetFile.new("")
|
69
|
+
assert_that(null_file.content).is_nil
|
66
70
|
end
|
67
71
|
|
68
72
|
should "get its content from its source proxy if no output file" do
|
69
|
-
digest_path =
|
73
|
+
digest_path = "nested/a-thing.txt.no-use"
|
70
74
|
exp_content = "thing\n\nDUMB\nUSELESS"
|
71
75
|
|
72
76
|
without_output = Dassets::AssetFile.new(digest_path)
|
73
|
-
|
77
|
+
assert_that(without_output.content).equals(exp_content)
|
74
78
|
end
|
75
79
|
|
76
|
-
should "build it's url/href from the file, fingerpint and
|
77
|
-
|
78
|
-
|
80
|
+
should "build it's url/href from the file, fingerpint, and "\
|
81
|
+
"any configured base url" do
|
82
|
+
assert_that(subject.url).matches(/^\/file1-[a-f0-9]{32}\.txt$/)
|
83
|
+
assert_that(subject.href).matches(subject.url)
|
79
84
|
|
80
|
-
nested = Dassets::AssetFile.new(
|
81
|
-
|
82
|
-
|
85
|
+
nested = Dassets::AssetFile.new("nested/file1.txt")
|
86
|
+
assert_that(nested.url).equals("/nested/file1-.txt")
|
87
|
+
assert_that(nested.href).equals(nested.url)
|
83
88
|
|
84
89
|
base_url = Factory.url
|
85
90
|
Assert.stub(Dassets.config, :base_url){ base_url }
|
86
91
|
|
87
|
-
|
88
|
-
|
92
|
+
assert_that(subject.url).matches(/^#{base_url}\/file1-[a-f0-9]{32}\.txt$/)
|
93
|
+
assert_that(subject.href).matches(subject.url)
|
89
94
|
|
90
|
-
|
91
|
-
|
95
|
+
assert_that(nested.url).equals("#{base_url}/nested/file1-.txt")
|
96
|
+
assert_that(nested.href).equals(nested.url)
|
92
97
|
end
|
93
98
|
|
94
99
|
should "not memoize its attributes" do
|
95
100
|
url1 = subject.url
|
96
101
|
url2 = subject.url
|
97
|
-
|
102
|
+
assert_that(url1).is_not(url2)
|
98
103
|
|
99
104
|
fingerprint1 = subject.fingerprint
|
100
105
|
fingerprint2 = subject.fingerprint
|
101
|
-
|
106
|
+
assert_that(fingerprint1).is_not(fingerprint2)
|
102
107
|
|
103
108
|
content1 = subject.content
|
104
109
|
content2 = subject.content
|
105
|
-
|
110
|
+
assert_that(content1).is_not(content2)
|
106
111
|
|
107
112
|
mtime1 = subject.mtime
|
108
113
|
mtime2 = subject.mtime
|
109
|
-
|
114
|
+
assert_that(mtime1).is_not(mtime2)
|
110
115
|
end
|
111
|
-
|
112
116
|
end
|
113
117
|
|
114
118
|
class DigestTests < UnitTests
|
115
119
|
desc "being digested with an output path configured"
|
120
|
+
|
116
121
|
setup do
|
117
122
|
base_url = Factory.base_url
|
118
123
|
Assert.stub(Dassets.config, :base_url){ base_url }
|
119
|
-
Dassets.config.file_store TEST_SUPPORT_PATH.join(
|
124
|
+
Dassets.config.file_store TEST_SUPPORT_PATH.join("public").to_s
|
120
125
|
|
121
126
|
@save_path = @asset_file.digest!
|
122
127
|
@outfile = Dassets.config.file_store.store_path(@asset_file.url)
|
123
128
|
end
|
129
|
+
|
124
130
|
teardown do
|
125
131
|
FileUtils.rm_rf(Dassets.config.file_store.root.to_s)
|
126
|
-
Dassets.config.file_store Dassets::
|
132
|
+
Dassets.config.file_store Dassets::NullFileStore.new
|
127
133
|
end
|
128
134
|
|
129
135
|
should "return the asset file url" do
|
130
|
-
|
136
|
+
assert_that(@save_path).equals(@outfile)
|
131
137
|
end
|
132
138
|
|
133
139
|
should "compile and write an asset file to the output path" do
|
134
|
-
|
135
|
-
|
140
|
+
assert_that(@outfile).is_a_file
|
141
|
+
assert_that(File.read(@outfile)).equals(subject.content)
|
136
142
|
end
|
137
|
-
|
138
143
|
end
|
139
|
-
|
140
144
|
end
|
data/test/unit/cache_tests.rb
CHANGED
@@ -1,53 +1,32 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
module Dassets::Cache
|
1
|
+
require "assert"
|
2
|
+
require "dassets/cache"
|
5
3
|
|
4
|
+
class Dassets::MemCache
|
6
5
|
class UnitTests < Assert::Context
|
7
|
-
desc "Dassets::
|
8
|
-
|
9
|
-
should "define an in-memory cache handler" do
|
10
|
-
assert MemCache
|
11
|
-
end
|
12
|
-
|
13
|
-
should "define a no-op cache handler" do
|
14
|
-
assert NoCache
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
class MemCacheTests < UnitTests
|
20
|
-
desc "MemCache"
|
21
|
-
setup do
|
22
|
-
@cache = MemCache.new
|
23
|
-
end
|
24
|
-
subject{ @cache }
|
6
|
+
desc "Dassets::MemCache"
|
7
|
+
subject { Dassets::MemCache.new }
|
25
8
|
|
26
9
|
should have_imeths :keys, :[], :[]=
|
27
10
|
|
28
11
|
should "cache given key/value pairs in memory" do
|
29
12
|
val = []
|
30
|
-
subject[
|
31
|
-
|
13
|
+
subject["something"] = val
|
14
|
+
assert_that(subject["something"]).is(val)
|
32
15
|
end
|
33
|
-
|
34
16
|
end
|
17
|
+
end
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
subject{ @cache }
|
19
|
+
class Dassets::NoCache
|
20
|
+
class UnitTests < Assert::Context
|
21
|
+
desc "Dassets::NoCache"
|
22
|
+
subject { Dassets::NoCache.new }
|
42
23
|
|
43
24
|
should have_imeths :keys, :[], :[]=
|
44
25
|
|
45
26
|
should "not cache given key/value pairs in memory" do
|
46
27
|
val = []
|
47
|
-
subject[
|
48
|
-
|
28
|
+
subject["something"] = val
|
29
|
+
assert_that(subject["something"]).is_not(val)
|
49
30
|
end
|
50
|
-
|
51
31
|
end
|
52
|
-
|
53
32
|
end
|
data/test/unit/config_tests.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "dassets/config"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "dassets/cache"
|
5
|
+
require "dassets/file_store"
|
6
6
|
|
7
7
|
class Dassets::Config
|
8
|
-
|
9
8
|
class UnitTests < Assert::Context
|
10
9
|
desc "Dassets::Config"
|
10
|
+
subject { @config }
|
11
|
+
|
11
12
|
setup do
|
12
13
|
@config = Dassets::Config.new
|
13
14
|
end
|
14
|
-
subject{ @config }
|
15
15
|
|
16
16
|
should have_readers :combinations
|
17
17
|
should have_imeths :reset
|
@@ -20,83 +20,83 @@ class Dassets::Config
|
|
20
20
|
should have_imeths :source, :combination, :combination?
|
21
21
|
|
22
22
|
should "reset its sources and combination on `reset`" do
|
23
|
-
|
24
|
-
|
23
|
+
assert_that(subject.sources).is_empty
|
24
|
+
assert_that(subject.combinations).is_empty
|
25
25
|
|
26
26
|
path = Factory.path
|
27
27
|
subject.source(path)
|
28
28
|
subject.combination path, [Factory.path]
|
29
|
-
|
30
|
-
|
29
|
+
assert_that(subject.sources.size).equals(1)
|
30
|
+
assert_that(subject.combinations.size).equals(1)
|
31
31
|
|
32
32
|
subject.reset
|
33
|
-
|
34
|
-
|
33
|
+
assert_that(subject.sources).is_empty
|
34
|
+
assert_that(subject.combinations).is_empty
|
35
35
|
end
|
36
36
|
|
37
37
|
should "have no base url by default" do
|
38
|
-
|
38
|
+
assert_that(subject.base_url).is_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
should "set non-nil base urls" do
|
42
42
|
url = Factory.url
|
43
43
|
subject.base_url url
|
44
|
-
|
44
|
+
assert_that(subject.base_url).equals(url)
|
45
45
|
|
46
46
|
subject.base_url(nil)
|
47
|
-
|
47
|
+
assert_that(subject.base_url).equals(url)
|
48
48
|
end
|
49
49
|
|
50
50
|
should "force set any base urls" do
|
51
51
|
url = Factory.url
|
52
52
|
subject.set_base_url url
|
53
|
-
|
53
|
+
assert_that(subject.base_url).equals(url)
|
54
54
|
|
55
55
|
subject.set_base_url(nil)
|
56
|
-
|
56
|
+
assert_that(subject.base_url).is_nil
|
57
57
|
end
|
58
58
|
|
59
59
|
should "default the file store option to a null file store" do
|
60
|
-
|
60
|
+
assert_that(subject.file_store).is_kind_of(Dassets::NullFileStore)
|
61
61
|
end
|
62
62
|
|
63
63
|
should "configure non-nil file stores" do
|
64
64
|
store_root = Factory.path
|
65
65
|
subject.file_store(store_root)
|
66
|
-
|
66
|
+
assert_that(subject.file_store.root).equals(store_root)
|
67
67
|
|
68
68
|
store = Dassets::FileStore.new(Factory.path)
|
69
69
|
subject.file_store(store)
|
70
|
-
|
70
|
+
assert_that(subject.file_store).equals(store)
|
71
71
|
|
72
72
|
subject.file_store(nil)
|
73
|
-
|
73
|
+
assert_that(subject.file_store).equals(store)
|
74
74
|
end
|
75
75
|
|
76
76
|
should "default its content cache" do
|
77
|
-
|
77
|
+
assert_that(subject.content_cache).is_instance_of(Dassets::NoCache)
|
78
78
|
end
|
79
79
|
|
80
80
|
should "configure non-nil content caches" do
|
81
|
-
cache = Dassets::
|
81
|
+
cache = Dassets::MemCache.new
|
82
82
|
subject.content_cache(cache)
|
83
|
-
|
83
|
+
assert_that(subject.content_cache).equals(cache)
|
84
84
|
|
85
85
|
subject.content_cache(nil)
|
86
|
-
|
86
|
+
assert_that(subject.content_cache).equals(cache)
|
87
87
|
end
|
88
88
|
|
89
89
|
should "default its fingerprint cache" do
|
90
|
-
assert_instance_of Dassets::
|
90
|
+
assert_instance_of Dassets::NoCache, subject.fingerprint_cache
|
91
91
|
end
|
92
92
|
|
93
93
|
should "configure non-nil fingerprint caches" do
|
94
|
-
cache = Dassets::
|
94
|
+
cache = Dassets::MemCache.new
|
95
95
|
subject.fingerprint_cache(cache)
|
96
|
-
|
96
|
+
assert_that(subject.fingerprint_cache).equals(cache)
|
97
97
|
|
98
98
|
subject.fingerprint_cache(nil)
|
99
|
-
|
99
|
+
assert_that(subject.fingerprint_cache).equals(cache)
|
100
100
|
end
|
101
101
|
|
102
102
|
should "register new sources with the `source` method" do
|
@@ -104,35 +104,39 @@ class Dassets::Config
|
|
104
104
|
filter = proc{ |paths| [] }
|
105
105
|
subject.source(path){ |s| s.filter(&filter) }
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
assert_that(subject.sources.size).equals(1)
|
108
|
+
assert_that(subject.sources.first).is_kind_of(Dassets::Source)
|
109
|
+
assert_that(subject.sources.first.path).equals(path)
|
110
|
+
assert_that(subject.sources.first.filter).equals(filter)
|
111
111
|
end
|
112
112
|
|
113
113
|
should "know its combinations and return the keyed digest path by default" do
|
114
|
-
|
115
|
-
|
114
|
+
assert_that(subject.combinations).is_kind_of(::Hash)
|
115
|
+
assert_that(subject.combinations["some/digest.path"])
|
116
|
+
.equals(["some/digest.path"])
|
116
117
|
end
|
117
118
|
|
118
119
|
should "allow registering new combinations" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
assert_that(subject.combinations["some/digest.path"])
|
121
|
+
.equals(["some/digest.path"])
|
122
|
+
exp_combination = ["some/other.path", "and/another.path"]
|
123
|
+
subject.combination "some/digest.path", exp_combination
|
124
|
+
assert_that(subject.combinations["some/digest.path"])
|
125
|
+
.equals(exp_combination)
|
126
|
+
|
127
|
+
assert_that(subject.combinations["test/digest.path"])
|
128
|
+
.equals(["test/digest.path"])
|
129
|
+
subject.combination "test/digest.path", ["some/other.path"]
|
130
|
+
assert_that(subject.combinations["test/digest.path"])
|
131
|
+
.equals(["some/other.path"])
|
127
132
|
end
|
128
133
|
|
129
|
-
should "know which digest paths are actual combinations and which are
|
130
|
-
|
134
|
+
should "know which digest paths are actual combinations and which are "\
|
135
|
+
"just pass-thrus" do
|
136
|
+
subject.combination "some/combination.path", ["some.path", "another.path"]
|
131
137
|
|
132
|
-
|
133
|
-
|
138
|
+
assert_that(subject.combination?("some/combination.path")).is_true
|
139
|
+
assert_that(subject.combination?("some/non-combo.path")).is_false
|
134
140
|
end
|
135
|
-
|
136
141
|
end
|
137
|
-
|
138
142
|
end
|