Skip to content

Commit

Permalink
Support test_mode_override argument in Payrix::Configuration.url
Browse files Browse the repository at this point in the history
  • Loading branch information
harrylewis committed Mar 9, 2024
1 parent a9d6685 commit 9ba96a0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/payrix/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ def initialize
@test_mode = false
end

def url
if @test_mode
def url(test_mode_override = nil)
test_mode = @test_mode
test_mode = test_mode_override if [true, false].include?(test_mode_override)

if test_mode
'https://test-api.payrix.com'
else
'https://api.payrix.com'
Expand Down
60 changes: 60 additions & 0 deletions spec/lib/payrix/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,65 @@
expect(configuration.url).to eq('https://api.payrix.com')
end
end

context 'when nil is passed and the default test mode is on' do
it 'returns https://test-api.payrix.com' do
configuration = described_class.new

configuration.test_mode = true

expect(configuration.url(nil)).to eq('https://test-api.payrix.com')
end
end

context 'when nil is passed and the default test mode is off' do
it 'returns https://api.payrix.com' do
configuration = described_class.new

configuration.test_mode = false

expect(configuration.url(nil)).to eq('https://api.payrix.com')
end
end

context 'when true is passed and the default test mode is on' do
it 'returns https://test-api.payrix.com' do
configuration = described_class.new

configuration.test_mode = true

expect(configuration.url(true)).to eq('https://test-api.payrix.com')
end
end

context 'when true is passed and the default test mode is off' do
it 'returns https://test-api.payrix.com' do
configuration = described_class.new

configuration.test_mode = false

expect(configuration.url(true)).to eq('https://test-api.payrix.com')
end
end

context 'when false is passed and the default test mode is on' do
it 'returns https://api.payrix.com' do
configuration = described_class.new

configuration.test_mode = true

expect(configuration.url(false)).to eq('https://api.payrix.com')
end
end

context 'when false is passed and the default test mode is off' do
it 'returns https://api.payrix.com' do
configuration = described_class.new

configuration.test_mode = false

expect(configuration.url(false)).to eq('https://api.payrix.com')
end
end
end
end

0 comments on commit 9ba96a0

Please sign in to comment.