sage_pay 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe SagePay::Server do
4
+ describe ".payment" do
5
+ before(:each) do
6
+ SagePay::Server.default_registration_options = {
7
+ :mode => :test,
8
+ :vendor => "rubaidh",
9
+ :notification_url => "http://test.host/notification"
10
+ }
11
+ end
12
+
13
+ after(:each) do
14
+ SagePay::Server.default_registration_options = {}
15
+ end
16
+
17
+ it "should pass in the default registration options" do
18
+
19
+ payment = SagePay::Server.payment
20
+ payment.mode.should == :test
21
+ payment.vendor.should == "rubaidh"
22
+ payment.notification_url.should == "http://test.host/notification"
23
+ end
24
+
25
+ it "should generate a vendor transaction code automatically" do
26
+ payment = SagePay::Server.payment
27
+ payment.vendor_tx_code.should_not be_nil
28
+ end
29
+
30
+ it "should set the transaction type to :payment" do
31
+ payment = SagePay::Server.payment
32
+ payment.tx_type.should == :payment
33
+ end
34
+
35
+ it "should duplicate the billing address to the delivery address if no billing address is supplied" do
36
+ address = mock("Home address")
37
+
38
+ payment = SagePay::Server.payment :billing_address => address
39
+ payment.delivery_address.should == address
40
+ end
41
+
42
+ it "should not overwrite a delivery address if one is supplied" do
43
+ billing_address = mock("Billing address")
44
+ delivery_address = mock("Delivery address")
45
+
46
+ payment = SagePay::Server.payment :billing_address => billing_address, :delivery_address => delivery_address
47
+ payment.delivery_address.should == delivery_address
48
+ payment.billing_address.should == billing_address
49
+ end
50
+
51
+ it "should allow the caller to override any of the default registration options" do
52
+ payment = SagePay::Server.payment :vendor => "chickens"
53
+ payment.vendor.should == "chickens"
54
+ end
55
+
56
+ it "should allow the caller to override any of the calculated default registration options (eg vendor tx code)" do
57
+ payment = SagePay::Server.payment :vendor_tx_code => "chickens"
58
+ payment.vendor_tx_code.should == "chickens"
59
+ end
60
+
61
+ it "should generate a valid payment given the minimum set of fields" do
62
+ address = address_factory
63
+ payment = SagePay::Server.payment(
64
+ :description => "Demo payment",
65
+ :amount => 12.34,
66
+ :currency => "GBP",
67
+ :billing_address => address
68
+ )
69
+ payment.should be_valid
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe SagePay do
4
+ it "should be version 0.2.0" do
5
+ SagePay::VERSION.should == '0.2.0'
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'spec/autorun'
3
+
4
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'sage_pay'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.include(Factories)
13
+ config.include(ValidationMatchers)
14
+ end
@@ -0,0 +1,58 @@
1
+ module Factories
2
+ include SagePay::Server
3
+
4
+ def model_factory(model_name, overrides = {})
5
+ send("#{model_name}_factory", overrides)
6
+ end
7
+
8
+ def address_factory(overrides = {})
9
+ # Data provided courtesy of Faker
10
+ defaults = {
11
+ :first_names => "Aryanna",
12
+ :surname => "Larkin",
13
+ :address_1 => "19313 Cristian Parks",
14
+ :city => "Lurlineport",
15
+ :post_code => "UI62 7BJ",
16
+ :country => "GB"
17
+ }
18
+ Address.new(defaults.merge(overrides))
19
+ end
20
+
21
+ def transaction_registration_factory(overrides = {})
22
+ defaults = {
23
+ :mode => :test,
24
+ :tx_type => :payment,
25
+ :vendor => "BobTheBuilder",
26
+ :vendor_tx_code => "random-transaction-id",
27
+ :amount => BigDecimal.new("35.49"),
28
+ :currency => "GBP",
29
+ :description => "Factory payment",
30
+ :notification_url => "http://test.host/notification",
31
+ :billing_address => address_factory,
32
+ :delivery_address => address_factory
33
+ }
34
+ TransactionRegistration.new(defaults.merge(overrides))
35
+ end
36
+
37
+ def transaction_registration_response_factory(overrides = {})
38
+ defaults = {
39
+ }
40
+ TransactionRegistrationResponse.new(defaults.merge(overrides))
41
+ end
42
+
43
+ def transaction_notification_factory(overrides = {})
44
+ defaults = {
45
+ }
46
+ TransactionNotification.new(defaults.merge(overrides))
47
+ end
48
+
49
+ def transaction_notification_response_factory(overrides = {})
50
+ defaults = {
51
+ :status => :ok,
52
+ :status_detail => "A-OK!",
53
+ :redirect_url => "http://test.host/redirect"
54
+ }
55
+ TransactionNotificationResponse.new(defaults.merge(overrides))
56
+ end
57
+
58
+ end
@@ -0,0 +1,9 @@
1
+ if ENV["SKIP_INTEGRATION"]
2
+ STDERR.puts "Skipping integration tests, as SKIP_INTEGRATION has been defined in the environment"
3
+ else
4
+ STDERR.puts "Running integration tests. Set SKIP_INTEGRATION=true to skip them."
5
+ end
6
+
7
+ def run_integration_specs?
8
+ ENV["SKIP_INTEGRATION"].nil?
9
+ end
@@ -0,0 +1,71 @@
1
+ module ValidationMatchers
2
+ def validates_the_presence_of(model_name, attribute, message = "can't be empty")
3
+ model = model_factory(model_name, attribute => "")
4
+ model.should_not be_valid
5
+ model.errors.on(attribute).should include(message)
6
+ end
7
+
8
+ def does_not_require_the_presence_of(model_name, attribute)
9
+ model = model_factory(model_name, attribute => "")
10
+ model.should be_valid
11
+ model.errors.on(attribute).should be_nil
12
+ end
13
+
14
+ def validates_the_length_of(model_name, attribute, limits, message = "is invalid")
15
+ if limits[:min]
16
+ model = model_factory(model_name, attribute => 'a' * (limits[:min] - 1))
17
+ model.should_not be_valid
18
+ model.errors.on(attribute).should include(message)
19
+
20
+ model = model_factory(model_name, attribute => 'a' * limits[:min])
21
+ model.should be_valid
22
+ model.errors.on(attribute).should be_nil
23
+
24
+ model = model_factory(model_name, attribute => 'a' * (limits[:min] + 1))
25
+ model.should be_valid
26
+ model.errors.on(attribute).should be_nil
27
+ end
28
+
29
+ if limits[:max]
30
+ model = model_factory(model_name, attribute => 'a' * (limits[:max] - 1))
31
+ model.should be_valid
32
+ model.errors.on(attribute).should be_nil
33
+
34
+ model = model_factory(model_name, attribute => 'a' * limits[:max])
35
+ model.should be_valid
36
+ model.errors.on(attribute).should be_nil
37
+
38
+ model = model_factory(model_name, attribute => 'a' * (limits[:max] + 1))
39
+ model.should_not be_valid
40
+ model.errors.on(attribute).should include(message)
41
+ end
42
+
43
+ if limits[:exactly]
44
+ model = model_factory(model_name, attribute => 'a' * (limits[:exactly] - 1))
45
+ model.should_not be_valid
46
+ model.errors.on(attribute).should include(message)
47
+
48
+ model = model_factory(model_name, attribute => 'a' * limits[:exactly])
49
+ model.should be_valid
50
+ model.errors.on(attribute).should be_nil
51
+
52
+ model = model_factory(model_name, attribute => 'a' * (limits[:exactly] + 1))
53
+ model.should_not be_valid
54
+ model.errors.on(attribute).should include(message)
55
+ end
56
+ end
57
+
58
+ def validates_the_format_of(model_name, attribute, examples, message = "is invalid")
59
+ (examples[:invalid] || []).each do |invalid|
60
+ model = model_factory(model_name, attribute => invalid)
61
+ model.should_not be_valid
62
+ model.errors.on(attribute).should == message
63
+ end
64
+
65
+ (examples[:valid] || []).each do |valid|
66
+ model = model_factory(model_name, attribute => valid)
67
+ model.should be_valid
68
+ model.errors.on(attribute).should be_nil
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Graeme Mathieson
@@ -14,10 +14,49 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-07 00:00:00 +01:00
17
+ date: 2010-04-13 00:00:00 +01:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: validatable
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 6
30
+ - 7
31
+ version: 1.6.7
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: uuid
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 0
45
+ version: 2.3.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id003
21
60
  description: |
