activeresource-persistent 0.1.0 → 0.2.0

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/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ Gemfile_*.lock
7
8
  InstalledFiles
8
9
  _yardoc
9
10
  coverage
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'activeresource', '2.3.10'
6
+ gem 'net-http-persistent', '2.6'
7
+
8
+ group :test do
9
+ gem 'rspec', '2.8.0'
10
+ gem 'sinatra', '1.3.2'
11
+ gem 'multi_json', '1.3.2'
12
+ gem 'posix-spawn', '0.3.6'
13
+ end
14
+
15
+ group :bundle do
16
+ gem 'passenger', '3.0.12'
17
+ end
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'activeresource', '3.0.10'
6
+ gem 'net-http-persistent', '2.6'
7
+
8
+ group :test do
9
+ gem 'rspec', '2.8.0'
10
+ gem 'sinatra', '1.3.2'
11
+ gem 'multi_json', '1.3.2'
12
+ gem 'posix-spawn', '0.3.6'
13
+ end
14
+
15
+ group :bundle do
16
+ gem 'passenger', '3.0.12'
17
+ end
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'activeresource', '3.1.4'
6
+ gem 'net-http-persistent', '2.6'
7
+
8
+ group :test do
9
+ gem 'rspec', '2.8.0'
10
+ gem 'sinatra', '1.3.2'
11
+ gem 'multi_json', '1.3.2'
12
+ gem 'posix-spawn', '0.3.6'
13
+ end
14
+
15
+ group :bundle do
16
+ gem 'passenger', '3.0.12'
17
+ end
@@ -8,6 +8,7 @@ gem 'net-http-persistent', '2.6'
8
8
  group :test do
9
9
  gem 'rspec', '2.8.0'
10
10
  gem 'sinatra', '1.3.2'
11
+ gem 'multi_json', '1.3.2'
11
12
  gem 'posix-spawn', '0.3.6'
12
13
  end
13
14
 
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'activeresource', '3.2.9'
6
+ gem 'net-http-persistent', '2.8'
7
+
8
+ group :test do
9
+ gem 'rspec', '2.12.0'
10
+ gem 'sinatra', '1.3.2'
11
+ gem 'multi_json', '1.3.2'
12
+ gem 'posix-spawn', '0.3.6'
13
+ end
14
+
15
+ group :bundle do
16
+ gem 'passenger', '3.0.18'
17
+ end
data/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  HTTP persistent connection support for ActiveResource.
4
4
 
5
+ Tested with ActiveResource:
6
+
7
+ * v2.3.10
8
+ * v3.0.10
9
+ * v3.1.4
10
+ * v3.2.3
11
+ * v3.2.9
12
+
5
13
  ## Installation
6
14
 
7
15
  Add this line to your application's Gemfile:
@@ -22,6 +30,44 @@ Works out of box after adding:
22
30
 
23
31
  require 'active_resource/persistent'
24
32
 
33
+ ## SSL Support
34
+
35
+ Supported ActiveResource ssl options:
36
+
37
+ * ca_file
38
+ * cert
39
+ * cert_store
40
+ * key
41
+ * verify_mode
42
+ * verify_callback
43
+
44
+ Unsupported ActiveResource ssl options:
45
+
46
+ * ca_path
47
+ * ssl_timeout
48
+ * verify_depth
49
+
50
+ ## Testing
51
+
52
+ Currently we use passenger server because it provides REMOTE_PORT enviroment variable.
53
+ Thus we can ensure that connections are persistent.
54
+
55
+ Before start suite ensure that passenger gem are installed correctly.
56
+
57
+ $ BUNDLE_GEMFILE=Gemfile_3.2.9 bundle
58
+ $ BUNDLE_GEMFILE=Gemfile_3.2.9 bundle exec passenger start
59
+
60
+ Run tests with:
61
+
62
+ $ BUNDLE_GEMFILE=Gemfile_3.2.9 bundle
63
+ $ BUNDLE_GEMFILE=Gemfile_3.2.9 bundle exec rspec -fs -c spec
64
+
65
+ $ rake test:gemfile_2.3.10 # Testing with Gemfile_2.3.10
66
+ $ rake test:gemfile_3.0.10 # Testing with Gemfile_3.0.10
67
+ $ rake test:gemfile_3.1.4 # Testing with Gemfile_3.1.4
68
+ $ rake test:gemfile_3.2.3 # Testing with Gemfile_3.2.3
69
+ $ rake test:gemfile_3.2.9 # Testing with Gemfile_3.2.9
70
+
25
71
  ## References
