Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ship_compliant/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ class << self
attr_accessor :ship_compliant_client
end

def self.ship_compliant_client
Thread.current[:ship_compliant_client]
end

def self.ship_compliant_client=(client)
Thread.current[:ship_compliant_client] = client
end

# Returns an instance of +Client+.
def self.client
self.ship_compliant_client ||= new_client_from_wsdl(configuration.wsdl)
Expand Down
6 changes: 5 additions & 1 deletion lib/ship_compliant/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ def self.configure
end

def self.configuration
@configuration ||= Configuration.new
Thread.current[:ship_compliant_configuration] ||= Configuration.new
end

def self.configuration=(value)
Thread.current[:ship_compliant_configuration] = value
end

# Stores runtime configuration to authenticate user.
Expand Down
4 changes: 1 addition & 3 deletions lib/ship_compliant/search_sales_orders_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def paging_cookie_expires
# Standardizes the XML response by converting fields to integers
# and forcing the order summaries into an array.
def parse!
unless raw.has_key?(:sales_orders)
raw[:sales_orders] = {}
end
raw[:sales_orders] ||= {}

# force orders to be an array
orders = raw[:sales_orders].fetch(:sales_order_summary, {})
Expand Down
4 changes: 2 additions & 2 deletions ship_compliant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Gem::Specification.new do |s|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.require_paths = ["lib"]

s.add_dependency "activesupport", "~> 4.0", ">= 4.0.3"
s.add_dependency "activesupport", ">= 4.0.3"
s.add_dependency "savon", "~> 2.3"

s.add_development_dependency "bundler", "~> 1.5"
s.add_development_dependency "bundler", "~> 2.0"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "sdoc", "~> 0.4"
s.add_development_dependency "pry", "~> 0.9"
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/ship_compliant/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ module ShipCompliant
expect(ShipCompliant.client.globals[:log]).to be_falsey
end

it "don't share configuration between threads" do
ShipCompliant.configure do |c|
c.username = 'foo'
end

Thread.new do
ShipCompliant.configure do |c|
c.username = 'bar'
end

expect(ShipCompliant.configuration.username).to eq('bar')
end.join

expect(ShipCompliant.configuration.username).to eq('foo')
end

context "call" do
before { savon.mock! }
after { savon.unmock! }
Expand Down