riddle 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -5
  3. data/Gemfile +10 -0
  4. data/HISTORY +4 -0
  5. data/README.markdown +1 -1
  6. data/lib/riddle.rb +1 -0
  7. data/lib/riddle/0.9.9/configuration/searchd.rb +1 -1
  8. data/lib/riddle/client.rb +4 -1
  9. data/lib/riddle/client/message.rb +15 -14
  10. data/lib/riddle/configuration/parser.rb +1 -0
  11. data/lib/riddle/configuration/section.rb +9 -9
  12. data/lib/riddle/configuration/source.rb +5 -5
  13. data/lib/riddle/query/select.rb +3 -2
  14. data/riddle.gemspec +2 -4
  15. metadata +4 -329
  16. data/spec/fixtures/.gitignore +0 -2
  17. data/spec/fixtures/data/0.9.9/anchor.bin +0 -0
  18. data/spec/fixtures/data/0.9.9/any.bin +0 -0
  19. data/spec/fixtures/data/0.9.9/boolean.bin +0 -0
  20. data/spec/fixtures/data/0.9.9/comment.bin +0 -0
  21. data/spec/fixtures/data/0.9.9/distinct.bin +0 -0
  22. data/spec/fixtures/data/0.9.9/field_weights.bin +0 -0
  23. data/spec/fixtures/data/0.9.9/filter.bin +0 -0
  24. data/spec/fixtures/data/0.9.9/filter_array.bin +0 -0
  25. data/spec/fixtures/data/0.9.9/filter_array_exclude.bin +0 -0
  26. data/spec/fixtures/data/0.9.9/filter_boolean.bin +0 -0
  27. data/spec/fixtures/data/0.9.9/filter_floats.bin +0 -0
  28. data/spec/fixtures/data/0.9.9/filter_floats_exclude.bin +0 -0
  29. data/spec/fixtures/data/0.9.9/filter_range.bin +0 -0
  30. data/spec/fixtures/data/0.9.9/filter_range_exclude.bin +0 -0
  31. data/spec/fixtures/data/0.9.9/group.bin +0 -0
  32. data/spec/fixtures/data/0.9.9/index.bin +0 -0
  33. data/spec/fixtures/data/0.9.9/index_weights.bin +0 -0
  34. data/spec/fixtures/data/0.9.9/keywords_with_hits.bin +0 -0
  35. data/spec/fixtures/data/0.9.9/keywords_without_hits.bin +0 -0
  36. data/spec/fixtures/data/0.9.9/overrides.bin +0 -0
  37. data/spec/fixtures/data/0.9.9/phrase.bin +0 -0
  38. data/spec/fixtures/data/0.9.9/rank_mode.bin +0 -0
  39. data/spec/fixtures/data/0.9.9/select.bin +0 -0
  40. data/spec/fixtures/data/0.9.9/simple.bin +0 -0
  41. data/spec/fixtures/data/0.9.9/sort.bin +0 -0
  42. data/spec/fixtures/data/0.9.9/update_simple.bin +0 -0
  43. data/spec/fixtures/data/0.9.9/weights.bin +0 -0
  44. data/spec/fixtures/data/1.10/anchor.bin +0 -0
  45. data/spec/fixtures/data/1.10/any.bin +0 -0
  46. data/spec/fixtures/data/1.10/boolean.bin +0 -0
  47. data/spec/fixtures/data/1.10/comment.bin +0 -0
  48. data/spec/fixtures/data/1.10/distinct.bin +0 -0
  49. data/spec/fixtures/data/1.10/field_weights.bin +0 -0
  50. data/spec/fixtures/data/1.10/filter.bin +0 -0
  51. data/spec/fixtures/data/1.10/filter_array.bin +0 -0
  52. data/spec/fixtures/data/1.10/filter_array_exclude.bin +0 -0
  53. data/spec/fixtures/data/1.10/filter_boolean.bin +0 -0
  54. data/spec/fixtures/data/1.10/filter_floats.bin +0 -0
  55. data/spec/fixtures/data/1.10/filter_floats_exclude.bin +0 -0
  56. data/spec/fixtures/data/1.10/filter_range.bin +0 -0
  57. data/spec/fixtures/data/1.10/filter_range_exclude.bin +0 -0
  58. data/spec/fixtures/data/1.10/group.bin +0 -0
  59. data/spec/fixtures/data/1.10/index.bin +0 -0
  60. data/spec/fixtures/data/1.10/index_weights.bin +0 -0
  61. data/spec/fixtures/data/1.10/keywords_with_hits.bin +0 -0
  62. data/spec/fixtures/data/1.10/keywords_without_hits.bin +0 -0
  63. data/spec/fixtures/data/1.10/overrides.bin +0 -0
  64. data/spec/fixtures/data/1.10/phrase.bin +0 -0
  65. data/spec/fixtures/data/1.10/rank_mode.bin +0 -0
  66. data/spec/fixtures/data/1.10/select.bin +0 -0
  67. data/spec/fixtures/data/1.10/simple.bin +0 -0
  68. data/spec/fixtures/data/1.10/sort.bin +0 -0
  69. data/spec/fixtures/data/1.10/update_simple.bin +0 -0
  70. data/spec/fixtures/data/1.10/weights.bin +0 -0
  71. data/spec/fixtures/data/2.0.1/anchor.bin +0 -0
  72. data/spec/fixtures/data/2.0.1/any.bin +0 -0
  73. data/spec/fixtures/data/2.0.1/boolean.bin +0 -0
  74. data/spec/fixtures/data/2.0.1/comment.bin +0 -0
  75. data/spec/fixtures/data/2.0.1/distinct.bin +0 -0
  76. data/spec/fixtures/data/2.0.1/field_weights.bin +0 -0
  77. data/spec/fixtures/data/2.0.1/filter.bin +0 -0
  78. data/spec/fixtures/data/2.0.1/filter_array.bin +0 -0
  79. data/spec/fixtures/data/2.0.1/filter_array_exclude.bin +0 -0
  80. data/spec/fixtures/data/2.0.1/filter_boolean.bin +0 -0
  81. data/spec/fixtures/data/2.0.1/filter_floats.bin +0 -0
  82. data/spec/fixtures/data/2.0.1/filter_floats_exclude.bin +0 -0
  83. data/spec/fixtures/data/2.0.1/filter_range.bin +0 -0
  84. data/spec/fixtures/data/2.0.1/filter_range_exclude.bin +0 -0
  85. data/spec/fixtures/data/2.0.1/group.bin +0 -0
  86. data/spec/fixtures/data/2.0.1/index.bin +0 -0
  87. data/spec/fixtures/data/2.0.1/index_weights.bin +0 -0
  88. data/spec/fixtures/data/2.0.1/keywords_with_hits.bin +0 -0
  89. data/spec/fixtures/data/2.0.1/keywords_without_hits.bin +0 -0
  90. data/spec/fixtures/data/2.0.1/overrides.bin +0 -0
  91. data/spec/fixtures/data/2.0.1/phrase.bin +0 -0
  92. data/spec/fixtures/data/2.0.1/rank_mode.bin +0 -0
  93. data/spec/fixtures/data/2.0.1/select.bin +0 -0
  94. data/spec/fixtures/data/2.0.1/simple.bin +0 -0
  95. data/spec/fixtures/data/2.0.1/sort.bin +0 -0
  96. data/spec/fixtures/data/2.0.1/update_simple.bin +0 -0
  97. data/spec/fixtures/data/2.0.1/weights.bin +0 -0
  98. data/spec/fixtures/data/2.1.0/anchor.bin +0 -0
  99. data/spec/fixtures/data/2.1.0/any.bin +0 -0
  100. data/spec/fixtures/data/2.1.0/boolean.bin +0 -0
  101. data/spec/fixtures/data/2.1.0/comment.bin +0 -0
  102. data/spec/fixtures/data/2.1.0/distinct.bin +0 -0
  103. data/spec/fixtures/data/2.1.0/field_weights.bin +0 -0
  104. data/spec/fixtures/data/2.1.0/filter.bin +0 -0
  105. data/spec/fixtures/data/2.1.0/filter_array.bin +0 -0
  106. data/spec/fixtures/data/2.1.0/filter_array_exclude.bin +0 -0
  107. data/spec/fixtures/data/2.1.0/filter_boolean.bin +0 -0
  108. data/spec/fixtures/data/2.1.0/filter_floats.bin +0 -0
  109. data/spec/fixtures/data/2.1.0/filter_floats_exclude.bin +0 -0
  110. data/spec/fixtures/data/2.1.0/filter_range.bin +0 -0
  111. data/spec/fixtures/data/2.1.0/filter_range_exclude.bin +0 -0
  112. data/spec/fixtures/data/2.1.0/group.bin +0 -0
  113. data/spec/fixtures/data/2.1.0/index.bin +0 -0
  114. data/spec/fixtures/data/2.1.0/index_weights.bin +0 -0
  115. data/spec/fixtures/data/2.1.0/keywords_with_hits.bin +0 -0
  116. data/spec/fixtures/data/2.1.0/keywords_without_hits.bin +0 -0
  117. data/spec/fixtures/data/2.1.0/overrides.bin +0 -0
  118. data/spec/fixtures/data/2.1.0/phrase.bin +0 -0
  119. data/spec/fixtures/data/2.1.0/rank_mode.bin +0 -0
  120. data/spec/fixtures/data/2.1.0/select.bin +0 -0
  121. data/spec/fixtures/data/2.1.0/simple.bin +0 -0
  122. data/spec/fixtures/data/2.1.0/sort.bin +0 -0
  123. data/spec/fixtures/data/2.1.0/update_simple.bin +0 -0
  124. data/spec/fixtures/data/2.1.0/weights.bin +0 -0
  125. data/spec/fixtures/data_generator.0.9.8.php +0 -208
  126. data/spec/fixtures/data_generator.0.9.9.php +0 -5
  127. data/spec/fixtures/data_generator.1.10.php +0 -5
  128. data/spec/fixtures/data_generator.2.0.1.php +0 -5
  129. data/spec/fixtures/data_generator.2.1.0.php +0 -5
  130. data/spec/fixtures/data_generator.php +0 -223
  131. data/spec/fixtures/sphinxapi.0.9.8.php +0 -1228
  132. data/spec/fixtures/sphinxapi.0.9.9.php +0 -1646
  133. data/spec/fixtures/sphinxapi.1.10.php +0 -1728
  134. data/spec/fixtures/sphinxapi.2.0.1.php +0 -1731
  135. data/spec/fixtures/sphinxapi.2.1.0.php +0 -1752
  136. data/spec/fixtures/sql/conf.example.yml +0 -3
  137. data/spec/fixtures/sql/data.sql +0 -25000
  138. data/spec/fixtures/sql/data.tsv +0 -25000
  139. data/spec/fixtures/sql/structure.sql +0 -16
  140. data/spec/functional/connection_spec.rb +0 -64
  141. data/spec/functional/escaping_spec.rb +0 -49
  142. data/spec/functional/excerpt_spec.rb +0 -139
  143. data/spec/functional/keywords_spec.rb +0 -40
  144. data/spec/functional/persistance_spec.rb +0 -17
  145. data/spec/functional/search_spec.rb +0 -67
  146. data/spec/functional/status_spec.rb +0 -21
  147. data/spec/functional/update_spec.rb +0 -41
  148. data/spec/riddle/auto_version_spec.rb +0 -95
  149. data/spec/riddle/client_spec.rb +0 -11
  150. data/spec/riddle/configuration_spec.rb +0 -28
  151. data/spec/riddle/controller_spec.rb +0 -39
  152. data/spec/riddle/query/delete_spec.rb +0 -18
  153. data/spec/riddle/query/insert_spec.rb +0 -25
  154. data/spec/riddle/query/select_spec.rb +0 -226
  155. data/spec/riddle/query_spec.rb +0 -97
  156. data/spec/riddle_spec.rb +0 -27
  157. data/spec/spec_helper.rb +0 -34
  158. data/spec/support/binary_fixtures.rb +0 -18
  159. data/spec/support/sphinx.rb +0 -137
  160. data/spec/unit/client_spec.rb +0 -290
  161. data/spec/unit/configuration/common_spec.rb +0 -60
  162. data/spec/unit/configuration/distributed_index_spec.rb +0 -58
  163. data/spec/unit/configuration/index_spec.rb +0 -124
  164. data/spec/unit/configuration/indexer_spec.rb +0 -73
  165. data/spec/unit/configuration/realtime_index_spec.rb +0 -65
  166. data/spec/unit/configuration/searchd_spec.rb +0 -228
  167. data/spec/unit/configuration/source_spec.rb +0 -5
  168. data/spec/unit/configuration/sql_source_spec.rb +0 -137
  169. data/spec/unit/configuration/template_index_spec.rb +0 -91
  170. data/spec/unit/configuration/tsv_source_spec.rb +0 -53
  171. data/spec/unit/configuration/xml_source_spec.rb +0 -51
  172. data/spec/unit/configuration_spec.rb +0 -25
  173. data/spec/unit/filter_spec.rb +0 -38
  174. data/spec/unit/message_spec.rb +0 -94
  175. data/spec/unit/response_spec.rb +0 -64
  176. data/spec/unit/riddle_spec.rb +0 -17
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::AutoVersion do
4
- describe '.configure' do
5
- before :each do
6
- @controller = Riddle::Controller.new stub('configuration'), 'sphinx.conf'
7
- Riddle::Controller.stub(:new => @controller)
8
-
9
- unless ENV['SPHINX_VERSION'].nil?
10
- @env_version, ENV['SPHINX_VERSION'] = ENV['SPHINX_VERSION'].dup, nil
11
- end
12
- end
13
-
14
- after :each do
15
- ENV['SPHINX_VERSION'] = @env_version unless @env_version.nil?
16
- end
17
-
18
- it "should require 0.9.8 if that is the known version" do
19
- Riddle::AutoVersion.should_receive(:require).with('riddle/0.9.8')
20
-
21
- @controller.stub(:sphinx_version => '0.9.8')
22
- Riddle::AutoVersion.configure
23
- end
24
-
25
- it "should require 0.9.9 if that is the known version" do
26
- Riddle::AutoVersion.should_receive(:require).with('riddle/0.9.9')
27
-
28
- @controller.stub(:sphinx_version => '0.9.9')
29
- Riddle::AutoVersion.configure
30
- end
31
-
32
- it "should require 1.10 if that is the known version" do
33
- Riddle::AutoVersion.should_receive(:require).with('riddle/1.10')
34
-
35
- @controller.stub(:sphinx_version => '1.10-beta')
36
- Riddle::AutoVersion.configure
37
- end
38
-
39
- it "should require 1.10 if using 1.10 with 64 bit IDs" do
40
- Riddle::AutoVersion.should_receive(:require).with('riddle/1.10')
41
-
42
- @controller.stub(:sphinx_version => '1.10-id64-beta')
43
- Riddle::AutoVersion.configure
44
- end
45
-
46
- it "should require 2.0.1 if that is the known version" do
47
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.0.1')
48
-
49
- @controller.stub(:sphinx_version => '2.0.1-beta')
50
- Riddle::AutoVersion.configure
51
- end
52
-
53
- it "should require 2.0.1 if 2.0.2-dev is being used" do
54
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.0.1')
55
-
56
- @controller.stub(:sphinx_version => '2.0.2-dev')
57
- Riddle::AutoVersion.configure
58
- end
59
-
60
- it "should require 2.1.0 if 2.0.3 is being used" do
61
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
62
-
63
- @controller.stub(:sphinx_version => '2.0.3-release')
64
- Riddle::AutoVersion.configure
65
- end
66
-
67
- it "should require 2.1.0 if 2.0.4 is being used" do
68
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
69
-
70
- @controller.stub(:sphinx_version => '2.0.4-release')
71
- Riddle::AutoVersion.configure
72
- end
73
-
74
- it "should require 2.1.0 if 2.0.5 is being used" do
75
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
76
-
77
- @controller.stub(:sphinx_version => '2.0.5-release')
78
- Riddle::AutoVersion.configure
79
- end
80
-
81
- it "should require 2.1.0 if 2.2.1 is being used" do
82
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
83
-
84
- @controller.stub(:sphinx_version => '2.2.1-beta')
85
- Riddle::AutoVersion.configure
86
- end
87
-
88
- it "should require 2.1.0 if that is the known version" do
89
- Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
90
-
91
- @controller.stub(:sphinx_version => '2.1.0-dev')
92
- Riddle::AutoVersion.configure
93
- end
94
- end
95
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Client do
4
- describe '#initialize' do
5
- it "should check the loaded Sphinx version" do
6
- Riddle.should_receive(:version_warning)
7
-
8
- Riddle::Client.new
9
- end
10
- end
11
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Configuration do
4
- describe Riddle::Configuration::Index do
5
- describe '#settings' do
6
- it 'should return array with all settings of index' do
7
- Riddle::Configuration::Index.settings.should_not be_empty
8
- end
9
-
10
- it 'should return array which contains a docinfo' do
11
- Riddle::Configuration::Index.settings.should be_include :docinfo
12
- end
13
- end
14
- end
15
-
16
- describe 'class inherited from Riddle::Configuration::Index' do
17
- before :all do
18
- class TestIndex < Riddle::Configuration::Index; end
19
- end
20
-
21
- describe '#settings' do
22
- it 'should has same settings as Riddle::Configuration::Index' do
23
- TestIndex.settings.should == Riddle::Configuration::Index.settings
24
- end
25
- end
26
-
27
- end
28
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Controller do
4
- describe '#sphinx_version' do
5
- before :each do
6
- @controller = Riddle::Controller.new stub('controller'), 'sphinx.conf'
7
- end
8
-
9
- it "should return 1.10 if using 1.10-beta" do
10
- @controller.stub(:` => 'Sphinx 1.10-beta (r2420)')
11
- @controller.sphinx_version.should == '1.10-beta'
12
- end
13
-
14
- it "should return 0.9.9 if using 0.9.9" do
15
- @controller.stub(:` => 'Sphinx 0.9.9-release (r2117)')
16
- @controller.sphinx_version.should == '0.9.9'
17
- end
18
-
19
- it "should return 0.9.9 if using 0.9.9 rc2" do
20
- @controller.stub(:` => 'Sphinx 0.9.9-rc2 (r1785)')
21
- @controller.sphinx_version.should == '0.9.9'
22
- end
23
-
24
- it "should return 0.9.9 if using 0.9.9 rc1" do
25
- @controller.stub(:` => 'Sphinx 0.9.9-rc1 (r1566)')
26
- @controller.sphinx_version.should == '0.9.9'
27
- end
28
-
29
- it "should return 0.9.8 if using 0.9.8.1" do
30
- @controller.stub(:` => 'Sphinx 0.9.8.1-release (r1533)')
31
- @controller.sphinx_version.should == '0.9.8'
32
- end
33
-
34
- it "should return 0.9.8 if using 0.9.8" do
35
- @controller.stub(:` => 'Sphinx 0.9.8-release (r1371)')
36
- @controller.sphinx_version.should == '0.9.8'
37
- end
38
- end
39
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Query::Delete do
4
- it 'handles a single id' do
5
- query = Riddle::Query::Delete.new 'foo_core', 5
6
- query.to_sql.should == 'DELETE FROM foo_core WHERE id = 5'
7
- end
8
-
9
- it 'handles multiple ids' do
10
- query = Riddle::Query::Delete.new 'foo_core', 5, 6, 7
11
- query.to_sql.should == 'DELETE FROM foo_core WHERE id IN (5, 6, 7)'
12
- end
13
-
14
- it 'handles multiple ids in an explicit array' do
15
- query = Riddle::Query::Delete.new 'foo_core', [5, 6, 7]
16
- query.to_sql.should == 'DELETE FROM foo_core WHERE id IN (5, 6, 7)'
17
- end
18
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Query::Insert do
4
- it 'handles inserts' do
5
- query = Riddle::Query::Insert.new('foo_core', [:id, :deleted], [4, false])
6
- query.to_sql.should == 'INSERT INTO foo_core (id, `deleted`) VALUES (4, 0)'
7
- end
8
-
9
- it 'handles replaces' do
10
- query = Riddle::Query::Insert.new('foo_core', [:id, :deleted], [4, false])
11
- query.replace!
12
- query.to_sql.should == 'REPLACE INTO foo_core (id, `deleted`) VALUES (4, 0)'
13
- end
14
-
15
- it 'encloses strings in single quotes' do
16
- query = Riddle::Query::Insert.new('foo_core', [:id, :name], [4, 'bar'])
17
- query.to_sql.should == "INSERT INTO foo_core (id, `name`) VALUES (4, 'bar')"
18
- end
19
-
20
- it 'handles inserts with more than one set of values' do
21
- query = Riddle::Query::Insert.new 'foo_core', [:id, :name], [[4, 'bar'], [5, 'baz']]
22
- query.to_sql.
23
- should == "INSERT INTO foo_core (id, `name`) VALUES (4, 'bar'), (5, 'baz')"
24
- end
25
- end
@@ -1,226 +0,0 @@
1
- require 'spec_helper'
2
- require 'date'
3
- require 'time'
4
-
5
- describe Riddle::Query::Select do
6
- let(:query) { Riddle::Query::Select.new }
7
-
8
- it 'handles basic queries on a specific index' do
9
- query.from('foo_core').to_sql.should == 'SELECT * FROM foo_core'
10
- end
11
-
12
- it 'handles queries on multiple indices' do
13
- query.from('foo_core').from('foo_delta').to_sql.
14
- should == 'SELECT * FROM foo_core, foo_delta'
15
- end
16
-
17
- it 'accepts multiple arguments for indices' do
18
- query.from('foo_core', 'foo_delta').to_sql.
19
- should == 'SELECT * FROM foo_core, foo_delta'
20
- end
21
-
22
- it "handles custom select values" do
23
- query.values('@weight').from('foo_core').to_sql.
24
- should == 'SELECT @weight FROM foo_core'
25
- end
26
-
27
- it 'handles JSON as a select value using dot notation' do
28
- query.values('key1.key2.key3').from('foo_core').to_sql.
29
- should == 'SELECT key1.key2.key3 FROM foo_core'
30
- end
31
-
32
- it 'handles JSON as a select value using bracket notation 2' do
33
- query.values("key1['key2']['key3']").from('foo_core').to_sql.
34
- should == "SELECT key1['key2']['key3'] FROM foo_core"
35
- end
36
-
37
- it "can prepend select values" do
38
- query.values('@weight').prepend_values('foo').from('foo_core').to_sql.
39
- should == 'SELECT foo, @weight FROM foo_core'
40
- end
41
-
42
- it 'handles basic queries with a search term' do
43
- query.from('foo_core').matching('foo').to_sql.
44
- should == "SELECT * FROM foo_core WHERE MATCH('foo')"
45
- end
46
-
47
- it "escapes single quotes in the search terms" do
48
- query.from('foo_core').matching("fo'o").to_sql.
49
- should == "SELECT * FROM foo_core WHERE MATCH('fo\\'o')"
50
- end
51
-
52
- it 'handles filters with integers' do
53
- query.from('foo_core').matching('foo').where(:bar_id => 10).to_sql.
54
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar_id` = 10"
55
- end
56
-
57
- it "handles exclusive filters with integers" do
58
- query.from('foo_core').matching('foo').where_not(:bar_id => 10).to_sql.
59
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar_id` <> 10"
60
- end
61
-
62
- it "handles filters with true" do
63
- query.from('foo_core').matching('foo').where(:bar => true).to_sql.
64
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar` = 1"
65
- end
66
-
67
- it "handles exclusive filters with true" do
68
- query.from('foo_core').matching('foo').where_not(:bar => true).to_sql.
69
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar` <> 1"
70
- end
71
-
72
- it "handles filters with false" do
73
- query.from('foo_core').matching('foo').where(:bar => false).to_sql.
74
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar` = 0"
75
- end
76
-
77
- it "handles exclusive filters with false" do
78
- query.from('foo_core').matching('foo').where_not(:bar => false).to_sql.
79
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar` <> 0"
80
- end
81
-
82
- it "handles filters with arrays" do
83
- query.from('foo_core').matching('foo').where(:bars => [1, 2]).to_sql.
84
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bars` IN (1, 2)"
85
- end
86
-
87
- it "ignores filters with empty arrays" do
88
- query.from('foo_core').matching('foo').where(:bars => []).to_sql.
89
- should == "SELECT * FROM foo_core WHERE MATCH('foo')"
90
- end
91
-
92
- it "handles exclusive filters with arrays" do
93
- query.from('foo_core').matching('foo').where_not(:bars => [1, 2]).to_sql.
94
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bars` NOT IN (1, 2)"
95
- end
96
-
97
- it "ignores exclusive filters with empty arrays" do
98
- query.from('foo_core').matching('foo').where_not(:bars => []).to_sql.
99
- should == "SELECT * FROM foo_core WHERE MATCH('foo')"
100
- end
101
-
102
- it "handles filters with timestamps" do
103
- time = Time.now
104
- query.from('foo_core').matching('foo').where(:created_at => time).to_sql.
105
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `created_at` = #{time.to_i}"
106
- end
107
-
108
- it "handles filters with dates" do
109
- date = Date.new 2014, 1, 1
110
- query.from('foo_core').matching('foo').where(:created_at => date).to_sql.
111
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `created_at` = #{Time.utc(2014, 1, 1).to_i}"
112
- end
113
-
114
- it "handles exclusive filters with timestamps" do
115
- time = Time.now
116
- query.from('foo_core').matching('foo').where_not(:created_at => time).
117
- to_sql.should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `created_at` <> #{time.to_i}"
118
- end
119
-
120
- it "handles filters with ranges" do
121
- query.from('foo_core').matching('foo').where(:bar => 1..5).to_sql.
122
- should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar` BETWEEN 1 AND 5"
123
- end
124
-
125
- it "handles filters with strings" do
126
- query.from('foo_core').where(:bar => 'baz').to_sql.
127
- should == "SELECT * FROM foo_core WHERE `bar` = 'baz'"
128
- end
129
-
130
- it "handles filters expecting matches on all values" do
131
- query.from('foo_core').where_all(:bars => [1, 2]).to_sql.
132
- should == "SELECT * FROM foo_core WHERE `bars` = 1 AND `bars` = 2"
133
- end
134
-
135
- it "handles filters expecting matches on all combinations of values" do
136
- query.from('foo_core').where_all(:bars => [[1,2], 3]).to_sql.
137
- should == "SELECT * FROM foo_core WHERE `bars` IN (1, 2) AND `bars` = 3"
138
- end
139
-
140
- it "handles exclusive filters expecting matches on none of the values" do
141
- query.from('foo_core').where_not_all(:bars => [1, 2]).to_sql.
142
- should == "SELECT * FROM foo_core WHERE (`bars` <> 1 OR `bars` <> 2)"
143
- end
144
-
145
- it 'handles filters on JSON with dot syntax' do
146
- query.from('foo_core').where('key1.key2.key3' => 10).to_sql.
147
- should == "SELECT * FROM foo_core WHERE key1.key2.key3 = 10"
148
- end
149
-
150
- it 'handles filters on JSON with bracket syntax' do
151
- query.from('foo_core').where("key1['key2']['key3']" => 10).to_sql.
152
- should == "SELECT * FROM foo_core WHERE key1['key2']['key3'] = 10"
153
- end
154
-
155
- it 'handles grouping' do
156
- query.from('foo_core').group_by('bar_id').to_sql.
157
- should == "SELECT * FROM foo_core GROUP BY `bar_id`"
158
- end
159
-
160
- it "handles grouping n-best results" do
161
- query.from('foo_core').group_by('bar_id').group_best(3).to_sql.
162
- should == "SELECT * FROM foo_core GROUP 3 BY `bar_id`"
163
- end
164
-
165
- it 'handles having conditions' do
166
- query.from('foo_core').group_by('bar_id').having('bar_id > 10').to_sql.
167
- should == "SELECT * FROM foo_core GROUP BY `bar_id` HAVING bar_id > 10"
168
- end
169
-
170
- it 'handles ordering' do
171
- query.from('foo_core').order_by('bar_id ASC').to_sql.
172
- should == 'SELECT * FROM foo_core ORDER BY `bar_id` ASC'
173
- end
174
-
175
- it 'handles ordering when an already escaped column is passed in' do
176
- query.from('foo_core').order_by('`bar_id` ASC').to_sql.
177
- should == 'SELECT * FROM foo_core ORDER BY `bar_id` ASC'
178
- end
179
-
180
- it 'handles ordering when just a symbol is passed in' do
181
- query.from('foo_core').order_by(:bar_id).to_sql.
182
- should == 'SELECT * FROM foo_core ORDER BY `bar_id`'
183
- end
184
-
185
- it 'handles ordering when a computed sphinx variable is passed in' do
186
- query.from('foo_core').order_by('@weight DESC').to_sql.
187
- should == 'SELECT * FROM foo_core ORDER BY @weight DESC'
188
- end
189
-
190
- it "handles ordering when a sphinx function is passed in" do
191
- query.from('foo_core').order_by('weight() DESC').to_sql.
192
- should == 'SELECT * FROM foo_core ORDER BY weight() DESC'
193
- end
194
-
195
- it 'handles group ordering' do
196
- query.from('foo_core').order_within_group_by('bar_id ASC').to_sql.
197
- should == 'SELECT * FROM foo_core WITHIN GROUP ORDER BY `bar_id` ASC'
198
- end
199
-
200
- it 'handles a limit' do
201
- query.from('foo_core').limit(10).to_sql.
202
- should == 'SELECT * FROM foo_core LIMIT 10'
203
- end
204
-
205
- it 'handles an offset' do
206
- query.from('foo_core').offset(20).to_sql.
207
- should == 'SELECT * FROM foo_core LIMIT 20, 20'
208
- end
209
-
210
- it 'handles an option' do
211
- query.from('foo_core').with_options(:bar => :baz).to_sql.
212
- should == 'SELECT * FROM foo_core OPTION bar=baz'
213
- end
214
-
215
- it 'handles multiple options' do
216
- sql = query.from('foo_core').with_options(:bar => :baz, :qux => :quux).
217
- to_sql
218
- sql.should match(/OPTION .*bar=baz/)
219
- sql.should match(/OPTION .*qux=quux/)
220
- end
221
-
222
- it "handles options of hashes" do
223
- query.from('foo_core').with_options(:weights => {:foo => 5}).to_sql.
224
- should == 'SELECT * FROM foo_core OPTION weights=(foo=5)'
225
- end
226
- end