Skip to content

Commit

Permalink
basic patch and spec for #992
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Apr 22, 2014
1 parent 16a528a commit dbcd8ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/formtastic/inputs/base/validations.rb
Expand Up @@ -37,6 +37,8 @@ def validator_relevant?(validator)

result = if conditional.respond_to?(:call) && conditional.arity > 0
conditional.call(object)
elsif conditional.respond_to?(:call) && conditional.arity == 0
object.instance_exec(&conditional)
elsif conditional.is_a?(::Symbol) && object.respond_to?(conditional)
object.send(conditional)
else
Expand Down
12 changes: 12 additions & 0 deletions spec/inputs/string_input_spec.rb
Expand Up @@ -108,6 +108,18 @@ def should_have_maxlength(maxlength, options)
should_have_maxlength(42, :options => { :maximum => 42, :unless => :specify_maxlength })
end
end

describe 'and validates_presence_of was called for the method' do
it 'does not blow up with a proc calling an instance method' do
@new_post.class.should_receive(:validators_on).with(:title).at_least(1).and_return([
active_model_presence_validator([:title], { :unless => -> { something? } })
])

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end)
end
end
end
end

Expand Down

0 comments on commit dbcd8ab

Please sign in to comment.