lib/picolena/templates/spec/models/document_spec.rb in picolena-0.1.8 vs lib/picolena/templates/spec/models/document_spec.rb in picolena-0.2.0

- old
+ new

@@ -1,7 +1,10 @@ require File.dirname(__FILE__) + '/../spec_helper' +# NOTE : This file should only be loaded after the Index has been created. +# Otherwise, no go + basic_pdf_attribute={ :dirname=>File.join(RAILS_ROOT, 'spec/test_dirs/indexed/basic'), :basename=>'basic', :complete_path=>File.join(RAILS_ROOT, '/spec/test_dirs/indexed/basic/basic.pdf'), :extname=>'.pdf', @@ -9,10 +12,15 @@ :filename=>'basic.pdf', :size => 9380 } describe Document do + before(:all) do + # To be sure this file has the right content + revert_changes!("spec/test_dirs/indexed/others/placeholder.txt","Absorption and Adsorption cooling machines!!!") + end + before(:each) do @valid_document=Document.new("spec/test_dirs/indexed/basic/basic.pdf") end it "should be an existing file" do @@ -37,15 +45,29 @@ it "should know its content" do another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") another_doc.content.should == "just a content test\nin a txt file" end + #FIXME: Check if content has been cached before trying to display cached content. extension check is not enough + #(e.g. unreadable pdf file) it "should know its cached content" do another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") another_doc.cached.should == "just a content test\nin a txt file" end - + + it "should keep content cached" do + filename = "spec/test_dirs/indexed/others/placeholder.txt" + content_before = "Absorption and Adsorption cooling machines!!!" + some_doc=Document.new(filename) + some_doc.content.should == content_before + File.open(filename,'a'){|doc| + doc.write("This line should not be indexed. It shouldn't be found in cache") + } + some_doc.content.should_not == content_before + some_doc.cached.should == content_before + end + it "should know its highlighted cached content for a given query" do another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") another_doc.highlighted_cache('a content test').should == "just a <<content>> <<test>>\nin a txt file" end @@ -107,7 +129,11 @@ it "should let finder specify its matching content" do @valid_document.should respond_to(:matching_content) @valid_document.matching_content.should be_nil @valid_document.matching_content=["thermal cooling", "heat driven cooling"] @valid_document.matching_content.should include("thermal cooling") + end + + after(:all) do + revert_changes!("spec/test_dirs/indexed/others/placeholder.txt","Absorption and Adsorption cooling machines!!!") end end