spec/factories/forms.rb
# TODO: Should be a way to refactor this to be part of the questioning factory.
Should be a way to refactor this to be part of the questioning factory.
Should be a way to refactor this to be part of the questioning factory .
def create_questioning(qtype_name_or_question, form, attribs = {})
  attribs[:parent] ||= form.root_group
  evaluator = attribs.delete(:evaluator)
  question = if qtype_name_or_question.is_a?(Question)
               qtype_name_or_question
             else
               pseudo_qtype_name = qtype_name_or_question
               q_attribs = {
                 mission: form.mission,
                 use_geo_option_set: pseudo_qtype_name.match?(/geo/),
                 multilingual: pseudo_qtype_name.match?(/multilingual/),
                 with_user_locale: pseudo_qtype_name.match?(/with_user_locale/),
                 auto_increment: pseudo_qtype_name == "counter_with_inc",
                 metadata_type: %w[formstart formend].include?(pseudo_qtype_name) ? pseudo_qtype_name : nil
               }
               if evaluator.try(:option_set)
                 q_attribs[:option_set] = evaluator.option_set
               elsif evaluator.try(:option_names)
                 q_attribs[:option_names] = evaluator.option_names
               end
               q_attribs[:qtype_name] =
                 case pseudo_qtype_name
                 when "select_one_as_text_for_sms", "select_one_with_appendix_for_sms", "geo_select_one",
                   "multilevel_select_one", "geo_multilevel_select_one", "large_select_one",
                   "super_multilevel_select_one", "multilevel_select_one_as_text_for_sms"
                   "select_one"
                 when "select_multiple_with_appendix_for_sms", "large_select_multiple"
                   "select_multiple"
                 when "multilingual_text", "multilingual_text_with_user_locale"
                   "text"
                 when "counter_with_inc"
                   "counter"
                 when "formstart", "formend"
                   "datetime"
                 else
                   pseudo_qtype_name
                 end
               preset_opt_sets_qtypes = %w[geo_select_one multilevel_select_one geo_multilevel_select_one
                                           large_select_one super_multilevel_select_one
                                           multilevel_select_one_as_text_for_sms large_select_multiple]
               if preset_opt_sets_qtypes.include?(pseudo_qtype_name)
                 q_attribs[:option_names] = pseudo_qtype_name.match(/(.+)_select_/)[1].to_sym
               end
               question = build(:question, q_attribs)
               if pseudo_qtype_name.match?(/as_text_for_sms/)
                 question.option_set.sms_guide_formatting = "treat_as_text"
               end
               if pseudo_qtype_name.match?(/with_appendix_for_sms/)
                 question.option_set.sms_guide_formatting = "appendix"
               end
               question
             end
  attribs[:mission] = form.mission
  attribs[:form] = form
  attribs[:question] = question
  create(:questioning, attribs)
end
def create_questioning ( qtype_name_or_question , form , attribs = { } ) attribs [ :parent ] ||= form . root_group evaluator = attribs . delete ( :evaluator ) question = if qtype_name_or_question . is_a? ( Question ) qtype_name_or_question else pseudo_qtype_name = qtype_name_or_question q_attribs = { mission : form . mission , use_geo_option_set : pseudo_qtype_name . match? ( / geo / ) , multilingual : pseudo_qtype_name . match? ( / multilingual / ) , with_user_locale : pseudo_qtype_name . match? ( / with_user_locale / ) , auto_increment : pseudo_qtype_name == "counter_with_inc" , metadata_type : %w[ formstart formend ] . include? ( pseudo_qtype_name ) ? pseudo_qtype_name : nil } if evaluator . try ( :option_set ) q_attribs [ :option_set ] = evaluator . option_set elsif evaluator . try ( :option_names ) q_attribs [ :option_names ] = evaluator . option_names end q_attribs [ :qtype_name ] = case pseudo_qtype_name when "select_one_as_text_for_sms" , "select_one_with_appendix_for_sms" , "geo_select_one" , "multilevel_select_one" , "geo_multilevel_select_one" , "large_select_one" , "super_multilevel_select_one" , "multilevel_select_one_as_text_for_sms" "select_one" when "select_multiple_with_appendix_for_sms" , "large_select_multiple" "select_multiple" when "multilingual_text" , "multilingual_text_with_user_locale" "text" when "counter_with_inc" "counter" when "formstart" , "formend" "datetime" else pseudo_qtype_name end preset_opt_sets_qtypes = %w[ geo_select_one multilevel_select_one geo_multilevel_select_one large_select_one super_multilevel_select_one multilevel_select_one_as_text_for_sms large_select_multiple ] if preset_opt_sets_qtypes . include? ( pseudo_qtype_name ) q_attribs [ :option_names ] = pseudo_qtype_name . match ( / (.+)_select_ / ) [ 1 ] . to_sym end question = build ( :question , q_attribs ) if pseudo_qtype_name . match? ( / as_text_for_sms / ) question . option_set . sms_guide_formatting = "treat_as_text" end if pseudo_qtype_name . match? ( / with_appendix_for_sms / ) question . option_set . sms_guide_formatting = "appendix" end question end attribs [ :mission ] = form . mission attribs [ :form ] = form attribs [ :question ] = question create ( :questioning , attribs ) end
TODO: Should be a way to refactor this to be part of the questioning factory.
TODO : Should be a way to refactor this to be part of the questioning factory .
qtype_name_or_question
<not_specific>
form
<not_specific>
attribs
<not_specific>