aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-09-06 11:38:58 +0200
committerXinhui2017-09-06 11:39:07 +0200
commite2270acdfcec57a8be2ada201a668d9d610953ab (patch)
tree8f94e214a3fe9091e02dbc090d5578c766aae23e
parent55f142f0a2ef77b88229585225edd561fcf53d92 (diff)
downloadchouette-core-e2270acdfcec57a8be2ada201a668d9d610953ab.tar.bz2
Model ComplianceCheckResult
Refs #4390
-rw-r--r--app/models/compliance_check_result.rb5
-rw-r--r--db/migrate/20131029115820_create_compliance_check_results.rb23
-rw-r--r--db/migrate/20170906092619_create_compliance_check_results.rb13
-rw-r--r--db/schema.rb17
-rw-r--r--spec/factories/compliance_check_results.rb7
-rw-r--r--spec/models/compliance_check_result_spec.rb10
6 files changed, 49 insertions, 26 deletions
diff --git a/app/models/compliance_check_result.rb b/app/models/compliance_check_result.rb
index 06f8649f5..161e45189 100644
--- a/app/models/compliance_check_result.rb
+++ b/app/models/compliance_check_result.rb
@@ -1,3 +1,4 @@
-class ComplianceCheckResult
-
+class ComplianceCheckResult < ActiveRecord::Base
+ belongs_to :compliance_check
+ belongs_to :compliance_check_resource
end
diff --git a/db/migrate/20131029115820_create_compliance_check_results.rb b/db/migrate/20131029115820_create_compliance_check_results.rb
deleted file mode 100644
index 7f5c8e436..000000000
--- a/db/migrate/20131029115820_create_compliance_check_results.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-class CreateComplianceCheckResults < ActiveRecord::Migration
- def up
- unless table_exists? :compliance_check_results
- create_table :compliance_check_results do |t|
- t.belongs_to :compliance_check_task , :null => :no ,:limit => 8
- t.string :rule_code # rule code value
- t.string :severity # warning, error, improvement
- t.string :status # NA, OK, NOK
- t.integer :violation_count # number of violation occurences
- t.text :detail # detail of violation location
- t.timestamps
- end
- add_foreign_key :compliance_check_results, :compliance_check_tasks, :on_delete => :cascade
- end
- end
-
- def down
- if table_exists? :compliance_check_results
- execute "drop table compliance_check_results"
- # drop_table :compliance_check_results
- end
- end
-end
diff --git a/db/migrate/20170906092619_create_compliance_check_results.rb b/db/migrate/20170906092619_create_compliance_check_results.rb
new file mode 100644
index 000000000..e917d384e
--- /dev/null
+++ b/db/migrate/20170906092619_create_compliance_check_results.rb
@@ -0,0 +1,13 @@
+class CreateComplianceCheckResults < ActiveRecord::Migration
+ def change
+ create_table :compliance_check_results do |t|
+ t.references :compliance_check, index: true, foreign_key: true
+ t.references :compliance_check_resource, index: true, foreign_key: true
+ t.string :message_key
+ t.hstore :message_attributes
+ t.hstore :resource_attributes
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a1897ac49..64e184467 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170906091136) do
+ActiveRecord::Schema.define(version: 20170906092619) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -165,6 +165,19 @@ ActiveRecord::Schema.define(version: 20170906091136) do
t.datetime "updated_at", null: false
end
+ create_table "compliance_check_results", id: :bigserial, force: :cascade do |t|
+ t.integer "compliance_check_id"
+ t.integer "compliance_check_resource_id"
+ t.string "message_key"
+ t.hstore "message_attributes"
+ t.hstore "resource_attributes"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "compliance_check_results", ["compliance_check_id"], name: "index_compliance_check_results_on_compliance_check_id", using: :btree
+ add_index "compliance_check_results", ["compliance_check_resource_id"], name: "index_compliance_check_results_on_compliance_check_resource_id", using: :btree
+
create_table "compliance_check_sets", id: :bigserial, force: :cascade do |t|
t.integer "referential_id"
t.integer "compliance_control_set_id"
@@ -947,6 +960,8 @@ ActiveRecord::Schema.define(version: 20170906091136) do
add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey"
add_foreign_key "api_keys", "organisations"
add_foreign_key "compliance_check_blocks", "compliance_check_sets"
+ add_foreign_key "compliance_check_results", "compliance_check_resources"
+ add_foreign_key "compliance_check_results", "compliance_checks"
add_foreign_key "compliance_check_sets", "compliance_control_sets"
add_foreign_key "compliance_check_sets", "referentials"
add_foreign_key "compliance_check_sets", "workbenches"
diff --git a/spec/factories/compliance_check_results.rb b/spec/factories/compliance_check_results.rb
new file mode 100644
index 000000000..a56d77ce4
--- /dev/null
+++ b/spec/factories/compliance_check_results.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :compliance_check_result do
+ association :compliance_check
+ association :compliance_check_resource
+ message_key "message_key"
+ end
+end
diff --git a/spec/models/compliance_check_result_spec.rb b/spec/models/compliance_check_result_spec.rb
new file mode 100644
index 000000000..95586862f
--- /dev/null
+++ b/spec/models/compliance_check_result_spec.rb
@@ -0,0 +1,10 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckResult, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check_result)).to be_valid
+ end
+
+ it { should belong_to :compliance_check }
+ it { should belong_to :compliance_check_resource }
+end