rsolr 0.13.0.pre → 1.0.0.beta
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.
- data/README.rdoc +48 -29
- data/VERSION +1 -1
- data/lib/rsolr/char.rb +9 -0
- data/lib/rsolr/client.rb +80 -58
- data/lib/rsolr/error.rb +122 -0
- data/lib/rsolr/http.rb +106 -0
- data/lib/rsolr/uri.rb +55 -0
- data/lib/rsolr/xml.rb +161 -0
- data/lib/rsolr.rb +18 -39
- data/spec/api/rsolr_client_spec.rb +195 -0
- data/spec/api/rsolr_error_spec.rb +4 -0
- data/spec/api/rsolr_http_spec.rb +4 -0
- data/spec/api/rsolr_spec.rb +11 -23
- data/spec/api/rsolr_uri_spec.rb +70 -0
- data/spec/api/{message_spec.rb → rsolr_xml_spec.rb} +5 -4
- metadata +14 -18
- data/lib/rsolr/connection/httpable.rb +0 -101
- data/lib/rsolr/connection/net_http.rb +0 -30
- data/lib/rsolr/connection/utils.rb +0 -74
- data/lib/rsolr/connection.rb +0 -9
- data/lib/rsolr/message/document.rb +0 -48
- data/lib/rsolr/message/field.rb +0 -20
- data/lib/rsolr/message/generator.rb +0 -89
- data/lib/rsolr/message.rb +0 -8
- data/spec/api/client_spec.rb +0 -115
- data/spec/api/connection/httpable_spec.rb +0 -157
- data/spec/api/connection/net_http_spec.rb +0 -137
- data/spec/api/connection/utils_spec.rb +0 -84
- data/spec/integration/http_errors_spec.rb +0 -12
@@ -1,137 +0,0 @@
|
|
1
|
-
describe RSolr::Connection::NetHttp do
|
2
|
-
|
3
|
-
# calls #let to set "net_http" as method accessor
|
4
|
-
module NetHttpHelper
|
5
|
-
def self.included base
|
6
|
-
base.let(:net_http){ RSolr::Connection::NetHttp.new }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context '#request' do
|
11
|
-
|
12
|
-
include NetHttpHelper
|
13
|
-
|
14
|
-
it 'should forward simple, non-data calls to #get' do
|
15
|
-
net_http.should_receive(:create_http_context).
|
16
|
-
with("/select", {:q=>"a"}, nil, {}).
|
17
|
-
and_return(:path=>"/solr/select?q=a", :params=>{:q=>"a"}, :data=>nil, :query=>"q=a", :host=>"http://127.0.0.1:8983")
|
18
|
-
net_http.should_receive(:get).
|
19
|
-
with("/solr/select?q=a").
|
20
|
-
and_return(['', 200, 'OK'])
|
21
|
-
net_http.request('/select', :q=>'a')
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should forward :method=>:post calls to #post with a special header' do
|
25
|
-
net_http.should_receive(:post).
|
26
|
-
with("/solr/select", "q=a", {"Content-Type"=>"application/x-www-form-urlencoded"}).
|
27
|
-
and_return(["", 200, "OK"])
|
28
|
-
net_http.request('/select', {:q=>'a'}, :method=>:post)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should forward data calls to #post' do
|
32
|
-
net_http.should_receive(:post).
|
33
|
-
with("/solr/update", "<optimize/>", {"Content-Type"=>"text/xml; charset=utf-8"}).
|
34
|
-
and_return(["", 200, "OK"])
|
35
|
-
net_http.request('/update', {}, '<optimize/>')
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'connection' do
|
41
|
-
|
42
|
-
include NetHttpHelper
|
43
|
-
|
44
|
-
it 'will create an instance of Net::HTTP' do
|
45
|
-
net_http.send(:connection).should be_a(Net::HTTP)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'get/post' do
|
51
|
-
|
52
|
-
include NetHttpHelper
|
53
|
-
|
54
|
-
it 'should make a GET request as expected' do
|
55
|
-
net_http_response = mock('net_http_response')
|
56
|
-
net_http_response.should_receive(:code).
|
57
|
-
and_return(200)
|
58
|
-
net_http_response.should_receive(:body).
|
59
|
-
and_return('The Response')
|
60
|
-
net_http_response.should_receive(:message).
|
61
|
-
and_return('OK')
|
62
|
-
c = net_http.send(:connection)
|
63
|
-
c.should_receive(:get).
|
64
|
-
with('/solr/select?q=1').
|
65
|
-
and_return(net_http_response)
|
66
|
-
|
67
|
-
context = net_http.send(:get, '/solr/select?q=1')
|
68
|
-
context.should be_a(Array)
|
69
|
-
|
70
|
-
context.size.should == 3
|
71
|
-
|
72
|
-
context[0].should == 200
|
73
|
-
context[1].should == 'OK'
|
74
|
-
context[2].should == 'The Response'
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should make a POST request as expected' do
|
78
|
-
net_http_response = mock('net_http_response')
|
79
|
-
net_http_response.should_receive(:code).
|
80
|
-
and_return(200)
|
81
|
-
net_http_response.should_receive(:body).
|
82
|
-
and_return('The Response')
|
83
|
-
net_http_response.should_receive(:message).
|
84
|
-
and_return('OK')
|
85
|
-
c = net_http.send(:connection)
|
86
|
-
c.should_receive(:post).
|
87
|
-
with('/solr/update', '<rollback/>', {}).
|
88
|
-
and_return(net_http_response)
|
89
|
-
context = net_http.send(:post, '/solr/update', '<rollback/>')
|
90
|
-
context.should be_a(Array)
|
91
|
-
|
92
|
-
context.size.should == 3
|
93
|
-
|
94
|
-
context[0].should == 200
|
95
|
-
context[1].should == 'OK'
|
96
|
-
context[2].should == 'The Response'
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'build_url' do
|
102
|
-
|
103
|
-
include NetHttpHelper
|
104
|
-
|
105
|
-
it 'should incude the base path to solr' do
|
106
|
-
result = net_http.send(:build_url, '/select', :q=>'*:*', :check=>'{!}')
|
107
|
-
# this is a non-ordered hash work around,
|
108
|
-
# -- the order of the parameters in the resulting url will be different depending on the ruby distribution/platform
|
109
|
-
# yuk.
|
110
|
-
begin
|
111
|
-
result.should == '/solr/select?check=%7B%21%7D&q=%2A%3A%2A'
|
112
|
-
rescue
|
113
|
-
result.should == '/solr/select?q=%2A%3A%2A&check=%7B%21%7D'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'encode_utf8' do
|
120
|
-
|
121
|
-
include NetHttpHelper
|
122
|
-
|
123
|
-
it 'should encode response body as utf-8' do
|
124
|
-
string = 'testing'
|
125
|
-
if RUBY_VERSION =~ /1\.9/
|
126
|
-
string.encoding.should == Encoding::US_ASCII
|
127
|
-
encoded_string = net_http.send(:encode_utf8, string)
|
128
|
-
string.encoding.should == Encoding::UTF_8
|
129
|
-
else
|
130
|
-
encoded_string = net_http.send(:encode_utf8, string)
|
131
|
-
encoded_string.should == string
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
describe RSolr::Connection::Utils do
|
2
|
-
|
3
|
-
# calls #let to set "utils" as a method accessor
|
4
|
-
module UtilsHelper
|
5
|
-
def self.included base
|
6
|
-
base.let(:utils){ nil.extend RSolr::Connection::Utils }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'hash_to_query method' do
|
11
|
-
|
12
|
-
include UtilsHelper
|
13
|
-
|
14
|
-
it "should build a query string from a hash, converting arrays to multi-params and removing nils/emptys" do
|
15
|
-
test_params = {
|
16
|
-
:z=>'should be whatever',
|
17
|
-
:q=>'test',
|
18
|
-
:item => [1, 2, 3, nil],
|
19
|
-
:nil=>nil
|
20
|
-
}
|
21
|
-
result = utils.hash_to_query(test_params)
|
22
|
-
[/z=should\+be\+whatever/, /q=test/, /item=1/, /item=2/, /item=3/].each do |regexp|
|
23
|
-
result.should match(regexp)
|
24
|
-
end
|
25
|
-
result.split('&').size.should == 5
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should escape &' do
|
29
|
-
utils.hash_to_query(:fq => "&").should == 'fq=%26'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should convert spaces to +' do
|
33
|
-
utils.hash_to_query(:fq => "me and you").should == 'fq=me+and+you'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should escape comlex queries, part 1' do
|
37
|
-
my_params = {'fq' => '{!raw f=field_name}crazy+\"field+value'}
|
38
|
-
expected = 'fq=%7B%21raw+f%3Dfield_name%7Dcrazy%2B%5C%22field%2Bvalue'
|
39
|
-
utils.hash_to_query(my_params).should == expected
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should escape complex queries, part 2' do
|
43
|
-
my_params = {'q' => '+popularity:[10 TO *] +section:0'}
|
44
|
-
expected = 'q=%2Bpopularity%3A%5B10+TO+%2A%5D+%2Bsection%3A0'
|
45
|
-
utils.hash_to_query(my_params).should == expected
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'escape method' do
|
51
|
-
|
52
|
-
include UtilsHelper
|
53
|
-
|
54
|
-
it 'should escape properly' do
|
55
|
-
utils.escape('+').should == '%2B'
|
56
|
-
utils.escape('This is a test').should == 'This+is+a+test'
|
57
|
-
utils.escape('<>/\\').should == '%3C%3E%2F%5C'
|
58
|
-
utils.escape('"').should == '%22'
|
59
|
-
utils.escape(':').should == '%3A'
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should escape brackets' do
|
63
|
-
utils.escape('{').should == '%7B'
|
64
|
-
utils.escape('}').should == '%7D'
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should escape exclamation marks!' do
|
68
|
-
utils.escape('!').should == '%21'
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'build_url method' do
|
74
|
-
|
75
|
-
include UtilsHelper
|
76
|
-
|
77
|
-
it 'should build correctly' do
|
78
|
-
url = utils.build_url '/solr/select', {:q=>'test'}, 'blah=blah'
|
79
|
-
url.should == '/solr/select?blah=blah&q=test'
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|