diff --git a/app/models/course_pace.rb b/app/models/course_pace.rb index 1219ef2b190..e57df22a8a3 100644 --- a/app/models/course_pace.rb +++ b/app/models/course_pace.rb @@ -94,8 +94,16 @@ class CoursePace < ActiveRecord::Base end end + # We need to add one day to the sum of durations here to + # account for the oddity of the first item's set due date. + # If a user is enrolled via a pace item with a duration of + # one day on Jan 1 at 11:58pm, their due date would be on + # Jan 2 at 11:59pm. If that same user were enrolled on Jan + # 2 at 12:00am, their due date would be Jan 3 at 11:59pm. + # While this oddity of finishing out the current day exists, + # we will always need to add one to the sum of durations. def duration - course_pace_module_items.sum(:duration) + course_pace_module_items.sum(:duration) + 1 end def valid_secondary_context diff --git a/spec/models/course_pace_spec.rb b/spec/models/course_pace_spec.rb index 0b088298d95..11d2524220c 100644 --- a/spec/models/course_pace_spec.rb +++ b/spec/models/course_pace_spec.rb @@ -160,8 +160,8 @@ describe CoursePace do end describe "#duration" do - it "returns 0 if there are no module items" do - expect(@course_pace.duration).to eq 0 + it "returns 1 if there are no module items" do + expect(@course_pace.duration).to eq 1 end context "multiple paced module items exist" do @@ -171,8 +171,8 @@ describe CoursePace do end end - it "returns the sum of all item durations" do - expect(@course_pace.duration).to eq 2 + it "returns the sum of all item durations, taking into account the day of enrollment" do + expect(@course_pace.duration).to eq 3 end end end diff --git a/spec/requests/pace_contexts_spec.rb b/spec/requests/pace_contexts_spec.rb index 225eb684cbe..6f0419b9b31 100644 --- a/spec/requests/pace_contexts_spec.rb +++ b/spec/requests/pace_contexts_spec.rb @@ -54,7 +54,7 @@ describe "Pace Contexts API" do applied_pace_json = course_json["applied_pace"] expect(applied_pace_json["name"]).to eq course.name expect(applied_pace_json["type"]).to eq "Course" - expect(applied_pace_json["duration"]).to eq 0 + expect(applied_pace_json["duration"]).to eq 1 expect(Time.parse(applied_pace_json["last_modified"])).to be_within(1.second).of(default_pace.published_at) end diff --git a/spec/selenium/course_paces/coursepaces_landing_page_spec.rb b/spec/selenium/course_paces/coursepaces_landing_page_spec.rb index 68468a5ea7e..acefdefe082 100644 --- a/spec/selenium/course_paces/coursepaces_landing_page_spec.rb +++ b/spec/selenium/course_paces/coursepaces_landing_page_spec.rb @@ -105,7 +105,7 @@ describe "course pace landing page" do expect(course_pace_context_table).to be_displayed expect(number_of_students.text).to include("1") expect(number_of_sections.text).to include("2") - expect(default_duration.text).to include("2 days") + expect(default_duration.text).to include("3 days") end end