dassets 0.14.1 → 0.15.0
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.
- 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 +54 -11
- data/lib/dassets/asset_file.rb +14 -12
- data/lib/dassets/cache.rb +27 -33
- data/lib/dassets/config.rb +55 -47
- data/lib/dassets/engine.rb +11 -23
- data/lib/dassets/file_store.rb +27 -27
- 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/{public/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt → 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 +64 -60
- data/test/unit/cache_tests.rb +14 -35
- data/test/unit/config_tests.rb +65 -45
- data/test/unit/dassets_tests.rb +41 -23
- data/test/unit/engine_tests.rb +7 -43
- data/test/unit/file_store_tests.rb +42 -31
- data/test/unit/server/request_tests.rb +48 -53
- 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 -70
- data/test/support/public/file2-9bbe1047cffbb590f59e0e5aeff46ae4.txt +0 -1
- data/test/support/public/grumpy_cat-b0d1f399a916f7a25c4c0f693c619013.jpg +0 -0
- data/test/support/public/nested/a-thing.txt-7413d18f2eba9c695a880aff67fde135.no-use +0 -4
@@ -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
|
-
FileUtils.
|
126
|
-
Dassets.config.file_store Dassets::
|
131
|
+
FileUtils.rm_rf(Dassets.config.file_store.root.to_s)
|
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,122 +1,142 @@
|
|
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
|
+
should have_imeths :reset
|
17
18
|
should have_imeths :base_url, :set_base_url
|
18
19
|
should have_imeths :file_store, :content_cache, :fingerprint_cache
|
19
20
|
should have_imeths :source, :combination, :combination?
|
20
21
|
|
22
|
+
should "reset its sources and combination on `reset`" do
|
23
|
+
assert_that(subject.sources).is_empty
|
24
|
+
assert_that(subject.combinations).is_empty
|
25
|
+
|
26
|
+
path = Factory.path
|
27
|
+
subject.source(path)
|
28
|
+
subject.combination path, [Factory.path]
|
29
|
+
assert_that(subject.sources.size).equals(1)
|
30
|
+
assert_that(subject.combinations.size).equals(1)
|
31
|
+
|
32
|
+
subject.reset
|
33
|
+
assert_that(subject.sources).is_empty
|
34
|
+
assert_that(subject.combinations).is_empty
|
35
|
+
end
|
36
|
+
|
21
37
|
should "have no base url by default" do
|
22
|
-
|
38
|
+
assert_that(subject.base_url).is_nil
|
23
39
|
end
|
24
40
|
|
25
41
|
should "set non-nil base urls" do
|
26
42
|
url = Factory.url
|
27
43
|
subject.base_url url
|
28
|
-
|
44
|
+
assert_that(subject.base_url).equals(url)
|
29
45
|
|
30
46
|
subject.base_url(nil)
|
31
|
-
|
47
|
+
assert_that(subject.base_url).equals(url)
|
32
48
|
end
|
33
49
|
|
34
50
|
should "force set any base urls" do
|
35
51
|
url = Factory.url
|
36
52
|
subject.set_base_url url
|
37
|
-
|
53
|
+
assert_that(subject.base_url).equals(url)
|
38
54
|
|
39
55
|
subject.set_base_url(nil)
|
40
|
-
|
56
|
+
assert_that(subject.base_url).is_nil
|
41
57
|
end
|
42
58
|
|
43
59
|
should "default the file store option to a null file store" do
|
44
|
-
|
60
|
+
assert_that(subject.file_store).is_kind_of(Dassets::NullFileStore)
|
45
61
|
end
|
46
62
|
|
47
63
|
should "configure non-nil file stores" do
|
48
64
|
store_root = Factory.path
|
49
65
|
subject.file_store(store_root)
|
50
|
-
|
66
|
+
assert_that(subject.file_store.root).equals(store_root)
|
51
67
|
|
52
68
|
store = Dassets::FileStore.new(Factory.path)
|
53
69
|
subject.file_store(store)
|
54
|
-
|
70
|
+
assert_that(subject.file_store).equals(store)
|
55
71
|
|
56
|
-
subject.
|
57
|
-
|
72
|
+
subject.file_store(nil)
|
73
|
+
assert_that(subject.file_store).equals(store)
|
58
74
|
end
|
59
75
|
|
60
76
|
should "default its content cache" do
|
61
|
-
|
77
|
+
assert_that(subject.content_cache).is_instance_of(Dassets::NoCache)
|
62
78
|
end
|
63
79
|
|
64
80
|
should "configure non-nil content caches" do
|
65
|
-
cache = Dassets::
|
81
|
+
cache = Dassets::MemCache.new
|
66
82
|
subject.content_cache(cache)
|
67
|
-
|
83
|
+
assert_that(subject.content_cache).equals(cache)
|
68
84
|
|
69
85
|
subject.content_cache(nil)
|
70
|
-
|
86
|
+
assert_that(subject.content_cache).equals(cache)
|
71
87
|
end
|
72
88
|
|
73
89
|
should "default its fingerprint cache" do
|
74
|
-
assert_instance_of Dassets::
|
90
|
+
assert_instance_of Dassets::NoCache, subject.fingerprint_cache
|
75
91
|
end
|
76
92
|
|
77
93
|
should "configure non-nil fingerprint caches" do
|
78
|
-
cache = Dassets::
|
94
|
+
cache = Dassets::MemCache.new
|
79
95
|
subject.fingerprint_cache(cache)
|
80
|
-
|
96
|
+
assert_that(subject.fingerprint_cache).equals(cache)
|
81
97
|
|
82
98
|
subject.fingerprint_cache(nil)
|
83
|
-
|
99
|
+
assert_that(subject.fingerprint_cache).equals(cache)
|
84
100
|
end
|
85
101
|
|
86
102
|
should "register new sources with the `source` method" do
|
87
|
-
path =
|
103
|
+
path = Factory.path
|
88
104
|
filter = proc{ |paths| [] }
|
89
105
|
subject.source(path){ |s| s.filter(&filter) }
|
90
106
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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)
|
95
111
|
end
|
96
112
|
|
97
113
|
should "know its combinations and return the keyed digest path by default" do
|
98
|
-
|
99
|
-
|
114
|
+
assert_that(subject.combinations).is_kind_of(::Hash)
|
115
|
+
assert_that(subject.combinations["some/digest.path"])
|
116
|
+
.equals(["some/digest.path"])
|
100
117
|
end
|
101
118
|
|
102
119
|
should "allow registering new combinations" do
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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"])
|
111
132
|
end
|
112
133
|
|
113
|
-
should "know which digest paths are actual combinations and which are
|
114
|
-
|
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"]
|
115
137
|
|
116
|
-
|
117
|
-
|
138
|
+
assert_that(subject.combination?("some/combination.path")).is_true
|
139
|
+
assert_that(subject.combination?("some/non-combo.path")).is_false
|
118
140
|
end
|
119
|
-
|
120
141
|
end
|
121
|
-
|
122
142
|
end
|