| @@ -113,12 +113,12 @@ class DocsDocTest < MiniTest::Spec · 112 unmodified lines |
| 113 | end | 113 | end |
| 114 | end | 114 | end |
| 115 | | 115 | |
| 116 | describe ".index_page" do | 116 | describe ".store_page" do |
| 117 | it "builds a page" do | 117 | it "builds a page" do |
| 118 | any_instance_of(doc) do |instance| | 118 | any_instance_of(doc) do |instance| |
| 119 | stub(instance).build_page('id') { @called = true; nil } | 119 | stub(instance).build_page('id') { @called = true; nil } |
| 120 | end | 120 | end |
| 121 | doc.index_page('id') {} | 121 | doc.store_page(store, 'id') {} |
| 122 | assert @called | 122 | assert @called |
| 123 | end | 123 | end |
| 124 | | 124 | |
| @@ -130,20 +130,23 @@ class DocsDocTest < MiniTest::Spec · 5 unmodified lines |
| 130 | end | 130 | end |
| 131 | | 131 | |
| 132 | context "and it has :entries" do | 132 | context "and it has :entries" do |
| 133 | it "yields the page's :store_path and :output" do | 133 | it "returns true" do |
| 134 | doc.index_page('') { |*args| @args = args } | 134 | assert doc.store_page(store, 'id') |
| 135 | assert_equal [page[:store_path], page[:output]], @args | | |
| 136 | end | 135 | end |
| 137 | | 136 | |
| 138 | it "returns an EntryIndex" do | 137 | it "stores a file" do |
| 139 | assert_instance_of Docs::EntryIndex, doc.index_page('') {} | 138 | mock(store).write(page[:store_path], page[:output]) |
| | 139 | doc.store_page(store, 'id') |
| 140 | end | 140 | end |
| 141 | | 141 | |
| 142 | describe "the index" do | 142 | it "opens the .path directory before storing the file" do |
| 143 | it "contains the page's entries" do | 143 | stub(doc).path { 'path' } |
| 144 | index = doc.index_page('') {} | 144 | stub(store).write { assert false } |
| 145 | assert_equal page[:entries], index.entries | 145 | mock(store).open('path') do |_, block| |
| | 146 | stub(store).write |
| | 147 | block.call |
| 146 | end | 148 | end |
| | 149 | doc.store_page(store, 'id') |
| 147 | end | 150 | end |
| 148 | end | 151 | end |
| 149 | | 152 | |
| @@ -152,13 +155,13 @@ class DocsDocTest < MiniTest::Spec · 2 unmodified lines |
| 152 | page[:entries] = [] | 155 | page[:entries] = [] |
| 153 | end | 156 | end |
| 154 | | 157 | |
| 155 | it "doesn't yield" do | 158 | it "returns false" do |
| 156 | doc.index_page('') { |*_| @yield = true } | 159 | refute doc.store_page(store, 'id') |
| 157 | refute @yield | | |
| 158 | end | 160 | end |
| 159 | | 161 | |
| 160 | it "returns nil" do | 162 | it "doesn't store a file" do |
| 161 | assert_nil doc.index_page('') {} | 163 | dont_allow(store).write |
| | 164 | doc.store_page(store, 'id') |
| 162 | end | 165 | end |
| 163 | end | 166 | end |
| 164 | end | 167 | end |
| @@ -170,13 +173,13 @@ class DocsDocTest < MiniTest::Spec · 5 unmodified lines |
| 170 | end | 173 | end |
| 171 | end | 174 | end |
| 172 | | 175 | |
| 173 | it "doesn't yield" do | 176 | it "returns false" do |
| 174 | doc.index_page('') { |*_| @yield = true } | 177 | refute doc.store_page(store, 'id') |
| 175 | refute @yield | | |
| 176 | end | 178 | end |
| 177 | | 179 | |
| 178 | it "returns nil" do | 180 | it "doesn't store a file" do |
| 179 | assert_nil doc.index_page('') {} | 181 | dont_allow(store).write |
| | 182 | doc.store_page(store, 'id') |
| 180 | end | 183 | end |
| 181 | end | 184 | end |
| 182 | end | 185 | end |
| @@ -256,48 +259,6 @@ class DocsDocTest < MiniTest::Spec · 73 unmodified lines |
| 256 | end | 259 | end |
| 257 | end | 260 | end |
| 258 | | 261 | |
| 259 | describe ".store_page" do | | |
| 260 | context "when the page is indexed successfully" do | | |
| 261 | before do | | |
| 262 | stub(doc).index_page('id').yields(page[:store_path], page[:output]) { index } | | |
| 263 | end | | |
| 264 | | | |
| 265 | it "returns true" do | | |
| 266 | assert doc.store_page(store, 'id') | | |
| 267 | end | | |
| 268 | | | |
| 269 | it "stores a file" do | | |
| 270 | mock(store).write(page[:store_path], page[:output]) | | |
| 271 | doc.store_page(store, 'id') | | |
| 272 | end | | |
| 273 | | | |
| 274 | it "opens the .path directory before storing the file" do | | |
| 275 | stub(doc).path { 'path' } | | |
| 276 | stub(store).write { assert false } | | |
| 277 | mock(store).open('path') do |_, block| | | |
| 278 | stub(store).write | | |
| 279 | block.call | | |
| 280 | end | | |
| 281 | doc.store_page(store, 'id') | | |
| 282 | end | | |
| 283 | end | | |
| 284 | | | |
| 285 | context "when the page isn't indexed successfully" do | | |
| 286 | before do | | |
| 287 | stub(doc).index_page('id') { nil } | | |
| 288 | end | | |
| 289 | | | |
| 290 | it "returns false" do | | |
| 291 | refute doc.store_page(store, 'id') | | |
| 292 | end | | |
| 293 | | | |
| 294 | it "doesn't store a file" do | | |
| 295 | dont_allow(store).write | | |
| 296 | doc.store_page(store, 'id') | | |
| 297 | end | | |
| 298 | end | | |
| 299 | end | | |
| 300 | | | |
| 301 | describe ".store_pages" do | 262 | describe ".store_pages" do |
| 302 | context "when pages are indexed successfully" do | 263 | context "when pages are indexed successfully" do |
| 303 | before do | 264 | before do |