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 #37426 - Rubocop minitest rules fix #9977

Merged
merged 4 commits into from
Jul 31, 2024
Merged
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
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ Style/ParenthesesAroundCondition:

Style/PreferredHashMethods:
Enabled: false

Minitest/AssertEmptyLiteral:
Enabled: true

Minitest/RefuteNil:
Enabled: true
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ Lint/Void:
- 'app/models/nic/base.rb'
- 'app/services/name_generator.rb'

# Offense count: 28
# Cop supports --auto-correct.
Minitest/AssertEmpty:
Enabled: false

# Offense count: 26
# Cop supports --auto-correct.
Expand Down Expand Up @@ -181,12 +177,6 @@ Minitest/AssertMatch:
- 'test/controllers/unattended_controller_test.rb'
- 'test/helpers/pagelets_helper_test.rb'

# Offense count: 1
# Cop supports --auto-correct.
Minitest/AssertNil:
Exclude:
- 'test/graphql/queries/personal_access_token_query_test.rb'

# Offense count: 3
# Cop supports --auto-correct.
Minitest/AssertRespondTo:
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v2/config_reports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_create_duplicate
assert_response :success
assert_not_nil assigns(:config_reports)
reports = ActiveSupport::JSON.decode(@response.body)
assert reports['results'].empty?
assert_empty reports['results']
assert_equal 0, reports['results'].count
end

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/api/v2/hostgroups_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def valid_attrs_with_root(extra_attrs = {})
assert_not_nil assigns(:hostgroups)
hostgroups = ActiveSupport::JSON.decode(@response.body)
assert !hostgroups.empty?
assert hostgroups['results'].select { |h| h.has_key?('parameters') }.empty?
assert_empty hostgroups['results'].select { |h| h.has_key?('parameters') }
end

test "should get index with parameters" do
Expand Down Expand Up @@ -101,7 +101,7 @@ def valid_attrs_with_root(extra_attrs = {})
test_attributes :pid => '86eca603-2cdd-4563-b6f6-aaa5cea1a723'
test "should update puppet_proxy" do
host_group = FactoryBot.create(:hostgroup)
assert host_group.puppet_proxy_id.nil?
assert_nil host_group.puppet_proxy_id
puppet_proxy = smart_proxies(:puppetmaster)
put :update, params: { :id => host_group.id, :hostgroup => { :puppet_proxy_id => puppet_proxy.id } }
assert_response :success
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v2/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ def setup

test "should return empty host list by unassigned hostgroup id" do
get :index, params: { :hostgroup_id => @unassigned_hg2.id }
assert_equal [], assigns(:hosts)
assert_empty assigns(:hosts)
end

test "should return a host in list" do
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/api/v2/roles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class Api::V2::RolesControllerTest < ActionController::TestCase
assert_response :success
cloned_role = Role.find_by :name => new_name
assert cloned_role
assert_equal [], cloned_role.organizations
assert_equal [], cloned_role.locations
assert_empty cloned_role.organizations
assert_empty cloned_role.locations
end

context "with organization and locations" do
Expand Down Expand Up @@ -223,8 +223,8 @@ class Api::V2::RolesControllerTest < ActionController::TestCase
assert @org, updated_role.organizations.first
assert @loc, updated_role.locations.first
updated_filter = Filter.find_by :id => filter.id
assert_equal [], updated_filter.organizations
assert_equal [], updated_filter.locations
assert_empty updated_filter.organizations
assert_empty updated_filter.locations
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v2/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def user_one_as_anonymous_viewer
test "#index should not show hidden users" do
get :index, params: { :search => "login == #{users(:anonymous).login}" }
results = ActiveSupport::JSON.decode(@response.body)
assert results['results'].empty?, results.inspect
assert_empty results['results']
end

test "#find_resource should not return hidden users" do
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/compute_resources_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ComputeResourcesControllerTest < ActionController::TestCase
setup_user "edit"
put :update, params: { :id => @compute_resource.to_param, :compute_resource => {:name => "editing_self", :password => ''} }, session: set_session_user
@compute_resource = ComputeResource.unscoped.find(@compute_resource.id)
assert @compute_resource.password.empty?
assert_empty @compute_resource.password
end

test "should not get edit when restricted" do
Expand Down Expand Up @@ -162,7 +162,7 @@ class ComputeResourcesControllerTest < ActionController::TestCase
test 'valid fields' do
get :index, params: { :search => 'name = openstack' }, session: set_session_user
assert_response :success
assert flash.empty?
assert_empty flash
end

test 'invalid fields' do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/hostgroups_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def setup_user(operation, type = 'hostgroups')
put :update, params: { :commit => "Update", :id => hostgroup.id, :hostgroup => {:root_pass => '', :name => hostgroup.name} }, session: set_session_user
end
hostgroup = Hostgroup.find(hostgroup.id)
assert hostgroup.root_pass.empty?
assert_empty hostgroup.root_pass
end

test "hostgroup rename changes matcher" do
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def set_remote_user_to(user)

test 'destroy' do
multiple_hosts_submit_request('destroy', [@host1.id, @host2.id], 'Destroyed selected hosts')
assert Host.where(:id => [@host1.id, @host2.id]).empty?
assert_empty Host.where(:id => [@host1.id, @host2.id])
end

test 'disable notifications' do
Expand Down Expand Up @@ -968,7 +968,7 @@ class Host::Valid < Host::Managed; end
test 'blank root password submitted in host does erase existing password' do
put :update, params: { :commit => "Update", :id => @host.name, :host => {:root_pass => '' } }, session: set_session_user
@host = Host.find(@host.id)
assert @host.root_pass.empty?
assert_empty @host.root_pass
end

test "host should get bmc status" do
Expand Down Expand Up @@ -996,7 +996,7 @@ class Host::Valid < Host::Managed; end
assert bmc1.save
put :update, params: { :commit => "Update", :id => @host.name, :host => {:interfaces_attributes => {"0" => {:id => bmc1.id, :password => ''} } } }, session: set_session_user
@host = Host.find(@host.id)
assert @host.interfaces.bmc.first.password.empty?
assert_empty @host.interfaces.bmc.first.password
end

# To test that work-around for Rails bug - https://github.com/rails/rails/issues/11031
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/operatingsystems_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def setup_os_user
test 'valid fields' do
get :index, params: { :search => 'name = centos' }, session: set_session_user
assert_response :success
assert flash.empty?
assert_empty flash
end

test 'invalid fields' do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/provisioning_templates_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ProvisioningTemplatesControllerTest < ActionController::TestCase
ProxyAPI::TFTP.any_instance.expects(:create_default).with(regexp_matches(/^PXE.*/), has_entry(:menu, regexp_matches(/ks=http:\/\/foreman.unattended.url\/unattended\/template/))).returns(true).times(3)
get :build_pxe_default, session: set_session_user
assert flash[:success].present?
assert flash[:error].empty?
assert_empty flash[:error]
assert_redirected_to provisioning_templates_path
end

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class UsersControllerTest < ActionController::TestCase

test "should clear the current user after processing the request" do
get :index, session: set_session_user
assert User.current.nil?
assert_nil User.current
end

test "should be able to create user without mail and update the mail later" do
Expand Down
2 changes: 1 addition & 1 deletion test/graphql/queries/personal_access_token_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PersonalAccessTokenQueryTest < GraphQLQueryTestCase
assert_equal personal_access_token.updated_at.utc.iso8601, data['updatedAt']
assert_equal personal_access_token.name, data['name']
assert_equal personal_access_token.expires_at.utc.iso8601, data['expiresAt']
assert_equal nil, data['lastUsedAt']
assert_nil data['lastUsedAt']
assert_equal personal_access_token.revoked?, data['revoked']
assert_equal personal_access_token.expires?, data['expires']
assert_equal personal_access_token.active?, data['active']
Expand Down
2 changes: 1 addition & 1 deletion test/integration/hostgroup_js_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HostgroupJSTest < IntegrationTestWithJavascript
click_button 'Submit'