26
72
 
27
73
  * [activeresource](https://github.com/rails/activeresource)
data/Rakefile CHANGED
@@ -1,2 +1,27 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ gemfiles = Dir['Gemfile_*'].reject { |filename| filename =~ /\.lock$/ }
5
+
6
+ namespace :test do
7
+ gemfile_tasks = []
8
+
9
+ gemfiles.each do |gemfile|
10
+ gemfile_task_name = gemfile.downcase.gsub('.', '_').to_sym
11
+ gemfile_tasks << gemfile_task_name
12
+ desc "Testing with #{gemfile}"
13
+ task gemfile_task_name do
14
+ puts "Testing with #{gemfile}"
15
+
16
+ ENV['BUNDLE_GEMFILE'] = gemfile
17
+
18
+ system "bundle install --quiet"
19
+ system "bundle exec rspec -c spec"
20
+ end
21
+ end
22
+
23
+ desc "Testing using all gemfiles"
24
+ task :all => gemfile_tasks
25
+ end
26
+
27
+ task :default => 'test:all'
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
12
  gem.name = "activeresource-persistent"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "0.1.0"
14
+ gem.version = "0.2.0"
15
15
 
16
16
  gem.add_runtime_dependency 'net-http-persistent', '>=2.5'
17
17
  gem.add_runtime_dependency 'activeresource', '>=2.3.0'
@@ -36,6 +36,17 @@ module ActiveResource
36
36
  req = Net::HTTP::Head.new(path, headers)
37
37
  request(@site, req)
38
38
  end
39
+
40
+ ##
41
+ # SSL support
42
+ #
43
+
44
+ def use_ssl=(value)
45
+ expected_scheme = value ? 'https' : 'http'
46
+ site.scheme == expected_scheme or
47
+ raise ArgumentError, "Site scheme should be #{expected_scheme.inspect}"
48
+ end
49
+
39
50
  end
40
51
  end
41
52
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe ActiveResource::Connection do
4
4
  let(:site) { TestServer.uri }
5
5
 
6
- let(:instance) { described_class.new(site) }
6
+ let(:instance) { described_class.new(site, ActiveResource::Formats[:json]) }
7
7
 
8
8
  describe "#http" do
9
9
  subject { instance.send(:http) }
@@ -30,7 +30,7 @@ describe ActiveResource::Connection do
30
30
  let(:body) { 'HELLO WORLD' }
31
31
  let(:headers) { { 'X_Header' => 'x_value' } }
32
32
  let(:http_mock) { mock('HTTP MOCK') }
33
- let(:response_mock) { mock('RESPONSE MOCK', :code => '200') }
33
+ let(:response_mock) { mock('RESPONSE MOCK', :code => '200', :body => '') }
34
34
 
35
35
  describe "#head" do
36
36
  it "should use ActiveResource::Persistent::HTTP#head" do
@@ -38,8 +38,14 @@ describe %q(
38
38
  end
39
39
 
40
40
  it "Updating different resources from the same site" do
41
- user = TestUser.find("101").update_attribute(:username, "jack")
42
- post = TestPost.find("202").update_attribute(:title, "hi")
41
+ user = TestUser.find("101")
42
+ post = TestPost.find("202")
43
+
44
+ user.username = "jack"
45
+ post.title = "hi"
46
+
47
+ user.save
48
+ post.save
43
49
 
44
50
  TestHelper.logged_requests.size.should == 4
45
51
  TestHelper.persistent_requests_logged?.should be_true
@@ -66,7 +66,7 @@ describe ActiveResource::Persistent::HTTP do
66
66
  @response.should be_instance_of(Net::HTTPOK)
67
67
 
68
68
  body = YAML.load(@response.body)
69
-
69
+
70
70
  body['REQUEST_METHOD'].should == request_method
71
71
  body['REQUEST_URI'].should == path
72
72
  body['HTTP_X_AUTHORIZATION'].should == 'qwerty'
@@ -74,4 +74,66 @@ describe ActiveResource::Persistent::HTTP do
74
74
  end
75
75
 
76
76
  end
77
+
78
+
79
+
80
+ context "ActiveResource ssl options support" do
81
+ let(:site) { URI.parse("https://127.0.0.1:2000") }
82
+ let(:instance) { described_class.new(site, nil) }
83
+
84
+ it "should support use_ssl for https scheme" do
85
+ instance = described_class.new(URI.parse("https://127.0.0.1:2000"), nil)
86
+ expect { instance.use_ssl = true }.to_not raise_error {ArgumentError}
87
+ end
88
+
89
+ it "should NOT support use_ssl for http scheme" do
90
+ instance = described_class.new(URI.parse("http://127.0.0.1:2000"), nil)
91
+ expect { instance.use_ssl = true }.to raise_error {ArgumentError}
92
+ end
93
+
94
+ it "should support verify_mode option" do
95
+ instance.verify_mode.should_not == OpenSSL::SSL::VERIFY_NONE
96
+ instance.verify_mode = OpenSSL::SSL::VERIFY_NONE
97
+ instance.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
98
+ end
99
+
100
+ it "should support verify_callback option" do
101
+ instance.verify_callback = "call_me_back"
102
+ instance.verify_callback.should == "call_me_back"
103
+ end
104
+
105
+
106
+ it "should support ca_file option" do
107
+ instance.ca_file = "/tmp/ca.crt"
108
+ instance.ca_file.should == "/tmp/ca.crt"
109
+ end
110
+
111
+ it "should support cert option" do
112
+ instance.cert = "/tmp/some.crt"
113
+ instance.cert.should == "/tmp/some.crt"
114
+ end
115
+
116
+ it "should support key option" do
117
+ instance.key = "/tmp/some.key"
118
+ instance.key.should == "/tmp/some.key"
119
+ end
120
+
121
+ it "should support cert_store option" do
122
+ instance.cert_store = "/tmp/some_cert_store"
123
+ instance.cert_store.should == "/tmp/some_cert_store"
124
+ end
125
+
126
+ it "should NOT support verify_depth option" do
127
+ expect { instance.verify_depth = 5 }.to raise_error { NoMethodError}
128
+ end
129
+
130
+ it "should NOT support ca_path option" do
131
+ expect { instance.ca_path = "/tmp/ca_path" }.to raise_error { NoMethodError }
132
+ end
133
+
134
+ it "should NOT support ssl_timeout option" do
135
+ expect { instance.ssl_timeout = 10 }.to raise_error { NoMethodError }
136
+ end
137
+ end
138
+
77
139
  end
@@ -2,8 +2,10 @@ require 'active_resource'
2
2
 
3
3
  class TestUser < ActiveResource::Base
4
4
  self.element_name = 'user'
5
+ self.format = :json
5
6
  end
6
7
 
7
8
  class TestPost < ActiveResource::Base
8
9
  self.element_name = 'post'
10
+ self.format = :json
9
11
  end
@@ -22,7 +22,7 @@ module TestServer
22
22
 
23
23
  def start
24
24
  @pid = POSIX::Spawn.spawn("passenger start --port #{port}", :out => 'test_server.output')
25
- sleep(1)
25
+ sleep(5)
26
26
  end
27
27
 
28
28
  def stop
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource-persistent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-http-persistent
16
- requirement: &16473480 !ruby/object:Gem::Requirement
16
+ requirement: &9169140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16473480
24
+ version_requirements: *9169140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activeresource
27
- requirement: &16472560 !ruby/object:Gem::Requirement
27
+ requirement: &9184980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.3.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16472560
35
+ version_requirements: *9184980
36
36
  description: HTTP persistent connection support for ActiveResource
37
37
  email:
38
38
  - andriy.yanko@gmail.com
@@ -41,7 +41,11 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
  files:
43
43
  - .gitignore
44
- - Gemfile
44
+ - Gemfile_2.3.10
45
+ - Gemfile_3.0.10
46
+ - Gemfile_3.1.4
47
+ - Gemfile_3.2.3
48
+ - Gemfile_3.2.9
45
49
  - LICENSE
46
50
  - README.md
47
51
  - Rakefile
@@ -80,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
84
  version: '0'
81
85
  requirements: []
82
86
  rubyforge_project:
83
- rubygems_version: 1.8.10
87
+ rubygems_version: 1.8.15
84
88
  signing_key:
85
89
  specification_version: 3
86
90
  summary: HTTP persistent connection support for ActiveResource
@@ -94,4 +98,3 @@ test_files:
94
98
  - spec/support/test_ipc.rb
95
99
  - spec/support/test_resources.rb
96
100
  - spec/support/test_server.rb
97
- has_rdoc: