Sha256: ca91db94c7a254337a0686ef906689a8638bd61acd09d668b8e814e9a0671c39
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
require 'spec_helper' describe Virtus::Attribute::EmbeddedValue, '#coerce' do subject { object.coerce(value) } let(:attribute_name) { :attribute_name } let(:model) { OpenStruct } let(:instance) { Object.new } context 'when the value is a hash' do let(:value) { Hash[:foo => 'bar'] } context 'when the options include the model' do let(:object) { described_class.new(attribute_name, :model => model) } let(:model) { mock('model') } let(:model_instance) { mock('model_instance') } before do model.should_receive(:new).with(value).and_return(model_instance) end it { should be(model_instance) } end context 'with the default OpenStruct model' do let(:model_instance) { OpenStruct.new(value) } context 'when the options are an empty Hash' do let(:object) { described_class.new(attribute_name, {}) } it { should == model_instance } end context 'when the options are not provided' do let(:object) { described_class.new(attribute_name) } it { should == model_instance } end end end context 'when the value is not a hash' do let(:object) { described_class.new(attribute_name) } let(:value) { mock('value') } before { model.should_not_receive(:new) } it { should be(value) } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
virtus-0.2.0 | spec/unit/virtus/attribute/embedded_value/coerce_spec.rb |
virtus-0.1.0 | spec/unit/virtus/attribute/embedded_value/coerce_spec.rb |