Skip to content

Commit

Permalink
Test activesupport versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kla committed Jul 6, 2024
1 parent ead9b9f commit 0ff12a5
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 60 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["2.7", "3.0", "3.1", "3.2", "3.3"]
ruby-version: ["3.0", "3.1", "3.2", "3.3"]
activesupport-version: ["activesupport-6.1", "activesupport-7.1"]

steps:
- uses: actions/checkout@v4
Expand All @@ -18,9 +19,11 @@ jobs:
- uses: actions/cache@v4
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}-v1
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}-v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- run: bin/setup
- run: bin/test
- run: bundle exec appraisal generate
- run: bundle exec appraisal install
- run: bundle exec appraisal ${{ matrix.activesupport-version }} bin/test
15 changes: 4 additions & 11 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
appraise "ruby-2.7" do
appraise "activesupport-6.1" do
gem "activesupport", "~> 6.1.0"
end

appraise "ruby-3.0" do
end

appraise "ruby-3.1" do
end

appraise "ruby-3.2" do
end

appraise "ruby-3.3" do
appraise "activesupport-7.1" do
gem "activesupport", "~> 7.1.0"
end
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
source "https://rubygems.org"
gemspec

gem "activesupport", ">= 5.1"
1 change: 1 addition & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

echo "== Running tests =="
[ "${CI}" = "1" ] && bundle info activesupport
bundle exec rake test "$@"
86 changes: 43 additions & 43 deletions test/cases/time_slice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,61 @@ class TimeSliceTest < TestCase
it "accepts a period and :length option" do
range = TimeSlice.new("2h", length: "4")
assert_equal 4, range.length
assert_equal "2019-01-06 10:00:00", range.from.to_fs(:db)
assert_equal "2019-01-06 16:00:00", range.to.to_fs(:db)
assert_time_range "[2019-01-06 10:00:00, 2019-01-06 12:00:00]", range[0]
assert_time_range "[2019-01-06 12:00:00, 2019-01-06 14:00:00]", range[1]
assert_time_range "[2019-01-06 14:00:00, 2019-01-06 16:00:00]", range[2]
assert_time_range "[2019-01-06 16:00:00, 2019-01-06 18:00:00]", range[3]
assert_equal "2019-01-06T10:00:00Z", range.from.iso8601
assert_equal "2019-01-06T16:00:00Z", range.to.iso8601
assert_time_range "[2019-01-06T10:00:00Z, 2019-01-06T12:00:00Z]", range[0]
assert_time_range "[2019-01-06T12:00:00Z, 2019-01-06T14:00:00Z]", range[1]
assert_time_range "[2019-01-06T14:00:00Z, 2019-01-06T16:00:00Z]", range[2]
assert_time_range "[2019-01-06T16:00:00Z, 2019-01-06T18:00:00Z]", range[3]

range = TimeSlice.new("2h", length: 1)
assert_equal 1, range.length
assert_time_range "[2019-01-06 16:00:00, 2019-01-06 18:00:00]", range[0]
assert_time_range "[2019-01-06T16:00:00Z, 2019-01-06T18:00:00Z]", range[0]
end

it "is enumerable" do
assert range.each { true }
assert_time_range "[[2019-01-06 14:00:00, 2019-01-06 16:00:00], [2019-01-06 16:00:00, 2019-01-06 18:00:00]]", range
assert_time_range "[[2019-01-06T14:00:00Z, 2019-01-06T16:00:00Z], [2019-01-06T16:00:00Z, 2019-01-06T18:00:00Z]]", range
end

it "accepts a :from option" do
range = TimeSlice.new("5m", from: "2019-01-06 17:20")
assert_equal "2019-01-06 17:20:00", range.from.to_fs(:db)
assert_equal "2019-01-06 17:40:00", range.to.to_fs(:db)
assert_time_range "[2019-01-06 17:20:00, 2019-01-06 17:25:00]", range.first
assert_time_range "[2019-01-06 17:40:00, 2019-01-06 17:45:00]", range.last
assert_equal "2019-01-06T17:20:00Z", range.from.iso8601
assert_equal "2019-01-06T17:40:00Z", range.to.iso8601
assert_time_range "[2019-01-06T17:20:00Z, 2019-01-06T17:25:00Z]", range.first
assert_time_range "[2019-01-06T17:40:00Z, 2019-01-06T17:45:00Z]", range.last
assert_equal 5, range.length

