Skip to content

Commit

Permalink
Fixes #37426 - Fix cop Minitest/AssertEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
archanaserver authored and ekohl committed Jul 31, 2024
1 parent 2845fc1 commit d59c5c1
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 35 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,5 @@ Style/PreferredHashMethods:
Minitest/AssertEmptyLiteral:
Enabled: true

Minitest/AssertNil:
Enabled: true

Minitest/RefuteNil:
Enabled: true
4 changes: 0 additions & 4 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
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
2 changes: 1 addition & 1 deletion 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
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
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/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 !@domain.destroy
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
2 changes: 1 addition & 1 deletion 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 Down
2 changes: 1 addition & 1 deletion test/models/orchestration/dhcp_test.rb
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion test/models/shared/taxonomies_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ module TaxonomiesBaseTest
taxonomy = taxonomy_class.create :name => "rack1", :parent_id => parent.id
# no hosts were assigned to taxonomy, so no missing ids need to be selected
taxonomy.need_to_be_selected_ids.each do |k, v|
assert v.empty?
assert_empty v
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/models/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class TemplateTest < ActiveSupport::TestCase
test 'should initialize a new template' do
template = ProvisioningTemplate.find_without_collision(:name, 'new template')
assert template.new_record?
assert template.errors.empty?
assert_empty template.errors
end

test 'should return existing template in current context' do
Expand Down
2 changes: 1 addition & 1 deletion test/models/token/build_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Token::BuildTest < ActiveSupport::TestCase
host.create_token(:value => 'aaaaaa', :expires => Time.now.utc + 1.minute)
assert_instance_of Token::Build, host.token
host.token = nil
assert Token.where(:value => 'aaaaaa', :host_id => host.id).empty?
assert_empty Token.where(:value => 'aaaaaa', :host_id => host.id)
end

test "a host cannot delete tokens for other hosts" do
Expand Down
4 changes: 2 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ def setup
# Mail enabled
u1 = FactoryBot.create(:user, :mail => '[email protected]', :mail_enabled => nil)
u2 = FactoryBot.create(:user, :mail => '[email protected]', :mail_enabled => '')
assert User.with_enabled_email.where(login: [u1, u2].map(&:login)).empty?
assert_empty User.with_enabled_email.where(login: [u1, u2].map(&:login))

# Mail missing
u1 = FactoryBot.create(:user, :mail => '', :mail_enabled => true)
u2 = FactoryBot.create(:user, :mail => nil, :mail_enabled => true)
assert User.with_enabled_email.where(login: [u1, u2].map(&:login)).empty?
assert_empty User.with_enabled_email.where(login: [u1, u2].map(&:login))

# Disabled
u1 = FactoryBot.create(:user, :mail => '[email protected]', :mail_enabled => true, :disabled => false)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/foreman/model/ovirt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def new_ovirt_cr(proto = 'http')
record.stubs(:datacenters).returns(['example', 1])
RestClient.expects(:post).never()
assert record.test_connection
assert record.errors.empty?
assert_empty record.errors
end

test "test_connection should detect 302 HTTPS redirect with HTTP url and fail" do
Expand Down
6 changes: 3 additions & 3 deletions test/unit/net/dhcp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DhcpTest < ActiveSupport::TestCase
record1 = Net::DHCP::Record.new(:hostname => "test1", :mac => "aa:bb:cc:dd:ee:ff",
:network => "127.0.0.0", :ip => "127.0.0.1",
"proxy" => subnets(:one).dhcp_proxy)
assert record1.conflicts.empty?
assert_empty record1.conflicts
end

test "dhcp record validation should return false when proxy returns nil" do
Expand Down Expand Up @@ -137,7 +137,7 @@ class DhcpTest < ActiveSupport::TestCase
record1 = Net::DHCP::Record.new(:hostname => "discovered_host1", :mac => "aa:bb:cc:dd:ee:01",
:network => "127.0.0.0", :ip => "127.0.0.2",
"proxy" => subnets(:one).dhcp_proxy)
assert record1.conflicts.empty?
assert_empty record1.conflicts
assert record1.valid?
end

Expand All @@ -160,7 +160,7 @@ class DhcpTest < ActiveSupport::TestCase
"proxy" => subnets(:one).dhcp_proxy)
assert_equal "lease", subnets(:one).dhcp_proxy.record("127.0.0.0", "aa:bb:cc:dd:ee:01").type
assert_equal "lease", subnets(:one).dhcp_proxy.records_by_ip("127.0.0.0", "127.0.0.2").first.type
assert rec.conflicts.empty?
assert_empty rec.conflicts
end

test "dhcp record and reservation with same MAC is not a conflict" do
Expand Down
4 changes: 2 additions & 2 deletions test/unit/role_lock_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def find_role(name)
refute find_role("Customized CRUD hosts")
original_role = find_role(original_name)
assert_equal original_role.id, role.id
assert original_role.permission_diff(perms).empty?
assert_empty original_role.permission_diff(perms)
end

test "should process existing role with origin and removed permissions" do
Expand All @@ -91,7 +91,7 @@ def find_role(name)
refute find_role("Customized CRUD hosts")
original_role = find_role(original_name)
assert_equal original_role.id, role.id
assert original_role.permission_diff(perms).empty?
assert_empty original_role.permission_diff(perms)
end

test "should process existing role with unchanged permissions list" do
Expand Down

0 comments on commit d59c5c1

Please sign in to comment.