fixed instance_tag value method when attribute value is nil and improved specs

This commit is contained in:
Adam Meehan 2008-08-14 11:44:18 +10:00
parent 22ade45114
commit d61249d6f5
2 changed files with 19 additions and 4 deletions

View File

@ -23,7 +23,7 @@ module ValidatesTimeliness
raw_value = value_before_type_cast(object)
if raw_value.acts_like?(:time) || raw_value.is_a?(Date)
if raw_value.nil? || raw_value.acts_like?(:time) || raw_value.is_a?(Date)
return value_without_timeliness(object)
end

View File

@ -6,9 +6,9 @@ describe ValidatesTimeliness::InstanceTag, :type => :helper do
@person = Person.new
end
it "should display invalid date as date_select values" do
@person.birth_date_and_time = "2008-02-30 12:00:00"
output = date_select(:person, :birth_date_and_time, :include_blank => true)
it "should display invalid datetime as datetime_select values" do
@person.birth_date_and_time = "2008-02-30 12:00:22"
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
output.should have_tag('select[id=person_birth_date_and_time_1i]') do
with_tag('option[selected=selected]', '2008')
@ -19,5 +19,20 @@ describe ValidatesTimeliness::InstanceTag, :type => :helper do
output.should have_tag('select[id=person_birth_date_and_time_3i]') do
with_tag('option[selected=selected]', '30')
end
output.should have_tag('select[id=person_birth_date_and_time_4i]') do
with_tag('option[selected=selected]', '12')
end
output.should have_tag('select[id=person_birth_date_and_time_5i]') do
with_tag('option[selected=selected]', '00')
end
output.should have_tag('select[id=person_birth_date_and_time_6i]') do
with_tag('option[selected=selected]', '22')
end
end
it "should display datetime_select when datetime value is nil" do
@person.birth_date_and_time = nil
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
output.should have_tag('select', 6)
end
end