rsolr 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,3 +1,5 @@
1
+ 1.0.8
2
+ - Fix connection refused errors in specs + add basic auth support (Denis Goeury)
1
3
  1.0.7
2
4
  - Response body encoding is set to response charset in Ruby >= 1.9
3
5
  - Ability to set :read_timeout and :open_timeout when creating new instance of RSolr
@@ -47,8 +47,6 @@ class RSolr::Connection
47
47
  when :get
48
48
  Net::HTTP::Get
49
49
  when :post
50
- #require 'net/http/post/multipart'
51
- #File === request_context[:data] ? Net::HTTP::Post::Multipart : Net::HTTP::Post
52
50
  Net::HTTP::Post
53
51
  when :head
54
52
  Net::HTTP::Head
@@ -56,17 +54,9 @@ class RSolr::Connection
56
54
  raise "Only :get, :post and :head http method types are allowed."
57
55
  end
58
56
  headers = request_context[:headers] || {}
59
- # if http_method.to_s == "Net::HTTP::Post::Multipart"
60
- # io = request_context[:data]
61
- # UploadIO.convert! io, request_context[:headers]["Content-Type"], io.path, io.path
62
- # raw_request =
63
- # Net::HTTP::Post::Multipart.new(
64
- # request_context[:path],
65
- # :file => io)
66
- # else
67
- raw_request = http_method.new request_context[:uri].request_uri
68
- # end
57
+ raw_request = http_method.new request_context[:uri].request_uri
69
58
  raw_request.initialize_http_header headers
59
+ raw_request.basic_auth(request_context[:uri].user, request_context[:uri].password) if request_context[:uri].user && request_context[:uri].password
70
60
  raw_request
71
61
  end
72
62
 
@@ -77,4 +67,4 @@ class RSolr::Connection
77
67
  body.force_encoding(charset)
78
68
  end
79
69
 
80
- end
70
+ end
data/lib/rsolr.rb CHANGED
@@ -6,7 +6,7 @@ module RSolr
6
6
 
7
7
  %W(Response Char Client Error Connection Uri Xml).each{|n|autoload n.to_sym, "rsolr/#{n.downcase}"}
8
8
 
9
- def self.version; "1.0.7" end
9
+ def self.version; "1.0.8" end
10
10
 
11
11
  VERSION = self.version
12
12
 
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'base64'
3
+
2
4
  describe "RSolr::Connection" do
3
5
 
4
6
  context "setup_raw_request" do
@@ -15,37 +17,60 @@ describe "RSolr::Connection" do
15
17
  context "read timeout configuration" do
16
18
  let(:client) { mock.as_null_object }
17
19
 
20
+ let(:http) { mock(Net::HTTP).as_null_object }
21
+
18
22
  subject { RSolr::Connection.new }
19
23
 
24
+ before do
25
+ Net::HTTP.stub(:new) { http }
26
+ end
27
+
20
28
  it "should configure Net:HTTP read_timeout" do
29
+ http.should_receive(:read_timeout=).with(42)
21
30
  subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :read_timeout => 42}
22
- http = subject.instance_variable_get(:@http)
23
- http.read_timeout.should == 42
24
31
  end
25
32
 
26
33
  it "should use Net:HTTP default read_timeout if not specified" do
34
+ http.should_not_receive(:read_timeout=)
27
35
  subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
28
- http = subject.instance_variable_get(:@http)
29
- http.read_timeout.should == 60
30
36
  end
31
37
  end
32
38
 
33
39
  context "open timeout configuration" do
34
40
  let(:client) { mock.as_null_object }
35
41
 
42
+ let(:http) { mock(Net::HTTP).as_null_object }
43
+
36
44
  subject { RSolr::Connection.new }
37
45
 
46
+ before do
47
+ Net::HTTP.stub(:new) { http }
48
+ end
49
+
38
50
  it "should configure Net:HTTP open_timeout" do
