Skip to content

Commit

Permalink
Fix Minitest/AssertPredicate cop
Browse files Browse the repository at this point in the history
  • Loading branch information
archanaserver committed Jan 9, 2024
1 parent d1ec4fd commit 96f1eae
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ Metrics/BlockLength:

Minitest/EmptyLineBeforeAssertionMethods:
Enabled: true

Minitest/AssertPredicate:
Enabled: true
12 changes: 6 additions & 6 deletions test/integration/hosts_js_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def multiple_actions_div
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')

# Dropdown visible?
assert multiple_actions_div.find('.dropdown-toggle').visible?
assert_predicate multiple_actions_div.find('.dropdown-toggle'), :visible?
multiple_actions_div.find('.dropdown-toggle').click

assert multiple_actions_div.find('ul').visible?
assert_predicate multiple_actions_div.find('ul'), :visible?

# Hosts are added to cookie
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))
Expand All @@ -43,7 +43,7 @@ def multiple_actions_div
click_on('Change Salt Master')
end

assert index_modal.visible?, 'Modal window was shown'
assert_predicate index_modal, :visible?, 'Modal window was shown'
page.find('#proxy_proxy_id').find("option[value='#{@host.salt_proxy.id}']").select_option

# remove hosts cookie on submit
Expand All @@ -61,10 +61,10 @@ def multiple_actions_div
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')

# Dropdown visible?
assert multiple_actions_div.find('.dropdown-toggle').visible?
assert_predicate multiple_actions_div.find('.dropdown-toggle'), :visible?
multiple_actions_div.find('.dropdown-toggle').click

assert multiple_actions_div.find('ul').visible?
assert_predicate multiple_actions_div.find('ul'), :visible?

# Hosts are added to cookie
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))
Expand All @@ -75,7 +75,7 @@ def multiple_actions_div
click_on('Change Salt Environment')
end

assert index_modal.visible?, 'Modal window was shown'
assert_predicate index_modal, :visible?, 'Modal window was shown'
page.find('#salt_environment_id').find("option[value='#{@host.salt_environment.id}']").select_option

# remove hosts cookie on submit
Expand Down
2 changes: 1 addition & 1 deletion test/integration/salt_autosign_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SaltKeysTest < ActionDispatch::IntegrationTest
test 'index page' do
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)

assert find_link('Keys').visible?, 'Keys is not visible'
assert_predicate find_link('Keys'), :visible?, 'Keys is not visible'
assert has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/host_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HostExtensionsTest < ActiveSupport::TestCase
assert_not host.configuration?
host.salt_proxy = @proxy

assert host.configuration?
assert_predicate host, :configuration?
end

context 'autosign handling' do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/hostgroup_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class HostgroupExtensionsTest < ActiveSupport::TestCase
child_one = FactoryBot.create :hostgroup, parent: parent
child_two = FactoryBot.create :hostgroup, :with_salt_modules, parent: child_one

assert child_two.all_salt_modules.any?
assert_predicate child_two.all_salt_modules, :any?
end
end
end
4 changes: 2 additions & 2 deletions test/unit/report_importer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReportImporterTest < ActiveSupport::TestCase
HostStatus::ConfigurationStatus.any_instance.stubs(:relevant?).returns(true)
ForemanSalt::ReportImporter.import(@report)

assert Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus).error?
assert_predicate Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus), :error?
end

test 'importing report has correct status' do
Expand Down Expand Up @@ -68,7 +68,7 @@ class ReportImporterTest < ActiveSupport::TestCase
HostStatus::ConfigurationStatus.any_instance.stubs(:relevant?).returns(true)
ForemanSalt::ReportImporter.import(@report_unhandled)

assert Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus).error?
assert_predicate Host.find_by(name: @host).get_status(HostStatus::ConfigurationStatus), :error?
end
end
end
4 changes: 2 additions & 2 deletions test/unit/salt_variables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class SaltVariablesTest < ActiveSupport::TestCase
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)

assert_valid salt_variable
assert salt_variable.salt?
assert_predicate salt_variable, :salt?
assert_equal @state.id, salt_variable.salt_module.id
end

test 'salt variable is referencing a LookupValue' do
salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)

assert salt_variable.lookup_values.count.zero?
assert_predicate salt_variable.lookup_values.count, :zero?
LookupValue.create(value: '[1.2.3.4,2.3.4.5]', match: 'domain = mydomain.net', lookup_key: salt_variable)

assert_equal(1, salt_variable.lookup_values.count)
Expand Down

0 comments on commit 96f1eae

Please sign in to comment.