braintree-rails 0.0.1
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.
- data/Gemfile +10 -0
- data/Gemfile.lock +34 -0
- data/README.md +2 -0
- data/Rakefile +4 -0
- data/braintree-rails.gemspec +18 -0
- data/lib/braintree-rails.rb +17 -0
- data/lib/braintree_rails/address.rb +75 -0
- data/lib/braintree_rails/addresses.rb +24 -0
- data/lib/braintree_rails/credit_card.rb +67 -0
- data/lib/braintree_rails/credit_cards.rb +24 -0
- data/lib/braintree_rails/customer.rb +37 -0
- data/lib/braintree_rails/exceptions.rb +2 -0
- data/lib/braintree_rails/model.rb +192 -0
- data/lib/env.rb +3 -0
- data/lib/tasks/test.rake +18 -0
- data/lib/test_env.rb +4 -0
- data/log/braintree_test.log +225696 -0
- data/test/config/braintree_auth.yml +4 -0
- data/test/config/braintree_auth.yml.example +4 -0
- data/test/fixtures/address.xml +19 -0
- data/test/fixtures/credit_card.xml +36 -0
- data/test/fixtures/credit_card_validation_error.xml +26 -0
- data/test/fixtures/customer.xml +90 -0
- data/test/integration/braintree_rails/address_integration_test.rb +72 -0
- data/test/integration/braintree_rails/credit_card_integration_test.rb +147 -0
- data/test/integration/braintree_rails/customer_integration_test.rb +41 -0
- data/test/integration/integration_test_helper.rb +13 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/braintree_rails/address_test.rb +87 -0
- data/test/unit/braintree_rails/addresses_test.rb +38 -0
- data/test/unit/braintree_rails/credit_card_test.rb +240 -0
- data/test/unit/braintree_rails/credit_cards_test.rb +38 -0
- data/test/unit/braintree_rails/customer_test.rb +171 -0
- data/test/unit/unit_test_helper.rb +3 -0
- metadata +176 -0
@@ -0,0 +1,171 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_test_helper'))
|
2
|
+
|
3
|
+
describe BraintreeRails::Customer do
|
4
|
+
before do
|
5
|
+
stub_braintree_request(:get, '/customers/customer_id', :body => fixture('customer.xml'))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'should find customer from braintree when given a customer id' do
|
10
|
+
customer = BraintreeRails::Customer.new('customer_id')
|
11
|
+
braintree_customer = Braintree::Customer.find('customer_id')
|
12
|
+
|
13
|
+
customer.persisted?.must_equal true
|
14
|
+
BraintreeRails::Customer::Attributes.each do |attribute|
|
15
|
+
customer.send(attribute).must_equal braintree_customer.send(attribute)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should wrap a Braintree::Customer' do
|
20
|
+
braintree_customer = Braintree::Customer.find('customer_id')
|
21
|
+
customer = BraintreeRails::Customer.new(braintree_customer)
|
22
|
+
|
23
|
+
customer.persisted?.must_equal true
|
24
|
+
BraintreeRails::Customer::Attributes.each do |attribute|
|
25
|
+
customer.send(attribute).must_equal braintree_customer.send(attribute)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should extract values from hash' do
|
30
|
+
customer = BraintreeRails::Customer.new(:id => 'new_id')
|
31
|
+
|
32
|
+
customer.persisted?.must_equal false
|
33
|
+
customer.id.must_equal 'new_id'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should try to extract value from other types' do
|
37
|
+
customer = BraintreeRails::Customer.new(OpenStruct.new(:id => 'foobar', :first_name => 'Foo', :last_name => 'Bar', :persisted? => true))
|
38
|
+
|
39
|
+
customer.persisted?.must_equal true
|
40
|
+
customer.id.must_equal 'foobar'
|
41
|
+
customer.first_name.must_equal 'Foo'
|
42
|
+
customer.last_name.must_equal 'Bar'
|
43
|
+
|
44
|
+
customer = BraintreeRails::Customer.new(OpenStruct.new)
|
45
|
+
customer.persisted?.must_equal false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#addresses' do
|
50
|
+
it 'behaves like enumerable' do
|
51
|
+
braintree_customer = Braintree::Customer.find('customer_id')
|
52
|
+
customer = BraintreeRails::Customer.new(braintree_customer)
|
53
|
+
|
54
|
+
customer.addresses.must_be_kind_of(Enumerable)
|
55
|
+
customer.addresses.size.must_equal braintree_customer.addresses.size
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#credit_cards' do
|
60
|
+
it 'behaves like enumerable' do
|
61
|
+
braintree_customer = Braintree::Customer.find('customer_id')
|
62
|
+
customer = BraintreeRails::Customer.new(braintree_customer)
|
63
|
+
|
64
|
+
customer.credit_cards.must_be_kind_of(Enumerable)
|
65
|
+
customer.credit_cards.size.must_equal braintree_customer.credit_cards.size
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'validations' do
|
70
|
+
it 'should validate id' do
|
71
|
+
customer = BraintreeRails::Customer.new(:id => '%')
|
72
|
+
customer.valid?
|
73
|
+
customer.errors[:id].wont_be :blank?
|
74
|
+
|
75
|
+
customer = BraintreeRails::Customer.new(:id => 'all')
|
76
|
+
customer.valid?
|
77
|
+
customer.errors[:id].wont_be :blank?
|
78
|
+
|
79
|
+
customer = BraintreeRails::Customer.new(:id => 'new')
|
80
|
+
customer.valid?
|
81
|
+
customer.errors[:id].wont_be :blank?
|
82
|
+
|
83
|
+
customer = BraintreeRails::Customer.new(:id => 'f' * 37)
|
84
|
+
customer.valid?
|
85
|
+
customer.errors[:id].wont_be :blank?
|
86
|
+
|
87
|
+
customer = BraintreeRails::Customer.new({})
|
88
|
+
customer.valid?
|
89
|
+
customer.errors[:id].must_be :blank?
|
90
|
+
|
91
|
+
customer = BraintreeRails::Customer.new(:id => 'f')
|
92
|
+
customer.valid?
|
93
|
+
customer.errors[:id].must_be :blank?
|
94
|
+
|
95
|
+
customer = BraintreeRails::Customer.new(:id => 'f' * 36)
|
96
|
+
customer.valid?
|
97
|
+
customer.errors[:id].must_be :blank?
|
98
|
+
end
|
99
|
+
|
100
|
+
[:first_name, :last_name, :company, :website, :phone, :fax].each do |attribute|
|
101
|
+
it "should validate length of #{attribute}" do
|
102
|
+
customer = BraintreeRails::Customer.new(attribute => 'f')
|
103
|
+
customer.valid?
|
104
|
+
customer.errors[attribute].must_be :blank?
|
105
|
+
|
106
|
+
customer = BraintreeRails::Customer.new(attribute => 'f' * 255)
|
107
|
+
customer.valid?
|
108
|
+
customer.errors[attribute].must_be :blank?
|
109
|
+
|
110
|
+
customer = BraintreeRails::Customer.new(attribute => 'foo' * 256)
|
111
|
+
customer.valid?
|
112
|
+
customer.errors[attribute].wont_be :blank?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'persistence' do
|
118
|
+
before do
|
119
|
+
stub_braintree_request(:post, '/customers', :body => fixture('customer.xml'))
|
120
|
+
stub_braintree_request(:put, '/customers/customer_id', :body => fixture('customer.xml'))
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'save, save!' do
|
124
|
+
it 'should return true when saved' do
|
125
|
+
customer = BraintreeRails::Customer.new
|
126
|
+
customer.save.must_equal true
|
127
|
+
customer.persisted?.must_equal true
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should not throw error when not valid' do
|
131
|
+
customer = BraintreeRails::Customer.new(:first_name => 'f' * 256)
|
132
|
+
customer.save.must_equal false
|
133
|
+
customer.persisted?.must_equal false
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should return true when saved with bang' do
|
137
|
+
customer = BraintreeRails::Customer.new
|
138
|
+
customer.save!.must_equal true
|
139
|
+
customer.persisted?.must_equal true
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should throw error when save invalid record with bang' do
|
143
|
+
customer = BraintreeRails::Customer.new(:first_name => 'f' * 256)
|
144
|
+
lambda{ customer.save! }.must_raise(RecordInvalid)
|
145
|
+
customer.persisted?.must_equal false
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'update_attributes, update_attributes!' do
|
150
|
+
it 'should return true when update_attributes' do
|
151
|
+
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
152
|
+
customer.update_attributes(:first_name => 'f').must_equal true
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should not throw error when not valid' do
|
156
|
+
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
157
|
+
customer.update_attributes(:first_name => 'f' * 256).must_equal false
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should return true when update_attributesd with bang' do
|
161
|
+
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
162
|
+
customer.update_attributes!(:first_name => 'f').must_equal true
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should throw error when update_attributes invalid record with bang' do
|
166
|
+
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
|
167
|
+
lambda{ customer.update_attributes!(:first_name => 'f' * 256) }.must_raise(RecordInvalid)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: braintree-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lin Yang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: braintree
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.14.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.14.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activemodel
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: minitest
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: webmock
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: turn
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Provides ActiveModel compatible wrappers for Braintree models and more.
|
111
|
+
email: github@linyang.me
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files: []
|
115
|
+
files:
|
116
|
+
- braintree-rails.gemspec
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- lib/braintree-rails.rb
|
120
|
+
- lib/braintree_rails/address.rb
|
121
|
+
- lib/braintree_rails/addresses.rb
|
122
|
+
- lib/braintree_rails/credit_card.rb
|
123
|
+
- lib/braintree_rails/credit_cards.rb
|
124
|
+
- lib/braintree_rails/customer.rb
|
125
|
+
- lib/braintree_rails/exceptions.rb
|
126
|
+
- lib/braintree_rails/model.rb
|
127
|
+
- lib/env.rb
|
128
|
+
- lib/tasks/test.rake
|
129
|
+
- lib/test_env.rb
|
130
|
+
- log/braintree_test.log
|
131
|
+
- Rakefile
|
132
|
+
- README.md
|
133
|
+
- test/config/braintree_auth.yml
|
134
|
+
- test/config/braintree_auth.yml.example
|
135
|
+
- test/fixtures/address.xml
|
136
|
+
- test/fixtures/credit_card.xml
|
137
|
+
- test/fixtures/credit_card_validation_error.xml
|
138
|
+
- test/fixtures/customer.xml
|
139
|
+
- test/integration/braintree_rails/address_integration_test.rb
|
140
|
+
- test/integration/braintree_rails/credit_card_integration_test.rb
|
141
|
+
- test/integration/braintree_rails/customer_integration_test.rb
|
142
|
+
- test/integration/integration_test_helper.rb
|
143
|
+
- test/test_helper.rb
|
144
|
+
- test/unit/braintree_rails/address_test.rb
|
145
|
+
- test/unit/braintree_rails/addresses_test.rb
|
146
|
+
- test/unit/braintree_rails/credit_card_test.rb
|
147
|
+
- test/unit/braintree_rails/credit_cards_test.rb
|
148
|
+
- test/unit/braintree_rails/customer_test.rb
|
149
|
+
- test/unit/unit_test_helper.rb
|
150
|
+
homepage: https://github.com/lyang/braintree-rails
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.24
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: Provides ActiveModel compatible wrappers for Braintree models.
|
175
|
+
test_files:
|
176
|
+
- test/test_helper.rb
|