rsolr 1.1.2 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
- describe "RSolr::Pagination" do
2
+
3
+ RSpec.describe RSolr::Client do
3
4
  context "build_paginated_request" do
4
5
  it "should create the proper solr params and query string" do
5
6
  c = RSolr::Client.new(nil, {})#.extend(RSolr::Pagination::Client)
@@ -11,13 +12,6 @@ describe "RSolr::Pagination" do
11
12
  expect(r[:uri].query).to match(/rows=25/)
12
13
  expect(r[:uri].query).to match(/start=50/)
13
14
  end
14
-
15
- it 'passes through client options' do
16
- c = RSolr::Client.new(nil, open_timeout: 5, read_timeout: 7)
17
- r = c.build_paginated_request 3, 25, "select", {:params => {:q => "test"}}
18
- expect(r[:open_timeout]).to eq(5)
19
- expect(r[:read_timeout]).to eq(7)
20
- end
21
15
  end
22
16
  context "paginate" do
23
17
  it "should build a paginated request context and call execute" do
@@ -28,7 +22,7 @@ describe "RSolr::Pagination" do
28
22
  :params => {
29
23
  "rows" => 10,
30
24
  "start" => 0,
31
- :wt => :ruby
25
+ :wt => :json
32
26
  }
33
27
  }))
34
28
  c.paginate 1, 10, "select"
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
- describe "RSolr" do
2
+
3
+ RSpec.describe RSolr do
3
4
 
4
5
  it "has a version that can be read via #version or VERSION" do
5
6
  expect(RSolr.version).to eq(RSolr::VERSION)
@@ -27,13 +28,4 @@ describe "RSolr" do
27
28
  expect(RSolr.solr_escape(str)).to eq str
28
29
  end
29
30
  end
30
-
31
- # deprecated as of 2015-02
32
- =begin
33
- it "can escape" do
34
- expect(RSolr).to be_a(RSolr::Char)
35
- expect(RSolr.escape("this string")).to eq("this\\ string")
36
- end
37
- =end
38
-
39
- end
31
+ end
data/spec/api/uri_spec.rb CHANGED
@@ -1,48 +1,8 @@
1
1
  require 'spec_helper'
2
- describe "RSolr::Uri" do
2
+
3
+ RSpec.describe RSolr::Uri do
3
4
 
4
5
  let(:uri) { RSolr::Uri }
5
-
6
- context '.create' do
7
- it "returns a URI object" do
8
- u = uri.create 'http://apache.org'
9
- expect(u).to be_a_kind_of URI
10
- end
11
- it "calls URI.parse" do
12
- expect(URI).to receive(:parse).twice.and_call_original
13
- u = uri.create 'http://apache.org'
14
- end
15
- it "adds a trailing slash after host if there is none" do
16
- u = uri.create 'http://apache.org'
17
- u_str = u.to_s
18
- size = u_str.size
19
- expect(u_str[size - 1]).to eq '/'
20
- end
21
- it "does not add trailing slash after host if there already is one" do
22
- u = uri.create 'http://apache.org/'
23
- u_str = u.to_s
24
- size = u_str.size
25
- expect(u_str[size - 2, 2]).to eq 'g/'
26
- end
27
- it "adds a trailing slash after path if there is none" do
28
- u = uri.create 'http://apache.org/lucene'
29
- u_str = u.to_s
30
- size = u_str.size
31
- expect(u_str[size - 1]).to eq '/'
32
- end
33
- it "does not add trailing slash after path if there already is one" do
34
- u = uri.create 'http://apache.org/lucene/'
35
- u_str = u.to_s
36
- size = u_str.size
37
- expect(u_str[size - 2, 2]).to eq 'e/'
38
- end
39
- it "does not add trailing slash if there are query params" do
40
- u = uri.create 'http://apache.org?foo=bar'
41
- u_str = u.to_s
42
- size = u_str.size
43
- expect(u_str[size - 1]).not_to eq '/'
44
- end
45
- end
46
6
 
47
7
  context '.params_to_solr' do
48
8
  it "converts Hash to Solr query string w/o a starting ?" do
@@ -74,55 +34,4 @@ describe "RSolr::Uri" do
74
34
  expect(uri.params_to_solr(my_params)).to eq(expected)
75
35
  end
76
36
  end
