From 65d8e948adbb12312d2b9902d38ae2298d679e6f Mon Sep 17 00:00:00 2001
From: Henk <henk.van.der.veen@gmail.com>
Date: Mon, 30 Nov 2020 10:05:50 +0100
Subject: [PATCH] change depend_on to array

---
 lib/quby/compiler/entities/flag.rb                 | 4 ++--
 lib/quby/compiler/services/definition_validator.rb | 4 ++--
 spec/quby/compiler/entities/flag_spec.rb           | 6 ++++++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/quby/compiler/entities/flag.rb b/lib/quby/compiler/entities/flag.rb
index fd05fb2..479b0eb 100644
--- a/lib/quby/compiler/entities/flag.rb
+++ b/lib/quby/compiler/entities/flag.rb
@@ -14,11 +14,11 @@ module Quby
                        trigger_on: true,
                        shows_questions: [],
                        hides_questions: [],
-                       depends_on: nil, # used in interface to hide this flag unless the depended on flag is set to true
+                       depends_on: [], # used in interface to hide this flag unless the depended on flag is set to true
                        default_in_interface: nil) # used in interface to set a default for the flag state,
                                                   # does not have an effect outside of the interface
           super(key, description_true, description_false, description, internal, trigger_on, shows_questions,
-                hides_questions, depends_on, default_in_interface)
+                hides_questions, Array.wrap(depends_on).map(&:to_s), default_in_interface)
           ensure_valid_descriptions
         end
         # rubocop:enable ParameterLists
diff --git a/lib/quby/compiler/services/definition_validator.rb b/lib/quby/compiler/services/definition_validator.rb
index 16b295a..d3a39e6 100644
--- a/lib/quby/compiler/services/definition_validator.rb
+++ b/lib/quby/compiler/services/definition_validator.rb
@@ -131,9 +131,9 @@ module Quby
         end
 
         def validate_flag_depends_on(questionnaire, flag)
-          return if flag.depends_on.blank? || questionnaire.flags.key?(flag.depends_on)
+          return if (missing = flag.depends_on - questionnaire.flags.keys).blank?
 
-          fail ArgumentError, "Flag #{flag.key} depends_on nonexistent flag '#{flag.depends_on}'"
+          fail ArgumentError, "Flag #{flag.key} depends_on nonexistent flag '#{missing.to_sentence}'"
         end
 
         def validate_respondent_types(questionnaire)
diff --git a/spec/quby/compiler/entities/flag_spec.rb b/spec/quby/compiler/entities/flag_spec.rb
index 99e3c28..90cdbe9 100644
--- a/spec/quby/compiler/entities/flag_spec.rb
+++ b/spec/quby/compiler/entities/flag_spec.rb
@@ -47,5 +47,11 @@ module Quby::Compiler::Entities
         expect(flag.variable_description).to eq("test flag (true - 'flag is true', false - 'flag is false')")
       end
     end
+
+    # we only set through the initializer.
+    it 'transforms depends_on into an array of string' do
+      flag = described_class.new key: :foo, description: 'foo', depends_on: :bar
+      expect(flag.depends_on).to eq ['bar']
+    end
   end
 end
-- 
GitLab