Skip to content
Browse files

Fix issue with Binary properties being treated like normal Strings, w…

…hich breaks dm-validations since it uses =~ /\S/ assuming valid UTF-8
  • Loading branch information...
1 parent e14d6ba commit 2638ea7a9be42b337479e0ee450aed81d6883e25 @d11wtq d11wtq committed Sep 11, 2011
Showing with 26 additions and 0 deletions.
  1. +9 −0 lib/dm-core/property/binary.rb
  2. +17 −0 spec/public/property/binary_spec.rb
View
9 lib/dm-core/property/binary.rb
@@ -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
View
17 spec/public/property/binary_spec.rb
@@ -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.
Something went wrong with that request. Please try again.