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.
Files changed (43) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +5 -1
  3. data/README.md +15 -17
  4. data/dassets.gemspec +14 -9
  5. data/lib/dassets.rb +51 -13
  6. data/lib/dassets/asset_file.rb +27 -24
  7. data/lib/dassets/cache.rb +27 -33
  8. data/lib/dassets/config.rb +55 -50
  9. data/lib/dassets/engine.rb +11 -23
  10. data/lib/dassets/file_store.rb +27 -27
  11. data/lib/dassets/server.rb +27 -27
  12. data/lib/dassets/server/request.rb +44 -41
  13. data/lib/dassets/server/response.rb +101 -80
  14. data/lib/dassets/source.rb +15 -9
  15. data/lib/dassets/source_file.rb +103 -82
  16. data/lib/dassets/source_proxy.rb +36 -20
  17. data/lib/dassets/version.rb +3 -1
  18. data/test/helper.rb +31 -25
  19. data/test/support/app.rb +5 -5
  20. data/test/support/empty/{.gitkeep → .keep} +0 -0
  21. data/test/support/factory.rb +3 -2
  22. data/test/support/{public/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt → linked_source_files/linked_file.txt} +0 -0
  23. data/test/support/source_files/linked +1 -0
  24. data/test/support/source_files/linked_file2.txt +1 -0
  25. data/test/system/rack_tests.rb +65 -61
  26. data/test/unit/asset_file_tests.rb +69 -61
  27. data/test/unit/cache_tests.rb +15 -34
  28. data/test/unit/config_tests.rb +59 -52
  29. data/test/unit/dassets_tests.rb +31 -24
  30. data/test/unit/engine_tests.rb +9 -43
  31. data/test/unit/file_store_tests.rb +44 -31
  32. data/test/unit/server/request_tests.rb +57 -59
  33. data/test/unit/server/response_tests.rb +82 -82
  34. data/test/unit/server_tests.rb +5 -9
  35. data/test/unit/source_file_tests.rb +80 -73
  36. data/test/unit/source_proxy_tests.rb +84 -90
  37. data/test/unit/source_tests.rb +66 -50
  38. data/tmp/.gitkeep +0 -0
  39. metadata +92 -72
  40. data/.gitignore +0 -19
  41. data/test/support/public/file2-9bbe1047cffbb590f59e0e5aeff46ae4.txt +0 -1
  42. data/test/support/public/grumpy_cat-b0d1f399a916f7a25c4c0f693c619013.jpg +0 -0
  43. data/test/support/public/nested/a-thing.txt-7413d18f2eba9c695a880aff67fde135.no-use +0 -4
@@ -1,53 +1,34 @@
1
- require 'assert'
2
- require 'dassets/cache'
1
+ # frozen_string_literal: true
3
2
 
4
- module Dassets::Cache
3
+ require "assert"
4
+ require "dassets/cache"
5
5
 
6
+ class Dassets::MemCache
6
7
  class UnitTests < Assert::Context
7
- desc "Dassets::Cache"
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['something'] = val
31
- assert_same val, subject['something']
15
+ subject["something"] = val
16
+ assert_that(subject["something"]).is(val)
32
17
  end
33
-
34
18
  end
19
+ end
35
20
 
36
- class NoCacheTests < UnitTests
37
- desc "NoCache"
38
- setup do
39
- @cache = NoCache.new
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['something'] = val
48
- assert_not_same val, subject['something']
30
+ subject["something"] = val
31
+ assert_that(subject["something"]).is_not(val)
49
32
  end
50
-
51
33
  end
52
-
53
34
  end
@@ -1,17 +1,19 @@
1
- require 'assert'
2
- require 'dassets/config'
1
+ # frozen_string_literal: true
3
2
 
4
- require 'dassets/cache'
5
- require 'dassets/file_store'
3
+ require "assert"
4
+ require "dassets/config"
6
5
 
7
- class Dassets::Config
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
- assert_empty subject.sources
24
- assert_empty subject.combinations
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
- assert_equal 1, subject.sources.size
30
- assert_equal 1, subject.combinations.size
31
+ assert_that(subject.sources.size).equals(1)
32
+ assert_that(subject.combinations.size).equals(1)
31
33
 
32
34
  subject.reset
33
- assert_empty subject.sources
34
- assert_empty subject.combinations
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
- assert_nil subject.base_url
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
- assert_equal url, subject.base_url
46
+ assert_that(subject.base_url).equals(url)
45
47
 
46
48
  subject.base_url(nil)
47
- assert_equal url, subject.base_url
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
- assert_equal url, subject.base_url
55
+ assert_that(subject.base_url).equals(url)
54
56
 
55
57
  subject.set_base_url(nil)
56
- assert_nil subject.base_url
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
- assert_kind_of Dassets::FileStore::NullStore, subject.file_store
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
- assert_equal store_root, subject.file_store.root
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
- assert_equal store, subject.file_store
72
+ assert_that(subject.file_store).equals(store)
71
73
 
72
- subject.content_cache(nil)
73
- assert_equal store, subject.file_store
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
- assert_instance_of Dassets::Cache::NoCache, subject.content_cache
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::Cache::MemCache.new
83
+ cache = Dassets::MemCache.new
82
84
  subject.content_cache(cache)
