dassets 0.3.0 → 0.4.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.
Files changed (40) hide show
  1. data/README.md +42 -10
  2. data/lib/dassets.rb +16 -28
  3. data/lib/dassets/asset_file.rb +36 -33
  4. data/lib/dassets/default_cache.rb +29 -0
  5. data/lib/dassets/digest_cmd.rb +36 -0
  6. data/lib/dassets/engine.rb +0 -2
  7. data/lib/dassets/file_store.rb +36 -0
  8. data/lib/dassets/runner.rb +2 -9
  9. data/lib/dassets/server/request.rb +5 -5
  10. data/lib/dassets/source_cache.rb +39 -0
  11. data/lib/dassets/source_file.rb +37 -13
  12. data/lib/dassets/version.rb +1 -1
  13. data/test/support/config/assets.rb +1 -0
  14. data/test/system/digest_cmd_run_tests.rb +37 -39
  15. data/test/system/rack_tests.rb +3 -7
  16. data/test/unit/asset_file_tests.rb +72 -40
  17. data/test/unit/config_tests.rb +3 -17
  18. data/test/unit/dassets_tests.rb +8 -42
  19. data/test/unit/default_cache_tests.rb +27 -0
  20. data/test/unit/{cmds/digest_cmd_tests.rb → digest_cmd_tests.rb} +4 -4
  21. data/test/unit/file_store_tests.rb +30 -0
  22. data/test/unit/server/request_tests.rb +7 -11
  23. data/test/unit/server/response_tests.rb +4 -5
  24. data/test/unit/source_cache_tests.rb +50 -0
  25. data/test/unit/source_file_tests.rb +28 -29
  26. metadata +16 -31
  27. data/lib/dassets/cmds/cache_cmd.rb +0 -33
  28. data/lib/dassets/cmds/digest_cmd.rb +0 -53
  29. data/lib/dassets/digests.rb +0 -61
  30. data/test/support/app/assets/.digests +0 -5
  31. data/test/support/app/assets/public/file1.txt +0 -1
  32. data/test/support/app/assets/public/file2.txt +0 -1
  33. data/test/support/app/assets/public/grumpy_cat.jpg +0 -0
  34. data/test/support/app/assets/public/nested/a-thing.txt.no-use +0 -4
  35. data/test/support/app/assets/public/nested/file3.txt +0 -0
  36. data/test/support/app_public/.gitkeep +0 -0
  37. data/test/support/example.digests +0 -3
  38. data/test/system/cache_cmd_run_tests.rb +0 -27
  39. data/test/unit/cmds/cache_cmd_tests.rb +0 -33
  40. data/test/unit/digests_tests.rb +0 -79
@@ -0,0 +1,27 @@
1
+ require 'assert'
2
+ require 'dassets/default_cache'
3
+
4
+ class Dassets::DefaultCache
5
+
6
+ class BaseTests < Assert::Context
7
+ desc "Dassets::DefaultCache"
8
+ setup do
9
+ @cache = Dassets::DefaultCache.new
10
+ end
11
+ subject{ @cache }
12
+
13
+ should have_imeths :keys, :[], :[]=
14
+
15
+ should "only cache fingerprint keys" do
16
+ subject['some val'] = 'something'
17
+ assert_empty subject.keys
18
+ assert_nil subject['some val']
19
+
20
+ subject['a -- fingerprint'] = 'finger'
21
+ assert_includes 'a -- fingerprint', subject.keys
22
+ assert_equal 'finger', subject['a -- fingerprint']
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -1,13 +1,13 @@
1
1
  require 'assert'
2
2
  require 'dassets'
3
- require 'dassets/cmds/digest_cmd'
3
+ require 'dassets/digest_cmd'
4
4
 
5
- class Dassets::Cmds::DigestCmd
5
+ class Dassets::DigestCmd
6
6
 
7
7
  class BaseTests < Assert::Context
8
- desc "Dassets::Cmds::DigestCmd"
8
+ desc "Dassets::DigestCmd"
9
9
  setup do
10
- @cmd = Dassets::Cmds::DigestCmd.new(['a/path'])
10
+ @cmd = Dassets::DigestCmd.new(['a/path'])
11
11
  end
12
12
  subject{ @cmd }
13
13
 
