Sha256: 6c374b85dd9ca000e597f17949f3cefc9e90abbdb21fc1f84734d5707d70e772
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
# encoding: UTF-8 require File.expand_path("./helper", File.dirname(__FILE__)) class Post < Ohm::Model include Ohm::Typecast attribute :created_on, Date def today ::Date.today end def date Date end def may_5 Date.new(2010, 05, 05) end def base_today Date.today end end test "still able to get top level methods" do assert Date.today == Post.new.base_today end test "allows instantiation of dates" do assert Date.new(2010, 05, 05) == Post.new.may_5 end test "handles nil case correctly" do post = Post.create(:created_on => nil) post = Post[post.id] assert nil == post.created_on end test "handles empty string case correctly" do post = Post.create(:created_on => "") post = Post[post.id] assert "" == post.created_on.to_s end test "allows for real time operations" do post = Post.create(:created_on => "2010-05-10") post = Post[post.id] assert post.created_on.respond_to?(:strftime) assert "2010-05-10" == post.created_on.strftime('%Y-%m-%d') end test "raises when trying to do date operations on a non-date" do post = Post.create(:created_on => "FooBar") post = Post[post.id] assert_raise ArgumentError do post.created_on.strftime("%Y") end end test "still able to access Date" do assert Date.today == Post.new.today end test "inspecting" do post = Post.create(:created_on => Date.new(2010, 5, 5)) assert '"2010-05-05"' == post.created_on.inspect post.created_on = 'FooBar' assert '"FooBar"' == post.created_on.inspect end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ohm-contrib-0.0.34 | test/typecast_date_test.rb |
ohm-contrib-0.0.33 | test/typecast_date_test.rb |