namespace :data do
  task :load_test, [:user_email] => :environment do |_t, args|
    user = User.find_by(email: args.user_email)
    if user.nil?
      STDERR.puts "Unable to find user #{args.user_email}"
      exit(-1)
    end

    rs = ResponseSet.new(created_by: user, status: 'draft',
                         name: '30 Code Response Set')
    responses = []
    30.times do |i|
      r = Response.new(value: "code-#{i}", code_system: 'test',
                       display_name: "Code #{i}")
      responses << r
    end
    rs.responses = responses
    rs.save!

    form = Form.new(name: '500 Question Form', created_by: user, status: 'draft')
    500.times do |i|
      position = i + 1
      q = Question.create(content: "Is your favorite number #{position}?",
                          created_by: user, status: 'draft')
      fq = FormQuestion.new(question: q, position: position)
      form.form_questions << fq
    end
    form.save!
  end
end

namespace :data do
  task :load_test, [:user_email] => :environment do |_t, args|
    user = User.find_by(email: args.user_email)
    if user.nil?
      STDERR.puts "Unable to find user #{args.user_email}"
      exit(-1)
    end

    rs = ResponseSet.new(created_by: user, status: 'draft',
                         name: '30 Code Response Set')
    responses = []
    30.times do |i|
      r = Response.new(value: "code-#{i}", code_system: 'test',
                       display_name: "Code #{i}")
      responses << r
    end
    rs.responses = responses
    rs.save!

    form = Form.new(name: '500 Question Form', created_by: user, status: 'draft')
    500.times do |i|
      position = i + 1
      q = Question.create(content: "Is your favorite number #{position}?",
                          created_by: user, status: 'draft')
      fq = FormQuestion.new(question: q, position: position)
      form.form_questions << fq
    end
    form.save!

    survey = Survey.new(name: '500 Question Survey', created_by: user, status: 'draft')
    ['a', 'b', 'c', 'd', 'e'].each_with_index do |form_letter, survey_position|
      f = Form.new(name: "Form #{form_letter} - 100 questions", created_by: user, status: 'draft')
      100.times do |i|
        position = i + 1
        q = Question.create(content: "Is your favorite letter #{form_letter} and number #{position}?",
                            created_by: user, status: 'draft')
        fq = FormQuestion.new(question: q, position: position)
        f.form_questions << fq
      end
      f.save!
      survey.survey_forms << SurveyForm.new(form: f, position: survey_position)
    end
    survey.save!
  end
end

Create 500 question survey for testing
Create 500 question survey for testing

Extend the data:load_test task so that it will now also create a survey
that has 500 questions. This is done by creating 5 forms that have 100
questions each.
