Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-68] Improved Specs and Added Coverage Report #70

Merged
merged 17 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 29 additions & 79 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,49 @@
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Test

on: [push]

name: Code Guard
on:
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
permissions:
contents: read

checks: write
contents: write
jobs:
test:

runs-on: ubuntu-20.04

strategy:
matrix:
ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
rails-version: ['4.2', '5.0', '5.1', '6.0', '6.1', '7.0', '7.1']
exclude:
# activesupport (~> 6.0.0) was resolved to 6.0.6.1, which depends on ruby (>= 2.5.0)
# activesupport (~> 6.1.0) was resolved to 6.1.7.2, which depends on ruby (>= 2.5.0)
- ruby-version: '2.3'
rails-version: '6.0'
- ruby-version: '2.3'
rails-version: '6.1'
- ruby-version: '2.4'
rails-version: '6.0'
- ruby-version: '2.4'
rails-version: '6.1'
# activesupport (~> 7.0.0) was resolved to 7.0.4.2, which depends on Ruby (>= 2.7.0)
- ruby-version: '2.3'
rails-version: '7.0'
- ruby-version: '2.4'
rails-version: '7.0'
- ruby-version: '2.5'
rails-version: '7.0'
- ruby-version: '2.6'
rails-version: '7.0'
# incompatbility with BigDecimal.new
- ruby-version: '2.7'
rails-version: '4.2'
- ruby-version: '3.0'
rails-version: '4.2'
- ruby-version: '3.1'
rails-version: '4.2'
- ruby-version: '3.2'
rails-version: '4.2'
# ArgumentError: expected attributes to be able to convert to Hash, got "#<Thing:0x000055d208b2e258>"
# probably keyword argument delegation different in Ruby 3
# https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
- ruby-version: '3.0'
rails-version: '5.0'
- ruby-version: '3.0'
rails-version: '5.1'
- ruby-version: '3.1'
rails-version: '5.0'
- ruby-version: '3.1'
rails-version: '5.1'
- ruby-version: '3.2'
rails-version: '5.0'
- ruby-version: '3.2'
rails-version: '5.1'
# rails (~> 7.1.0) was resolved to 7.1.3.2, which depends on Ruby (>= 2.7.0)
- ruby-version: '2.3'
rails-version: '7.1'
- ruby-version: '2.4'
rails-version: '7.1'
- ruby-version: '2.5'
rails-version: '7.1'
- ruby-version: '2.6'
rails-version: '7.1'
# Because rails >= 4.0.0.beta1, < 5.0.5.rc1 depends on bundler >= 1.3.0, < 2.0
# and the current Bundler version (2.5.9) does not satisfy bundler >= 1.3.0, < 2.0,
# rails >= 4.0.0.beta1, < 5.0.5.rc1 cannot be used.
# So, because Gemfile depends on rails ~> 4.2.0,
# version solving has failed.
- ruby-version: '3.3'
rails-version: '4.2'

