recurly 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of recurly might be problematic. Click here for more details.
- data/README.md +53 -7
- data/lib/recurly/account.rb +60 -7
- data/lib/recurly/base.rb +60 -43
- data/lib/recurly/billing_info.rb +2 -3
- data/lib/recurly/charge.rb +7 -2
- data/lib/recurly/credit.rb +7 -2
- data/lib/recurly/formats/xml_with_pagination.rb +38 -0
- data/lib/recurly/invoice.rb +17 -2
- data/lib/recurly/plan.rb +1 -4
- data/lib/recurly/subscription.rb +10 -11
- data/lib/recurly/transaction.rb +16 -1
- data/lib/recurly/version.rb +3 -0
- data/lib/recurly.rb +32 -9
- data/spec/integration/account_spec.rb +92 -0
- data/spec/integration/billing_info_spec.rb +66 -0
- data/spec/integration/charge_spec.rb +82 -0
- data/spec/integration/credit_spec.rb +87 -0
- data/spec/integration/invoice_spec.rb +75 -0
- data/spec/integration/plan_spec.rb +85 -0
- data/spec/integration/subscription_spec.rb +90 -0
- data/spec/integration/transaction_spec.rb +116 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/spec_settings.yml.example +3 -0
- data/spec/support/factory.rb +204 -0
- data/spec/support/spec_settings.rb +36 -0
- data/spec/support/vcr.rb +11 -0
- metadata +112 -52
- data/Manifest +0 -23
- data/Rakefile +0 -14
- data/recurly.gemspec +0 -31
- data/test/account_test.rb +0 -41
- data/test/billing_info_test.rb +0 -28
- data/test/charge_test.rb +0 -30
- data/test/credit_test.rb +0 -30
- data/test/plan_test.rb +0 -18
- data/test/subscription_test.rb +0 -87
- data/test/test_helper.rb +0 -44
- data/test/transaction_test.rb +0 -19
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe BillingInfo do
|
5
|
+
# version accounts based on this current files modification dates
|
6
|
+
timestamp = File.mtime(__FILE__).to_i
|
7
|
+
|
8
|
+
def verify_billing_info(billing_info, billing_attributes)
|
9
|
+
# check the billing data fields
|
10
|
+
billing_info.first_name.should == billing_attributes[:first_name]
|
11
|
+
billing_info.last_name.should == billing_attributes[:last_name]
|
12
|
+
billing_info.address1.should == billing_attributes[:address1]
|
13
|
+
billing_info.city.should == billing_attributes[:city]
|
14
|
+
billing_info.state.should == billing_attributes[:state]
|
15
|
+
billing_info.zip.should == billing_attributes[:zip]
|
16
|
+
|
17
|
+
# check the credit card fields
|
18
|
+
billing_info.credit_card.last_four.should == billing_attributes[:credit_card][:number]
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#create" do
|
22
|
+
use_vcr_cassette "billing/create/#{timestamp}"
|
23
|
+
let(:account){ Factory.create_account("billing-create-#{timestamp}") }
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
@billing_attributes = Factory.billing_attributes({
|
27
|
+
:account_code => account.account_code,
|
28
|
+
:first_name => account.first_name,
|
29
|
+
:last_name => account.last_name
|
30
|
+
})
|
31
|
+
|
32
|
+
@billing_info = BillingInfo.create(@billing_attributes)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should successfully create the billing info record" do
|
36
|
+
@billing_info.updated_at.should_not be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set the correct billing_info on the server " do
|
40
|
+
billing_info = BillingInfo.find(account.account_code)
|
41
|
+
verify_billing_info(billing_info, @billing_attributes)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#find" do
|
46
|
+
use_vcr_cassette "billing/find/#{timestamp}"
|
47
|
+
let(:account){ Factory.create_account_with_billing_info("billing-find-#{timestamp}") }
|
48
|
+
|
49
|
+
before(:each) do
|
50
|
+
@billing_attributes = Factory.billing_attributes({
|
51
|
+
:account_code => account.account_code,
|
52
|
+
:first_name => account.first_name,
|
53
|
+
:last_name => account.last_name
|
54
|
+
})
|
55
|
+
|
56
|
+
@billing_info = BillingInfo.find(account.account_code)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return the correct billing_info from the server" do
|
60
|
+
billing_info = BillingInfo.find(account.account_code)
|
61
|
+
verify_billing_info(billing_info, @billing_attributes)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe Charge do
|
5
|
+
# version accounts based on this current files modification dates
|
6
|
+
timestamp = File.mtime(__FILE__).to_i
|
7
|
+
|
8
|
+
describe "create a charge" do
|
9
|
+
use_vcr_cassette "charge/create/#{timestamp}"
|
10
|
+
|
11
|
+
let(:account) { Factory.create_account_with_billing_info("charge-create-#{timestamp}") }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
charge = Factory.create_charge account.account_code,
|
15
|
+
:amount => 2.50,
|
16
|
+
:description => "virtual cow maintence fee"
|
17
|
+
|
18
|
+
@charge = Charge.lookup(account.account_code, charge.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should save successfully" do
|
22
|
+
@charge.created_at.should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the amount" do
|
26
|
+
@charge.amount_in_cents.should == 250
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set the description" do
|
30
|
+
@charge.description.should == "virtual cow maintence fee"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "list charges for an account" do
|
35
|
+
use_vcr_cassette "charge/list/#{timestamp}"
|
36
|
+
|
37
|
+
let(:account) { Factory.create_account("charge-list-#{timestamp}") }
|
38
|
+
before(:each) do
|
39
|
+
Factory.create_charge(account.account_code)
|
40
|
+
Factory.create_charge(account.account_code)
|
41
|
+
Factory.create_charge(account.account_code)
|
42
|
+
|
43
|
+
@charges = Charge.list(account.account_code)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return all the transactions" do
|
47
|
+
@charges.length.should == 3
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should also be available via Account#charges" do
|
51
|
+
account.charges.should == @charges
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "lookup a charge" do
|
57
|
+
use_vcr_cassette "charge/lookup/#{timestamp}"
|
58
|
+
|
59
|
+
let(:account) { Factory.create_account("charge-lookup-#{timestamp}") }
|
60
|
+
|
61
|
+
before(:each) do
|
62
|
+
charge = Factory.create_charge account.account_code,
|
63
|
+
:amount => 13.15,
|
64
|
+
:description => "inconvenience fee"
|
65
|
+
|
66
|
+
@charge = Charge.lookup(account.account_code, charge.id)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return the correct amount" do
|
70
|
+
@charge.amount_in_cents.should == 1315
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return the correct description" do
|
74
|
+
@charge.description.should == "inconvenience fee"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should also be available via Account#lookup_charge" do
|
78
|
+
account.lookup_charge(@charge.id).should == @charge
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe Credit do
|
5
|
+
# version accounts based on this current files modification dates
|
6
|
+
timestamp = File.mtime(__FILE__).to_i
|
7
|
+
|
8
|
+
describe "create a credit" do
|
9
|
+
use_vcr_cassette "credit/create/#{timestamp}"
|
10
|
+
|
11
|
+
let(:account){ Factory.create_account("credit-create-#{timestamp}") }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
credit = Factory.create_credit account.account_code,
|
15
|
+
:amount => 10.05,
|
16
|
+
:description => "free moniez"
|
17
|
+
|
18
|
+
@credit = Credit.lookup(account.account_code, credit.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should save successfully" do
|
22
|
+
@credit.created_at.should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the amount" do
|
26
|
+
@credit.amount_in_cents.should == -1005
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set the description" do
|
30
|
+
@credit.description.should == "free moniez"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "list credits for an account" do
|
35
|
+
use_vcr_cassette "credit/list/#{timestamp}"
|
36
|
+
let(:account){ Factory.create_account("credit-list-#{timestamp}") }
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
Factory.create_credit(account.account_code, :amount => 1, :description => "one")
|
40
|
+
Factory.create_credit(account.account_code, :amount => 2, :description => "two")
|
41
|
+
Factory.create_credit(account.account_code, :amount => 3, :description => "three")
|
42
|
+
@credits = Credit.list(account.account_code)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return results" do
|
46
|
+
@credits.length.should == 3
|
47
|
+
end
|
48
|
+
|
49
|
+
it "amounts should be correct" do
|
50
|
+
@credits.map{|c| c.amount_in_cents}.should == [-300, -200, -100]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "descriptions should be correct" do
|
54
|
+
@credits.map{|c| c.description}.should == ["three", "two", "one"]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should also be available via Account#credits" do
|
58
|
+
account.credits.should == @credits
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "lookup a credit" do
|
63
|
+
use_vcr_cassette "credit/lookup/#{timestamp}"
|
64
|
+
let(:account) { Factory.create_account("credit-lookup-#{timestamp}") }
|
65
|
+
|
66
|
+
before(:each) do
|
67
|
+
credit = Factory.create_credit account.account_code,
|
68
|
+
:amount => 13.15,
|
69
|
+
:description => "free moniez 4 u"
|
70
|
+
@credit = Credit.lookup(account.account_code, credit.id)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return the correct amount" do
|
74
|
+
@credit.amount_in_cents.should == -1315
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return the correct description" do
|
78
|
+
@credit.description.should == "free moniez 4 u"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should also be available via Account#lookup_credit" do
|
82
|
+
account.lookup_credit(@credit.id).should == @credit
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe Invoice do
|
5
|
+
# version accounts based on this current files modification dates
|
6
|
+
timestamp = File.mtime(__FILE__).to_i
|
7
|
+
|
8
|
+
def create_sample_charges(account)
|
9
|
+
Factory.create_charge(account.account_code, :amount => 10.00)
|
10
|
+
Factory.create_charge(account.account_code, :amount => 15.00)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "creating an invoice" do
|
14
|
+
context "with charges" do
|
15
|
+
use_vcr_cassette "invoice/create/#{timestamp}"
|
16
|
+
|
17
|
+
let(:account) { Factory.create_account_with_billing_info("invoice-create-#{timestamp}") }
|
18
|
+
before(:each) do
|
19
|
+
create_sample_charges(account)
|
20
|
+
@invoice = Invoice.create(:account_code => account.account_code)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should save successfully" do
|
24
|
+
@invoice.total_in_cents.should == 2500
|
25
|
+
@invoice.line_items.length.should == 2
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "listing invoices" do
|
31
|
+
use_vcr_cassette "invoice/list/#{timestamp}"
|
32
|
+
|
33
|
+
let(:account) { Factory.create_account_with_billing_info("invoice-list-#{timestamp}") }
|
34
|
+
before(:each) do
|
35
|
+
Factory.create_charge(account.account_code, :amount => 1.00)
|
36
|
+
invoice = Invoice.create(:account_code => account.account_code)
|
37
|
+
|
38
|
+
Factory.create_charge(account.account_code, :amount => 3.00)
|
39
|
+
invoice = Invoice.create(:account_code => account.account_code)
|
40
|
+
|
41
|
+
@invoices = Invoice.list(account.account_code)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the list of invoices" do
|
45
|
+
@invoices.length.should == 2
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should also be available via Account#invoices" do
|
49
|
+
account.invoices.should == @invoices
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "looking up an invoice" do
|
55
|
+
use_vcr_cassette "invoice/lookup/#{timestamp}"
|
56
|
+
|
57
|
+
let(:account) { Factory.create_account_with_billing_info("invoice-lookup-#{timestamp}") }
|
58
|
+
before(:each) do
|
59
|
+
Factory.create_charge(account.account_code, :amount => 15.00)
|
60
|
+
invoice = Invoice.create(:account_code => account.account_code)
|
61
|
+
@invoice = Invoice.lookup(account.account_code, invoice.id)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return the invoice" do
|
65
|
+
@invoice.total_in_cents.should == 1500
|
66
|
+
@invoice.line_items.length.should == 1
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should also be available via Account#lookup_invoice" do
|
70
|
+
account.lookup_invoice(@invoice.id).should == @invoice
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe Plan do
|
5
|
+
describe "list all plans" do
|
6
|
+
use_vcr_cassette "plan/all"
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@paid = Factory.paid_plan
|
10
|
+
@trial = Factory.trial_plan
|
11
|
+
@plans = Plan.all
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return a list result" do
|
15
|
+
@plans.should be_an_instance_of(Array)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return the paid plan" do
|
19
|
+
@plans.should include(@paid)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return the trial plan" do
|
23
|
+
@plans.should include(@trial)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "find plan" do
|
29
|
+
use_vcr_cassette 'plan/find'
|
30
|
+
before(:each) do
|
31
|
+
@paid = Factory.paid_plan
|
32
|
+
@trial = Factory.trial_plan
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return the paid plan" do
|
36
|
+
plan = Plan.find(@paid.plan_code)
|
37
|
+
plan.should_not be_nil
|
38
|
+
plan.should == @paid
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the trial plan" do
|
42
|
+
plan = Plan.find(@trial.plan_code)
|
43
|
+
plan.should_not be_nil
|
44
|
+
plan.should == @trial
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "update a plan" do
|
49
|
+
use_vcr_cassette 'plan/update'
|
50
|
+
|
51
|
+
# grabs a fresh test_plan
|
52
|
+
def test_plan
|
53
|
+
Plan.find("test")
|
54
|
+
end
|
55
|
+
|
56
|
+
before(:each) do
|
57
|
+
|
58
|
+
begin
|
59
|
+
@test_plan = test_plan
|
60
|
+
rescue ActiveResource::ResourceNotFound => e
|
61
|
+
Plan.new({
|
62
|
+
:plan_code => "test",
|
63
|
+
:name => "Test Plan",
|
64
|
+
:unit_amount_in_cents => 100,
|
65
|
+
:plan_interval_length => 1,
|
66
|
+
:plan_interval_unit => "months",
|
67
|
+
:trial_interval_length => 0,
|
68
|
+
:trial_interval_unit => "months"
|
69
|
+
}).save!
|
70
|
+
@test_plan = test_plan
|
71
|
+
end
|
72
|
+
|
73
|
+
# double the price
|
74
|
+
@test_plan.unit_amount_in_cents = 200
|
75
|
+
@test_plan.save!
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should update the plan" do
|
79
|
+
@test_plan = test_plan
|
80
|
+
@test_plan.unit_amount_in_cents.should == 200
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe Subscription do
|
5
|
+
# version accounts based on this current files modification dates
|
6
|
+
timestamp = File.mtime(__FILE__).to_i
|
7
|
+
|
8
|
+
describe "#create" do
|
9
|
+
use_vcr_cassette "subscription/create/#{timestamp}"
|
10
|
+
|
11
|
+
let(:account){ Factory.create_account("subscription-create-#{timestamp}") }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@subscription = Factory.create_subscription(account, :paid)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create the subscription successfully" do
|
18
|
+
@subscription.should_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not be canceled" do
|
22
|
+
@subscription.canceled_at.should be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be active" do
|
26
|
+
@subscription.state.should == "active"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be started" do
|
30
|
+
@subscription.current_period_started_at.should_not be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#update" do
|
35
|
+
use_vcr_cassette "subscription/update/#{timestamp}"
|
36
|
+
|
37
|
+
let(:account){ Factory.create_account("subscription-update-#{timestamp}") }
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
Factory.create_subscription(account, :paid)
|
41
|
+
@subscription = Subscription.find(account.account_code)
|
42
|
+
|
43
|
+
@subscription.change('now', :quantity => 2)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should update the subscription quantity" do
|
47
|
+
Subscription.find(account.account_code).quantity.should == 2
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#cancel" do
|
52
|
+
use_vcr_cassette "subscription/cancel/#{timestamp}"
|
53
|
+
|
54
|
+
let(:account){ Factory.create_account("subscription-cancel-#{timestamp}") }
|
55
|
+
before(:each) do
|
56
|
+
Factory.create_subscription(account, :paid)
|
57
|
+
@subscription = Subscription.find(account.account_code)
|
58
|
+
|
59
|
+
# cancel subscription
|
60
|
+
@subscription.cancel(account.account_code)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should mark the subscription state as canceled" do
|
64
|
+
Subscription.find(account.account_code).state.should == "canceled"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should mark the subscription canceled_at" do
|
68
|
+
Subscription.find(account.account_code).canceled_at.should_not be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#refund" do
|
73
|
+
use_vcr_cassette "subscription/refund/#{timestamp}"
|
74
|
+
|
75
|
+
let(:account){ Factory.create_account("subscription-refund-#{timestamp}") }
|
76
|
+
|
77
|
+
before(:each) do
|
78
|
+
Factory.create_subscription(account, :paid)
|
79
|
+
@subscription = Subscription.find(account.account_code)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should remove the subscription entry" do
|
83
|
+
@subscription.refund(:full)
|
84
|
+
expect {
|
85
|
+
Subscription.find(account.account_code)
|
86
|
+
}.to raise_error(ActiveResource::ResourceNotFound)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Recurly
|
4
|
+
describe Transaction do
|
5
|
+
# version accounts based on this current files modification dates
|
6
|
+
timestamp = File.mtime(__FILE__).to_i
|
7
|
+
|
8
|
+
describe "create new transaction" do
|
9
|
+
context "on an new account" do
|
10
|
+
use_vcr_cassette "transaction/create-no-account/#{timestamp}"
|
11
|
+
let(:account_code) { "transaction-create-with-accout-#{timestamp}" }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@transaction = Factory.create_full_transaction account_code,
|
15
|
+
:amount_in_cents => 700,
|
16
|
+
:description => "setup fee of 7 dollarz"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should save successfully" do
|
20
|
+
@transaction.status.should == "success"
|
21
|
+
@transaction.errors.should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with an existing account" do
|
26
|
+
use_vcr_cassette "transaction/create-with-account/#{timestamp}"
|
27
|
+
let(:account) { Factory.create_account_with_billing_info("transaction-create-with-account-#{timestamp}") }
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
@transaction = Factory.create_transaction account.account_code,
|
31
|
+
:amount_in_cents => 700,
|
32
|
+
:description => "test transaction for $7"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should save successfully" do
|
36
|
+
@transaction.status.should == "success"
|
37
|
+
@transaction.errors.should be_empty
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "find all transactions" do
|
43
|
+
use_vcr_cassette "transaction/all/#{timestamp}"
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
@transactions = Transaction.all
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be successful" do
|
50
|
+
@transactions.should be_an_instance_of(Array)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "list account transactions" do
|
55
|
+
context "empty transactions" do
|
56
|
+
use_vcr_cassette "transaction/list-empty/#{timestamp}"
|
57
|
+
let(:account) { Factory.create_account_with_billing_info("transaction-list-empty-#{timestamp}") }
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
@transactions = Transaction.list(account.account_code)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return an empty array of transactions" do
|
64
|
+
@transactions.should be_empty
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with transactions" do
|
69
|
+
use_vcr_cassette "transaction/list-filled/#{timestamp}"
|
70
|
+
let(:account) { Factory.create_account_with_billing_info("transaction-list-filled-#{timestamp}") }
|
71
|
+
|
72
|
+
before(:each) do
|
73
|
+
Factory.create_transaction account.account_code, :amount_in_cents => 100, :description => "one"
|
74
|
+
Factory.create_transaction account.account_code, :amount_in_cents => 200, :description => "two"
|
75
|
+
Factory.create_transaction account.account_code, :amount_in_cents => 300, :description => "three"
|
76
|
+
|
77
|
+
@successful_transactions = Transaction.list(account.account_code, :success)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return a list of transactions made on the account" do
|
81
|
+
@successful_transactions.length.should == 3
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should also be available via Account#transactions" do
|
85
|
+
account.transactions(:success).should == @successful_transactions
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "lookup account transaction" do
|
92
|
+
use_vcr_cassette "transaction/lookup/#{timestamp}"
|
93
|
+
let(:account) { Factory.create_account_with_billing_info("transaction-lookup-#{timestamp}") }
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
t1 = Factory.create_transaction account.account_code, :amount_in_cents => 100, :description => "one"
|
97
|
+
t2 = Factory.create_transaction account.account_code, :amount_in_cents => 200, :description => "two"
|
98
|
+
t3 = Factory.create_transaction account.account_code, :amount_in_cents => 300, :description => "three"
|
99
|
+
|
100
|
+
@transaction1 = Transaction.lookup(account.account_code, t1.id)
|
101
|
+
@transaction2 = Transaction.lookup(account.account_code, t2.id)
|
102
|
+
@transaction3 = Transaction.lookup(account.account_code, t3.id)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should the transaction details" do
|
106
|
+
@transaction2.amount_in_cents.should == 200
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should also be available via Account#lookup_transaction" do
|
110
|
+
account.lookup_transaction(@transaction3.id).should == @transaction3
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require "bundler"
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/../lib/recurly'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
# loads the settings from yml
|
13
|
+
Recurly::SpecSettings.reload!
|
14
|
+
|
15
|
+
# setup recurly authentication details for testing
|
16
|
+
Recurly.configure do |c|
|
17
|
+
c.username = Recurly::SpecSettings["username"]
|
18
|
+
c.password = Recurly::SpecSettings["password"]
|
19
|
+
c.site = Recurly::SpecSettings["site"]
|
20
|
+
end
|