diff --git a/.rubocop.yml b/.rubocop.yml index 0d0665b31c3..05a6af3d54f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -86,8 +86,5 @@ Style/PreferredHashMethods: Minitest/AssertEmptyLiteral: Enabled: true -Minitest/AssertNil: - Enabled: true - Minitest/RefuteNil: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 678b069f6d8..cc287e6429e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/test/controllers/api/v2/config_reports_controller_test.rb b/test/controllers/api/v2/config_reports_controller_test.rb index a8f5ad5125b..2d8ebef01cd 100644 --- a/test/controllers/api/v2/config_reports_controller_test.rb +++ b/test/controllers/api/v2/config_reports_controller_test.rb @@ -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 diff --git a/test/controllers/api/v2/hostgroups_controller_test.rb b/test/controllers/api/v2/hostgroups_controller_test.rb index f3ffe8952cd..8d9f566fa93 100644 --- a/test/controllers/api/v2/hostgroups_controller_test.rb +++ b/test/controllers/api/v2/hostgroups_controller_test.rb @@ -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 diff --git a/test/controllers/api/v2/users_controller_test.rb b/test/controllers/api/v2/users_controller_test.rb index a2583d59471..7d6aff0d889 100644 --- a/test/controllers/api/v2/users_controller_test.rb +++ b/test/controllers/api/v2/users_controller_test.rb @@ -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 diff --git a/test/controllers/compute_resources_controller_test.rb b/test/controllers/compute_resources_controller_test.rb index d055abd369e..4e4739c38f3 100644 --- a/test/controllers/compute_resources_controller_test.rb +++ b/test/controllers/compute_resources_controller_test.rb @@ -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 @@ -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 diff --git a/test/controllers/hostgroups_controller_test.rb b/test/controllers/hostgroups_controller_test.rb index 697729e0e81..5a619f41e7b 100644 --- a/test/controllers/hostgroups_controller_test.rb +++ b/test/controllers/hostgroups_controller_test.rb @@ -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 diff --git a/test/controllers/hosts_controller_test.rb b/test/controllers/hosts_controller_test.rb index 4223378077b..21a68003240 100644 --- a/test/controllers/hosts_controller_test.rb +++ b/test/controllers/hosts_controller_test.rb @@ -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 @@ -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 @@ -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 diff --git a/test/controllers/operatingsystems_controller_test.rb b/test/controllers/operatingsystems_controller_test.rb index 0e3dc811a7e..1336eff2f5a 100644 --- a/test/controllers/operatingsystems_controller_test.rb +++ b/test/controllers/operatingsystems_controller_test.rb @@ -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 diff --git a/test/controllers/provisioning_templates_controller_test.rb b/test/controllers/provisioning_templates_controller_test.rb index 55270802fe7..8c061ebaedc 100644 --- a/test/controllers/provisioning_templates_controller_test.rb +++ b/test/controllers/provisioning_templates_controller_test.rb @@ -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 diff --git a/test/models/compute_resources/compute_resource_test_helpers.rb b/test/models/compute_resources/compute_resource_test_helpers.rb index 60919ff471e..2c2b00a49b8 100644 --- a/test/models/compute_resources/compute_resource_test_helpers.rb +++ b/test/models/compute_resources/compute_resource_test_helpers.rb @@ -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 diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index 268c8632f0f..a0dd7cceb19 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -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") @@ -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 diff --git a/test/models/medium_test.rb b/test/models/medium_test.rb index 74e80d36d4b..cab87ab3979 100644 --- a/test/models/medium_test.rb +++ b/test/models/medium_test.rb @@ -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 diff --git a/test/models/orchestration/dhcp_test.rb b/test/models/orchestration/dhcp_test.rb index 458c52781f5..feb7cad8e52 100644 --- a/test/models/orchestration/dhcp_test.rb +++ b/test/models/orchestration/dhcp_test.rb @@ -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 diff --git a/test/models/orchestration/tftp_test.rb b/test/models/orchestration/tftp_test.rb index f0baa984f59..f9d2fbde25a 100644 --- a/test/models/orchestration/tftp_test.rb +++ b/test/models/orchestration/tftp_test.rb @@ -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 diff --git a/test/models/shared/taxonomies_base_test.rb b/test/models/shared/taxonomies_base_test.rb index ac26751908f..260cfbfbb90 100644 --- a/test/models/shared/taxonomies_base_test.rb +++ b/test/models/shared/taxonomies_base_test.rb @@ -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 diff --git a/test/models/template_test.rb b/test/models/template_test.rb index 94d29c8bb1b..f69a24653a7 100644 --- a/test/models/template_test.rb +++ b/test/models/template_test.rb @@ -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 diff --git a/test/models/token/build_test.rb b/test/models/token/build_test.rb index a9ea92300b5..7267d6265e9 100644 --- a/test/models/token/build_test.rb +++ b/test/models/token/build_test.rb @@ -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 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 80ff082023c..7bbc43df018 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -176,12 +176,12 @@ def setup # Mail enabled u1 = FactoryBot.create(:user, :mail => 'foo@bar.baz', :mail_enabled => nil) u2 = FactoryBot.create(:user, :mail => 'foo@bar.baz', :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 => 'foo@bar.baz', :mail_enabled => true, :disabled => false) diff --git a/test/unit/foreman/model/ovirt_test.rb b/test/unit/foreman/model/ovirt_test.rb index f5af5fc3900..5d014486cc6 100644 --- a/test/unit/foreman/model/ovirt_test.rb +++ b/test/unit/foreman/model/ovirt_test.rb @@ -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 diff --git a/test/unit/net/dhcp_test.rb b/test/unit/net/dhcp_test.rb index 471aa0f6ed1..bca53732c79 100644 --- a/test/unit/net/dhcp_test.rb +++ b/test/unit/net/dhcp_test.rb @@ -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 @@ -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 @@ -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 diff --git a/test/unit/role_lock_test.rb b/test/unit/role_lock_test.rb index 63aa5f8ddb4..6cfc82e0421 100644 --- a/test/unit/role_lock_test.rb +++ b/test/unit/role_lock_test.rb @@ -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 @@ -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