braintree 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,13 +26,11 @@ The Braintree gem provides integration access to the Braintree Gateway.
26
26
  )
27
27
 
28
28
  if result.success?
29
- if result.transaction.status == Braintree::Transaction::Status::Authorized
30
- puts "sucess!: #{result.transaction.id}"
31
- else
32
- puts "Error processing transaction:"
33
- puts " code: #{result.transaction.processor_response_code}"
34
- puts " text: #{result.transaction.processor_response_text}"
35
- end
29
+ puts "success!: #{result.transaction.id}"
30
+ elsif result.transaction
31
+ puts "Error processing transaction:"
32
+ puts " code: #{result.transaction.processor_response_code}"
33
+ puts " text: #{result.transaction.processor_response_text}"
36
34
  else
37
35
  p result.errors
38
36
  end
@@ -45,7 +43,7 @@ the created or updated resource, or it will raise a ValidationsFailed exception.
45
43
 
46
44
  Example of using non-bang method:
47
45
 
48
- result = Braintree::Customer.create!(:first_name => "Josh")
46
+ result = Braintree::Customer.create(:first_name => "Josh")
49
47
  if result.success?
50
48
  puts "Created customer #{result.customer.id}
51
49
  else
@@ -33,7 +33,7 @@ require "braintree/error_codes.rb"
33
33
  require "braintree/error_result.rb"
34
34
  require "braintree/errors.rb"
35
35
  require "braintree/http.rb"
36
- require "braintree/paged_collection.rb"
36
+ require "braintree/resource_collection.rb"
37
37
  require "braintree/ssl_expiration_check.rb"
38
38
  require "braintree/subscription"
39
39
  require "braintree/subscription_search"
@@ -8,7 +8,7 @@ module Braintree
8
8
  # By default, the logger will log to +STDOUT+. The log level is set to info.
9
9
  # The logger can be set to any Logger object.
10
10
  module Configuration
11
- API_VERSION = "1" # :nodoc:
11
+ API_VERSION = "2" # :nodoc:
12
12
 
13
13
  class << self
14
14
  attr_accessor :logger
@@ -1,4 +1,8 @@
1
1
  module Braintree
2
+ # == More Information
3
+ #
4
+ # For more detailed documentation on CreditCards, see http://www.braintreepaymentsolutions.com/gateway/credit-card-api
5
+ # For more detailed documentation on CreditCard verification, see http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api
2
6
  class CreditCard
3
7
  include BaseModule # :nodoc:
4
8
 
@@ -37,7 +41,7 @@ module Braintree
37
41
  return_object_or_raise(:transaction) { credit(token, transaction_attributes) }
38
42
  end
39
43
 
40
- # Returns a PagedCollection of expired credit cards.
44
+ # Returns a ResourceCollection of expired credit cards.
41
45
  def self.expired(options = {})
42
46
  page_number = options[:page] || 1
43
47
  response = Http.get("/payment_methods/all/expired?page=#{page_number}")
@@ -45,10 +49,10 @@ module Braintree
45
49
  attributes[:items] = Util.extract_attribute_as_array(attributes, :credit_card).map do |payment_method_attributes|
46
50
  new payment_method_attributes
47
51
  end
48
- PagedCollection.new(attributes) { |page_number| CreditCard.expired(:page => page_number) }
52
+ ResourceCollection.new(attributes) { |page_number| CreditCard.expired(:page => page_number) }
49
53
  end
50
54
 
51
- # Returns a PagedCollection of credit cards expiring between +start_date+ and +end_date+ inclusive.
55
+ # Returns a ResourceCollection of credit cards expiring between +start_date+ and +end_date+ inclusive.
52
56
  # Only the month and year of the start and end dates are used.
53
57
  def self.expiring_between(start_date, end_date, options = {})
54
58
  page_number = options[:page] || 1
@@ -57,7 +61,7 @@ module Braintree
57
61
  attributes[:items] = Util.extract_attribute_as_array(attributes, :credit_card).map do |payment_method_attributes|
58
62
  new payment_method_attributes
59
63
  end
60
- PagedCollection.new(attributes) { |page_number| CreditCard.expiring_between(start_date, end_date, :page => page_number) }
64
+ ResourceCollection.new(attributes) { |page_number| CreditCard.expiring_between(start_date, end_date, :page => page_number) }
61
65
  end
62
66
 
63
67
  # Finds the credit card with the given +token+. Raises a NotFoundError if it cannot be found.
@@ -1,11 +1,14 @@
1
1
  module Braintree
2
+ # == More Information
3
+ #
4
+ # For more detailed documentation on Customers, see http://www.braintreepaymentsolutions.com/gateway/customer-api
2
5
  class Customer
3
6
  include BaseModule
4
7
 
5
8
  attr_reader :addresses, :company, :created_at, :credit_cards, :email, :fax, :first_name, :id, :last_name,
6
9
  :phone, :updated_at, :website, :custom_fields
7
10
 
8
- # Returns a PagedCollection of all customers stored in the vault. Due to race conditions, this method
11
+ # Returns a ResourceCollection of all customers stored in the vault. Due to race conditions, this method
9
12
  # may not reliably return all customers stored in the vault.
10
13
  #
11
14
  # page = Braintree::Customer.all
@@ -23,7 +26,7 @@ module Braintree
23
26
  attributes[:items] = Util.extract_attribute_as_array(attributes, :customer).map do |customer_attributes|
24
27
  new customer_attributes
25
28
  end
26
- PagedCollection.new(attributes) { |page_number| Customer.all(:page => page_number) }
29
+ ResourceCollection.new(attributes) { |page_number| Customer.all(:page => page_number) }
27
30
  end
28
31
 
29
32
  # Creates a customer using the given +attributes+. If <tt>:id</tt> is not passed,
@@ -95,7 +98,7 @@ module Braintree
95
98
  return_object_or_raise(:transaction){ sale(customer_id, transaction_attributes) }
96
99
  end
97
100
 
98
- # Returns a PagedCollection of transactions for the customer with the given +customer_id+.
101
+ # Returns a ResourceCollection of transactions for the customer with the given +customer_id+.
99
102
  def self.transactions(customer_id, options = {})
