Sha256: 1c0f4f4d658ce0ebf506bb391eea6d5d2427ea8a3e18162c732ecca6de033331

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require 'test_plugin_helper'

class Api::V2::PoliciesControllerTest < ActionController::TestCase
  setup do
    Scaptimony::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
  end

  test "should get index" do
    FactoryGirl.create(:policy)
    get :index, {}, set_session_user
    response = ActiveSupport::JSON.decode(@response.body)
    assert response['results'].length > 0
    assert_response :success
  end

  test "should show a policy" do
    policy = FactoryGirl.create(:policy)
    get :show, { :id => policy.to_param }, set_session_user
    response = ActiveSupport::JSON.decode(@response.body)
    assert response['name'], policy.name
    assert_response :success
  end

  test "should update a policy" do
    policy = FactoryGirl.create(:policy)
    put :update, {:id => policy.id, :policy => {:period => 'monthly'}}
    updated_policy = ActiveSupport::JSON.decode(@response.body)
    assert(updated_policy['period'], 'monthly')
    assert_response :ok
  end

  test "should not update invalid" do
    policy = FactoryGirl.create(:policy)
    put :update, {:id => policy.id, :policy => {:name => 'say my name'}}
    assert_response :unprocessable_entity
  end

  test "should create a policy" do
    scap_content_profile = FactoryGirl.create(:scap_content_profile)
    attributes = {:policy => {:name => 'my_policy', :scap_content_profile_id => scap_content_profile.id, :scap_content_id => scap_content_profile.scap_content_id}}
    post :create, attributes, set_session_user
    response = ActiveSupport::JSON.decode(@response.body)
    assert response['scap_content_profile_id'], scap_content_profile.to_param
    assert_response :created
  end

  test "should not create invalid policy" do
    post :create, {}, set_session_user
    assert_response :unprocessable_entity
  end

  test "should destroy" do
    policy = FactoryGirl.create(:policy)
    delete :destroy, { :id => policy.id }, set_session_user
    assert_response :ok
    refute Scaptimony::Policy.exists?(policy.id)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_openscap-0.4.0 test/functional/api/v2/policies_controller_test.rb