mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-13 01:10:39 -07:00
feat: Support two date formats: ISO 8601 and the standard US date format
used in google sheets
This commit is contained in:
parent
03349b0ed5
commit
d6735d449d
6 changed files with 45 additions and 23 deletions
|
|
@ -14,7 +14,8 @@ RSpec.describe Cleaner do
|
|||
create(:respondent, school: second_school, academic_year:, one: 0, four: 40, five: 40, six: 40, seven: 40,
|
||||
eight: 40)
|
||||
end
|
||||
let(:recorded_date) { "2023-04-01" }
|
||||
let(:recorded_date) { "4/1/2023" }
|
||||
|
||||
let(:input_filepath) do
|
||||
Rails.root.join("spec", "fixtures", "raw")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ RSpec.describe SurveyItemValues, type: :model do
|
|||
create(:respondent, school: attleboro, academic_year: ay_2022_23, nine: 40, ten: 40, eleven: 40, twelve: 40)
|
||||
end
|
||||
let(:schools) { School.school_hash }
|
||||
let(:recorded_date) { "2023-04-01" }
|
||||
let(:recorded_date) { "2023-04-01T12:12:12" }
|
||||
let(:ay_2022_23) do
|
||||
create(:academic_year, range: "2022-23")
|
||||
end
|
||||
|
|
@ -104,14 +104,14 @@ RSpec.describe SurveyItemValues, type: :model do
|
|||
|
||||
context ".recorded_date" do
|
||||
it "returns the recorded date" do
|
||||
row = { "RecordedDate" => "2017-01-01" }
|
||||
row = { "RecordedDate" => "2017-01-01T12:12:121" }
|
||||
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
|
||||
expect(values.recorded_date).to eq Date.parse("2017-01-01")
|
||||
expect(values.recorded_date).to eq Date.parse("2017-01-01T12:12:12")
|
||||
|
||||
headers = ["Recorded Date"]
|
||||
row = { "Recorded Date" => "2017-01-02" }
|
||||
row = { "Recorded Date" => "2017-01-02T12:12:122" }
|
||||
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
|
||||
expect(values.recorded_date).to eq Date.parse("2017-01-02")
|
||||
expect(values.recorded_date).to eq Date.parse("2017-01-02T12:12:12")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -826,4 +826,27 @@ RSpec.describe SurveyItemValues, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ".academic_year" do
|
||||
before do
|
||||
create(:academic_year, range: "2020-21")
|
||||
create(:academic_year, range: "2021-22")
|
||||
end
|
||||
|
||||
it "parses the date correctly when the date is in standard date format for google sheets" do
|
||||
recorded_date = "1/10/2022 14:21:45"
|
||||
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, survey_items:,
|
||||
schools:)
|
||||
ay_21_22 = AcademicYear.find_by_range "2021-22"
|
||||
expect(values.academic_year).to eq ay_21_22
|
||||
end
|
||||
|
||||
it "parses the date correctly when the date is in iso standard 8601" do
|
||||
recorded_date = "2022-1-10T14:21:45"
|
||||
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, survey_items:,
|
||||
schools:)
|
||||
ay_21_22 = AcademicYear.find_by_range "2021-22"
|
||||
expect(values.academic_year).to eq ay_21_22
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -316,10 +316,10 @@ def assigns_recorded_date_to_student_responses
|
|||
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 = { "teacher_survey_response_1" => "2020-10-16T11:09:03",
|
||||
"teacher_survey_response_3" => "2020-12-06T8:36:52",
|
||||
"teacher_survey_response_4" => "2020-12-06T8:51:25",
|
||||
"teacher_survey_response_5" => "2020-12-06T8:55:58" }
|
||||
results.each do |key, value|
|
||||
expect(SurveyItemResponse.find_by_response_id(key).recorded_date).to eq Date.parse(value)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue