dassets 0.14.2 → 0.15.1
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/Gemfile +5 -1
- data/README.md +15 -17
- data/dassets.gemspec +14 -9
- data/lib/dassets.rb +51 -13
- data/lib/dassets/asset_file.rb +27 -24
- data/lib/dassets/cache.rb +27 -33
- data/lib/dassets/config.rb +55 -50
- data/lib/dassets/engine.rb +11 -23
- data/lib/dassets/file_store.rb +27 -27
- data/lib/dassets/server.rb +27 -27
- data/lib/dassets/server/request.rb +44 -41
- data/lib/dassets/server/response.rb +101 -80
- data/lib/dassets/source.rb +15 -9
- data/lib/dassets/source_file.rb +103 -82
- data/lib/dassets/source_proxy.rb +36 -20
- data/lib/dassets/version.rb +3 -1
- data/test/helper.rb +31 -25
- data/test/support/app.rb +5 -5
- data/test/support/empty/{.gitkeep → .keep} +0 -0
- data/test/support/factory.rb +3 -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 +65 -61
- data/test/unit/asset_file_tests.rb +69 -61
- data/test/unit/cache_tests.rb +15 -34
- data/test/unit/config_tests.rb +59 -52
- data/test/unit/dassets_tests.rb +31 -24
- data/test/unit/engine_tests.rb +9 -43
- data/test/unit/file_store_tests.rb +44 -31
- data/test/unit/server/request_tests.rb +57 -59
- data/test/unit/server/response_tests.rb +82 -82
- data/test/unit/server_tests.rb +5 -9
- data/test/unit/source_file_tests.rb +80 -73
- data/test/unit/source_proxy_tests.rb +84 -90
- data/test/unit/source_tests.rb +66 -50
- data/tmp/.gitkeep +0 -0
- metadata +92 -72
- data/.gitignore +0 -19
- 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
data/test/unit/cache_tests.rb
CHANGED
@@ -1,53 +1,34 @@
|
|
1
|
-
|
2
|
-
require 'dassets/cache'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "assert"
|
4
|
+
require "dassets/cache"
|
5
5
|
|
6
|
+
class Dassets::MemCache
|
6
7
|
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 }
|
8
|
+
desc "Dassets::MemCache"
|
9
|
+
subject{ Dassets::MemCache.new }
|
25
10
|
|
26
11
|
should have_imeths :keys, :[], :[]=
|
27
12
|
|
28
13
|
should "cache given key/value pairs in memory" do
|
29
14
|
val = []
|
30
|
-
subject[
|
31
|
-
|
15
|
+
subject["something"] = val
|
16
|
+
assert_that(subject["something"]).is(val)
|
32
17
|
end
|
33
|
-
|
34
18
|
end
|
19
|
+
end
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
subject{ @cache }
|
21
|
+
class Dassets::NoCache
|
22
|
+
class UnitTests < Assert::Context
|
23
|
+
desc "Dassets::NoCache"
|
24
|
+
subject{ Dassets::NoCache.new }
|
42
25
|
|
43
26
|
should have_imeths :keys, :[], :[]=
|
44
27
|
|
45
28
|
should "not cache given key/value pairs in memory" do
|
46
29
|
val = []
|
47
|
-
subject[
|
48
|
-
|
30
|
+
subject["something"] = val
|
31
|
+
assert_that(subject["something"]).is_not(val)
|
49
32
|
end
|
50
|
-
|
51
33
|
end
|
52
|
-
|
53
34
|
end
|
data/test/unit/config_tests.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
require 'dassets/config'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "assert"
|
4
|
+
require "dassets/config"
|
6
5
|
|
7
|
-
|
6
|
+
require "dassets/cache"
|
7
|
+
require "dassets/file_store"
|
8
8
|
|
9
|
+
class Dassets::Config
|
9
10
|
class UnitTests < Assert::Context
|
10
11
|
desc "Dassets::Config"
|
12
|
+
subject{ @config }
|
13
|
+
|
11
14
|
setup do
|
12
15
|
@config = Dassets::Config.new
|
13
16
|
end
|
14
|
-
subject{ @config }
|
15
17
|
|
16
18
|
should have_readers :combinations
|
17
19
|
should have_imeths :reset
|
@@ -20,119 +22,124 @@ class Dassets::Config
|
|
20
22
|
should have_imeths :source, :combination, :combination?
|
21
23
|
|
22
24
|
should "reset its sources and combination on `reset`" do
|
23
|
-
|
24
|
-
|
25
|
+
assert_that(subject.sources).is_empty
|
26
|
+
assert_that(subject.combinations).is_empty
|
25
27
|
|
26
28
|
path = Factory.path
|
27
29
|
subject.source(path)
|
28
30
|
subject.combination path, [Factory.path]
|
29
|
-
|
30
|
-
|
31
|
+
assert_that(subject.sources.size).equals(1)
|
32
|
+
assert_that(subject.combinations.size).equals(1)
|
31
33
|
|
32
34
|
subject.reset
|
33
|
-
|
34
|
-
|
35
|
+
assert_that(subject.sources).is_empty
|
36
|
+
assert_that(subject.combinations).is_empty
|
35
37
|
end
|
36
38
|
|
37
39
|
should "have no base url by default" do
|
38
|
-
|
40
|
+
assert_that(subject.base_url).is_nil
|
39
41
|
end
|
40
42
|
|
41
43
|
should "set non-nil base urls" do
|
42
44
|
url = Factory.url
|
43
45
|
subject.base_url url
|
44
|
-
|
46
|
+
assert_that(subject.base_url).equals(url)
|
45
47
|
|
46
48
|
subject.base_url(nil)
|
47
|
-
|
49
|
+
assert_that(subject.base_url).equals(url)
|
48
50
|
end
|
49
51
|
|
50
52
|
should "force set any base urls" do
|
51
53
|
url = Factory.url
|
52
54
|
subject.set_base_url url
|
53
|
-
|
55
|
+
assert_that(subject.base_url).equals(url)
|
54
56
|
|
55
57
|
subject.set_base_url(nil)
|
56
|
-
|
58
|
+
assert_that(subject.base_url).is_nil
|
57
59
|
end
|
58
60
|
|
59
61
|
should "default the file store option to a null file store" do
|
60
|
-
|
62
|
+
assert_that(subject.file_store).is_kind_of(Dassets::NullFileStore)
|
61
63
|
end
|
62
64
|
|
63
65
|
should "configure non-nil file stores" do
|
64
66
|
store_root = Factory.path
|
65
67
|
subject.file_store(store_root)
|
66
|
-
|
68
|
+
assert_that(subject.file_store.root).equals(store_root)
|
67
69
|
|
68
70
|
store = Dassets::FileStore.new(Factory.path)
|
69
71
|
subject.file_store(store)
|
70
|
-
|
72
|
+
assert_that(subject.file_store).equals(store)
|
71
73
|
|
72
|
-
subject.
|
73
|
-
|
74
|
+
subject.file_store(nil)
|
75
|
+
assert_that(subject.file_store).equals(store)
|
74
76
|
end
|
75
77
|
|
76
78
|
should "default its content cache" do
|
77
|
-
|
79
|
+
assert_that(subject.content_cache).is_instance_of(Dassets::NoCache)
|
78
80
|
end
|
79
81
|
|
80
82
|
should "configure non-nil content caches" do
|
81
|
-
cache = Dassets::
|
83
|
+
cache = Dassets::MemCache.new
|
82
84
|
subject.content_cache(cache)
|
83
|
-
|
85
|
+
assert_that(subject.content_cache).equals(cache)
|
84
86
|
|
85
87
|
subject.content_cache(nil)
|
86
|
-
|
88
|
+
assert_that(subject.content_cache).equals(cache)
|
87
89
|
end
|
88
90
|
|
89
91
|
should "default its fingerprint cache" do
|
90
|
-
assert_instance_of Dassets::
|
92
|
+
assert_instance_of Dassets::NoCache, subject.fingerprint_cache
|
91
93
|
end
|
92
94
|
|
93
95
|
should "configure non-nil fingerprint caches" do
|
94
|
-
cache = Dassets::
|
96
|
+
cache = Dassets::MemCache.new
|
95
97
|
subject.fingerprint_cache(cache)
|
96
|
-
|
98
|
+
assert_that(subject.fingerprint_cache).equals(cache)
|
97
99
|
|
98
100
|
subject.fingerprint_cache(nil)
|
99
|
-
|
101
|
+
assert_that(subject.fingerprint_cache).equals(cache)
|
100
102
|
end
|
101
103
|
|
102
104
|
should "register new sources with the `source` method" do
|
103
105
|
path = Factory.path
|
104
|
-
filter = proc{ |
|
106
|
+
filter = proc{ |_paths| [] }
|
105
107
|
subject.source(path){ |s| s.filter(&filter) }
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
assert_that(subject.sources.size).equals(1)
|
110
|
+
assert_that(subject.sources.first).is_kind_of(Dassets::Source)
|
111
|
+
assert_that(subject.sources.first.path).equals(path)
|
112
|
+
assert_that(subject.sources.first.filter).equals(filter)
|
111
113
|
end
|
112
114
|
|
113
|
-
should "know its combinations and return the keyed digest path by
|
114
|
-
|
115
|
-
|
115
|
+
should "know its combinations and return the keyed digest path by "\
|
116
|
+
"default" do
|
117
|
+
assert_that(subject.combinations).is_kind_of(::Hash)
|
118
|
+
assert_that(subject.combinations["some/digest.path"])
|
119
|
+
.equals(["some/digest.path"])
|
116
120
|
end
|
117
121
|
|
118
122
|
should "allow registering new combinations" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
assert_that(subject.combinations["some/digest.path"])
|
124
|
+
.equals(["some/digest.path"])
|
125
|
+
exp_combination = ["some/other.path", "and/another.path"]
|
126
|
+
subject.combination "some/digest.path", exp_combination
|
127
|
+
assert_that(subject.combinations["some/digest.path"])
|
128
|
+
.equals(exp_combination)
|
129
|
+
|
130
|
+
assert_that(subject.combinations["test/digest.path"])
|
131
|
+
.equals(["test/digest.path"])
|
132
|
+
subject.combination "test/digest.path", ["some/other.path"]
|
133
|
+
assert_that(subject.combinations["test/digest.path"])
|
134
|
+
.equals(["some/other.path"])
|
127
135
|
end
|
128
136
|
|
129
|
-
should "know which digest paths are actual combinations and which are
|
130
|
-
|
137
|
+
should "know which digest paths are actual combinations and which are "\
|
138
|
+
"just pass-thrus" do
|
139
|
+
subject.combination "some/combination.path", ["some.path", "another.path"]
|
131
140
|
|
132
|
-
|
133
|
-
|
141
|
+
assert_that(subject.combination?("some/combination.path")).is_true
|
142
|
+
assert_that(subject.combination?("some/non-combo.path")).is_false
|
134
143
|
end
|
135
|
-
|
136
144
|
end
|
137
|
-
|
138
145
|
end
|
data/test/unit/dassets_tests.rb
CHANGED
@@ -1,60 +1,67 @@
|
|
1
|
-
|
2
|
-
require 'dassets'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "assert"
|
4
|
+
require "dassets"
|
6
5
|
|
7
|
-
|
6
|
+
require "fileutils"
|
7
|
+
require "dassets/asset_file"
|
8
8
|
|
9
|
+
module Dassets
|
9
10
|
class UnitTests < Assert::Context
|
10
11
|
desc "Dassets"
|
11
12
|
subject{ Dassets }
|
12
13
|
|
13
14
|
should have_imeths :config, :configure, :init, :reset
|
14
|
-
should have_imeths :[], :source_files
|
15
|
+
should have_imeths :asset_file, :[], :source_files, :combinations
|
15
16
|
|
16
17
|
should "return a `Config` instance with the `config` method" do
|
17
|
-
|
18
|
+
assert_that(subject.config).is_kind_of(Dassets::Config)
|
18
19
|
end
|
19
20
|
|
20
21
|
should "know how to reset itself" do
|
21
22
|
config_reset_called = false
|
22
23
|
Assert.stub(subject.config, :reset){ config_reset_called = true }
|
23
24
|
|
24
|
-
file1 = subject[
|
25
|
+
file1 = subject["nested/file3.txt"]
|
25
26
|
|
26
27
|
subject.reset
|
27
28
|
|
28
|
-
file2 = subject[
|
29
|
-
|
30
|
-
|
29
|
+
file2 = subject["nested/file3.txt"]
|
30
|
+
assert_that(file2).is_not(file1)
|
31
|
+
assert_that(config_reset_called).is_true
|
31
32
|
end
|
32
33
|
|
33
|
-
should "return asset files given
|
34
|
-
file = subject
|
34
|
+
should "return asset files given their digest path " do
|
35
|
+
file = subject.asset_file("nested/file3.txt")
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
assert_that(file).is_kind_of(subject::AssetFile)
|
38
|
+
assert_that(file.digest_path).equals("nested/file3.txt")
|
39
|
+
assert_that(file.fingerprint).equals("d41d8cd98f00b204e9800998ecf8427e")
|
39
40
|
end
|
40
41
|
|
41
42
|
should "cache asset files" do
|
42
|
-
file1 = subject
|
43
|
-
file2 = subject
|
43
|
+
file1 = subject.asset_file("nested/file3.txt")
|
44
|
+
file2 = subject.asset_file("nested/file3.txt")
|
44
45
|
|
45
|
-
|
46
|
+
assert_that(file2).is(file1)
|
46
47
|
end
|
47
48
|
|
48
|
-
should "
|
49
|
-
|
50
|
-
|
49
|
+
should "complain if digest path is not found using the index operator" do
|
50
|
+
assert_that(->{
|
51
|
+
subject.asset_file("path/not/found.txt")
|
52
|
+
}).does_not_raise
|
53
|
+
|
54
|
+
assert_that{ subject["path/not/found.txt"] }.raises(AssetFileError)
|
51
55
|
end
|
52
56
|
|
53
57
|
should "know its list of configured source files" do
|
54
58
|
exp = Dassets::SourceFiles.new(subject.config.sources)
|
55
|
-
|
59
|
+
assert_that(subject.source_files).equals(exp)
|
56
60
|
end
|
57
61
|
|
62
|
+
should "know its configured combinations" do
|
63
|
+
exp = subject.config.combinations
|
64
|
+
assert_that(subject.combinations).equals(exp)
|
65
|
+
end
|
58
66
|
end
|
59
|
-
|
60
67
|
end
|
data/test/unit/engine_tests.rb
CHANGED
@@ -1,59 +1,25 @@
|
|
1
|
-
|
2
|
-
require 'dassets/engine'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "assert"
|
4
|
+
require "dassets/engine"
|
5
5
|
|
6
|
+
class Dassets::Engine
|
6
7
|
class UnitTests < Assert::Context
|
7
8
|
desc "Dassets::Engine"
|
8
|
-
|
9
|
-
@engine = Dassets::Engine.new
|
10
|
-
end
|
11
|
-
subject{ @engine }
|
9
|
+
subject{ Dassets::Engine.new }
|
12
10
|
|
13
11
|
should have_reader :opts
|
14
12
|
should have_imeths :ext, :compile
|
15
13
|
|
16
14
|
should "default the opts if none given" do
|
17
15
|
exp_opts = {}
|
18
|
-
|
16
|
+
assert_that(subject.opts).equals(exp_opts)
|
19
17
|
end
|
20
18
|
|
21
19
|
should "raise NotImplementedError on `ext` and `compile`" do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
assert_raises NotImplementedError do
|
27
|
-
subject.compile('some content')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
class NullEngineTests < Assert::Context
|
34
|
-
desc "Dassets::NullEngine"
|
35
|
-
setup do
|
36
|
-
@engine = Dassets::NullEngine.new('some' => 'opts')
|
37
|
-
end
|
38
|
-
subject{ @engine }
|
39
|
-
|
40
|
-
should "be a Engine" do
|
41
|
-
assert_kind_of Dassets::Engine, subject
|
42
|
-
end
|
43
|
-
|
44
|
-
should "know its opts" do
|
45
|
-
exp_opts = {'some' => 'opts'}
|
46
|
-
assert_equal exp_opts, subject.opts
|
47
|
-
end
|
48
|
-
|
49
|
-
should "return the given extension on `ext`" do
|
50
|
-
assert_equal 'foo', subject.ext('foo')
|
20
|
+
assert_that{ subject.ext("foo") }.raises(NotImplementedError)
|
21
|
+
assert_that{ subject.compile("some content") }
|
22
|
+
.raises(NotImplementedError)
|
51
23
|
end
|
52
|
-
|
53
|
-
should "return the given input on `compile" do
|
54
|
-
assert_equal 'some content', subject.compile('some content')
|
55
|
-
end
|
56
|
-
|
57
24
|
end
|
58
|
-
|
59
25
|
end
|
@@ -1,62 +1,75 @@
|
|
1
|
-
|
2
|
-
require 'dassets/file_store'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "assert"
|
4
|
+
require "dassets/file_store"
|
5
5
|
|
6
|
+
class Dassets::FileStore
|
6
7
|
class UnitTests < Assert::Context
|
7
8
|
desc "Dassets::FileStore"
|
8
|
-
|
9
|
-
@root = TEST_SUPPORT_PATH.join('public')
|
10
|
-
@url = 'some/url'
|
11
|
-
@url_path = @root.join(@url).to_s
|
12
|
-
FileUtils.rm_f(@url_path)
|
9
|
+
subject{ Dassets::FileStore.new(@root.to_s) }
|
13
10
|
|
14
|
-
|
11
|
+
setup do
|
12
|
+
@root = TEST_SUPPORT_PATH.join("public")
|
13
|
+
@url_path = Factory.url
|
14
|
+
@root_path = File.join(@root, @url_path).to_s
|
15
|
+
FileUtils.rm_f(@root_path)
|
15
16
|
end
|
17
|
+
|
16
18
|
teardown do
|
17
|
-
FileUtils.
|
19
|
+
FileUtils.rm_rf(@root.to_s)
|
18
20
|
end
|
19
|
-
subject{ @store }
|
20
21
|
|
21
22
|
should have_readers :root
|
22
23
|
should have_imeths :save, :store_path
|
23
24
|
|
24
|
-
should "know its root
|
25
|
-
|
25
|
+
should "know its root" do
|
26
|
+
assert_that(subject.root).equals(@root.to_s)
|
26
27
|
end
|
27
28
|
|
28
|
-
should "build the store path based on a given url" do
|
29
|
-
|
29
|
+
should "build the store path based on a given url path" do
|
30
|
+
assert_that(subject.store_path(@url_path)).equals(@root_path)
|
30
31
|
end
|
31
32
|
|
32
|
-
should "
|
33
|
-
|
34
|
-
|
33
|
+
should "write a file and return the store path on save" do
|
34
|
+
content = Factory.text
|
35
|
+
assert_that(@root_path).is_not_a_file
|
35
36
|
|
36
|
-
|
37
|
-
assert_file_exists @url_path
|
38
|
-
end
|
37
|
+
path = subject.save(@url_path){ content }
|
39
38
|
|
39
|
+
assert_that(path).equals(@root_path)
|
40
|
+
assert_that(@root_path).is_a_file
|
41
|
+
assert_that(File.read(@root_path)).equals(content)
|
42
|
+
end
|
40
43
|
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Dassets::NullFileStore
|
47
|
+
class UnitTests < Assert::Context
|
48
|
+
desc "Dassets::NullFileStore"
|
49
|
+
subject{ Dassets::NullFileStore.new }
|
41
50
|
|
42
|
-
class NullStoreTests < UnitTests
|
43
|
-
desc "NullStore"
|
44
51
|
setup do
|
45
|
-
@
|
52
|
+
@root = TEST_SUPPORT_PATH.join("public")
|
53
|
+
@url_path = Factory.url
|
54
|
+
@root_path = File.join(@root, @url_path).to_s
|
55
|
+
FileUtils.rm_f(@root_path)
|
46
56
|
end
|
47
57
|
|
48
|
-
|
49
|
-
|
58
|
+
teardown do
|
59
|
+
FileUtils.rm_rf(@root.to_s)
|
50
60
|
end
|
51
61
|
|
52
|
-
should "
|
53
|
-
|
62
|
+
should "be a kind of Dassets::FileStore" do
|
63
|
+
assert_that(subject).is_kind_of(Dassets::FileStore)
|
54
64
|
end
|
55
65
|
|
56
|
-
should "
|
57
|
-
|
66
|
+
should "know its root" do
|
67
|
+
assert_that(subject.root).equals("")
|
58
68
|
end
|
59
69
|
|
70
|
+
should "return the store path on save but not save a file" do
|
71
|
+
assert_that(subject.save(@url_path)).equals(File.join("", @url_path))
|
72
|
+
assert_that(@root_path).is_not_a_file
|
73
|
+
end
|
60
74
|
end
|
61
|
-
|
62
75
|
end
|