@@ -0,0 +1,30 @@
1
+ require 'assert'
2
+ require 'dassets/root_path'
3
+ require 'dassets/file_store'
4
+
5
+ class Dassets::FileStore
6
+
7
+ class BaseTests < Assert::Context
8
+ desc "Dassets::NullFileStore"
9
+ subject{ Dassets::NullFileStore.new }
10
+
11
+ should have_reader :root
12
+ should have_imeths :save, :store_path
13
+
14
+ should "be a kind of FileStore" do
15
+ assert_kind_of Dassets::FileStore, subject
16
+ end
17
+
18
+ should "build its root based on the config's root_path" do
19
+ assert_equal Dassets::RootPath.new(''), subject.root
20
+ end
21
+
22
+ should "build the store path based on a given url" do
23
+ end
24
+
25
+ should "return the store path on save" do
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -6,12 +6,8 @@ class Dassets::Server::Request
6
6
  class BaseTests < Assert::Context
7
7
  desc "Dassets::Server::Request"
8
8
  setup do
9
- Dassets.init
10
9
  @req = file_request('GET', '/file1-daa05c683a4913b268653f7a7e36a5b4.txt')
11
10
  end
12
- teardown do
13
- Dassets.reset
14
- end
15
11
  subject{ @req }
16
12
 
17
13
  should have_imeths :for_asset_file?, :asset_path, :asset_file
@@ -25,23 +21,23 @@ class Dassets::Server::Request
25
21
  end
26
22
 
27
23
  should "know if it is for an asset file" do
28
- # find nested path with matching md5
24
+ # find nested path with matching fingerprint
29
25
  req = file_request('GET', '/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt')
30
26
  assert req.for_asset_file?
31
27
 
32
- # find not nested path with matching md5
28
+ # find not nested path with matching fingerprint
33
29
  req = file_request('HEAD', '/file1-daa05c683a4913b268653f7a7e36a5b4.txt')
34
30
  assert req.for_asset_file?
35
31
 
36
- # find even if md5 is *not* matching - just need to have any md5
32
+ # find even if fingerprint is *not* matching - just need to have any fingerprint
37
33
  req = file_request('GET', '/file1-d41d8cd98f00b204e9800998ecf8427e.txt')
38
34
  assert req.for_asset_file?
39
35
 
40
- # no find on invalid md5
36
+ # no find on invalid fingerprint
41
37
  req = file_request('GET', '/file1-daa05c683a4913b268653f7a7e36a.txt')
42
38
  assert_not req.for_asset_file?
43
39
 
44
- # no find on missing md5
40
+ # no find on missing fingerprint
45
41
  req = file_request('HEAD', '/file1.txt')
46
42
  assert_not req.for_asset_file?
47
43
 
@@ -49,7 +45,7 @@ class Dassets::Server::Request
49
45
  req = file_request('GET', '/some-file.txt')
50
46
  assert_not req.for_asset_file?
51
47
 
52
- # no find on unknown file with an md5
48
+ # no find on unknown file with an fingerprint
53
49
  req = file_request('GET', '/some-file-daa05c683a4913b268653f7a7e36a5b4.txt')
54
50
  assert_not req.for_asset_file?
55
51
  end
@@ -58,7 +54,7 @@ class Dassets::Server::Request
58
54
  req = file_request('GET', '/some-file.txt')
59
55
 
60
56
  assert_equal '', req.asset_path
61
- assert_equal Dassets::AssetFile.new('', ''), req.asset_file
57
+ assert_equal Dassets::AssetFile.new(''), req.asset_file
62
58
  end
63
59
 
64
60
  protected
@@ -7,7 +7,7 @@ class Dassets::Server::Response
7
7
  class BaseTests < Assert::Context
8
8
  desc "Dassets::Server::Response"
9
9
  setup do
10
- @resp = file_response(Dassets::AssetFile.new('', ''))
10
+ @resp = file_response(Dassets::AssetFile.new(''))
11
11
  end
12
12
  subject{ @resp }
13
13
 
@@ -16,8 +16,7 @@ class Dassets::Server::Response
16
16
 
17
17
  should "handle not modified files" do
18
18
  af = Dassets['file1.txt']
19
- mtime = File.mtime(af.output_path).httpdate.to_s
20
- resp = file_response(af, 'HTTP_IF_MODIFIED_SINCE' => mtime)
19
+ resp = file_response(af, 'HTTP_IF_MODIFIED_SINCE' => af.mtime)
21
20
 
