Skip to content

Commit 964895e

Browse files
mhgbrownMorgan Brown
andauthored
Add Official Ruby 3 Compatibility; Establish Testing Procedure for Multiple Rubies (#55)
* Add Ruby 3 stanzas * Get started with github actions * Add a ruby workflow * Update ruby uses * Remove github actions demo * Remove not yet supported ruby 3.2 * Fix supported setup ruby * Update README * Try 1.8.7 * Try 1.9 (1.8 is unsupported by actions) * Add 1.9 to compat * Try setting multiple rails versions * Exclude combination that caused segmentation fault * Exclude incompatbility with 1.9 * Puts rails version * Try extensions... * Try to override version in Gemfile directly * Thrash with a spec he;per * Log ENV['TEST_RAILS_VERSION'] * Beef up the log * Set rails version during bundle install * Add matrix exclude from compat errors * Fix BigDecimal error * Remove seg fault steps * Come on big decimal * Remove dup require in spec helper * Maybe fix bigdecimal? * Back down to BigDecimal 1.3.5 * Giveup on BigDecimal * Add one more bigdecimal incompat * cleanup * Remove matrix entries for Ruby 3 Argument error * Add more incompatiblity exclusions for BigDecimal.new * Update compatibility section of Readme * Use github actions badge instead * Fix typo * Edit TEST_RAILS_VERSION messages * Revert to use add_runtime_dependency for gemspec * Remove unused travis.yml * Install rails instead of acive support * Remove appraisal gem * Revert to activesupport / active resource * Try installing old bundler * Remove all bundler's first * Use rails instead of acivesupport and stuff * Try requiring a gemfile insside a gemfile * Try another way to require * Try some crazy gemfile evaling * Use __FILE__ for Ruby 1.9 * Fix name of gemfile * Fix path of 4.2 gemfile * Try to see if it's loading * Load all rails via gemfiles * Add ruby 2.6 * Update README for ruby 2.6 * Remove appraisal * only puts with env debug * only add env variable when needed * Remove require of bigdecimal * Update README with new test instructions * Specify required ruby version * Update email * Update version number to 7.0.0 --------- Co-authored-by: Morgan Brown <brown.mhg+git@gmail.com>
1 parent 0576e0b commit 964895e

21 files changed

+189
-1106
lines changed

.github/workflows/ruby.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7+
8+
name: Test
9+
10+
on: [push]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
test:
17+
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
ruby-version: ['1.9', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
23+
rails-version: ['4.2', '5.0', '5.1', '6.0', '6.1', '7.0']
24+
exclude:
25+
# Segmentation faults during tests, but should work?
26+
- ruby-version: '2.2'
27+
rails-version: '5.0'
28+
- ruby-version: '2.2'
29+
rails-version: '5.1'
30+
# Too old
31+
- ruby-version: '1.9'
32+
rails-version: '5.0'
33+
- ruby-version: '1.9'
34+
rails-version: '5.1'
35+
- ruby-version: '1.9'
36+
rails-version: '6.0'
37+
- ruby-version: '1.9'
38+
rails-version: '6.1'
39+
- ruby-version: '1.9'
40+
rails-version: '7.0'
41+
# activesupport (~> 6.0.0) was resolved to 6.0.6.1, which depends on ruby (>= 2.5.0)
42+
# activesupport (~> 6.1.0) was resolved to 6.1.7.2, which depends on ruby (>= 2.5.0)
43+
- ruby-version: '2.2'
44+
rails-version: '6.0'
45+
- ruby-version: '2.2'
46+
rails-version: '6.1'
47+
- ruby-version: '2.3'
48+
rails-version: '6.0'
49+
- ruby-version: '2.3'
50+
rails-version: '6.1'
51+
- ruby-version: '2.4'
52+
rails-version: '6.0'
53+
- ruby-version: '2.4'
54+
rails-version: '6.1'
55+
# activesupport (~> 7.0.0) was resolved to 7.0.4.2, which depends on Ruby (>= 2.7.0)
56+
- ruby-version: '2.2'
57+
rails-version: '7.0'
58+
- ruby-version: '2.3'
59+
rails-version: '7.0'
60+
- ruby-version: '2.4'
61+
rails-version: '7.0'
62+
- ruby-version: '2.5'
63+
rails-version: '7.0'
64+
- ruby-version: '2.6'
65+
rails-version: '7.0'
66+
# incompatbility with BigDecimal.new
67+
- ruby-version: '2.7'
68+
rails-version: '4.2'
69+
- ruby-version: '3.0'
70+
rails-version: '4.2'
71+
- ruby-version: '3.1'
72+
rails-version: '4.2'
73+
- ruby-version: '3.2'
74+
rails-version: '4.2'
75+
# ArgumentError: expected attributes to be able to convert to Hash, got "#<Thing:0x000055d208b2e258>"
76+
# probably keyword argument delegation different in Ruby 3
77+
# https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
78+
- ruby-version: '3.0'
79+
rails-version: '5.0'
80+
- ruby-version: '3.0'
81+
rails-version: '5.1'
82+
- ruby-version: '3.1'
83+
rails-version: '5.0'
84+
- ruby-version: '3.1'
85+
rails-version: '5.1'
86+
- ruby-version: '3.2'
87+
rails-version: '5.0'
88+
- ruby-version: '3.2'
89+
rails-version: '5.1'
90+
91+
steps:
92+
- uses: actions/checkout@v3
93+
- name: Set up Ruby ${{ matrix.ruby-version }}
94+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
95+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
96+
# uses: ruby/setup-ruby@v1
97+
uses: ruby/setup-ruby@v1
98+
with:
99+
ruby-version: ${{ matrix.ruby-version }}
100+
- name: Install bundler 1.x.x
101+
if: matrix.rails-version == '4.2'
102+
run: gem uninstall -aIx bundler && gem install bundler -v 1.17.3
103+
- name: Install dependencies
104+
run: bundle install
105+
env:
106+
TEST_RAILS_VERSION: ${{ matrix.rails-version }}
107+
DEBUG: true
108+
- name: Run tests
109+
run: bundle exec rake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Gemfile.lock
44
pkg/*
55
*DS_Store
66
.ruby-version
7+
.tool-versions

.travis.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

Appraisals

Lines changed: 0 additions & 28 deletions
This file was deleted.

Gemfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
source "http://rubygems.org"
22

33
gemspec
4+
5+
def eval_gemfile(path)
6+
gemfile_local = File.expand_path(path, __FILE__)
7+
if File.readable?(gemfile_local)
8+
puts "Loading #{gemfile_local}..." if ENV['DEBUG']
9+
instance_eval(File.read(gemfile_local))
10+
end
11+
end
12+
13+
puts "\e[93mUsing TEST_RAILS_VERSION #{ENV['TEST_RAILS_VERSION']}\e[0m" if ENV['DEBUG']
14+
case ENV['TEST_RAILS_VERSION']
15+
when "4.2"
16+
eval_gemfile('../gemfiles/4.2.gemfile')
17+
when "5.0"
18+
eval_gemfile('../gemfiles/5.0.gemfile')
19+
when "5.1"
20+
eval_gemfile('../gemfiles/5.1.gemfile')
21+
when "6.0"
22+
eval_gemfile('../gemfiles/6.0.gemfile')
23+
when "6.1"
24+
eval_gemfile('../gemfiles/6.1.gemfile')
25+
when "7.0"
26+
eval_gemfile('../gemfiles/7.0.gemfile')
27+
else
28+
puts "\e[93mNo TEST_RAILS_VERSION present, letting dependency manager decide what's best.\e[0m" if ENV['DEBUG']
29+
end

README.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# CachedResource [![Build Status](https://app.travis-ci.com/mhgbrown/cached_resource.svg?branch=master)](https://app.travis-ci.com/github/mhgbrown/cached_resource)
1+
# CachedResource ![Tests](https://github.com/mhgbrown/cached_resource/actions/workflows/ruby.yml/badge.svg)
2+
23
CachedResource is a Ruby gem whose goal is to increase the performance of interacting with web services via ActiveResource by caching responses based on request parameters. It can help reduce the lag created by making repeated requests across a network.
34

45
## Installation
@@ -8,28 +9,25 @@ gem install cached_resource
89
```
910

1011
## Compatibility
11-
CachedResource supports the following Ruby versions:
12-
13-
* 2.2.x
14-
* 2.3.x
15-
* 2.4.x
16-
* 2.5.x
17-
* 2.7.x
18-
19-
...and likely other modern Ruby versions. If you require 1.8.7 support, please use version 2.3.4.
2012

21-
CachedResource is designed to be framework agnostic, but will hook into Rails for caching and logging if available. The latest CachedResource officially supports the following Rails versions:
13+
CachedResource is designed to be framework agnostic, but will hook into Rails for caching and logging if available. CachedResource supports the following ActiveSupport/Rails (right) and Ruby (down) version combinations:
2214

23-
* 4.2.x
24-
* 5.0.x
25-
* 5.1.x
26-
* 6.0.x
27-
* 6.1.x
28-
* 7.0.x
15+
| | 🛤️ 4.2 | 🛤️ 5.0 | 🛤️ 5.1 | 🛤️ 6.0 | 🛤️ 6.1 | 🛤️ 7.0 |
16+
|-------|-----|-----|-----|-----|-----|-----|
17+
| 💎 1.9 || | | | | |
18+
| 💎 2.2 || | | | | |
19+
| 💎 2.3 |||| | | |
20+
| 💎 2.4 |||| | | |
21+
| 💎 2.5 |||||| |
22+
| 💎 2.6 |||||| |
23+
| 💎 2.7 | ||||||
24+
| 💎 3.0 | | | ||||
25+
| 💎 3.1 | | | ||||
26+
| 💎 3.2 | | | ||||
2927

30-
For previously supported versions, use 4.2.0 or below.
3128

3229
## Configuration
30+
3331
**Set up CachedResource across all ActiveResources:**
3432

3533
```ruby
@@ -154,25 +152,46 @@ Since resources are cached with an argument based key, you may pass in extra dat
154152
```ruby
155153
MyActiveResource.find(:one, from: "/admin/shop.json", uid: "unique value")
156154
```
155+
157156
## Testing
158157

159-
```ruby
160-
rake
158+
To test the Ruby + Rails combination configured by default:
159+
160+
```bash
161+
$ rake
161162
```
162163

163-
or to test all supported environments, make sure appraisal is setup
164+
or to test all supported environments...you have to do a little more work...
164165

165-
```ruby
166-
bundle exec appraisal install
166+
Switch your Ruby version to the desired version. This project's maintainer uses `asdf`, so switching to Ruby 3 looks like this:
167+
168+
```bash
169+
$ asdf local ruby 3.0.5
167170
```
168171

169-
and then run
172+
If you have a `Gemfile.lock`, delete it:
170173

171-
```ruby
172-
bundle exec appraisal rake
174+
```bash
175+
$ rm Gemfile.lock
173176
```
174177

175-
For more details, head over to the [appraisal](https://github.com/thoughtbot/appraisal) documentation.
178+
Then reinstall your dependencies:
179+
180+
```bash
181+
$ bundle install
182+
```
183+
184+
and finally, run the tests:
185+
186+
```bash
187+
$ rake
188+
```
189+
190+
If you want to test with a specific Rails version, start over and install dependencies with `TEST_RAILS_VERSION` set:
191+
192+
```bash
193+
$ TEST_RAILS_VERSION=6.1 bundle install
194+
```
176195

177196
## Credit/Inspiration
178197
* quamen and [this gist](http://gist.github.com/947734)

cached_resource.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
66
s.name = "cached_resource"
77
s.version = CachedResource::VERSION
88
s.authors = "Morgan Brown"
9-
s.email = "brown.mhg@gmail.com"
9+
s.email = "cached_resource@email.mhgbrown.is"
1010
s.homepage = "https://github.com/mhgbrown/cached_resource"
1111
s.summary = %q{Caching for ActiveResource}
1212
s.description = %q{Enables request-based caching for ActiveResource}
@@ -17,11 +17,12 @@ Gem::Specification.new do |s|
1717
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
1818
s.require_paths = ["lib"]
1919

20+
s.required_ruby_version = '>= 1.9.0'
21+
2022
s.add_runtime_dependency "activeresource", ">= 4.0"
2123
s.add_runtime_dependency "activesupport", ">= 4.0"
2224
s.add_runtime_dependency "nilio", ">= 1.0"
2325

2426
s.add_development_dependency "rake"
2527
s.add_development_dependency "rspec"
26-
s.add_development_dependency "appraisal"
2728
end

gemfiles/4.2.gemfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# This file was generated by Appraisal
2-
31
source "http://rubygems.org"
42

53
gem "rails", "~> 4.2.0"
6-
gem "bigdecimal", "1.3.5"
74

8-
gemspec path: "../"
5+
# https://stackoverflow.com/questions/60226893/rails-nomethoderror-undefined-method-new-for-bigdecimalclass
6+
# gem "bigdecimal", "1.3.5"

0 commit comments

Comments
 (0)