hostgroup = Hostgroup.where(:name => "myhostgroup1").first
refute hostgroup.nil?
refute_nil hostgroup
assert_equal os.id, hostgroup.operatingsystem_id
assert page.has_current_path? hostgroups_path
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ def check_vm_attribute_names(cr)
unexpected_names = normalized_keys - (normalized_keys & allowed_vm_attr_names)
msg = "Some unexpected attributes detected: #{unexpected_names.join(', ')}."
msg += "\nMake user you can't use one of names that already exist. If not, please extend ComputeResourceTestHelpers.allowed_vm_attr_names."
assert(unexpected_names.empty?, msg)
assert_empty(unexpected_names, msg)
end
end
4 changes: 2 additions & 2 deletions test/models/compute_resources/libvirt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Foreman::Model::LibvirtTest < ActiveSupport::TestCase
test 'adds volumes_attributes when they were missing' do
normalized = cr.normalize_vm_attrs({})

assert_equal({}, normalized['volumes_attributes'])
assert_empty(normalized['volumes_attributes'])
end

test 'normalizes volumes_attributes' do
Expand Down Expand Up @@ -213,7 +213,7 @@ class Foreman::Model::LibvirtTest < ActiveSupport::TestCase
test 'adds interfaces_attributes when they were missing' do
normalized = cr.normalize_vm_attrs({})

assert_equal({}, normalized['interfaces_attributes'])
assert_empty(normalized['interfaces_attributes'])
end

test 'normalizes interfaces_attributes' do
Expand Down
8 changes: 4 additions & 4 deletions test/models/concerns/audit_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def setup
domain = FactoryBot.create(:domain, :with_auditing, :locations => [], :organizations => [])
audit = domain.audits.last
assert_equal 'create', audit.action
assert_equal [], audit.location_ids
assert_equal [], audit.organization_ids
assert_empty audit.location_ids
assert_empty audit.organization_ids

domain.name = 'blablabla' # needed for a new audit to be generated
domain.locations = [@loc]
Expand Down Expand Up @@ -92,8 +92,8 @@ def setup
host = FactoryBot.create(:host, :with_auditing, :location => nil, :organization => nil)
audit = host.audits.last
assert_equal 'create', audit.action
assert_equal [], audit.location_ids
assert_equal [], audit.organization_ids
assert_empty audit.location_ids
assert_empty audit.organization_ids

host.location_id = @loc.id
host.organization_id = @org.id
Expand Down
2 changes: 1 addition & 1 deletion test/models/concerns/belongs_to_proxies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EmptySampleModel
setup :clear_plugins

test '#registered_smart_proxies has default value' do
assert_equal({}, EmptySampleModel.registered_smart_proxies)
assert_empty(EmptySampleModel.registered_smart_proxies)
end

test '#registered_smart_proxies contains foo proxy' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setup

test "should not destroy if it contains subnets" do
@domain.subnets.clear
assert @domain.subnets.empty?
assert_empty @domain.subnets
@domain.subnets << Subnet.first
assert [email protected]
assert_match /is used by/, @domain.errors.full_messages.join("\n")
Expand Down Expand Up @@ -81,7 +81,7 @@ def create_a_host

test "should query local nameservers when enabled" do
Setting['query_local_nameservers'] = true
assert Domain.first.nameservers.empty?
assert_empty Domain.first.nameservers
end

test "should query remote nameservers from domain SOA" do
Expand Down
4 changes: 2 additions & 2 deletions test/models/fact_value_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup
assert_equal [@child_value], result

