mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
changed method to check type and compose string for specific type to properly validate
refactored specs
This commit is contained in:
@@ -1,37 +1,47 @@
|
||||
require File.dirname(__FILE__) + '/spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::MultiparameterAttributes do
|
||||
include ValidatesTimeliness::MultiparameterAttributes
|
||||
def obj
|
||||
@obj ||= Person.new
|
||||
end
|
||||
|
||||
class AttributeAssignmentError; def initialize(*args); end; end
|
||||
class MultiparameterAssignmentErrors; def initialize(*args); end; end
|
||||
|
||||
before do
|
||||
self.class.stub!(:reflect_on_aggregation).and_return(nil)
|
||||
end
|
||||
|
||||
it "should convert time array into string" do
|
||||
time_string = time_array_to_string([2000,2,1,9,10,11])
|
||||
it "should convert array for datetime type into datetime string" do
|
||||
time_string = obj.time_array_to_string([2000,2,1,9,10,11], :datetime)
|
||||
time_string.should == "2000-02-01 09:10:11"
|
||||
end
|
||||
|
||||
describe "execute_callstack_for_multiparameter_attributes" do
|
||||
before do
|
||||
@date_array = [2000,2,1,9,10,11]
|
||||
end
|
||||
it "should convert array for date type into date string" do
|
||||
time_string = obj.time_array_to_string([2000,2,1,0,0,0], :date)
|
||||
time_string.should == "2000-02-01"
|
||||
end
|
||||
|
||||
it "should store time string for a Time class column" do
|
||||
self.stub!(:column_for_attribute).and_return( mock('Column', :klass => Time) )
|
||||
self.should_receive(:birth_date_and_time=).once.with("2000-02-01 09:10:11")
|
||||
callstack = {'birth_date_and_time' => @date_array}
|
||||
execute_callstack_for_multiparameter_attributes(callstack)
|
||||
it "should convert array for time type into time string" do
|
||||
time_string = obj.time_array_to_string([2000,1,1,9,10,11], :time)
|
||||
time_string.should == "09:10:11"
|
||||
end
|
||||
|
||||
describe "execute_callstack_for_multiparameter_attributes" do
|
||||
before do
|
||||
@callstack = {
|
||||
'birth_date_and_time' => [2000,2,1,9,10,11],
|
||||
'birth_date' => [2000,2,1,9,10,11],
|
||||
'birth_time' => [2000,2,1,9,10,11]
|
||||
}
|
||||
end
|
||||
|
||||
it "should store datetime string for datetime column" do
|
||||
obj.should_receive(:birth_date_and_time=).once.with("2000-02-01 09:10:11")
|
||||
obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
|
||||
end
|
||||
|
||||
it "should store time string for a Date class column" do
|
||||
self.stub!(:column_for_attribute).and_return( mock('Column', :klass => Date) )
|
||||
self.should_receive(:birth_date=).once.with("2000-02-01 09:10:11")
|
||||
callstack = {'birth_date' => @date_array}
|
||||
execute_callstack_for_multiparameter_attributes(callstack)
|
||||
it "should store date string for a date column" do
|
||||
obj.should_receive(:birth_date=).once.with("2000-02-01")
|
||||
obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
|
||||
end
|
||||
|
||||
it "should store time string for a time column" do
|
||||
obj.should_receive(:birth_time=).once.with("09:10:11")
|
||||
obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user