Commit 5f88328e authored by Sergey Gernyak's avatar Sergey Gernyak

REF: connection init for every request

parent 633213c3
...@@ -182,13 +182,4 @@ module BetfairApiNgRails ...@@ -182,13 +182,4 @@ module BetfairApiNgRails
@_config ||= BetfairApiNgRails::Api::Config @_config ||= BetfairApiNgRails::Api::Config
block_given? ? yield(@_config) : @_config block_given? ? yield(@_config) : @_config
end end
def self.connection
raise BetfairApiNgRails::NoConnectionError unless @connection
@connection
end
def self.connection=(value)
@connection = value
end
end end
...@@ -14,7 +14,7 @@ module BetfairApiNgRails ...@@ -14,7 +14,7 @@ module BetfairApiNgRails
private private
def run_request(method, params, account_name = '') def run_request(method, params, account_name = '')
BetfairApiNgRails.connection.request build_request_type(method), params#, account_name BetfairApiNgRails::Api::Connection.new.request build_request_type(method), params#, account_name
end end
def build_request_type(name) def build_request_type(name)
......
module BetfairApiNgRails module BetfairApiNgRails
class Railtie < Rails::Railtie class Railtie < Rails::Railtie
config.after_initialize do config.after_initialize do
BetfairApiNgRails.connection = BetfairApiNgRails::Api::Connection.new
BetfairApiNgRails.log = BetfairApiNgRails::Api::Logs::FileLogger.new Rails.root, Rails.env BetfairApiNgRails.log = BetfairApiNgRails::Api::Logs::FileLogger.new Rails.root, Rails.env
BetfairApiNgRails.account_manager = BetfairApiNgRails::AccountManager.instance BetfairApiNgRails.account_manager = BetfairApiNgRails::AccountManager.instance
BetfairApiNgRails.account_session_manager = BetfairApiNgRails::AccountSessionManager.instance BetfairApiNgRails.account_session_manager = BetfairApiNgRails::AccountSessionManager.instance
......
...@@ -45,12 +45,10 @@ describe BetfairApiNgRails::Api::RequestMethods do ...@@ -45,12 +45,10 @@ describe BetfairApiNgRails::Api::RequestMethods do
let(:params) { {key1: 'value'} } let(:params) { {key1: 'value'} }
let(:connection) { double(:connection) } let(:connection) { double(:connection) }
before(:each) { BetfairApiNgRails.connection = connection }
after(:each) { TestModule.send(:run_request, 'some_method', params) } after(:each) { TestModule.send(:run_request, 'some_method', params) }
it "calls request method with proper params" do it "calls request method with proper params" do
expect(connection).to receive(:request).with('someMethod', params) expect_any_instance_of(BetfairApiNgRails::Api::Connection).to receive(:request).with('someMethod', params)
end end
end end
end end
......
shared_examples 'request method' do shared_examples 'request method' do
let(:ssoid) { 'vnboeirubvyebvuekrybobvuiberlvbre' } let(:ssoid) { 'vnboeirubvyebvuekrybobvuiberlvbre' }
let(:connection) { BetfairApiNgRails::Api::Connection.new }
let(:http_response) { double(:http_response, code: '200', body: result_hash) } let(:http_response) { double(:http_response, code: '200', body: result_hash) }
let(:result) { BetfairApiNgRails::Api::Http::Responser.new(http_response) } let(:result) { BetfairApiNgRails::Api::Http::Responser.new(http_response) }
let(:filter) { BetfairApiNgRails::MarketFilter.new } let(:filter) { BetfairApiNgRails::MarketFilter.new }
...@@ -10,7 +9,6 @@ shared_examples 'request method' do ...@@ -10,7 +9,6 @@ shared_examples 'request method' do
allow(api_http_requester).to receive(:do_request).and_return result allow(api_http_requester).to receive(:do_request).and_return result
expect(BetfairApiNgRails::Api::SessionManager).to receive(:new_ssoid).and_return ssoid expect(BetfairApiNgRails::Api::SessionManager).to receive(:new_ssoid).and_return ssoid
expect(BetfairApiNgRails::Api::Http::Factory).to receive(:provider_requester).and_return api_http_requester expect(BetfairApiNgRails::Api::Http::Factory).to receive(:provider_requester).and_return api_http_requester
BetfairApiNgRails.connection = connection
end end
subject { TestModule.send(method_name, parameters) } subject { TestModule.send(method_name, parameters) }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment