Sha256: 226c30c2a2259b32d5319dc2e0c1c7a768e23488a1f61876d7f77b41ac63bcbb

Contents?: true

Size: 1.87 KB

Versions: 5

Compression:

Stored size: 1.87 KB

Contents

require 'test_helper'

class Api::V1::HostsControllerTest < ActionController::TestCase

  def valid_attrs
    { :name               => 'testhost11',
      :environment_id     => environments(:production).id,
      :domain_id          => domains(:mydomain).id,
      :ip                 => '10.0.0.20',
      :mac                => '52:53:00:1e:85:93',
      :architecture_id    => Architecture.find_by_name('x86_64').id,
      :operatingsystem_id => Operatingsystem.find_by_name('Redhat').id,
      :puppet_proxy_id    => 7
    }
  end

  test "should get index" do
    get :index, { }
    assert_response :success
    assert_not_nil assigns(:hosts)
    hosts = ActiveSupport::JSON.decode(@response.body)
    assert !hosts.empty?
  end

  test "should show individual record" do
    get :show, { :id => hosts(:one).to_param }
    assert_response :success
    show_response = ActiveSupport::JSON.decode(@response.body)
    assert !show_response.empty?
  end

  test "should create host" do
    disable_orchestration
    assert_difference('Host.count') do
      post :create, { :host => valid_attrs }
    end
    assert_response :success
    last_host = Host.order('id desc').last
  end

  test "should create host with managed is false if parameter is passed" do
    disable_orchestration
    post :create, { :host => valid_attrs.merge!(:managed => false) }
    assert_response :success
    last_host = Host.order('id desc').last
    assert_equal false, last_host.managed?
  end

  test "should update host" do
    put :update, { :id => hosts(:two).to_param, :host => { } }
    assert_response :success
  end

  test "should destroy hosts" do
    assert_difference('Host.count', -1) do
      delete :destroy, { :id => hosts(:one).to_param }
    end
    assert_response :success
  end

  test "should show status hosts" do
    get :status, { :id => hosts(:one).to_param }
    assert_response :success
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/test/functional/api/v1/hosts_controller_test.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/test/functional/api/v1/hosts_controller_test.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/test/functional/api/v1/hosts_controller_test.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/test/functional/api/v1/hosts_controller_test.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/test/functional/api/v1/hosts_controller_test.rb