diff --git a/lib/dm-validations/validation_errors.rb b/lib/dm-validations/validation_errors.rb index 603b274f..c54f6163 100644 --- a/lib/dm-validations/validation_errors.rb +++ b/lib/dm-validations/validation_errors.rb @@ -116,8 +116,8 @@ def method_missing(meth, *args, &block) errors.send(meth, *args, &block) end - def respond_to?(method) - super || errors.respond_to?(method) + def respond_to?(method, include_all=false) + super || errors.respond_to?(method, include_all) end def [](property_name) diff --git a/lib/dm-validations/validators/block_validator.rb b/lib/dm-validations/validators/block_validator.rb index eab8bd43..f5ddff86 100644 --- a/lib/dm-validations/validators/block_validator.rb +++ b/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? diff --git a/spec/fixtures/g3_concert.rb b/spec/fixtures/g3_concert.rb index 0cc55787..9d328d86 100644 --- a/spec/fixtures/g3_concert.rb +++ b/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 diff --git a/spec/integration/block_validator/block_validator_spec.rb b/spec/integration/block_validator/block_validator_spec.rb index 2db80eba..2b747ebf 100644 --- a/spec/integration/block_validator/block_validator_spec.rb +++ b/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