aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock3
-rw-r--r--app/models/compliance_check_block.rb6
-rw-r--r--app/models/compliance_control.rb3
-rw-r--r--app/models/compliance_control_block.rb6
-rw-r--r--app/models/generic_attribute_control/min_max.rb2
-rw-r--r--app/models/generic_attribute_control/pattern.rb2
-rw-r--r--app/models/generic_attribute_control/uniqueness.rb2
-rw-r--r--app/models/vehicle_journey_control/delta.rb2
-rw-r--r--app/models/vehicle_journey_control/speed.rb2
-rw-r--r--app/models/vehicle_journey_control/waiting_time.rb2
-rw-r--r--db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb33
-rw-r--r--db/schema.rb4
-rw-r--r--spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb3
-rw-r--r--spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb1
-rw-r--r--spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb1
-rw-r--r--spec/support/shared_examples/compliance_control_validation.rb10
17 files changed, 63 insertions, 20 deletions
diff --git a/Gemfile b/Gemfile
index 898293ac5..ed71f8bb5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -127,7 +127,6 @@ gem 'acts-as-taggable-on', '~> 4.0.0'
gem 'acts_as_list', '~> 0.6.0'
gem 'acts_as_tree', '~> 2.1.0', require: 'acts_as_tree'
-gem "hstore_accessor", "~> 1.1"
gem 'rabl'
gem 'carrierwave', '~> 1.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 27d3c18eb..9c59016e6 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -254,8 +254,6 @@ GEM
hashdiff (0.3.4)
highline (1.7.8)
hike (1.2.3)
- hstore_accessor (1.1.0)
- activerecord (>= 4.0.0)
htmlbeautifier (1.3.1)
httparty (0.14.0)
multi_xml (>= 0.5.2)
@@ -614,7 +612,6 @@ DEPENDENCIES
google-analytics-rails
gretel
has_array_of!
- hstore_accessor (~> 1.1)
htmlbeautifier
i18n-tasks
inherited_resources
diff --git a/app/models/compliance_check_block.rb b/app/models/compliance_check_block.rb
index 05240b428..059547e1b 100644
--- a/app/models/compliance_check_block.rb
+++ b/app/models/compliance_check_block.rb
@@ -6,8 +6,8 @@ class ComplianceCheckBlock < ActiveRecord::Base
has_many :compliance_checks
- hstore_accessor :condition_attributes,
- transport_mode: :string,
- transport_submode: :string
+ store_accessor :condition_attributes,
+ :transport_mode,
+ :transport_submode
end
diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb
index 65e22643d..3fcf26f5d 100644
--- a/app/models/compliance_control.rb
+++ b/app/models/compliance_control.rb
@@ -6,7 +6,7 @@ class ComplianceControl < ActiveRecord::Base
def prerequisite; I18n.t('compliance_controls.metas.no_prerequisite'); end
def predicate; I18n.t("compliance_controls.#{self.name.underscore}.description") end
def dynamic_attributes
- hstore_metadata_for_control_attributes.keys
+ stored_attributes[:control_attributes]
end
def policy_class
@@ -39,7 +39,6 @@ class ComplianceControl < ActiveRecord::Base
belongs_to :compliance_control_block
enumerize :criticity, in: criticities, scope: true, default: :warning
- hstore_accessor :control_attributes, {}
validates :criticity, presence: true
validates :name, presence: true
diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb
index e27f85ae0..d7d84fd06 100644
--- a/app/models/compliance_control_block.rb
+++ b/app/models/compliance_control_block.rb
@@ -5,9 +5,9 @@ class ComplianceControlBlock < ActiveRecord::Base
belongs_to :compliance_control_set
has_many :compliance_controls, dependent: :destroy
- hstore_accessor :condition_attributes,
- transport_mode: :string,
- transport_submode: :string
+ store_accessor :condition_attributes,
+ :transport_mode,
+ :transport_submode
validates :transport_mode, presence: true
validates :compliance_control_set, presence: true
diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb
index ab6f546a7..1c429b9a4 100644
--- a/app/models/generic_attribute_control/min_max.rb
+++ b/app/models/generic_attribute_control/min_max.rb
@@ -1,6 +1,6 @@
module GenericAttributeControl
class MinMax < ComplianceControl
- hstore_accessor :control_attributes, minimum: :integer, maximum: :integer, target: :string
+ store_accessor :control_attributes, :minimum, :maximum, :target
validates :minimum, numericality: true, allow_nil: true
validates :maximum, numericality: true, allow_nil: true
diff --git a/app/models/generic_attribute_control/pattern.rb b/app/models/generic_attribute_control/pattern.rb
index 3a4a55d5c..7fc008e28 100644
--- a/app/models/generic_attribute_control/pattern.rb
+++ b/app/models/generic_attribute_control/pattern.rb
@@ -1,6 +1,6 @@
module GenericAttributeControl
class Pattern < ComplianceControl
- hstore_accessor :control_attributes, pattern: :string, target: :string
+ store_accessor :control_attributes, :pattern, :target
validates :target, presence: true
validates :pattern, presence: true
diff --git a/app/models/generic_attribute_control/uniqueness.rb b/app/models/generic_attribute_control/uniqueness.rb
index f707c944b..82b5c0892 100644
--- a/app/models/generic_attribute_control/uniqueness.rb
+++ b/app/models/generic_attribute_control/uniqueness.rb
@@ -1,6 +1,6 @@
module GenericAttributeControl
class Uniqueness < ComplianceControl
- hstore_accessor :control_attributes, target: :string
+ store_accessor :control_attributes, :target
validates :target, presence: true
diff --git a/app/models/vehicle_journey_control/delta.rb b/app/models/vehicle_journey_control/delta.rb
index 1f3a4d492..077dd6c4a 100644
--- a/app/models/vehicle_journey_control/delta.rb
+++ b/app/models/vehicle_journey_control/delta.rb
@@ -1,7 +1,7 @@
module VehicleJourneyControl
class Delta < ComplianceControl
- hstore_accessor :control_attributes, maximum: :integer
+ store_accessor :control_attributes, :maximum
validates :maximum, numericality: true, allow_nil: true
diff --git a/app/models/vehicle_journey_control/speed.rb b/app/models/vehicle_journey_control/speed.rb
index be9f838e4..14fad9139 100644
--- a/app/models/vehicle_journey_control/speed.rb
+++ b/app/models/vehicle_journey_control/speed.rb
@@ -1,6 +1,6 @@
module VehicleJourneyControl
class Speed < ComplianceControl
- hstore_accessor :control_attributes, minimum: :integer, maximum: :integer
+ store_accessor :control_attributes, :minimum, :maximum
validates :minimum, numericality: true, allow_nil: true
validates :maximum, numericality: true, allow_nil: true
diff --git a/app/models/vehicle_journey_control/waiting_time.rb b/app/models/vehicle_journey_control/waiting_time.rb
index 68fccb5c1..252135f04 100644
--- a/app/models/vehicle_journey_control/waiting_time.rb
+++ b/app/models/vehicle_journey_control/waiting_time.rb
@@ -1,6 +1,6 @@
module VehicleJourneyControl
class WaitingTime < ComplianceControl
- hstore_accessor :control_attributes, maximum: :integer
+ store_accessor :control_attributes, :maximum
validates :maximum, numericality: true, allow_nil: true
diff --git a/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb b/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb
new file mode 100644
index 000000000..0576dddf2
--- /dev/null
+++ b/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb
@@ -0,0 +1,33 @@
+class ChangeComplianceControlComplianceCheckControlAttributesFormatFromHstoreToJson < ActiveRecord::Migration
+ def up
+ change_column :compliance_controls,
+ :control_attributes,
+ 'json USING hstore_to_json(control_attributes)'
+ change_column :compliance_checks,
+ :control_attributes,
+ 'json USING hstore_to_json(control_attributes)'
+ end
+
+ def down
+ execute <<-SQL
+ CREATE OR REPLACE FUNCTION my_json_to_hstore(json)
+ RETURNS hstore
+ IMMUTABLE
+ STRICT
+ LANGUAGE sql
+ AS $func$
+ SELECT hstore(array_agg(key), array_agg(value))
+ FROM json_each_text($1)
+ $func$;
+ SQL
+
+ change_column :compliance_controls,
+ :control_attributes,
+ 'hstore USING my_json_to_hstore(control_attributes)'
+ change_column :compliance_checks,
+ :control_attributes,
+ 'hstore USING my_json_to_hstore(control_attributes)'
+
+ execute "DROP FUNCTION my_json_to_hstore(json)"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 81966575b..182df3159 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -208,7 +208,7 @@ ActiveRecord::Schema.define(version: 20171220164059) do
t.integer "compliance_check_set_id", limit: 8
t.integer "compliance_check_block_id", limit: 8
t.string "type"
- t.hstore "control_attributes"
+ t.json "control_attributes"
t.string "name"
t.string "code"
t.string "criticity"
@@ -243,7 +243,7 @@ ActiveRecord::Schema.define(version: 20171220164059) do
create_table "compliance_controls", id: :bigserial, force: :cascade do |t|
t.integer "compliance_control_set_id", limit: 8
t.string "type"
- t.hstore "control_attributes"
+ t.json "control_attributes"
t.string "name"
t.string "code"
t.string "criticity"
diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb
index 9610cc796..90bb660ee 100644
--- a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb
+++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb
@@ -4,4 +4,7 @@ RSpec.describe GenericAttributeControl::Pattern, type: :model do
let( :factory ){ :generic_attribute_control_pattern }
it_behaves_like 'ComplianceControl Class Level Defaults'
+ it_behaves_like 'has target attribute'
+
+ it { should validate_presence_of(:pattern) }
end
diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb
index e4ab8d2cd..c4874b5a2 100644
--- a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb
+++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb
@@ -4,4 +4,5 @@ RSpec.describe GenericAttributeControl::Uniqueness, type: :model do
let( :factory ){ :generic_attribute_control_uniqueness }
it_behaves_like 'ComplianceControl Class Level Defaults'
+ it_behaves_like 'has target attribute'
end
diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb
index 4d30d61e3..138f7aae1 100644
--- a/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb
+++ b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb
@@ -4,5 +4,6 @@ RSpec.describe GenericAttributeControl::MinMax do
subject{ build factory }
it_behaves_like 'has min_max_values'
+ it_behaves_like 'has target attribute'
end
diff --git a/spec/support/shared_examples/compliance_control_validation.rb b/spec/support/shared_examples/compliance_control_validation.rb
index d4ab9f41d..c76712c4c 100644
--- a/spec/support/shared_examples/compliance_control_validation.rb
+++ b/spec/support/shared_examples/compliance_control_validation.rb
@@ -1,6 +1,9 @@
RSpec.shared_examples_for 'has min_max_values' do
context "is valid" do
+ it { should validate_numericality_of(:minimum) }
+ it { should validate_numericality_of(:maximum) }
+
it 'if no value is provided' do
expect_it.to be_valid
end
@@ -41,3 +44,10 @@ RSpec.shared_examples_for 'has min_max_values' do
end
end
end
+
+
+RSpec.shared_examples_for "has target attribute" do
+ context "is valid" do
+ it { should validate_presence_of(:target) }
+ end
+end