diff --git a/lib/docs/core/manifest.rb b/lib/docs/core/manifest.rb index 2c04b2b0..23f27bdb 100644 --- a/lib/docs/core/manifest.rb +++ b/lib/docs/core/manifest.rb @@ -15,7 +15,7 @@ module Docs def as_json indexed_docs.map(&:as_json).each do |json| - json[:mtime] = @store.mtime(json[:index_path]).to_i + json[:mtime] = doc_mtime(json) end end @@ -30,5 +30,9 @@ module Docs @store.exist?(doc.index_path) && @store.exist?(doc.db_path) end end + + def doc_mtime(doc) + [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max + end end end diff --git a/test/lib/docs/core/manifest_test.rb b/test/lib/docs/core/manifest_test.rb index 7b22a25e..f5045c55 100644 --- a/test/lib/docs/core/manifest_test.rb +++ b/test/lib/docs/core/manifest_test.rb @@ -69,10 +69,14 @@ class ManifestTest < MiniTest::Spec assert_empty doc.as_json.keys - json.first.keys end - it "adds an :mtime attribute" do - mtime = Time.now - 1 - stub(store).mtime(index_path) { mtime } - assert_equal mtime.to_i, manifest.as_json.first[:mtime] + it "adds an :mtime attribute with the greatest of the index and db files' mtime" do + mtime_index = Time.now - 1 + mtime_db = Time.now - 2 + stub(store).mtime(index_path) { mtime_index } + stub(store).mtime(db_path) { mtime_db } + assert_equal mtime_index.to_i, manifest.as_json.first[:mtime] + mtime_index, mtime_db = mtime_db, mtime_index + assert_equal mtime_db.to_i, manifest.as_json.first[:mtime] end end