Browse Source

Optionally include 'release' and 'links' in docs manifest

Thibaut Courouble 10 years ago
parent
commit
bd6e27eca2
2 changed files with 6 additions and 5 deletions
  1. 4 5
      lib/docs/core/doc.rb
  2. 2 0
      test/lib/docs/core/doc_test.rb

+ 4 - 5
lib/docs/core/doc.rb

@@ -33,11 +33,10 @@ module Docs
       end
 
       def as_json
-        { name: name,
-          slug: slug,
-          type: type,
-          release: release,
-          links: links }
+        json = { name: name, slug: slug, type: type }
+        json[:links] = links if links.present?
+        json[:release] = release if release.present?
+        json
       end
 
       def store_page(store, id)

+ 2 - 0
test/lib/docs/core/doc_test.rb

@@ -116,6 +116,8 @@ class DocsDocTest < MiniTest::Spec
     end
 
     it "includes the doc's name, slug, type, and release" do
+      assert_equal %i(name slug type), doc.as_json.keys
+
       %w(name slug type release links).each do |attribute|
         eval "stub(doc).#{attribute} { attribute }"
         assert_equal attribute, doc.as_json[attribute.to_sym]