From 9a64fa1c3a4edb760427b685e144f9b02480ee77 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Fri, 10 Nov 2023 17:53:06 +0000 Subject: [PATCH] Fixes #36849 - Run GHA on Ruby 3.0 --- .github/matrix.json | 2 +- app/models/host.rb | 6 +++++- db/migrate/20150525081931_remove_duplicate_tokens.rb | 8 ++++---- db/migrate/20180613100703_add_type_to_token.rb | 8 ++++---- test/controllers/home_controller_test.rb | 2 +- test/unit/setting_manager_test.rb | 2 +- test/unit/tasks/interfaces_test.rb | 6 +++--- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/matrix.json b/.github/matrix.json index 81e37ac5f94b..f15a18dd6920 100644 --- a/.github/matrix.json +++ b/.github/matrix.json @@ -1,5 +1,5 @@ { "postgresql": ["12"], - "ruby": ["2.7"], + "ruby": ["2.7", "3.0"], "node": ["14"] } diff --git a/app/models/host.rb b/app/models/host.rb index 12d7d98593ee..5c71a671f2d1 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -12,7 +12,11 @@ def self.method_missing(method, *args, &block) end end if type.constantize.respond_to?(method, true) - type.constantize.send(method, *args, &block) + if method.to_s =~ /\Afind_in_(.*)\Z/ && args.size == 1 && args[0].is_a?(Hash) + type.constantize.send(method, **args[0], &block) + else + type.constantize.send(method, *args, &block) + end else super end diff --git a/db/migrate/20150525081931_remove_duplicate_tokens.rb b/db/migrate/20150525081931_remove_duplicate_tokens.rb index a43edd20fc8f..29efabcfee13 100644 --- a/db/migrate/20150525081931_remove_duplicate_tokens.rb +++ b/db/migrate/20150525081931_remove_duplicate_tokens.rb @@ -1,15 +1,15 @@ class RemoveDuplicateTokens < ActiveRecord::Migration[4.2] def up - remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, name: "tokens_host_id_fk") remove_index :tokens, :host_id if index_exists? :tokens, :host_id add_index :tokens, :host_id, :unique => true - add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, name: "tokens_host_id_fk") end def down - remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, name: "tokens_host_id_fk") remove_index :tokens, :host_id if index_exists? :tokens, :host_id add_index :tokens, :host_id - add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, name: "tokens_host_id_fk") end end diff --git a/db/migrate/20180613100703_add_type_to_token.rb b/db/migrate/20180613100703_add_type_to_token.rb index 1f1e7901c63c..953ea271d0e6 100644 --- a/db/migrate/20180613100703_add_type_to_token.rb +++ b/db/migrate/20180613100703_add_type_to_token.rb @@ -1,9 +1,9 @@ class AddTypeToToken < ActiveRecord::Migration[5.1] def up - remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, name: "tokens_host_id_fk") remove_index :tokens, :host_id if index_exists? :tokens, :host_id # was unique add_index :tokens, :host_id - add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, name: "tokens_host_id_fk") add_column :tokens, :type, :string, default: 'Token::Build', null: false, index: true change_column :tokens, :value, :text end @@ -11,9 +11,9 @@ def up def down change_column :tokens, :value, :string, limit: 255 remove_column :tokens, :type - remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + remove_foreign_key :tokens, :column => :host_id if foreign_key_exists?(:tokens, name: "tokens_host_id_fk") remove_index :tokens, :host_id if index_exists? :tokens, :host_id add_index :tokens, :host_id, :unique => true - add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, { :name => "tokens_host_id_fk" }) + add_foreign_key :tokens, :hosts, :name => "tokens_host_id_fk" unless foreign_key_exists?(:tokens, name: "tokens_host_id_fk") end end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb index 75ce9c9d2098..d61724e93e8f 100644 --- a/test/controllers/home_controller_test.rb +++ b/test/controllers/home_controller_test.rb @@ -2,7 +2,7 @@ class HomeControllerTest < ActionController::TestCase test "should get status without an error" do - get :status, {:format => "json"} + get :status, :format => "json" assert_response :success end end diff --git a/test/unit/setting_manager_test.rb b/test/unit/setting_manager_test.rb index d6024bb9fd13..6610acd44d53 100644 --- a/test/unit/setting_manager_test.rb +++ b/test/unit/setting_manager_test.rb @@ -118,7 +118,7 @@ class SettingManagerTest < ActiveSupport::TestCase default: 'bar@example.com', description: 'This is nicely described foo setting', full_name: 'Foo setting') - validates(:validfoo, email: true) + validates(:validfoo, { email: true }) end end Foreman::SettingManager.validations.setup! diff --git a/test/unit/tasks/interfaces_test.rb b/test/unit/tasks/interfaces_test.rb index d4aa00446739..4fa69fa36ebc 100644 --- a/test/unit/tasks/interfaces_test.rb +++ b/test/unit/tasks/interfaces_test.rb @@ -34,7 +34,7 @@ class InterfacesTest < ActiveSupport::TestCase end assert_match /cleaned 0 interfaces/, stdout - encoded_hostname = URI.encode("(#{host.name})") + encoded_hostname = CGI.escape("(#{host.name})") assert_match /#{encoded_hostname}/, stdout assert_match /ignored interface set as primary/, stdout end @@ -49,9 +49,9 @@ class InterfacesTest < ActiveSupport::TestCase end assert_match /cleaned 0 interfaces/, stdout - encoded_hostname = URI.encode("(#{host.name})") + encoded_hostname = CGI.escape("(#{host.name})") assert_match /#{encoded_hostname}/, stdout - query = URI.decode(stdout.match(/^.*search=(.*?%29)/)[1]).tr('+', ' ') + query = CGI.unescape(stdout.match(/^.*search=(.*?%29)/)[1]).tr('+', ' ') assert_equal host.id, Host.search_for(query).first.id assert_match /ignored interface set as provision/, stdout end