aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
authorRobert2017-10-13 18:17:00 +0200
committerRobert2017-10-16 07:50:34 +0200
commit9dd7b4d050b64b6fcaebb2cd3f635593a0cb34c3 (patch)
treed20fb589df06d01e46fa8ef4c5313c8cdc7aff94 /spec/support
parentc266ee913353d67a3674ed6188c2ff96b44407c1 (diff)
downloadchouette-core-9dd7b4d050b64b6fcaebb2cd3f635593a0cb34c3.tar.bz2
Refs: #4720@1.3h;
Validation implemented for min_max_values with correct I18n'd error messages Applied to: VehicleJourneyControl::Speed & GenericAttributeControl::MinMax
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared_examples/compliance_control_validation.rb43
1 files changed, 43 insertions, 0 deletions
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