100
103
  page_number = options[:page] || 1
101
104
  response = Http.get "/customers/#{customer_id}/transactions?page=#{page_number}"
@@ -103,7 +106,7 @@ module Braintree
103
106
  attributes[:items] = Util.extract_attribute_as_array(attributes, :transaction).map do |transaction_attributes|
104
107
  Transaction._new transaction_attributes
105
108
  end
106
- PagedCollection.new(attributes) { |page_number| Customer.transactions(customer_id, :page => page_number) }
109
+ ResourceCollection.new(attributes) { |page_number| Customer.transactions(customer_id, :page => page_number) }
107
110
  end
108
111
 
109
112
  def self.update(customer_id, attributes)
@@ -160,7 +163,7 @@ module Braintree
160
163
  return_object_or_raise(:transaction) { sale(transaction_attributes) }
161
164
  end
162
165
 
163
- # Returns a PagedCollection of transactions for the customer.
166
+ # Returns a ResourceCollection of transactions for the customer.
164
167
  def transactions(options = {})
165
168
  Customer.transactions(id, options)
166
169
  end
@@ -17,13 +17,12 @@ module Braintree
17
17
  # end
18
18
  class ErrorResult
19
19
 
20
- attr_reader :credit_card_verification, :errors, :params
20
+ attr_reader :credit_card_verification, :transaction, :errors, :params
21
21
 
22
22
  def initialize(data) # :nodoc:
23
23
  @params = data[:params]
24
- if data[:verification]
25
- @credit_card_verification = CreditCardVerification._new(data[:verification])
26
- end
24
+ @credit_card_verification = CreditCardVerification._new(data[:verification]) if data[:verification]
25
+ @transaction = Transaction._new(data[:transaction]) if data[:transaction]
27
26
  @errors = Errors.new(data[:errors])
28
27
  end
29
28
 
@@ -1,23 +1,22 @@
1
1
  module Braintree
2
- class PagedCollection
2
+ class ResourceCollection
3
3
  include BaseModule
4
4
  include Enumerable
5
5
 
6
- attr_reader :current_page_number, :items, :next_page_number, :page_size, :previous_page_number, :total_items
7
-
8
6
  def initialize(attributes, &block) # :nodoc:
9
7
  set_instance_variables_from_hash attributes
10
8
  @paging_block = block
11
9
  end
12
10
 
13
- # Returns the item from the current page at the given +index+.
14
- def [](index)
15
- @items[index]
16
- end
17
-
18
11
  # Yields each item on the current page.
19
12
  def each(&block)
20
13
  @items.each(&block)
14
+
15
+ _next_page.each(&block) unless _last_page?
16
+ end
17
+
18
+ def empty?
19
+ @items.empty?
21
20
  end
22
21
 
23
22
  # Returns the first item from the current page.
@@ -26,27 +25,28 @@ module Braintree
26
25
  end
27
26
 
28
27
  # Returns true if the page is the last page. False otherwise.
29
- def last_page?
30
- current_page_number == total_pages
28
+ def _last_page?
29
+ @current_page_number == _total_pages
31
30
  end
32
31
 
33
32
  # Retrieves the next page of records.
34
- def next_page
35
- if last_page?
33
+ def _next_page
34
+ if _last_page?
36
35
  return nil
37
36
  end
38
- @paging_block.call(next_page_number)
37
+ @paging_block.call(@current_page_number + 1)
39
38
  end
40
39
 
41
- # The next page number. Returns +nil+ if on the last page.
42
- def next_page_number
43
- last_page? ? nil : current_page_number + 1
40
+ # The size of a resource collection is only approximate due to race conditions when pulling back results. This method
41
+ # should be avoided.
42
+ def _approximate_size
43
+ @total_items
44
44
  end
45
45
 
46
46
  # Returns the total number of pages.
47
- def total_pages
48
- total = total_items / page_size
49
- if total_items % page_size != 0
47
+ def _total_pages
48
+ total = @total_items / @page_size
49
+ if @total_items % @page_size != 0
50
50
  total += 1
51
51
  end
52
52
  total
@@ -20,6 +20,10 @@ module Braintree
20
20
  # :trial_duration => "2",
21
21
  # :trial_duration_unit => Subscription::TrialDurationUnit::Day
22
22
  # )
23
+ #
24
+ # == More Information
25
+ #
26
+ # For more detailed documentation on Subscriptions, see http://www.braintreepaymentsolutions.com/gateway/subscription-api
23
27
  class Subscription
24
28
  include BaseModule
25
29
 
@@ -90,7 +94,7 @@ module Braintree
90
94
  response = Http.post "/subscriptions/advanced_search?page=#{page}", {:search => search.to_hash}
91
95
  attributes = response[:subscriptions]
92
96
  attributes[:items] = Util.extract_attribute_as_array(attributes, :subscription).map { |attrs| new(attrs) }
93
- PagedCollection.new(attributes) { |page_number| Subscription.search(page_number, &block) }
97
+ ResourceCollection.new(attributes) { |page_number| Subscription.search(page_number, &block) }
94
98
  end
95
99
 
96
100
  def self.update(subscription_id, attributes)
@@ -116,6 +116,10 @@ module Braintree
116
116
  # :submit_for_settlement => true
117
117
  # }
118
118
  # )
119
+ #
120
+ # == More Information
121
+ #
122
+ # For more detailed documentation on Transactions, see http://www.braintreepaymentsolutions.com/gateway/transaction-api
119
123
  class Transaction
120
124
  include BaseModule
121
125
 
@@ -138,18 +142,20 @@ module Braintree
138
142
  end
139
143
 
140
144
  attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
141
- attr_reader :amount, :created_at, :credit_card_details, :customer_details, :id, :status
145
+ attr_reader :amount, :created_at, :credit_card_details, :customer_details, :id
142
146
  attr_reader :custom_fields
143
147
  attr_reader :cvv_response_code
144
148
  attr_reader :order_id
145
149
  attr_reader :billing_details, :shipping_details
146
- attr_reader :status_history
147
150
  # The authorization code from the processor.
148
151
  attr_reader :processor_authorization_code
149
152
  # The response code from the processor.
150
153
  attr_reader :processor_response_code
