Changeset 264

Show
Ignore:
Timestamp:
04/25/08 07:25:28 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

matching_document was only used in specs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/picolena/templates/app/models/finder.rb

    r263 r264  
    5555  } 
    5656 
    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 
    7058 
    7159  def self.reload! 
  • trunk/lib/picolena/templates/spec/models/finder_spec.rb

    r263 r264  
    66  } 
    77end 
     8 
     9 
     10def 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 
     17end 
     18 
    819 
    920describe Finder do 
     
    6071 
    6172  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 == 19696 
     73    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 
    6576    #Support for xls has been added meanwhile. The test is still valid though. 
    66     Finder.new("table.xls").matching_document.size.should == 8704 
     77    matching_document_for("table.xls").size.should == 8704 
    6778  end 
    6879 
     
    8192 
    8293  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 == 30 
    85     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" 
    8697  end 
    8798 
    8899  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" 
    90101  end 
    91102 
    92103  it "should find documents according to their modification date" do 
    93104    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" 
    97108  end 
    98109 
     
    125136 
    126137  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>>!!!") 
    128139  end 
    129140 
    130141  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>>!!!") 
    132143  end 
    133144