Permalink
Browse files

specs and tweaks for yaml serialization

  • Loading branch information...
bkeepers committed May 4, 2010
1 parent e22ac4e commit 0885b196124a5c5d4ab95b644ba5d5ab5ad2a1e6
@@ -5,6 +5,8 @@ class ActiveRecord::Base
def self.yaml_new(klass, tag, val)
klass.find(val['attributes']['id'])
+ rescue ActiveRecord::RecordNotFound
+ nil
end
def to_yaml_properties
@@ -1,7 +1,18 @@
require 'dm-core'
require 'dm-observer'
require 'dm-aggregates'
-require 'dm-serializer'
+
+DataMapper::Resource.class_eval do
+ yaml_as "tag:ruby.yaml.org,2002:DataMapper"
+
+ def self.yaml_new(klass, tag, val)
+ klass.find(val['id'])
+ end
+
+ def to_yaml_properties
+ ['@id']
+ end
+end
module Delayed
module Backend
@@ -4,9 +4,7 @@
yaml_as "tag:ruby.yaml.org,2002:MongoMapper"
def self.yaml_new(klass, tag, val)
- klass.find!(val['_id'])
- rescue MongoMapper::DocumentNotFound
- nil
+ klass.find(val['_id'])
end
def to_yaml_properties
@@ -270,4 +270,22 @@ def create_job(opts = {})
@job.id.should_not be_nil
end
end
+
+ describe "yaml serialization" do
+ it "should reload changed attributes" do
+ job = @backend.enqueue SimpleJob.new
+ yaml = job.to_yaml
+ job.priority = 99
+ job.save
+ YAML.load(yaml).priority.should == 99
+ end
+
+ it "should ignore destroyed records" do
+ job = @backend.enqueue SimpleJob.new
+ yaml = job.to_yaml
+ job.destroy
+ lambda { YAML.load(yaml).should be_nil }.should_not raise_error
+ end
+ end
+
end

0 comments on commit 0885b19

Please sign in to comment.