mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
added support for :discard_day in form helpers
This commit is contained in:
parent
7886132114
commit
b4c1a39343
@ -14,7 +14,31 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
TimelinessDateTime = Struct.new(:year, :month, :day, :hour, :min, :sec)
|
class TimelinessDateTime
|
||||||
|
|
||||||
|
attr_accessor :year, :month, :day, :hour, :min, :sec
|
||||||
|
|
||||||
|
def initialize(year, month, day, hour, min, sec)
|
||||||
|
@year = year
|
||||||
|
@month = month
|
||||||
|
@day = day
|
||||||
|
@hour = hour
|
||||||
|
@min = min
|
||||||
|
@sec = sec
|
||||||
|
end
|
||||||
|
|
||||||
|
# adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
|
||||||
|
def change(options)
|
||||||
|
TimelinessDateTime.new(
|
||||||
|
options[:year] || year,
|
||||||
|
options[:month] || month,
|
||||||
|
options[:day] || day,
|
||||||
|
options[:hour] || hour,
|
||||||
|
options[:min] || (options[:hour] ? 0 : min),
|
||||||
|
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def datetime_selector_with_timeliness(*args)
|
def datetime_selector_with_timeliness(*args)
|
||||||
@timeliness_date_or_time_tag = true
|
@timeliness_date_or_time_tag = true
|
||||||
|
|||||||
@ -101,6 +101,20 @@ describe ValidatesTimeliness::Extensions::DateTimeSelect do
|
|||||||
@output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
@output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
||||||
should_not_have_datetime_selected(:birth_time, :year, :month, :day)
|
should_not_have_datetime_selected(:birth_time, :year, :month, :day)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should support discarding of the day part" do
|
||||||
|
# this doesn't make sense for birthdays, but it does for credit card expirations, for example
|
||||||
|
@params["person"] = {
|
||||||
|
"birth_date(1i)" => 2009,
|
||||||
|
"birth_date(2i)" => 2,
|
||||||
|
}
|
||||||
|
person.birth_date = nil
|
||||||
|
@output = date_select(:person, :birth_date, :discard_day => true)
|
||||||
|
should_have_datetime_selected(:birth_date, :year => 2009, :month => 'February')
|
||||||
|
should_not_have_datetime_selected(:birth_date, :day)
|
||||||
|
@output.should have_tag("input[id=person_birth_date_3i][type=hidden][value='1']")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "time_select" do
|
describe "time_select" do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user