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
8686 json
8787 end
8888
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−
9989 def store_page(store, id)
10090 index = EntryIndex.new
10191 pages = PageDb.new
lib/docs/core/manifest.rb+5−1
@@ -16,7 +16,11 @@ module Docs · 15 unmodified lines
1616 def as_json
1717 @docs.each_with_object [] do |doc, result|
1818 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
2024 end
2125 end
2226
test/lib/docs/core/manifest_test.rb+2−2
@@ -57,14 +57,14 @@ class ManifestTest < MiniTest::Spec · 56 unmodified lines
5757
5858 context "when the doc has a meta file" do
5959 before do
60− stub(store).exist?("testdoc/db.json") { false }
6160 stub(store).exist?(meta_path) { true }
61+ stub(store).read(meta_path) { '{"name":"Test", "db_size": 776533}' }
6262 end
6363
6464 it "includes the doc's meta representation" do
6565 json = manifest.as_json
6666 assert_equal 1, json.length
67− assert_equal "{:name=>\"TestDoc\", :slug=>\"testdoc\", :type=>nil, :attribution=>\"foo\", :mtime=>0}", json[0].to_s
67+ assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s
6868 end
6969 end
7070