151
154
  # The response text from the processor.
152
155
  attr_reader :processor_response_text
156
+ # See Transaction::Status
157
+ attr_reader :status
158
+ attr_reader :status_history
153
159
  # Will either be "sale" or "credit"
154
160
  attr_reader :type
155
161
  attr_reader :updated_at
@@ -200,7 +206,7 @@ module Braintree
200
206
  return_object_or_raise(:transaction) { sale(attributes) }
201
207
  end
202
208
 
203
- # Returns a PagedCollection of transactions matching the search query.
209
+ # Returns a ResourceCollection of transactions matching the search query.
204
210
  # If <tt>query</tt> is a string, the search will be a basic search.
205
211
  # If <tt>query</tt> is a hash, the search will be an advanced search.
206
212
  def self.search(query, options = {})
@@ -379,7 +385,7 @@ module Braintree
379
385
  response = Http.post "/transactions/advanced_search?page=#{Util.url_encode(page)}", :search => query
380
386
  attributes = response[:credit_card_transactions]
381
387
  attributes[:items] = Util.extract_attribute_as_array(attributes, :transaction).map { |attrs| _new(attrs) }
382
- PagedCollection.new(attributes) { |page_number| Transaction.search(query, :page => page_number) }
388
+ ResourceCollection.new(attributes) { |page_number| Transaction.search(query, :page => page_number) }
383
389
  end
384
390
 
385
391
  def self._attributes # :nodoc:
@@ -391,13 +397,13 @@ module Braintree
391
397
  response = Http.get "/transactions/all/search?q=#{Util.url_encode(query)}&page=#{Util.url_encode(page)}"
392
398
  attributes = response[:credit_card_transactions]
393
399
  attributes[:items] = Util.extract_attribute_as_array(attributes, :transaction).map { |attrs| _new(attrs) }
394
- PagedCollection.new(attributes) { |page_number| Transaction.search(query, :page => page_number) }
400
+ ResourceCollection.new(attributes) { |page_number| Transaction.search(query, :page => page_number) }
395
401
  end
396
402
 
397
403
  def self._create_signature # :nodoc:
