Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Object#respond_to? takes an optional second argument in 2.0 #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/dm-validations/validation_errors.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/dm-validations/validators/block_validator.rb
Expand Up @@ -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?

Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/g3_concert.rb
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/block_validator/block_validator_spec.rb
Expand Up @@ -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