0
require File.join(File.dirname(__FILE__), 'spec_helper')
0
describe ActiveDocument do
0
+ MockRecord.manager.indexed_docs.clear
0
+ FileUtils.rm_rf File.join(File.dirname(__FILE__), 'doc')
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
- describe "Indexed Fields" do
0
+ it "indexes record after storing it" do
0
+ MockRecord.indexes :content, :name => {:sortable => true}
0
+ record = MockRecord.new
0
+ end.should change { MockRecord.manager.indexed_docs.size }.by(1)
0
+ it "skips indexing after saving if there are no indexed fields" do
0
+ record = MockRecord.new
0
+ end.should change { MockRecord.manager.indexed_docs.size }.by(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
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
+ describe "#doc_message" do
0
+ MockRecord.indexes :content, :name => {:sortable => true}
0
+ @record = MockRecord.new
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
+ it "receives #docid from record ID" do
0
+ @doc.docid.should == @record.id
0
+ it "receives index name from the record class" do
0
+ @doc.index.should == @record.class.index_name
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
+ it "stores field value from record" do
0
+ @content_field.value.should == @record.content
0
+ @name_field.value.should == @record.name
0
\ No newline at end of file
Comments
No one has commented yet.