aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_time_ext_test.rb
diff options
context:
space:
mode:
authorT.J. Schuck <tj@tjschuck.com>2017-11-28 17:49:54 -0500
committerT.J. Schuck <tj@tjschuck.com>2017-11-28 17:49:54 -0500
commit333ff24b8524094d55badb6c7f42f4b53832c0b6 (patch)
tree632cfb228f523cfea9b63140cee60c7455cbf8f4 /activesupport/test/core_ext/date_time_ext_test.rb
parent8633567169bb7b7bbab1ec8ddf6fe140d6db2e99 (diff)
downloadrails-333ff24b8524094d55badb6c7f42f4b53832c0b6.tar.gz
rails-333ff24b8524094d55badb6c7f42f4b53832c0b6.tar.bz2
rails-333ff24b8524094d55badb6c7f42f4b53832c0b6.zip
Refactor Date/Time next_occurring and prev_occurring
These methods were originally added in https://github.com/rails/rails/pull/26600 This includes a couple of refactors to make these methods behave more similarly to other Date/Time extensions added by Active Support: 1. Use `advance` instead of `since` and `ago` to time-travel — this is particularly important to keep the returned instance’s class matching `self`. Before this change: today = Date.today # => Tue, 28 Nov 2017 today.class # => Date today.next_occurring(:wednesday) # => Wed, 29 Nov 2017 00:00:00 UTC +00:00 today.next_occurring(:wednesday).class # => ActiveSupport::TimeWithZone After this change, a Date (or Time, or DateTime) instance is properly returned (just like is shown in the new docs). This is generally how everything else in DateAndTime::Calculations works. 2. Move the tests from the DateTime tests to the DateAndTimeBehavior tests. The latter location is mixed in to the core_ext tests for _all_ of Date, Time, and DateTime to test the behavior across all of the classes. The previous location is for testing core_ext functionality added specifically just to DateTime. 3. Better docs!
Diffstat (limited to 'activesupport/test/core_ext/date_time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb22
1 files changed, 0 insertions, 22 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index d942cddb2a..ed962803fa 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -30,28 +30,6 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_next_occur
- datetime = DateTime.new(2016, 9, 24, 0, 0) # saturday
- assert_equal datetime.next_occurring(:monday), datetime.since(2.days)
- assert_equal datetime.next_occurring(:tuesday), datetime.since(3.days)
- assert_equal datetime.next_occurring(:wednesday), datetime.since(4.days)
- assert_equal datetime.next_occurring(:thursday), datetime.since(5.days)
- assert_equal datetime.next_occurring(:friday), datetime.since(6.days)
- assert_equal datetime.next_occurring(:saturday), datetime.since(1.week)
- assert_equal datetime.next_occurring(:sunday), datetime.since(1.day)
- end
-
- def test_prev_occur
- datetime = DateTime.new(2016, 9, 24, 0, 0) # saturday
- assert_equal datetime.prev_occurring(:monday), datetime.ago(5.days)
- assert_equal datetime.prev_occurring(:tuesday), datetime.ago(4.days)
- assert_equal datetime.prev_occurring(:wednesday), datetime.ago(3.days)
- assert_equal datetime.prev_occurring(:thursday), datetime.ago(2.days)
- assert_equal datetime.prev_occurring(:friday), datetime.ago(1.day)
- assert_equal datetime.prev_occurring(:saturday), datetime.ago(1.week)
- assert_equal datetime.prev_occurring(:sunday), datetime.ago(6.days)
- end
-
def test_readable_inspect
datetime = DateTime.new(2005, 2, 21, 14, 30, 0)
assert_equal "Mon, 21 Feb 2005 14:30:00 +0000", datetime.readable_inspect