require 'test_puppet_helper' module ForemanPuppet class HostsControllerTest < ActionController::TestCase tests ::HostsController setup do @routes = ForemanPuppet::Engine.routes as_admin do host1 host2 end end let(:org) { users(:one).organizations.first } let(:loc) { users(:one).locations.first } let(:environment1) { FactoryBot.create(:environment, organizations: [org], locations: [loc]) } let(:environment2) { FactoryBot.create(:environment, organizations: [org], locations: [loc]) } let(:hostgroup) { FactoryBot.create(:hostgroup, :with_puppet_enc, environment: environment2, organizations: [org], locations: [loc]) } let(:host_defaults) { { hostgroup: hostgroup, environment: environment1, organization: org, location: loc } } let(:host1) { FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass, host_defaults) } let(:host2) { FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass, host_defaults) } test 'user with edit host rights with update environments should change environments' do @request.env['HTTP_REFERER'] = '/hosts' setup_user 'edit', 'hosts' post :update_multiple_environment, params: { host_ids: [host1.id, host2.id], environment: { id: environment2.id } }, session: set_session_user(:one) assert_equal environment2.id, host1.reload.puppet.environment_id assert_equal environment2.id, host2.reload.puppet.environment_id assert_equal 'Updated hosts: changed environment', flash[:success] end test 'should inherit the hostgroup environment if *inherit from hostgroup* selected' do @request.env['HTTP_REFERER'] = '/hosts' setup_user 'edit', 'hosts' params = { host_ids: [host1.id, host2.id], environment: { id: 'inherit' } } post :update_multiple_environment, params: params, session: set_session_user(:one) assert_equal hostgroup.puppet.environment_id, host1.reload.puppet.environment_id assert_equal hostgroup.puppet.environment_id, host2.reload.puppet.environment_id end describe '#edit' do setup { @routes = Rails.application.routes } test 'lookup value and description should be html escaped' do FactoryBot.create(:puppetclass_lookup_key, default_value: "", description: "", puppetclass: host1.puppet.puppetclasses.first) get :edit, params: { id: host1.to_param }, session: set_session_user assert_not response.body.include?('