aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Dober2017-10-16 09:27:27 +0200
committerGitHub2017-10-16 09:27:27 +0200
commit072564dc48524f0bcc28d16051ec730ac1872e5e (patch)
tree81f69b00184eb5d23f62d948384a5d78ab924547
parenta8da41521f5e45d2ab39ddd9b0269d8cd1094d35 (diff)
parentd9ef8415e1da99db258a5181bff16b213f8c231a (diff)
downloadchouette-core-072564dc48524f0bcc28d16051ec730ac1872e5e.tar.bz2
Merge pull request #93 from af83/4720-compliance-contorl-subclass-values
4720 compliance contorl subclass values
-rw-r--r--app/assets/stylesheets/components/_referential_suites.sass69
-rw-r--r--app/models/concerns/min_max_values_validation.rb13
-rw-r--r--app/models/generic_attribute_control/min_max.rb5
-rw-r--r--app/models/vehicle_journey_control/speed.rb1
-rw-r--r--config/locales/compliance_controls.en.yml1
-rw-r--r--config/locales/compliance_controls.fr.yml1
-rw-r--r--spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb8
-rw-r--r--spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb23
-rw-r--r--spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb8
-rw-r--r--spec/support/shared_examples/compliance_control_validation.rb43
10 files changed, 168 insertions, 4 deletions
diff --git a/app/assets/stylesheets/components/_referential_suites.sass b/app/assets/stylesheets/components/_referential_suites.sass
new file mode 100644
index 000000000..5e564ea8e
--- /dev/null
+++ b/app/assets/stylesheets/components/_referential_suites.sass
@@ -0,0 +1,69 @@
+table.calendar
+ display: table
+ width: 100%
+ table-layout: fixed
+ margin-bottom: 20px
+
+ th, td
+ border: 1px solid $darkgrey
+ text-align: center
+ padding: 0.35em 0.5em
+
+ th
+ padding: 0.5em
+
+ thead
+ tr
+ > th
+ border: none
+
+ &:first-child
+ text-transform: uppercase
+
+ tbody
+ tr > td
+ &.weekNumber
+ border: none
+ padding: 0.5em 0.5em 0.5em 0
+
+ &.outsideMonth
+ color: rgba($darkgrey, 0.35)
+
+ &.weekend
+ font-weight: bold
+
+ &.selected_period, &.selected_date, &.overlaped_date
+ > a
+ display: block
+ margin: 0 auto
+ width: 24px
+ height: 24px
+ line-height: 24px
+ color: $darkgrey
+ background-color: rgba($gold, 0.75)
+ border-radius: 50%
+
+ &:hover, &:focus
+ color: $darkgrey
+ text-decoration: none
+
+.col-xs-6
+ &:nth-child(2n +1)
+ clear: both
+
+.col-sm-4
+ @media (min-width: 768px)
+ &:nth-child(2n +1)
+ clear: none
+ &:nth-child(3n+1)
+ clear: both
+
+// .col-md-4
+// @media (min-width: 992px)
+
+.col-lg-3
+ @media (min-width: 1200px)
+ &:nth-child(2n +1), &:nth-child(3n+1)
+ clear: none
+ &:nth-child(4n+1)
+ clear: both
diff --git a/app/models/concerns/min_max_values_validation.rb b/app/models/concerns/min_max_values_validation.rb
new file mode 100644
index 000000000..c177e55ca
--- /dev/null
+++ b/app/models/concerns/min_max_values_validation.rb
@@ -0,0 +1,13 @@
+module MinMaxValuesValidation
+ extend ActiveSupport::Concern
+
+ included do
+ validate :min_max_values_validation
+ end
+
+ def min_max_values_validation
+ return true unless minimum && maximum
+ return true unless maximum < minimum
+ errors.add(:min_max_values, I18n.t('compliance_controls.min_max_values', min: minimum, max: maximum))
+ end
+end
diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb
index c46ba0453..1f75c2edb 100644
--- a/app/models/generic_attribute_control/min_max.rb
+++ b/app/models/generic_attribute_control/min_max.rb
@@ -5,10 +5,7 @@ module GenericAttributeControl
validates :minimum, numericality: true, allow_nil: true
validates :maximum, numericality: true, allow_nil: true
#validates :target, presence: true
- validate :min_max_values
- def min_max_values
- true
- end
+ include MinMaxValuesValidation
class << self
def attribute_type; :integer end
diff --git a/app/models/vehicle_journey_control/speed.rb b/app/models/vehicle_journey_control/speed.rb
index 099a46d1d..be9f838e4 100644
--- a/app/models/vehicle_journey_control/speed.rb
+++ b/app/models/vehicle_journey_control/speed.rb
@@ -4,6 +4,7 @@ module VehicleJourneyControl
validates :minimum, numericality: true, allow_nil: true
validates :maximum, numericality: true, allow_nil: true
+ include MinMaxValuesValidation
def self.default_code; "3-VehicleJourney-2" end
end
diff --git a/config/locales/compliance_controls.en.yml b/config/locales/compliance_controls.en.yml
index cee83afee..02235be33 100644
--- a/config/locales/compliance_controls.en.yml
+++ b/config/locales/compliance_controls.en.yml
@@ -1,5 +1,6 @@
en:
compliance_controls:
+ min_max_values: "the minimum (%{min}) is not supposed to be greater than the maximum (%{max})"
errors:
incoherent_control_sets: "Impossible to assign a control to a set (id: %{direct_set_name}) differing from the one of its group (id: %{indirect_set_name})"
show:
diff --git a/config/locales/compliance_controls.fr.yml b/config/locales/compliance_controls.fr.yml
index 1f60e0fbc..ce9d15cab 100644
--- a/config/locales/compliance_controls.fr.yml
+++ b/config/locales/compliance_controls.fr.yml
@@ -1,5 +1,6 @@
fr:
compliance_controls:
+ min_max_values: "la valeur de minimum (%{min}) ne doit pas être superieur à la valuer du maximum (%{max})"
errors:
incoherent_control_sets: "Le contrôle ne peut pas être associé à un jeu de contrôle (id: %{direct_set_name}) différent de celui de son groupe (id: %{indirect_set_name})"
mandatory_control_type: "Un type de contrôle doit être sélectionné"
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
new file mode 100644
index 000000000..276d09a92
--- /dev/null
+++ b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb
@@ -0,0 +1,8 @@
+# RSpec.describe GenericAttributeControl::MinMax do
+
+# let( :factory ){ :generic_attribute_control_min_max }
+# subject{ build factory }
+
+# it_behaves_like 'has min_max_values'
+
+# end
diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb
new file mode 100644
index 000000000..2a1d8cf5c
--- /dev/null
+++ b/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb
@@ -0,0 +1,23 @@
+RSpec.describe GenericAttributeControl::Pattern do
+
+ let( :factory ){ :generic_attribute_control_pattern }
+ subject{ build factory }
+
+ context "is valid" do
+ it 'if the pattern contains a basic regex' do
+ subject.pattern = 'hel+o?'
+ expect_it.to be_valid
+ end
+ end
+
+ context "is invalid" do
+ it 'if no pattern has been provided' do
+ expect_it.not_to be_valid
+ end
+ it 'if the pattern is empty' do
+ subject.pattern = ' '
+ expect_it.not_to be_valid
+ end
+
+ end
+end
diff --git a/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb b/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb
new file mode 100644
index 000000000..88316ab37
--- /dev/null
+++ b/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb
@@ -0,0 +1,8 @@
+RSpec.describe VehicleJourneyControl::Speed do
+
+ let( :factory ){ :vehicle_journey_control_speed }
+ subject{ build factory }
+
+ it_behaves_like 'has min_max_values'
+
+end
diff --git a/spec/support/shared_examples/compliance_control_validation.rb b/spec/support/shared_examples/compliance_control_validation.rb
new file mode 100644
index 000000000..d4ab9f41d
--- /dev/null
+++ b/spec/support/shared_examples/compliance_control_validation.rb
@@ -0,0 +1,43 @@
+RSpec.shared_examples_for 'has min_max_values' do
+
+ context "is valid" do
+ it 'if no value is provided' do
+ expect_it.to be_valid
+ end
+ it 'if minimum is provided alone' do
+ subject.minimum = 42
+ expect_it.to be_valid
+ end
+ it 'if maximum is provided alone' do
+ subject.maximum = 42
+ expect_it.to be_valid
+ end
+
+ it 'if maximum is not smaller than minimum' do
+ 100.times do
+ min = random_int
+ max = min + random_int(20)
+ subject.assign_attributes maximum: max, minimum: min
+ subject.assign_attributes maximum: min, minimum: min
+ expect_it.to be_valid
+ end
+ end
+ end
+
+ context "is invalid" do
+ it 'if maximum is smaller than minimum' do
+ 100.times do
+ min = random_int
+ max = min - random_int(20) - 1
+ subject.assign_attributes maximum: max, minimum: min
+ expect_it.not_to be_valid
+ end
+ end
+
+ it 'and has a correct error message' do
+ subject.assign_attributes maximum: 1, minimum: 2
+ expect_it.not_to be_valid
+ expect( subject.errors.messages[:min_max_values].first ).to match("la valeur de minimum (2) ne doit pas être superieur à la valuer du maximum (1)")
+ end
+ end
+end