mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
initial Rails 3 rewrite commit
completely rewritten for ActiveModel compatibility uses ActiveModel EachValidator class as validator base class simplifies :between by splitting into a :on_or_before and an :on_of_after only :is_at option tested
This commit is contained in:
27
spec/model_helpers.rb
Normal file
27
spec/model_helpers.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
module ModelHelpers
|
||||
|
||||
# Some test helpers from Rails source
|
||||
def invalid!(attr_name, values, error = nil)
|
||||
with_each_person_value(attr_name, values) do |record, value|
|
||||
record.should be_invalid
|
||||
record.errors[attr_name].size.should >= 1
|
||||
record.errors[attr_name].first.should == error if error
|
||||
end
|
||||
end
|
||||
|
||||
def valid!(attr_name, values)
|
||||
with_each_person_value(attr_name, values) do |record, value|
|
||||
record.should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
def with_each_person_value(attr_name, values)
|
||||
record = Person.new
|
||||
values = [values] unless values.is_a?(Array)
|
||||
values.each do |value|
|
||||
record.send("#{attr_name}=", value)
|
||||
yield record, value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user