From e0b86cb3095f5d99f126581668bcfdd1bd945663 Mon Sep 17 00:00:00 2001 From: Swapnil Abnave Date: Thu, 21 Dec 2017 10:02:12 +0000 Subject: [PATCH] Fixes #22054 - Audit resources which lack auditing Http Proxy, Models(H/W Models) --- app/models/http_proxy.rb | 2 ++ app/models/model.rb | 2 ++ test/models/model_test.rb | 10 ++++++++++ test/unit/http_proxy_test.rb | 10 ++++++++++ 4 files changed, 24 insertions(+) diff --git a/app/models/http_proxy.rb b/app/models/http_proxy.rb index 3ce16bfaa35..a7c480a868e 100644 --- a/app/models/http_proxy.rb +++ b/app/models/http_proxy.rb @@ -3,6 +3,8 @@ class HttpProxy < ApplicationRecord include Taxonomix include Encryptable + audited + extend FriendlyId encrypts :password diff --git a/app/models/model.rb b/app/models/model.rb index d02f3a15071..1b2112e4d1b 100644 --- a/app/models/model.rb +++ b/app/models/model.rb @@ -4,6 +4,8 @@ class Model < ApplicationRecord friendly_id :name include Parameterizable::ByIdName + audited + before_destroy EnsureNotUsedBy.new(:hosts) has_many_hosts has_many :trends, :as => :trendable, :class_name => "ForemanTrend" diff --git a/test/models/model_test.rb b/test/models/model_test.rb index fd3432eb42b..37e51a5378e 100644 --- a/test/models/model_test.rb +++ b/test/models/model_test.rb @@ -23,4 +23,14 @@ class ModelTest < ActiveSupport::TestCase assert_equal 1, m.reload.hosts.size assert !m.destroy end + + context 'is audited' do + test 'on creation on of a new model' do + model = FactoryBot.build(:model, :with_auditing) + + assert_difference 'model.audits.count' do + model.save! + end + end + end end diff --git a/test/unit/http_proxy_test.rb b/test/unit/http_proxy_test.rb index b50c370b1e6..6db23ddf79c 100644 --- a/test/unit/http_proxy_test.rb +++ b/test/unit/http_proxy_test.rb @@ -15,4 +15,14 @@ class HttpProxyTest < ActiveSupport::TestCase test 'search by name' do assert_equal 1, HttpProxy.search_for("name = #{http_proxy.name}").count end + + context 'is audited' do + test 'on creation on of a new http_proxy' do + http_proxy = FactoryBot.build(:http_proxy, :with_auditing) + + assert_difference 'http_proxy.audits.count' do + http_proxy.save! + end + end + end end