51
+ http.should_receive(:open_timeout=).with(42)
39
52
  subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
40
- http = subject.instance_variable_get(:@http)
41
- http.open_timeout.should == 42
42
53
  end
43
54
 
44
55
  it "should use Net:HTTP default open_timeout if not specified" do
56
+ http.should_not_receive(:open_timeout=)
45
57
  subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
46
- http = subject.instance_variable_get(:@http)
47
- http.open_timeout.should == nil
48
58
  end
49
59
  end
50
60
 
61
+ describe "basic auth support" do
62
+ let(:http) { mock(Net::HTTP).as_null_object }
63
+
64
+ before do
65
+ Net::HTTP.stub(:new) { http }
66
+ end
67
+
68
+ it "sets the authorization header" do
69
+ http.should_receive(:request) do |request|
70
+ request.fetch('authorization').should == "Basic #{Base64.encode64("joe:pass")}".strip
71
+ mock(Net::HTTPResponse).as_null_object
72
+ end
73
+ RSolr::Connection.new.execute nil, :uri => URI.parse("http://joe:pass@localhost:8983/solr"), :method => :get
74
+ end
75
+ end
51
76
  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.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -29,11 +29,11 @@ authors:
29
29
  autorequire:
30
30
  bindir: bin
31
31
  cert_chain: []
32
- date: 2012-02-12 00:00:00.000000000Z
32
+ date: 2012-04-22 00:00:00.000000000Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: builder
36
- requirement: &70108731684080 !ruby/object:Gem::Requirement
36
+ requirement: &70327300845420 !ruby/object:Gem::Requirement
37
37
  none: false
38
38
  requirements:
39
39
  - - ! '>='
@@ -41,10 +41,10 @@ dependencies:
41
41
  version: 2.1.2
42
42
  type: :runtime
43
43
  prerelease: false
44
- version_requirements: *70108731684080
44
+ version_requirements: *70327300845420
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: rake
47
- requirement: &70108731667240 !ruby/object:Gem::Requirement
47
+ requirement: &70327300844920 !ruby/object:Gem::Requirement
48
48
  none: false
49
49
  requirements:
50
50
  - - ~>
@@ -52,10 +52,10 @@ dependencies:
52
52
  version: 0.9.2
53
53
  type: :development
54
54
  prerelease: false
55
- version_requirements: *70108731667240
55
+ version_requirements: *70327300844920
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rdoc
58
- requirement: &70108731666080 !ruby/object:Gem::Requirement
58
+ requirement: &70327300844460 !ruby/object:Gem::Requirement
59
59
  none: false
60
60
  requirements:
61
61
  - - ~>
@@ -63,10 +63,10 @@ dependencies:
63
63
  version: 3.9.4
64
64
  type: :development
65
65
  prerelease: false
66
- version_requirements: *70108731666080
66
+ version_requirements: *70327300844460
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rspec
69
- requirement: &70108731665120 !ruby/object:Gem::Requirement
69
+ requirement: &70327300844000 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
72
72
  - - ~>
@@ -74,7 +74,7 @@ dependencies:
74
74
  version: 2.6.0
75
75
  type: :development
76
76
  prerelease: false
77
- version_requirements: *70108731665120
77
+ version_requirements: *70327300844000
78
78
  description: RSolr aims to provide a simple and extensible library for working with
79
79
  Solr
80
80
  email:
@@ -123,18 +123,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
- segments:
127
- - 0
128
- hash: -700646824116965374
129
126
  required_rubygems_version: !ruby/object:Gem::Requirement
130
127
  none: false
131
128
  requirements:
132
129
  - - ! '>='
133
130
  - !ruby/object:Gem::Version
134
131
  version: '0'
135
- segments:
136
- - 0
137
- hash: -700646824116965374
138
132
  requirements: []
139
133
  rubyforge_project: rsolr
140
134
  rubygems_version: 1.8.11