History

Merge pull request #1912 from freeCodeCamp/fix-manifest-db_size

Fix manifest db_size

Oliver Eyton-Williams committed 3 years ago

Commit 08147e32 parents da5430a ce248ce3 files · +7 −13Browse files

Unified · Split

3 files
  1. lib/docs/core/doc.rb +0 −10
  2. lib/docs/core/manifest.rb +5 −1
  3. test/lib/docs/core/manifest_test.rb +2 −2
lib/docs/core/doc.rb+0−10
@@ -86,16 +86,6 @@ module Docs · 85 unmodified lines
86 json86 json
87 end87 end
88 88
89 def as_json_extra(store)
90 json = self.as_json
91 if options[:attribution].is_a?(String)
92 json[:attribution] = options[:attribution].strip
93 end
94 json[:db_size] = store.size(self.db_path) if store.exist?(self.db_path)
95 json[:mtime] = store.mtime(self.meta_path).to_i if store.exist?(self.meta_path)
96 json
97 end
98
99 def store_page(store, id)89 def store_page(store, id)
100 index = EntryIndex.new90 index = EntryIndex.new
101 pages = PageDb.new91 pages = PageDb.new
lib/docs/core/manifest.rb+5−1
@@ -16,7 +16,11 @@ module Docs · 15 unmodified lines
16 def as_json16 def as_json
17 @docs.each_with_object [] do |doc, result|17 @docs.each_with_object [] do |doc, result|
18 next unless @store.exist?(doc.meta_path)18 next unless @store.exist?(doc.meta_path)
19 result << doc.as_json_extra(@store)19 json = JSON.parse(@store.read(doc.meta_path))
20 if doc.options[:attribution].is_a?(String)
21 json[:attribution] = doc.options[:attribution].strip
22 end
23 result << json
20 end24 end
21 end25 end
22 26
test/lib/docs/core/manifest_test.rb+2−2
@@ -57,14 +57,14 @@ class ManifestTest < MiniTest::Spec · 56 unmodified lines
57 57
58 context "when the doc has a meta file" do58 context "when the doc has a meta file" do
59 before do59 before do
60 stub(store).exist?("testdoc/db.json") { false }
61 stub(store).exist?(meta_path) { true }60 stub(store).exist?(meta_path) { true }
61 stub(store).read(meta_path) { '{"name":"Test", "db_size": 776533}' }
62 end62 end
63 63
64 it "includes the doc's meta representation" do64 it "includes the doc's meta representation" do
65 json = manifest.as_json65 json = manifest.as_json
66 assert_equal 1, json.length66 assert_equal 1, json.length
67 assert_equal "{:name=>\"TestDoc\", :slug=>\"testdoc\", :type=>nil, :attribution=>\"foo\", :mtime=>0}", json[0].to_s67 assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s
68 end68 end
69 end69 end
70 70