Sha256: 671141f8a1a0bcfd79d5e73590458460dc2381cb51d57cfa5b38de56368e6095

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe ButterCMS::ButterCollection do
  let(:json) { {"data" => ["foo"], "meta" => {}} }
  let(:klass) { double('klass', :new => 'bar') }

  it 'implements #items' do
    collection = ButterCMS::ButterCollection.new(klass, json)

    expect(collection.items).to match_array(["bar"])
  end

  it 'implements #meta' do
    collection = ButterCMS::ButterCollection.new(klass, json)

    expect(collection.meta).to be_a(OpenStruct)
  end

  it 'implements #count' do
    collection = ButterCMS::ButterCollection.new(klass, json)

    expect(collection.count).to eq 1
  end

  # Marshal.load (used by Rails for caching) was not restoring the ButterResource's dynamic methods
  # See https://github.com/ButterCMS/buttercms-ruby/issues/13
  describe 'marshal load' do
    subject { described_class.new(ButterCMS::ButterResource, 'data' => [{ 'name' => 'Test Name', 'description' => 'Test Description' }]) }

    it 'restores the ButterResource dynamic methods' do
      collection = Marshal.load(Marshal.dump(subject))
      resource = collection.first

      aggregate_failures do
        expect(resource.name).to eq('Test Name')
        expect(resource.description).to eq('Test Description')
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
buttercms-ruby-zwg-2.5.7 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-zwg-2.5.2 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-zwg-2.5.3 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-zwg-2.4.2 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-zwg-2.4.1 spec/lib/buttercms/butter_collection_spec.rb
zuzanky-buttercms-ruby-2.4 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-2.4 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-2.3 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-2.2 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-2.1 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-2.0 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-1.9 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-1.8 spec/lib/buttercms/butter_collection_spec.rb
buttercms-ruby-1.7 spec/lib/buttercms/butter_collection_spec.rb