Permalink
Browse files

Merge pull request #141 from d11wtq/bugfix/binary-encoding2

Fix Binary property type to specify 'binary' encoding under >= 1.9
  • Loading branch information...
2 parents e14d6ba + 5b9bebd commit 8765c85189d7ec53b49f314223755bd25e14ebb8 @solnic solnic committed Sep 13, 2011
Showing with 32 additions and 0 deletions.
  1. +13 −0 lib/dm-core/property/binary.rb
  2. +19 −0 spec/public/property/binary_spec.rb
@@ -2,6 +2,19 @@ module DataMapper
class Property
class Binary < String
include PassThroughLoadDump
+
+ if RUBY_VERSION >= "1.9"
+
+ def load(value)
+ super.dup.force_encoding("BINARY") unless value.nil?
+ end
+
+ def dump(value)
+ super.dup.force_encoding("BINARY") unless value.nil?
+ end
+
+ end
+
end # class Binary
end # class Property
end # module DataMapper
@@ -19,4 +19,23 @@
it { should eql(:primitive => @primitive, :length => 50) }
end
+
+ if RUBY_VERSION >= "1.9"
+ 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".freeze).encoding.names.should include("BINARY")
+ end
+
+ it 'should always load with BINARY' do
+ model.bin_data.load("foo".freeze).encoding.names.should include("BINARY")
+ end
+ end
+ end
end

0 comments on commit 8765c85

Please sign in to comment.