Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Conditionally force encoding based on RUBY_VERSION and dup input valu…

…es before encoding
  • Loading branch information...
commit 22b351f4bd15fca08af9e0ee689f1df75bea253c 1 parent 2638ea7
@d11wtq d11wtq authored
Showing with 23 additions and 17 deletions.
  1. +10 −6 lib/dm-core/property/binary.rb
  2. +13 −11 spec/public/property/binary_spec.rb
View
16 lib/dm-core/property/binary.rb
@@ -3,14 +3,18 @@ class Property
class Binary < String
include PassThroughLoadDump
- def load(value)
- super.force_encoding("BINARY") if value
- end
+ if RUBY_VERSION >= "1.9"
+
+ def load(value)
+ super.dup.force_encoding("BINARY") if value
+ end
+
+ def dump(value)
+ super.dup.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
24 spec/public/property/binary_spec.rb
@@ -20,20 +20,22 @@
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
+ 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
- end
- it 'should always dump with BINARY' do
- model.bin_data.dump("foo").encoding.names.should include("BINARY")
- 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").encoding.names.should include("BINARY")
+ it 'should always load with BINARY' do
+ model.bin_data.load("foo".freeze).encoding.names.should include("BINARY")
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.