Navigation Menu

Skip to content

Commit

Permalink
+ query base, field specs
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Oct 25, 2010
1 parent 24266d8 commit a5da40f
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 0 deletions.
140 changes: 140 additions & 0 deletions server/spec/lib/configuration/field_spec.rb
Expand Up @@ -2,6 +2,146 @@
describe Configuration::Field do

context "unit specs" do
describe "virtual?" do
context "with virtual true" do
before(:each) do
@field = Configuration::Field.new :some_name, :virtual => true
end
it "returns the right value" do
@field.virtual?.should == true
end
end
context "with virtual object" do
before(:each) do
@field = Configuration::Field.new :some_name, :virtual => 123.6
end
it "returns the right value" do
@field.virtual?.should == true
end
end
context "with virtual nil" do
before(:each) do
@field = Configuration::Field.new :some_name, :virtual => nil
end
it "returns the right value" do
@field.virtual?.should == false
end
end
context "with virtual false" do
before(:each) do
@field = Configuration::Field.new :some_name, :virtual => false
end
it "returns the right value" do
@field.virtual?.should == false
end
end
end
describe "tokenizer" do
context "with default tokenizer" do
before(:each) do
@field = Configuration::Field.new :some_name
end
it "caches" do
@field.tokenizer.should == @field.tokenizer
end
end
context "with specific tokenizer" do
before(:each) do
@field = Configuration::Field.new :some_name, :tokenizer => Tokenizers::Default

@field.type = :some_type
end
it "caches" do
@field.tokenizer.should == @field.tokenizer
end
it "returns an instance" do
@field.tokenizer.should be_kind_of(Tokenizers::Default)
end
it "creates a new instance of the right class" do
Tokenizers::Default.should_receive(:new).once.with

@field.tokenizer
end
end
end
describe "indexer" do
context "with default indexer" do
before(:each) do
@field = Configuration::Field.new :some_name
end
it "caches" do
@field.indexer.should == @field.indexer
end
end
context "with specific indexer" do
before(:each) do
@field = Configuration::Field.new :some_name, :indexer => Indexers::Default

@field.type = :some_type
end
it "caches" do
@field.indexer.should == @field.indexer
end
it "returns an instance" do
@field.indexer.should be_kind_of(Indexers::Default)
end
it "creates a new instance of the right class" do
Indexers::Default.should_receive(:new).once.with :some_type, @field

@field.indexer
end
end
end
describe "cache" do
before(:each) do
@field = Configuration::Field.new :some_name
@field.stub! :prepare_cache_directory

@generated = stub :generated, :generate_caches => nil
@field.stub! :generate => @generated
end
it "prepares the cache directory" do
@field.should_receive(:prepare_cache_directory).once.with

@field.cache
end
it "tells the indexer to index" do
@generated.should_receive(:generate_caches).once.with

@field.cache
end
end
describe "prepare_cache_directory" do
before(:each) do
@field = Configuration::Field.new :some_name

@field.stub! :cache_directory => :some_cache_directory
end
it "tells the FileUtils to mkdir_p" do
FileUtils.should_receive(:mkdir_p).once.with :some_cache_directory

@field.prepare_cache_directory
end
end
describe "index" do
before(:each) do
@field = Configuration::Field.new :some_name
@field.stub! :prepare_cache_directory

@indexer = stub :indexer, :index => nil
@field.stub! :indexer => @indexer
end
it "prepares the cache directory" do
@field.should_receive(:prepare_cache_directory).once.with

@field.index
end
it "tells the indexer to index" do
@indexer.should_receive(:index).once.with

@field.index
end
end
describe "source" do
context "with source" do
before(:each) do
Expand Down
37 changes: 37 additions & 0 deletions server/spec/lib/query/base_spec.rb
Expand Up @@ -3,6 +3,43 @@

describe 'Query::Base' do

describe "empty_results" do
before(:each) do
@query = Query::Full.new

@result_type = stub :result_type
@query.stub! :result_type => @result_type
end
it "returns a new result type" do
@result_type.should_receive(:new).once.with :some_offset

@query.empty_results :some_offset
end
it "returns a new result type with default offset" do
@result_type.should_receive(:new).once.with 0

@query.empty_results
end
end

describe "search_with_text" do
before(:each) do
@query = Query::Full.new
end
it "delegates to search" do
@query.stub! :tokenized => :tokens

@query.should_receive(:search).once.with :tokens, :offset

@query.search_with_text :text, :offset
end
it "uses the tokenizer" do
@query.should_receive(:tokenized).once.with :text

@query.search_with_text :text, :anything
end
end

describe 'reduce' do
context 'real' do
before(:each) do
Expand Down

0 comments on commit a5da40f

Please sign in to comment.