Sha256: df91446c027989aee5894b2a82e47904ec233639d9e475bc70d744d2a872e55a

Contents?: true

Size: 1.79 KB

Versions: 79

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'test_plugin_helper'

module Api
  module V2
    # Tests for the controller to CRUD Ansible Variables
    class AnsibleVariablesControllerTest < ActionController::TestCase
      setup do
        @variable = FactoryBot.create(:ansible_variable)
      end

      test 'should get index' do
        get :index, :session => set_session_user
        response = JSON.parse(@response.body)
        refute_empty response['results']
        assert_response :success
      end

      test 'should destroy' do
        delete :destroy,
               :params => { :id => @variable.id },
               :session => set_session_user
        assert_response :ok
        refute AnsibleVariable.exists?(@variable.id)
      end

      test 'should import' do
        put :import,
            :session => set_session_user
        assert_response :success
      end

      test 'should obsolete' do
        put :obsolete,
            :session => set_session_user
        assert_response :success
      end

      test 'should create' do
        params = { :key => 'test name', :ansible_role_id => FactoryBot.create(:ansible_role).id }
        post :create,
             :params => params,
             :session => set_session_user
        assert_response :success
        res = JSON.parse(@response.body)
        refute res['imported']
      end

      test 'should update' do
        variable = FactoryBot.create(:ansible_variable, :default_value => 'my default value')
        new_value = 'changed default value'
        post :update,
             :params => { :id => variable.id, :default_value => new_value },
             :session => set_session_user

        assert_response :success
        res = JSON.parse(@response.body)
        assert_equal new_value, res['default_value']
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-15.0.1 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-15.0.0 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-14.2.2 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-14.2.1 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.7 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-14.2.0 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-14.1.1 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-14.1.0 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.5 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-14.0.0 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.4 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.3 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.2 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.1 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-13.0.0 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-12.0.7 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-10.4.4 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-7.1.8 test/functional/api/v2/ansible_variables_controller_test.rb
foreman_ansible-12.0.6 test/functional/api/v2/ansible_variables_controller_test.rb