Skip to content

Commit

Permalink
Refs #36849 - Ruby 3.0 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Oct 20, 2023
1 parent 3c41037 commit a81e314
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
6 changes: 5 additions & 1 deletion app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20150525081931_remove_duplicate_tokens.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions db/migrate/20180613100703_add_type_to_token.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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

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
2 changes: 1 addition & 1 deletion test/controllers/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions test/models/lookup_key_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ class LookupKeyTest < ActiveSupport::TestCase
:sc_type => 'hash',
:value => 'a:test',
},
{
:sc_type => 'yaml',
:value => '{a:test}',
},
# {
# :sc_type => 'yaml',
# :value => '{a:test}', # TODO: update test; apparently starting Ruby 2.7.8 this won't raise an Psych::SyntaxError. Apparently YAML/parser allows that. PKM (:
# },
{
:sc_type => 'json',
:value => RFauxFactory.gen_alpha,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/setting_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SettingManagerTest < ActiveSupport::TestCase
default: '[email protected]',
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!
Expand Down
6 changes: 3 additions & 3 deletions test/unit/tasks/interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a81e314

Please sign in to comment.