aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-10-13 15:28:45 +0200
committerGitHub2017-10-13 15:28:45 +0200
commita8fd113096d1cf9e88685106b0e45fff2c4a5aed (patch)
tree1c194882ebabb9e10ba599218f420af6ff638c4d
parentccf42142c7f9f965a0e22fec6f7d7d84f3e1150e (diff)
parentf4cc0ece7c86f03eac3dcbbdb032b036237df314 (diff)
downloadchouette-core-a8fd113096d1cf9e88685106b0e45fff2c4a5aed.tar.bz2
Merge pull request #91 from af83/4709-compliance-check-criticity-as-string
4709 compliance check criticity as string
-rw-r--r--app/models/compliance_check.rb8
-rw-r--r--db/migrate/20171010202716_change_criticity_in_compliance_check_to_string.rb5
-rw-r--r--db/schema.rb4
-rw-r--r--lib/compliance_control_set_copier.rb5
-rw-r--r--spec/factories/compliance_checks.rb2
-rw-r--r--spec/lib/compliance_control_set_copier_spec.rb130
-rw-r--r--spec/models/compliance_check_message_spec.rb2
-rw-r--r--spec/models/compliance_check_spec.rb4
-rw-r--r--yarn.lock4
9 files changed, 106 insertions, 58 deletions
diff --git a/app/models/compliance_check.rb b/app/models/compliance_check.rb
index 4c29129b9..55f2ae228 100644
--- a/app/models/compliance_check.rb
+++ b/app/models/compliance_check.rb
@@ -1,8 +1,12 @@
class ComplianceCheck < ActiveRecord::Base
+
+ self.inheritance_column = nil
+
+ extend Enumerize
belongs_to :compliance_check_set
belongs_to :compliance_check_block
-
- enum criticity: [:info, :warning, :error]
+
+ enumerize :criticity, in: %i(warning error), scope: true, default: :warning
validates :criticity, presence: true
validates :name, presence: true
validates :code, presence: true
diff --git a/db/migrate/20171010202716_change_criticity_in_compliance_check_to_string.rb b/db/migrate/20171010202716_change_criticity_in_compliance_check_to_string.rb
new file mode 100644
index 000000000..684c37a06
--- /dev/null
+++ b/db/migrate/20171010202716_change_criticity_in_compliance_check_to_string.rb
@@ -0,0 +1,5 @@
+class ChangeCriticityInComplianceCheckToString < ActiveRecord::Migration
+ def change
+ change_column :compliance_checks, :criticity, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 7f02a342d..583851ffc 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: 20171003133042) do
+ActiveRecord::Schema.define(version: 20171010202716) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -213,7 +213,7 @@ ActiveRecord::Schema.define(version: 20171003133042) do
t.hstore "control_attributes"
t.string "name"
t.string "code"
- t.integer "criticity"
+ t.string "criticity"
t.text "comment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
diff --git a/lib/compliance_control_set_copier.rb b/lib/compliance_control_set_copier.rb
index 0a688c964..20518ee0e 100644
--- a/lib/compliance_control_set_copier.rb
+++ b/lib/compliance_control_set_copier.rb
@@ -36,7 +36,8 @@ class ComplianceControlSetCopier
# Copy Blocks:
def make_cck_block cc_block
cck_set.compliance_check_blocks.create(
- name: name_with_refid(cc_block.name)).tap do | cck_block |
+ name: name_with_refid(cc_block.name),
+ condition_attributes: cc_block.condition_attributes).tap do | cck_block |
relink_checks_to_block cc_block, cck_block
end
end
@@ -58,8 +59,10 @@ class ComplianceControlSetCopier
end
def make_compliance_check(compliance_control)
cck_set.compliance_checks.create(
+ control_attributes: compliance_control.control_attributes,
criticity: compliance_control.criticity,
name: name_with_refid(compliance_control.name),
+ comment: compliance_control.comment,
code: compliance_control.code,
origin_code: compliance_control.origin_code
).tap do | compliance_check |
diff --git a/spec/factories/compliance_checks.rb b/spec/factories/compliance_checks.rb
index f9af62c73..526052329 100644
--- a/spec/factories/compliance_checks.rb
+++ b/spec/factories/compliance_checks.rb
@@ -2,7 +2,7 @@ FactoryGirl.define do
factory :compliance_check do
sequence(:name) { |n| "Compliance check #{n}" }
type "Type"
- criticity :info
+ criticity "warning"
code "code"
origin_code "code"
comment "Text"
diff --git a/spec/lib/compliance_control_set_copier_spec.rb b/spec/lib/compliance_control_set_copier_spec.rb
index 1b4a75634..3cecc44d1 100644
--- a/spec/lib/compliance_control_set_copier_spec.rb
+++ b/spec/lib/compliance_control_set_copier_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe ComplianceControlSetCopier do
let( :cc_set ){ create :compliance_control_set }
- context 'Copying empty set' do
+ context 'Copying empty set' do
context 'incorrect organisation' do
# Assuring the organisation missmatch
before { referential.organisation_id = cc_set.organisation_id.succ }
@@ -18,53 +18,87 @@ RSpec.describe ComplianceControlSetCopier do
end
end
- context 'correct organisation' do
+ context 'correct organisation' do
let(:ref){ create :referential, organisation_id: cc_set.organisation_id }
- let(:cc_blox){
- 3.times.map{ |_| create :compliance_control_block, compliance_control_set: cc_set }
- }
- let!(:direct_ccs){
- 3.times.map{ |n| create :compliance_control, compliance_control_set: cc_set, name: "direct #{n.succ}" }
- }
- # Needed to check we do not dulicate a node (compliance_control) twice
- let!(:indirect_ccs){
- # Create 1 child for each block and also associate first of the direct ccs to the first block
- # seconf of the direct css to the second block
- cc_blox.take(2).zip(direct_ccs.take(2)).each do | cc_block, cc |
- cc.update compliance_control_block_id: cc_block.id
- end
- cc_blox.each_with_index.map{ | cc_block, n |
- create(:compliance_control, compliance_control_set: cc_set, compliance_control_block: cc_block, name: "indirect #{n.succ}")
+ context 'Directed Acyclic Graph is copied correctly' do
+ let(:cc_blox){
+ 3.times.map{ |_| create :compliance_control_block, compliance_control_set: cc_set }
+ }
+ let!(:direct_ccs){
+ 3.times.map{ |n| create :compliance_control, compliance_control_set: cc_set, name: "direct #{n.succ}" }
+ }
+ # Needed to check we do not dulicate a node (compliance_control) twice
+ let!(:indirect_ccs){
+ # Create 1 child for each block and also associate first of the direct ccs to the first block
+ # seconf of the direct css to the second block
+ cc_blox.take(2).zip(direct_ccs.take(2)).each do | cc_block, cc |
+ cc.update compliance_control_block_id: cc_block.id
+ end
+ cc_blox.each_with_index.map{ | cc_block, n |
+ create(:compliance_control, compliance_control_set: cc_set, compliance_control_block: cc_block, name: "indirect #{n.succ}")
+ }
}
- }
-
- let( :cck_set ){ ComplianceCheckSet.last }
- let( :cck_blox ){ cck_set.compliance_check_blocks }
- let( :ccks ){ cck_set.compliance_checks }
-
- it 'correctly creates a cck_set for a complete DAG' do
- # Slowness of tests constrains us to create a minimum of objects in the DB,
- # hence only one example :(
- counts = object_counts
- subject.copy(cc_set.id, ref.id)
-
- # Did not change the original objects
- # Correct numbers
- expect( ComplianceControlSet.count ).to eq(counts.cc_set_count)
- expect( ComplianceControlBlock.count ).to eq(counts.cc_block_count)
- expect( ComplianceControl.count ).to eq(counts.cc_count)
-
- expect( ComplianceCheckSet.count ).to eq(counts.cck_set_count + 1)
- expect( cck_blox.count ).to eq(counts.cck_block_count + cc_blox.size)
- expect( ccks.count ).to eq(counts.cck_count + direct_ccs.size + indirect_ccs.size)
-
- # Correcly associated
- expect( cck_blox.map(&:compliance_checks).map(&:size) )
- .to eq([2, 2, 1])
- expect( ComplianceCheck.where(name: mk_name('direct 1')).first.compliance_check_block_id )
- .to eq( cck_blox.first.id )
- expect( ComplianceCheck.where(name: mk_name('direct 3')).first.compliance_check_block_id ).to be_nil
+
+ let( :cck_set ){ ComplianceCheckSet.last }
+ let( :cck_blox ){ cck_set.compliance_check_blocks }
+ let( :ccks ){ cck_set.compliance_checks }
+
+ it 'correctly creates a cck_set for a complete DAG' do
+ # Slowness of tests constrains us to create a minimum of objects in the DB,
+ # hence only one example :(
+ counts = object_counts
+ subject.copy(cc_set.id, ref.id)
+
+ # Did not change the original objects
+ # Correct numbers
+ expect( ComplianceControlSet.count ).to eq(counts.cc_set_count)
+ expect( ComplianceControlBlock.count ).to eq(counts.cc_block_count)
+ expect( ComplianceControl.count ).to eq(counts.cc_count)
+
+ expect( ComplianceCheckSet.count ).to eq(counts.cck_set_count + 1)
+ expect( cck_blox.count ).to eq(counts.cck_block_count + cc_blox.size)
+ expect( ccks.count ).to eq(counts.cck_count + direct_ccs.size + indirect_ccs.size)
+
+ # Correcly associated
+ expect( cck_blox.map(&:compliance_checks).map(&:size) )
+ .to eq([2, 2, 1])
+ expect( ComplianceCheck.where(name: mk_name('direct 1')).first.compliance_check_block_id )
+ .to eq( cck_blox.first.id )
+ expect( ComplianceCheck.where(name: mk_name('direct 3')).first.compliance_check_block_id ).to be_nil
+ end
+ end
+
+ context 'Node data is copied correctly' do
+ let( :cc_block ){ create :compliance_control_block, compliance_control_set: cc_set }
+
+ let!( :control ){ create :compliance_control,
+ compliance_control_set: cc_set,
+ compliance_control_block: cc_block,
+ name: 'control' }
+
+ let( :cck_set ) { ComplianceCheckSet.last }
+ let( :cck_block ) { ComplianceCheckBlock.last }
+ let( :cck ) { ComplianceCheck.last }
+
+ it 'into the compliance_check nodes' do
+ subject.copy(cc_set.id, ref.id)
+
+ # Set
+ expect( cck_set.name ).to eq(mk_name(cc_set.name))
+
+ # Block
+ expect( cck_block.name ).to eq(mk_name(cc_block.name))
+ expect( cck_block.condition_attributes ).to eq(cc_block.condition_attributes)
+
+ # Control/Check
+ att_names = %w{ control_attributes code criticity comment origin_code }
+ expected = control.attributes.values_at(*att_names) << mk_name(control.name)
+ actual = cck.attributes.values_at(*(att_names << 'name'))
+
+ expect( actual ).to eq( expected )
+
+ end
end
end
@@ -80,9 +114,9 @@ RSpec.describe ComplianceControlSetCopier do
cck_count: ComplianceCheck.count
end
- def mk_name name
- [name, ref.name].join('-')
- end
+ def mk_name name
+ [name, ref.name].join('-')
+ end
end
end
diff --git a/spec/models/compliance_check_message_spec.rb b/spec/models/compliance_check_message_spec.rb
index 7c8f05953..b55537f95 100644
--- a/spec/models/compliance_check_message_spec.rb
+++ b/spec/models/compliance_check_message_spec.rb
@@ -1,5 +1,3 @@
-require 'rails_helper'
-
RSpec.describe ComplianceCheckMessage, type: :model do
it 'should have a valid factory' do
expect(FactoryGirl.build(:compliance_check_message)).to be_valid
diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb
index 710cd4b4f..bd797ab09 100644
--- a/spec/models/compliance_check_spec.rb
+++ b/spec/models/compliance_check_spec.rb
@@ -3,6 +3,10 @@ RSpec.describe ComplianceCheck, type: :model do
expect(FactoryGirl.build(:compliance_check)).to be_valid
end
+ it 'has STI disabled' do
+ expect( described_class.inheritance_column ).to be_blank
+ end
+
it { should belong_to :compliance_check_set }
it { should belong_to :compliance_check_block }
diff --git a/yarn.lock b/yarn.lock
index fa92344d4..4c06202d4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2,7 +2,7 @@
# yarn lockfile v1
-"@rails/webpacker@3.0.2":
+"@rails/webpacker@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-3.0.2.tgz#574b021c1f3d700b40a934576c9bdac5c9f9c744"
dependencies:
@@ -5502,7 +5502,7 @@ webpack-dev-middleware@^1.11.0:
range-parser "^1.0.3"
time-stamp "^2.0.0"
-webpack-dev-server@2.9.1:
+webpack-dev-server@^2.9.1:
version "2.9.1"
resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-2.9.1.tgz#7ac9320b61b00eb65b2109f15c82747fc5b93585"
dependencies: