picky 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. data/bin/picky +14 -0
  2. data/lib/bundling.rb +10 -0
  3. data/lib/constants.rb +9 -0
  4. data/lib/deployment.rb +212 -0
  5. data/lib/picky/application.rb +40 -0
  6. data/lib/picky/cacher/convenience.rb +3 -0
  7. data/lib/picky/cacher/generator.rb +17 -0
  8. data/lib/picky/cacher/partial/default.rb +7 -0
  9. data/lib/picky/cacher/partial/none.rb +19 -0
  10. data/lib/picky/cacher/partial/strategy.rb +7 -0
  11. data/lib/picky/cacher/partial/subtoken.rb +91 -0
  12. data/lib/picky/cacher/partial_generator.rb +15 -0
  13. data/lib/picky/cacher/similarity/default.rb +7 -0
  14. data/lib/picky/cacher/similarity/double_levenshtone.rb +73 -0
  15. data/lib/picky/cacher/similarity/none.rb +25 -0
  16. data/lib/picky/cacher/similarity/strategy.rb +7 -0
  17. data/lib/picky/cacher/similarity_generator.rb +15 -0
  18. data/lib/picky/cacher/weights/default.rb +7 -0
  19. data/lib/picky/cacher/weights/logarithmic.rb +39 -0
  20. data/lib/picky/cacher/weights/strategy.rb +7 -0
  21. data/lib/picky/cacher/weights_generator.rb +15 -0
  22. data/lib/picky/configuration/configuration.rb +13 -0
  23. data/lib/picky/configuration/field.rb +68 -0
  24. data/lib/picky/configuration/indexes.rb +60 -0
  25. data/lib/picky/configuration/queries.rb +32 -0
  26. data/lib/picky/configuration/type.rb +52 -0
  27. data/lib/picky/cores.rb +101 -0
  28. data/lib/picky/db/configuration.rb +23 -0
  29. data/lib/picky/ext/ruby19/extconf.rb +7 -0
  30. data/lib/picky/ext/ruby19/performant.c +339 -0
  31. data/lib/picky/extensions/array.rb +45 -0
  32. data/lib/picky/extensions/hash.rb +11 -0
  33. data/lib/picky/extensions/module.rb +15 -0
  34. data/lib/picky/extensions/symbol.rb +18 -0
  35. data/lib/picky/generator.rb +156 -0
  36. data/lib/picky/helpers/cache.rb +23 -0
  37. data/lib/picky/helpers/gc.rb +11 -0
  38. data/lib/picky/helpers/measuring.rb +45 -0
  39. data/lib/picky/helpers/search.rb +27 -0
  40. data/lib/picky/index/bundle.rb +328 -0
  41. data/lib/picky/index/category.rb +109 -0
  42. data/lib/picky/index/combined.rb +38 -0
  43. data/lib/picky/index/type.rb +30 -0
  44. data/lib/picky/indexers/base.rb +77 -0
  45. data/lib/picky/indexers/default.rb +3 -0
  46. data/lib/picky/indexers/field.rb +13 -0
  47. data/lib/picky/indexers/no_source_specified_error.rb +5 -0
  48. data/lib/picky/indexers/solr.rb +60 -0
  49. data/lib/picky/indexes.rb +180 -0
  50. data/lib/picky/initializers/ext.rb +6 -0
  51. data/lib/picky/initializers/mysql.rb +22 -0
  52. data/lib/picky/loader.rb +287 -0
  53. data/lib/picky/loggers/search.rb +19 -0
  54. data/lib/picky/performant/array.rb +23 -0
  55. data/lib/picky/query/allocation.rb +82 -0
  56. data/lib/picky/query/allocations.rb +131 -0
  57. data/lib/picky/query/base.rb +124 -0
  58. data/lib/picky/query/combination.rb +69 -0
  59. data/lib/picky/query/combinations.rb +106 -0
  60. data/lib/picky/query/combinator.rb +92 -0
  61. data/lib/picky/query/full.rb +15 -0
  62. data/lib/picky/query/live.rb +22 -0
  63. data/lib/picky/query/qualifiers.rb +73 -0
  64. data/lib/picky/query/solr.rb +77 -0
  65. data/lib/picky/query/token.rb +215 -0
  66. data/lib/picky/query/tokens.rb +102 -0
  67. data/lib/picky/query/weigher.rb +159 -0
  68. data/lib/picky/query/weights.rb +55 -0
  69. data/lib/picky/rack/harakiri.rb +37 -0
  70. data/lib/picky/results/base.rb +103 -0
  71. data/lib/picky/results/full.rb +19 -0
  72. data/lib/picky/results/live.rb +19 -0
  73. data/lib/picky/routing.rb +165 -0
  74. data/lib/picky/signals.rb +11 -0
  75. data/lib/picky/solr/schema_generator.rb +73 -0
  76. data/lib/picky/sources/base.rb +19 -0
  77. data/lib/picky/sources/csv.rb +30 -0
  78. data/lib/picky/sources/db.rb +77 -0
  79. data/lib/picky/tokenizers/base.rb +130 -0
  80. data/lib/picky/tokenizers/default.rb +3 -0
  81. data/lib/picky/tokenizers/index.rb +73 -0
  82. data/lib/picky/tokenizers/query.rb +70 -0
  83. data/lib/picky/umlaut_substituter.rb +21 -0
  84. data/lib/picky-tasks.rb +6 -0
  85. data/lib/picky.rb +18 -0
  86. data/lib/tasks/application.rake +5 -0
  87. data/lib/tasks/cache.rake +53 -0
  88. data/lib/tasks/framework.rake +4 -0
  89. data/lib/tasks/index.rake +29 -0
  90. data/lib/tasks/server.rake +48 -0
  91. data/lib/tasks/shortcuts.rake +13 -0
  92. data/lib/tasks/solr.rake +36 -0
  93. data/lib/tasks/spec.rake +11 -0
  94. data/lib/tasks/statistics.rake +13 -0
  95. data/lib/tasks/try.rake +29 -0
  96. data/prototype_project/Gemfile +23 -0
  97. data/prototype_project/Rakefile +1 -0
  98. data/prototype_project/app/README +6 -0
  99. data/prototype_project/app/application.rb +50 -0
  100. data/prototype_project/app/application.ru +29 -0
  101. data/prototype_project/app/db.yml +10 -0
  102. data/prototype_project/app/logging.rb +20 -0
  103. data/prototype_project/app/unicorn.ru +10 -0
  104. data/prototype_project/log/README +1 -0
  105. data/prototype_project/script/console +34 -0
  106. data/prototype_project/tmp/README +0 -0
  107. data/prototype_project/tmp/pids/README +0 -0
  108. data/spec/ext/performant_spec.rb +64 -0
  109. data/spec/lib/application_spec.rb +61 -0
  110. data/spec/lib/cacher/partial/subtoken_spec.rb +89 -0
  111. data/spec/lib/cacher/partial_generator_spec.rb +35 -0
  112. data/spec/lib/cacher/similarity/double_levenshtone_spec.rb +60 -0
  113. data/spec/lib/cacher/similarity/none_spec.rb +23 -0
  114. data/spec/lib/cacher/similarity_generator_spec.rb +22 -0
  115. data/spec/lib/cacher/weights/logarithmic_spec.rb +30 -0
  116. data/spec/lib/cacher/weights_generator_spec.rb +21 -0
  117. data/spec/lib/configuration/configuration_spec.rb +38 -0
  118. data/spec/lib/configuration/type_spec.rb +49 -0
  119. data/spec/lib/configuration_spec.rb +8 -0
  120. data/spec/lib/cores_spec.rb +65 -0
  121. data/spec/lib/extensions/array_spec.rb +37 -0
  122. data/spec/lib/extensions/hash_spec.rb +11 -0
  123. data/spec/lib/extensions/module_spec.rb +27 -0
  124. data/spec/lib/extensions/symbol_spec.rb +85 -0
  125. data/spec/lib/generator_spec.rb +135 -0
  126. data/spec/lib/helpers/cache_spec.rb +35 -0
  127. data/spec/lib/helpers/gc_spec.rb +71 -0
  128. data/spec/lib/helpers/measuring_spec.rb +18 -0
  129. data/spec/lib/helpers/search_spec.rb +50 -0
  130. data/spec/lib/index/bundle_partial_generation_speed_spec.rb +47 -0
  131. data/spec/lib/index/bundle_spec.rb +260 -0
  132. data/spec/lib/index/category_spec.rb +203 -0
  133. data/spec/lib/indexers/base_spec.rb +73 -0
  134. data/spec/lib/indexers/field_spec.rb +20 -0
  135. data/spec/lib/loader_spec.rb +48 -0
  136. data/spec/lib/loggers/search_spec.rb +19 -0
  137. data/spec/lib/performant/array_spec.rb +13 -0
  138. data/spec/lib/query/allocation_spec.rb +194 -0
  139. data/spec/lib/query/allocations_spec.rb +336 -0
  140. data/spec/lib/query/base_spec.rb +104 -0
  141. data/spec/lib/query/combination_spec.rb +90 -0
  142. data/spec/lib/query/combinations_spec.rb +83 -0
  143. data/spec/lib/query/combinator_spec.rb +112 -0
  144. data/spec/lib/query/full_spec.rb +22 -0
  145. data/spec/lib/query/live_spec.rb +61 -0
  146. data/spec/lib/query/qualifiers_spec.rb +31 -0
  147. data/spec/lib/query/solr_spec.rb +51 -0
  148. data/spec/lib/query/token_spec.rb +297 -0
  149. data/spec/lib/query/tokens_spec.rb +189 -0
  150. data/spec/lib/query/weights_spec.rb +47 -0
  151. data/spec/lib/results/base_spec.rb +233 -0
  152. data/spec/lib/routing_spec.rb +318 -0
  153. data/spec/lib/solr/schema_generator_spec.rb +42 -0
  154. data/spec/lib/sources/db_spec.rb +91 -0
  155. data/spec/lib/tokenizers/base_spec.rb +61 -0
  156. data/spec/lib/tokenizers/index_spec.rb +51 -0
  157. data/spec/lib/tokenizers/query_spec.rb +105 -0
  158. data/spec/lib/umlaut_substituter_spec.rb +84 -0
  159. data/spec/specific/speed_spec.rb +55 -0
  160. metadata +371 -15
  161. data/README.textile +0 -9
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe 'Query::Combination' do
6
+
7
+ before(:each) do
8
+ @bundle = stub :bundle
9
+ @token = stub :token, :text => :some_text, :partial => false, :similar? => true
10
+ @category = stub :category, :bundle_for => @bundle, :name => :some_category_name
11
+
12
+ @combination = Query::Combination.new @token, @category
13
+ end
14
+
15
+ describe 'hash' do
16
+ it 'should hash the token and the bundle' do
17
+ @combination.hash.should == [@token.to_s, @bundle].hash
18
+ end
19
+ end
20
+
21
+ describe 'in?' do
22
+ before(:each) do
23
+ @combination.stub! :identifier => :some_identifier
24
+ end
25
+ it 'should check if the given identifiers include the identifier' do
26
+ @combination.in?([:some_other_identifier, :some_identifier, :some_other_identifier]).should == true
27
+ end
28
+ it 'should check if the given identifiers include the identifier' do
29
+ @combination.in?([:some_other_identifier, :some_other_identifier]).should == false
30
+ end
31
+ end
32
+
33
+ describe 'to_result' do
34
+ context 'functional with qualifier' do
35
+ before(:each) do
36
+ token = Tokenizers::Query.new.tokenize('name:Blä~').first
37
+
38
+ @combination = Query::Combination.new token, @category
39
+ end
40
+ it 'should return a correct result' do
41
+ @combination.to_result.should == [:some_category_name, 'Blä~', :blae]
42
+ end
43
+ end
44
+ it 'should return a correct result' do
45
+ @token.stub! :to_result => [:some_original_text, :some_text]
46
+ @combination.stub! :identifier => :some_identifier
47
+
48
+ @combination.to_result.should == [:some_identifier, :some_original_text, :some_text]
49
+ end
50
+ end
51
+
52
+ describe 'identifier' do
53
+ it 'should get the category name from the bundle' do
54
+ @combination.identifier.should == :some_category_name
55
+ end
56
+ end
57
+
58
+ describe 'ids' do
59
+ it 'should call ids with the text on bundle' do
60
+ @bundle.should_receive(:ids).once.with :some_text
61
+
62
+ @combination.ids
63
+ end
64
+ it 'should not call it twice, but cache' do
65
+ @bundle.stub! :ids => :some_ids
66
+ @combination.ids
67
+
68
+ @bundle.should_receive(:ids).never
69
+
70
+ @combination.ids.should == :some_ids
71
+ end
72
+ end
73
+
74
+ describe 'weight' do
75
+ it 'should call weight with the text on bundle' do
76
+ @bundle.should_receive(:weight).once.with :some_text
77
+
78
+ @combination.weight
79
+ end
80
+ it 'should not call it twice, but cache' do
81
+ @bundle.stub! :weight => :some_weight
82
+ @combination.weight
83
+
84
+ @bundle.should_receive(:weight).never
85
+
86
+ @combination.weight.should == :some_weight
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,83 @@
1
+ # coding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe 'Query::Combinations' do
6
+
7
+ before(:each) do
8
+ @combinations_ary = stub :combinations_ary
9
+
10
+ @combinations = Query::Combinations.new :some_type, @combinations_ary
11
+ end
12
+
13
+ describe 'remove' do
14
+ before(:each) do
15
+ @combination1 = stub :combination1, :in? => false
16
+ @combination2 = stub :combination2, :in? => true
17
+ @combination3 = stub :combination3, :in? => true
18
+
19
+ @combinations = Query::Combinations.new :some_type, [@combination1, @combination2, @combination3]
20
+ end
21
+ it 'should remove the combinations' do
22
+ @combinations.remove([:any]).should == [@combination1]
23
+ end
24
+ end
25
+
26
+ describe 'keep' do
27
+ before(:each) do
28
+ @combination1 = stub :combination1, :in? => false
29
+ @combination2 = stub :combination2, :in? => true
30
+ @combination3 = stub :combination3, :in? => true
31
+
32
+ @combinations = Query::Combinations.new :some_type, [@combination1, @combination2, @combination3]
33
+ end
34
+ it 'should filter the combinations' do
35
+ @combinations.keep([:any]).should == [@combination2, @combination3]
36
+ end
37
+ end
38
+
39
+ describe "ids" do
40
+ before(:each) do
41
+ @combination1 = stub :combination1
42
+ @combination2 = stub :combination2
43
+ @combination3 = stub :combination3
44
+ @combinations = Query::Combinations.new :some_type, [@combination1, @combination2, @combination3]
45
+ end
46
+ it "should intersect correctly" do
47
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
48
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
49
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
50
+
51
+ @combinations.ids.should == (1..10).to_a
52
+ end
53
+ it "should intersect correctly when intermediate intersect result is empty" do
54
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
55
+ @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
56
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
57
+
58
+ @combinations.ids.should == []
59
+ end
60
+ it "should be fast" do
61
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
62
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
63
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
64
+
65
+ Benchmark.realtime { @combinations.ids }.should <= 0.004
66
+ end
67
+ it "should be fast" do
68
+ @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
69
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
70
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
71
+
72
+ Benchmark.realtime { @combinations.ids }.should <= 0.00015
73
+ end
74
+ it "should be fast" do
75
+ @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
76
+ @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
77
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
78
+
79
+ Benchmark.realtime { @combinations.ids }.should <= 0.0001
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe Query::Combinator do
4
+
5
+ context 'with option ignore_unassigned_tokens' do
6
+ before(:each) do
7
+ @category1 = stub :category1, :name => :category1
8
+ @category2 = stub :category2, :name => :category2
9
+ @category3 = stub :category3, :name => :category3
10
+ @categories = [@category1, @category2, @category3]
11
+ end
12
+ context 'ignore_unassigned_tokens true' do
13
+ before(:each) do
14
+ @combinator = Query::Combinator.new @categories, :ignore_unassigned_tokens => true
15
+ end
16
+ it 'should return the right value' do
17
+ @combinator.ignore_unassigned_tokens.should == true
18
+ end
19
+ end
20
+ context 'ignore_unassigned_tokens false' do
21
+ before(:each) do
22
+ @combinator = Query::Combinator.new @categories, :ignore_unassigned_tokens => false
23
+ end
24
+ it 'should return the right value' do
25
+ @combinator.ignore_unassigned_tokens.should == false
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'without options' do
31
+ before(:each) do
32
+ @category1 = stub :category1, :name => :category1
33
+ @category2 = stub :category2, :name => :category2
34
+ @category3 = stub :category3, :name => :category3
35
+ @categories = [@category1, @category2, @category3]
36
+
37
+ @combinator = Query::Combinator.new @categories
38
+ end
39
+
40
+ describe 'possible_for' do
41
+ context 'without preselected categories' do
42
+ context 'user defined exists' do
43
+ before(:each) do
44
+ @token = stub :token, :user_defined_category_name => :category2
45
+ end
46
+ context 'combination exists' do
47
+ before(:each) do
48
+ @combination = stub :combination
49
+ @category2.stub! :combination_for => @combination
50
+ end
51
+ it 'should return the right combinations' do
52
+ @combinator.possible_for(@token).should == [@combination]
53
+ end
54
+ end
55
+ context 'combination does not exist' do
56
+ before(:each) do
57
+ @category2.stub! :combination_for => nil
58
+ end
59
+ it 'should return the right combinations' do
60
+ @combinator.possible_for(@token).should == []
61
+ end
62
+ end
63
+ end
64
+ context 'user defined does not exist' do
65
+
66
+ end
67
+ end
68
+ context 'with preselected categories' do
69
+
70
+ end
71
+ end
72
+
73
+ describe 'possible_categories' do
74
+ context 'user defined exists' do
75
+ before(:each) do
76
+ @token = stub :token, :user_defined_category_name => :category2
77
+ end
78
+ it 'should return the right categories' do
79
+ @combinator.possible_categories(@token).should == [@category2]
80
+ end
81
+ end
82
+ context 'user defined does not exist' do
83
+ before(:each) do
84
+ @token = stub :token, :user_defined_category_name => nil
85
+ end
86
+ it 'should return all categories' do
87
+ @combinator.possible_categories(@token).should == @categories
88
+ end
89
+ end
90
+ end
91
+
92
+ describe 'user_defined_categories' do
93
+ context 'category exists' do
94
+ before(:each) do
95
+ @token = stub :token, :user_defined_category_name => :category2
96
+ end
97
+ it 'should return the right categories' do
98
+ @combinator.user_defined_categories(@token).should == [@category2]
99
+ end
100
+ end
101
+ context 'category does not exist' do
102
+ before(:each) do
103
+ @token = stub :token, :user_defined_category_name => :gnoergel
104
+ end
105
+ it 'should return nil' do
106
+ @combinator.user_defined_categories(@token).should == nil
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Query::Full do
4
+
5
+ before(:each) do
6
+ @index = stub :index
7
+ end
8
+
9
+ describe 'result_type' do
10
+ before(:each) do
11
+ @tokens = [
12
+ Query::Token.processed('some'),
13
+ Query::Token.processed('query')
14
+ ]
15
+ @query = Query::Full.new @tokens, @index
16
+ end
17
+ it "should return a specific type" do
18
+ @query.result_type.should == Results::Full
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Query::Live do
4
+
5
+ before(:each) do
6
+ # @category1 = Index::Category.new
7
+ # @type_index = Index::Type.new :some_name, :some_result_type, @category1
8
+ @index = stub :index
9
+ end
10
+
11
+ describe 'result_type' do
12
+ before(:each) do
13
+ @query = Query::Live.new 'some query', 0, @index
14
+ end
15
+ it "should return a specific type" do
16
+ @query.result_type.should == Results::Live
17
+ end
18
+ end
19
+
20
+ describe "execute" do
21
+ before(:each) do
22
+ @query = Query::Live.new @index
23
+ end
24
+ it "should get allocations" do
25
+ @query.should_receive(:results_from).and_return stub(:results, :prepare! => true)
26
+ @query.should_receive(:sorted_allocations).once
27
+
28
+ @query.execute 'some_query', 0
29
+ end
30
+ it "should generate a max amount of results from allocations" do
31
+ allocations = stub :allocations
32
+ @query.should_receive(:sorted_allocations).and_return allocations
33
+
34
+ @query.should_receive(:results_from).once.with(allocations, 0).and_return stub(:results, :prepare! => true)
35
+
36
+ @query.execute 'some query', 0
37
+ end
38
+ end
39
+
40
+ describe "results_from" do
41
+ describe "with empty ids" do
42
+ before(:each) do
43
+ @query = Query::Live.new 'some query', @index
44
+ @allocations = stub :allocations, :total => 0, :ids => [], :to_result => :some_results, :process! => nil
45
+ end
46
+ it "should generate a result" do
47
+ @query.results_from(@allocations).should be_kind_of Results::Live
48
+ end
49
+ it "should generate a result with 0 result count" do
50
+ @query.results_from(@allocations).total.should == 0
51
+ end
52
+ it "should generate a result with 0 duration" do
53
+ @query.results_from(@allocations).duration.should == 0
54
+ end
55
+ it "should generate a result with the allocations" do
56
+ @query.results_from(@allocations).allocations.should == @allocations
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Query::Qualifiers do
4
+
5
+ before(:each) do
6
+ Query::Qualifiers.instance << Query::Qualifier.new(:test1, [:t1, :tt1, :ttt1])
7
+ Query::Qualifiers.instance << Query::Qualifier.new(:test2, [:t2, :tt2, :ttt2])
8
+ Query::Qualifiers.instance << Query::Qualifier.new(:test3, [:t3, :tt3, :ttt3])
9
+ Query::Qualifiers.instance.prepare
10
+ end
11
+
12
+ def self.it_should_normalize(qualifier, expected)
13
+ it "should map #{qualifier} to #{expected}" do
14
+ Query::Qualifiers.instance.normalize(qualifier).should == expected
15
+ end
16
+ end
17
+
18
+ describe "mapping" do
19
+ it_should_normalize :t1, :test1
20
+ it_should_normalize :tt1, :test1
21
+ it_should_normalize :ttt1, :test1
22
+
23
+ it_should_normalize :t2, :test2
24
+ it_should_normalize :tt2, :test2
25
+ it_should_normalize :ttt2, :test2
26
+
27
+ it_should_normalize :t3, :test3
28
+ it_should_normalize :tt3, :test3
29
+ it_should_normalize :ttt3, :test3
30
+ end
31
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Query::Solr do
4
+
5
+ describe 'real server' do
6
+ before(:each) do
7
+ @server = Query::Solr.new
8
+ end
9
+
10
+ describe 'execute' do
11
+ context 'error cases' do
12
+ before(:each) do
13
+ @tokens = stub :tokens
14
+ end
15
+ context 'tokens are malformed' do
16
+
17
+ end
18
+ context 'server returns strange values' do
19
+
20
+ end
21
+ context 'server raises' do
22
+ before(:each) do
23
+ @server.stub! :select => lambda { raise Solr::RequestError }
24
+ end
25
+ it 'should not fail' do
26
+ @tokens.stub! :to_solr_query => ''
27
+
28
+ lambda { @server.execute(@tokens) }.should_not raise_error
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ context 'with connected Server' do
36
+ before(:each) do
37
+ @server = stub :server
38
+ RSolr.stub! :connect => @server
39
+ end
40
+ end
41
+
42
+ context 'without connected server' do
43
+ before(:each) do
44
+ RSolr.should_receive(:connect).and_raise RuntimeError
45
+ end
46
+ it 'should have a nil server' do
47
+ Query::Solr.new(:some_index_type).server.should == nil
48
+ end
49
+ end
50
+
51
+ end