22
21
  assert_equal 304, resp.status
23
22
  assert_equal [], resp.body
@@ -30,8 +29,8 @@ class Dassets::Server::Response
30
29
  resp = file_response(af)
31
30
  exp_headers = {
32
31
  'Content-Type' => 'text/plain',
33
- 'Content-Length' => File.size?(af.output_path).to_s,
34
- 'Last-Modified' => File.mtime(af.output_path).httpdate.to_s
32
+ 'Content-Length' => Rack::Utils.bytesize(af.content).to_s,
33
+ 'Last-Modified' => af.mtime.to_s
35
34
  }
36
35
 
37
36
  assert_equal 200, resp.status
@@ -0,0 +1,50 @@
1
+ require 'assert'
2
+ require 'dassets/source_file'
3
+ require 'dassets/source_cache'
4
+
5
+ class Dassets::SourceCache
6
+
7
+ class BaseTests < Assert::Context
8
+ desc "Dassets::SourceCache"
9
+ setup do
10
+ @source_cache = Dassets::SourceCache.new('file1.txt')
11
+ end
12
+ subject{ @source_cache }
13
+
14
+ should have_readers :digest_path, :source_file
15
+ should have_imeths :content, :fingerprint, :key, :mtime, :exists?
16
+
17
+ should "know its digest path" do
18
+ assert_equal 'file1.txt', subject.digest_path
19
+ end
20
+
21
+ should "know its source file" do
22
+ exp_source_file = Dassets::SourceFile.find_by_digest_path('file1.txt')
23
+ assert_equal exp_source_file, subject.source_file
24
+ end
25
+
26
+ should "exist if its source file exists" do
27
+ assert_equal subject.source_file.exists?, subject.exists?
28
+ end
29
+
30
+ should "use its source file's mtime as its mtime" do
31
+ assert_equal subject.source_file.mtime, subject.mtime
32
+ end
33
+
34
+ should "use its digest path and mtime as its key" do
35
+ exp_key = "#{subject.digest_path} -- #{subject.mtime}"
36
+ assert_equal exp_key, subject.key
37
+ end
38
+
39
+ should "get its fingerprint from the source file" do
40
+ assert_equal subject.source_file.fingerprint, subject.fingerprint
41
+ end
42
+
43
+ should "get its content from the source file" do
44
+ assert_equal subject.source_file.compiled, subject.content
45
+ end
46
+
47
+
48
+ end
49
+
50
+ end
@@ -1,5 +1,5 @@
1
1
  require 'assert'
2
- require 'dassets/engine'
2
+ require 'dassets/asset_file'
3
3
  require 'dassets/source_file'
4
4
 
5
5
  class Dassets::SourceFile
@@ -13,7 +13,9 @@ class Dassets::SourceFile
13
13
  subject{ @source_file }
14
14
 
15
15
  should have_readers :file_path
16
- should have_imeths :exists?, :digest_path, :compiled, :fingerprint
16
+ should have_imeths :asset_file, :digest_path
17
+ should have_imeths :compiled, :fingerprint, :exists?, :mtime
18
+ should have_cmeth :find_by_digest_path
17
19
 
18
20
  should "know its file path" do
19
21
  assert_equal @file_path, subject.file_path
@@ -23,14 +25,38 @@ class Dassets::SourceFile
23
25
  assert subject.exists?
24
26
  end
25
27
 
28
+ should "use the mtime of its file as its mtime" do
29
+ assert_equal File.mtime(subject.file_path).httpdate, subject.mtime
30
+ end
31
+
26
32
  should "know its digest path" do
27
33
  assert_equal 'file1.txt', subject.digest_path
28
34
  end
29
35
 
36
+ should "know its asset file" do
37
+ assert_kind_of Dassets::AssetFile, subject.asset_file
38
+ assert_equal Dassets::AssetFile.new(subject.digest_path), subject.asset_file
39
+ end
40
+
30
41
  should "know its compiled content fingerprint" do
31
42
  assert_equal 'daa05c683a4913b268653f7a7e36a5b4', subject.fingerprint
32
43
  end
33
44
 
