Sha256: 03e94869ced8177fcb42fed1df7b0b68c86f5bc9279b3000543d04d570873e6c

Contents?: true

Size: 1.76 KB

Versions: 16

Compression:

Stored size: 1.76 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe "Braintree::ResourceCollection" do
  describe "enumeration" do
    it "iterates over the elements, yielding to the block in pages" do
      values = %w(a b c d e)
      collection = Braintree::ResourceCollection.new(:search_results => {:ids => [0,1,2,3,4], :page_size => 2}) do |ids|
        ids.map { |id| values[id] }
      end

      count = 0
      collection.each_with_index do |item, index|
        item.should == values[index]
        count += 1
      end

      count.should == 5
    end
  end

  describe "#first" do
    it "returns nil with no results" do
      values = %w(a b c d e)
      collection = Braintree::ResourceCollection.new(:search_results => {:ids => [], :page_size => 2}) do |ids|
        ids.map { |id| values[id] }
      end

      collection.first.should == nil
    end

    context "with results" do
      let(:collection) do
        values = %w(a b c d e)

        Braintree::ResourceCollection.new(:search_results => {:ids => [0,1,2,3,4], :page_size => 2}) do |ids|
          ids.map { |id| values[id] }
        end
      end

      it "returns the first occourence" do
        collection.first.should == "a"
      end

      it "returns the first N occourences" do
        collection.first(4).should == ["a","b","c","d"]
      end
    end
  end

  describe "#ids" do
    it "returns a list of the resource collection ids" do
      collection = Braintree::ResourceCollection.new(:search_results => {:ids => [0,1,2,3,4], :page_size => 2})
      collection.ids.should == [0,1,2,3,4]
    end
  end

  it "returns an empty array when the collection is empty" do
    collection = Braintree::ResourceCollection.new(:search_results => {:page_size => 2})
    collection.ids.should == []
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
braintree-4.14.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.13.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.12.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.11.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.10.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.9.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.8.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.7.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.6.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.5.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.4.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.3.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.2.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.1.0 spec/unit/braintree/resource_collection_spec.rb
braintree-4.0.0 spec/unit/braintree/resource_collection_spec.rb
braintree-3.4.0 spec/unit/braintree/resource_collection_spec.rb