dassets 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -7
  2. data/.ruby-version +1 -0
  3. data/Gemfile +3 -1
  4. data/README.md +15 -17
  5. data/dassets.gemspec +7 -6
  6. data/lib/dassets.rb +54 -11
  7. data/lib/dassets/asset_file.rb +14 -12
  8. data/lib/dassets/cache.rb +27 -33
  9. data/lib/dassets/config.rb +55 -47
  10. data/lib/dassets/engine.rb +11 -23
  11. data/lib/dassets/file_store.rb +27 -27
  12. data/lib/dassets/server.rb +27 -28
  13. data/lib/dassets/server/request.rb +43 -41
  14. data/lib/dassets/server/response.rb +93 -81
  15. data/lib/dassets/source.rb +13 -8
  16. data/lib/dassets/source_file.rb +100 -82
  17. data/lib/dassets/source_proxy.rb +32 -16
  18. data/lib/dassets/version.rb +3 -1
  19. data/test/helper.rb +18 -24
  20. data/test/support/app.rb +3 -5
  21. data/test/support/factory.rb +1 -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 +55 -59
  26. data/test/unit/asset_file_tests.rb +64 -60
  27. data/test/unit/cache_tests.rb +14 -35
  28. data/test/unit/config_tests.rb +65 -45
  29. data/test/unit/dassets_tests.rb +41 -23
  30. data/test/unit/engine_tests.rb +7 -43
  31. data/test/unit/file_store_tests.rb +42 -31
  32. data/test/unit/server/request_tests.rb +48 -53
  33. data/test/unit/server/response_tests.rb +79 -81
  34. data/test/unit/server_tests.rb +3 -9
  35. data/test/unit/source_file_tests.rb +73 -72
  36. data/test/unit/source_proxy_tests.rb +78 -89
  37. data/test/unit/source_tests.rb +58 -50
  38. metadata +78 -70
  39. data/test/support/public/file2-9bbe1047cffbb590f59e0e5aeff46ae4.txt +0 -1
  40. data/test/support/public/grumpy_cat-b0d1f399a916f7a25c4c0f693c619013.jpg +0 -0
  41. data/test/support/public/nested/a-thing.txt-7413d18f2eba9c695a880aff67fde135.no-use +0 -4
@@ -1,140 +1,144 @@
1
- require 'assert'
2
- require 'dassets/asset_file'
1
+ require "assert"
2
+ require "dassets/asset_file"
3
3
 
4
- require 'fileutils'
5
- require 'dassets/file_store'
6
- require 'dassets/source_proxy'
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('file1.txt')
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
- assert_equal 'file1.txt', subject.digest_path
23
- assert_equal '.', subject.dirname
24
- assert_equal '.txt', subject.extname
25
- assert_equal 'file1', subject.basename
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
- assert_equal subject.source_proxy.mtime.httpdate, subject.mtime
30
- assert_equal Rack::Utils.bytesize(subject.content), subject.size
31
- assert_equal "text/plain", subject.mime_type
32
- assert_equal subject.source_proxy.response_headers, subject.response_headers
33
- assert subject.exists?
34
-
35
- null_file = Dassets::AssetFile.new('')
36
- assert_nil null_file.mtime
37
- assert_nil null_file.size
38
- assert_nil null_file.mime_type
39
- assert_not null_file.exists?
40
- assert_equal null_file.source_proxy.response_headers, null_file.response_headers
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
- assert_not_nil source_proxy
46
- assert_kind_of Dassets::SourceProxy, source_proxy
47
- assert_equal subject.digest_path, source_proxy.digest_path
48
- assert_equal Dassets.config.content_cache, source_proxy.content_cache
49
- assert_equal Dassets.config.fingerprint_cache, source_proxy.fingerprint_cache
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
- assert_not_nil subject.fingerprint
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('file1.txt')
58
- assert_equal af.source_proxy.fingerprint, af.fingerprint
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
- assert_equal "file1.txt\n", subject.content
66
+ assert_that(subject.content).equals("file1.txt\n")
63
67
 
64
- null_file = Dassets::AssetFile.new('')
65
- assert_nil null_file.content
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 = 'nested/a-thing.txt.no-use'
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
- assert_equal exp_content, without_output.content
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 any configured base url" do
77
- assert_match /^\/file1-[a-f0-9]{32}\.txt$/, subject.url
78
- assert_match subject.url, subject.href
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('nested/file1.txt')
81
- assert_equal "/nested/file1-.txt", nested.url
82
- assert_equal nested.url, nested.href
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
- assert_match /^#{base_url}\/file1-[a-f0-9]{32}\.txt$/, subject.url
88
- assert_match subject.url, subject.href
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
- assert_equal "#{base_url}/nested/file1-.txt", nested.url
91
- assert_equal nested.url, nested.href
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
- assert_not_same url2, url1
102
+ assert_that(url1).is_not(url2)
98
103
 
