sunstone 6.0.0.5 → 6.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/active_record/associations.rb +2 -2
- data/ext/active_record/attribute_methods.rb +2 -2
- data/ext/active_record/callbacks.rb +1 -1
- data/ext/active_record/finder_methods.rb +42 -36
- data/ext/active_record/persistence.rb +2 -0
- data/ext/active_record/relation/calculations.rb +2 -2
- data/ext/active_record/statement_cache.rb +9 -5
- data/ext/active_record/transactions.rb +8 -15
- data/ext/arel/attributes/empty_relation.rb +31 -31
- data/ext/arel/nodes/select_statement.rb +1 -1
- data/lib/active_record/connection_adapters/sunstone/column.rb +3 -3
- data/lib/active_record/connection_adapters/sunstone/database_statements.rb +5 -5
- data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +18 -8
- data/lib/active_record/connection_adapters/sunstone/type/binary.rb +34 -0
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +39 -26
- data/lib/arel/visitors/sunstone.rb +13 -15
- data/lib/sunstone.rb +16 -2
- data/lib/sunstone/connection.rb +1 -1
- data/lib/sunstone/version.rb +1 -1
- metadata +40 -64
- data/.gitignore +0 -31
- data/.tm_properties +0 -1
- data/.travis.yml +0 -49
- data/Gemfile +0 -4
- data/README.md +0 -10
- data/Rakefile +0 -37
- data/TODO.md +0 -89
- data/ext/arel/attributes/relation.rb +0 -31
- data/sunstone.gemspec +0 -39
- data/test/active_record/associations/belongs_to_test.rb +0 -162
- data/test/active_record/associations/has_and_belongs_to_many_test.rb +0 -125
- data/test/active_record/associations/has_many_test.rb +0 -244
- data/test/active_record/eager_loading_test.rb +0 -62
- data/test/active_record/persistance_test.rb +0 -159
- data/test/active_record/preload_test.rb +0 -51
- data/test/active_record/query/all_test.rb +0 -33
- data/test/active_record/query/count_test.rb +0 -51
- data/test/active_record/query/distinct_test.rb +0 -30
- data/test/active_record/query/find_test.rb +0 -37
- data/test/active_record/query/limit_test.rb +0 -19
- data/test/active_record/query/order_test.rb +0 -27
- data/test/active_record/query/where_test.rb +0 -79
- data/test/active_record/query_test.rb +0 -123
- data/test/active_record/rpc_test.rb +0 -30
- data/test/schema_mock.rb +0 -117
- data/test/sunstone/connection/configuration_test.rb +0 -44
- data/test/sunstone/connection/cookie_store_test.rb +0 -37
- data/test/sunstone/connection/request_helper_test.rb +0 -105
- data/test/sunstone/connection/send_request_test.rb +0 -164
- data/test/sunstone/connection_test.rb +0 -23
- data/test/test_helper.rb +0 -152
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ActiveRecord::RPCTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
schema do
|
6
|
-
create_table "ships", limit: 100 do |t|
|
7
|
-
t.string "name", limit: 255
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Ship < ActiveRecord::Base
|
12
|
-
rpc :self_destruct
|
13
|
-
end
|
14
|
-
|
15
|
-
test '::rpc calls custom controller function' do
|
16
|
-
webmock(:get, "/ships", { limit: 1, order: [{id: :asc}] }).to_return({
|
17
|
-
body: [{id: 3, name: 'Sivar'}].to_json
|
18
|
-
})
|
19
|
-
|
20
|
-
webmock(:post, '/ships/3/self_destruct').to_return({
|
21
|
-
body: {name: 'DESTROYED'}.to_json
|
22
|
-
})
|
23
|
-
|
24
|
-
ship = Ship.first
|
25
|
-
assert ship.self_destruct!
|
26
|
-
assert_equal 'DESTROYED', ship.name
|
27
|
-
assert ship.changes.empty?
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/schema_mock.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
class ActiveSupport::TestCase
|
2
|
-
class Schema
|
3
|
-
|
4
|
-
class Table
|
5
|
-
|
6
|
-
class Column
|
7
|
-
|
8
|
-
def initialize(name, type, options={})
|
9
|
-
@name = name
|
10
|
-
@type = type
|
11
|
-
@options = options
|
12
|
-
end
|
13
|
-
|
14
|
-
def as_json
|
15
|
-
{type: @type, primary_key: false, null: true, array: false}.merge(@options)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
attr_accessor :name, :options, :columns
|
20
|
-
|
21
|
-
def initialize(name, options={}, &block)
|
22
|
-
@name = name
|
23
|
-
@options = options
|
24
|
-
@columns = {}
|
25
|
-
case options[:id]
|
26
|
-
when false
|
27
|
-
else
|
28
|
-
integer('id', primary_key: true, null: false)
|
29
|
-
end
|
30
|
-
|
31
|
-
block.call(self)
|
32
|
-
end
|
33
|
-
|
34
|
-
def string(name, options={})
|
35
|
-
@columns[name] = Column.new(name, :string, options)
|
36
|
-
end
|
37
|
-
|
38
|
-
def datetime(name, options={})
|
39
|
-
@columns[name] = Column.new(name, :datetime, options)
|
40
|
-
end
|
41
|
-
|
42
|
-
def integer(name, options={})
|
43
|
-
@columns[name] = Column.new(name, :integer, options)
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_json
|
47
|
-
json = @options.slice(:limit)
|
48
|
-
json[:columns] = {}
|
49
|
-
@columns.each do |name, column|
|
50
|
-
json[:columns][name] = column.as_json
|
51
|
-
end
|
52
|
-
json.to_json
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
attr_accessor :tables
|
58
|
-
|
59
|
-
def initialize
|
60
|
-
@tables = {}
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.define(&block)
|
64
|
-
i = new
|
65
|
-
i.define(&block)
|
66
|
-
i
|
67
|
-
end
|
68
|
-
|
69
|
-
def define(&block)
|
70
|
-
instance_eval(&block)
|
71
|
-
end
|
72
|
-
|
73
|
-
def create_table(name, options={}, &block)
|
74
|
-
@tables[name] = Table.new(name, options, &block)
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.schema(&block)
|
80
|
-
self.class_variable_set(:@@schema, Schema.define(&block))
|
81
|
-
end
|
82
|
-
|
83
|
-
set_callback(:setup, :before) do
|
84
|
-
if !instance_variable_defined?(:@suite_setup_run) && self.class.class_variable_defined?(:@@schema)
|
85
|
-
ActiveRecord::Base.establish_connection(adapter: 'sunstone', url: 'http://example.com')
|
86
|
-
|
87
|
-
req_stub = stub_request(:get, /^http:\/\/example.com/).with do |req|
|
88
|
-
case req.uri.path
|
89
|
-
when '/tables'
|
90
|
-
true
|
91
|
-
when /^\/\w+\/schema$/i
|
92
|
-
true
|
93
|
-
else
|
94
|
-
false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
req_stub.to_return do |req|
|
99
|
-
case req.uri.path
|
100
|
-
when '/tables'
|
101
|
-
{
|
102
|
-
body: self.class.class_variable_get(:@@schema).tables.keys.to_json,
|
103
|
-
headers: { 'StandardAPI-Version' => '5.0.0.5' }
|
104
|
-
}
|
105
|
-
when /^\/(\w+)\/schema$/i
|
106
|
-
{
|
107
|
-
body: self.class.class_variable_get(:@@schema).tables[$1].to_json,
|
108
|
-
headers: { 'StandardAPI-Version' => '5.0.0.5' }
|
109
|
-
}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
@suite_setup_run = true
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Sunstone::Connection::ConfigurationTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test "setting the url sets the api_key" do
|
6
|
-
connection = Sunstone::Connection.new(url: 'http://my_api_key@localhost')
|
7
|
-
assert_equal('my_api_key', connection.api_key)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "setting the url sets the host" do
|
11
|
-
connection = Sunstone::Connection.new(url: 'https://example.com')
|
12
|
-
assert_equal('example.com', connection.host)
|
13
|
-
end
|
14
|
-
|
15
|
-
test "setting the url sets the port" do
|
16
|
-
connection = Sunstone::Connection.new(url: 'http://localhost')
|
17
|
-
assert_equal(80, connection.port)
|
18
|
-
|
19
|
-
connection = Sunstone::Connection.new(url: 'https://localhost')
|
20
|
-
assert_equal(443, connection.port)
|
21
|
-
|
22
|
-
connection = Sunstone::Connection.new(url: 'https://localhost:4321')
|
23
|
-
assert_equal(4321, connection.port)
|
24
|
-
end
|
25
|
-
|
26
|
-
test "setting the url sets the use_ssl option" do
|
27
|
-
connection = Sunstone::Connection.new(url: 'http://localhost')
|
28
|
-
assert_equal(false, connection.use_ssl)
|
29
|
-
|
30
|
-
connection = Sunstone::Connection.new(url: 'https://localhost')
|
31
|
-
assert_equal(true, connection.use_ssl)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "setting the user_agent appends it to the User-Agent" do
|
35
|
-
connection = Sunstone::Connection.new(url: 'http://localhost')
|
36
|
-
assert_equal("Sunstone/#{Sunstone::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_PLATFORM}", connection.user_agent)
|
37
|
-
|
38
|
-
connection = Sunstone::Connection.new(url: 'http://localhost', user_agent: "MyGem/3.14")
|
39
|
-
assert_equal("MyGem/3.14 Sunstone/#{Sunstone::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_PLATFORM}", connection.user_agent)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Sunstone::Connection::CookieStoreTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test '#send_request(#<Net::HTTPRequest) adds cookies to the cookie store if present' do
|
6
|
-
store = CookieStore::HashStore.new
|
7
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
8
|
-
stub_request(:get, "http://testhost.com/test").to_return(:body => 'get', :headers => {'Set-Cookie' => 'foo=bar; Max-Age=3600'})
|
9
|
-
|
10
|
-
Sunstone::Connection.with_cookie_store(store) { connection.get('/test') }
|
11
|
-
|
12
|
-
assert_equal 1, store.instance_variable_get(:@domains).size
|
13
|
-
assert_equal 1, store.instance_variable_get(:@domains)['testhost.com'].size
|
14
|
-
assert_equal 1, store.instance_variable_get(:@domains)['testhost.com']['/test'].size
|
15
|
-
assert_equal 'bar', store.instance_variable_get(:@domains)['testhost.com']['/test']['foo'].value
|
16
|
-
end
|
17
|
-
|
18
|
-
test '#send_request(#<Net::HTTPRequest) sends cookie header if cookie store is present' do
|
19
|
-
store = CookieStore::HashStore.new
|
20
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
21
|
-
stub_request(:get, "http://testhost.com/test").to_return(
|
22
|
-
headers: {
|
23
|
-
'Set-Cookie' => 'foo=bar; Path="/" Max-Age=3600'
|
24
|
-
},
|
25
|
-
body: 'get'
|
26
|
-
)
|
27
|
-
cookie_stub = stub_request(:get, "http://testhost.com/verify").with { |req|
|
28
|
-
req.headers['Cookie'] == 'foo=bar'
|
29
|
-
}.to_return(body: 'verify')
|
30
|
-
|
31
|
-
Sunstone::Connection.with_cookie_store(store) { connection.get('/test') }
|
32
|
-
Sunstone::Connection.with_cookie_store(store) { connection.get('/verify') }
|
33
|
-
|
34
|
-
assert_requested(cookie_stub)
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Sunstone::Connection::RequestHelpersTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
# Sunstone.get ==============================================================
|
6
|
-
|
7
|
-
test '#get(path)' do
|
8
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
9
|
-
stub_request(:get, "http://testhost.com/test").to_return(:body => "get")
|
10
|
-
|
11
|
-
assert_equal('get', connection.get('/test').body)
|
12
|
-
end
|
13
|
-
|
14
|
-
test '#get(path, params) with params as string' do
|
15
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
16
|
-
stub_request(:get, "http://testhost.com/test").with(:query => {'key' => 'value'}).to_return(:body => "get")
|
17
|
-
|
18
|
-
assert_equal 'get', connection.get('/test', 'key=value').body
|
19
|
-
end
|
20
|
-
|
21
|
-
test '#get(path, params) with params as hash' do
|
22
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
23
|
-
stub_request(:get, "http://testhost.com/test").with(:query => {'key' => 'value'}).to_return(:body => "get")
|
24
|
-
|
25
|
-
assert_equal 'get', connection.get('/test', {:key => 'value'}).body
|
26
|
-
end
|
27
|
-
|
28
|
-
test '#get(path, &block)' do
|
29
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
30
|
-
stub_request(:get, "http://testhost.com/test").to_return(:body => 'get')
|
31
|
-
|
32
|
-
connection.get('/test') do |response|
|
33
|
-
assert_equal 'get', response.body
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Sunstone.post =============================================================
|
38
|
-
|
39
|
-
test '#post(path)' do
|
40
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
41
|
-
stub_request(:post, "http://testhost.com/test").to_return(:body => "post")
|
42
|
-
|
43
|
-
assert_equal('post', connection.post('/test').body)
|
44
|
-
end
|
45
|
-
|
46
|
-
test '#post(path, body)' do
|
47
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
48
|
-
stub_request(:post, "http://testhost.com/test").with(:body => 'body').to_return(:body => "post")
|
49
|
-
|
50
|
-
assert_equal('post', connection.post('/test', 'body').body)
|
51
|
-
end
|
52
|
-
|
53
|
-
test '#post(path, &block)' do
|
54
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
55
|
-
stub_request(:post, "http://testhost.com/test").to_return(:body => 'post')
|
56
|
-
|
57
|
-
connection.post('/test') do |response|
|
58
|
-
assert_equal 'post', response.body
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Sunstone.put ==============================================================
|
63
|
-
|
64
|
-
test '#put(path)' do
|
65
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
66
|
-
stub_request(:put, "http://testhost.com/test").to_return(:body => "put")
|
67
|
-
|
68
|
-
assert_equal('put', connection.put('/test').body)
|
69
|
-
end
|
70
|
-
|
71
|
-
test '#put(path, body)' do
|
72
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
73
|
-
stub_request(:put, "http://testhost.com/test").with(:body => 'body').to_return(:body => "put")
|
74
|
-
|
75
|
-
assert_equal('put', connection.put('/test', 'body').body)
|
76
|
-
end
|
77
|
-
|
78
|
-
test '#put(path, &block)' do
|
79
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
80
|
-
stub_request(:put, "http://testhost.com/test").to_return(:body => 'put')
|
81
|
-
|
82
|
-
connection.put('/test') do |response|
|
83
|
-
assert_equal 'put', response.body
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Sunstone.delete ===========================================================
|
88
|
-
|
89
|
-
test '#delete' do
|
90
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
91
|
-
stub_request(:delete, "http://testhost.com/test").to_return(:body => "delete")
|
92
|
-
|
93
|
-
assert_equal('delete', connection.delete('/test').body)
|
94
|
-
end
|
95
|
-
|
96
|
-
test '#delete(path, &block)' do
|
97
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
98
|
-
stub_request(:delete, "http://testhost.com/test").to_return(:body => 'delete')
|
99
|
-
|
100
|
-
connection.delete('/test') do |response|
|
101
|
-
assert_equal 'delete', response.body
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Sunstone::Connection::SendRequestTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test '#send_request(#<Net::HTTPRequest>) includes the api-key header when present' do
|
6
|
-
connection = Sunstone::Connection.new(url: "http://my_api_key@example.com")
|
7
|
-
|
8
|
-
test_stub = stub_request(:get, "http://example.com/verify").with { |req|
|
9
|
-
req.headers['Api-Key'] == 'my_api_key'
|
10
|
-
}
|
11
|
-
connection.get('/verify')
|
12
|
-
assert_requested(test_stub)
|
13
|
-
end
|
14
|
-
|
15
|
-
test '#send_request(#<Net::HTTPRequest>) includes the user_agent' do
|
16
|
-
connection = Sunstone::Connection.new(url: "http://example.com")
|
17
|
-
|
18
|
-
test_stub = stub_request(:get, "http://example.com/verify").with { |req|
|
19
|
-
req.headers['User-Agent'] =~ /Sunstone\/\S+ Ruby\/\S+ \S+/
|
20
|
-
}
|
21
|
-
connection.get('/verify')
|
22
|
-
assert_requested(test_stub)
|
23
|
-
|
24
|
-
# Custom Agent
|
25
|
-
connection = Sunstone::Connection.new(url: "http://example.com", user_agent: "MyClient/2")
|
26
|
-
|
27
|
-
test_stub = stub_request(:get, "http://example.com/verify").with { |req|
|
28
|
-
req.headers['User-Agent'] =~ /MyClient\/2 Sunstone\/\S+ Ruby\/\S+ \S+/
|
29
|
-
}
|
30
|
-
connection.get('/verify')
|
31
|
-
assert_requested(test_stub)
|
32
|
-
end
|
33
|
-
|
34
|
-
test '#send_request(#<Net::HTTPRequest>)' do
|
35
|
-
stub_request(:get, "http://testhost.com/test").to_return(body: 'get')
|
36
|
-
|
37
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
38
|
-
assert_equal('get', connection.send_request(Net::HTTP::Get.new('/test')).body)
|
39
|
-
end
|
40
|
-
|
41
|
-
test '#send_request(#<Net::HTTPRequest>, body) with string body' do
|
42
|
-
stub_request(:post, "http://testhost.com/test").with(
|
43
|
-
body: '{"key":"value"}'
|
44
|
-
).to_return(
|
45
|
-
body: "post"
|
46
|
-
)
|
47
|
-
|
48
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
49
|
-
assert_equal('post', connection.send_request(Net::HTTP::Post.new('/test'), '{"key":"value"}').body)
|
50
|
-
end
|
51
|
-
|
52
|
-
test '#send_request(#<Net::HTTPRequest>, body) with IO body' do
|
53
|
-
stub_request(:post, "http://testhost.com/test").with { |request|
|
54
|
-
request.headers['Transfer-Encoding'] == "chunked" && request.body == '{"key":"value"}'
|
55
|
-
}.to_return(:body => "post")
|
56
|
-
|
57
|
-
rd, wr = IO.pipe
|
58
|
-
wr.write('{"key":"value"}')
|
59
|
-
wr.close
|
60
|
-
|
61
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
62
|
-
assert_equal('post', connection.send_request(Net::HTTP::Post.new('/test'), rd).body)
|
63
|
-
end
|
64
|
-
|
65
|
-
test '#send_request(#<Net::HTTPRequest>, body) with Ruby Object body' do
|
66
|
-
stub_request(:post, "http://testhost.com/test").with(body: '{"key":"value"}').to_return(body: "post")
|
67
|
-
|
68
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
69
|
-
assert_equal('post', connection.send_request(Net::HTTP::Post.new('/test'), {:key => 'value'}).body)
|
70
|
-
end
|
71
|
-
|
72
|
-
test '#send_request(#<Net::HTTPRequest>) raises Sunstone::Exceptions on non-200 responses' do
|
73
|
-
stub_request(:get, "http://testhost.com/400").to_return(status: 400)
|
74
|
-
stub_request(:get, "http://testhost.com/401").to_return(status: 401)
|
75
|
-
stub_request(:get, "http://testhost.com/403").to_return(status: 403)
|
76
|
-
stub_request(:get, "http://testhost.com/404").to_return(status: 404)
|
77
|
-
stub_request(:get, "http://testhost.com/410").to_return(status: 410)
|
78
|
-
stub_request(:get, "http://testhost.com/422").to_return(status: 422)
|
79
|
-
stub_request(:get, "http://testhost.com/450").to_return(status: 450)
|
80
|
-
stub_request(:get, "http://testhost.com/503").to_return(status: 503)
|
81
|
-
stub_request(:get, "http://testhost.com/550").to_return(status: 550)
|
82
|
-
|
83
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
84
|
-
assert_raises(Sunstone::Exception::BadRequest) { connection.send_request(Net::HTTP::Get.new('/400')) }
|
85
|
-
assert_raises(Sunstone::Exception::Unauthorized) { connection.send_request(Net::HTTP::Get.new('/401')) }
|
86
|
-
assert_raises(Sunstone::Exception::Forbidden) { connection.send_request(Net::HTTP::Get.new('/403')) }
|
87
|
-
assert_raises(Sunstone::Exception::NotFound) { connection.send_request(Net::HTTP::Get.new('/404')) }
|
88
|
-
assert_raises(Sunstone::Exception::Gone) { connection.send_request(Net::HTTP::Get.new('/410')) }
|
89
|
-
assert_raises(Sunstone::Exception::ApiVersionUnsupported) { connection.send_request(Net::HTTP::Get.new('/422')) }
|
90
|
-
assert_raises(Sunstone::Exception) { connection.send_request(Net::HTTP::Get.new('/450')) }
|
91
|
-
assert_raises(Sunstone::Exception::ServiceUnavailable) { connection.send_request(Net::HTTP::Get.new('/503')) }
|
92
|
-
assert_raises(Sunstone::ServerError) { connection.send_request(Net::HTTP::Get.new('/550')) }
|
93
|
-
end
|
94
|
-
|
95
|
-
test '#send_request(#<Net::HTTPRequest>, &block) returns value returned from &block' do
|
96
|
-
stub_request(:get, "http://testhost.com/test").to_return(body: 'get')
|
97
|
-
|
98
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
99
|
-
value = connection.send_request(Net::HTTP::Get.new('/test')) do |response|
|
100
|
-
3215
|
101
|
-
end
|
102
|
-
|
103
|
-
assert_equal 3215, value
|
104
|
-
end
|
105
|
-
|
106
|
-
test '#send_request(#<Net::HTTPRequest>, &block)' do
|
107
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
108
|
-
stub_request(:get, "http://testhost.com/test").to_return(body: 'get')
|
109
|
-
|
110
|
-
connection.send_request(Net::HTTP::Get.new('/test')) do |response|
|
111
|
-
assert_equal 'get', response.body
|
112
|
-
end
|
113
|
-
|
114
|
-
# make sure block is not called when not in valid_response_codes
|
115
|
-
stub_request(:get, "http://testhost.com/test").to_return(status: 401, body: 'get')
|
116
|
-
|
117
|
-
assert_raises(Sunstone::Exception::Unauthorized) {
|
118
|
-
connection.send_request(Net::HTTP::Get.new('/test')) do |response|
|
119
|
-
raise Sunstone::Exception, 'Should not get here'
|
120
|
-
end
|
121
|
-
}
|
122
|
-
end
|
123
|
-
|
124
|
-
test '#send_request(#<Net::HTTPRequest>, &block) with block reading chunks' do
|
125
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
126
|
-
|
127
|
-
rd, wr = IO.pipe
|
128
|
-
rd = Net::BufferedIO.new(rd)
|
129
|
-
wr.write(<<-DATA.gsub(/^ +/, '').gsub(/\n/, "\r\n"))
|
130
|
-
HTTP/1.1 200 OK
|
131
|
-
Content-Length: 5
|
132
|
-
|
133
|
-
hello
|
134
|
-
DATA
|
135
|
-
|
136
|
-
res = Net::HTTPResponse.read_new(rd)
|
137
|
-
mock_connection = mock('connection')
|
138
|
-
mock_connection.stubs(:request).yields(res)
|
139
|
-
connection.instance_variable_set(:@connection, mock_connection)
|
140
|
-
|
141
|
-
res.reading_body(rd, true) do
|
142
|
-
connection.send_request(Net::HTTP::Get.new('/test')) do |response|
|
143
|
-
response.read_body do |chunk|
|
144
|
-
assert_equal('hello', chunk)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# TODO: support multple depreaction-notice headers
|
151
|
-
test 'deprecation warning printed when deprecation header returned' do
|
152
|
-
connection = Sunstone::Connection.new(url: "http://testhost.com")
|
153
|
-
|
154
|
-
stub_request(:get, "http://testhost.com/test").to_return(
|
155
|
-
body: 'get',
|
156
|
-
headers: { 'Deprecation-Notice': 'my deprecation message' }
|
157
|
-
)
|
158
|
-
|
159
|
-
ActiveSupport::Deprecation.expects(:warn).with('my deprecation message')
|
160
|
-
|
161
|
-
connection.send_request(Net::HTTP::Get.new('/test'))
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|