Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Ensure attributes= typecasts values for Property keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
gix authored and dkubb committed Mar 16, 2013
1 parent b439e1f commit f4ae661
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/dm-core/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ def attributes=(attributes)
raise ArgumentError, "The attribute '#{name}' is not accessible in #{model}"
end
when Associations::Relationship, Property
# only call a public #typecast (e.g. on Property instances)
if name.respond_to?(:typecast)
value = name.typecast(value)
end
self.persistence_state = persistence_state.set(name, value)
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/dm-core/spec/shared/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,17 @@
describe 'when a public mutator is specified' do
before :all do
rescue_if @skip do
@user.attributes = { :name => 'dkubb' }
@user.attributes = { :name => 'dkubb', @user.class.properties[:age] => '42' }
end
end

it 'should set the value' do
@user.name.should eql('dkubb')
end

it 'should typecast and set the value' do
@user.age.should eql(42)
end
end

describe 'when a non-public mutator is specified' do
Expand Down

0 comments on commit f4ae661

Please sign in to comment.