浏览代码

Make docs mtime the greatest of the index and db files' mtime

Thibaut 11 年之前
父节点
当前提交
bc5488faa2
共有 2 个文件被更改,包括 13 次插入5 次删除
  1. 5 1
      lib/docs/core/manifest.rb
  2. 8 4
      test/lib/docs/core/manifest_test.rb

+ 5 - 1
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

+ 8 - 4
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