range = TimeSlice.new("1m", from: "2019-01-06 17:20")
assert_equal "2019-01-06 17:20:00", range.from.to_fs(:db)
assert_equal "2019-01-06 17:44:00", range.to.to_fs(:db)
assert_time_range "[2019-01-06 17:20:00, 2019-01-06 17:21:00]", range.first
assert_time_range "[2019-01-06 17:44:00, 2019-01-06 17:45:00]", range.last
assert_equal "2019-01-06T17:20:00Z", range.from.iso8601
assert_equal "2019-01-06T17:44:00Z", range.to.iso8601
assert_time_range "[2019-01-06T17:20:00Z, 2019-01-06T17:21:00Z]", range.first
assert_time_range "[2019-01-06T17:44:00Z, 2019-01-06T17:45:00Z]", range.last
assert_equal 25, range.length
end

it "accepts a :from and :to option" do
range = TimeSlice.new("5m", from: "2019-01-06 17:10", to: "2019-01-06 17:35")
assert_equal "2019-01-06 17:10:00", range.from.to_fs(:db)
assert_equal "2019-01-06 17:35:00", range.to.to_fs(:db)
assert_time_range "[2019-01-06 17:10:00, 2019-01-06 17:15:00]", range.first
assert_time_range "[2019-01-06 17:35:00, 2019-01-06 17:40:00]", range.last
assert_equal "2019-01-06T17:10:00Z", range.from.iso8601
assert_equal "2019-01-06T17:35:00Z", range.to.iso8601
assert_time_range "[2019-01-06T17:10:00Z, 2019-01-06T17:15:00Z]", range.first
assert_time_range "[2019-01-06T17:35:00Z, 2019-01-06T17:40:00Z]", range.last
assert_equal 6, range.length

range = TimeSlice.new("5m", from: "2019-01-06 17:10:00", to: "2019-01-06 17:10:05")
assert_equal "2019-01-06 17:10:00", range.from.to_fs(:db)
assert_equal "2019-01-06 17:10:00", range.to.to_fs(:db)
assert_time_range "[2019-01-06 17:10:00, 2019-01-06 17:15:00]", range.first
assert_time_range "[2019-01-06 17:10:00, 2019-01-06 17:15:00]", range.last
assert_equal "2019-01-06T17:10:00Z", range.from.iso8601
assert_equal "2019-01-06T17:10:00Z", range.to.iso8601
assert_time_range "[2019-01-06T17:10:00Z, 2019-01-06T17:15:00Z]", range.first
assert_time_range "[2019-01-06T17:10:00Z, 2019-01-06T17:15:00Z]", range.last
assert_equal 1, range.length
end

it "accepts a :from and :length option" do
range = TimeSlice.new("5m", from: "2019-01-06 17:10", length: 3)
assert_equal "2019-01-06 17:10:00", range.from.to_fs(:db)
assert_equal "2019-01-06 17:20:00", range.to.to_fs(:db)
assert_time_range "[2019-01-06 17:10:00, 2019-01-06 17:15:00]", range.first
assert_time_range "[2019-01-06 17:20:00, 2019-01-06 17:25:00]", range.last
assert_equal "2019-01-06T17:10:00Z", range.from.iso8601
assert_equal "2019-01-06T17:20:00Z", range.to.iso8601
assert_time_range "[2019-01-06T17:10:00Z, 2019-01-06T17:15:00Z]", range.first
assert_time_range "[2019-01-06T17:20:00Z, 2019-01-06T17:25:00Z]", range.last
assert_equal 3, range.length
end

Expand All @@ -90,11 +90,11 @@ class TimeSliceTest < TestCase
it "gets previous times" do
range = TimeSlice.new("5m", from: "2019-01-06 17:00", to: "2019-01-06 17:35")
prev = range.previous("2019-01-06 17:20:00", 3)
assert_equal "2019-01-06 17:05:00", prev.from.to_fs(:db)
assert_equal "2019-01-06 17:15:00", prev.to.to_fs(:db)
assert_time_range "[2019-01-06 17:05:00, 2019-01-06 17:10:00]", prev[0]
assert_time_range "[2019-01-06 17:10:00, 2019-01-06 17:15:00]", prev[1]
assert_time_range "[2019-01-06 17:15:00, 2019-01-06 17:20:00]", prev[2]
assert_equal "2019-01-06T17:05:00Z", prev.from.iso8601
assert_equal "2019-01-06T17:15:00Z", prev.to.iso8601
assert_time_range "[2019-01-06T17:05:00Z, 2019-01-06T17:10:00Z]", prev[0]
assert_time_range "[2019-01-06T17:10:00Z, 2019-01-06T17:15:00Z]", prev[1]
assert_time_range "[2019-01-06T17:15:00Z, 2019-01-06T17:20:00Z]", prev[2]
assert_equal 3, prev.length
end

