mdwan-rsolr 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,97 @@
1
+ # These are all of the test methods used by the various connection + adapter tests
2
+ # Currently: Direct and HTTP
3
+ # By sharing these tests, we can make sure the adapters are doing what they're suppossed to
4
+ # while staying "dry"
5
+
6
+ module ConnectionTestMethods
7
+
8
+
9
+ def teardown
10
+ @solr.delete_by_query('id:[* TO *]')
11
+ @solr.commit
12
+ assert_equal 0, @solr.select(:q=>'*:*')[:response][:docs].size
13
+ end
14
+
15
+ # If :wt is NOT :ruby, the format doesn't get converted into a Mash (special Hash; see lib/mash.rb)
16
+ # Raw ruby can be returned by using :wt=>'ruby', not :ruby
17
+ def test_raw_response_formats
18
+ ruby_response = @solr.select(:q=>'*:*', :wt=>'ruby')
19
+ assert ruby_response.is_a?(String)
20
+ assert ruby_response =~ %r('wt'=>'ruby')
21
+ # xml?
22
+ xml_response = @solr.select(:q=>'*:*', :wt=>'xml')
23
+ assert xml_response.is_a?(String)
24
+ assert xml_response =~ %r(<str name="wt">xml</str>)
25
+ # json?
26
+ json_response = @solr.select(:q=>'*:*', :wt=>'json')
27
+ assert json_response.is_a?(String)
28
+ assert json_response =~ %r("wt":"json")
29
+ end
30
+
31
+ def test_raise_on_invalid_query
32
+ assert_raise RSolr::RequestError do
33
+ @solr.select(:q=>'!')
34
+ end
35
+ end
36
+
37
+ def test_select_response_docs
38
+ @solr.add(:id=>1, :price=>1.00, :cat=>['electronics', 'something else'])
39
+ @solr.commit
40
+ r = @solr.select(:q=>'*:*')
41
+ assert r.is_a?(Mash)
42
+
43
+ docs = r[:response][:docs]
44
+ assert_equal Array, docs.class
45
+ first = docs.first
46
+
47
+ # test the has? method
48
+ assert_equal 1.00, first[:price]
49
+
50
+ assert_equal Array, first[:cat].class
51
+ assert first[:cat].include?('electronics')
52
+ assert first[:cat].include?('something else')
53
+ assert first[:cat].include?('something else')
54
+
55
+ end
56
+
57
+ def test_add
58
+ assert_equal 0, @solr.select(:q=>'*:*')[:response][:numFound]
59
+ update_response = @solr.add({:id=>100})
60
+ assert update_response.is_a?(Mash)
61
+ #
62
+ @solr.commit
63
+ assert_equal 1, @solr.select(:q=>'*:*')[:response][:numFound]
64
+ end
65
+
66
+ def test_delete_by_id
67
+ @solr.add(:id=>100)
68
+ @solr.commit
69
+ total = @solr.select(:q=>'*:*')[:response][:numFound]
70
+ assert_equal 1, total
71
+ delete_response = @solr.delete_by_id(100)
72
+ @solr.commit
73
+ assert delete_response.is_a?(Mash)
74
+ total = @solr.select(:q=>'*:*')[:response][:numFound]
75
+ assert_equal 0, total
76
+ end
77
+
78
+ def test_delete_by_query
79
+ @solr.add(:id=>1, :name=>'BLAH BLAH BLAH')
80
+ @solr.commit
81
+ assert_equal 1, @solr.select(:q=>'*:*')[:response][:numFound]
82
+ response = @solr.delete_by_query('name:"BLAH BLAH BLAH"')
83
+ @solr.commit
84
+ assert response.is_a?(Mash)
85
+ assert_equal 0, @solr.select(:q=>'*:*')[:response][:numFound]
86
+ end
87
+
88
+ def test_admin_luke_index_info
89
+ response = @solr.send_request('/admin/luke', :numTerms=>0)
90
+ assert response.is_a?(Mash)
91
+ # make sure the ? methods are true/false
92
+ assert [true, false].include?(response[:index][:current])
93
+ assert [true, false].include?(response[:index][:optimized])
94
+ assert [true, false].include?(response[:index][:hasDeletions])
95
+ end
96
+
97
+ end
@@ -0,0 +1,18 @@
1
+ # don't run this test in jruby,
2
+ # the curb gem is a c extension based gem, jruby has no support for this
3
+ unless defined?(JRUBY_VERSION)
4
+
5
+ require 'helper'
6
+ require 'http_client/test_methods'
7
+
8
+ class CurbTest < RSolrBaseTest
9
+
10
+ def setup
11
+ @c ||= RSolr::HTTPClient::Connector.new(:curb).connect(URL)
12
+ end
13
+
14
+ include HTTPClientTestMethods
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+ require 'http_client/test_methods'
3
+
4
+ class NetHTTPTest < RSolrBaseTest
5
+
6
+ def setup
7
+ @c ||= RSolr::HTTPClient::Connector.new(:net_http).connect(URL)
8
+ end
9
+
10
+ include HTTPClientTestMethods
11
+
12
+ end
@@ -0,0 +1,40 @@
1
+ module HTTPClientTestMethods
2
+
3
+ URL = 'http://localhost:8983/solr/'
4
+
5
+ def test_raise_unknown_adapter
6
+ assert_raise RSolr::HTTPClient::UnkownAdapterError do
7
+ c = RSolr::HTTPClient::Connector.new(:blah).connect(URL)
8
+ end
9
+ end
10
+
11
+ # the responses from the HTTPClient adapter should return the same hash structure
12
+ def test_get_response
13
+ headers = {}
14
+ data = nil
15
+ response = @c.get('select', :q=>'*:*')
16
+ assert_equal data, response[:data]
17
+ assert_equal 200, response[:status_code]
18
+ expected_params = {:q=>'*:*'}
19
+ assert_equal expected_params, response[:params]
20
+ assert_equal 'select', response[:path]
21
+ assert response[:body] =~ /name="responseHeader"/
22
+ assert_equal 'http://localhost:8983/solr/select?q=%2A%3A%2A', response[:url]
23
+ assert_equal headers, response[:headers]
24
+ end
25
+
26
+ def test_post_response
27
+ headers = {"Content-Type" => 'text/xml; charset=utf-8'}
28
+ data = '<add><doc><field name="id">1</field></doc></add>'
29
+ response = @c.post('update', data, {}, headers)
30
+ assert_equal data, response[:data]
31
+ assert_equal 200, response[:status_code]
32
+ expected_params = {}
33
+ assert_equal expected_params, response[:params]
34
+ assert_equal 'update', response[:path]
35
+ assert response[:body] =~ /name="responseHeader"/
36
+ assert_equal 'http://localhost:8983/solr/update', response[:url]
37
+ assert_equal headers, response[:headers]
38
+ end
39
+
40
+ end
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ class HTTPUtilTest < RSolrBaseTest
4
+
5
+ class DummyClass
6
+ include RSolr::HTTPClient::Util
7
+ end
8
+
9
+ def setup
10
+ @c = DummyClass.new
11
+ end
12
+
13
+ def test_build_url
14
+ m = @c.method(:build_url)
15
+ assert_equal '/something', m.call('/something')
16
+ assert_equal '/something?q=Testing', m.call('/something', :q=>'Testing')
17
+ assert_equal '/something?array=1&array=2&array=3', m.call('/something', :array=>[1, 2, 3])
18
+ assert_equal '/something?array=1&array=2&array=3&q=A', m.call('/something', :q=>'A', :array=>[1, 2, 3])
19
+ end
20
+
21
+ def test_escape
22
+ assert_equal '%2B', @c.escape('+')
23
+ assert_equal 'This+is+a+test', @c.escape('This is a test')
24
+ assert_equal '%3C%3E%2F%5C', @c.escape('<>/\\')
25
+ assert_equal '%22', @c.escape('"')
26
+ assert_equal '%3A', @c.escape(':')
27
+ end
28
+
29
+ def test_hash_to_params
30
+ my_params = {
31
+ :z=>'should be last',
32
+ :q=>'test',
33
+ :d=>[1, 2, 3, 4],
34
+ :b=>:zxcv,
35
+ :x=>['!', '*', nil]
36
+ }
37
+ assert_equal 'b=zxcv&d=1&d=2&d=3&d=4&q=test&x=%21&x=%2A&z=should+be+last', @c.hash_to_params(my_params)
38
+ end
39
+
40
+ end
@@ -0,0 +1,107 @@
1
+
2
+ require 'helper'
3
+
4
+ class MessageTest < RSolrBaseTest
5
+
6
+ # call all of the simple methods...
7
+ # make sure the xml string is valid
8
+ # ensure the class is actually Solr::XML
9
+ def test_simple_methods
10
+ [:optimize, :rollback, :commit].each do |meth|
11
+ result = RSolr::Message.send(meth)
12
+ assert_equal "<#{meth}/>", result.to_s
13
+ assert_equal String, result.class
14
+ end
15
+ end
16
+
17
+ def test_add_yields_doc_objects_if_block_given
18
+ documents = [{:id=>1, :name=>'sam', :cat=>['cat 1', 'cat 2']}]
19
+ add_attrs = {:boost=>200.00}
20
+ result = RSolr::Message.add(documents, add_attrs) do |doc|
21
+ doc.field_by_name(:name).attrs[:boost] = 10
22
+ assert_equal 4, doc.fields.size
23
+ assert_equal 2, doc.fields_by_name(:cat).size
24
+ end
25
+ #<add boost="200.0">
26
+ #<doc>
27
+ #<field name="cat">cat 1</field>
28
+ #<field name="cat">cat 2</field>
29
+ #<field name="name" boost="10">sam</field>
30
+ #<field name="id">1</field>
31
+ #</doc>
32
+ #</add>
33
+ assert result =~ %r(name="cat">cat 1</field>)
34
+ assert result =~ %r(name="cat">cat 2</field>)
35
+ assert result =~ %r(<add boost="200.0">)
36
+ assert result =~ %r(boost="10")
37
+ assert result =~ %r(<field name="id">1</field>)
38
+ end
39
+
40
+ def test_delete_by_id
41
+ result = RSolr::Message.delete_by_id(10)
42
+ assert_equal String, result.class
43
+ assert_equal '<delete><id>10</id></delete>', result.to_s
44
+ end
45
+
46
+ def test_delete_by_multiple_ids
47
+ result = RSolr::Message.delete_by_id([1, 2, 3])
48
+ assert_equal String, result.class
49
+ assert_equal '<delete><id>1</id><id>2</id><id>3</id></delete>', result.to_s
50
+ end
51
+
52
+ def test_delete_by_query
53
+ result = RSolr::Message.delete_by_id('status:"LOST"')
54
+ assert_equal String, result.class
55
+ assert_equal '<delete><id>status:"LOST"</id></delete>', result.to_s
56
+ end
57
+
58
+ def test_delete_by_multiple_queries
59
+ result = RSolr::Message.delete_by_id(['status:"LOST"', 'quantity:0'])
60
+ assert_equal String, result.class
61
+ assert_equal '<delete><id>status:"LOST"</id><id>quantity:0</id></delete>', result.to_s
62
+ end
63
+
64
+ # add a single hash ("doc")
65
+ def test_add_hash
66
+ data = {
67
+ :id=>1,
68
+ :name=>'matt'
69
+ }
70
+ assert RSolr::Message.add(data).to_s =~ /<field name="name">matt<\/field>/
71
+ assert RSolr::Message.add(data).to_s =~ /<field name="id">1<\/field>/
72
+ end
73
+
74
+ # add an array of hashes
75
+ def test_add_array
76
+ data = [
77
+ {
78
+ :id=>1,
79
+ :name=>'matt'
80
+ },
81
+ {
82
+ :id=>2,
83
+ :name=>'sam'
84
+ }
85
+ ]
86
+
87
+ message = RSolr::Message.add(data)
88
+ expected = '<add><doc><field name="id">1</field><field name="name">matt</field></doc><doc><field name="id">2</field><field name="name">sam</field></doc></add>'
89
+
90
+ assert message.to_s=~/<field name="name">matt<\/field>/
91
+ assert message.to_s=~/<field name="name">sam<\/field>/
92
+ end
93
+
94
+ # multiValue field support test, thanks to Fouad Mardini!
95
+ def test_add_multi_valued_field
96
+ data = {
97
+ :id => 1,
98
+ :name => ['matt1', 'matt2']
99
+ }
100
+
101
+ result = RSolr::Message.add(data)
102
+
103
+ assert result.to_s =~ /<field name="name">matt1<\/field>/
104
+ assert result.to_s =~ /<field name="name">matt2<\/field>/
105
+ end
106
+
107
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdwan-rsolr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.2
5
+ platform: ruby
6
+ authors:
7
+ - Matt Mitchell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: builder
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.2
24
+ version:
25
+ description: RSolr is a Ruby gem for working with Apache Solr!
26
+ email: goodieboy@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - Rakefile
34
+ - README.rdoc
35
+ - CHANGES.txt
36
+ files:
37
+ - examples/http.rb
38
+ - examples/direct.rb
39
+ - lib/core_ext.rb
40
+ - lib/mash.rb
41
+ - lib/rsolr.rb
42
+ - lib/rsolr/adapter/common_methods.rb
43
+ - lib/rsolr/adapter/direct.rb
44
+ - lib/rsolr/adapter/http.rb
45
+ - lib/rsolr/adapter.rb
46
+ - lib/rsolr/connection.rb
47
+ - lib/rsolr/http_client/adapter/curb.rb
48
+ - lib/rsolr/http_client/adapter/net_http.rb
49
+ - lib/rsolr/http_client/adapter.rb
50
+ - lib/rsolr/http_client.rb
51
+ - lib/rsolr/message.rb
52
+ - LICENSE
53
+ - Rakefile
54
+ - README.rdoc
55
+ - rsolr-ruby.gemspec
56
+ - CHANGES.txt
57
+ has_rdoc: true
58
+ homepage: http://github.com/mwmitchell/rsolr
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.2.0
80
+ signing_key:
81
+ specification_version: 2
82
+ summary: A Ruby client for Apache Solr
83
+ test_files:
84
+ - test/connection/direct_test.rb
85
+ - test/connection/http_test.rb
86
+ - test/connection/test_methods.rb
87
+ - test/http_client/curb_test.rb
88
+ - test/http_client/net_http_test.rb
89
+ - test/http_client/test_methods.rb
90
+ - test/http_client/util_test.rb
91
+ - test/message_test.rb
92
+ - test/rsolr_test
93
+ - test/test_helpers.rb