aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/compliance_check_set.rb10
-rw-r--r--db/migrate/20170905130413_create_compliance_check_sets.rb14
-rw-r--r--db/schema.rb22
-rw-r--r--spec/factories/compliance_check_sets.rb8
-rw-r--r--spec/models/compliance_check_set_spec.rb12
5 files changed, 65 insertions, 1 deletions
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
new file mode 100644
index 000000000..7b6400a21
--- /dev/null
+++ b/app/models/compliance_check_set.rb
@@ -0,0 +1,10 @@
+class ComplianceCheckSet < ActiveRecord::Base
+ extend Enumerize
+
+ belongs_to :referential
+ belongs_to :compliance_control_set
+ belongs_to :workbench
+ belongs_to :parent, polymorphic: true
+
+ enumerize :status, in: %w[new pending successful warning failed running aborted canceled]
+end
diff --git a/db/migrate/20170905130413_create_compliance_check_sets.rb b/db/migrate/20170905130413_create_compliance_check_sets.rb
new file mode 100644
index 000000000..21055a3f2
--- /dev/null
+++ b/db/migrate/20170905130413_create_compliance_check_sets.rb
@@ -0,0 +1,14 @@
+class CreateComplianceCheckSets < ActiveRecord::Migration
+ def change
+ create_table :compliance_check_sets do |t|
+ t.references :referential, index: true, foreign_key: true
+ t.references :compliance_control_set, index: true, foreign_key: true
+ t.references :workbench, index: true, foreign_key: true
+ t.string :creator
+ t.string :status
+ t.references :parent, polymorphic: true, index: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index df887f277..dad05b449 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: 20170905123421) do
+ActiveRecord::Schema.define(version: 20170905130413) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -145,6 +145,23 @@ ActiveRecord::Schema.define(version: 20170905123421) do
add_index "companies", ["objectid"], name: "companies_objectid_key", unique: true, using: :btree
add_index "companies", ["registration_number"], name: "companies_registration_number_key", using: :btree
+ create_table "compliance_check_sets", id: :bigserial, force: :cascade do |t|
+ t.integer "referential_id"
+ t.integer "compliance_control_set_id"
+ t.integer "workbench_id"
+ t.string "creator"
+ t.string "status"
+ t.integer "parent_id"
+ t.string "parent_type"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "compliance_check_sets", ["compliance_control_set_id"], name: "index_compliance_check_sets_on_compliance_control_set_id", using: :btree
+ add_index "compliance_check_sets", ["parent_type", "parent_id"], name: "index_compliance_check_sets_on_parent_type_and_parent_id", using: :btree
+ 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_control_blocks", id: :bigserial, force: :cascade do |t|
t.string "name"
t.hstore "condition_attributes"
@@ -893,6 +910,9 @@ ActiveRecord::Schema.define(version: 20170905123421) do
add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey"
add_foreign_key "api_keys", "organisations"
+ 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_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_check_sets.rb b/spec/factories/compliance_check_sets.rb
new file mode 100644
index 000000000..d16f19845
--- /dev/null
+++ b/spec/factories/compliance_check_sets.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :compliance_check_set do
+ status :new
+ referential
+ compliance_control_set
+ workbench
+ end
+end
diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb
new file mode 100644
index 000000000..6e53c9def
--- /dev/null
+++ b/spec/models/compliance_check_set_spec.rb
@@ -0,0 +1,12 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckSet, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check_set)).to be_valid
+ end
+
+ it { should belong_to :referential }
+ it { should belong_to :workbench }
+ it { should belong_to :compliance_control_set }
+ it { should belong_to :parent }
+end