diff options
| author | Xinhui | 2017-09-06 10:59:44 +0200 |
|---|---|---|
| committer | Xinhui | 2017-09-06 10:59:44 +0200 |
| commit | 64e68de279967fc352f96e414ddb04bd32aa8a74 (patch) | |
| tree | f3e2240cddf750196dcb55f8bf0f2ca599130f7b | |
| parent | 26affe0da7bb7987e54c862e40acd4db8641d162 (diff) | |
| download | chouette-core-64e68de279967fc352f96e414ddb04bd32aa8a74.tar.bz2 | |
Model ComplianceCheck
Refs #4388
| -rw-r--r-- | app/models/compliance_check.rb | 8 | ||||
| -rw-r--r-- | config/initializers/apartment.rb | 1 | ||||
| -rw-r--r-- | db/migrate/20170906084628_create_compliance_checks.rb | 16 | ||||
| -rw-r--r-- | db/schema.rb | 20 | ||||
| -rw-r--r-- | spec/factories/compliance_checks.rb | 11 | ||||
| -rw-r--r-- | spec/models/compliance_check_spec.rb | 14 |
6 files changed, 68 insertions, 2 deletions
diff --git a/app/models/compliance_check.rb b/app/models/compliance_check.rb index a9dbc4211..85cf5e37e 100644 --- a/app/models/compliance_check.rb +++ b/app/models/compliance_check.rb @@ -1,3 +1,9 @@ -class ComplianceCheck +class ComplianceCheck < ActiveRecord::Base + belongs_to :compliance_check_set + belongs_to :compliance_check_block + enum criticity: [:info, :warning, :error] + validates :criticity, presence: true + validates :name, presence: true + validates :code, presence: true end diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 00ec593de..faaa5ee81 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -50,6 +50,7 @@ Apartment.configure do |config| 'ComplianceControl', 'ComplianceControlSet', 'ComplianceControlBlock', + 'ComplianceCheck', 'ComplianceCheckSet', 'ComplianceCheckBlock' ] diff --git a/db/migrate/20170906084628_create_compliance_checks.rb b/db/migrate/20170906084628_create_compliance_checks.rb new file mode 100644 index 000000000..1d6bdaaf2 --- /dev/null +++ b/db/migrate/20170906084628_create_compliance_checks.rb @@ -0,0 +1,16 @@ +class CreateComplianceChecks < ActiveRecord::Migration + def change + create_table :compliance_checks do |t| + t.references :compliance_check_set, index: true, foreign_key: true + t.references :compliance_check_block, index: true, foreign_key: true + t.string :type + t.json :control_attributes + t.string :name + t.string :code + t.integer :criticity + t.text :comment + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 29887979f..1cc3692cf 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: 20170905135646) do +ActiveRecord::Schema.define(version: 20170906084628) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -172,6 +172,22 @@ ActiveRecord::Schema.define(version: 20170905135646) do add_index "compliance_check_sets", ["referential_id"], name: "index_compliance_check_sets_on_referential_id", using: :btree add_index "compliance_check_sets", ["workbench_id"], name: "index_compliance_check_sets_on_workbench_id", using: :btree + create_table "compliance_checks", id: :bigserial, force: :cascade do |t| + t.integer "compliance_check_set_id" + t.integer "compliance_check_block_id" + t.string "type" + t.json "control_attributes" + t.string "name" + t.string "code" + t.integer "criticity" + t.text "comment" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "compliance_checks", ["compliance_check_block_id"], name: "index_compliance_checks_on_compliance_check_block_id", using: :btree + add_index "compliance_checks", ["compliance_check_set_id"], name: "index_compliance_checks_on_compliance_check_set_id", using: :btree + create_table "compliance_control_blocks", id: :bigserial, force: :cascade do |t| t.string "name" t.hstore "condition_attributes" @@ -924,6 +940,8 @@ ActiveRecord::Schema.define(version: 20170905135646) do add_foreign_key "compliance_check_sets", "compliance_control_sets" add_foreign_key "compliance_check_sets", "referentials" add_foreign_key "compliance_check_sets", "workbenches" + add_foreign_key "compliance_checks", "compliance_check_blocks" + add_foreign_key "compliance_checks", "compliance_check_sets" add_foreign_key "compliance_control_blocks", "compliance_control_sets" add_foreign_key "compliance_control_sets", "organisations" add_foreign_key "compliance_controls", "compliance_control_blocks" diff --git a/spec/factories/compliance_checks.rb b/spec/factories/compliance_checks.rb new file mode 100644 index 000000000..4009653da --- /dev/null +++ b/spec/factories/compliance_checks.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :compliance_check do + sequence(:name) { |n| "Compliance check #{n}" } + type "Type" + criticity :info + code "code" + comment "Text" + association :compliance_check_set + association :compliance_check_block + end +end diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb new file mode 100644 index 000000000..4fbc23d42 --- /dev/null +++ b/spec/models/compliance_check_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe ComplianceCheck, type: :model do + it 'should have a valid factory' do + expect(FactoryGirl.build(:compliance_check)).to be_valid + end + + it { should belong_to :compliance_check_set } + it { should belong_to :compliance_check_block } + + it { should validate_presence_of :criticity } + it { should validate_presence_of :name } + it { should validate_presence_of :code } +end |
