Sha256: cc3f4ef97c9649a3e6ba88e22ef9c73af6a67a1a74b3558dc3050253a36f8658
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
require 'test_helper' module Vedeu describe Coercions do describe '.coercer' do [nil, [], {}].each do |empty_value| it 'returns an empty collection when nil or empty' do CoercionsTestClass.coercer(empty_value).must_equal([]) end end it 'returns when an object' do klass = CoercionsTestClass.new CoercionsTestClass.coercer([klass]).must_equal([klass]) end it 'returns a collection of models when a single hash' do coerced = CoercionsTestClass.coercer({ :name => 'test1' }) coerced.must_be_instance_of(Array) coerced.first.attributes.must_equal({ name: "test1" }) end it 'returns a collection of models when multiple hashes' do coerced = CoercionsTestClass.coercer([ { :name => 'test1' }, { :name => 'test2' } ]) coerced.size.must_equal(2) coerced.map(&:attributes).must_equal( [{ name: "test1" }, { name: "test2" }] ) end it 'returns a collection of models when a single array' do coerced = CoercionsTestClass.coercer([{ :name => 'test3' }]) coerced.size.must_equal(1) coerced.first.attributes.must_equal({ name: "test3" }) end end end # Coercions end # Vedeu
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.2.12 | test/lib/vedeu/support/coercions_test.rb |
vedeu-0.2.11 | test/lib/vedeu/support/coercions_test.rb |