Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #35432 - Use Rails 6.1 defaults #9382

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def auto_complete_controller_name

def sort(field, permitted: [], **kwargs)
kwargs[:url_options] ||= current_url_params(permitted: permitted)
super(field, kwargs)
super(field, **kwargs)
end

def help_button
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/foreman/sti.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def new(*attributes, &block)
end
end

def save(*args)
def save(*args, **kwargs)
type_changed = type_changed?
self.class.instance_variable_set("@finder_needs_type_condition", :false) if type_changed
super
Expand Down
22 changes: 10 additions & 12 deletions app/models/concerns/has_many_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ class << self; self end
end

#### has_many ####
def has_many(*args)
options = args.last.is_a?(Hash) ? args.last : {}
has_many_names_for(args.first, options)
def has_many(name, scope = nil, **kwargs, &extension)
has_many_names_for(name)
super
end

def has_and_belongs_to_many(association, options = {})
has_many_names_for(association, options)
def has_and_belongs_to_many(name, scope = nil, **kwargs, &extension)
has_many_names_for(name)
super
end

def has_many_names_for(association, options)
def has_many_names_for(association)
assoc = association.to_s.tableize.singularize

# SETTER _names= method
Expand All @@ -71,15 +70,14 @@ def has_many_names_for(association, options)
end

#### belongs_to ####
def belongs_to(*args)
options = args.last.is_a?(Hash) ? args.last : {}
belongs_to_name_for(args.first, options)
super
def belongs_to(name, scope = nil, name_accessor: nil, **kwargs)
belongs_to_name_for(name, name_accessor)
super(name, scope, **kwargs)
end

def belongs_to_name_for(association, options)
def belongs_to_name_for(association, name_accessor)
assoc = association.to_s.tableize.singularize
assoc_name = options.delete(:name_accessor) || "#{assoc}_name"
assoc_name = name_accessor || "#{assoc}_name"

# SETTER _name= method
define_method "#{assoc_name}=" do |name_value|
Expand Down
2 changes: 1 addition & 1 deletion app/services/csv_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.export(resources, columns, header = nil)
context = Foreman::ThreadSession::Context.get

Enumerator.new do |csv|
Foreman::ThreadSession::Context.set(context)
Foreman::ThreadSession::Context.set(**context)
csv << CSV.generate_line(header)
cols = columns.map { |c| c.to_s.split('.').map(&:to_sym) }
resources.uncached do
Expand Down
2 changes: 1 addition & 1 deletion app/services/foreman/renderer/scope/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Template < Foreman::Renderer::Scope::Base
attr_reader :template_input_values

def initialize(template_input_values: {}, **params)
super(params)
super(**params)
@template_input_values = template_input_values
end
end
Expand Down
8 changes: 8 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ class Foreman::Consoletie < Rails::Railtie

module Foreman
class Application < Rails::Application
config.load_defaults 6.1

# Rails 5.0 changed this to true, but a lot of code depends on this
config.active_record.belongs_to_required_by_default = false

# Rails 6.0 changed this to :zeitwerk
config.autoloader = :classic

# Setup additional routes by loading all routes file from routes directory
Dir["#{Rails.root}/config/routes/**/*.rb"].each do |route_file|
config.paths['config/routes.rb'] << route_file
Expand Down
2 changes: 1 addition & 1 deletion test/models/external_usergroup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExternalUsergroupTest < ActiveSupport::TestCase
test 'update_usergroups matches LDAP gids with external user groups case insensitively' do
setup_ldap_stubs

@auth_source_ldap.expects(:valid_group?).with('IPAUSERS').returns(true)
@auth_source_ldap.expects(:valid_group?).with('IPAUSERS').returns(true).twice
external = FactoryBot.create(:external_usergroup, :auth_source => @auth_source_ldap, :name => 'IPAUSERS')
ldap_user = FactoryBot.create(:user, :login => 'JohnSmith', :mail => '[email protected]', :auth_source => @auth_source_ldap)
AuthSourceLdap.any_instance.expects(:users_in_group).with('IPAUSERS').returns(['JohnSmith'])
Expand Down
4 changes: 2 additions & 2 deletions test/models/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2500,8 +2500,8 @@ def to_managed!
refute_nil host.provision_interface
primary = host.primary_interface

nic = FactoryBot.build_stubbed(:nic_managed, :host => host, :mac => '00:00:00:AA:BB:CC', :ip => '192.168.0.1',
:name => 'host2', :domain => host.domain)
nic = FactoryBot.build(:nic_managed, :host => host, :mac => '00:00:00:AA:BB:CC', :ip => '192.168.0.1',
:name => 'host2', :domain => host.domain)
nic.primary = true
nic.provision = true

Expand Down