Fix manifest db_size

This commit is contained in:
Simon Legner 2023-01-10 19:44:10 +01:00
parent da5430aaff
commit ce248cebd0
3 changed files with 7 additions and 13 deletions

View file

@ -86,16 +86,6 @@ module Docs
json
end
def as_json_extra(store)
json = self.as_json
if options[:attribution].is_a?(String)
json[:attribution] = options[:attribution].strip
end
json[:db_size] = store.size(self.db_path) if store.exist?(self.db_path)
json[:mtime] = store.mtime(self.meta_path).to_i if store.exist?(self.meta_path)
json
end
def store_page(store, id)
index = EntryIndex.new
pages = PageDb.new

View file

@ -16,7 +16,11 @@ module Docs
def as_json
@docs.each_with_object [] do |doc, result|
next unless @store.exist?(doc.meta_path)
result << doc.as_json_extra(@store)
json = JSON.parse(@store.read(doc.meta_path))
if doc.options[:attribution].is_a?(String)
json[:attribution] = doc.options[:attribution].strip
end
result << json
end
end

View file

@ -57,14 +57,14 @@ class ManifestTest < MiniTest::Spec
context "when the doc has a meta file" do
before do
stub(store).exist?("testdoc/db.json") { false }
stub(store).exist?(meta_path) { true }
stub(store).read(meta_path) { '{"name":"Test", "db_size": 776533}' }
end
it "includes the doc's meta representation" do
json = manifest.as_json
assert_equal 1, json.length
assert_equal "{:name=>\"TestDoc\", :slug=>\"testdoc\", :type=>nil, :attribution=>\"foo\", :mtime=>0}", json[0].to_s
assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s
end
end