paid 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/.travis.yml +16 -0
- data/History.txt +4 -0
- data/README.md +58 -0
- data/Rakefile +9 -29
- data/VERSION +1 -0
- data/bin/paid-console +7 -0
- data/gemfiles/default-with-activesupport.gemfile +10 -0
- data/gemfiles/json.gemfile +12 -0
- data/gemfiles/yajl.gemfile +12 -0
- data/lib/paid.rb +129 -177
- data/lib/paid/account.rb +14 -1
- data/lib/paid/api_class.rb +336 -0
- data/lib/paid/api_list.rb +47 -0
- data/lib/paid/api_resource.rb +8 -25
- data/lib/paid/api_singleton.rb +5 -0
- data/lib/paid/customer.rb +36 -21
- data/lib/paid/errors/api_error.rb +6 -0
- data/lib/paid/event.rb +22 -1
- data/lib/paid/invoice.rb +16 -21
- data/lib/paid/plan.rb +18 -2
- data/lib/paid/subscription.rb +17 -11
- data/lib/paid/transaction.rb +19 -12
- data/lib/paid/util.rb +53 -106
- data/lib/paid/version.rb +1 -1
- data/paid.gemspec +10 -11
- data/tasks/api_test.rb +187 -0
- data/test/mock_resource.rb +69 -0
- data/test/paid/account_test.rb +41 -4
- data/test/paid/api_class_test.rb +412 -0
- data/test/paid/api_list_test.rb +17 -0
- data/test/paid/api_resource_test.rb +13 -343
- data/test/paid/api_singleton_test.rb +12 -0
- data/test/paid/authentication_test.rb +50 -0
- data/test/paid/customer_test.rb +189 -29
- data/test/paid/event_test.rb +74 -0
- data/test/paid/invoice_test.rb +101 -20
- data/test/paid/plan_test.rb +84 -8
- data/test/paid/status_codes_test.rb +63 -0
- data/test/paid/subscription_test.rb +100 -20
- data/test/paid/transaction_test.rb +110 -37
- data/test/paid/util_test.rb +15 -24
- data/test/test_data.rb +144 -93
- data/test/test_helper.rb +6 -4
- metadata +32 -26
- data/Gemfile.lock +0 -54
- data/README.rdoc +0 -35
- data/lib/data/ca-certificates.crt +0 -0
- data/lib/paid/alias.rb +0 -16
- data/lib/paid/api_operations/create.rb +0 -17
- data/lib/paid/api_operations/delete.rb +0 -11
- data/lib/paid/api_operations/list.rb +0 -17
- data/lib/paid/api_operations/update.rb +0 -57
- data/lib/paid/certificate_blacklist.rb +0 -55
- data/lib/paid/list_object.rb +0 -37
- data/lib/paid/paid_object.rb +0 -187
- data/lib/paid/singleton_api_resource.rb +0 -20
- data/lib/tasks/paid_tasks.rake +0 -4
- data/test/paid/alias_test.rb +0 -22
- data/test/paid/certificate_blacklist_test.rb +0 -18
- data/test/paid/list_object_test.rb +0 -16
- data/test/paid/paid_object_test.rb +0 -27
- data/test/paid/properties_test.rb +0 -103
data/test/paid/customer_test.rb
CHANGED
@@ -2,43 +2,203 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Paid
|
4
4
|
class CustomerTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
@
|
7
|
-
c = Paid::Customer.all.data
|
8
|
-
assert c.kind_of? Array
|
9
|
-
assert c[0].kind_of? Paid::Customer
|
5
|
+
setup do
|
6
|
+
@customer_url = "#{Paid.api_base}/v0/customers"
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
context 'Customer class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "customer_id"
|
12
|
+
@mock.expects(:get).once.with("#{@customer_url}/#{id}", anything, anything).returns(test_response(test_customer))
|
13
|
+
customer = Paid::Customer.retrieve(id)
|
14
|
+
assert(customer.is_a?(Paid::Customer))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be retrieveable by alias' do
|
18
|
+
al = "alias_for_cust"
|
19
|
+
@mock.expects(:get).once.with("#{Paid.api_base}/v0/aliases/#{al}", anything, anything).returns(test_response(test_customer))
|
20
|
+
customer = Paid::Customer.by_alias(al)
|
21
|
+
assert(customer.is_a?(Paid::Customer))
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be retrieveable by external_id' do
|
25
|
+
external_id = "external_id_for_cust"
|
26
|
+
@mock.expects(:get).once.with("#{@customer_url}/by_external_id/#{external_id}", anything, anything).returns(test_response(test_customer))
|
27
|
+
customer = Paid::Customer.by_external_id(external_id)
|
28
|
+
assert(customer.is_a?(Paid::Customer))
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'be createable' do
|
32
|
+
@mock.expects(:post).once.with(@customer_url, anything, test_customer).returns(test_response(test_customer))
|
33
|
+
customer = Paid::Customer.create(test_customer)
|
34
|
+
assert(customer.is_a?(Paid::Customer))
|
35
|
+
assert_equal(test_customer[:id], customer.id)
|
36
|
+
end
|
37
|
+
|
38
|
+
should 'be listable' do
|
39
|
+
@mock.expects(:get).once.returns(test_response(test_customer_list))
|
40
|
+
|
41
|
+
customers = Paid::Customer.all
|
42
|
+
|
43
|
+
assert(customers.is_a?(Paid::APIList))
|
44
|
+
customers.each do |customer|
|
45
|
+
assert(customer.is_a?(Paid::Customer))
|
46
|
+
end
|
47
|
+
end
|
17
48
|
end
|
18
49
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
50
|
+
context 'Customer instance' do
|
51
|
+
should 'be refreshable' do
|
52
|
+
@mock.expects(:get).once.with("#{@customer_url}/#{test_customer[:id]}", anything, anything).returns(test_response(test_customer))
|
53
|
+
customer = Paid::Customer.new(test_customer[:id])
|
54
|
+
customer.refresh
|
55
|
+
assert_equal(test_customer[:name], customer.name)
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'be updateable' do
|
59
|
+
customer = Paid::Customer.new(test_customer)
|
60
|
+
customer.name = "new name"
|
61
|
+
customer.email = "new_email@domain.com"
|
62
|
+
|
63
|
+
@mock.expects(:put).once.with do |url, headers, params|
|
64
|
+
params == customer.changed_attributes && url == "#{@customer_url}/#{customer.id}"
|
65
|
+
end.returns(test_response(test_customer))
|
66
|
+
|
67
|
+
# This should update this instance with test_customer since it was returned
|
68
|
+
customer.save
|
69
|
+
assert_equal(test_customer[:name], customer.name)
|
70
|
+
assert_equal(test_customer[:email], customer.email)
|
71
|
+
end
|
72
|
+
|
73
|
+
should 'be able to generate an invoice' do
|
74
|
+
customer = Paid::Customer.new(test_customer)
|
75
|
+
@mock.expects(:post).once.with("#{@customer_url}/#{customer.id}/generate_invoice", anything, anything).returns(test_response(test_invoice))
|
76
|
+
|
77
|
+
invoice = customer.generate_invoice
|
78
|
+
assert(invoice.is_a?(Paid::Invoice))
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'be able to list invoices' do
|
82
|
+
customer = Paid::Customer.new(test_customer)
|
83
|
+
@mock.expects(:get).once.with("#{Paid.api_base}#{Paid::Invoice.path}?customer=#{customer.id}", anything, anything).returns(test_response(test_invoice_list))
|
84
|
+
|
85
|
+
invoices = customer.invoices
|
86
|
+
assert(invoices.is_a?(Paid::APIList))
|
87
|
+
invoices.each do |invoice|
|
88
|
+
assert(invoice.is_a?(Paid::Invoice))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'be able to list transactions' do
|
93
|
+
customer = Paid::Customer.new(test_customer)
|
94
|
+
@mock.expects(:get).once.with("#{Paid.api_base}#{Paid::Transaction.path}?customer=#{customer.id}", anything, anything).returns(test_response(test_transaction_list))
|
95
|
+
|
96
|
+
transactions = customer.transactions
|
97
|
+
assert(transactions.is_a?(Paid::APIList))
|
98
|
+
transactions.each do |transaction|
|
99
|
+
assert(transaction.is_a?(Paid::Transaction))
|
100
|
+
end
|
101
|
+
end
|
27
102
|
end
|
28
103
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
104
|
+
|
105
|
+
context 'Retrieved Paid::Customer instance' do
|
106
|
+
setup do
|
107
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
108
|
+
@customer = Paid::Customer.retrieve('customer_id')
|
109
|
+
end
|
110
|
+
|
111
|
+
should 'have the id attribute' do
|
112
|
+
assert_equal(test_customer[:id], @customer.id)
|
113
|
+
end
|
114
|
+
|
115
|
+
should 'have the object attribute' do
|
116
|
+
assert_equal(test_customer[:object], @customer.object)
|
117
|
+
end
|
118
|
+
|
119
|
+
should 'have the name attribute' do
|
120
|
+
assert_equal(test_customer[:name], @customer.name)
|
121
|
+
end
|
122
|
+
|
123
|
+
should 'have the email attribute' do
|
124
|
+
assert_equal(test_customer[:email], @customer.email)
|
125
|
+
end
|
126
|
+
|
127
|
+
should 'have the description attribute' do
|
128
|
+
assert_equal(test_customer[:description], @customer.description)
|
129
|
+
end
|
130
|
+
|
131
|
+
should 'have the phone attribute' do
|
132
|
+
assert_equal(test_customer[:phone], @customer.phone)
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'have the address_line1 attribute' do
|
136
|
+
assert_equal(test_customer[:address_line1], @customer.address_line1)
|
137
|
+
end
|
138
|
+
|
139
|
+
should 'have the address_line2 attribute' do
|
140
|
+
assert_equal(test_customer[:address_line2], @customer.address_line2)
|
141
|
+
end
|
142
|
+
|
143
|
+
should 'have the address_city attribute' do
|
144
|
+
assert_equal(test_customer[:address_city], @customer.address_city)
|
145
|
+
end
|
146
|
+
|
147
|
+
should 'have the address_state attribute' do
|
148
|
+
assert_equal(test_customer[:address_state], @customer.address_state)
|
149
|
+
end
|
150
|
+
|
151
|
+
should 'have the address_zip attribute' do
|
152
|
+
assert_equal(test_customer[:address_zip], @customer.address_zip)
|
153
|
+
end
|
154
|
+
|
155
|
+
should 'have the allow_ach attribute' do
|
156
|
+
assert_equal(test_customer[:allow_ach], @customer.allow_ach)
|
157
|
+
end
|
158
|
+
|
159
|
+
should 'have the allow_wire attribute' do
|
160
|
+
assert_equal(test_customer[:allow_wire], @customer.allow_wire)
|
161
|
+
end
|
162
|
+
|
163
|
+
should 'have the allow_check attribute' do
|
164
|
+
assert_equal(test_customer[:allow_check], @customer.allow_check)
|
165
|
+
end
|
166
|
+
|
167
|
+
should 'have the allow_credit_card attribute' do
|
168
|
+
assert_equal(test_customer[:allow_credit_card], @customer.allow_credit_card)
|
169
|
+
end
|
170
|
+
|
171
|
+
should 'have the terms attribute' do
|
172
|
+
assert_equal(test_customer[:terms], @customer.terms)
|
173
|
+
end
|
174
|
+
|
175
|
+
should 'have the billing_type attribute' do
|
176
|
+
assert_equal(test_customer[:billing_type], @customer.billing_type)
|
177
|
+
end
|
178
|
+
|
179
|
+
should 'have the billing_cycle attribute' do
|
180
|
+
assert_equal(test_customer[:billing_cycle], @customer.billing_cycle)
|
181
|
+
end
|
182
|
+
|
183
|
+
should 'have the stripe_customer_id attribute' do
|
184
|
+
assert_equal(test_customer[:stripe_customer_id], @customer.stripe_customer_id)
|
185
|
+
end
|
186
|
+
|
187
|
+
should 'have the external_id attribute' do
|
188
|
+
assert_equal(test_customer[:external_id], @customer.external_id)
|
189
|
+
end
|
190
|
+
|
191
|
+
should 'have & convert the aliases attribute' do
|
192
|
+
assert(@customer.aliases.is_a?(Paid::APIList))
|
193
|
+
assert_equal(test_customer[:aliases][:data], @customer.aliases.data)
|
194
|
+
end
|
195
|
+
|
33
196
|
end
|
34
197
|
|
35
|
-
should
|
36
|
-
|
37
|
-
|
38
|
-
c = Paid::Customer.create
|
39
|
-
@mock.expects(:post).once.returns(test_response(test_invoice))
|
40
|
-
i = c.generate_invoice
|
41
|
-
assert i.kind_of?(Paid::Invoice)
|
198
|
+
should 'be registered' do
|
199
|
+
assert(APIClass.subclasses.include?(Paid::Customer))
|
200
|
+
assert_equal(Paid::Customer, APIClass.subclass_fetch("customer"))
|
42
201
|
end
|
202
|
+
|
43
203
|
end
|
44
204
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class EventTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
@event_url = "#{Paid.api_base}/v0/events"
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'Event class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "event_id"
|
12
|
+
@mock.expects(:get).once.with("#{@event_url}/#{id}", anything, anything).returns(test_response(test_event))
|
13
|
+
event = Paid::Event.retrieve(id)
|
14
|
+
assert(event.is_a?(Paid::Event))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be listable' do
|
18
|
+
@mock.expects(:get).once.returns(test_response(test_event_list))
|
19
|
+
|
20
|
+
events = Paid::Event.all
|
21
|
+
|
22
|
+
assert(events.is_a?(Paid::APIList))
|
23
|
+
events.each do |event|
|
24
|
+
assert(event.is_a?(Paid::Event))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'Event instance' do
|
30
|
+
should 'be refreshable' do
|
31
|
+
@mock.expects(:get).once.with("#{@event_url}/#{test_event[:id]}", anything, anything).returns(test_response(test_event))
|
32
|
+
event = Paid::Event.new(test_event[:id])
|
33
|
+
event.refresh
|
34
|
+
assert_equal(test_event[:type], event.type)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'Retrieved Paid::Event instance' do
|
39
|
+
setup do
|
40
|
+
@mock.expects(:get).once.returns(test_response(test_event))
|
41
|
+
@event = Paid::Event.retrieve('event_id')
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'have the id attribute' do
|
45
|
+
assert_equal(test_event[:id], @event.id)
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'have the object attribute' do
|
49
|
+
assert_equal(test_event[:object], @event.object)
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'have the created_at attribute' do
|
53
|
+
assert_equal(test_event[:created_at], @event.created_at)
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'have the type attribute' do
|
57
|
+
assert_equal(test_event[:type], @event.type)
|
58
|
+
end
|
59
|
+
|
60
|
+
should 'have & convert the data attribute' do
|
61
|
+
assert(@event.data.is_a?(Paid::APIClass))
|
62
|
+
event2 = Paid::Event.new(test_event(test_invoice))
|
63
|
+
assert(event2.data.is_a?(Paid::Invoice))
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'be registered' do
|
69
|
+
assert(APIClass.subclasses.include?(Paid::Event))
|
70
|
+
assert_equal(Paid::Event, APIClass.subclass_fetch("event"))
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/test/paid/invoice_test.rb
CHANGED
@@ -2,32 +2,113 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Paid
|
4
4
|
class InvoiceTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
@
|
7
|
-
i = Paid::Invoice.retrieve('in_test_invoice')
|
8
|
-
assert_equal 'inv_test_invoice', i.id
|
5
|
+
setup do
|
6
|
+
@invoice_url = "#{Paid.api_base}/v0/invoices"
|
9
7
|
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
context 'Invoice class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "invoice_id"
|
12
|
+
@mock.expects(:get).once.with("#{@invoice_url}/#{id}", anything, anything).returns(test_response(test_invoice))
|
13
|
+
invoice = Paid::Invoice.retrieve(id)
|
14
|
+
assert(invoice.is_a?(Paid::Invoice))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@invoice_url, anything, test_invoice).returns(test_response(test_invoice))
|
19
|
+
invoice = Paid::Invoice.create(test_invoice)
|
20
|
+
assert(invoice.is_a?(Paid::Invoice))
|
21
|
+
assert_equal(test_invoice[:id], invoice.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_invoice_list))
|
26
|
+
|
27
|
+
invoices = Paid::Invoice.all
|
28
|
+
|
29
|
+
assert(invoices.is_a?(Paid::APIList))
|
30
|
+
invoices.each do |invoice|
|
31
|
+
assert(invoice.is_a?(Paid::Invoice))
|
32
|
+
end
|
33
|
+
end
|
15
34
|
end
|
16
35
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
36
|
+
context 'Invoice instance' do
|
37
|
+
setup do
|
38
|
+
@invoice = Paid::Invoice.new(test_invoice[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'be refreshable' do
|
42
|
+
@mock.expects(:get).once.with("#{@invoice_url}/#{@invoice.id}", anything, anything).returns(test_response(test_invoice))
|
43
|
+
@invoice.refresh
|
44
|
+
assert_equal(test_invoice[:summary], @invoice.summary)
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'be able to mark as paid' do
|
48
|
+
via = :ach
|
49
|
+
@mock.expects(:post).once.with("#{@invoice_url}/#{@invoice.id}/mark_as_paid", anything, { :via => via }).returns(test_response(test_invoice))
|
50
|
+
|
51
|
+
@invoice.mark_as_paid(:via => via)
|
52
|
+
assert_equal(test_invoice[:summary], @invoice.summary)
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'be issuable' do
|
56
|
+
@mock.expects(:post).once.with("#{@invoice_url}/#{@invoice.id}/issue", anything, anything).returns(test_response(test_invoice))
|
57
|
+
|
58
|
+
@invoice.issue
|
59
|
+
assert_equal(test_invoice[:summary], @invoice.summary)
|
60
|
+
end
|
23
61
|
end
|
24
62
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
63
|
+
|
64
|
+
context 'Retrieved Paid::Invoice instance' do
|
65
|
+
setup do
|
66
|
+
@mock.expects(:get).once.returns(test_response(test_invoice))
|
67
|
+
@invoice = Paid::Invoice.retrieve('invoice_id')
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'have the id attribute' do
|
71
|
+
assert_equal(test_invoice[:id], @invoice.id)
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'have the object attribute' do
|
75
|
+
assert_equal(test_invoice[:object], @invoice.object)
|
76
|
+
end
|
77
|
+
|
78
|
+
should 'have the summary attribute' do
|
79
|
+
assert_equal(test_invoice[:summary], @invoice.summary)
|
80
|
+
end
|
81
|
+
|
82
|
+
should 'have the chase_schedule attribute' do
|
83
|
+
assert_equal(test_invoice[:chase_schedule], @invoice.chase_schedule)
|
84
|
+
end
|
85
|
+
|
86
|
+
should 'have the next_chase_on attribute' do
|
87
|
+
assert_equal(test_invoice[:next_chase_on], @invoice.next_chase_on)
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'have the customer attribute' do
|
91
|
+
assert_equal(test_invoice[:customer], @invoice.customer)
|
92
|
+
end
|
93
|
+
|
94
|
+
should 'have the issued_at attribute' do
|
95
|
+
assert_equal(test_invoice[:issued_at], @invoice.issued_at)
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'have the terms attribute' do
|
99
|
+
assert_equal(test_invoice[:terms], @invoice.terms)
|
100
|
+
end
|
101
|
+
|
102
|
+
should 'have the url attribute' do
|
103
|
+
assert_equal(test_invoice[:url], @invoice.url)
|
104
|
+
end
|
105
|
+
|
31
106
|
end
|
107
|
+
|
108
|
+
should 'be registered' do
|
109
|
+
assert(APIClass.subclasses.include?(Paid::Invoice))
|
110
|
+
assert_equal(Paid::Invoice, APIClass.subclass_fetch("invoice"))
|
111
|
+
end
|
112
|
+
|
32
113
|
end
|
33
114
|
end
|
data/test/paid/plan_test.rb
CHANGED
@@ -2,16 +2,92 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Paid
|
4
4
|
class PlanTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
@
|
7
|
-
i = Paid::Plan.retrieve('in_test_plan')
|
8
|
-
assert_equal 'pl_test_plan', i.id
|
5
|
+
setup do
|
6
|
+
@plan_url = "#{Paid.api_base}/v0/plans"
|
9
7
|
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
context 'Plan class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "plan_id"
|
12
|
+
@mock.expects(:get).once.with("#{@plan_url}/#{id}", anything, anything).returns(test_response(test_plan))
|
13
|
+
plan = Paid::Plan.retrieve(id)
|
14
|
+
assert(plan.is_a?(Paid::Plan))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@plan_url, anything, test_plan).returns(test_response(test_plan))
|
19
|
+
plan = Paid::Plan.create(test_plan)
|
20
|
+
assert(plan.is_a?(Paid::Plan))
|
21
|
+
assert_equal(test_plan[:id], plan.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_plan_list))
|
26
|
+
|
27
|
+
plans = Paid::Plan.all
|
28
|
+
|
29
|
+
assert(plans.is_a?(Paid::APIList))
|
30
|
+
plans.each do |plan|
|
31
|
+
assert(plan.is_a?(Paid::Plan))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'Plan instance' do
|
37
|
+
should 'be refreshable' do
|
38
|
+
@mock.expects(:get).once.with("#{@plan_url}/#{test_plan[:id]}", anything, anything).returns(test_response(test_plan))
|
39
|
+
plan = Paid::Plan.new(test_plan[:id])
|
40
|
+
plan.refresh
|
41
|
+
assert_equal(test_plan[:name], plan.name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
context 'Retrieved Paid::Plan instance' do
|
47
|
+
setup do
|
48
|
+
@mock.expects(:get).once.returns(test_response(test_plan))
|
49
|
+
@plan = Paid::Plan.retrieve('plan_id')
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'have the id attribute' do
|
53
|
+
assert_equal(test_plan[:id], @plan.id)
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'have the object attribute' do
|
57
|
+
assert_equal(test_plan[:object], @plan.object)
|
58
|
+
end
|
59
|
+
|
60
|
+
should 'have the created_at attribute' do
|
61
|
+
assert_equal(test_plan[:created_at], @plan.created_at)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'have the description attribute' do
|
65
|
+
assert_equal(test_plan[:description], @plan.description)
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'have the name attribute' do
|
69
|
+
assert_equal(test_plan[:name], @plan.name)
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'have the interval attribute' do
|
73
|
+
assert_equal(test_plan[:interval], @plan.interval)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'have the interval_count attribute' do
|
77
|
+
assert_equal(test_plan[:interval_count], @plan.interval_count)
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'have the amount attribute' do
|
81
|
+
assert_equal(test_plan[:amount], @plan.amount)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
should 'be registered' do
|
87
|
+
assert(APIClass.subclasses.include?(Paid::Plan))
|
88
|
+
assert_equal(Paid::Plan, APIClass.subclass_fetch("plan"))
|
15
89
|
end
|
90
|
+
|
91
|
+
|
16
92
|
end
|
17
93
|
end
|