braintree 1.1.3 → 1.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.
- data/lib/braintree.rb +2 -0
- data/lib/braintree/advanced_search.rb +69 -0
- data/lib/braintree/configuration.rb +2 -2
- data/lib/braintree/credit_card.rb +2 -1
- data/lib/braintree/subscription.rb +50 -1
- data/lib/braintree/subscription_search.rb +10 -0
- data/lib/braintree/transparent_redirect.rb +8 -5
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/xml/generator.rb +7 -2
- data/lib/ssl/{valicert_ca.crt → sandbox_braintreegateway_com.ca.crt} +1 -0
- data/lib/ssl/www_braintreegateway_com.ca.crt +202 -0
- data/spec/integration/braintree/credit_card_spec.rb +27 -35
- data/spec/integration/braintree/customer_spec.rb +37 -36
- data/spec/integration/braintree/http_spec.rb +17 -0
- data/spec/integration/braintree/subscription_spec.rb +244 -3
- data/spec/integration/braintree/transaction_spec.rb +9 -18
- data/spec/integration/braintree/transparent_redirect_spec.rb +21 -0
- data/spec/integration/spec_helper.rb +0 -23
- data/spec/spec_helper.rb +34 -0
- data/spec/support/matchers/include_on_any_page.rb +24 -0
- data/spec/unit/braintree/configuration_spec.rb +3 -3
- data/spec/unit/braintree/credit_card_spec.rb +1 -1
- data/spec/unit/braintree/customer_spec.rb +1 -1
- data/spec/unit/braintree/paged_collection_spec.rb +50 -0
- data/spec/unit/braintree/subscription_search_spec.rb +35 -0
- data/spec/unit/braintree/subscription_spec.rb +10 -0
- data/spec/unit/braintree/transaction_spec.rb +1 -1
- data/spec/unit/braintree/transparent_redirect_spec.rb +8 -2
- data/spec/unit/braintree/xml_spec.rb +5 -0
- metadata +11 -5
@@ -207,7 +207,8 @@ describe Braintree::CreditCard do
|
|
207
207
|
:customer_id => customer.id
|
208
208
|
}
|
209
209
|
}
|
210
|
-
|
210
|
+
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
211
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::CreditCard.create_credit_card_url, tr_data, params)
|
211
212
|
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
212
213
|
result.success?.should == true
|
213
214
|
credit_card = result.credit_card
|
@@ -234,7 +235,8 @@ describe Braintree::CreditCard do
|
|
234
235
|
:customer_id => customer.id
|
235
236
|
}
|
236
237
|
}
|
237
|
-
|
238
|
+
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
239
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::CreditCard.create_credit_card_url, tr_data, params)
|
238
240
|
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
239
241
|
result.success?.should == false
|
240
242
|
result.params[:customer_id] == customer.id
|
@@ -439,7 +441,8 @@ describe Braintree::CreditCard do
|
|
439
441
|
:token => new_token
|
440
442
|
}
|
441
443
|
}
|
442
|
-
|
444
|
+
tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
445
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::CreditCard.update_credit_card_url, tr_data, params)
|
443
446
|
result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
|
444
447
|
result.success?.should == true
|
445
448
|
credit_card = result.credit_card
|
@@ -578,6 +581,27 @@ describe Braintree::CreditCard do
|
|
578
581
|
credit_card.expiration_date.should == "05/2012"
|
579
582
|
end
|
580
583
|
|
584
|
+
it "returns associated subscriptions with the credit card" do
|
585
|
+
customer = Braintree::Customer.create.customer
|
586
|
+
credit_card = Braintree::CreditCard.create(
|
587
|
+
:customer_id => customer.id,
|
588
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
589
|
+
:expiration_date => "05/2012"
|
590
|
+
).credit_card
|
591
|
+
|
592
|
+
subscription = Braintree::Subscription.create(
|
593
|
+
:payment_method_token => credit_card.token,
|
594
|
+
:plan_id => "integration_trialless_plan",
|
595
|
+
:price => "1.00"
|
596
|
+
).subscription
|
597
|
+
|
598
|
+
found_card = Braintree::CreditCard.find(credit_card.token)
|
599
|
+
found_card.subscriptions.first.id.should == subscription.id
|
600
|
+
found_card.subscriptions.first.plan_id.should == "integration_trialless_plan"
|
601
|
+
found_card.subscriptions.first.payment_method_token.should == credit_card.token
|
602
|
+
found_card.subscriptions.first.price.should == BigDecimal.new("1.00")
|
603
|
+
end
|
604
|
+
|
581
605
|
it "raises a NotFoundError exception if payment method cannot be found" do
|
582
606
|
expect do
|
583
607
|
Braintree::CreditCard.find("invalid-token")
|
@@ -827,36 +851,4 @@ describe Braintree::CreditCard do
|
|
827
851
|
end.to raise_error(Braintree::ValidationsFailed)
|
828
852
|
end
|
829
853
|
end
|
830
|
-
|
831
|
-
def create_credit_card_via_tr(regular_params, tr_params = {})
|
832
|
-
response = nil
|
833
|
-
Net::HTTP.start("localhost", Braintree::Configuration.port) do |http|
|
834
|
-
request = Net::HTTP::Post.new("/" + Braintree::CreditCard.create_credit_card_url.split("/", 4)[3])
|
835
|
-
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
836
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_params))
|
837
|
-
request.body = Braintree::Util.hash_to_query_string({:tr_data => tr_data}.merge(regular_params))
|
838
|
-
response = http.request(request)
|
839
|
-
end
|
840
|
-
if response.code.to_i == 303
|
841
|
-
query_string = response["Location"].split("?", 2).last
|
842
|
-
else
|
843
|
-
raise "did not receive a valid tr response: #{response.body[0,1000].inspect}"
|
844
|
-
end
|
845
|
-
end
|
846
|
-
|
847
|
-
def update_credit_card_via_tr(regular_params, tr_params = {})
|
848
|
-
response = nil
|
849
|
-
Net::HTTP.start("localhost", Braintree::Configuration.port) do |http|
|
850
|
-
request = Net::HTTP::Post.new("/" + Braintree::CreditCard.update_credit_card_url.split("/", 4)[3])
|
851
|
-
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
852
|
-
tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_params))
|
853
|
-
request.body = Braintree::Util.hash_to_query_string({:tr_data => tr_data}.merge(regular_params))
|
854
|
-
response = http.request(request)
|
855
|
-
end
|
856
|
-
if response.code.to_i == 303
|
857
|
-
query_string = response["Location"].split("?", 2).last
|
858
|
-
else
|
859
|
-
raise "did not receive a valid tr response: #{response.body[0,1000].inspect}"
|
860
|
-
end
|
861
|
-
end
|
862
854
|
end
|
@@ -416,8 +416,11 @@ describe Braintree::Customer do
|
|
416
416
|
:website => "www.johndoe.com"
|
417
417
|
}
|
418
418
|
}
|
419
|
-
|
419
|
+
|
420
|
+
tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
|
421
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::Customer.create_customer_url, tr_data, params)
|
420
422
|
result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
|
423
|
+
|
421
424
|
result.success?.should == true
|
422
425
|
customer = result.customer
|
423
426
|
customer.first_name.should == "John"
|
@@ -443,8 +446,11 @@ describe Braintree::Customer do
|
|
443
446
|
:website => "www.johndoe.com"
|
444
447
|
}
|
445
448
|
}
|
446
|
-
|
449
|
+
|
450
|
+
tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
451
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::Customer.create_customer_url, tr_data, {})
|
447
452
|
result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
|
453
|
+
|
448
454
|
result.success?.should == true
|
449
455
|
customer = result.customer
|
450
456
|
customer.id.should == customer_id
|
@@ -489,6 +495,27 @@ describe Braintree::Customer do
|
|
489
495
|
customer.last_name.should == "Cool"
|
490
496
|
end
|
491
497
|
|
498
|
+
it "returns associated subscriptions" do
|
499
|
+
customer = Braintree::Customer.create.customer
|
500
|
+
credit_card = Braintree::CreditCard.create(
|
501
|
+
:customer_id => customer.id,
|
502
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
503
|
+
:expiration_date => "05/2012"
|
504
|
+
).credit_card
|
505
|
+
|
506
|
+
subscription = Braintree::Subscription.create(
|
507
|
+
:payment_method_token => credit_card.token,
|
508
|
+
:plan_id => "integration_trialless_plan",
|
509
|
+
:price => "1.00"
|
510
|
+
).subscription
|
511
|
+
|
512
|
+
found_customer = Braintree::Customer.find(customer.id)
|
513
|
+
found_customer.credit_cards.first.subscriptions.first.id.should == subscription.id
|
514
|
+
found_customer.credit_cards.first.subscriptions.first.plan_id.should == "integration_trialless_plan"
|
515
|
+
found_customer.credit_cards.first.subscriptions.first.payment_method_token.should == credit_card.token
|
516
|
+
found_customer.credit_cards.first.subscriptions.first.price.should == BigDecimal.new("1.00")
|
517
|
+
end
|
518
|
+
|
492
519
|
it "works for a blank customer" do
|
493
520
|
created_customer = Braintree::Customer.create!
|
494
521
|
found_customer = Braintree::Customer.find(created_customer.id)
|
@@ -651,8 +678,11 @@ describe Braintree::Customer do
|
|
651
678
|
tr_data_params = {
|
652
679
|
:customer_id => original_customer.id
|
653
680
|
}
|
654
|
-
|
681
|
+
|
682
|
+
tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
683
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::Customer.update_customer_url, tr_data, params)
|
655
684
|
result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
|
685
|
+
|
656
686
|
result.success?.should == true
|
657
687
|
customer = result.customer
|
658
688
|
customer.id.should == original_customer.id
|
@@ -689,8 +719,11 @@ describe Braintree::Customer do
|
|
689
719
|
:website => "new.website.com"
|
690
720
|
}
|
691
721
|
}
|
692
|
-
|
722
|
+
|
723
|
+
tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
724
|
+
query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::Customer.update_customer_url, tr_data, {})
|
693
725
|
result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
|
726
|
+
|
694
727
|
result.success?.should == true
|
695
728
|
customer = result.customer
|
696
729
|
customer.id.should == new_customer_id
|
@@ -703,36 +736,4 @@ describe Braintree::Customer do
|
|
703
736
|
customer.website.should == "new.website.com"
|
704
737
|
end
|
705
738
|
end
|
706
|
-
|
707
|
-
def create_customer_via_tr(regular_params, tr_data_params = {})
|
708
|
-
response = nil
|
709
|
-
Net::HTTP.start(Braintree::Configuration.server, Braintree::Configuration.port) do |http|
|
710
|
-
request = Net::HTTP::Post.new("/" + Braintree::Customer.create_customer_url.split("/", 4)[3])
|
711
|
-
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
712
|
-
params = {
|
713
|
-
:tr_data => Braintree::TransparentRedirect.create_customer_data(
|
714
|
-
{:redirect_url => "http://testing.com"}.merge(tr_data_params)
|
715
|
-
)
|
716
|
-
}.merge(regular_params)
|
717
|
-
request.body = Braintree::Util.hash_to_query_string(params)
|
718
|
-
response = http.request(request)
|
719
|
-
end
|
720
|
-
query_string = response["Location"].split("?", 2).last
|
721
|
-
query_string
|
722
|
-
end
|
723
|
-
|
724
|
-
def update_customer_via_tr(regular_params, tr_data_params = {})
|
725
|
-
raise "need a customer_id (of the customer to update) in tr_data_params" unless tr_data_params[:customer_id]
|
726
|
-
response = nil
|
727
|
-
Net::HTTP.start(Braintree::Configuration.server, Braintree::Configuration.port) do |http|
|
728
|
-
request = Net::HTTP::Post.new("/" + Braintree::Customer.update_customer_url.split("/", 4)[3])
|
729
|
-
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
730
|
-
tr_data = Braintree::TransparentRedirect.update_customer_data(
|
731
|
-
{:redirect_url => "http://testing.com"}.merge(tr_data_params)
|
732
|
-
)
|
733
|
-
request.body = Braintree::Util.hash_to_query_string({ :tr_data => tr_data }.merge(regular_params))
|
734
|
-
response = http.request(request)
|
735
|
-
end
|
736
|
-
query_string = response["Location"].split("?", 2).last
|
737
|
-
end
|
738
739
|
end
|
@@ -67,6 +67,23 @@ describe Braintree::Http do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
describe "user_agent" do
|
71
|
+
after do
|
72
|
+
Braintree::Configuration.custom_user_agent = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it "sets the User-Agent header using the default user agent" do
|
76
|
+
response = Braintree::Http.get("/test/headers")
|
77
|
+
response[:headers][:HTTP_USER_AGENT].should == "Braintree Ruby Gem #{Braintree::Version::String}"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "sets the User-Agent header using a customer user agent" do
|
81
|
+
Braintree::Configuration.custom_user_agent = "ActiveMerchant 1.2.3"
|
82
|
+
response = Braintree::Http.get("/test/headers")
|
83
|
+
response[:headers][:HTTP_USER_AGENT].should == "Braintree Ruby Gem #{Braintree::Version::String} (ActiveMerchant 1.2.3)"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
70
87
|
describe "ssl verification" do
|
71
88
|
it "rejects when the certificate isn't verified by our certificate authority (self-signed)" do
|
72
89
|
begin
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../spec_helper"
|
2
2
|
|
3
3
|
describe Braintree::Subscription do
|
4
|
-
|
5
4
|
TrialPlan = {
|
6
5
|
:description => "Plan for integration tests -- with trial",
|
7
6
|
:id => "integration_trial_plan",
|
@@ -18,6 +17,9 @@ describe Braintree::Subscription do
|
|
18
17
|
:trial_period => false
|
19
18
|
}
|
20
19
|
|
20
|
+
DefaultMerchantAccountId = "sandbox_credit_card"
|
21
|
+
NonDefaultMerchantAccountId = "sandbox_credit_card_non_default"
|
22
|
+
|
21
23
|
before(:each) do
|
22
24
|
@credit_card = Braintree::Customer.create!(
|
23
25
|
:credit_card => {
|
@@ -62,6 +64,29 @@ describe Braintree::Subscription do
|
|
62
64
|
result.subscription.id.should == new_id
|
63
65
|
end
|
64
66
|
|
67
|
+
context "merchant_account_id" do
|
68
|
+
it "defaults to the default merchant account if no merchant_account_id is provided" do
|
69
|
+
result = Braintree::Subscription.create(
|
70
|
+
:payment_method_token => @credit_card.token,
|
71
|
+
:plan_id => TriallessPlan[:id]
|
72
|
+
)
|
73
|
+
|
74
|
+
result.success?.should == true
|
75
|
+
result.subscription.merchant_account_id.should == DefaultMerchantAccountId
|
76
|
+
end
|
77
|
+
|
78
|
+
it "allows setting the merchant_account_id" do
|
79
|
+
result = Braintree::Subscription.create(
|
80
|
+
:payment_method_token => @credit_card.token,
|
81
|
+
:plan_id => TriallessPlan[:id],
|
82
|
+
:merchant_account_id => NonDefaultMerchantAccountId
|
83
|
+
)
|
84
|
+
|
85
|
+
result.success?.should == true
|
86
|
+
result.subscription.merchant_account_id.should == NonDefaultMerchantAccountId
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
65
90
|
context "trial period" do
|
66
91
|
context "defaults to the plan's trial period settings" do
|
67
92
|
it "with no trial" do
|
@@ -190,7 +215,7 @@ describe Braintree::Subscription do
|
|
190
215
|
:trial_duration => nil
|
191
216
|
)
|
192
217
|
result.success?.should == false
|
193
|
-
result.errors.for(:subscription)[0].message.should == "Trial Duration is required."
|
218
|
+
result.errors.for(:subscription).on(:trial_duration)[0].message.should == "Trial Duration is required."
|
194
219
|
end
|
195
220
|
|
196
221
|
it "trial duration unit required" do
|
@@ -235,6 +260,17 @@ describe Braintree::Subscription do
|
|
235
260
|
).subscription
|
236
261
|
end
|
237
262
|
|
263
|
+
context "merchant_account_id" do
|
264
|
+
it "allows changing the merchant_account_id" do
|
265
|
+
result = Braintree::Subscription.update(@subscription.id,
|
266
|
+
:merchant_account_id => NonDefaultMerchantAccountId
|
267
|
+
)
|
268
|
+
|
269
|
+
result.success?.should == true
|
270
|
+
result.subscription.merchant_account_id.should == NonDefaultMerchantAccountId
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
238
274
|
context "when successful" do
|
239
275
|
it "returns a success response with the updated subscription if valid" do
|
240
276
|
new_id = rand(36**9).to_s(36)
|
@@ -359,7 +395,7 @@ describe Braintree::Subscription do
|
|
359
395
|
}.to raise_error(Braintree::NotFoundError, 'subscription with id "noSuchSubscription" not found')
|
360
396
|
end
|
361
397
|
|
362
|
-
it "cannot be canceled if already
|
398
|
+
it "cannot be canceled if already canceled" do
|
363
399
|
subscription = Braintree::Subscription.create(
|
364
400
|
:payment_method_token => @credit_card.token,
|
365
401
|
:price => 54.32,
|
@@ -375,4 +411,209 @@ describe Braintree::Subscription do
|
|
375
411
|
result.errors.for(:subscription)[0].code.should == "81905"
|
376
412
|
end
|
377
413
|
end
|
414
|
+
|
415
|
+
describe "self.search" do
|
416
|
+
context "search_fields" do
|
417
|
+
it "correctly returns a result with no matches" do
|
418
|
+
collection = Braintree::Subscription.search do |search|
|
419
|
+
search.plan_id.is "not_a_real_plan_id"
|
420
|
+
end
|
421
|
+
|
422
|
+
collection.items.size.should == 0
|
423
|
+
end
|
424
|
+
|
425
|
+
context "is statement" do
|
426
|
+
it "returns paged collection with matching results" do
|
427
|
+
trialless_subscription = Braintree::Subscription.create(
|
428
|
+
:payment_method_token => @credit_card.token,
|
429
|
+
:plan_id => TriallessPlan[:id]
|
430
|
+
).subscription
|
431
|
+
|
432
|
+
trial_subscription = Braintree::Subscription.create(
|
433
|
+
:payment_method_token => @credit_card.token,
|
434
|
+
:plan_id => TrialPlan[:id]
|
435
|
+
).subscription
|
436
|
+
|
437
|
+
collection = Braintree::Subscription.search do |search|
|
438
|
+
search.plan_id.is TriallessPlan[:id]
|
439
|
+
end
|
440
|
+
|
441
|
+
collection.should include_on_any_page(trialless_subscription)
|
442
|
+
collection.should_not include_on_any_page(trial_subscription)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
context "is_not statement" do
|
447
|
+
it "returns paged collection without matching results" do
|
448
|
+
trialless_subscription = Braintree::Subscription.create(
|
449
|
+
:payment_method_token => @credit_card.token,
|
450
|
+
:plan_id => TriallessPlan[:id]
|
451
|
+
).subscription
|
452
|
+
|
453
|
+
trial_subscription = Braintree::Subscription.create(
|
454
|
+
:payment_method_token => @credit_card.token,
|
455
|
+
:plan_id => TrialPlan[:id]
|
456
|
+
).subscription
|
457
|
+
|
458
|
+
collection = Braintree::Subscription.search do |search|
|
459
|
+
search.plan_id.is_not TriallessPlan[:id]
|
460
|
+
end
|
461
|
+
|
462
|
+
collection.should_not include_on_any_page(trialless_subscription)
|
463
|
+
collection.should include_on_any_page(trial_subscription)
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
context "ends_with statement" do
|
468
|
+
it "returns paged collection with matching results" do
|
469
|
+
trialless_subscription = Braintree::Subscription.create(
|
470
|
+
:payment_method_token => @credit_card.token,
|
471
|
+
:plan_id => TriallessPlan[:id]
|
472
|
+
).subscription
|
473
|
+
|
474
|
+
trial_subscription = Braintree::Subscription.create(
|
475
|
+
:payment_method_token => @credit_card.token,
|
476
|
+
:plan_id => TrialPlan[:id]
|
477
|
+
).subscription
|
478
|
+
|
479
|
+
collection = Braintree::Subscription.search do |search|
|
480
|
+
search.plan_id.ends_with "trial_plan"
|
481
|
+
end
|
482
|
+
|
483
|
+
collection.should include_on_any_page(trial_subscription)
|
484
|
+
collection.should_not include_on_any_page(trialless_subscription)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context "starts_with statement" do
|
489
|
+
it "returns paged collection with matching results" do
|
490
|
+
trialless_subscription = Braintree::Subscription.create(
|
491
|
+
:payment_method_token => @credit_card.token,
|
492
|
+
:plan_id => TriallessPlan[:id]
|
493
|
+
).subscription
|
494
|
+
|
495
|
+
trial_subscription = Braintree::Subscription.create(
|
496
|
+
:payment_method_token => @credit_card.token,
|
497
|
+
:plan_id => TrialPlan[:id]
|
498
|
+
).subscription
|
499
|
+
|
500
|
+
collection = Braintree::Subscription.search do |search|
|
501
|
+
search.plan_id.starts_with "integration_trial_p"
|
502
|
+
end
|
503
|
+
|
504
|
+
collection.should include_on_any_page(trial_subscription)
|
505
|
+
collection.should_not include_on_any_page(trialless_subscription)
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
context "contains statement" do
|
510
|
+
it "returns paged collection with matching results" do
|
511
|
+
trialless_subscription = Braintree::Subscription.create(
|
512
|
+
:payment_method_token => @credit_card.token,
|
513
|
+
:plan_id => TriallessPlan[:id]
|
514
|
+
).subscription
|
515
|
+
|
516
|
+
trial_subscription = Braintree::Subscription.create(
|
517
|
+
:payment_method_token => @credit_card.token,
|
518
|
+
:plan_id => TrialPlan[:id]
|
519
|
+
).subscription
|
520
|
+
|
521
|
+
collection = Braintree::Subscription.search do |search|
|
522
|
+
search.plan_id.contains "trial_p"
|
523
|
+
end
|
524
|
+
|
525
|
+
collection.should include_on_any_page(trial_subscription)
|
526
|
+
collection.should_not include_on_any_page(trialless_subscription)
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
context "multiple_value_fields" do
|
532
|
+
context "in" do
|
533
|
+
it "matches all values if none are specified" do
|
534
|
+
subscription1 = Braintree::Subscription.create(
|
535
|
+
:payment_method_token => @credit_card.token,
|
536
|
+
:plan_id => TriallessPlan[:id]
|
537
|
+
).subscription
|
538
|
+
|
539
|
+
subscription2 = Braintree::Subscription.create(
|
540
|
+
:payment_method_token => @credit_card.token,
|
541
|
+
:plan_id => TriallessPlan[:id]
|
542
|
+
).subscription
|
543
|
+
|
544
|
+
Braintree::Subscription.cancel(subscription2.id)
|
545
|
+
|
546
|
+
collection = Braintree::Subscription.search do |search|
|
547
|
+
search.plan_id.is TriallessPlan[:id]
|
548
|
+
end
|
549
|
+
|
550
|
+
collection.should include_on_any_page(subscription1)
|
551
|
+
collection.should include_on_any_page(subscription2)
|
552
|
+
end
|
553
|
+
|
554
|
+
it "returns only matching results" do
|
555
|
+
subscription1 = Braintree::Subscription.create(
|
556
|
+
:payment_method_token => @credit_card.token,
|
557
|
+
:plan_id => TriallessPlan[:id]
|
558
|
+
).subscription
|
559
|
+
|
560
|
+
subscription2 = Braintree::Subscription.create(
|
561
|
+
:payment_method_token => @credit_card.token,
|
562
|
+
:plan_id => TriallessPlan[:id]
|
563
|
+
).subscription
|
564
|
+
|
565
|
+
Braintree::Subscription.cancel(subscription2.id)
|
566
|
+
|
567
|
+
collection = Braintree::Subscription.search do |search|
|
568
|
+
search.status.in Braintree::Subscription::Status::Active
|
569
|
+
end
|
570
|
+
|
571
|
+
collection.should include_on_any_page(subscription1)
|
572
|
+
collection.should_not include_on_any_page(subscription2)
|
573
|
+
end
|
574
|
+
|
575
|
+
it "returns only matching results given an argument list" do
|
576
|
+
subscription1 = Braintree::Subscription.create(
|
577
|
+
:payment_method_token => @credit_card.token,
|
578
|
+
:plan_id => TriallessPlan[:id]
|
579
|
+
).subscription
|
580
|
+
|
581
|
+
subscription2 = Braintree::Subscription.create(
|
582
|
+
:payment_method_token => @credit_card.token,
|
583
|
+
:plan_id => TriallessPlan[:id]
|
584
|
+
).subscription
|
585
|
+
|
586
|
+
Braintree::Subscription.cancel(subscription2.id)
|
587
|
+
|
588
|
+
collection = Braintree::Subscription.search do |search|
|
589
|
+
search.status.in Braintree::Subscription::Status::Active, Braintree::Subscription::Status::Canceled
|
590
|
+
end
|
591
|
+
|
592
|
+
collection.should include_on_any_page(subscription1)
|
593
|
+
collection.should include_on_any_page(subscription2)
|
594
|
+
end
|
595
|
+
|
596
|
+
it "returns only matching results given an array" do
|
597
|
+
subscription1 = Braintree::Subscription.create(
|
598
|
+
:payment_method_token => @credit_card.token,
|
599
|
+
:plan_id => TriallessPlan[:id]
|
600
|
+
).subscription
|
601
|
+
|
602
|
+
subscription2 = Braintree::Subscription.create(
|
603
|
+
:payment_method_token => @credit_card.token,
|
604
|
+
:plan_id => TriallessPlan[:id]
|
605
|
+
).subscription
|
606
|
+
|
607
|
+
Braintree::Subscription.cancel(subscription2.id)
|
608
|
+
|
609
|
+
collection = Braintree::Subscription.search do |search|
|
610
|
+
search.status.in [Braintree::Subscription::Status::Active, Braintree::Subscription::Status::Canceled]
|
611
|
+
end
|
612
|
+
|
613
|
+
collection.should include_on_any_page(subscription1)
|
614
|
+
collection.should include_on_any_page(subscription2)
|
615
|
+
end
|
616
|
+
end
|
617
|
+
end
|
618
|
+
end
|
378
619
|
end
|