rails-version: ['6.1', '7.1']
jlurena marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby-version }}
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install bundler 1.x.x
if: matrix.rails-version == '4.2'
run: gem uninstall -aIx bundler && gem install bundler -v 1.17.3
ruby-version: '3.0'
jlurena marked this conversation as resolved.
Show resolved Hide resolved
- name: Install dependencies
run: bundle install
env:
TEST_RAILS_VERSION: ${{ matrix.rails-version }}
DEBUG: true
- name: Run tests
run: bundle exec rake
# Doesn't work. Needs secret or repo setting update
# - name: Code Coverage
# if: matrix.rails-version == '7.1'
# uses: joshmfrankel/[email protected]
# with:
# check_job_name: Code Coverage
# minimum_suite_coverage: 100
# github_token: ${{ secrets.GITHUB_TOKEN }}
# Doesn't work. Needs secret or repo setting update?
# lint:
# needs: [test]
# runs-on: ubuntu-20.04
# steps:
# - name: Lint
# uses: standardrb/standard-ruby-action@v1
# with:
# ruby-version: '3.0'
jlurena marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pkg/*
*DS_Store
.ruby-version
.tool-versions
coverage
3 changes: 3 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fix: true
parallel: true
ruby_version: 3.0
22 changes: 11 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ gemspec
def eval_gemfile(path)
gemfile_local = File.expand_path(path, __FILE__)
if File.readable?(gemfile_local)
puts "Loading #{gemfile_local}..." if ENV['DEBUG']
puts "Loading #{gemfile_local}..." if ENV["DEBUG"]
instance_eval(File.read(gemfile_local))
end
end

puts "\e[93mUsing TEST_RAILS_VERSION #{ENV['TEST_RAILS_VERSION']}\e[0m" if ENV['DEBUG']
case ENV['TEST_RAILS_VERSION']
puts "\e[93mUsing TEST_RAILS_VERSION #{ENV["TEST_RAILS_VERSION"]}\e[0m" if ENV["DEBUG"]
case ENV["TEST_RAILS_VERSION"]
when "4.2"
eval_gemfile('../gemfiles/4.2.gemfile')
eval_gemfile("../gemfiles/4.2.gemfile")
when "5.0"
eval_gemfile('../gemfiles/5.0.gemfile')
eval_gemfile("../gemfiles/5.0.gemfile")
when "5.1"
eval_gemfile('../gemfiles/5.1.gemfile')
eval_gemfile("../gemfiles/5.1.gemfile")
when "6.0"
eval_gemfile('../gemfiles/6.0.gemfile')
eval_gemfile("../gemfiles/6.0.gemfile")
when "6.1"
eval_gemfile('../gemfiles/6.1.gemfile')
eval_gemfile("../gemfiles/6.1.gemfile")
when "7.0"
eval_gemfile('../gemfiles/7.0.gemfile')
eval_gemfile("../gemfiles/7.0.gemfile")
when "7.1"
eval_gemfile('../gemfiles/7.1.gemfile')
eval_gemfile("../gemfiles/7.1.gemfile")
else
puts "\e[93mNo TEST_RAILS_VERSION present, letting dependency manager decide what's best.\e[0m" if ENV['DEBUG']
puts "\e[93mNo TEST_RAILS_VERSION present, letting dependency manager decide what's best.\e[0m" if ENV["DEBUG"]
end
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require "rspec/core/rake_task"
require "standard/rake"

desc "Run all examples"
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: [:spec, :standard]
30 changes: 16 additions & 14 deletions cached_resource.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "cached_resource/version"

Gem::Specification.new do |s|
s.name = "cached_resource"
s.version = CachedResource::VERSION
s.authors = "Morgan Brown"
s.email = "[email protected]"
s.homepage = "https://github.com/mhgbrown/cached_resource"
s.summary = %q{Caching for ActiveResource}
s.description = %q{Enables request-based caching for ActiveResource}
s.licenses = ['MIT']
s.name = "cached_resource"
s.version = CachedResource::VERSION
s.authors = "Morgan Brown"
s.email = "[email protected]"
s.homepage = "https://github.com/mhgbrown/cached_resource"
s.summary = "Caching for ActiveResource"
s.description = "Enables request-based caching for ActiveResource"
s.licenses = ["MIT"]

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ["lib"]

s.required_ruby_version = '>= 1.9.0'
s.required_ruby_version = ">= 3.0"

s.add_runtime_dependency "activeresource", ">= 4.0"
s.add_runtime_dependency "activesupport", ">= 4.0"
s.add_runtime_dependency "nilio", ">= 1.0"

s.add_development_dependency "concurrent-ruby", "~> 1.2", ">= 1.2.3"
s.add_development_dependency "pry-byebug"
s.add_development_dependency "rake"
s.add_development_dependency "rspec"
s.add_development_dependency "concurrent-ruby", '~> 1.2', '>= 1.2.3'
s.add_development_dependency "simplecov", "~> 0.22.0"
s.add_development_dependency "timecop", "~> 0.9.10"
s.add_development_dependency "standard", "~> 1.39", ">= 1.39.1"
end
20 changes: 10 additions & 10 deletions lib/cached_resource.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'ostruct'
require "ostruct"

require 'nilio'
require 'active_support/cache'
require 'active_support/concern'
require 'active_support/logger'
require 'cached_resource/cached_resource'
require 'cached_resource/configuration'
require 'cached_resource/caching'
require 'cached_resource/version'
require 'active_resource'
require "nilio"
require "active_support/cache"
require "active_support/concern"
require "active_support/logger"
require "cached_resource/cached_resource"
require "cached_resource/configuration"
require "cached_resource/caching"
require "cached_resource/version"
require "active_resource"

module CachedResource
# nada
Expand Down
6 changes: 3 additions & 3 deletions lib/cached_resource/cached_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class << self
attr_accessor :cached_resource

# Initialize cached resource or retrieve the current cached resource configuration.
def cached_resource(options={})
def cached_resource(options = {})
defined?(@cached_resource) && @cached_resource || setup_cached_resource!(options)
end

Expand All @@ -20,7 +20,7 @@ def setup_cached_resource!(options)
@cached_resource = CachedResource::Configuration.new(options)
if @cached_resource.concurrent_write
begin
send :require, 'concurrent/promise'
require "concurrent/promise"
rescue LoadError
@cached_resource.logger.error(
"`concurrent_write` option is enabled, but `concurrent-ruby` is not an installed dependency"
Expand All @@ -40,7 +40,7 @@ module ClassMethods
# that wants an independent configuration will need to execute:
# self.cached_resource = CachedResource::Configuration.new(options={})
def inherited(child)
child.cached_resource = self.cached_resource if defined?(@cached_resource)
child.cached_resource = cached_resource if defined?(@cached_resource)
super
end
end
Expand Down
Loading