Explorar o código

Fix manifest db_size

Simon Legner %!s(int64=2) %!d(string=hai) anos
pai
achega
ce248cebd0
Modificáronse 3 ficheiros con 7 adicións e 13 borrados
  1. 0 10
      lib/docs/core/doc.rb
  2. 5 1
      lib/docs/core/manifest.rb
  3. 2 2
      test/lib/docs/core/manifest_test.rb

+ 0 - 10
lib/docs/core/doc.rb

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

+ 5 - 1
lib/docs/core/manifest.rb

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

+ 2 - 2
test/lib/docs/core/manifest_test.rb

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