lib/quby/compiler/services/definition_validator.rb in quby-compiler-0.3.3 vs lib/quby/compiler/services/definition_validator.rb in quby-compiler-0.3.4

- old
+ new

@@ -23,11 +23,10 @@ validate_flags(questionnaire) validate_respondent_types(questionnaire) validate_outcome_tables(questionnaire) validate_markdown_fields(questionnaire) if questionnaire.validate_html validate_raw_content_items(questionnaire) if questionnaire.validate_html - validate_scores(questionnaire) # Some compilation errors are Exceptions (pure syntax errors) and some StandardErrors (NameErrors) rescue Exception => exception # rubocop:disable Lint/RescueException definition.errors.add(:sourcecode, {message: "Questionnaire error: #{definition.key}\n" \ "#{exception.message}", backtrace: exception.backtrace[0..20]}) @@ -79,10 +78,17 @@ score_schema = questionnaire.score_schemas[score.key] fail "Score #{score.key} does not have a score schema" unless score_schema fail "Score label langer dan 100 tekens (geeft problemen oru accare)\n #{score_schema.label}" if score_schema.label&.length > 100 end + + export_keys = questionnaire.score_schemas.flat_map { |_key, score_schema| + score_schema.subscore_schemas.map(&:export_key) + } + + duplicate_export_keys = export_keys.tally.select { |key, count| count > 1 }.keys + fail "Score export keys not unique, duplicates: #{duplicate_export_keys}" if duplicate_export_keys.present? end def validate_question_options(questionnaire, question) question.options.each do |option| msg_base = "Question #{option.question.key} option #{option.key}" @@ -239,11 +245,9 @@ end end def validate_score_label_present(score) fail "Score #{score.key} label must be passed in as an option." unless score.label.present? - - end def validate_subquestion_absence_in_select(question) return unless question.type == :select question.options.each do |option|