22
61
  This is a Ruby library for integrating with SagePay. SagePay is a payment
23
62
  gateway for accepting credit card payments through your web app.
@@ -35,7 +74,31 @@ files:
35
74
  - README.md
36
75
  - Rakefile
37
76
  - lib/sage_pay.rb
77
+ - lib/sage_pay/server.rb
78
+ - lib/sage_pay/server/address.rb
79
+ - lib/sage_pay/server/signature_verification_details.rb
80
+ - lib/sage_pay/server/transaction_code.rb
81
+ - lib/sage_pay/server/transaction_notification.rb
82
+ - lib/sage_pay/server/transaction_notification_response.rb
83
+ - lib/sage_pay/server/transaction_registration.rb
84
+ - lib/sage_pay/server/transaction_registration_response.rb
85
+ - lib/validatable-ext.rb
86
+ - lib/validations/validates_inclusion_of.rb
38
87
  - sage_pay.gemspec
88
+ - spec/integration/sage_pay/server_spec.rb
89
+ - spec/sage_pay/server/address_spec.rb
90
+ - spec/sage_pay/server/signature_verification_details_spec.rb
91
+ - spec/sage_pay/server/transaction_code_spec.rb
92
+ - spec/sage_pay/server/transaction_notification_response_spec.rb
93
+ - spec/sage_pay/server/transaction_notification_spec.rb
94
+ - spec/sage_pay/server/transaction_registration_response_spec.rb
95
+ - spec/sage_pay/server/transaction_registration_spec.rb
96
+ - spec/sage_pay/server_spec.rb
97
+ - spec/sage_pay_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/support/factories.rb
100
+ - spec/support/integration.rb
101
+ - spec/support/validation_matchers.rb
39
102
  has_rdoc: true
40
103
  homepage: http://github.com/mathie/sage_pay
41
104
  licenses: []
@@ -66,5 +129,14 @@ rubygems_version: 1.3.6
66
129
  signing_key:
67
130
  specification_version: 2
68
131
  summary: Ruby implementation of the SagePay payment gateway protocol.
69
- test_files: []
70
-
132
+ test_files:
133
+ - spec/integration/sage_pay/server_spec.rb
134
+ - spec/sage_pay/server/address_spec.rb
135
+ - spec/sage_pay/server/signature_verification_details_spec.rb
136
+ - spec/sage_pay/server/transaction_code_spec.rb
137
+ - spec/sage_pay/server/transaction_notification_response_spec.rb
138
+ - spec/sage_pay/server/transaction_notification_spec.rb
139
+ - spec/sage_pay/server/transaction_registration_response_spec.rb
140
+ - spec/sage_pay/server/transaction_registration_spec.rb
141
+ - spec/sage_pay/server_spec.rb
142
+ - spec/sage_pay_spec.rb