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

pull/1/head
rebuilt 2 years ago
parent 8bc14a79f6
commit e8aa75bf66

@ -56,7 +56,6 @@ class SurveyResponsesDataLoader
return if rule.new(row:).skip_row?
end
# byebug if row.response_id == 'butler_student_survey_response_1'
process_survey_items(row:)
end
@ -77,11 +76,11 @@ class SurveyResponsesDataLoader
gender = row.gender
grade = row.grade
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
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

@ -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.
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
enable_extension "plpgsql"
@ -76,6 +76,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_10_165508) do
t.datetime "updated_at", null: false
end
create_table "incomes", force: :cascade do |t|
t.string "designation"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "legacy_attempts", id: :serial, force: :cascade do |t|
t.integer "recipient_id"
t.integer "schedule_id"
@ -444,8 +450,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_10_165508) do
t.bigint "student_id"
t.integer "grade"
t.bigint "gender_id"
t.bigint "income_id"
t.datetime "recorded_date"
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 ["income_id"], name: "index_survey_item_responses_on_income_id"
t.index ["response_id"], name: "index_survey_item_responses_on_response_id"
t.index ["school_id", "academic_year_id", "survey_item_id"], name: "by_school_year_and_survey_item"
t.index ["school_id", "academic_year_id"], name: "index_survey_item_responses_on_school_id_and_academic_year_id"
@ -500,6 +509,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_10_165508) do
add_foreign_key "subcategories", "categories"
add_foreign_key "survey_item_responses", "academic_years"
add_foreign_key "survey_item_responses", "genders"
add_foreign_key "survey_item_responses", "incomes"
add_foreign_key "survey_item_responses", "schools"
add_foreign_key "survey_item_responses", "students"
add_foreign_key "survey_item_responses", "survey_items"

@ -97,6 +97,7 @@ describe SurveyResponsesDataLoader do
it "ensures teacher responses load correctly" do
assigns_academic_year_to_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_all_survey_item_responses_for_a_given_survey_item
captures_likert_scores_for_survey_item_responses
@ -112,6 +113,7 @@ describe SurveyResponsesDataLoader do
it "ensures student responses load correctly" do
assigns_academic_year_to_student_survey_item_responses
assigns_school_to_student_survey_item_responses
assigns_recorded_date_to_student_responses
loads_student_survey_item_response_values
student_survey_item_response_count_matches_expected
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
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