Sha256: 25bfbea9c5d5c409b0ed9bebf2209bf8573f7367113c0c5e7f7eff2099f4a139

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

require 'test_helper'

class Api::V1::SubnetsControllerTest < ActionController::TestCase

  valid_attrs = { :name => 'QA2', :network => '10.35.2.27', :mask => '255.255.255.0' }

  def test_index
    get :index
    subnets = ActiveSupport::JSON.decode(@response.body)
    assert subnets.is_a?(Array)
    assert_response :success
    assert !subnets.empty?

  end

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

  test "should create subnet" do
    assert_difference('Subnet.count') do
      post :create, { :subnet => valid_attrs }
    end
    assert_response :success
  end

  test "should update subnet" do
    put :update, { :id => subnets(:one).to_param, :subnet => { } }
    assert_response :success
  end

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

  test "should NOT destroy subnet that is in use" do
    assert_difference('Subnet.count', 0) do
      delete :destroy, { :id => subnets(:one).to_param }
    end
    assert_response :unprocessable_entity
  end

  def test_destroy_json
    subnet = Subnet.first
    subnet.hosts.clear
    subnet.interfaces.clear
    as_admin { delete :destroy, {:id => subnet.id} }
    ActiveSupport::JSON.decode(@response.body)
    assert_response :ok
    assert !Subnet.exists?(:id => subnet.id)
  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/subnets_controller_test.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/test/functional/api/v1/subnets_controller_test.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/test/functional/api/v1/subnets_controller_test.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/test/functional/api/v1/subnets_controller_test.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/test/functional/api/v1/subnets_controller_test.rb