From ca61a2b746ae2e3e92242579cc02de5f0bd22d9b Mon Sep 17 00:00:00 2001 From: Thibaut Date: Wed, 31 Dec 2014 14:00:20 -0500 Subject: [PATCH] Add Doc#db_path --- assets/javascripts/models/doc.coffee | 2 +- lib/docs/core/doc.rb | 7 ++++++- test/lib/docs/core/doc_test.rb | 11 +++++++++-- test/lib/docs/core/manifest_test.rb | 5 +++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index 03c799c6..3af515c3 100644 --- a/assets/javascripts/models/doc.coffee +++ b/assets/javascripts/models/doc.coffee @@ -1,5 +1,5 @@ class app.models.Doc extends app.Model - # Attributes: name, slug, type, version, index_path, mtime + # Attributes: name, slug, type, version, index_path, db_path, mtime constructor: -> super diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index c0772a1c..6388c568 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -26,12 +26,17 @@ module Docs File.join path, INDEX_FILENAME end + def db_path + File.join path, DB_FILENAME + end + def as_json { name: name, slug: slug, type: type, version: version, - index_path: index_path } + index_path: index_path, + db_path: db_path } end def store_page(store, id) diff --git a/test/lib/docs/core/doc_test.rb b/test/lib/docs/core/doc_test.rb index 9cf65270..dfad3731 100644 --- a/test/lib/docs/core/doc_test.rb +++ b/test/lib/docs/core/doc_test.rb @@ -87,6 +87,13 @@ class DocsDocTest < MiniTest::Spec end end + describe ".db_path" do + it "returns .path + ::DB_FILENAME" do + stub(doc).path { 'path' } + assert_equal File.join('path', Docs::Doc::DB_FILENAME), doc.db_path + end + end + describe ".new" do it "raises an error when .abstract is true" do doc.abstract = true @@ -101,8 +108,8 @@ class DocsDocTest < MiniTest::Spec assert_instance_of Hash, doc.as_json end - it "includes the doc's name, slug, type, version and index_path" do - %w(name slug type version index_path).each do |attribute| + it "includes the doc's name, slug, type, version, index_path and db_path" do + %w(name slug type version index_path db_path).each do |attribute| eval "stub(doc).#{attribute} { attribute }" assert_equal attribute, doc.as_json[attribute.to_sym] end diff --git a/test/lib/docs/core/manifest_test.rb b/test/lib/docs/core/manifest_test.rb index 06c498a5..cb02e259 100644 --- a/test/lib/docs/core/manifest_test.rb +++ b/test/lib/docs/core/manifest_test.rb @@ -43,8 +43,13 @@ class ManifestTest < MiniTest::Spec 'index_path' end + let :db_path do + 'db_path' + end + before do stub(doc).index_path { index_path } + stub(doc).db_path { db_path } end it "returns an array" do