-
Notifications
You must be signed in to change notification settings - Fork 65
/
policies_controller_test.rb
65 lines (56 loc) · 2.23 KB
/
policies_controller_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'test_plugin_helper'
class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
setup do
::ForemanOpenscap::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 => ''}}
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 ForemanOpenscap::Policy.exists?(policy.id)
end
test "should return xml of scap content" do
policy = FactoryGirl.create(:policy)
get :content, { :id => policy.id }, set_session_user
assert(@response.header['Content-Type'], 'application/xml')
assert_response :success
end
end