spreedly_core 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spreedly_core/base.rb +2 -1
- data/lib/spreedly_core/test_extensions.rb +33 -23
- data/lib/spreedly_core/version.rb +1 -1
- data/test/spreedly_core_test.rb +10 -0
- data/test/test_helper.rb +14 -0
- metadata +19 -3
data/lib/spreedly_core/base.rb
CHANGED
@@ -63,7 +63,8 @@ module SpreedlyCore
|
|
63
63
|
raise InvalidResponse.new(response, "Error retrieving #{path}. Got status of #{response.code}. Expected status to be in #{allowed_codes.join(",")}")
|
64
64
|
end
|
65
65
|
|
66
|
-
if options.has_key?(:has_key) &&
|
66
|
+
if options.has_key?(:has_key) &&
|
67
|
+
(response.parsed_response.nil? || !response.parsed_response.has_key?(options[:has_key]))
|
67
68
|
raise InvalidResponse.new(response, "Expected parsed response to contain key '#{options[:has_key]}'")
|
68
69
|
end
|
69
70
|
|
@@ -1,32 +1,42 @@
|
|
1
1
|
require 'cgi'
|
2
|
+
require 'uri'
|
2
3
|
|
3
|
-
module SpreedlyCore
|
4
|
-
|
5
|
-
|
6
|
-
def cc_data(cc_type, options={})
|
7
|
-
|
8
|
-
card_numbers = {:master => [5555555555554444, 5105105105105100],
|
9
|
-
:visa => [4111111111111111, 4012888888881881],
|
10
|
-
:american_express => [378282246310005, 371449635398431],
|
11
|
-
:discover => [6011111111111117, 6011000990139424]
|
12
|
-
}
|
4
|
+
module SpreedlyCore
|
5
|
+
module TestHelper
|
6
|
+
extend self
|
13
7
|
|
14
|
-
|
15
|
-
|
8
|
+
def cc_data(cc_type, options={})
|
9
|
+
|
10
|
+
card_numbers = {:master => [5555555555554444, 5105105105105100],
|
11
|
+
:visa => [4111111111111111, 4012888888881881],
|
12
|
+
:american_express => [378282246310005, 371449635398431],
|
13
|
+
:discover => [6011111111111117, 6011000990139424]
|
14
|
+
}
|
15
|
+
|
16
|
+
card_number = options[:card_number] == :failed ? :last : :first
|
17
|
+
number = card_numbers[cc_type].send(card_number)
|
18
|
+
|
19
|
+
{ :credit_card => {
|
20
|
+
:first_name => "John",
|
21
|
+
:last_name => "Foo",
|
22
|
+
:card_type => cc_type,
|
23
|
+
:number => number,
|
24
|
+
:verification_value => 123,
|
25
|
+
:month => 4,
|
26
|
+
:year => Time.now.year + 1 }.merge(options[:credit_card] || {})
|
27
|
+
}
|
28
|
+
end
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
30
|
+
# Return the base uri as a mocking framework would expect
|
31
|
+
def mocked_base_uri_string
|
32
|
+
uri = URI.parse(Base.base_uri)
|
33
|
+
auth_params = Base.default_options[:basic_auth]
|
34
|
+
uri.user = auth_params[:username]
|
35
|
+
uri.password = auth_params[:password]
|
36
|
+
uri.to_s
|
37
|
+
end
|
26
38
|
end
|
27
|
-
end
|
28
39
|
|
29
|
-
module SpreedlyCore
|
30
40
|
class PaymentMethod
|
31
41
|
|
32
42
|
# Call spreedly core to create a test token.
|
data/test/spreedly_core_test.rb
CHANGED
@@ -15,6 +15,16 @@ module SpreedlyCore
|
|
15
15
|
PaymentMethod.reset_additional_required_cc_fields
|
16
16
|
end
|
17
17
|
|
18
|
+
def test_mocked_500_error
|
19
|
+
with_disabled_network do
|
20
|
+
stub_request(:put, "#{mocked_base_uri_string}/payment_methods/FAKE.xml").
|
21
|
+
to_return(:body => '', :status => 500)
|
22
|
+
assert_raises InvalidResponse do
|
23
|
+
Base.verify_put('/payment_methods/FAKE.xml', :has_key => "test") {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
18
28
|
def test_can_get_payment_token
|
19
29
|
payment_method = given_a_payment_method(:master,
|
20
30
|
:credit_card => {:year => 2015})
|
data/test/test_helper.rb
CHANGED
@@ -12,8 +12,22 @@ require 'spreedly_core'
|
|
12
12
|
require 'spreedly_core/test_extensions'
|
13
13
|
require 'test_factory'
|
14
14
|
|
15
|
+
require 'webmock/test_unit'
|
16
|
+
# Allow real connections, see https://github.com/bblimke/webmock for more info
|
17
|
+
WebMock.allow_net_connect!
|
18
|
+
|
19
|
+
require 'webmock'
|
20
|
+
|
15
21
|
class Test::Unit::TestCase
|
16
22
|
def assert_false(test, failure_message=nil)
|
17
23
|
assert(!test, failure_message)
|
18
24
|
end
|
25
|
+
|
26
|
+
def with_disabled_network(&block)
|
27
|
+
WebMock.disable_net_connect!
|
28
|
+
block.call
|
29
|
+
ensure
|
30
|
+
WebMock.allow_net_connect!
|
31
|
+
end
|
32
|
+
|
19
33
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreedly_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- 403 Labs
|
@@ -63,6 +63,22 @@ dependencies:
|
|
63
63
|
version: 0.8.7
|
64
64
|
type: :development
|
65
65
|
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: webmock
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 11
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 6
|
78
|
+
- 2
|
79
|
+
version: 1.6.2
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id004
|
66
82
|
description:
|
67
83
|
email: github@403labs.com
|
68
84
|
executables: []
|