Skip to content

Commit

Permalink
Test empting classes
Browse files Browse the repository at this point in the history
This did not work due to a foreman issue, that wrongly defines the facet associations.
  • Loading branch information
ezr-ondrej committed Feb 17, 2022
1 parent 31b2dd9 commit 073e252
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,22 @@ class HostsControllerTest < ActionController::TestCase

test 'should update with puppet class' do
puppetclass = environment.puppetclasses.first
# uses the deprecated version of params passing without namespace, to test it works :)
put :update, params: { id: host.id, host: { environment_id: environment.id, puppetclass_ids: [puppetclass.id] } }
assert_response :success
response = JSON.parse(@response.body)
assert_equal environment.id, response['environment_id'], "Can't update host with environment #{environment}"
assert_equal puppetclass.id, response['puppetclasses'][0]['id'], "Can't update host with puppetclass #{puppetclass}"
end

test 'should remove puppetclass by passing empty array' do
host2 = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)

put :update, params: { id: host2.id, host: { puppet_attributes: { puppetclass_ids: [] } } }
assert_response :success
response = JSON.parse(@response.body)
assert_empty(response['puppetclasses'], 'Can not remove puppetclasses')
end
end

describe '#enc' do
Expand Down
11 changes: 11 additions & 0 deletions test/models/foreman_puppet/host_puppet_facet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ class HostPuppetFacetTest < ActiveSupport::TestCase
end
end

describe '#puppetclass_ids=' do
test 'allows empting classes' do
host = FactoryBot.create(:host, :with_puppet_enc,
environment: environment,
puppetclasses: [puppetclass_both])
host.attributes = { puppet_attributes: { puppetclass_ids: [] } }
assert host.save, 'Host could not be saved after updating puppetclasses'
assert_empty host.reload.all_puppetclasses, 'Puppetclasses were not removed successfuly'
end
end

describe '#all_puppetclasses' do
test 'should return all classes for environment only' do
host = FactoryBot.create(:host, :with_puppet_enc,
Expand Down

0 comments on commit 073e252

Please sign in to comment.