77
-
78
- =begin
79
- # deprecated
80
- context '.build_param' do
81
- it "calls URI.encode_www_form_component by default" do
82
- expect(URI).to receive(:encode_www_form_component).twice
83
- uri.build_param("foo", "bar")
84
- end
85
- it "calls URI.encode_www_form_component if escape arg = true" do
86
- expect(URI).to receive(:encode_www_form_component).twice
87
- uri.build_param("foo", "bar", true)
88
- end
89
- it "doesn't call URI.encode_www_form_component if escape arg = false" do
90
- expect(URI).not_to receive(:encode_www_form_component)
91
- uri.build_param("foo", "bar", false)
92
- end
93
- end
94
-
95
- # deprecated
96
- context ".escape_query_value" do
97
- it 'should escape properly' do
98
- expect(uri.escape_query_value('+')).to eq('%2B')
99
- expect(uri.escape_query_value('This is a test')).to eq('This+is+a+test')
100
- expect(uri.escape_query_value('<>/\\')).to eq('%3C%3E%2F%5C')
101
- expect(uri.escape_query_value('"')).to eq('%22')
102
- expect(uri.escape_query_value(':')).to eq('%3A')
103
- end
104
-
105
- it 'should escape brackets' do
106
- expect(uri.escape_query_value('{')).to eq('%7B')
107
- expect(uri.escape_query_value('}')).to eq('%7D')
108
- end
109
-
110
- it 'should escape exclamation marks!' do
111
- expect(uri.escape_query_value('!')).to eq('%21')
112
- end
113
- end
114
-
115
- # deprecated
116
- context '.bytesize' do
117
- it "calls .bytesize for String" do
118
- str = "testing"
119
- expect(str).to receive(:bytesize)
120
- uri.bytesize(str)
121
- end
122
- it "returns the size of a String" do
123
- expect(uri.bytesize("test")).to eq(4)
124
- end
125
- end
126
- =end
127
-
128
37
  end
data/spec/api/xml_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'builder'
3
3
  require 'nokogiri'
4
- describe "RSolr::Xml" do
5
-
4
+
5
+ RSpec.describe RSolr::Xml do
6
6
  let(:generator){ RSolr::Xml::Generator.new }
7
7
 
8
8
  builder_engines = {
@@ -52,8 +52,6 @@ describe "RSolr::Xml" do
52
52
  add_attrs = {:boost=>200.00}
53
53
  result = generator.add(documents, add_attrs) do |doc|
54
54
  doc.field_by_name(:name).attrs[:boost] = 10
55
- expect(doc.fields.size).to eq(4)
56
- expect(doc.fields_by_name(:cat).size).to eq(2)
57
55
  end
58
56
  expect(result).to match(%r(name="cat">cat 1</field>))
59
57
  expect(result).to match(%r(name="cat">cat 2</field>))
@@ -81,6 +79,17 @@ describe "RSolr::Xml" do
81
79
  expect(result).to match(/<field name="id">1<\/field>/)
82
80
  end
83
81
 
82
+ # add a single hash ("doc")
83
+ it 'should create an add from a hash formatted for atomic updates' do
84
+ data = {
85
+ :id=>1,
86
+ :name=> { set: 'matt' }
87
+ }
88
+ result = generator.add(data)
89
+ expect(result).to match(/<field name="name" update="set">matt<\/field>/)
90
+ expect(result).to match(/<field name="id">1<\/field>/)
91
+ end
92
+
84
93
  # add an array of hashes
85
94
  it 'should create many adds from an array of hashes' do
86
95
  data = [
@@ -95,8 +104,8 @@ describe "RSolr::Xml" do
95
104
  ]
96
105
  message = generator.add(data)
97
106
  expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><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>"
98
- expect(message).to match(/<field name="name">matt<\/field>/)
99
- expect(message).to match(/<field name="name">sam<\/field>/)
107
+ expect(message).to match %r{<field name="name">matt</field>}
108
+ expect(message).to match %r{<field name="name">sam</field>}
100
109
  end
101
110
 
102
111
  # multiValue field support test, thanks to Fouad Mardini!
@@ -122,7 +131,7 @@ describe "RSolr::Xml" do
122
131
  end
123
132
 
124
133
  it 'should create an add from a single Message::Document' do
125
- document = RSolr::Xml::Document.new
134
+ document = RSolr::Document.new
126
135
  document.add_field('id', 1)
127
136
  document.add_field('name', 'matt', :boost => 2.0)
128
137
  result = generator.add(document)
@@ -135,7 +144,7 @@ describe "RSolr::Xml" do
135
144
 
136
145
  it 'should create adds from multiple Message::Documents' do
137
146
  documents = (1..2).map do |i|
138
- doc = RSolr::Xml::Document.new
147
+ doc = RSolr::Document.new
139
148
  doc.add_field('id', i)
140
149
  doc.add_field('name', "matt#{i}")
141
150
  doc
@@ -144,7 +153,24 @@ describe "RSolr::Xml" do
144
153
  expect(result).to match(/<field name="name">matt1<\/field>/)
145
154
  expect(result).to match(/<field name="name">matt2<\/field>/)
146
155
  end
147
-
156
+
157
+ it 'supports nested child documents' do
158
+ data = {
159
+ :_childDocuments_ => [
160
+ {
161
+ :id => 1
162
+ },
163
+ {
164
+ :id => 2
165
+ }
166
+ ]
167
+ }
168
+
169
+ result = generator.add(data)
170
+ expect(result).to match(%r{<add><doc><doc>})
171
+ expect(result).to match(%r{<doc><field name="id">1</field></doc>})
172
+ expect(result).to match(%r{<doc><field name="id">2</field></doc>})
173
+ end
148
174
  end
149
175
 
150
176
  context :delete_by_id do
@@ -217,5 +243,5 @@ describe "RSolr::Xml" do
217
243
  expect(result).to match(/<field name="whatever">some string<\/field>/)
218
244
  end
219
245
  end
220
- end
246
+ end
221
247
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'solr_wrapper'
3
3
 
4
- describe "Solr basic_configs" do
4
+ RSpec.describe "Solr basic_configs" do
5
5
  SOLR_INSTANCE = SolrWrapper.default_instance({})
6
6
  before(:all) { SOLR_INSTANCE.start }
7
7
  after(:all) { SOLR_INSTANCE.stop }
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,87 @@ require 'rspec'
3
3
 
4
4
  FIXTURES_DIR = File.expand_path("fixtures", File.dirname(__FILE__))
5
5
 
6
- RSpec.configure do |c|
6
+ RSpec.configure do |config|
7
+ # rspec-expectations config goes here. You can use an alternate
8
+ # assertion/expectation library such as wrong or the stdlib/minitest
9
+ # assertions if you prefer.
10
+ config.expect_with :rspec do |expectations|
11
+ # This option will default to `true` in RSpec 4. It makes the `description`
12
+ # and `failure_message` of custom matchers include text for helper methods
13
+ # defined using `chain`, e.g.:
14
+ # be_bigger_than(2).and_smaller_than(4).description
15
+ # # => "be bigger than 2 and smaller than 4"
16
+ # ...rather than:
17
+ # # => "be bigger than 2"
18
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
19
+ end
7
20
 
8
- end
21
+ # rspec-mocks config goes here. You can use an alternate test double
22
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
23
+ config.mock_with :rspec do |mocks|
24
+ # Prevents you from mocking or stubbing a method that does not exist on
25
+ # a real object. This is generally recommended, and will default to
26
+ # `true` in RSpec 4.
27
+ mocks.verify_partial_doubles = true
28
+ end
29
+
30
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
31
+ # have no way to turn it off -- the option exists only for backwards
32
+ # compatibility in RSpec 3). It causes shared context metadata to be
33
+ # inherited by the metadata hash of host groups and examples, rather than
34
+ # triggering implicit auto-inclusion in groups with matching metadata.
35
+ config.shared_context_metadata_behavior = :apply_to_host_groups
36
+
37
+ # The settings below are suggested to provide a good initial experience
38
+ # with RSpec, but feel free to customize to your heart's content.
39
+
40
+ # This allows you to limit a spec run to individual examples or groups
41
+ # you care about by tagging them with `:focus` metadata. When nothing
42
+ # is tagged with `:focus`, all examples get run. RSpec also provides
43
+ # aliases for `it`, `describe`, and `context` that include `:focus`
44
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
45
+ config.filter_run_when_matching :focus
46
+
47
+ # Allows RSpec to persist some state between runs in order to support
48
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
49
+ # you configure your source control system to ignore this file.
50
+ config.example_status_persistence_file_path = 'spec/examples.txt'
51
+
52
+ # Limits the available syntax to the non-monkey patched syntax that is
53
+ # recommended. For more details, see:
54
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
55
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
56
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
57
+ config.disable_monkey_patching!
58
+
59
+ # This setting enables warnings. It's recommended, but in some cases may
60
+ # be too noisy due to issues in dependencies.
61
+ config.warnings = true
62
+
63
+ # Many RSpec users commonly either run the entire suite or an individual
64
+ # file, and it's useful to allow more verbose output when running an
65
+ # individual spec file.
66
+ if config.files_to_run.one?
67
+ # Use the documentation formatter for detailed output,
68
+ # unless a formatter has already been configured
69
+ # (e.g. via a command-line flag).
70
+ config.default_formatter = 'doc'
71
+ end
72
+
73
+ # Print the 10 slowest examples and example groups at the
74
+ # end of the spec run, to help surface which specs are running
75
+ # particularly slow.
76
+ config.profile_examples = 10
77
+
78
+ # Run specs in random order to surface order dependencies. If you find an
79
+ # order dependency and want to debug it, you can fix the order by providing
80
+ # the seed, which is printed after each run.
81
+ # --seed 1234
82
+ config.order = :random
83
+
84
+ # Seed global randomization in this process using the `--seed` CLI option.
85
+ # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # test failures related to randomization by passing the same `--seed` value
87
+ # as the one that triggered the failure.
88
+ Kernel.srand config.seed
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Latter
@@ -29,7 +29,7 @@ authors:
29
29
  autorequire:
30
30
  bindir: bin
31
31
  cert_chain: []
32
- date: 2016-08-19 00:00:00.000000000 Z
32
+ date: 2016-09-30 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: builder
@@ -45,6 +45,20 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.1.2
48
+ - !ruby/object:Gem::Dependency
49
+ name: faraday
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: activesupport
50
64
  requirement: !ruby/object:Gem::Requirement
@@ -138,6 +152,7 @@ extensions: []
138
152
  extra_rdoc_files: []
139
153
  files:
140
154
  - ".gitignore"
155
+ - ".rspec"
141
156
  - ".travis.yml"
142
157
  - CHANGES.txt
143
158
  - Gemfile
@@ -147,17 +162,18 @@ files:
147
162
  - lib/rsolr.rb
148
163
  - lib/rsolr/char.rb
149
164
  - lib/rsolr/client.rb
150
- - lib/rsolr/connection.rb
165
+ - lib/rsolr/document.rb
151
166
  - lib/rsolr/error.rb
167
+ - lib/rsolr/json.rb
152
168
  - lib/rsolr/response.rb
153
169
  - lib/rsolr/uri.rb
154
170
  - lib/rsolr/version.rb
155
171
  - lib/rsolr/xml.rb
156
172
  - rsolr.gemspec
157
- - spec/api/char_spec.rb
158
173
  - spec/api/client_spec.rb
159
- - spec/api/connection_spec.rb
174
+ - spec/api/document_spec.rb
160
175
  - spec/api/error_spec.rb
176
+ - spec/api/json_spec.rb
161
177
  - spec/api/pagination_spec.rb
162
178
  - spec/api/rsolr_spec.rb
163
179
  - spec/api/uri_spec.rb
@@ -172,9 +188,6 @@ files:
172
188
  - spec/fixtures/basic_configs/synonyms.txt
173
189
  - spec/integration/solr5_spec.rb
174
190
  - spec/spec_helper.rb
175
- - tasks/rdoc.rake
176
- - tasks/rsolr.rake
177
- - tasks/spec.rake
178
191
  homepage: https://github.com/rsolr/rsolr
179
192
  licenses:
180
193
  - Apache-2.0
@@ -190,9 +203,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
203
  version: 1.9.3
191
204
  required_rubygems_version: !ruby/object:Gem::Requirement
192
205
  requirements:
193
- - - ">="
206
+ - - ">"
194
207
  - !ruby/object:Gem::Version
195
- version: '0'
208
+ version: 1.3.1
196
209
  requirements: []
197
210
  rubyforge_project: rsolr
198
211
  rubygems_version: 2.5.1
@@ -1,74 +0,0 @@
1
- require 'net/http'
2
- require 'net/https'
3
-
4
- # The default/Net::Http adapter for RSolr.
5
- class RSolr::Connection
6
-
7
- # using the request_context hash,
8
- # send a request,
9
- # then return the standard rsolr response hash {:status, :body, :headers}
10
- def execute client, request_context
11
- h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout]
12
- request = setup_raw_request request_context
13
- request.body = request_context[:data] if request_context[:method] == :post and request_context[:data]
14
- begin
15
- response = h.request request
16
- charset = response.type_params["charset"]
17
- {:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)}
18
- rescue Errno::ECONNREFUSED
19
- raise RSolr::Error::ConnectionRefused, request_context.inspect
20
- # catch the undefined closed? exception -- this is a confirmed ruby bug
21
- rescue NoMethodError => e
22
- e.message == "undefined method `closed?' for nil:NilClass" ?
23
- raise(RSolr::Error::ConnectionRefused, request_context.inspect) :
24
- raise(e)
25
- end
26
- end
27
-
28
- protected
29
-
30
- # This returns a singleton of a Net::HTTP or Net::HTTP.Proxy request object.
31
- def http uri, proxy = nil, read_timeout = nil, open_timeout = nil
32
- http = if proxy
33
- proxy_user, proxy_pass = proxy.userinfo.split(/:/) if proxy.userinfo
34
- Net::HTTP.Proxy(proxy.host, proxy.port, proxy_user, proxy_pass).new uri.host, uri.port
35
- elsif proxy == false
36
- # If explicitly passing in false, make sure we set proxy_addr to nil
37
- # to tell Net::HTTP to *not* use the environment proxy variables.
38
- Net::HTTP.new uri.host, uri.port, nil
39
- else
40
- Net::HTTP.new uri.host, uri.port
41
- end
42
- http.use_ssl = uri.port == 443 || uri.instance_of?(URI::HTTPS)
43
- http.read_timeout = read_timeout if read_timeout
44
- http.open_timeout = open_timeout if open_timeout
45
- http
46
- end
47
-
48
- #
49
- def setup_raw_request request_context
50
- http_method = case request_context[:method]
51
- when :get
52
- Net::HTTP::Get
53
- when :post
54
- Net::HTTP::Post
55
- when :head
56
- Net::HTTP::Head
57
- else
58
- raise "Only :get, :post and :head http method types are allowed."
59
- end
60
- headers = request_context[:headers] || {}
61
- raw_request = http_method.new request_context[:uri].request_uri
62
- raw_request.initialize_http_header headers
63
- raw_request.basic_auth(request_context[:uri].user, request_context[:uri].password) if request_context[:uri].user && request_context[:uri].password
64
- raw_request
65
- end
66
-
67
- private
68
-
69
- def force_charset body, charset
70
- return body unless charset and body.respond_to?(:force_encoding)
71
- body.force_encoding(charset)
72
- end
73
-
74
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
- # @deprecated remove this module's specs when we remove the method (duh)
3
- describe "RSolr::Char" do
4
-
5
- let(:char){Object.new.extend RSolr::Char}
6
-
7
- # deprecated as of 2015-02, as it is incorrect Solr escaping.
8
- # instead, use RSolr.solr_escape
9
- # commented out as it gives a mess of deprecation warnings
10
- =begin
11
- it 'should escape everything that is not a word with \\' do
12
- (0..255).each do |ascii|
13
- chr = ascii.chr
14
- esc = char.escape(chr)
15
- if chr =~ /\W/
16
- expect(esc.to_s).to eq("\\#{chr}")
17
- else
18
- expect(esc.to_s).to eq(chr)
19
- end
20
- end
21
- end
22
- =end
23
- end
@@ -1,140 +0,0 @@
1
- require 'spec_helper'
2
- require 'base64'
3
-
4
- describe "RSolr::Connection" do
5
-
6
- context "setup_raw_request" do
7
- it "should set the correct request parameters" do
8
- c = RSolr::Connection.new
9
- base_url = "http://localhost:8983/solr"
10
- client = RSolr::Client.new c, :url => base_url
11
- req = c.send :setup_raw_request, {:headers => {"content-type" => "text/xml"}, :method => :get, :uri => URI.parse(base_url + "/select?q=*:*")}
12
- expect(req.path).to eq("/solr/select?q=*:*")
13
- headers = {}
14
- req.each_header{|k,v| headers[k] = v}
15
- expect(headers).to eq({"content-type"=>"text/xml"})
16
- end
17
- end
18
-
19
- context "when the connection is refused" do
20
- subject { RSolr::Connection.new }
21
-
22
- it "raises a custom exception" do
23
- http_stub = double("Net:HTTP")
24
- allow(http_stub).to receive(:request).and_raise(Errno::ECONNREFUSED)
25
-
26
- allow(subject).to receive(:setup_raw_request) { http_stub }
27
- allow(subject).to receive(:http) { Net::HTTP.new("localhost", 80) }
28
-
29
- expect { subject.execute(nil, {}) }.to raise_error(RSolr::Error::ConnectionRefused)
30
- end
31
- end
32
-
33
- context "read timeout configuration" do
34
- let(:client) { double.as_null_object }
35
-
36
- let(:http) { double(Net::HTTP).as_null_object }
37
-
38
- subject { RSolr::Connection.new }
39
-
40
- before do
41
- allow(Net::HTTP).to receive(:new) { http }
42
- end
43
-
44
- it "should configure Net:HTTP read_timeout" do
45
- expect(http).to receive(:read_timeout=).with(42)
46
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :read_timeout => 42}
47
- end
48
-
49
- it "should use Net:HTTP default read_timeout if not specified" do
50
- expect(http).not_to receive(:read_timeout=)
51
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
52
- end
53
- end
54
-
55
- context "open timeout configuration" do
56
- let(:client) { double.as_null_object }
57
-
58
- let(:http) { double(Net::HTTP).as_null_object }
59
-
60
- subject { RSolr::Connection.new }
61
-
62
- before do
63
- allow(Net::HTTP).to receive(:new) { http }
64
- end
65
-
66
- it "should configure Net:HTTP open_timeout" do
67
- expect(http).to receive(:open_timeout=).with(42)
68
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
69
- end
70
-
71
- it "should use Net:HTTP default open_timeout if not specified" do
72
- expect(http).not_to receive(:open_timeout=)
73
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
74
- end
75
- end
76
-
77
- context "proxy configuration" do
78
- let(:client) { double.as_null_object }
79
-
80
- let(:http) { double(Net::HTTP).as_null_object }
81
-
82
- let(:uri) { URI.parse("http://localhost/some_url") }
83
- let(:proxy) { URI.parse("http://my.proxy/") }
84
-
85
- subject { RSolr::Connection.new }
86
-
87
- it "should use the default if no proxy is provided" do
88
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port) { http }
89
- subject.execute client, { :uri => uri, :method => :get }
90
- end
91
-
92
- it "should use the proxy if one is provided" do
93
- expect(Net::HTTP).to receive(:Proxy).with(proxy.host, proxy.port, nil, nil) { http }
94
- subject.execute client, { :uri => uri, :proxy => proxy, :method => :get }
95
- end
96
-
97
- it "should not use a proxy if proxy setting is false" do
98
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, nil) { http }
99
- subject.execute client, { :uri => uri, :proxy => false, :method => :get }
100
- end
101
- end
102
-
103
- context "connection refused" do
104
- let(:client) { double.as_null_object }
105
-
106
- let(:http) { double(Net::HTTP).as_null_object }
107
- let(:request_context) {
108
- {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
109
- }
110
- subject { RSolr::Connection.new }
111
-
112
- before do
113
- allow(Net::HTTP).to receive(:new) { http }
114
- end
115
-
116
- it "should configure Net:HTTP open_timeout" do
117
- skip "doesn't work with ruby 1.8" if RUBY_VERSION < "1.9"
118
- expect(http).to receive(:request).and_raise(Errno::ECONNREFUSED)
119
- expect {
120
- subject.execute client, request_context
121
- }.to raise_error(Errno::ECONNREFUSED, /#{request_context}/)
122
- end
123
- end
124
-
125
- describe "basic auth support" do
126
- let(:http) { double(Net::HTTP).as_null_object }
127
-
128
- before do
129
- allow(Net::HTTP).to receive(:new) { http }
130
- end
131
-
132
- it "sets the authorization header" do
133
- expect(http).to receive(:request) do |request|
134
- expect(request.fetch('authorization')).to eq("Basic #{Base64.encode64("joe:pass")}".strip)
135
- double(Net::HTTPResponse).as_null_object
136
- end
137
- RSolr::Connection.new.execute nil, :uri => URI.parse("http://joe:pass@localhost:8983/solr"), :method => :get
138
- end
139
- end
140
- end