Expand All @@ -106,20 +106,20 @@ class TimeSliceTest < TestCase
it "correctly handles different time periods" do
range = TimeSlice.new("15m", from: "2019-01-06 12:00", to: "2019-01-06 13:00")
assert_equal 5, range.length
assert_time_range "[2019-01-06 12:00:00, 2019-01-06 12:15:00]", range.first
assert_time_range "[2019-01-06 13:00:00, 2019-01-06 13:15:00]", range.last
assert_time_range "[2019-01-06T12:00:00Z, 2019-01-06T12:15:00Z]", range.first
assert_time_range "[2019-01-06T13:00:00Z, 2019-01-06T13:15:00Z]", range.last

range = TimeSlice.new("1d", from: "2019-01-01", to: "2019-01-05")
assert_equal 5, range.length
assert_time_range "[2019-01-01 00:00:00, 2019-01-02 00:00:00]", range.first
assert_time_range "[2019-01-05 00:00:00, 2019-01-06 00:00:00]", range.last
assert_time_range "[2019-01-01T00:00:00Z, 2019-01-02T00:00:00Z]", range.first
assert_time_range "[2019-01-05T00:00:00Z, 2019-01-06T00:00:00Z]", range.last
end

it "handles empty ranges" do
range = TimeSlice.new("1h", from: "2019-01-06 12:00", to: "2019-01-06 12:00")
assert_equal 1, range.length
assert_time_range "[2019-01-06 12:00:00, 2019-01-06 13:00:00]", range.first
assert_time_range "[2019-01-06 12:00:00, 2019-01-06 13:00:00]", range.last
assert_time_range "[2019-01-06T12:00:00Z, 2019-01-06T13:00:00Z]", range.first
assert_time_range "[2019-01-06T12:00:00Z, 2019-01-06T13:00:00Z]", range.last
end

it "correctly implements the Enumerable interface" do
Expand Down Expand Up @@ -153,11 +153,11 @@ class TimeSliceTest < TestCase
it "correctly handles previous method with edge cases" do
range = TimeSlice.new("1h", from: "2019-01-06 12:00", to: "2019-01-06 15:00")
prev = range.previous("2019-01-06 13:00", 2)
assert_time_range "[2019-01-06 11:00:00, 2019-01-06 12:00:00]", prev.first
assert_time_range "[2019-01-06 12:00:00, 2019-01-06 13:00:00]", prev.last
assert_time_range "[2019-01-06T11:00:00Z, 2019-01-06T12:00:00Z]", prev.first
assert_time_range "[2019-01-06T12:00:00Z, 2019-01-06T13:00:00Z]", prev.last

prev = range.previous("2019-01-06 12:00", 2)
assert_time_range "[2019-01-06 10:00:00, 2019-01-06 11:00:00]", prev.first
assert_time_range "[2019-01-06 11:00:00, 2019-01-06 12:00:00]", prev.last
assert_time_range "[2019-01-06T10:00:00Z, 2019-01-06T11:00:00Z]", prev.first
assert_time_range "[2019-01-06T11:00:00Z, 2019-01-06T12:00:00Z]", prev.last
end
end
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "minitest/autorun"
require "minitest/focus"
require "mocha/minitest"
require_relative "../lib/time_slice"

Expand All @@ -13,7 +14,7 @@ def time_array_to_s(times)
end

times = times
.map { |times| times.map { |t| t.to_fs(:db) } }
.map { |times| times.map { |t| t.iso8601 } }
.map { |times| "[#{times.join(", ")}]" }
.join(", ")

Expand Down
5 changes: 3 additions & 2 deletions time_slice.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.7.0"
spec.required_ruby_version = ">= 3.0"

spec.add_dependency("activesupport", "> 5.1")
spec.add_dependency("activesupport", ">= 5.1")
spec.add_dependency("rounding", "> 1.0")

spec.add_development_dependency("appraisal", "~> 2.5.0")
spec.add_development_dependency("minitest", "~> 5.24.1")
spec.add_development_dependency("minitest-focus", "~> 1.4")
spec.add_development_dependency("mocha", "~> 2.4.0")
spec.add_development_dependency("rake", "~> 13.2.1")
end

0 comments on commit 0ff12a5

Please sign in to comment.