This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed problem with Resource#save failing with custom properties
* Resource#save now tests the loaded value rather than the dumped value for validity. * Updated variable names to differentiate between a loaded value and a dumped value. A loaded value is what is set within the Resource after retrieving/loading/typecasting it. A dumped value is what is stored in the datastore. * Fixed Object type so if loaded value is nil, it will just store nil rather than sending an encoded String to the datastore * Fixed Property#primitive? so that properties with a Text primitive can be tested for validity. * Added specs for Object type [#1118 state:resolved]
- Loading branch information
Showing
7 changed files
with
143 additions
and
42 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
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
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
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,100 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')) | ||
|
||
describe DataMapper::Property, 'Object type' do | ||
before :all do | ||
module ::Blog | ||
class Article | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
property :title, String | ||
property :meta, Object, :nullable => false | ||
end | ||
end | ||
|
||
@model = Blog::Article | ||
@property = @model.properties[:meta] | ||
end | ||
|
||
subject { @property } | ||
|
||
it { should respond_to(:typecast) } | ||
|
||
describe '#typecast' do | ||
before do | ||
@value = { 'lang' => 'en_CA' } | ||
end | ||
|
||
subject { @property.typecast(@value) } | ||
|
||
it { should equal(@value) } | ||
end | ||
|
||
it { should respond_to(:value) } | ||
|
||
describe '#value' do | ||
describe 'with a value' do | ||
subject { @property.value('lang' => 'en_CA') } | ||
|
||
it { should == "BAh7BiIJbGFuZyIKZW5fQ0E=\n" } | ||
end | ||
|
||
describe 'with nil' do | ||
subject { @property.value(nil) } | ||
|
||
it { should be_nil } | ||
end | ||
end | ||
|
||
it { should respond_to(:valid?) } | ||
|
||
describe '#valid?' do | ||
describe 'with a valid primitive' do | ||
subject { @property.valid?('lang' => 'en_CA') } | ||
|
||
it { should be_true } | ||
end | ||
|
||
describe 'with nil and property is nullable' do | ||
before do | ||
@property = @model.property(:meta, Object, :nullable => true) | ||
end | ||
|
||
subject { @property.valid?(nil) } | ||
|
||
it { should be_true } | ||
end | ||
|
||
describe 'with nil and property is not nullable' do | ||
subject { @property.valid?(nil) } | ||
|
||
it { should be_false } | ||
end | ||
|
||
describe 'with nil and property is not nullable, but validity is negated' do | ||
subject { @property.valid?(nil, true) } | ||
|
||
it { should be_true } | ||
end | ||
end | ||
|
||
describe 'persistable' do | ||
supported_by :all do | ||
before :all do | ||
@do_adapter = defined?(DataMapper::Adapters::DataObjectsAdapter) && @adapter.kind_of?(DataMapper::Adapters::DataObjectsAdapter) | ||
end | ||
|
||
before :all do | ||
@resource = @model.create(:title => 'Test', :meta => { 'lang' => 'en_CA' }) | ||
end | ||
|
||
subject { @resource.reload.meta } | ||
|
||
it 'should load the correct value' do | ||
pending_if 'Fix adapters to use different serialization methods', !@do_adapter do | ||
should == { 'lang' => 'en_CA' } | ||
end | ||
end | ||
end | ||
end | ||
end |