Skip to content

Commit

Permalink
ci(appraisal): run rails in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Sep 15, 2022
1 parent 93e6d13 commit 363b6bf
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ jobs:
#
bundler-cache: true
- name: Run RSpec
run: bundle exec rspec
run: bundle exec rspec --format progress
- name: Install dependencies for appraisals
run: bundle exec appraisal install
- name: Run RSpec with Rails 5.2
run: bundle exec appraisal rails_5.2 rspec --format progress --require rails_helper
- name: Run RSpec with Rails 6.0
run: bundle exec appraisal rails_6.0 rspec --format progress --require rails_helper
- name: Run RSpec with Rails 6.1
run: bundle exec appraisal rails_6.1 rspec --format progress --require rails_helper
- name: Run RSpec with Rails 7.0
run: bundle exec appraisal rails_7.0 rspec --format progress --require rails_helper
##
# NOTE: `lcov-result-merger' is written in JS.
#
Expand All @@ -112,8 +122,17 @@ jobs:
# NOTE: `npx --yes' option.
# https://stackoverflow.com/questions/70742968/automatically-accept-installing-npx-package
#
# NOTE: `lcov-result-merger' uses `vinyl-fs' for globs which in turn uses `node-glob'.
# - https://github.com/mweibel/lcov-result-merger/blob/v3.3.0/bin/lcov-result-merger.js#L38
# - https://github.com/gulpjs/vinyl-fs#srcglobs-options
# - https://github.com/isaacs/node-glob#glob-primer
#
# NOTE: Append `&& cat coverage/lcov.info' to debug.
#
# IMPORTANT: 'coverage/**/lcov.info' single quotes are mandatory.
#
- name: Merge coverage reports into single file
run: npx --yes lcov-result-merger ./coverage/**/lcov.info ./coverage/lcov.info
run: npx --yes lcov-result-merger 'coverage/**/lcov.info' coverage/lcov.info
- name: Configure coverage reports for Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
14 changes: 10 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# frozen_string_literal: true

appraise "rails-5" do
gem "activemodel", "~> 5.0.0"
appraise "rails_5.2" do
gem "activemodel", "~> 5.2.0"

gem "shoulda-matchers", "~> 4.0.0"
end

appraise "rails-6" do
appraise "rails_6.0" do
gem "activemodel", "~> 6.0.0"

gem "shoulda-matchers", "~> 5.0.0"
end

appraise "rails-7" do
appraise "rails_6.1" do
gem "activemodel", "~> 6.1.0"

gem "shoulda-matchers", "~> 5.0.0"
end

appraise "rails_7.0" do
gem "activemodel", "~> 7.0.0"

gem "shoulda-matchers", "~> 5.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ module UsingActiveModelAttributes
module Patches
##
# Copy of `ActiveModel::Attributes'.
# https://api.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html
# - https://api.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html
#
# - https://github.com/rails/rails/blob/v7.0.0/activemodel/lib/active_model/attributes.rb
# - https://github.com/rails/rails/blob/v6.1.0/activemodel/lib/active_model/attributes.rbhttps://github.com/rails/rails/blob/v6.1.0/activemodel/lib/active_model/attributes.rb
# - https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/attributes.rb
# - https://github.com/rails/rails/blob/v5.2.0/activemodel/lib/active_model/attributes.rb
#
ActiveModelAttributes =
::ActiveModel::Attributes.dup.tap do |mod|
Expand Down
11 changes: 9 additions & 2 deletions spec/coverage_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@ def branch_coverage?
SimpleCov::Formatter::LcovFormatter.config do |config|
config.report_with_single_file = true

##
# NOTE: Replaces dots since they have specific meaning in globs. Check:
# - https://github.com/isaacs/node-glob#glob-primer
# - convenient_service/.github/workflows/ci.yml
#
escape = ->(name) { name.tr(".", "_") }

##
# NOTE: `ENV["APPRAISAL_NAME"]' is set in `spec_helper'.
#
appraisal_name = ENV["APPRAISAL_NAME"].to_s.empty? ? "without_appraisal" : ENV["APPRAISAL_NAME"].to_s
appraisal_name = escape[ENV["APPRAISAL_NAME"].to_s.empty? ? "without_appraisal" : ENV["APPRAISAL_NAME"].to_s]

##
# NOTE: `ENV["RUBY_VERSION"]' is set by Ruby.
#
ruby_version = ENV["RUBY_VERSION"].to_s
ruby_version = escape[ENV["RUBY_VERSION"].to_s]

config.single_report_path = File.join("coverage", ruby_version, appraisal_name, "lcov.info")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ class self::Internals

attr_reader :foo

validates :foo, length: {maximum: 2}
##
# NOTE: Rails 6 and 7 differently handle nested hashes in `validates' call. See links below.
# - https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/translation.rb#L67
# - https://github.com/rails/rails/blob/v7.0.0/activemodel/lib/active_model/translation.rb#L67
# - https://github.com/rails/rails/commit/4645f2d34fc1d9f037096de988e5cc5ca41a3cf3
#
# For example, the following works in Ruby 2.7 + Rails 6, Ruby 2.7 + Rails 7, Ruby 3.* + Rails 7,
# but fails in Ruby 3.* and Rails 6.
# validates :foo, length: {maximum: 2}
#
# To imitate a similar behaviour in Rails 6 a custom validation can be used.
# validate { errors.add(:foo, "Foo length is over 2") if foo.to_s.length > 2 }
# validate_with LengthValidatior, fields: :foo
#
# More info:
# - https://guides.rubyonrails.org/active_record_validations.html#performing-custom-validations
#
# TODO: Add to troubleshoting.
#
# validates :foo, length: {maximum: 2}
validate { errors.add(:foo, "Foo length is over 2") if foo.to_s.length > 2 }

def initialize(foo:)
@foo = foo
Expand Down

0 comments on commit 363b6bf

Please sign in to comment.