diff --git a/Gemfile b/Gemfile index 4ac0c5306..21d8437af 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' gem 'rake' -platforms :ruby do +platforms :ruby, :mingw do gem 'sqlite3' end diff --git a/lib/delayed/psych_ext.rb b/lib/delayed/psych_ext.rb index 827a685f5..5c9e378b5 100644 --- a/lib/delayed/psych_ext.rb +++ b/lib/delayed/psych_ext.rb @@ -36,7 +36,9 @@ def visit_Class(klass) end class ToRuby - def visit_Psych_Nodes_Scalar(o) + original_visit_Psych_Nodes_Scalar_method = instance_method(:visit_Psych_Nodes_Scalar) + + define_method(:visit_Psych_Nodes_Scalar) do |o| @st[o.anchor] = o.value if o.anchor if klass = Psych.load_tags[o.tag] @@ -57,6 +59,9 @@ def visit_Psych_Nodes_Scalar(o) case o.tag when '!binary', 'tag:yaml.org,2002:binary' o.value.unpack('m').first + when '!ruby/object:BigDecimal' + require 'bigdecimal' + BigDecimal._load o.value when '!str', 'tag:yaml.org,2002:str' o.value when "!ruby/object:DateTime" @@ -94,7 +99,7 @@ def visit_Psych_Nodes_Scalar(o) when /^!ruby\/sym(bol)?:?(.*)?$/ o.value.to_sym else - @ss.tokenize o.value + original_visit_Psych_Nodes_Scalar_method.bind(self).call o end end diff --git a/spec/delayed/psych_ext_spec.rb b/spec/delayed/psych_ext_spec.rb new file mode 100644 index 000000000..86cc7391c --- /dev/null +++ b/spec/delayed/psych_ext_spec.rb @@ -0,0 +1,12 @@ +require 'helper' + +describe 'Psych::Visitors::ToRuby', :if => defined?(Psych::Visitors::ToRuby) do + context BigDecimal do + it 'deserializes correctly' do + deserialized = YAML.load("--- !ruby/object:BigDecimal 18:0.1337E2\n...\n") + + expect(deserialized).to be_an_instance_of(BigDecimal) + expect(deserialized).to eq(BigDecimal('13.37')) + end + end +end diff --git a/spec/helper.rb b/spec/helper.rb index 7cd1108c0..00bcf771b 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -11,13 +11,15 @@ require 'simplecov' require 'coveralls' +require 'tempfile' + SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ] SimpleCov.start -Delayed::Worker.logger = Logger.new('/tmp/dj.log') +Delayed::Worker.logger = Logger.new(Tempfile.new('dj.log')) ENV['RAILS_ENV'] = 'test' Delayed::Worker.backend = :test