diff options
| author | Teddy Wing | 2017-12-19 16:35:09 +0100 |
|---|---|---|
| committer | Teddy Wing | 2017-12-19 16:46:34 +0100 |
| commit | c67e855f1bea867c75aff193b7d61561e55cbeaa (patch) | |
| tree | 91fef99cf7646fad77442cc512e8d538ac799132 /app | |
| parent | dd70f15fef475fa1abc627244af22e843959bedc (diff) | |
| download | chouette-core-c67e855f1bea867c75aff193b7d61561e55cbeaa.tar.bz2 | |
Remove `hstore_accessor` usage
The places we were using `hstore_accessor` have now been converted to
Postgres JSON fields. Thus we no longer need `hstore_accessor` in order
to add accessors for the fields.
Instead we can use Rails' built-in support for Postgres JSON fields and
create accessors for our JSON hash keys with `store_accessor`. We get
rid of the data types because `store_accessor` doesn't work like that
and JSON already types our values with primitive data types.
Finally, add some extra validation tests now that the vaildation for our
JSON fields should work.
Refs #5316
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/compliance_check_block.rb | 6 | ||||
| -rw-r--r-- | app/models/compliance_control.rb | 1 | ||||
| -rw-r--r-- | app/models/compliance_control_block.rb | 6 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/min_max.rb | 2 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/pattern.rb | 2 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/uniqueness.rb | 2 | ||||
| -rw-r--r-- | app/models/vehicle_journey_control/delta.rb | 2 | ||||
| -rw-r--r-- | app/models/vehicle_journey_control/speed.rb | 2 | ||||
| -rw-r--r-- | app/models/vehicle_journey_control/waiting_time.rb | 2 |
9 files changed, 12 insertions, 13 deletions
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..847e3a253 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -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 |
