spec/lib/application_spec.rb in picky-3.0.0.pre1 vs spec/lib/application_spec.rb in picky-3.0.0.pre2
- old
+ new
@@ -6,15 +6,16 @@
describe "integration" do
it "should run ok" do
lambda {
class MinimalTestApplication < described_class
- books = Picky::Indexes::Memory.new :books,
- source: Picky::Sources::DB.new(
- 'SELECT id, title FROM books',
- :file => 'app/db.yml'
- )
+ books = Picky::Indexes::Memory.new :books do
+ source Picky::Sources::DB.new(
+ 'SELECT id, title FROM books',
+ :file => 'app/db.yml'
+ )
+ end
books.define_category :title
rack_adapter.stub! :exclaim # Stopping it from exclaiming.
route %r{^/books} => Picky::Search.new(books)
@@ -41,15 +42,17 @@
normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']],
substitutes_characters_with: Picky::CharacterSubstituters::WestEuropean.new,
maximum_tokens: 5
- books_index = Picky::Indexes::Memory.new :books,
- source: Picky::Sources::DB.new(
- 'SELECT id, title, author, isbn13 as isbn FROM books',
- :file => 'app/db.yml'
- )
+ books_index = Picky::Indexes::Memory.new :books do
+ source Picky::Sources::DB.new(
+ 'SELECT id, title, author, isbn13 as isbn FROM books',
+ :file => 'app/db.yml'
+ )
+ end
+
books_index.define_category :title,
similarity: Picky::Similarity::DoubleMetaphone.new(3) # Up to three similar title word indexed.
books_index.define_category :author,
similarity: Picky::Similarity::Soundex.new(2)
books_index.define_category :isbn,
@@ -65,13 +68,15 @@
end
rack_adapter.stub! :exclaim # Stopping it from exclaiming.
route %r{^/books} => Picky::Search.new(books_index)
- route %r{^/buks} => Picky::Search.new(books_index) do
+
+ buks_search = Picky::Search.new(books_index) do
searching removes_characters: /[buks]/
end
+ route %r{^/buks} => buks_search
end
}.should_not raise_error
end
end
@@ -114,9 +119,24 @@
it "should return a new FrontendAdapters::Rack instance" do
described_class.rack_adapter.should be_kind_of(Picky::FrontendAdapters::Rack)
end
it "should cache the instance" do
described_class.rack_adapter.should == described_class.rack_adapter
+ end
+ end
+
+ describe 'route' do
+ it 'is delegated' do
+ described_class.rack_adapter.should_receive(:route).once.with :some_options
+
+ described_class.route(:some_options)
+ end
+ it 'raises on block' do
+ expect {
+ described_class.route :quack => Hash.new do # Anything with a block.
+ # do something
+ end
+ }.to raise_error("Warning: block passed into #route method, not into Search.new!")
end
end
describe 'call' do
before(:each) do
\ No newline at end of file