Skip to content

Commit

Permalink
Fix rails version CI variables
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Sep 1, 2024
1 parent 65558c1 commit 4de3f03
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ jobs:
- ruby: "3.3"
### TEST RAILS VERSIONS
- ruby: "2.7"
rails_version: "~> 6.0"
rails_version: "~> 6.0.0"
- ruby: "2.7"
rails_version: "~> 6.1"
rails_version: "~> 6.1.0"
- ruby: "3.3"
rails_version: "~> 7.0"
rails_version: "~> 7.0.0"
db_gem_version: "~> 1.4" # fixes sqlite3 gem dependency issue
- ruby: "3.3"
rails_version: "~> 7.1"
rails_version: "~> 7.1.0"
- ruby: "3.3"
rails_version: "~> 7.2"
rails_version: "~> 7.2.0"

steps:
- uses: actions/checkout@v3
Expand Down
34 changes: 34 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,37 @@

config.filter_rails_from_backtrace!
end

if Rails::VERSION::STRING.to_f <= 6.0
def assert_no_difference(expression, message = nil, &block)
assert_difference expression, 0, message, &block
end

def assert_difference(expression, *args, &block)
expressions =
if expression.is_a?(Hash)
message = args[0]
expression
else
difference = args[0] || 1
message = args[1]
Array(expression).index_with(difference)
end

exps = expressions.keys.map { |e|
e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
}
before = exps.map(&:call)

retval = assert_nothing_raised(&block)

expressions.zip(exps, before) do |(code, diff), exp, before_value|
actual = exp.call
error = "#{code.inspect} didn't change by #{diff}, but by #{actual - before_value}"
error = "#{message}.\n#{error}" if message
assert_equal(before_value + diff, actual, error)
end

retval
end
end

0 comments on commit 4de3f03

Please sign in to comment.