rsolr 1.0.0.beta → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,195 +0,0 @@
1
- require 'spec_helper'
2
- describe "RSolr::Client" do
3
-
4
- module ClientHelper
5
- def client
6
- @client ||= (
7
- connection = RSolr::Http.new URI.parse("http://localhost:9999/solr")
8
- RSolr::Client.new(connection)
9
- )
10
- end
11
- end
12
-
13
- context "initialize" do
14
- it "should accept whatevs and set it as the @connection" do
15
- RSolr::Client.new(:whatevs).connection.should == :whatevs
16
- end
17
- end
18
-
19
- context "adapt_response" do
20
-
21
- include ClientHelper
22
-
23
- it 'should not try to evaluate ruby when the :qt is not :ruby' do
24
- body = '{:time=>"NOW"}'
25
- result = client.send(:adapt_response, {:params=>{}}, {:body => body})
26
- result.should be_a(String)
27
- result.should == body
28
- end
29
-
30
- it 'should evaluate ruby responses when the :wt is :ruby' do
31
- body = '{:time=>"NOW"}'
32
- result = client.send(:adapt_response, {:params=>{:wt=>:ruby}}, {:body=>body})
33
- result.should be_a(Hash)
34
- result.should == {:time=>"NOW"}
35
- end
36
-
37
- ["nil", :ruby].each do |wt|
38
- it "should return an object that responds to :request and :response when :wt == #{wt}" do
39
- req = {:params=>{:wt=>wt}}
40
- res = {:body=>""}
41
- result = client.send(:adapt_response, req, res)
42
- result.request.should == req
43
- result.response.should == res
44
- end
45
- end
46
-
47
- it "ought raise a RSolr::Error::InvalidRubyResponse when the ruby is indeed frugged" do
48
- lambda {
49
- client.send(:adapt_response, {:params=>{:wt => :ruby}}, {:body => "<woops/>"})
50
- }.should raise_error RSolr::Error::InvalidRubyResponse
51
- end
52
-
53
- end
54
-
55
- context "build_request" do
56
- include ClientHelper
57
- it 'should return a request context array' do
58
- result = client.build_request 'select', {:q=>'test', :fq=>[0,1]}, "data", headers = {}
59
- ["select?fq=0&fq=1&q=test", "select?q=test&fq=0&fq=1"].should include(result[0].to_s)
60
- result[1].should == "data"
61
- result[2].should == headers
62
- end
63
- it "should set the Content-Type header to application/x-www-form-urlencoded if a hash is passed in to the data arg" do
64
- result = client.build_request 'select', nil, {:q=>'test', :fq=>[0,1]}, headers = {}
65
- result[0].to_s.should == "select"
66
- ["fq=0&fq=1&q=test", "q=test&fq=0&fq=1"].should include(result[1])
67
- result[2].should == headers
68
- end
69
- end
70
-
71
- context "map_params" do
72
- include ClientHelper
73
- it "should return a hash if nil is passed in" do
74
- client.map_params(nil).should == {:wt => :ruby}
75
- end
76
- it "should set the :wt to ruby if blank" do
77
- r = client.map_params({:q=>"q"})
78
- r[:q].should == "q"
79
- r[:wt].should == :ruby
80
- end
81
- it "should not override the :wt to ruby if set" do
82
- r = client.map_params({:q=>"q", :wt => :json})
83
- r[:q].should == "q"
84
- r[:wt].should == :json
85
- end
86
- end
87
-
88
- context "send_request" do
89
- include ClientHelper
90
- it "should forward these method calls the #connection object" do
91
- [:get, :post, :head].each do |meth|
92
- client.connection.should_receive(meth).
93
- and_return({:status => 200})
94
- client.send_request meth, '', {}, nil, {}
95
- end
96
- end
97
- it "should extend any exception raised by the #connection object with a RSolr::Error::SolrContext" do
98
- client.connection.should_receive(:get).
99
- and_raise(RuntimeError)
100
- lambda {
101
- client.send_request :get, '', {}, nil, {}
102
- }.should raise_error(RuntimeError){|error|
103
- error.should be_a(RSolr::Error::SolrContext)
104
- error.should respond_to(:request)
105
- error.request.keys.should include(:connection, :method, :uri, :data, :headers, :params)
106
- }
107
- end
108
- it "should raise an Http error if the response status code aint right" do
109
- client.connection.should_receive(:get).
110
- and_return({:status_code => 404})
111
- lambda{
112
- client.send_request :get, '', {}, nil, {}
113
- }.should raise_error(RSolr::Error::Http) {|error|
114
- error.should be_a(RSolr::Error::Http)
115
- error.should respond_to(:request)
116
- error.should respond_to(:response)
117
- }
118
- end
119
- end
120
-
121
- context "post" do
122
- include ClientHelper
123
- it "should pass the expected params to the connection's #post method" do
124
- client.connection.should_receive(:post).
125
- with("update?wt=ruby", "the data", {"Content-Type" => "text/plain"}).
126
- and_return(:status => 200)
127
- client.post "update", "the data", nil, {"Content-Type" => "text/plain"}
128
- end
129
- end
130
-
131
- context "xml" do
132
- include ClientHelper
133
- it "should return an instance of RSolr::Xml::Generator" do
134
- client.xml.should be_a RSolr::Xml::Generator
135
- end
136
- end
137
-
138
- context "add" do
139
- include ClientHelper
140
- it "should send xml to the connection's #post method" do
141
- client.connection.should_receive(:post).
142
- with("update?wt=ruby", "<xml/>", {"Content-Type"=>"text/xml"}).
143
- and_return(:status => 200)
144
- # the :xml attr is lazy loaded... so load it up first
145
- client.xml
146
- client.xml.should_receive(:add).
147
- with({:id=>1}, :commitWith=>1.0).
148
- and_return("<xml/>")
149
- client.add({:id=>1}, {:commitWith=>1.0})
150
- end
151
- end
152
-
153
- context "update" do
154
- include ClientHelper
155
- it "should send data to the connection's #post method" do
156
- client.connection.should_receive(:post).
157
- with("update?wt=xml", instance_of(String), {"Content-Type"=>"text/xml"}).
158
- and_return(:status => 200)
159
- client.update("<optimize/>", {:wt=>:xml})
160
- end
161
- end
162
-
163
- context "post based helper methods:" do
164
- include ClientHelper
165
- [:commit, :optimize, :rollback].each do |meth|
166
- it "should send a #{meth} message to the connection's #post method" do
167
- client.connection.should_receive(:post).
168
- with("update?wt=ruby", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><#{meth}/>", {"Content-Type"=>"text/xml"}).
169
- and_return(:status => 200)
170
- client.send meth
171
- end
172
- end
173
- end
174
-
175
- context "delete_by_id" do
176
- include ClientHelper
177
- it "should send data to the connection's #post method" do
178
- client.connection.should_receive(:post).
179
- with("update?wt=ruby", instance_of(String), {"Content-Type"=>"text/xml"}).
180
- and_return(:status => 200)
181
- client.delete_by_id 1
182
- end
183
- end
184
-
185
- context "delete_by_query" do
186
- include ClientHelper
187
- it "should send data to the connection's #post method" do
188
- client.connection.should_receive(:post).
189
- with("update?wt=ruby", instance_of(String), {"Content-Type"=>"text/xml"}).
190
- and_return(:status => 200)
191
- client.delete_by_query :fq => "category:\"trash\""
192
- end
193
- end
194
-
195
- end
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
- describe "RSolr::Error" do
3
- # add some shiz here...
4
- end
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
- describe "RSolr::Http" do
3
- # add some shiz here...
4
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- describe "RSolr class methods" do
3
-
4
- it "should parse these here options" do
5
- result = RSolr.parse_options "http://localhost:8983/solr/blah", :proxy => "http://qtpaglzvm.com"
6
- result[0].should be_a(URI)
7
- result[1].should be_a(Hash)
8
- result[1][:proxy].should be_a(URI)
9
- end
10
-
11
- it "should not create a URI instance for :proxy => nil" do
12
- result = RSolr.parse_options "http://localhost:8983/solr/blah"
13
- result[0].should be_a(URI)
14
- result[1].should == {:proxy => nil}
15
- end
16
-
17
- end