99
104
  fingerprint1 = subject.fingerprint
100
105
  fingerprint2 = subject.fingerprint
101
- assert_not_same fingerprint2, fingerprint1
106
+ assert_that(fingerprint1).is_not(fingerprint2)
102
107
 
103
108
  content1 = subject.content
104
109
  content2 = subject.content
105
- assert_not_same content2, content1
110
+ assert_that(content1).is_not(content2)
106
111
 
107
112
  mtime1 = subject.mtime
108
113
  mtime2 = subject.mtime
109
- assert_not_same mtime2, mtime1
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('public').to_s
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.rm(@outfile)
126
- Dassets.config.file_store Dassets::FileStore::NullStore.new
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
- assert_equal @outfile, @save_path
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
- assert_file_exists @outfile
135
- assert_equal subject.content, File.read(@outfile)
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
@@ -1,53 +1,32 @@
1
- require 'assert'
2
- require 'dassets/cache'
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::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 }
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['something'] = val
31
- assert_same val, subject['something']
13
+ subject["something"] = val
14
+ assert_that(subject["something"]).is(val)
32
15
  end
33
-
34
16
  end
17
+ end
35
18
 
36
- class NoCacheTests < UnitTests
37
- desc "NoCache"
38
- setup do
39
- @cache = NoCache.new
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['something'] = val
48
- assert_not_same val, subject['something']
28
+ subject["something"] = val
29
+ assert_that(subject["something"]).is_not(val)
49
30
  end
50
-
51
31
  end
52
-
53
32
  end
@@ -1,122 +1,142 @@
1
- require 'assert'
2
- require 'dassets/config'
1
+ require "assert"
2
+ require "dassets/config"
3
3
 
4
- require 'dassets/cache'
5
- require 'dassets/file_store'
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
- assert_nil subject.base_url
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
- assert_equal url, subject.base_url
44
+ assert_that(subject.base_url).equals(url)
29
45
 
30
46
  subject.base_url(nil)
31
- assert_equal url, subject.base_url
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
- assert_equal url, subject.base_url
53
+ assert_that(subject.base_url).equals(url)
38
54
 
39
55
  subject.set_base_url(nil)
40
- assert_nil subject.base_url
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
- assert_kind_of Dassets::FileStore::NullStore, subject.file_store
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
- assert_equal store_root, subject.file_store.root
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
- assert_equal store, subject.file_store
70
+ assert_that(subject.file_store).equals(store)
55
71
 
56
- subject.content_cache(nil)
57
- assert_equal store, subject.file_store
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
- assert_instance_of Dassets::Cache::NoCache, subject.content_cache
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::Cache::MemCache.new
81
+ cache = Dassets::MemCache.new
66
82
  subject.content_cache(cache)
67
- assert_equal cache, subject.content_cache
83
+ assert_that(subject.content_cache).equals(cache)
68
84
 
69
85
  subject.content_cache(nil)
70
- assert_equal cache, subject.content_cache
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::Cache::NoCache, subject.fingerprint_cache
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::Cache::MemCache.new
94
+ cache = Dassets::MemCache.new
79
95
  subject.fingerprint_cache(cache)
80
- assert_equal cache, subject.fingerprint_cache
96
+ assert_that(subject.fingerprint_cache).equals(cache)
81
97
 
82
98
  subject.fingerprint_cache(nil)
83
- assert_equal cache, subject.fingerprint_cache
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 = '/path/to/app/assets'
103
+ path = Factory.path
88
104
  filter = proc{ |paths| [] }
89
105
  subject.source(path){ |s| s.filter(&filter) }
90
106
 
91
- assert_equal 1, subject.sources.size
92
- assert_kind_of Dassets::Source, subject.sources.first
93
- assert_equal path, subject.sources.first.path
94
- assert_equal filter, subject.sources.first.filter
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
- assert_kind_of ::Hash, subject.combinations
99
- assert_equal ['some/digest.path'], subject.combinations['some/digest.path']
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
- assert_equal ['some/digest.path'], subject.combinations['some/digest.path']
104
- exp_combination = ['some/other.path', 'and/another.path']
105
- subject.combination 'some/digest.path', exp_combination
106
- assert_equal exp_combination, subject.combinations['some/digest.path']
107
-
108
- assert_equal ['test/digest.path'], subject.combinations['test/digest.path']
109
- subject.combination 'test/digest.path', ['some/other.path']
110
- assert_equal ['some/other.path'], subject.combinations['test/digest.path']
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 just pass-thrus" do
114
- subject.combination 'some/combination.path', ['some.path', 'another.path']
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
- assert subject.combination? 'some/combination.path'
117
- assert_not subject.combination? 'some/non-combo.path'
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