From 6695c4e9350c53ca179987b338dbe08c25eeb8d8 Mon Sep 17 00:00:00 2001 From: Zach Pendleton Date: Thu, 9 Feb 2012 16:05:13 -0700 Subject: [PATCH] fix assignment status in 'Coming Up' sidebar. fixes #6783 submitted assignments weren't having their status consistently updated because the partial depended on the @current_user_submissions variable that wasn't being set in every view. fixed this by adding an extra conditional to the view (eek!). also included a fix to ensure that the correct context is always used when checking permissions (the page context isn't always the context of the 'Coming Up' item). test plan: * create a course with an assignment due tomorrow; * as student of that course, log in and submit the assignment; * verify that the assignment shows as submitted on both the user dashboard and the course home page. * click around the app and ensure that the sidebar works as expected. Change-Id: If1b955cd4e49c3c83cae9c92a0f3c515e8d3c2d3 Reviewed-on: https://gerrit.instructure.com/8633 Tested-by: Hudson Reviewed-by: Ryan Florence --- app/helpers/courses_helper.rb | 5 +++++ app/views/courses/_recent_event.html.erb | 10 ++++++---- spec/views/courses/_recent_event.html.erb_spec.rb | 5 ++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 88cae4c5e09..d412e89be69 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -29,6 +29,11 @@ module CoursesHelper return end + # because this happens in a sidebar, the context may be wrong. check and fix + # it if that's the case. + context = context.class == recent_event.class && context.id == recent_event.context_id ? + context : recent_event.context + icon_data = [nil, 'icon-grading-gray'] if can_do(context, current_user, :participate_as_student) icon_data = submission && submission.submitted_or_graded? ? [submission.readable_state, 'icon-grading'] : [t('#courses.recent_event.not_submitted', 'not submitted'), "icon-grading-gray"] diff --git a/app/views/courses/_recent_event.html.erb b/app/views/courses/_recent_event.html.erb index 78744dc13d3..53bd0c82146 100644 --- a/app/views/courses/_recent_event.html.erb +++ b/app/views/courses/_recent_event.html.erb @@ -1,9 +1,11 @@ <% show_context ||= false; upcoming ||= false - submissions ||= @current_user_submissions || [] - submission = nil - submission = submissions.detect{|s| s.assignment_id == recent_event.id} if recent_event.is_a?(Assignment) - + if recent_event.is_a?(Assignment) + submission = @current_user_submissions.nil? ? + @current_user.submissions.scoped(:select => 'id, assignment_id, score, workflow_state', :conditions => { :assignment_id => recent_event.id }).first : + @current_user_submissions.detect { |s| s.assignment_id == recent_event.id } + end + cache(['recent_event_render', submission || 'no_submission', recent_event || 'blank_event', Time.zone.utc_offset, recent_event.cached_context_grants_right?(@current_user, nil, :manage_grades), recent_event.cached_context_grants_right?(@current_user, nil, :participate_as_student)].cache_key) do set_icon_data(:context => @context, :contexts => @contexts, :current_user => @current_user, :recent_event => recent_event, :submission => submission) %> diff --git a/spec/views/courses/_recent_event.html.erb_spec.rb b/spec/views/courses/_recent_event.html.erb_spec.rb index 0265986a3fa..acbca5c26e2 100644 --- a/spec/views/courses/_recent_event.html.erb_spec.rb +++ b/spec/views/courses/_recent_event.html.erb_spec.rb @@ -44,8 +44,7 @@ describe "/courses/_recent_event" do @quiz_submission.grade_submission @submission = @quiz_submission.submission - @submission.score = 1234567890987654400 # long magic number that should be distinct in the partial for the test - @submission.save + Submission.any_instance.stubs(:score).returns(1234567890987654400) end it "should show the score for a non-muted assignment" do @@ -61,4 +60,4 @@ describe "/courses/_recent_event" do end end -# Sidebar content \ No newline at end of file +# Sidebar content