beginning of .invalid and .valid selections

This commit is contained in:
Gant
2014-08-01 14:01:24 -05:00
parent fbdce9a2a4
commit 592bddd063
2 changed files with 14 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
module RubyMotionQuery
class RMQ
attr_reader :valid, :invalid
# @return [Validation]
def self.validation
Validation
@@ -26,9 +28,14 @@ module RubyMotionQuery
self
end
# This method validates all the selected and is responsible for filling
# invalid/valid arrays as well as calling invalid/valid events
#
# @return [Boolean] false if any validations fail
def valid?
result = true
@invalid = []
@valid = []
selected.each do |view|
view.rmq_data.validations.each do |validation|
@@ -36,10 +43,12 @@ module RubyMotionQuery
has_events = view.rmq_data.events
if validation.valid?(rmq(view).data)
@valid << view
if has_events && view.rmq_data.events.has_event?(:valid)
view.rmq_data.events[:valid].fire!
end
else
@invalid << view
if has_events && view.rmq_data.events.has_event?(:invalid)
view.rmq_data.events[:invalid].fire!
end

View File

@@ -107,7 +107,7 @@ describe 'validation' do
@rmq.validation.valid?('test', :length, min_length: 8, max_length: 16).should == false
@rmq.validation.valid?('test', :length, exact_length: 2..7).should == true
@rmq.validation.valid?('test', :length, exact_length: 8..16).should == false
# ignore pre/post whitespace in length
# Next 2 lines testing ignore pre/post whitespace in length
@rmq.validation.valid?(' test ', :length, min_length: 5).should == true
@rmq.validation.valid?(' test ', :length, min_length: 5, strip: true).should == false
end
@@ -149,6 +149,10 @@ describe 'validation' do
end
it 'maintains what selected items are invalid' do
end
it 'can clear all validations' do
vc = UIViewController.new