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

REF: connection init for every request

parent 633213c3
......@@ -182,13 +182,4 @@ module BetfairApiNgRails
@_config ||= BetfairApiNgRails::Api::Config
block_given? ? yield(@_config) : @_config
end
def self.connection
raise BetfairApiNgRails::NoConnectionError unless @connection
@connection
end
def self.connection=(value)
@connection = value
end
end
......@@ -14,7 +14,7 @@ module BetfairApiNgRails
private
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
def build_request_type(name)
......
module BetfairApiNgRails
class Railtie < Rails::Railtie
config.after_initialize do
BetfairApiNgRails.connection = BetfairApiNgRails::Api::Connection.new
BetfairApiNgRails.log = BetfairApiNgRails::Api::Logs::FileLogger.new Rails.root, Rails.env
BetfairApiNgRails.account_manager = BetfairApiNgRails::AccountManager.instance
BetfairApiNgRails.account_session_manager = BetfairApiNgRails::AccountSessionManager.instance
......
......@@ -45,12 +45,10 @@ describe BetfairApiNgRails::Api::RequestMethods do
let(:params) { {key1: 'value'} }
let(:connection) { double(:connection) }
before(:each) { BetfairApiNgRails.connection = connection }
after(:each) { TestModule.send(:run_request, 'some_method', params) }
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
......
shared_examples 'request method' do
let(:ssoid) { 'vnboeirubvyebvuekrybobvuiberlvbre' }
let(:connection) { BetfairApiNgRails::Api::Connection.new }
let(:http_response) { double(:http_response, code: '200', body: result_hash) }
let(:result) { BetfairApiNgRails::Api::Http::Responser.new(http_response) }
let(:filter) { BetfairApiNgRails::MarketFilter.new }
......@@ -10,7 +9,6 @@ shared_examples 'request method' do
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::Http::Factory).to receive(:provider_requester).and_return api_http_requester
BetfairApiNgRails.connection = connection
end
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