From 0bacde0c7ed020ede6f696b6b2ee769eaf2dbfc0 Mon Sep 17 00:00:00 2001 From: Jarmo Pertman Date: Tue, 8 Oct 2013 22:22:30 +0300 Subject: [PATCH 1/5] Make development environment working on Windows too. --- Gemfile | 2 +- spec/helper.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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/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 From 0d998398defc72a59bbcef687fc4bf1af5188e43 Mon Sep 17 00:00:00 2001 From: Jarmo Pertman Date: Tue, 8 Oct 2013 22:23:10 +0300 Subject: [PATCH 2/5] Fix deserialization of BigDecimal. Fixes #588. --- lib/delayed/psych_ext.rb | 4 +++- spec/delayed/psych_ext_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 spec/delayed/psych_ext_spec.rb diff --git a/lib/delayed/psych_ext.rb b/lib/delayed/psych_ext.rb index 827a685f5..5b5b8566b 100644 --- a/lib/delayed/psych_ext.rb +++ b/lib/delayed/psych_ext.rb @@ -36,6 +36,8 @@ def visit_Class(klass) end class ToRuby + alias_method :original_visit_Psych_Nodes_Scalar, :visit_Psych_Nodes_Scalar + def visit_Psych_Nodes_Scalar(o) @st[o.anchor] = o.value if o.anchor @@ -94,7 +96,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 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..14817067b --- /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 From 5f1c475b7656037dbd0578a61baf401fb66c8c7d Mon Sep 17 00:00:00 2001 From: Jarmo Pertman Date: Tue, 8 Oct 2013 22:26:35 +0300 Subject: [PATCH 3/5] Fix quotes. --- spec/delayed/psych_ext_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/delayed/psych_ext_spec.rb b/spec/delayed/psych_ext_spec.rb index 14817067b..86cc7391c 100644 --- a/spec/delayed/psych_ext_spec.rb +++ b/spec/delayed/psych_ext_spec.rb @@ -1,12 +1,12 @@ require 'helper' -describe "Psych::Visitors::ToRuby", :if => defined?(Psych::Visitors::ToRuby) do +describe 'Psych::Visitors::ToRuby', :if => defined?(Psych::Visitors::ToRuby) do context BigDecimal do - it "deserializes correctly" 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")) + expect(deserialized).to eq(BigDecimal('13.37')) end end end From ed14ca6974159855f0d3c2673f0516eb0f2499e0 Mon Sep 17 00:00:00 2001 From: Jarmo Pertman Date: Tue, 8 Oct 2013 22:41:06 +0300 Subject: [PATCH 4/5] Do not expose original visit_Psych_Nodes_Scalar method to outside scope. --- lib/delayed/psych_ext.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/delayed/psych_ext.rb b/lib/delayed/psych_ext.rb index 5b5b8566b..5283d8e6e 100644 --- a/lib/delayed/psych_ext.rb +++ b/lib/delayed/psych_ext.rb @@ -36,9 +36,9 @@ def visit_Class(klass) end class ToRuby - alias_method :original_visit_Psych_Nodes_Scalar, :visit_Psych_Nodes_Scalar + original_visit_Psych_Nodes_Scalar_method = instance_method(:visit_Psych_Nodes_Scalar) - def visit_Psych_Nodes_Scalar(o) + define_method(:visit_Psych_Nodes_Scalar) do |o| @st[o.anchor] = o.value if o.anchor if klass = Psych.load_tags[o.tag] @@ -96,7 +96,7 @@ def visit_Psych_Nodes_Scalar(o) when /^!ruby\/sym(bol)?:?(.*)?$/ o.value.to_sym else - original_visit_Psych_Nodes_Scalar o + original_visit_Psych_Nodes_Scalar_method.bind(self).call o end end From e8db7863a1ad16c3a54d109fcde6ef964e73c47c Mon Sep 17 00:00:00 2001 From: Jarmo Pertman Date: Tue, 8 Oct 2013 23:16:19 +0300 Subject: [PATCH 5/5] Try to make it work with Ruby 1.9.2 too. Damn! --- lib/delayed/psych_ext.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/delayed/psych_ext.rb b/lib/delayed/psych_ext.rb index 5283d8e6e..5c9e378b5 100644 --- a/lib/delayed/psych_ext.rb +++ b/lib/delayed/psych_ext.rb @@ -59,6 +59,9 @@ class ToRuby 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"