83
- assert_equal cache, subject.content_cache
85
+ assert_that(subject.content_cache).equals(cache)
84
86
 
85
87
  subject.content_cache(nil)
86
- assert_equal cache, subject.content_cache
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::Cache::NoCache, subject.fingerprint_cache
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::Cache::MemCache.new
96
+ cache = Dassets::MemCache.new
95
97
  subject.fingerprint_cache(cache)
96
- assert_equal cache, subject.fingerprint_cache
98
+ assert_that(subject.fingerprint_cache).equals(cache)
97
99
 
98
100
  subject.fingerprint_cache(nil)
99
- assert_equal cache, subject.fingerprint_cache
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{ |paths| [] }
106
+ filter = proc{ |_paths| [] }
105
107
  subject.source(path){ |s| s.filter(&filter) }
106
108
 
107
- assert_equal 1, subject.sources.size
108
- assert_kind_of Dassets::Source, subject.sources.first
109
- assert_equal path, subject.sources.first.path
110
- assert_equal filter, subject.sources.first.filter
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 default" do
114
- assert_kind_of ::Hash, subject.combinations
115
- assert_equal ['some/digest.path'], subject.combinations['some/digest.path']
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
- assert_equal ['some/digest.path'], subject.combinations['some/digest.path']
120
- exp_combination = ['some/other.path', 'and/another.path']
121
- subject.combination 'some/digest.path', exp_combination
122
- assert_equal exp_combination, subject.combinations['some/digest.path']
123
-
124
- assert_equal ['test/digest.path'], subject.combinations['test/digest.path']
125
- subject.combination 'test/digest.path', ['some/other.path']
126
- assert_equal ['some/other.path'], subject.combinations['test/digest.path']
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 just pass-thrus" do
130
- subject.combination 'some/combination.path', ['some.path', 'another.path']
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
- assert subject.combination? 'some/combination.path'
133
- assert_not subject.combination? 'some/non-combo.path'
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
@@ -1,60 +1,67 @@
1
- require 'assert'
2
- require 'dassets'
1
+ # frozen_string_literal: true
3
2
 
4
- require 'fileutils'
5
- require 'dassets/asset_file'
3
+ require "assert"
4
+ require "dassets"
6
5
 
7
- module Dassets
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
- assert_kind_of Config, subject.config
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['nested/file3.txt']
25
+ file1 = subject["nested/file3.txt"]
25
26
 
26
27
  subject.reset
27
28
 
28
- file2 = subject['nested/file3.txt']
29
- assert_not_same file2, file1
30
- assert_true config_reset_called
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 a their digest path using the index operator" do
34
- file = subject['nested/file3.txt']
34
+ should "return asset files given their digest path " do
35
+ file = subject.asset_file("nested/file3.txt")
35
36
 
36
- assert_kind_of subject::AssetFile, file
37
- assert_equal 'nested/file3.txt', file.digest_path
38
- assert_equal 'd41d8cd98f00b204e9800998ecf8427e', file.fingerprint
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['nested/file3.txt']
43
- file2 = subject['nested/file3.txt']
43
+ file1 = subject.asset_file("nested/file3.txt")
44
+ file2 = subject.asset_file("nested/file3.txt")
44
45
 
45
- assert_same file2, file1
46
+ assert_that(file2).is(file1)
46
47
  end
47
48
 
48
- should "return an asset file that doesn't exist if digest path not found" do
49
- file = subject['path/not/found.txt']
50
- assert_not file.exists?
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
- assert_equal exp, subject.source_files
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
@@ -1,59 +1,25 @@
1
- require 'assert'
2
- require 'dassets/engine'
1
+ # frozen_string_literal: true
3
2
 
4
- class Dassets::Engine
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
- setup do
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
- assert_equal exp_opts, subject.opts
16
+ assert_that(subject.opts).equals(exp_opts)
19
17
  end
20
18
 
21
19
  should "raise NotImplementedError on `ext` and `compile`" do
22
- assert_raises NotImplementedError do
23
- subject.ext('foo')
24
- end
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
- require 'assert'
2
- require 'dassets/file_store'
1
+ # frozen_string_literal: true
3
2
 
4
- class Dassets::FileStore
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
- setup do
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
- @store = Dassets::FileStore.new(@root.to_s)
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.rm_f(@url_path)
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 path" do
25
- assert_equal @root.to_s, subject.root
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
- assert_equal @url_path, subject.store_path(@url)
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 "return write a file and return the store path on save" do
33
- assert_not_file_exists @url_path
34
- path = subject.save(@url){ 'some contents' }
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
- assert_equal @url_path, path
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
- @store = Dassets::FileStore::NullStore.new
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
- should "be a kind of FileStore" do
49
- assert_kind_of Dassets::FileStore, subject
58
+ teardown do
59
+ FileUtils.rm_rf(@root.to_s)
50
60
  end
51
61
 
52
- should "know its root path" do
53
- assert_equal '', subject.root
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 "return the store path on save" do
57
- assert_equal "/#{@url}", subject.save(@url)
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