Sha256: f25d28538554d95c689fb90e32c0db00b27e0d89bda1d70a1ec6b32b9f9eb4ba

Contents?: true

Size: 1.92 KB

Versions: 44

Compression:

Stored size: 1.92 KB

Contents

require 'test_puppet_helper'

module ForemanPuppet
  class PuppetclassLookupKeysControllerTest < ActionController::TestCase
    setup do
      @routes = ForemanPuppet::Engine.routes
      @factory_options = [{ puppetclass: FactoryBot.create(:puppetclass), override: true, default_value: 'test' }]
    end

    let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, override: true) }

    basic_pagination_rendered_test
    basic_pagination_per_page_test

    test 'should get index' do
      lookup_key # we dont want to render welcome
      get :index, session: set_session_user
      assert_response :success
      assert_not_nil assigns(:lookup_keys)
    end

    test 'should get edit' do
      get :edit, params: { id: lookup_key.to_param }, session: set_session_user
      assert_response :success
    end

    test 'should update lookup_keys' do
      put :update, params: { id: lookup_key.to_param, puppetclass_lookup_key: { description: 'test that' } }, session: set_session_user
      assert_equal 'test that', lookup_key.reload.description
      assert_redirected_to puppetclass_lookup_keys_path
    end

    test 'should destroy lookup_keys' do
      lookup_key
      assert_difference(-> { ForemanPuppet::PuppetclassLookupKey.count }, -1) do
        delete :destroy, params: { id: lookup_key.to_param }, session: set_session_user
      end
      assert_redirected_to puppetclass_lookup_keys_path
    end

    test 'user with viewer rights should fail to edit an external variable' do
      setup_user
      get :edit, params: { id: lookup_key.id }, session: set_session_user(:one)
      assert_equal(403, response.status)
    end

    test 'user with viewer rights should succeed in viewing external variables' do
      setup_user
      get :index, session: set_session_user(:one)
      assert_response :success
    end

    private

    def setup_user
      users(:one).roles = [Role.default, Role.find_by(name: 'Viewer')]
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
foreman_puppet-8.0.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.4.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-7.0.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.3.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.2.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.1.1 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-5.1.3 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.1.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.0.1 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-6.0.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-5.1.2 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-4.1.1 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-5.1.1 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-5.1.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-4.1.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-4.0.4 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-5.0.0 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-4.0.3 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-4.0.2 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb
foreman_puppet-3.0.7 test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb