braintree-rails 1.2.3 → 1.3.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +13 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -4
- data/Gemfile.lock +33 -14
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/braintree-rails.gemspec +4 -5
- data/lib/braintree_rails/address.rb +1 -1
- data/lib/braintree_rails/address_details.rb +14 -0
- data/lib/braintree_rails/address_details_validator.rb +7 -0
- data/lib/braintree_rails/association.rb +2 -2
- data/lib/braintree_rails/braintree_ext.rb +27 -1
- data/lib/braintree_rails/business_details.rb +29 -0
- data/lib/braintree_rails/business_details_validator.rb +12 -0
- data/lib/braintree_rails/configuration.rb +1 -1
- data/lib/braintree_rails/credit_card.rb +6 -6
- data/lib/braintree_rails/credit_card_validator.rb +2 -17
- data/lib/braintree_rails/customer.rb +6 -6
- data/lib/braintree_rails/customer_validator.rb +1 -12
- data/lib/braintree_rails/funding_details.rb +17 -0
- data/lib/braintree_rails/funding_details_validator.rb +10 -0
- data/lib/braintree_rails/individual_details.rb +32 -0
- data/lib/braintree_rails/individual_details_validator.rb +11 -0
- data/lib/braintree_rails/merchant_account.rb +45 -0
- data/lib/braintree_rails/merchant_account_validator.rb +14 -0
- data/lib/braintree_rails/plan.rb +3 -3
- data/lib/braintree_rails/subscription.rb +5 -5
- data/lib/braintree_rails/transaction.rb +9 -9
- data/lib/braintree_rails/transaction_validator.rb +1 -5
- data/lib/braintree_rails/validator.rb +13 -0
- data/lib/braintree_rails/version.rb +1 -1
- data/lib/tasks/ci.rake +7 -0
- data/lib/tasks/spec.rake +18 -0
- data/lib/test_env.rb +1 -7
- data/{test → spec}/config/braintree_auth.yml.example +0 -0
- data/{test → spec}/fixtures/add_ons.xml +0 -0
- data/{test → spec}/fixtures/address.xml +0 -0
- data/{test → spec}/fixtures/credit_card.xml +0 -0
- data/{test → spec}/fixtures/credit_card_validation_error.xml +0 -0
- data/{test → spec}/fixtures/customer.xml +0 -0
- data/{test → spec}/fixtures/discounts.xml +0 -0
- data/spec/fixtures/merchant_account.xml +7 -0
- data/{test → spec}/fixtures/plans.xml +0 -0
- data/{test → spec}/fixtures/subscription.xml +0 -0
- data/{test → spec}/fixtures/subscription_ids.xml +0 -0
- data/{test → spec}/fixtures/subscriptions.xml +0 -0
- data/{test → spec}/fixtures/transaction.xml +0 -0
- data/{test → spec}/fixtures/transaction_error.xml +0 -0
- data/{test → spec}/fixtures/transaction_ids.xml +0 -0
- data/{test → spec}/fixtures/transactions.xml +0 -0
- data/{test/integration/braintree_rails/address_integration_test.rb → spec/integration/braintree_rails/address_integration_spec.rb} +8 -8
- data/{test/integration/braintree_rails/credit_card_integration_test.rb → spec/integration/braintree_rails/credit_card_integration_spec.rb} +20 -20
- data/{test/integration/braintree_rails/customer_integration_test.rb → spec/integration/braintree_rails/customer_integration_spec.rb} +20 -20
- data/spec/integration/braintree_rails/merchant_account_integration_spec.rb +37 -0
- data/{test/integration/braintree_rails/transaction_integration_test.rb → spec/integration/braintree_rails/transaction_integration_spec.rb} +27 -27
- data/spec/integration/integration_spec_helper.rb +23 -0
- data/spec/spec_helper.rb +17 -0
- data/{test/test_helper.rb → spec/support/helper.rb} +42 -21
- data/spec/support/string_ext.rb +5 -0
- data/{test/unit/braintree_rails/add_on_test.rb → spec/unit/braintree_rails/add_on_spec.rb} +10 -10
- data/{test/unit/braintree_rails/add_ons_test.rb → spec/unit/braintree_rails/add_ons_spec.rb} +4 -4
- data/spec/unit/braintree_rails/address_details_spec.rb +13 -0
- data/{test/unit/braintree_rails/address_test.rb → spec/unit/braintree_rails/address_spec.rb} +26 -26
- data/{test/unit/braintree_rails/addresses_test.rb → spec/unit/braintree_rails/addresses_spec.rb} +7 -7
- data/spec/unit/braintree_rails/business_details_spec.rb +28 -0
- data/{test/unit/braintree_rails/configuration_test.rb → spec/unit/braintree_rails/configuration_spec.rb} +6 -6
- data/{test/unit/braintree_rails/credit_card_test.rb → spec/unit/braintree_rails/credit_card_spec.rb} +78 -72
- data/{test/unit/braintree_rails/credit_cards_test.rb → spec/unit/braintree_rails/credit_cards_spec.rb} +15 -10
- data/{test/unit/braintree_rails/customer_test.rb → spec/unit/braintree_rails/customer_spec.rb} +46 -46
- data/{test/unit/braintree_rails/discount_test.rb → spec/unit/braintree_rails/discount_spec.rb} +10 -10
- data/{test/unit/braintree_rails/discounts_test.rb → spec/unit/braintree_rails/discounts_spec.rb} +4 -4
- data/spec/unit/braintree_rails/funding_details_spec.rb +36 -0
- data/spec/unit/braintree_rails/individual_details_spec.rb +19 -0
- data/{test/unit/braintree_rails/luhn_10_validator_test.rb → spec/unit/braintree_rails/luhn_10_validator_spec.rb} +5 -5
- data/spec/unit/braintree_rails/merchant_account_spec.rb +50 -0
- data/{test/unit/braintree_rails/plan_test.rb → spec/unit/braintree_rails/plan_spec.rb} +12 -12
- data/{test/unit/braintree_rails/subscription_test.rb → spec/unit/braintree_rails/subscription_spec.rb} +55 -55
- data/{test/unit/braintree_rails/subscriptions_test.rb → spec/unit/braintree_rails/subscriptions_spec.rb} +4 -4
- data/{test/unit/braintree_rails/transaction_test.rb → spec/unit/braintree_rails/transaction_spec.rb} +55 -55
- data/{test/unit/braintree_rails/transactions_test.rb → spec/unit/braintree_rails/transactions_spec.rb} +9 -9
- data/{test/unit/braintree_rails/validation_error_test.rb → spec/unit/braintree_rails/validation_error_spec.rb} +4 -4
- data/{test/unit/braintree_rails/validator_test.rb → spec/unit/braintree_rails/validator_spec.rb} +7 -7
- data/spec/unit/unit_spec_helper.rb +4 -0
- metadata +69 -63
- data/lib/tasks/test.rake +0 -18
- data/test/integration/integration_test_helper.rb +0 -13
- data/test/unit/unit_test_helper.rb +0 -3
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
|
+
|
3
|
+
describe BraintreeRails::MerchantAccount do
|
4
|
+
describe 'validations' do
|
5
|
+
[:tos_accepted, :master_merchant_account_id, :individual, :funding].each do |attribute|
|
6
|
+
it "requires #{attribute}" do
|
7
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(attribute => nil))
|
8
|
+
merchant_account.should be_invalid
|
9
|
+
merchant_account.errors[attribute].should == ["can't be blank"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "validates id format" do
|
14
|
+
[nil, "", "a", "_", "-", "0", "a"*32].each do |valid_value|
|
15
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:id => valid_value))
|
16
|
+
merchant_account.should be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
["%", "/"].each do |invalid_value|
|
20
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:id => invalid_value))
|
21
|
+
merchant_account.should be_invalid
|
22
|
+
merchant_account.errors[:id].should == ["is invalid"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "validates id length" do
|
27
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:id => "a"*33))
|
28
|
+
merchant_account.should be_invalid
|
29
|
+
merchant_account.errors[:id].should == ["is too long (maximum is 32 characters)"]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "validates individual" do
|
33
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:individual => {}))
|
34
|
+
merchant_account.should be_invalid
|
35
|
+
merchant_account.errors[:individual].should_not be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it "validates funding" do
|
39
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:funding => {}))
|
40
|
+
merchant_account.should be_invalid
|
41
|
+
merchant_account.errors[:funding].should_not be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it "validates business if present" do
|
45
|
+
merchant_account = BraintreeRails::MerchantAccount.new(merchant_account_hash.merge(:business => {:legal_name => "foo"}))
|
46
|
+
merchant_account.should be_invalid
|
47
|
+
merchant_account.errors[:business].should_not be_empty
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
2
|
|
3
3
|
describe BraintreeRails::Plan do
|
4
4
|
before do
|
@@ -10,9 +10,9 @@ describe BraintreeRails::Plan do
|
|
10
10
|
braintree_plan = Braintree::Plan.all.find { |p| p.id == 'plan_id' }
|
11
11
|
plan = BraintreeRails::Plan.new(braintree_plan)
|
12
12
|
|
13
|
-
plan.
|
13
|
+
plan.should be_persisted
|
14
14
|
BraintreeRails::Plan.attributes.each do |attribute|
|
15
|
-
plan.send(attribute).
|
15
|
+
plan.send(attribute).should == braintree_plan.send(attribute)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,9 +20,9 @@ describe BraintreeRails::Plan do
|
|
20
20
|
braintree_plan = Braintree::Plan.all.find { |p| p.id == 'plan_id' }
|
21
21
|
plan = BraintreeRails::Plan.find('plan_id')
|
22
22
|
|
23
|
-
plan.
|
23
|
+
plan.should be_persisted
|
24
24
|
BraintreeRails::Plan.attributes.each do |attribute|
|
25
|
-
plan.send(attribute).
|
25
|
+
plan.send(attribute).should == braintree_plan.send(attribute)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -32,8 +32,8 @@ describe BraintreeRails::Plan do
|
|
32
32
|
braintree_plans = Braintree::Plan.all
|
33
33
|
plans = BraintreeRails::Plan.all
|
34
34
|
|
35
|
-
plans.
|
36
|
-
plans.size.
|
35
|
+
plans.should respond_to(:each)
|
36
|
+
plans.size.should == braintree_plans.size
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -43,8 +43,8 @@ describe BraintreeRails::Plan do
|
|
43
43
|
braintree_plan = Braintree::Plan.all.find { |p| p.id == 'plan_id' }
|
44
44
|
plan = BraintreeRails::Plan.new(braintree_plan)
|
45
45
|
|
46
|
-
plan.send(association).
|
47
|
-
plan.send(association).size.
|
46
|
+
plan.send(association).should respond_to(:each)
|
47
|
+
plan.send(association).size.should == braintree_plan.send(association).size
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -62,14 +62,14 @@ describe BraintreeRails::Plan do
|
|
62
62
|
search.plan_id.is 'plan_id'
|
63
63
|
end.to_a
|
64
64
|
|
65
|
-
plan.subscriptions.
|
66
|
-
plan.subscriptions.size.
|
65
|
+
plan.subscriptions.should respond_to(:each)
|
66
|
+
plan.subscriptions.size.should == braintree_subscriptions.size
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'can build new subscription' do
|
70
70
|
plan = BraintreeRails::Plan.new('plan_id')
|
71
71
|
subscription = plan.subscriptions.build
|
72
|
-
subscription.plan_id.
|
72
|
+
subscription.plan_id.should == plan.id
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
2
|
|
3
3
|
describe BraintreeRails::Subscription do
|
4
4
|
before do
|
@@ -10,10 +10,10 @@ describe BraintreeRails::Subscription do
|
|
10
10
|
subscription = BraintreeRails::Subscription.new('subscription_id')
|
11
11
|
braintree_subscription = Braintree::Subscription.find('subscription_id')
|
12
12
|
|
13
|
-
subscription.
|
14
|
-
subscription.never_expires?.
|
13
|
+
subscription.should be_persisted
|
14
|
+
subscription.never_expires?.should == braintree_subscription.never_expires?
|
15
15
|
BraintreeRails::Subscription.attributes.each do |attribute|
|
16
|
-
subscription.send(attribute).
|
16
|
+
subscription.send(attribute).should == braintree_subscription.send(attribute) if braintree_subscription.respond_to?(attribute)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,27 +21,27 @@ describe BraintreeRails::Subscription do
|
|
21
21
|
braintree_subscription = Braintree::Subscription.find('subscription_id')
|
22
22
|
subscription = BraintreeRails::Subscription.new(braintree_subscription)
|
23
23
|
|
24
|
-
subscription.
|
24
|
+
subscription.should be_persisted
|
25
25
|
BraintreeRails::Subscription.attributes.each do |attribute|
|
26
|
-
subscription.send(attribute).
|
26
|
+
subscription.send(attribute).should == braintree_subscription.send(attribute) if braintree_subscription.respond_to?(attribute)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should extract values from hash' do
|
31
31
|
subscription = BraintreeRails::Subscription.new(:id => 'new_id')
|
32
32
|
|
33
|
-
subscription.
|
34
|
-
subscription.id.
|
33
|
+
subscription.should_not be_persisted
|
34
|
+
subscription.id.should == 'new_id'
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should try to extract value from other types' do
|
38
38
|
subscription = BraintreeRails::Subscription.new(OpenStruct.new(:id => 'foobar', :persisted? => true))
|
39
39
|
|
40
|
-
subscription.
|
41
|
-
subscription.id.
|
40
|
+
subscription.should be_persisted
|
41
|
+
subscription.id.should == 'foobar'
|
42
42
|
|
43
43
|
subscription = BraintreeRails::Subscription.new(OpenStruct.new)
|
44
|
-
subscription.
|
44
|
+
subscription.should_not be_persisted
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -49,136 +49,136 @@ describe BraintreeRails::Subscription do
|
|
49
49
|
it 'should validate id' do
|
50
50
|
subscription = BraintreeRails::Subscription.new
|
51
51
|
subscription.valid?
|
52
|
-
subscription.errors[:id].
|
52
|
+
subscription.errors[:id].should be_blank
|
53
53
|
|
54
54
|
subscription = BraintreeRails::Subscription.new(:id => '@#$%')
|
55
55
|
subscription.valid?
|
56
|
-
subscription.errors[:id].
|
56
|
+
subscription.errors[:id].should_not be_blank
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should billing_day_of_month' do
|
60
60
|
subscription = BraintreeRails::Subscription.new
|
61
61
|
subscription.valid?
|
62
|
-
subscription.errors[:billing_day_of_month].
|
62
|
+
subscription.errors[:billing_day_of_month].should be_blank
|
63
63
|
|
64
64
|
[*(1..28), 31].each do |valid_day|
|
65
65
|
subscription = BraintreeRails::Subscription.new(:billing_day_of_month => valid_day)
|
66
66
|
subscription.valid?
|
67
|
-
subscription.errors[:billing_day_of_month].
|
67
|
+
subscription.errors[:billing_day_of_month].should be_blank
|
68
68
|
end
|
69
69
|
|
70
70
|
[29, 30, 'foo'].each do |invalid_day|
|
71
71
|
subscription = BraintreeRails::Subscription.new(:billing_day_of_month => invalid_day)
|
72
72
|
subscription.valid?
|
73
|
-
subscription.errors[:billing_day_of_month].
|
73
|
+
subscription.errors[:billing_day_of_month].should_not be_blank
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'should validate numericality of number_of_billing_cycles' do
|
78
78
|
subscription = BraintreeRails::Subscription.new(:number_of_billing_cycles => 'foobar')
|
79
79
|
subscription.valid?
|
80
|
-
subscription.errors[:number_of_billing_cycles].
|
80
|
+
subscription.errors[:number_of_billing_cycles].should_not be_blank
|
81
81
|
|
82
82
|
[123, '123', nil].each do |valid_number|
|
83
83
|
subscription = BraintreeRails::Subscription.new(:number_of_billing_cycles => valid_number)
|
84
84
|
subscription.valid?
|
85
|
-
subscription.errors[:number_of_billing_cycles].
|
85
|
+
subscription.errors[:number_of_billing_cycles].should be_blank
|
86
86
|
end
|
87
87
|
|
88
88
|
[123.45, '123.45', 'foo'].each do |invalid_number|
|
89
89
|
subscription = BraintreeRails::Subscription.new(:number_of_billing_cycles => 'foo')
|
90
90
|
subscription.valid?
|
91
|
-
subscription.errors[:number_of_billing_cycles].
|
91
|
+
subscription.errors[:number_of_billing_cycles].should_not be_blank
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should validate number_of_billing_cycles is greater than current_billing_cycle' do
|
96
96
|
subscription = BraintreeRails::Subscription.new(:number_of_billing_cycles => '2', :current_billing_cycle => '1')
|
97
97
|
subscription.valid?
|
98
|
-
subscription.errors[:number_of_billing_cycles].
|
98
|
+
subscription.errors[:number_of_billing_cycles].should be_blank
|
99
99
|
|
100
100
|
subscription = BraintreeRails::Subscription.new(:number_of_billing_cycles => '2', :current_billing_cycle => '3')
|
101
101
|
subscription.valid?
|
102
|
-
subscription.errors[:number_of_billing_cycles].
|
102
|
+
subscription.errors[:number_of_billing_cycles].should_not be_blank
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should validate precence of payment_method_token if new_record?' do
|
106
106
|
subscription = BraintreeRails::Subscription.new
|
107
107
|
subscription.valid?
|
108
|
-
subscription.errors[:payment_method_token].
|
108
|
+
subscription.errors[:payment_method_token].should_not be_blank
|
109
109
|
|
110
110
|
subscription = BraintreeRails::Subscription.new(:payment_method_token => 'token')
|
111
111
|
subscription.valid?
|
112
|
-
subscription.errors[:payment_method_token].
|
112
|
+
subscription.errors[:payment_method_token].should be_blank
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should validate precence of plan_id if new_record?' do
|
116
116
|
subscription = BraintreeRails::Subscription.new
|
117
117
|
subscription.valid?
|
118
|
-
subscription.errors[:plan_id].
|
118
|
+
subscription.errors[:plan_id].should_not be_blank
|
119
119
|
|
120
120
|
subscription = BraintreeRails::Subscription.new(:plan_id => 'plan_id')
|
121
121
|
subscription.valid?
|
122
|
-
subscription.errors[:plan_id].
|
122
|
+
subscription.errors[:plan_id].should be_blank
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'should validate numericality of price' do
|
126
126
|
subscription = BraintreeRails::Subscription.new(:price => 'foobar')
|
127
127
|
subscription.valid?
|
128
|
-
subscription.errors[:price].
|
128
|
+
subscription.errors[:price].should_not be_blank
|
129
129
|
|
130
130
|
[123, 123.45, '123', '123.45', nil].each do |valid_price|
|
131
131
|
subscription = BraintreeRails::Subscription.new(:price => valid_price)
|
132
132
|
subscription.valid?
|
133
|
-
subscription.errors[:price].
|
133
|
+
subscription.errors[:price].should be_blank
|
134
134
|
end
|
135
135
|
|
136
136
|
subscription = BraintreeRails::Subscription.new(:price => 'foo')
|
137
137
|
subscription.valid?
|
138
|
-
subscription.errors[:price].
|
138
|
+
subscription.errors[:price].should_not be_blank
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'should validate numericality of trial_duration if trial_period' do
|
142
142
|
subscription = BraintreeRails::Subscription.new(:trial_duration => 'foobar')
|
143
143
|
subscription.valid?
|
144
|
-
subscription.errors[:trial_duration].
|
144
|
+
subscription.errors[:trial_duration].should be_blank
|
145
145
|
|
146
146
|
subscription = BraintreeRails::Subscription.new(:trial_duration => 'foobar', :trial_period => true)
|
147
147
|
subscription.valid?
|
148
|
-
subscription.errors[:trial_duration].
|
148
|
+
subscription.errors[:trial_duration].should_not be_blank
|
149
149
|
|
150
150
|
[1, 9999, '123'].each do |valid_duration|
|
151
151
|
subscription = BraintreeRails::Subscription.new(:trial_duration => valid_duration, :trial_period => true)
|
152
152
|
subscription.valid?
|
153
|
-
subscription.errors[:trial_duration].
|
153
|
+
subscription.errors[:trial_duration].should be_blank
|
154
154
|
end
|
155
155
|
|
156
156
|
[0, 10000, 1.23, nil].each do |invalid_duration|
|
157
157
|
subscription = BraintreeRails::Subscription.new(:trial_duration => invalid_duration, :trial_period => true)
|
158
158
|
subscription.valid?
|
159
|
-
subscription.errors[:trial_duration].
|
159
|
+
subscription.errors[:trial_duration].should_not be_blank
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'should validate trial_duration_unit if trial_period' do
|
164
164
|
subscription = BraintreeRails::Subscription.new(:trial_duration_unit => 'foobar')
|
165
165
|
subscription.valid?
|
166
|
-
subscription.errors[:trial_duration_unit].
|
166
|
+
subscription.errors[:trial_duration_unit].should be_blank
|
167
167
|
|
168
168
|
subscription = BraintreeRails::Subscription.new(:trial_duration_unit => 'foobar', :trial_period => true)
|
169
169
|
subscription.valid?
|
170
|
-
subscription.errors[:trial_duration_unit].
|
170
|
+
subscription.errors[:trial_duration_unit].should_not be_blank
|
171
171
|
|
172
172
|
['day', 'month'].each do |valid_unit|
|
173
173
|
subscription = BraintreeRails::Subscription.new(:trial_duration_unit => valid_unit, :trial_period => true)
|
174
174
|
subscription.valid?
|
175
|
-
subscription.errors[:trial_duration_unit].
|
175
|
+
subscription.errors[:trial_duration_unit].should be_blank
|
176
176
|
end
|
177
177
|
|
178
178
|
["", "foo", nil].each do |invalid_duration|
|
179
179
|
subscription = BraintreeRails::Subscription.new(:trial_duration_unit => invalid_duration, :trial_period => true)
|
180
180
|
subscription.valid?
|
181
|
-
subscription.errors[:trial_duration_unit].
|
181
|
+
subscription.errors[:trial_duration_unit].should_not be_blank
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
@@ -186,13 +186,13 @@ describe BraintreeRails::Subscription do
|
|
186
186
|
[Date.today, Date.tomorrow, Date.tomorrow.to_s, nil].each do |valid_date|
|
187
187
|
subscription = BraintreeRails::Subscription.new(:first_billing_date => valid_date)
|
188
188
|
subscription.valid?
|
189
|
-
subscription.errors[:first_billing_date].
|
189
|
+
subscription.errors[:first_billing_date].should be_blank
|
190
190
|
end
|
191
191
|
|
192
192
|
[Date.yesterday, "invalid date"].each do |invalid_date|
|
193
193
|
subscription = BraintreeRails::Subscription.new(:first_billing_date => invalid_date)
|
194
194
|
subscription.valid?
|
195
|
-
subscription.errors[:first_billing_date].
|
195
|
+
subscription.errors[:first_billing_date].should_not be_blank
|
196
196
|
end
|
197
197
|
end
|
198
198
|
end
|
@@ -202,7 +202,7 @@ describe BraintreeRails::Subscription do
|
|
202
202
|
subscription = BraintreeRails::Subscription.new('subscription_id')
|
203
203
|
braintree_subscription = Braintree::Subscription.find('subscription_id')
|
204
204
|
stub_braintree_request(:get, '/plans', :body => fixture('plans.xml'))
|
205
|
-
subscription.plan.id.
|
205
|
+
subscription.plan.id.should == braintree_subscription.plan_id
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
@@ -211,7 +211,7 @@ describe BraintreeRails::Subscription do
|
|
211
211
|
subscription = BraintreeRails::Subscription.new('subscription_id')
|
212
212
|
braintree_subscription = Braintree::Subscription.find('subscription_id')
|
213
213
|
stub_braintree_request(:get, '/payment_methods/credit_card_id', :body => fixture('credit_card.xml'))
|
214
|
-
subscription.credit_card.token.
|
214
|
+
subscription.credit_card.token.should == braintree_subscription.payment_method_token
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -221,13 +221,13 @@ describe BraintreeRails::Subscription do
|
|
221
221
|
braintree_subscription = Braintree::Subscription.find('subscription_id')
|
222
222
|
subscription = BraintreeRails::Subscription.new(braintree_subscription)
|
223
223
|
|
224
|
-
subscription.send(association).
|
225
|
-
subscription.send(association).size.
|
224
|
+
subscription.send(association).should respond_to(:each)
|
225
|
+
subscription.send(association).size.should == braintree_subscription.send(association).size
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'does not support create' do
|
229
229
|
subscription = BraintreeRails::Subscription.new('subscription_id')
|
230
|
-
|
230
|
+
expect {subscription.send(association).create}.to raise_error(BraintreeRails::NotSupportedApiException)
|
231
231
|
end
|
232
232
|
end
|
233
233
|
end
|
@@ -241,48 +241,48 @@ describe BraintreeRails::Subscription do
|
|
241
241
|
describe 'save, save!' do
|
242
242
|
it 'should return true when saved' do
|
243
243
|
subscription = BraintreeRails::Subscription.new(subscription_hash)
|
244
|
-
subscription.save.
|
245
|
-
subscription.
|
244
|
+
subscription.save.should be_true
|
245
|
+
subscription.should be_persisted
|
246
246
|
end
|
247
247
|
|
248
248
|
it 'should not throw error when not valid' do
|
249
249
|
subscription = BraintreeRails::Subscription.new
|
250
|
-
subscription.save.
|
251
|
-
subscription.
|
250
|
+
subscription.save.should be_false
|
251
|
+
subscription.should_not be_persisted
|
252
252
|
end
|
253
253
|
|
254
254
|
it 'should return true when saved with bang' do
|
255
255
|
subscription = BraintreeRails::Subscription.new(subscription_hash)
|
256
|
-
subscription.save!.
|
257
|
-
subscription.
|
256
|
+
subscription.save!.should be_true
|
257
|
+
subscription.should be_persisted
|
258
258
|
end
|
259
259
|
|
260
260
|
it 'should throw error when save invalid record with bang' do
|
261
261
|
subscription = BraintreeRails::Subscription.new(:first_name => 'f' * 256)
|
262
|
-
|
263
|
-
subscription.
|
262
|
+
expect { subscription.save! }.to raise_error(BraintreeRails::RecordInvalid)
|
263
|
+
subscription.should_not be_persisted
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
267
267
|
describe 'update_attributes, update_attributes!' do
|
268
268
|
it 'should return true when update_attributes' do
|
269
269
|
subscription = BraintreeRails::Subscription.new(Braintree::Subscription.find('subscription_id'))
|
270
|
-
subscription.update_attributes(:price => '10').
|
270
|
+
subscription.update_attributes(:price => '10').should be_true
|
271
271
|
end
|
272
272
|
|
273
273
|
it 'should not throw error when not valid' do
|
274
274
|
subscription = BraintreeRails::Subscription.new(Braintree::Subscription.find('subscription_id'))
|
275
|
-
subscription.update_attributes(:price => 'f' * 256).
|
275
|
+
subscription.update_attributes(:price => 'f' * 256).should be_false
|
276
276
|
end
|
277
277
|
|
278
278
|
it 'should return true when update_attributesd with bang' do
|
279
279
|
subscription = BraintreeRails::Subscription.new(Braintree::Subscription.find('subscription_id'))
|
280
|
-
subscription.update_attributes!(:price => '10').
|
280
|
+
subscription.update_attributes!(:price => '10').should be_true
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'should throw error when update_attributes invalid record with bang' do
|
284
284
|
subscription = BraintreeRails::Subscription.new(Braintree::Subscription.find('subscription_id'))
|
285
|
-
|
285
|
+
expect { subscription.update_attributes!(:price => 'f' * 256) }.to raise_error(BraintreeRails::RecordInvalid)
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../unit_spec_helper'))
|
2
2
|
|
3
3
|
describe BraintreeRails::Subscriptions do
|
4
4
|
|
@@ -16,7 +16,7 @@ describe BraintreeRails::Subscriptions do
|
|
16
16
|
|
17
17
|
subscriptions = BraintreeRails::Subscriptions.new(BraintreeRails::Plan.new('plan_id'))
|
18
18
|
|
19
|
-
subscriptions.map(&:id).sort.
|
19
|
+
subscriptions.map(&:id).sort.should == braintree_subscriptions.map(&:id).sort
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should load all subscriptions' do
|
@@ -25,7 +25,7 @@ describe BraintreeRails::Subscriptions do
|
|
25
25
|
|
26
26
|
braintree_subscriptions = Braintree::Subscription.search
|
27
27
|
subscriptions = BraintreeRails::Subscriptions.new(nil)
|
28
|
-
subscriptions.map(&:id).sort.
|
28
|
+
subscriptions.map(&:id).sort.should == braintree_subscriptions.map(&:id).sort
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ describe BraintreeRails::Subscriptions do
|
|
33
33
|
it 'has no default options when loading all' do
|
34
34
|
subscriptions = BraintreeRails::Subscriptions.new(nil)
|
35
35
|
subscription = subscriptions.build
|
36
|
-
subscription.attributes.values.compact.
|
36
|
+
subscription.attributes.values.compact.should be_empty
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|