diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 798a52f9e52..d3aee3f1ddf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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. # @@ -113,7 +123,7 @@ jobs: # https://stackoverflow.com/questions/70742968/automatically-accept-installing-npx-package # - 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/rails_7.0/lcov.info' 'coverage/lcov.info' && cat coverage/lcov.info - name: Configure coverage reports for Coveralls uses: coverallsapp/github-action@master with: diff --git a/Appraisals b/Appraisals index 04b78000e39..02ce573dbd7 100644 --- a/Appraisals +++ b/Appraisals @@ -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" diff --git a/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches/active_model_attributes.rb b/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches/active_model_attributes.rb index 7a51628b92e..9c0d3d281cc 100644 --- a/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches/active_model_attributes.rb +++ b/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches/active_model_attributes.rb @@ -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| diff --git a/spec/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/middleware_spec.rb b/spec/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/middleware_spec.rb index 55e7e6d5f70..f7e09ee35d0 100644 --- a/spec/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/middleware_spec.rb +++ b/spec/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/middleware_spec.rb @@ -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