2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
require "cases/helper"
|
|
|
|
require "models/topic"
|
2008-02-01 23:28:42 -05:00
|
|
|
|
2016-06-11 12:03:10 -04:00
|
|
|
class DateTest < ActiveRecord::TestCase
|
|
|
|
def test_date_with_time_value
|
|
|
|
time_value = Time.new(2016, 05, 11, 19, 0, 0)
|
|
|
|
topic = Topic.create(last_read: time_value)
|
|
|
|
assert_equal topic, Topic.find_by(last_read: time_value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_date_with_string_value
|
2016-08-06 12:26:20 -04:00
|
|
|
string_value = "2016-05-11 19:00:00"
|
2016-06-11 12:03:10 -04:00
|
|
|
topic = Topic.create(last_read: string_value)
|
|
|
|
assert_equal topic, Topic.find_by(last_read: string_value)
|
|
|
|
end
|
|
|
|
|
2008-02-01 23:28:42 -05:00
|
|
|
def test_assign_valid_dates
|
|
|
|
valid_dates = [[2007, 11, 30], [1993, 2, 28], [2008, 2, 29]]
|
|
|
|
|
|
|
|
invalid_dates = [[2007, 11, 31], [1993, 2, 29], [2007, 2, 29]]
|
|
|
|
|
|
|
|
valid_dates.each do |date_src|
|
|
|
|
topic = Topic.new("last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s)
|
Rails `DateTime` type is mapped to Oracle `TIMESTAMP` since Rails 5.0
Kind of reverting https://github.com/rails/rails/commit/3a1cbc5c3b3bcb2de4be6e4469bb87b99759dc59
```
From: test/cases/date_test.rb @ line 26 :
21:
22: invalid_dates = [[2007, 11, 31], [1993, 2, 29], [2007, 2, 29]]
23:
24: valid_dates.each do |date_src|
25: topic = Topic.new("last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s)
=> 26: binding.irb
27: assert_equal(topic.last_read, Date.new(*date_src))
28: end
29:
30: invalid_dates.each do |date_src|
31: assert_nothing_raised do
irb(#<DateTest:0x0000556618194668>):001:0> topic.last_read.class
=> Date
```
Refer rsim/oracle-enhanced#845
rails/rails#25897
2019-03-02 23:22:48 -05:00
|
|
|
assert_equal(topic.last_read, Date.new(*date_src))
|
2008-02-01 23:28:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
invalid_dates.each do |date_src|
|
|
|
|
assert_nothing_raised do
|
2016-08-06 13:44:11 -04:00
|
|
|
topic = Topic.new("last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s)
|
Rails `DateTime` type is mapped to Oracle `TIMESTAMP` since Rails 5.0
Kind of reverting https://github.com/rails/rails/commit/3a1cbc5c3b3bcb2de4be6e4469bb87b99759dc59
```
From: test/cases/date_test.rb @ line 26 :
21:
22: invalid_dates = [[2007, 11, 31], [1993, 2, 29], [2007, 2, 29]]
23:
24: valid_dates.each do |date_src|
25: topic = Topic.new("last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s)
=> 26: binding.irb
27: assert_equal(topic.last_read, Date.new(*date_src))
28: end
29:
30: invalid_dates.each do |date_src|
31: assert_nothing_raised do
irb(#<DateTest:0x0000556618194668>):001:0> topic.last_read.class
=> Date
```
Refer rsim/oracle-enhanced#845
rails/rails#25897
2019-03-02 23:22:48 -05:00
|
|
|
assert_equal(topic.last_read, Time.local(*date_src).to_date, "The date should be modified according to the behavior of the Time object")
|
2008-02-01 23:28:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|