feat: update survey_item_response table to indlude recorded date and import recorded date when loading responses

mciea-main
rebuilt 2 years ago
parent acb01ec92f
commit 784e23982e

@ -56,7 +56,6 @@ class SurveyResponsesDataLoader
return if rule.new(row:).skip_row? return if rule.new(row:).skip_row?
end end
# byebug if row.response_id == 'butler_student_survey_response_1'
process_survey_items(row:) process_survey_items(row:)
end end
@ -77,11 +76,11 @@ class SurveyResponsesDataLoader
gender = row.gender gender = row.gender
grade = row.grade grade = row.grade
if survey_item_response.present? if survey_item_response.present?
survey_item_response.update!(likert_score:, grade:, gender:) survey_item_response.update!(likert_score:, grade:, gender:, recorded_date: row.recorded_date)
[] []
else else
SurveyItemResponse.new(response_id: row.response_id, academic_year: row.academic_year, school: row.school, survey_item:, SurveyItemResponse.new(response_id: row.response_id, academic_year: row.academic_year, school: row.school, survey_item:,
likert_score:, grade:, gender:) likert_score:, grade:, gender:, recorded_date: row.recorded_date)
end end
end end

@ -0,0 +1,5 @@
class AddRecordedDateToSurveyItemResponse < ActiveRecord::Migration[7.0]
def change
add_column :survey_item_responses, :recorded_date, :datetime
end
end

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_06_10_165508) do ActiveRecord::Schema[7.0].define(version: 2023_06_22_224103) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements" enable_extension "pg_stat_statements"
enable_extension "plpgsql" enable_extension "plpgsql"
@ -444,6 +444,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_10_165508) do
t.bigint "student_id" t.bigint "student_id"
t.integer "grade" t.integer "grade"
t.bigint "gender_id" t.bigint "gender_id"
t.datetime "recorded_date"
t.index ["academic_year_id"], name: "index_survey_item_responses_on_academic_year_id" t.index ["academic_year_id"], name: "index_survey_item_responses_on_academic_year_id"
t.index ["gender_id"], name: "index_survey_item_responses_on_gender_id" t.index ["gender_id"], name: "index_survey_item_responses_on_gender_id"
t.index ["response_id"], name: "index_survey_item_responses_on_response_id" t.index ["response_id"], name: "index_survey_item_responses_on_response_id"

@ -97,6 +97,7 @@ describe SurveyResponsesDataLoader do
it "ensures teacher responses load correctly" do it "ensures teacher responses load correctly" do
assigns_academic_year_to_survey_item_responses assigns_academic_year_to_survey_item_responses
assigns_school_to_the_survey_item_responses assigns_school_to_the_survey_item_responses
assigns_recorded_date_to_teacher_responses
loads_survey_item_responses_for_a_given_survey_response loads_survey_item_responses_for_a_given_survey_response
loads_all_survey_item_responses_for_a_given_survey_item loads_all_survey_item_responses_for_a_given_survey_item
captures_likert_scores_for_survey_item_responses captures_likert_scores_for_survey_item_responses
@ -112,6 +113,7 @@ describe SurveyResponsesDataLoader do
it "ensures student responses load correctly" do it "ensures student responses load correctly" do
assigns_academic_year_to_student_survey_item_responses assigns_academic_year_to_student_survey_item_responses
assigns_school_to_student_survey_item_responses assigns_school_to_student_survey_item_responses
assigns_recorded_date_to_student_responses
loads_student_survey_item_response_values loads_student_survey_item_response_values
student_survey_item_response_count_matches_expected student_survey_item_response_count_matches_expected
captures_likert_scores_for_student_survey_item_responses captures_likert_scores_for_student_survey_item_responses
@ -297,3 +299,25 @@ def assigns_gender_to_responses
expect(SurveyItemResponse.where(response_id: key).first.gender).to eq value expect(SurveyItemResponse.where(response_id: key).first.gender).to eq value
end end
end end
def assigns_recorded_date_to_student_responses
results = {"student_survey_response_1" => "2020-09-30T18:48:50",
"student_survey_response_3" => "2021-03-31T09:59:02",
"student_survey_response_4" => "2021-03-31T10:00:17",
"student_survey_response_5" => "2021-03-31T10:01:36",
"student_survey_response_6" => "2021-03-31T10:01:37",
"student_survey_response_7" => "2021-03-31T10:01:38"}
results.each do |key, value|
expect(SurveyItemResponse.find_by_response_id(key).recorded_date).to eq Date.parse(value)
end
end
def assigns_recorded_date_to_teacher_responses
results = {"teacher_survey_response_1" => "2020-10-16 11:09:03",
"teacher_survey_response_3" => "2020-12-06 8:36:52",
"teacher_survey_response_4" => "2020-12-06 8:51:25",
"teacher_survey_response_5" => "2020-12-06 8:55:58"}
results.each do |key, value|
expect(SurveyItemResponse.find_by_response_id(key).recorded_date).to eq Date.parse(value)
end
end

Loading…
Cancel
Save