Changeset 264
- Timestamp:
- 04/25/08 07:25:28 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/picolena/templates/app/models/finder.rb
r263 r264 55 55 } 56 56 57 # Returns matching document for any given query only if 58 # exactly one document is found. 59 # Raises otherwise. 60 def matching_document 61 case matching_documents.size 62 when 0 63 raise IndexError, "No document found" 64 when 1 65 matching_documents.first 66 else 67 raise IndexError, "More than one document found" 68 end 69 end 57 70 58 71 59 def self.reload! trunk/lib/picolena/templates/spec/models/finder_spec.rb
r263 r264 6 6 } 7 7 end 8 9 10 def matching_document_for(query) 11 # Returns matching document for any given query only if 12 # exactly one document is found. 13 # Specs don't pass otherwise. 14 matching_documents=Finder.new(query).matching_documents 15 matching_documents.size.should == 1 16 matching_documents.first 17 end 18 8 19 9 20 describe Finder do … … 60 71 61 72 it "should also index files with unknown mimetypes" do 62 Finder.new("filetype:xyz").matching_document.basename.should == "ghjopdfg"63 Finder.new("filetype:abc").matching_document.filename.should == "asfg.abc"64 Finder.new("unreadable.png").matching_document.size.should == 1969673 matching_document_for("filetype:xyz").basename.should == "ghjopdfg" 74 matching_document_for("filetype:abc").filename.should == "asfg.abc" 75 matching_document_for("unreadable.png").size.should == 19696 65 76 #Support for xls has been added meanwhile. The test is still valid though. 66 Finder.new("table.xls").matching_document.size.should == 870477 matching_document_for("table.xls").size.should == 8704 67 78 end 68 79 … … 81 92 82 93 it "should find documents according to their utf8 content" do 83 Finder.new("Ãric MöÃer ext:pdf").matching_document.basename.should == "utf8"84 Finder.new("no me hace daño").matching_document.size.should == 3085 Finder.new("Ãric MöÃer filetype:pdf").matching_document.filename.should == "utf8.pdf"94 matching_document_for("Ãric MöÃer ext:pdf").basename.should == "utf8" 95 matching_document_for("no me hace daño").size.should == 30 96 matching_document_for("Ãric MöÃer filetype:pdf").filename.should == "utf8.pdf" 86 97 end 87 98 88 99 it "should find documents according to their utf8 filenames" do 89 Finder.new("bÀñÌÃé").matching_document.content.should == "just to know if files are indexed with utf8 filenames"100 matching_document_for("bÀñÌÃé").content.should == "just to know if files are indexed with utf8 filenames" 90 101 end 91 102 92 103 it "should find documents according to their modification date" do 93 104 Finder.new("date:<1982").matching_documents.should be_empty 94 Finder.new("19831209*").matching_document.basename.should == "office2003-word-template"95 Finder.new("date:<1983").matching_document.filename.should == "basic.pdf"96 Finder.new("date:>=1989 AND date:<=1992").matching_document.filename.should == "placeholder.txt"105 matching_document_for("19831209*").basename.should == "office2003-word-template" 106 matching_document_for("date:<1983").filename.should == "basic.pdf" 107 matching_document_for("date:>=1989 AND date:<=1992").filename.should == "placeholder.txt" 97 108 end 98 109 … … 125 136 126 137 it "should use ? as placeholder" do 127 Finder.new("A?sorption machines").matching_document.matching_content.should include("<<Absorption>> and <<Adsorption>> cooling <<machines>>!!!")138 matching_document_for("A?sorption machines").matching_content.should include("<<Absorption>> and <<Adsorption>> cooling <<machines>>!!!") 128 139 end 129 140 130 141 it "should use * as placeholder" do 131 results= Finder.new("A*ption machines").matching_document.matching_content.should include("<<Absorption>> and <<Adsorption>> cooling <<machines>>!!!")142 results=matching_document_for("A*ption machines").matching_content.should include("<<Absorption>> and <<Adsorption>> cooling <<machines>>!!!") 132 143 end 133 144
