Changeset 292
- Timestamp:
- 04/29/08 02:42:46 (7 months ago)
- Files:
-
- branches/log_indexing_time_with_ferret/lib/picolena/templates/app/models/document.rb (modified) (1 diff)
- branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/document_spec.rb (modified) (3 diffs)
- branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/host_indexing_system_spec.rb (modified) (1 diff)
- branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/plain_text_extractor_spec.rb (modified) (1 diff)
- branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/query_spec.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/log_indexing_time_with_ferret/lib/picolena/templates/app/models/document.rb
r279 r292 70 70 :field => :content, :excerpt_length => :all, 71 71 :pre_tag => "<<", :post_tag => ">>" 72 ) 72 ).first 73 73 end 74 74 branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/document_spec.rb
r270 r292 6 6 :complete_path=>File.join(RAILS_ROOT, '/spec/test_dirs/indexed/basic/basic.pdf'), 7 7 :extname=>'.pdf', 8 :filename=>'basic.pdf' 8 :ext_as_sym => :pdf, 9 :filename=>'basic.pdf', 10 :size => 9380 9 11 } 10 12 11 13 describe Document do 12 14 before(:each) do 13 @valid_ random_doc=Document.find(:random) rescueDocument.new("spec/test_dirs/indexed/basic/basic.pdf")15 @valid_document=Document.new("spec/test_dirs/indexed/basic/basic.pdf") 14 16 end 15 17 16 18 it "should be an existing file" do 17 19 lambda {Document.new("/patapouf.txt")}.should raise_error(Errno::ENOENT) 18 lambda {@valid_ random_doc}.should_not raise_error20 lambda {@valid_document}.should_not raise_error 19 21 lambda {Document.new("spec/test_dirs/not_indexed/Rakefile")}.should_not raise_error(Errno::ENOENT) 20 22 end 21 23 22 24 it "should belong to an indexed directory" do 23 lambda {@valid_ random_doc}.should_not raise_error25 lambda {@valid_document}.should_not raise_error 24 26 lambda {Document.new("spec/test_dirs/not_indexed/Rakefile")}.should raise_error(ArgumentError, "required document is not in indexed directory") 25 27 end … … 27 29 basic_pdf_attribute.each{|attribute,expected_value| 28 30 it "should know its #{attribute}" do 29 @valid_ random_doc.should respond_to(attribute)31 @valid_document.should respond_to(attribute) 30 32 @basic_pdf=Document.new('spec/test_dirs/indexed/basic/basic.pdf') 31 33 @basic_pdf.send(attribute).should == expected_value … … 37 39 another_doc.content.should == "just a content test\nin a txt file" 38 40 end 41 42 it "should know its cached content" do 43 another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") 44 another_doc.cached.should == "just a content test\nin a txt file" 45 end 46 47 it "should know its highlighted cached content for a given query" do 48 another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") 49 another_doc.highlighted_cache('a content test').should == "just a <<content>> <<test>>\nin a txt file" 50 end 39 51 40 52 it "should know its alias_path" do 41 @valid_ random_doc.should respond_to(:alias_path)42 @valid_ random_doc.alias_path.starts_with?("http://picolena.devjavu.com/browser/trunk/lib/picolena/templates/spec/test_dirs/indexed").should be_true53 @valid_document.should respond_to(:alias_path) 54 @valid_document.alias_path.starts_with?("http://picolena.devjavu.com/browser/trunk/lib/picolena/templates/spec/test_dirs/indexed").should be_true 43 55 end 56 57 it "should know its probably_unique_id" do 58 @valid_document.should respond_to(:probably_unique_id) 59 @valid_document.probably_unique_id.should =~/^[a-z]+$/ 60 @valid_document.probably_unique_id.size.should == Picolena::HashLength 61 end 62 63 it "should know its modification date" do 64 @valid_document.pretty_date.class.should == String 65 @valid_document.pretty_date.should =~/^\d{4}\-\d{2}\-\d{2}$/ 66 end 67 68 it "should know its modification time and returns it in a pretty way" do 69 @valid_document.should respond_to(:mtime) 70 @valid_document.mtime.class.should == Bignum 71 @valid_document.should respond_to(:pretty_mtime) 72 @valid_document.pretty_mtime.class.should == String 73 @valid_document.pretty_mtime.should =~/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/ 74 end 75 76 it "should know if its content can be extracted" do 77 @valid_document.should respond_to(:supported?) 78 @valid_document.should be_supported 79 Document.new("spec/test_dirs/indexed/others/ghjopdfg.xyz").should_not be_supported 80 end 81 82 it "should know its language when enough content is available" do 83 Document.new("spec/test_dirs/indexed/lang/goethe").language.should == "de" 84 Document.new("spec/test_dirs/indexed/lang/shakespeare").language.should == "en" 85 Document.new("spec/test_dirs/indexed/lang/lorca").language.should == "es" 86 Document.new("spec/test_dirs/indexed/lang/hugo").language.should == "fr" 87 end if Picolena::UseLanguageRecognition 88 89 it "should not try to guess language when file is too small" do 90 Document.new("spec/test_dirs/indexed/basic/hello.rb").language.should be_nil 91 Document.new("spec/test_dirs/indexed/README").language.should be_nil 92 end if Picolena::UseLanguageRecognition 44 93 45 94 it "should let finder specify its score" do 46 @valid_ random_doc.should respond_to(:score)47 @valid_ random_doc.score.should be_nil48 @valid_ random_doc.score=2549 @valid_ random_doc.score.should == 2595 @valid_document.should respond_to(:score) 96 @valid_document.score.should be_nil 97 @valid_document.score=25 98 @valid_document.score.should == 25 50 99 end 51 100 52 101 it "should let finder specify its matching content" do 53 @valid_ random_doc.should respond_to(:matching_content)54 @valid_ random_doc.matching_content.should be_nil55 @valid_ random_doc.matching_content=["thermal cooling", "heat driven cooling"]56 @valid_ random_doc.matching_content.should include("thermal cooling")102 @valid_document.should respond_to(:matching_content) 103 @valid_document.matching_content.should be_nil 104 @valid_document.matching_content=["thermal cooling", "heat driven cooling"] 105 @valid_document.matching_content.should include("thermal cooling") 57 106 end 58 107 end branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/host_indexing_system_spec.rb
r263 r292 14 14 it "should know which IP addresses are allowed (config/custom/white_list_ip.yml)" do 15 15 File.should be_readable('config/custom/white_list_ip.yml') 16 ip_conf=YAML.load_file('config/custom/white_list_ip.yml') 17 ip_conf.class.should == Hash 18 ip_conf['Allow'].should_not be_nil 16 19 end 17 20 18 21 it "should know which directories are to be indexed (config/custom/indexed_directories.yml)" do 19 22 File.should be_readable('config/custom/indexed_directories.yml') 23 dirs_conf=YAML.load_file('config/custom/indexed_directories.yml') 24 dirs_conf.class.should == Hash 25 %w(development test production).all?{|env| 26 dirs_conf[env].should_not be_nil 27 } 20 28 end 21 29 branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/plain_text_extractor_spec.rb
r263 r292 28 28 } 29 29 } 30 31 it "should guess language when enough content is available" do32 Document.new("spec/test_dirs/indexed/lang/goethe").language.should == "de"33 Document.new("spec/test_dirs/indexed/lang/shakespeare").language.should == "en"34 Document.new("spec/test_dirs/indexed/lang/lorca").language.should == "es"35 Document.new("spec/test_dirs/indexed/lang/hugo").language.should == "fr"36 end if Picolena::UseLanguageRecognition37 38 it "should not try to guess language when file is too small" do39 Document.new("spec/test_dirs/indexed/basic/hello.rb").language.should be_nil40 Document.new("spec/test_dirs/indexed/README").language.should be_nil41 end if Picolena::UseLanguageRecognition42 30 end branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/query_spec.rb
r263 r292 2 2 3 3 describe Query do 4 it "should return a BooleanQuery " do4 it "should return a BooleanQuery, a TermQuery or a RangeQuery" do 5 5 Query.extract_from("whatever").class.should == Ferret::Search::BooleanQuery 6 Query.extract_from("lang:de").class.should == Ferret::Search::TermQuery 7 Query.extract_from("date:<1990").class.should == Ferret::Search::RangeQuery 8 end 9 10 it "should not remove stop-words from TermQuery" do 11 # it means "Italian language", but also is a stop-word. 12 Query.extract_from("lang:it").class.should == Ferret::Search::TermQuery 13 Query.extract_from("lang:it").to_s.should == "language:it" 6 14 end 7 15
