Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Fix issue with Binary properties being treated like normal Strings, w…
Browse files Browse the repository at this point in the history
…hich breaks dm-validations since it uses =~ /\S/ assuming valid UTF-8
  • Loading branch information
d11wtq committed Sep 13, 2011
1 parent e14d6ba commit 2638ea7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/dm-core/property/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ module DataMapper
class Property
class Binary < String
include PassThroughLoadDump

def load(value)
super.force_encoding("BINARY") if value
end

def dump(value)
super.force_encoding("BINARY") if value
end

end # class Binary
end # class Property
end # module DataMapper
17 changes: 17 additions & 0 deletions spec/public/property/binary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,21 @@

it { should eql(:primitive => @primitive, :length => 50) }
end

describe 'encoding' do
let(:model) do
Class.new do
include ::DataMapper::Resource
property :bin_data, ::DataMapper::Property::Binary
end
end

it 'should always dump with BINARY' do
model.bin_data.dump("foo").encoding.names.should include("BINARY")
end

it 'should always load with BINARY' do
model.bin_data.load("foo").encoding.names.should include("BINARY")
end
end
end

0 comments on commit 2638ea7

Please sign in to comment.