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

pull/165/head
Thibaut 10 years ago
parent ca7ff6086e
commit bc5488faa2

@ -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

@ -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

Loading…
Cancel
Save