398
404
  [
399
405
  :amount, :customer_id, :order_id, :payment_method_token, :type,
400
- {:credit_card => [:token, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
406
+ {:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
401
407
  {:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]},
402
408
  {:billing => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
403
409
  {:shipping => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
@@ -3,7 +3,7 @@ module Braintree
3
3
  class CreditCardDetails # :nodoc:
4
4
  include BaseModule
5
5
 
6
- attr_reader :bin, :card_type, :customer_location, :expiration_month,
6
+ attr_reader :bin, :card_type, :cardholder_name, :customer_location, :expiration_month,
7
7
  :expiration_year, :last_4, :token
8
8
 
9
9
  def initialize(attributes)
@@ -11,7 +11,7 @@ module Braintree
11
11
  end
12
12
 
13
13
  def inspect
14
- attr_order = [:token, :bin, :last_4, :card_type, :expiration_date, :customer_location]
14
+ attr_order = [:token, :bin, :last_4, :card_type, :expiration_date, :cardholder_name, :customer_location]
15
15
  formatted_attrs = attr_order.map do |attr|
16
16
  "#{attr}: #{send(attr).inspect}"
17
17
  end
@@ -18,6 +18,10 @@ module Braintree
18
18
  # #=> [#<Braintree::ValidationError (81715) Credit card number is invalid.>]
19
19
  # result.errors.for(:customer).for(:credit_card).for(:billing_address).on(:country_name)
20
20
  # #=> [#<Braintree::ValidationError (91803) Country name is not an accepted country.>]
21
+ #
22
+ # == More Information
23
+ #
24
+ # For more detailed documentation on ValidationErrors, see http://www.braintreepaymentsolutions.com/gateway/validation-errors
21
25
  class ValidationErrorCollection
22
26
  include Enumerable
23
27
 
@@ -1,8 +1,8 @@
1
1
  module Braintree
2
2
  module Version
3
- Major = 1
4
- Minor = 2
5
- Tiny = 1
3
+ Major = 2
4
+ Minor = 0
5
+ Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -21,7 +21,7 @@ module Braintree
21
21
 
22
22
  if contents.is_a?(String)
23
23
  builder = Builder::XmlMarkup.new
24
- builder.__send__(root) { |b| b.text! contents }
24
+ builder.__send__(_xml_escape(root)) { |b| b.text! contents }
25
25
  else
26
26
  _convert_to_xml contents, :root => root
27
27
  end
@@ -32,7 +32,7 @@ module Braintree
32
32
  options[:indent] ||= 2
33
33
  options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
34
34
  options[:builder].instruct! unless options.delete(:skip_instruct)
35
- root = options[:root].to_s.tr("_", "-")
35
+ root = _xml_escape(options[:root])
36
36
 
37
37
  options[:builder].__send__(:method_missing, root) do
38
38
  hash_to_convert.each do |key, value|
@@ -44,14 +44,12 @@ module Braintree
44
44
  else
45
45
  type_name = XML_TYPE_NAMES[value.class.name]
46
46
 
47
- key = key.to_s.tr("_", "-")
48
-
49
47
  attributes = ((value.nil? || type_name.nil?) ? {} : { :type => type_name })
50
48
  if value.nil?
51
49
  attributes[:nil] = true
52
50
  end
53
51
 
54
- options[:builder].tag!(key,
52
+ options[:builder].tag!(_xml_escape(key),
55
53
  XML_FORMATTING[type_name] ? XML_FORMATTING[type_name].call(value) : value,
56
54
  attributes
57
55
  )
@@ -80,6 +78,10 @@ module Braintree
80
78
  end
81
79
  end
82
80
  end
81
+
82
+ def self._xml_escape(key)
83
+ key.to_s.tr("_", "-").to_xs
84
+ end
83
85
  end
84
86
  end
85
87
  end
@@ -638,42 +638,19 @@ describe Braintree::CreditCard do
638
638
 
639
639
  describe "self.expired" do
640
640
  it "finds expired payment methods, paginated" do
641
- first_page = Braintree::CreditCard.expired
642
- first_page.current_page_number.should == 1
643
- first_page.total_items.should > 0
644
- first_page.all? { |pm| pm.expired?.should == true }
645
- end
646
-
647
- it "can get the next_page" do
648
- first_page = Braintree::CreditCard.expired
649
- first_page.current_page_number.should == 1
650
- first_page.all? { |pm| pm.expired?.should == true }
651
- second_page = first_page.next_page
652
- # TODO: we don't have enough expired payment methods to go onto a second page
653
- # second_page.current_page_number.should == 2
654
- # second_page.all? { |pm| pm.expired?.should == true }
641
+ collection = Braintree::CreditCard.expired
642
+ collection._approximate_size.should > 0
643
+ collection.all? { |pm| pm.expired?.should == true }
655
644
  end
656
645
  end
657
646
 
658
647
  describe "self.expiring_between" do
659
648
  it "finds payment methods expiring between the given dates" do
660
649
  next_year = Time.now.year + 1
661
- first_page = Braintree::CreditCard.expiring_between(Time.mktime(next_year, 1), Time.mktime(next_year, 12))
662
- first_page.current_page_number.should == 1
663
- first_page.total_items.should > 0
664
- first_page.all? { |pm| pm.expired?.should == false }
665
- first_page.all? { |pm| pm.expiration_year.should == next_year.to_s }
666
- end
667
-
668
- it "can get the next_page" do
669
- next_year = Time.now.year + 1
670
- first_page = Braintree::CreditCard.expiring_between(Time.mktime(next_year, 1), Time.mktime(next_year, 12))
671
- first_page.current_page_number.should == 1
672
- second_page = first_page.next_page
673
- # TODO: we don't have enough expired payment methods to go onto a second page
674
- # second_page.current_page_number.should == 2
675
- # second_page.all? { |pm| pm.expired?.should == false }
676
- # second_page.all? { |pm| pm.expiration_year.should == next_year.to_s }
650
+ collection = Braintree::CreditCard.expiring_between(Time.mktime(next_year, 1), Time.mktime(next_year, 12))
651
+ collection._approximate_size.should > 0
652
+ collection.all? { |pm| pm.expired?.should == false }
653
+ collection.all? { |pm| pm.expiration_year.should == next_year.to_s }
677
654
  end
678
655
  end
679
656
 
@@ -2,16 +2,12 @@ require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe Braintree::Customer do
4
4
  describe "self.all" do
5
- it "returns page 1 if page isn't specified" do
6
- first_page = Braintree::Customer.all
7
- first_page.current_page_number.should == 1
8
- end
5
+ it "gets more than a page of customers" do
6
+ customers = Braintree::Customer.all
7
+ customers._approximate_size.should > 100
9
8
 
10
- it "can get the next_page" do
11
- first_page = Braintree::Customer.all
12
- first_page.current_page_number.should == 1
13
- second_page = first_page.next_page
14
- second_page.current_page_number.should == 2
9
+ customer_ids = customers.map {|c| c.id }.uniq.compact
10
+ customer_ids.size.should == customers._approximate_size
15
11
  end
16
12
  end
17
13
 
@@ -298,9 +294,7 @@ describe Braintree::Customer do
298
294
  )
299
295
  transaction = customer.sale!(:amount => "100.00")
300
296
  collection = Braintree::Customer.transactions(customer.id)
301
- collection.current_page_number.should == 1
302
- collection.total_items.should == 1
303
- collection[0].should == transaction
297
+ collection.first.should == transaction
304
298
  end
305
299
  end
306
300
 
@@ -356,9 +350,7 @@ describe Braintree::Customer do
356
350
  )
357
351
  transaction = customer.sale!(:amount => "100.00")
358
352
  collection = customer.transactions
359
- collection.current_page_number.should == 1
360
- collection.total_items.should == 1
361
- collection[0].should == transaction
353
+ collection.first.should == transaction
362
354
  end
363
355
  end
364
356
 
@@ -419,11 +419,11 @@ describe Braintree::Subscription do
419
419
  search.plan_id.is "not_a_real_plan_id"
420
420
  end
421
421
 
422
- collection.items.size.should == 0
422
+ collection._approximate_size.should == 0
423
423
  end
424
424
 
425
425
  context "is statement" do
426
- it "returns paged collection with matching results" do
426
+ it "returns resource collection with matching results" do
427
427
  trialless_subscription = Braintree::Subscription.create(
428
428
  :payment_method_token => @credit_card.token,
429
429
  :plan_id => TriallessPlan[:id]
@@ -438,13 +438,13 @@ describe Braintree::Subscription do
438
438
  search.plan_id.is TriallessPlan[:id]
439
439
  end
440
440
 
441
- collection.should include_on_any_page(trialless_subscription)
442
- collection.should_not include_on_any_page(trial_subscription)
441
+ collection.should include(trialless_subscription)
442
+ collection.should_not include(trial_subscription)
443
443
  end
444
444
  end
445
445
 
446
446
  context "is_not statement" do
447
- it "returns paged collection without matching results" do
447
+ it "returns resource collection without matching results" do
448
448
  trialless_subscription = Braintree::Subscription.create(
449
449
  :payment_method_token => @credit_card.token,
450
450
  :plan_id => TriallessPlan[:id]
@@ -459,13 +459,13 @@ describe Braintree::Subscription do
459
459
  search.plan_id.is_not TriallessPlan[:id]
460
460
  end
461
461
 
462
- collection.should_not include_on_any_page(trialless_subscription)
463
- collection.should include_on_any_page(trial_subscription)
462
+ collection.should_not include(trialless_subscription)
463
+ collection.should include(trial_subscription)
464
464
  end
465
465
  end
466
466
 
467
467
  context "ends_with statement" do
468
- it "returns paged collection with matching results" do
468
+ it "returns resource collection with matching results" do
469
469
  trialless_subscription = Braintree::Subscription.create(
470
470
  :payment_method_token => @credit_card.token,
471
471
  :plan_id => TriallessPlan[:id]
@@ -480,13 +480,13 @@ describe Braintree::Subscription do
480
480
  search.plan_id.ends_with "trial_plan"
481
481
  end
482
482
 
483
- collection.should include_on_any_page(trial_subscription)
484
- collection.should_not include_on_any_page(trialless_subscription)
483
+ collection.should include(trial_subscription)
484
+ collection.should_not include(trialless_subscription)
485
485
  end
486
486
  end
487
487
 
488
488
  context "starts_with statement" do
489
- it "returns paged collection with matching results" do
489
+ it "returns resource collection with matching results" do
490
490
  trialless_subscription = Braintree::Subscription.create(
491
491
  :payment_method_token => @credit_card.token,
492
492
  :plan_id => TriallessPlan[:id]
@@ -501,13 +501,13 @@ describe Braintree::Subscription do
501
501
  search.plan_id.starts_with "integration_trial_p"
502
502
  end
503
503
 
504
- collection.should include_on_any_page(trial_subscription)
505
- collection.should_not include_on_any_page(trialless_subscription)
504
+ collection.should include(trial_subscription)
505
+ collection.should_not include(trialless_subscription)
506
506
  end
507
507
  end
508
508
 
509
509
  context "contains statement" do
510
- it "returns paged collection with matching results" do
510
+ it "returns resource collection with matching results" do
511
511
  trialless_subscription = Braintree::Subscription.create(
512
512
  :payment_method_token => @credit_card.token,
513
513
  :plan_id => TriallessPlan[:id]
@@ -522,8 +522,8 @@ describe Braintree::Subscription do
522
522
  search.plan_id.contains "trial_p"
523
523
  end
524
524
 
525
- collection.should include_on_any_page(trial_subscription)
526
- collection.should_not include_on_any_page(trialless_subscription)
525
+ collection.should include(trial_subscription)
526
+ collection.should_not include(trialless_subscription)
527
527
  end
528
528
  end
529
529
  end
@@ -547,8 +547,8 @@ describe Braintree::Subscription do
547
547
  search.plan_id.is TriallessPlan[:id]
548
548
  end
549
549
 
550
- collection.should include_on_any_page(subscription1)
551
- collection.should include_on_any_page(subscription2)
550
+ collection.should include(subscription1)
551
+ collection.should include(subscription2)
552
552
  end
553
553
 
554
554
  it "returns only matching results" do
@@ -568,8 +568,8 @@ describe Braintree::Subscription do
568
568
  search.status.in Braintree::Subscription::Status::Active
569
569
  end
570
570
 
571
- collection.should include_on_any_page(subscription1)
572
- collection.should_not include_on_any_page(subscription2)
571
+ collection.should include(subscription1)
572
+ collection.should_not include(subscription2)
573
573
  end
574
574
 
575
575
  it "returns only matching results given an argument list" do
@@ -589,8 +589,8 @@ describe Braintree::Subscription do
589
589
  search.status.in Braintree::Subscription::Status::Active, Braintree::Subscription::Status::Canceled
590
590
  end
591
591
 
592
- collection.should include_on_any_page(subscription1)
593
- collection.should include_on_any_page(subscription2)
592
+ collection.should include(subscription1)
593
+ collection.should include(subscription2)
594
594
  end
595
595
 
596
596
  it "returns only matching results given an array" do
@@ -610,8 +610,8 @@ describe Braintree::Subscription do
610
610
  search.status.in [Braintree::Subscription::Status::Active, Braintree::Subscription::Status::Canceled]
611
611
  end
612
612
 
613
- collection.should include_on_any_page(subscription1)
614
- collection.should include_on_any_page(subscription2)
613
+ collection.should include(subscription1)
614
+ collection.should include(subscription2)
615
615
  end
616
616
  end
617
617
  end
@@ -16,14 +16,14 @@ describe Braintree::Test::TransactionAmounts do
16
16
 
17
17
  describe "Decline" do
18
18
  it "creates a transaction with status processor_declined" do
19
- transaction = Braintree::Transaction.sale!(
19
+ result = Braintree::Transaction.sale(
20
20
  :amount => Braintree::Test::TransactionAmounts::Decline,
21
21
  :credit_card => {
22
22
  :number => Braintree::Test::CreditCardNumbers::Visa,
23
23
  :expiration_date => "12/2012"
24
24
  }
25
25
  )
26
- transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
26
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
27
27
  end
28
28
  end
29
29
  end
@@ -31,7 +31,7 @@ describe Braintree::Transaction do
31
31
  :expiration_date => "05/2009"
32
32
  }
33
33
  )
34
- result.success?.should == true
34
+ result.success?.should == false
35
35
  result.transaction.id.should =~ /^\w{6}$/
36
36
  result.transaction.type.should == "sale"
37
37
  result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
@@ -42,7 +42,7 @@ describe Braintree::Transaction do
42
42
  it "accepts credit card expiration month and expiration year" do
43
43
  result = Braintree::Transaction.create(
44
44
  :type => "sale",
45
- :amount => Braintree::Test::TransactionAmounts::Decline,
45
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
46
46
  :credit_card => {
47
47
  :number => Braintree::Test::CreditCardNumbers::Visa,
48
48
  :expiration_month => "05",
@@ -256,6 +256,7 @@ describe Braintree::Transaction do
256
256
  :amount => "100.00",
257
257
  :order_id => "123",
258
258
  :credit_card => {
259
+ :cardholder_name => "The Cardholder",
259
260
  :number => "5105105105105100",
260
261
  :expiration_date => "05/2011",
261
262
  :cvv => "123"
@@ -303,6 +304,7 @@ describe Braintree::Transaction do
303
304
  transaction.created_at.between?(Time.now - 5, Time.now).should == true
304
305
  transaction.updated_at.between?(Time.now - 5, Time.now).should == true
305
306
  transaction.credit_card_details.bin.should == "510510"
307
+ transaction.credit_card_details.cardholder_name.should == "The Cardholder"
306
308
  transaction.credit_card_details.last_4.should == "5100"
307
309
  transaction.credit_card_details.masked_number.should == "510510******5100"
308
310
  transaction.credit_card_details.card_type.should == "MasterCard"
@@ -583,13 +585,13 @@ describe Braintree::Transaction do
583
585
  end
584
586
 
585
587
  it "returns an error result if status is not authorized" do
586
- transaction = Braintree::Transaction.sale!(
588
+ transaction = Braintree::Transaction.sale(
587
589
  :amount => Braintree::Test::TransactionAmounts::Decline,
588
590
  :credit_card => {
589
591
  :number => Braintree::Test::CreditCardNumbers::Visa,
590
592
  :expiration_date => "06/2009"
591
593
  }
592
- )
594
+ ).transaction
593
595
  result = Braintree::Transaction.submit_for_settlement(transaction.id)
594
596
  result.success?.should == false
595
597
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotSubmitForSettlement
@@ -729,6 +731,7 @@ describe Braintree::Transaction do
729
731
  :order_id => "123",
730
732
  :type => "sale",
731
733
  :credit_card => {
734
+ :cardholder_name => "The Cardholder",
732
735
  :number => "5105105105105100",
733
736
  :expiration_date => "05/2011",
734
737
  :cvv => "123"
@@ -781,6 +784,7 @@ describe Braintree::Transaction do
781
784
  transaction.updated_at.between?(Time.now - 60, Time.now).should == true
782
785
  transaction.credit_card_details.bin.should == "510510"
783
786
  transaction.credit_card_details.last_4.should == "5100"
787
+ transaction.credit_card_details.cardholder_name.should == "The Cardholder"
784
788
  transaction.credit_card_details.masked_number.should == "510510******5100"
785
789
  transaction.credit_card_details.card_type.should == "MasterCard"
786
790
  transaction.avs_error_response_code.should == nil
@@ -878,13 +882,13 @@ describe Braintree::Transaction do
878
882
  end
879
883
 
880
884
  it "returns an error result if unsuccessful" do
881
- transaction = Braintree::Transaction.sale!(
885
+ transaction = Braintree::Transaction.sale(
882
886
  :amount => Braintree::Test::TransactionAmounts::Decline,
883
887
  :credit_card => {
884
888
  :number => Braintree::Test::CreditCardNumbers::Visa,
885
889
  :expiration_date => "05/2009"
886
890
  }
887
- )
891
+ ).transaction
888
892
  result = Braintree::Transaction.void(transaction.id)
889
893
  result.success?.should == false
890
894
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotBeVoided
@@ -906,13 +910,13 @@ describe Braintree::Transaction do
906
910
  end
907
911
 
908
912
  it "raises a ValidationsFailed if unsuccessful" do
909
- transaction = Braintree::Transaction.sale!(
913
+ transaction = Braintree::Transaction.sale(
910
914
  :amount => Braintree::Test::TransactionAmounts::Decline,
911
915
  :credit_card => {
912
916
  :number => Braintree::Test::CreditCardNumbers::Visa,
913
917
  :expiration_date => "05/2009"
914
918
  }
915
- )
919
+ ).transaction
916
920
  expect do
917
921
  Braintree::Transaction.void!(transaction.id)
918
922
  end.to raise_error(Braintree::ValidationsFailed)
@@ -992,7 +996,7 @@ describe Braintree::Transaction do
992
996
  result.success?.should == true
993
997
  transaction.amount.should == BigDecimal.new("999.99")
994
998
  transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
995
- transaction.updated_at.between?(Time.now - 5, Time.now).should == true
999
+ transaction.updated_at.between?(Time.now - 60, Time.now).should == true
996
1000
  end
997
1001
 
998
1002
  it "returns an error result if unsuccessful" do
@@ -1115,25 +1119,22 @@ describe Braintree::Transaction do
1115
1119
  }
1116
1120
  )
1117
1121
  search_results = Braintree::Transaction.search(:transaction_id => {:is => transaction.id})
1118
- search_results.total_items.should == 1
1119
- search_results[0].should == transaction
1122
+ search_results.first.should == transaction
1120
1123
  end
1121
1124
  end
1122
1125
 
1123
1126
  describe "basic" do
1124
- it "returns paged transactions matching the given search terms" do
1127
+ it "returns transactions matching the given search terms" do
1125
1128
  transactions = Braintree::Transaction.search "1111"
1126
- transactions.total_items.should > 0
1129
+ transactions._approximate_size.should > 0
1127
1130
  end
1128
1131
 
1129
- it "is paged" do
1130
- transactions = Braintree::Transaction.search "1111", :page => 2
1131
- transactions.current_page_number.should == 2
1132
- end
1132
+ it "can iterate over the entire collection" do
1133
+ transactions = Braintree::Transaction.search "411111"
1134
+ transactions._approximate_size.should > 100
1133
1135
 
1134
- it "can traverse pages" do
1135
- transactions = Braintree::Transaction.search "1111", :page => 1
1136
- transactions.next_page.current_page_number.should == 2
1136
+ transaction_ids = transactions.map {|t| t.id }.uniq.compact
1137
+ transaction_ids.size.should == transactions._approximate_size
1137
1138
  end
1138
1139
  end
1139
1140
  end
@@ -1224,13 +1225,13 @@ describe Braintree::Transaction do
1224
1225
  end
1225
1226
 
1226
1227
  it "returns an error result if unsuccessful" do
1227
- transaction = Braintree::Transaction.sale!(
1228
+ transaction = Braintree::Transaction.sale(
1228
1229
  :amount => Braintree::Test::TransactionAmounts::Decline,
1229
1230
  :credit_card => {
1230
1231
  :number => Braintree::Test::CreditCardNumbers::Visa,
1231
1232
  :expiration_date => "05/2009"
1232
1233
  }
1233
- )
1234
+ ).transaction
1234
1235
  transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
1235
1236
  result = transaction.void
1236
1237
  result.success?.should == false
@@ -1252,13 +1253,13 @@ describe Braintree::Transaction do
1252
1253
  end
1253
1254
 
1254
1255
  it "raises a ValidationsFailed if unsuccessful" do
1255
- transaction = Braintree::Transaction.sale!(
1256
+ transaction = Braintree::Transaction.sale(
1256
1257
  :amount => Braintree::Test::TransactionAmounts::Decline,
1257
1258
  :credit_card => {
1258
1259
  :number => Braintree::Test::CreditCardNumbers::Visa,
1259
1260
  :expiration_date => "05/2009"
1260
1261
  }
1261
- )
1262
+ ).transaction
1262
1263
  transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
1263
1264
  expect do
1264
1265
  transaction.void!
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "Braintree::ResourceCollection" do
4
+ it "includes enumerable" do
5
+ collection = Braintree::ResourceCollection.new(:items => ["a"])
6
+ collection.detect { |item| item == "a" }.should == "a"
7
+ end
8
+
9
+ describe "each" do
10
+ it "iterates over the contents" do
11
+ expected = ["apples", "bananas", "cherries"]
12
+ collection = Braintree::ResourceCollection.new(
13
+ :current_page_number => 1,
14
+ :items => expected,
15
+ :page_size => 5,
16
+ :total_items => expected.size
17
+ )
18
+ actual = []
19
+ collection.each do |item|
20
+ actual << item
21
+ end
22
+ actual.should == expected
23
+ end
24
+ end
25
+
26
+ describe "empty?" do
27
+ it "returns true if there are no items" do
28
+ collection = Braintree::ResourceCollection.new(
29
+ :current_page_number => 1,
30
+ :items => [],
31
+ :page_size => 5,
32
+ :total_items => 0
33
+ )
34
+ collection.should be_empty
35
+ end
36
+
37
+ it "returns false if there are items" do
38
+ collection = Braintree::ResourceCollection.new(
39
+ :current_page_number => 1,
40
+ :items => ["one"],
41
+ :page_size => 5,
42
+ :total_items => 1
43
+ )
44
+ collection.should_not be_empty
45
+ end
46
+ end
47
+
48
+ describe "first" do
49
+ it "returns the first element" do
50
+ collection = Braintree::ResourceCollection.new(
51
+ :items => ["apples", "bananas", "cherries"]
52
+ )
53
+ collection.first.should == "apples"
54
+ end
55
+ end
56
+
57
+ describe "_last_page?" do
58
+ it "returns true if the page is the last page" do
59
+ collection = Braintree::ResourceCollection.new(:current_page_number => 3, :page_size => 50, :total_items => 150)
60
+ collection._last_page?.should == true
61
+ end
62
+
63
+ it "returns false if the page is not the last page" do
64
+ collection = Braintree::ResourceCollection.new(:current_page_number => 3, :page_size => 50, :total_items => 151)
65
+ collection._last_page?.should == false
66
+ end
67
+ end
68
+ end
@@ -16,13 +16,14 @@ describe Braintree::Transaction::CreditCardDetails do
16
16
  details = Braintree::Transaction::CreditCardDetails.new(
17
17
  :bin => "123456",
18
18
  :card_type => "Visa",
19
+ :cardholder_name => "The Cardholder",
19
20
  :expiration_month => "05",
20
21
  :expiration_year => "2012",
21
22
  :last_4 => "6789",
22
23
  :token => "token",
23
24
  :customer_location => "US"
24
25
  )
25
- details.inspect.should == %(#<token: "token", bin: "123456", last_4: "6789", card_type: "Visa", expiration_date: "05/2012", customer_location: "US">)
26
+ details.inspect.should == %(#<token: "token", bin: "123456", last_4: "6789", card_type: "Visa", expiration_date: "05/2012", cardholder_name: "The Cardholder", customer_location: "US">)
26
27
  end
27
28
  end
28
29
 
@@ -123,5 +123,15 @@ describe Braintree::Xml do
123
123
  hash = {:id => "123"}
124
124
  verify_to_xml_and_back hash
125
125
  end
126
+
127
+ it "escapes keys and values" do
128
+ hash = { "ke<y" => "val>ue" }
129
+ Braintree::Xml.hash_to_xml(hash).should include("<ke&lt;y>val&gt;ue</ke&lt;y>")
130
+ end
131
+
132
+ it "escapes nested keys and values" do
133
+ hash = { "top<" => { "ke<y" => "val>ue" } }
134
+ Braintree::Xml.hash_to_xml(hash).gsub(/\s/, '').should include("<top&lt;><ke&lt;y>val&gt;ue</ke&lt;y></top&lt;>")
135
+ end
126
136
  end
127
137
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: braintree
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
7
6
  - 2
8
- - 1
9
- version: 1.2.1
7
+ - 0
8
+ - 0
9
+ version: 2.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Braintree Payment Solutions
@@ -14,10 +14,33 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-13 00:00:00 -05:00
17
+ date: 2010-04-23 00:00:00 -05:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: builder
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: libxml-ruby
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
21
44
  description: Ruby library for integrating with the Braintree Gateway
22
45
  email: devs@getbraintree.com
23
46
  executables: []
@@ -42,7 +65,7 @@ files:
42
65
  - lib/braintree/errors.rb
43
66
  - lib/braintree/exceptions.rb
44
67
  - lib/braintree/http.rb
45
- - lib/braintree/paged_collection.rb
68
+ - lib/braintree/resource_collection.rb
46
69
  - lib/braintree/ssl_expiration_check.rb
47
70
  - lib/braintree/subscription.rb
48
71
  - lib/braintree/subscription_search.rb
@@ -77,7 +100,6 @@ files:
77
100
  - spec/integration/spec_helper.rb
78
101
  - spec/script/httpsd.rb
79
102
  - spec/spec_helper.rb
80
- - spec/support/matchers/include_on_any_page.rb
81
103
  - spec/unit/braintree/address_spec.rb
82
104
  - spec/unit/braintree/base_module_spec.rb
83
105
  - spec/unit/braintree/configuration_spec.rb
@@ -88,7 +110,7 @@ files:
88
110
  - spec/unit/braintree/error_result_spec.rb
89
111
  - spec/unit/braintree/errors_spec.rb
90
112
  - spec/unit/braintree/http_spec.rb
91
- - spec/unit/braintree/paged_collection_spec.rb
113
+ - spec/unit/braintree/resource_collection_spec.rb
92
114
  - spec/unit/braintree/ssl_expiration_check_spec.rb
93
115
  - spec/unit/braintree/subscription_search_spec.rb
94
116
  - spec/unit/braintree/subscription_spec.rb
@@ -1,24 +0,0 @@
1
- Spec::Matchers.define :include_on_any_page do |expected|
2
- match do |collection|
3
- on_any_page?(collection, expected)
4
- end
5
-
6
- def on_any_page?(collection, expected)
7
- return true if collection.any? { |item| item.id == expected.id }
8
- return false if collection.last_page?
9
-
10
- on_any_page?(collection.next_page, expected)
11
- end
12
-
13
- failure_message_for_should do |collection|
14
- "expected that the paged collection would include an item with id #{expected.id}"
15
- end
16
-
17
- failure_message_for_should_not do |collection|
18
- "expected that the paged collection would not include an item with id #{expected.id}"
19
- end
20
-
21
- description do
22
- "include the given subsription in the paged collection"
23
- end
24
- end
@@ -1,178 +0,0 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "Braintree::PagedCollection" do
4
- it "includes enumerable" do
5
- collection = Braintree::PagedCollection.new(:items => ["a"])
6
- collection.detect { |item| item == "a" }.should == "a"
7
- end
8
-
9
- describe "[]" do
10
- it "returns the element at the given index" do
11
- collection = Braintree::PagedCollection.new(:items => ["one", "two", "three"])
12
- collection[0].should == "one"
13
- collection[2].should == "three"
14
- collection[3].should == nil
15
- end
16
- end
17
-
18
- describe "each" do
19
- it "iterates over the contents" do
20
- expected = ["apples", "bananas", "cherries"]
21
- collection = Braintree::PagedCollection.new(
22
- :items => expected
23
- )
24
- actual = []
25
- collection.each do |item|
26
- actual << item
27
- end
28
- actual.should == expected
29
- end
30
- end
31
-
32
- describe "first" do
33
- it "returns the first element" do
34
- collection = Braintree::PagedCollection.new(
35
- :items => ["apples", "bananas", "cherries"]
36
- )
37
- collection.first.should == "apples"
38
- end
39
- end
40
-
41
- describe "initialize" do
42
- it "initializes attributes as expected" do
43
- collection = Braintree::PagedCollection.new(
44
- :current_page_number => 1,
45
- :page_size => 2,
46
- :total_items => 4,
47
- :items => ["apples", "bananas", "cherries"]
48
- )
49
- collection.current_page_number.should == 1
50
- collection.page_size.should == 2
51
- collection.total_items.should == 4
52
- collection.items.should == ["apples", "bananas", "cherries"]
53
- end
54
- end
55
-
56
- describe "last_page?" do
57
- it "returns true if the page is the last page" do
58
- collection = Braintree::PagedCollection.new(:current_page_number => 3, :page_size => 50, :total_items => 150)
59
- collection.last_page?.should == true
60
- end
61
-
62
- it "returns false if the page is not the last page" do
63
- collection = Braintree::PagedCollection.new(:current_page_number => 3, :page_size => 50, :total_items => 151)
64
- collection.last_page?.should == false
65
- end
66
- end
67
-
68
- describe "next_page" do
69
- it "returns the next page of results" do
70
- collection = Braintree::PagedCollection.new(
71
- :current_page_number => 1,
72
- :page_size => 1,
73
- :total_items => 2
74
- ) do |page_num|
75
- "contents of page #{page_num}"
76
- end
77
- collection.next_page.should == "contents of page 2"
78
- end
79
-
80
- it "returns nil if on last page" do
81
- collection = Braintree::PagedCollection.new(
82
- :current_page_number => 2,
83
- :page_size => 2,
84
- :total_items => 4
85
- )
86
- collection.next_page.should == nil
87
- end
88
- end
89
-
90
- describe "next_page_number" do
91
- it "returns the next page number when not on the last page" do
92
- collection = Braintree::PagedCollection.new(
93
- :current_page_number => 2,
94
- :page_size => 1,
95
- :total_items => 50
96
- )
97
- collection.next_page_number.should == 3
98
- end
99
-
100
- it "returns nil when on the last page" do
101
- collection = Braintree::PagedCollection.new(
102
- :current_page_number => 1,
103
- :page_size => 1,
104
- :total_items => 1
105
- )
106
- collection.next_page_number.should == nil
107
- end
108
- end
109
-
110
- describe "total_pages" do
111
- it "calculates the total number of pages when total items is not evenly divisible by page size" do
112
- collection = Braintree::PagedCollection.new(
113
- :page_size => 5,
114
- :total_items => 13
115
- )
116
- collection.total_pages.should == 3
117
- end
118
-
119
- it "calculates the total number of pages when total items is not evenly divisible by page size" do
120
- collection = Braintree::PagedCollection.new(
121
- :page_size => 5,
122
- :total_items => 20
123
- )
124
- collection.total_pages.should == 4
125
- end
126
- end
127
-
128
- context "custom matchers" do
129
- require 'enumerator'
130
-
131
- DummyItem = Struct.new(:id)
132
-
133
- def paged_collection(items, page_size)
134
- pages = []
135
- items.each_slice(page_size) do |slice|
136
- pages << slice
137
- end
138
-
139
- _build_collection(pages, page_size, items.size, 1)
140
- end
141
-
142
- def _build_collection(paged_items, page_size, total_size, current_page)
143
- Braintree::PagedCollection.new(:items => paged_items[current_page - 1], :total_items => total_size, :page_size => page_size, :current_page_number => current_page) do |page|
144
- _build_collection(paged_items, page_size, total_size, page)
145
- end
146
- end
147
-
148
- describe "include_on_any_page" do
149
- it "finds a match in a simple collection" do
150
- element = DummyItem.new(123)
151
- collection = paged_collection([element], 10)
152
-
153
- collection.should include_on_any_page(element)
154
- end
155
-
156
- it "does not find a match in a simple collection" do
157
- element = DummyItem.new(1)
158
- collection = paged_collection([DummyItem.new(2)], 10)
159
-
160
- collection.should_not include_on_any_page(element)
161
- end
162
-
163
- it "finds a match on a subsequent page" do
164
- element = DummyItem.new(1)
165
- collection = paged_collection([DummyItem.new(2), element], 1)
166
-
167
- collection.should include_on_any_page(element)
168
- end
169
-
170
- it "does not find a match on a subsequent page" do
171
- element = DummyItem.new(1)
172
- collection = paged_collection([DummyItem.new(2), DummyItem.new(3)], 1)
173
-
174
- collection.should_not include_on_any_page(element)
175
- end
176
- end
177
- end
178
- end