public
Description: Library for accessing ThruDB documents.
Clone URL: git://github.com/technoweenie/activedocument.git
indexing
technoweenie (author)
Sat Jan 12 11:26:03 -0800 2008
commit  2e1e1fec7b5b10c8765098eb178eb17a8c75d993
tree    833d00401c957fc368a350195bfa4dfbd2782549
parent  f61a498cead3ecf65ed0b7dae1d8c771d187d12c
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ module ActiveDocument
0
     end
0
     
0
     def index!
0
- manager.index self
0
+ (@id.nil? || self.class.indexed_fields.nil? || self.class.indexed_fields.empty?) ? nil : manager.index(self)
0
     end
0
     
0
     def doc_message
...
1
2
 
 
 
 
 
 
 
 
 
3
4
5
...
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
...
28
29
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
36
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
25
26
27
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
...
52
53
54
 
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
0
@@ -1,5 +1,14 @@
0
 require File.join(File.dirname(__FILE__), 'spec_helper')
0
 describe ActiveDocument do
0
+ before do
0
+ MockRecord.manager.indexed_docs.clear
0
+ MockRecord.indexes
0
+ end
0
+
0
+ after :all do
0
+ FileUtils.rm_rf File.join(File.dirname(__FILE__), 'doc')
0
+ end
0
+
0
   # generic tests meant to work with mock yaml manager or thrudb manager
0
   it "serializes and deserializes records" do
0
     record = MockRecord.new
0
@@ -16,7 +25,22 @@ describe ActiveDocument do
0
     MockRecord.fetch(record.id).should == record
0
   end
0
   
0
- describe "Indexed Fields" do
0
+ it "indexes record after storing it" do
0
+ MockRecord.indexes :content, :name => {:sortable => true}
0
+ record = MockRecord.new
0
+ lambda do
0
+ record.save
0
+ end.should change { MockRecord.manager.indexed_docs.size }.by(1)
0
+ end
0
+
0
+ it "skips indexing after saving if there are no indexed fields" do
0
+ record = MockRecord.new
0
+ lambda do
0
+ record.save
0
+ end.should change { MockRecord.manager.indexed_docs.size }.by(0)
0
+ end
0
+
0
+ describe "#indexes" do
0
     it "stores index filed data in #indexed_fields" do
0
       MockRecord.indexes :name => {:sortable => true}
0
       MockRecord.indexed_fields.should == {:name => {:sortable => true}}
0
@@ -28,8 +52,38 @@ describe ActiveDocument do
0
     end
0
     
0
     it "accepts array of attributes without custom options" do
0
- MockRecord.indexes :contents, :name => {:sortable => true}
0
- MockRecord.indexed_fields.should == {:name => {:sortable => true}, :contents => {}}
0
+ MockRecord.indexes :content, :name => {:sortable => true}
0
+ MockRecord.indexed_fields.should == {:name => {:sortable => true}, :content => {}}
0
+ end
0
+ end
0
+
0
+ describe "#doc_message" do
0
+ before :all do
0
+ MockRecord.indexes :content, :name => {:sortable => true}
0
+ @record = MockRecord.new
0
+ @record.save
0
+ @doc = @record.doc_message
0
+ @content_field = @doc.fields.detect { |f| f.name == 'content' }
0
+ @name_field = @doc.fields.detect { |f| f.name == 'name' }
0
+ end
0
+
0
+ it "receives #docid from record ID" do
0
+ @doc.docid.should == @record.id
0
+ end
0
+
0
+ it "receives index name from the record class" do
0
+ @doc.index.should == @record.class.index_name
0
+ end
0
+
0
+ it "lists indexed fields specified by ActiveDocument::ClassMethods#indexes" do
0
+ @doc.should have(2).fields
0
+ @doc.fields.should include(@content_field)
0
+ @doc.fields.should include(@name_field)
0
+ end
0
+
0
+ it "stores field value from record" do
0
+ @content_field.value.should == @record.content
0
+ @name_field.value.should == @record.name
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
26
27
28
 
 
 
 
 
 
 
 
29
30
...
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -26,4 +26,12 @@ class MockManager
0
     end
0
     record.object_id
0
   end
0
+
0
+ def indexed_docs
0
+ @indexed_docs ||= []
0
+ end
0
+
0
+ def index(doc)
0
+ indexed_docs << doc
0
+ end
0
 end
0
\ No newline at end of file
...
8
9
10
 
 
 
 
11
12
 
13
14
15
...
8
9
10
11
12
13
14
15
 
16
17
18
19
0
@@ -8,8 +8,12 @@ rescue LoadError
0
   # no debugging
0
 end
0
 
0
+$LOAD_PATH << File.join(File.dirname(__FILE__))
0
+$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
0
+$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'vendor', 'thrudb')
0
+
0
 require 'mock_manager'
0
-require '../lib/active_document'
0
+require 'active_document'
0
 
0
 require 'digest/sha1'
0
 class MockRecord

Comments

    No one has commented yet.