aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-02-27 16:30:40 +0100
committerZog2018-02-27 16:30:40 +0100
commitff9f6fa9674a4a50da480b550611cd1ce9d84c23 (patch)
tree9666c7d989709b43dfe56822062f5256a5521fa9
parent0a91ae5d80e476f967160e1987cc7e63beabea94 (diff)
downloadchouette-core-ff9f6fa9674a4a50da480b550611cd1ce9d84c23.tar.bz2
refs #5878; Remove hard link between a ComplianceCheck and the associated ComplianceControl
-rw-r--r--app/models/compliance_check.rb6
-rw-r--r--app/models/compliance_control.rb4
-rw-r--r--db/migrate/20180227151937_add_compliance_control_name_to_compliance_checks.rb5
-rw-r--r--db/schema.rb9
-rw-r--r--lib/compliance_control_set_copier.rb5
5 files changed, 20 insertions, 9 deletions
diff --git a/app/models/compliance_check.rb b/app/models/compliance_check.rb
index 71cb9aef2..fda95ea08 100644
--- a/app/models/compliance_check.rb
+++ b/app/models/compliance_check.rb
@@ -13,10 +13,10 @@ class ComplianceCheck < ActiveRecord::Base
validates :code, presence: true
validates :origin_code, presence: true
- def control
- ComplianceControl.find_by! origin_code: origin_code
+ def control_class
+ compliance_control_name.present? ? compliance_control_name.constantize : nil
end
- delegate :predicate, to: :control
+ delegate :predicate, to: :control_class, allow_nil: true
end
diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb
index 45f886005..7cd9ba933 100644
--- a/app/models/compliance_control.rb
+++ b/app/models/compliance_control.rb
@@ -28,6 +28,8 @@ class ComplianceControl < ActiveRecord::Base
end
super
end
+
+ def predicate; I18n.t("compliance_controls.#{self.name.underscore}.description") end
end
extend Enumerize
@@ -60,7 +62,7 @@ class ComplianceControl < ActiveRecord::Base
self.origin_code ||= self.class.default_code
end
- def predicate; I18n.t("compliance_controls.#{self.class.name.underscore}.description") end
+ def predicate; self.class.predicate end
end
diff --git a/db/migrate/20180227151937_add_compliance_control_name_to_compliance_checks.rb b/db/migrate/20180227151937_add_compliance_control_name_to_compliance_checks.rb
new file mode 100644
index 000000000..49ab0da11
--- /dev/null
+++ b/db/migrate/20180227151937_add_compliance_control_name_to_compliance_checks.rb
@@ -0,0 +1,5 @@
+class AddComplianceControlNameToComplianceChecks < ActiveRecord::Migration
+ def change
+ add_column :compliance_checks, :compliance_control_name, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c709290f5..450d2ce5d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,13 +11,14 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180202170009) do
+ActiveRecord::Schema.define(version: 20180227151937) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "hstore"
enable_extension "postgis"
enable_extension "unaccent"
+ enable_extension "objectid"
create_table "access_links", id: :bigserial, force: :cascade do |t|
t.integer "access_point_id", limit: 8
@@ -90,9 +91,9 @@ ActiveRecord::Schema.define(version: 20180202170009) do
t.integer "organisation_id", limit: 8
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "workgroup_id", limit: 8
t.integer "int_day_types"
t.date "excluded_dates", array: true
+ t.integer "workgroup_id", limit: 8
end
add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree
@@ -221,6 +222,7 @@ ActiveRecord::Schema.define(version: 20180202170009) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "origin_code"
+ t.string "compliance_control_name"
end
add_index "compliance_checks", ["compliance_check_block_id"], name: "index_compliance_checks_on_compliance_check_block_id", using: :btree
@@ -421,9 +423,9 @@ ActiveRecord::Schema.define(version: 20180202170009) do
t.string "type"
t.integer "parent_id", limit: 8
t.string "parent_type"
+ t.datetime "notified_parent_at"
t.integer "current_step", default: 0
t.integer "total_steps", default: 0
- t.datetime "notified_parent_at"
t.string "creator"
end
@@ -765,6 +767,7 @@ ActiveRecord::Schema.define(version: 20180202170009) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "objectid_format"
+ t.string "registration_number_format"
end
create_table "stop_areas", id: :bigserial, force: :cascade do |t|
diff --git a/lib/compliance_control_set_copier.rb b/lib/compliance_control_set_copier.rb
index 58d40cdbf..06622f302 100644
--- a/lib/compliance_control_set_copier.rb
+++ b/lib/compliance_control_set_copier.rb
@@ -21,7 +21,7 @@ class ComplianceControlSetCopier
# Workers
# -------
def check_organisation_coherence!
- return true if cc_set.organisation_id == referential.organisation_id
+ return true if cc_set.organisation_id == referential.organisation_id
raise ArgumentError, "Incoherent organisation of referential"
end
@@ -66,7 +66,8 @@ class ComplianceControlSetCopier
name: name_with_refid(compliance_control.name),
comment: compliance_control.comment,
code: compliance_control.code,
- origin_code: compliance_control.origin_code
+ origin_code: compliance_control.origin_code,
+ compliance_control_name: compliance_control.class.name
).tap do | compliance_check |
control_id_to_check.update compliance_control.id => compliance_check
end