Unified · Split
| @@ -15,7 +15,7 @@ module Docs · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | def as_json | 16 | def as_json |
| 17 | indexed_docs.map(&:as_json).each do |json| | 17 | indexed_docs.map(&:as_json).each do |json| |
| 18 | json[:mtime] = @store.mtime(json[:index_path]).to_i | 18 | json[:mtime] = doc_mtime(json) |
| 19 | end | 19 | end |
| 20 | end | 20 | end |
| 21 | 21 | ||
| @@ -30,5 +30,9 @@ module Docs · 8 unmodified lines | |||
| 30 | @store.exist?(doc.index_path) && @store.exist?(doc.db_path) | 30 | @store.exist?(doc.index_path) && @store.exist?(doc.db_path) |
| 31 | end | 31 | end |
| 32 | end | 32 | end |
| 33 | |||
| 34 | def doc_mtime(doc) | ||
| 35 | [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max | ||
| 36 | end | ||
| 33 | end | 37 | end |
| 34 | end | 38 | end |
| @@ -69,10 +69,14 @@ class ManifestTest < MiniTest::Spec · 68 unmodified lines | |||
| 69 | assert_empty doc.as_json.keys - json.first.keys | 69 | assert_empty doc.as_json.keys - json.first.keys |
| 70 | end | 70 | end |
| 71 | 71 | ||
| 72 | it "adds an :mtime attribute" do | 72 | it "adds an :mtime attribute with the greatest of the index and db files' mtime" do |
| 73 | mtime = Time.now - 1 | 73 | mtime_index = Time.now - 1 |
| 74 | stub(store).mtime(index_path) { mtime } | 74 | mtime_db = Time.now - 2 |
| 75 | assert_equal mtime.to_i, manifest.as_json.first[:mtime] | 75 | stub(store).mtime(index_path) { mtime_index } |
| 76 | stub(store).mtime(db_path) { mtime_db } | ||
| 77 | assert_equal mtime_index.to_i, manifest.as_json.first[:mtime] | ||
| 78 | mtime_index, mtime_db = mtime_db, mtime_index | ||
| 79 | assert_equal mtime_db.to_i, manifest.as_json.first[:mtime] | ||
| 76 | end | 80 | end |
| 77 | end | 81 | end |
| 78 | 82 | ||