-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace EmbeddedValue#set with EmbeddedValue#coerce
* this change is required so that it works correctly with collection member coercions
- Loading branch information
Showing
3 changed files
with
55 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 |
This file was deleted.
Oops, something went wrong.