45
+ should "be findable by its digest path" do
46
+ found = Dassets::SourceFile.find_by_digest_path(subject.digest_path)
47
+
48
+ assert_equal subject, found
49
+ assert_not_same subject, found
50
+ end
51
+
52
+ should "find a null src file if finding by an unknown digest path" do
53
+ null_src = Dassets::NullSourceFile.new('not/found/digest/path')
54
+ found = Dassets::SourceFile.find_by_digest_path('not/found/digest/path')
55
+
56
+ assert_equal null_src, found
57
+ assert_not_same null_src, found
58
+ end
59
+
34
60
  end
35
61
 
36
62
  class EngineTests < BaseTests
@@ -52,31 +78,4 @@ class Dassets::SourceFile
52
78
 
53
79
  end
54
80
 
55
- class DigestTests < EngineTests
56
- desc "being digested"
57
- setup do
58
- Dassets.init
59
- @digested_asset_file = @source_file.digest
60
- end
61
- teardown do
62
- Dassets.reset
63
- end
64
-
65
- should "return the digested asset file" do
66
- assert_not_nil @digested_asset_file
67
- assert_kind_of Dassets::AssetFile, @digested_asset_file
68
- end
69
-
70
- should "compile and write an asset file to the output path" do
71
- assert_file_exists @digested_asset_file.output_path
72
- assert_equal subject.compiled, File.read(@digested_asset_file.output_path)
73
- end
74
-
75
- should "add a digests entry for the asset file with its fingerprint" do
76
- digests_on_disk = Dassets::Digests.new(Dassets.config.digests_path)
77
- assert_equal subject.fingerprint, digests_on_disk[subject.digest_path]
78
- end
79
-
80
- end
81
-
82
81
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dassets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-04-25 00:00:00 Z
19
+ date: 2013-05-01 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: assert
@@ -114,34 +114,27 @@ files:
114
114
  - lib/dassets.rb
115
115
  - lib/dassets/asset_file.rb
116
116
  - lib/dassets/cli.rb
117
- - lib/dassets/cmds/cache_cmd.rb
118
- - lib/dassets/cmds/digest_cmd.rb
119
- - lib/dassets/digests.rb
117
+ - lib/dassets/default_cache.rb
118
+ - lib/dassets/digest_cmd.rb
120
119
  - lib/dassets/engine.rb
120
+ - lib/dassets/file_store.rb
121
121
  - lib/dassets/root_path.rb
122
122
  - lib/dassets/runner.rb
123
123
  - lib/dassets/server.rb
124
124
  - lib/dassets/server/request.rb
125
125
  - lib/dassets/server/response.rb
126
+ - lib/dassets/source_cache.rb
126
127
  - lib/dassets/source_file.rb
127
128
  - lib/dassets/version.rb
128
129
  - log/.gitkeep
129
130
  - test/helper.rb
130
131
  - test/support/app.rb
131
- - test/support/app/assets/.digests
132
132
  - test/support/app/assets/file1.txt
133
133
  - test/support/app/assets/file2.txt
134
134
  - test/support/app/assets/grumpy_cat.jpg
135
135
  - test/support/app/assets/nested/a-thing.txt.useless.dumb
136
136
  - test/support/app/assets/nested/file3.txt
137
- - test/support/app/assets/public/file1.txt
138
- - test/support/app/assets/public/file2.txt
139
- - test/support/app/assets/public/grumpy_cat.jpg
140
- - test/support/app/assets/public/nested/a-thing.txt.no-use
141
- - test/support/app/assets/public/nested/file3.txt
142
- - test/support/app_public/.gitkeep
143
137
  - test/support/config/assets.rb
144
- - test/support/example.digests
145
138
  - test/support/public/file1-daa05c683a4913b268653f7a7e36a5b4.txt
146
139
  - test/support/public/file2-9bbe1047cffbb590f59e0e5aeff46ae4.txt
147
140
  - test/support/public/grumpy_cat-b0d1f399a916f7a25c4c0f693c619013.jpg
@@ -151,20 +144,20 @@ files:
151
144
  - test/support/source_files/nested/_nested_ignored.txt
152
145
  - test/support/source_files/nested/test2.txt
153
146
  - test/support/source_files/test1.txt
154
- - test/system/cache_cmd_run_tests.rb
155
147
  - test/system/digest_cmd_run_tests.rb
156
148
  - test/system/rack_tests.rb
157
149
  - test/unit/asset_file_tests.rb
158
- - test/unit/cmds/cache_cmd_tests.rb
159
- - test/unit/cmds/digest_cmd_tests.rb
160
150
  - test/unit/config_tests.rb