result = FactValue.with_fact_parent_id(@child_name.id)
assert_equal [], result
assert_empty result
end

test "should return search results if search free text is fact name" do
Expand Down Expand Up @@ -182,7 +182,7 @@ def setup
users(:one).locations = [@locs.first]
users(:one).organizations = [@orgs.first]

assert_equal [], FactValue.my_facts.map(&:id).sort
assert_empty FactValue.my_facts.map(&:id).sort
end

test 'user can view host taxonomy, my_facts contains host facts' do
Expand Down
2 changes: 1 addition & 1 deletion test/models/host_status/configuration_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def stub_outofsync_setting(value)
@status.save
assert_equal [@host], Host.search_for('status.applied = 0')
assert_equal [@host], Host.search_for('status.applied = false')
assert_equal [], Host.search_for('status.applied = 1')
assert_empty Host.search_for('status.applied = 1')
end

test 'overwrite puppet_interval as host parameter' do
Expand Down
2 changes: 1 addition & 1 deletion test/models/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,7 @@ def to_managed!
host = FactoryBot.create(:host)
ComputeResource.any_instance.stubs(:vm_compute_attributes_for).returns({:foo => 'bar'})
copy = host.clone
assert copy.compute_attributes.nil?
assert_nil copy.compute_attributes
end

test 'facts are deleted when build set to true' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/medium_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MediumTest < ActiveSupport::TestCase

test "can't be blank" do
@medium.path = ' '
assert @medium.path.strip.empty?
assert_empty @medium.path.strip
refute_valid @medium
end

Expand All @@ -83,7 +83,7 @@ class MediumTest < ActiveSupport::TestCase

assert medium.destroy
host.reload
assert host.medium.nil?
assert_nil host.medium
end

test "should not destroy if medium has hosts that are in build mode" do
Expand Down
2 changes: 1 addition & 1 deletion test/models/nics/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Nic::BaseTest < ActiveSupport::TestCase

test '#children_mac_addresses defaults to empty array' do
nic = FactoryBot.build_stubbed(:nic_base)
assert_equal [], nic.children_mac_addresses
assert_empty nic.children_mac_addresses
end

describe 'MAC validation' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/nics/bond_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class BondTest < ActiveSupport::TestCase
assert_equal %w(eth2), bond.attached_devices_identifiers

assert bond.remove_slave('eth2')
assert_equal [], bond.attached_devices_identifiers
assert_empty bond.attached_devices_identifiers

assert bond.remove_slave('eth2')
assert_equal [], bond.attached_devices_identifiers
assert_empty bond.attached_devices_identifiers
end

test 'identifier is required for managed bonds' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/orchestration/dhcp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup
h = FactoryBot.create(:host)
assert h.valid?
assert_equal false, h.dhcp?
assert_equal [], h.dhcp_records
assert_empty h.dhcp_records
end

test 'unmanaged should not call methods after managed?' do
Expand Down Expand Up @@ -382,7 +382,7 @@ def host_with_loader(loader)

h.build = true
assert h.valid?
assert h.errors.empty?
assert_empty h.errors
assert_equal ["dhcp_create_aa:bb:cc:dd:ee:f1"], h.queue.task_ids
end

Expand Down
2 changes: 1 addition & 1 deletion test/models/orchestration/tftp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class TFTPOrchestrationTest < ActiveSupport::TestCase

result = h.send(:generate_pxe_template, :ZTP)
assert result.blank?
assert h.errors.empty?
assert_empty h.errors
end

test 'should rebuild tftp IPv4' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/provisioning_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ProvisioningTemplateTest < ActiveSupport::TestCase
assert tmplt.save
end
assert_nil tmplt.template_kind
assert_equal [], tmplt.hostgroups
assert_equal [], tmplt.template_combinations
assert_empty tmplt.hostgroups
assert_empty tmplt.template_combinations
end

# If the template is not a snippet is should require the specific declaration
Expand Down
Loading
Loading