Sha256: 6d6f5b9713be53af9cd92fc7a8620656de8e8db044c04176971d65a22624f953

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'test_helper'

module Vedeu
  class TestClass
    include Collection

    def initialize(*args); end
  end

  describe Collection do
    describe '#coercer' do
      it 'returns an empty collection when nil or empty' do
        [nil, '', [], {}].each do |empty_value|
          Collection.coercer(empty_value, TestClass, :key).must_equal([])
        end
      end

      it 'returns a single model in a collection when a String' do
        Collection.coercer('test', TestClass, :key).size.must_equal(1)
      end

      it 'returns a collection of models when a single hash' do
        Collection.coercer({ :test1 => 'test1' }, TestClass, :key)
          .size.must_equal(1)
      end

      it 'returns a collection of models when multiple hashes' do
        Collection.coercer([
          { :test1 => 'test1' }, { :test2 => 'test2' }
        ], TestClass, :key).size.must_equal(2)
      end

      it 'returns a collection of models when a single array' do
        Collection.coercer([{ :test3 => 'test3' }], TestClass, :key)
          .size.must_equal(1)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.10 test/lib/vedeu/models/attributes/collection_test.rb