Skip to content

Loading…

Issue 174 release 1.2 dm-core #52

Open
wants to merge 3 commits into from

3 participants

@lance

Good morning. This is a fix for release 1.2 for dm-core issue #174 datamapper/dm-core#174

According to old Lighthouse bugs and such, the issue has been resolved in dm-core a while back. But it seems, if you require dm-validations (or require 'data_mapper' since it does this by proxy), then things go bad again. This is because there are several places within dm-validations where a default value is generated by a proc supplied to the Hash constructor. Marshal.dump/load doesn't deal well with procs for default values. This should all be resolved in the 1.2 line.

I'm working on a fix for the master branch, but it seems this pattern of using procs for hash defaults has propagated, and there is much more to muck with for the master branch.

Lance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 8, 2011
  1. @markiz
Commits on Dec 7, 2011
  1. @emmanuel
Commits on Jan 23, 2012
  1. @lance

    Fix for issue #174

    lance committed
View
4 lib/dm-validations/validation_errors.rb
@@ -46,7 +46,7 @@ def self.default_error_message(key, field, *values)
def initialize(resource)
@resource = resource
- @errors = DataMapper::Validations::OrderedHash.new { |h,k| h[k] = [] }
+ @errors = DataMapper::Validations::OrderedHash.new
end
# Clear existing validation errors.
@@ -123,6 +123,8 @@ def respond_to?(method)
def [](property_name)
if (property_errors = errors[property_name.to_sym])
property_errors
+ else
+ []
end
end
View
2 lib/dm-validations/validators/block_validator.rb
@@ -50,7 +50,7 @@ def validates_with_block(*fields, &block)
method_name = "__validates_with_block_#{@__validates_with_block_count}".to_sym
define_method(method_name, &block)
- options = fields.last.is_a?(Hash) ? fields.last.pop.dup : {}
+ options = fields.last.is_a?(Hash) ? fields.pop.dup : {}
options[:method] = method_name
fields = [method_name] if fields.empty?
View
4 spec/fixtures/g3_concert.rb
@@ -14,13 +14,13 @@ class G3Concert
# Attributes
#
- attr_accessor :year, :participants, :city
+ attr_accessor :year, :participants, :city, :planned
#
# Validations
#
- validates_with_block :participants do
+ validates_with_block :participants, :unless => :planned do
if self.class.known_performances.any? { |perf| perf == self }
true
else
View
9 spec/integration/block_validator/block_validator_spec.rb
@@ -29,4 +29,13 @@
it_should_behave_like "valid model"
end
+
+ describe "planned concert for non-existing year/participants/city combinations" do
+ before :all do
+ @model.planned = true
+ @model.year = 2021
+ end
+
+ it_should_behave_like "valid model"
+ end
end
View
15 spec/public/resource_spec.rb
@@ -102,4 +102,19 @@
end
end
end
+
+ describe 'Marshal' do
+ before :all do
+ @resource.save
+ end
+
+ describe 'Marshal.load(Marshal.dump(resource))' do
+ it 'should not raise an error' do
+ Marshal.load(Marshal.dump(@resource)).should == @resource
+ end
+ end
+ end
end
+
+
+
Something went wrong with that request. Please try again.