| @@ -3,7 +3,7 @@ require 'docs' · 2 unmodified lines |
| 3 | | 3 | |
| 4 | class DocsEntryIndexTest < MiniTest::Spec | 4 | class DocsEntryIndexTest < MiniTest::Spec |
| 5 | let :entry do | 5 | let :entry do |
| 6 | Docs::Entry.new 'name', 'type', 'path' | 6 | Docs::Entry.new 'name', 'path', 'type' |
| 7 | end | 7 | end |
| 8 | | 8 | |
| 9 | let :index do | 9 | let :index do |
| @@ -29,7 +29,11 @@ class DocsEntryIndexTest < MiniTest::Spec · 19 unmodified lines |
| 29 | end | 29 | end |
| 30 | | 30 | |
| 31 | it "stores an array of entries" do | 31 | it "stores an array of entries" do |
| 32 | entries = [entry, entry] | 32 | entries = [ |
| | 33 | Docs::Entry.new('one', 'path', 'type'), |
| | 34 | Docs::Entry.new('two', 'path', 'type') |
| | 35 | ] |
| | 36 | |
| 33 | index.add(entries) | 37 | index.add(entries) |
| 34 | assert_equal entries, index.entries | 38 | assert_equal entries, index.entries |
| 35 | end | 39 | end |
| @@ -46,11 +50,17 @@ class DocsEntryIndexTest < MiniTest::Spec · 10 unmodified lines |
| 46 | assert_empty index.types | 50 | assert_empty index.types |
| 47 | end | 51 | end |
| 48 | | 52 | |
| | 53 | it "doesn't store the same entry twice" do |
| | 54 | 2.times { index.add(entry.dup) } |
| | 55 | assert_equal [entry], index.entries |
| | 56 | end |
| | 57 | |
| 49 | it "creates and indexes the type" do | 58 | it "creates and indexes the type" do |
| 50 | entry.type = 'one'; index.add(entry) | 59 | index.add Docs::Entry.new('one', 'path', 'a') |
| 51 | entry.type = 'two'; 2.times { index.add(entry) } | 60 | index.add Docs::Entry.new('two', 'path', 'b') |
| 52 | assert_equal ['one', 'two'], index.types.keys | 61 | index.add Docs::Entry.new('three', 'path', 'b') |
| 53 | assert_instance_of Docs::Type, index.types['one'] | 62 | assert_equal ['a', 'b'], index.types.keys |
| | 63 | assert_instance_of Docs::Type, index.types['a'] |
| 54 | end | 64 | end |
| 55 | | 65 | |
| 56 | it "doesn't index the nil type" do | 66 | it "doesn't index the nil type" do |
| @@ -59,8 +69,9 @@ class DocsEntryIndexTest < MiniTest::Spec · 2 unmodified lines |
| 59 | end | 69 | end |
| 60 | | 70 | |
| 61 | it "increments the type's count" do | 71 | it "increments the type's count" do |
| 62 | 2.times { index.add(entry) } | 72 | index.add Docs::Entry.new('one', 'path', 'type') |
| 63 | assert_equal 2, index.types[entry.type].count | 73 | index.add Docs::Entry.new('two', 'path', 'type') |
| | 74 | assert_equal 2, index.types['type'].count |
| 64 | end | 75 | end |
| 65 | end | 76 | end |
| 66 | | 77 | |
| @@ -90,8 +101,9 @@ class DocsEntryIndexTest < MiniTest::Spec · 23 unmodified lines |
| 90 | end | 101 | end |
| 91 | | 102 | |
| 92 | it "includes the json representation of the #entries" do | 103 | it "includes the json representation of the #entries" do |
| 93 | index.add [entry, entry] | 104 | index.add one = Docs::Entry.new('one', 'path', 'type') |
| 94 | assert_equal [entry.as_json, entry.as_json], index.as_json[:entries] | 105 | index.add two = Docs::Entry.new('two', 'path', 'type') |
| | 106 | assert_equal [one.as_json, two.as_json], index.as_json[:entries] |
| 95 | end | 107 | end |
| 96 | | 108 | |
| 97 | it "is sorted by name, case-insensitive" do | 109 | it "is sorted by name, case-insensitive" do |