161
151
  - test/unit/dassets_tests.rb
162
- - test/unit/digests_tests.rb
152
+ - test/unit/default_cache_tests.rb
153
+ - test/unit/digest_cmd_tests.rb
163
154
  - test/unit/engine_tests.rb
155
+ - test/unit/file_store_tests.rb
164
156
  - test/unit/runner_tests.rb
165
157
  - test/unit/server/request_tests.rb
166
158
  - test/unit/server/response_tests.rb
167
159
  - test/unit/server_tests.rb
160
+ - test/unit/source_cache_tests.rb
168
161
  - test/unit/source_file_tests.rb
169
162
  - tmp/.gitkeep
170
163
  homepage: http://github.com/redding/dassets
@@ -203,20 +196,12 @@ summary: Digested asset files
203
196
  test_files:
204
197
  - test/helper.rb
205
198
  - test/support/app.rb
206
- - test/support/app/assets/.digests
207
199
  - test/support/app/assets/file1.txt
208
200
  - test/support/app/assets/file2.txt
209
201
  - test/support/app/assets/grumpy_cat.jpg
210
202
  - test/support/app/assets/nested/a-thing.txt.useless.dumb
211
203
  - test/support/app/assets/nested/file3.txt
212
- - test/support/app/assets/public/file1.txt
213
- - test/support/app/assets/public/file2.txt
214
- - test/support/app/assets/public/grumpy_cat.jpg
215
- - test/support/app/assets/public/nested/a-thing.txt.no-use
216
- - test/support/app/assets/public/nested/file3.txt
217
- - test/support/app_public/.gitkeep
218
204
  - test/support/config/assets.rb
219
- - test/support/example.digests
220
205
  - test/support/public/file1-daa05c683a4913b268653f7a7e36a5b4.txt
221
206
  - test/support/public/file2-9bbe1047cffbb590f59e0e5aeff46ae4.txt
222
207
  - test/support/public/grumpy_cat-b0d1f399a916f7a25c4c0f693c619013.jpg
@@ -226,18 +211,18 @@ test_files:
226
211
  - test/support/source_files/nested/_nested_ignored.txt
227
212
  - test/support/source_files/nested/test2.txt
228
213
  - test/support/source_files/test1.txt
229
- - test/system/cache_cmd_run_tests.rb
230
214
  - test/system/digest_cmd_run_tests.rb
231
215
  - test/system/rack_tests.rb
232
216
  - test/unit/asset_file_tests.rb
233
- - test/unit/cmds/cache_cmd_tests.rb
234
- - test/unit/cmds/digest_cmd_tests.rb
235
217
  - test/unit/config_tests.rb
236
218
  - test/unit/dassets_tests.rb
237
- - test/unit/digests_tests.rb
219
+ - test/unit/default_cache_tests.rb
220
+ - test/unit/digest_cmd_tests.rb
238
221
  - test/unit/engine_tests.rb
222
+ - test/unit/file_store_tests.rb
239
223
  - test/unit/runner_tests.rb
240
224
  - test/unit/server/request_tests.rb
241
225
  - test/unit/server/response_tests.rb
242
226
  - test/unit/server_tests.rb
227
+ - test/unit/source_cache_tests.rb
243
228
  - test/unit/source_file_tests.rb
@@ -1,33 +0,0 @@
1
- require 'pathname'
2
- require 'fileutils'
3
- require 'dassets'
4
- require 'dassets/digests'
5
-
6
- module Dassets; end
7
- class Dassets::Cmds; end
8
- class Dassets::Cmds::CacheCmd
9
-
10
- attr_reader :cache_root_path, :digests
11
-
12
- def initialize(cache_root_path)
13
- @cache_root_path = Pathname.new(cache_root_path)
14
- @digests = Dassets::Digests.new(Dassets.config.digests_path)
15
- end
16
-
17
- def run(io=nil)
18
- log io, "caching #{@digests.asset_files.count} asset file(s) to `#{@cache_root_path}` ..."
19
- @digests.asset_files.each do |file|
20
- cache_path = @cache_root_path.join(file.url).to_s
21
-
22
- FileUtils.mkdir_p File.dirname(cache_path)
23
- FileUtils.cp(file.output_path, cache_path)
24
- end
25
- end
26
-
27
- private
28
-
29
- def log(io, msg)
30
- io.puts msg if io
31
- end
32
-
33
- end