Sha256: 2cb402a37b82909ae11fb49f1f82a8fb0c5af80cb288a97b779f7559c69683e5
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
require 'spec_helper' describe ValidatesTimeliness::AttributeMethods do it 'should define _timeliness_raw_value_for instance method' do Person.instance_methods.should include('_timeliness_raw_value_for') end context "attribute write method" do class EmployeeWithCache < ActiveRecord::Base set_table_name 'employees' validates_datetime :birth_datetime end it 'should cache attribute raw value' do r = EmployeeWithCache.new r.birth_datetime = date_string = '2010-01-01' r._timeliness_raw_value_for(:birth_datetime).should == date_string end context "with plugin parser" do class EmployeeWithParser < ActiveRecord::Base set_table_name 'employees' validates_datetime :birth_date end before :all do ValidatesTimeliness.use_plugin_parser = true end it 'should parse a string value' do ValidatesTimeliness::Parser.should_receive(:parse) r = EmployeeWithParser.new r.birth_date = '2010-01-01' end it 'should be strict on day values' do r = EmployeeWithParser.new r.birth_date = '2010-02-31' r.birth_date.should be_nil end after :all do ValidatesTimeliness.use_plugin_parser = false end end end context "before_type_cast method" do it 'should be defined on class if ORM supports it' do Employee.instance_methods(false).should include("birth_datetime_before_type_cast") end it 'should not be defined if ORM does not support it' do Person.instance_methods(false).should_not include("birth_datetime_before_type_cast") end it 'should return original value' do r = Employee.new r.birth_datetime = date_string = '2010-01-01' r.birth_datetime_before_type_cast.should == date_string end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_timeliness-3.0.0.beta.2 | spec/validates_timeliness/attribute_methods_spec.rb |