Skip to content

Commit

Permalink
+ default qualifier spec
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Nov 24, 2010
1 parent 9225ee3 commit ef16d5b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 2 additions & 3 deletions server/lib/picky/indexed/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ def initialize name, index, options = {}
@exact = exact_lambda.call(@exact, @partial) if exact_lambda = options[:exact_lambda]
@partial = partial_lambda.call(@exact, @partial) if partial_lambda = options[:partial_lambda]

# Extract?
# TODO Extract?
#
qualifiers = generate_qualifiers_from options || [name]
Query::Qualifiers.add(configuration.category_name, qualifiers) if qualifiers
Query::Qualifiers.add(configuration.category_name, generate_qualifiers_from(options) || [name])
end

# TODO Move to Index.
Expand Down
18 changes: 18 additions & 0 deletions server/spec/lib/indexed/category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@
@category.stub! :exclaim
end

describe 'generate_qualifiers_from' do
context 'with qualifiers' do
it 'returns that' do
@category.generate_qualifiers_from(:qualifiers => [:a, :b]).should == [:a, :b]
end
end
context 'without anything' do
it 'returns that' do
@category.generate_qualifiers_from({}).should == nil
end
end
context 'with qualifier' do
it 'returns that' do
@category.generate_qualifiers_from(:qualifier => :a).should == [:a]
end
end
end

describe 'weight' do
before(:each) do
@token = stub :token, :text => :some_text
Expand Down
1 change: 0 additions & 1 deletion server/test_project/app/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class BookSearch < Application
partial: Partial::Substring.new(:from => 1),
similarity: Similarity::Phonetic.new(2)
main_index.define_category :author,
qualifiers: [:a, :author, :auteur],
partial: Partial::Substring.new(:from => -2)
main_index.define_category :year,
qualifiers: [:y, :year, :annee]
Expand Down
1 change: 1 addition & 0 deletions server/test_project/spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def ids_of results
it_should_find_ids_in_main_full 'Hystori~ author:ferg', []
it_should_find_ids_in_main_full 'Hystori~ author:fergu', [4, 4]
it_should_find_ids_in_main_full 'Hystori~ author:fergus', [4, 4]
it_should_find_ids_in_main_full 'author:fergus', [4]

# Partial
#
Expand Down

0 comments on commit ef16d5b

Please sign in to comment.