Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

Commit

Permalink
Revert "display quiz questions in grader's language in SpeedGrader"
Browse files Browse the repository at this point in the history
This reverts commit 6533b36.

fixes CNVS-29795

Test plan:
Submission translation should match the user who took the quiz

Change-Id: Ib615a24b702cccbc5b9b01c5377bee265b6b99ee
Reviewed-on: https://gerrit.instructure.com/81603
Reviewed-by: Bryan Petty <[email protected]>
Tested-by: Jenkins
QA-Review: Michael Hargiss <[email protected]>
Product-Review: Jason Sparks <[email protected]>
Product-Review: Chris Wang <[email protected]>
  • Loading branch information
Davis McClellan committed Jun 6, 2016
1 parent df67a6e commit 580e16f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 113 deletions.
8 changes: 2 additions & 6 deletions app/models/quizzes/quiz_question_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,14 @@ def build_submission_questions(quiz_id, quiz_data)
end
end

def self.translate_question_number_text(q, position)
def self.decorate_question_for_submission(q, position)
question_name = t(
'#quizzes.quiz.question_name_counter',
"Question %{question_number}", {
question_number: position
})

q[:position] = position
q[:name] = q[:question_name] = question_name
end

def self.decorate_question_for_submission(q, position)
translate_question_number_text(q, position)

case q[:question_type]
when ::Quizzes::QuizQuestion::Q_TEXT_ONLY
Expand Down Expand Up @@ -183,6 +178,7 @@ def self.decorate_question_for_submission(q, position)
q[:question_text] = text
end # case q[:question_type]

q[:name] = q[:question_name] = question_name
q
end

Expand Down
1 change: 0 additions & 1 deletion app/views/quizzes/quizzes/_display_question.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%
display_question ||= nil
question = display_question
Quizzes::QuizQuestionBuilder.translate_question_number_text(question, question[:position]) if question.present?
question_type = answer_type(question)
user_answer ||= nil
user_answer_hash ||= {}
Expand Down
5 changes: 1 addition & 4 deletions app/views/quizzes/quizzes/_quiz_submission.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@
<%= before_label(:questions_need_review, "The following questions need review") %>
<ul id="questions_needing_review" style="margin-top: 0;">
<% questions_needing_review.each do |answer| %>
<%
question = submission_questions_hash[answer[:question_id]]
Quizzes::QuizQuestionBuilder.decorate_question_for_submission(question, question[:position])
%>
<% question = submission_questions_hash[answer[:question_id]] %>
<li>
<a href="#question_<%= answer[:question_id] %>"><%= h(question[:name]) %></a>
</li>
Expand Down
42 changes: 0 additions & 42 deletions spec/models/quizzes/quiz_question_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,46 +273,4 @@
subject.shuffle_matches(question)
end
end

describe '.translate_question_number_text' do
before(:once) do
@question = Quizzes::QuizQuestion.new({
question_data: {
question_type: 'essay_question',
question_text: 'qq 1'
}
})
end

it 'does not translate the question_name when no locale is set' do
question_data = @question.question_data
Quizzes::QuizQuestionBuilder.translate_question_number_text(question_data, 3)

expect(question_data[:name]).to eq('Question 3')
expect(question_data[:name]).to eq(question_data[:question_name])
end

it 'translates the question_name to the current locale' do
{
es: 'Pregunta',
de: 'Frage'
}.each do |locale, translation|
I18n.locale = locale.to_s

question_data = @question.question_data
Quizzes::QuizQuestionBuilder.translate_question_number_text(question_data, 3)

expect(question_data[:name]).to eq("#{translation} 3")
expect(question_data[:name]).to eq(question_data[:question_name])
end
end

it 'handles nil positions' do
question_data = @question.question_data
Quizzes::QuizQuestionBuilder.translate_question_number_text(question_data, nil)

expect(question_data[:name]).to eq('Question ')
expect(question_data[:name]).to eq(question_data[:question_name])
end
end
end
6 changes: 3 additions & 3 deletions spec/selenium/quizzes/quizzes_grading_teacher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
include QuizzesCommon

context 'as a teacher' do
before(:each) do
before(:once) do
course_with_teacher(active_all: 1)
student_in_course(active_all: 1)
@quiz = seed_quiz_with_submission(1, student: @student)

user_session(@teacher)
end

before(:each) { user_session(@teacher) }

context 'when on the course home page' do
before(:each) { get "/courses/#{@course.id}" }

Expand Down
70 changes: 13 additions & 57 deletions spec/views/quizzes/quizzes/_display_question.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,73 +20,29 @@
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/quizzes/quizzes/_display_question" do
def render_as(user)
view_context @course, user

render :partial => "quizzes/quizzes/display_question", :object => @q, :locals => {
:user_answer => @submission.submission_data.find{|a| a[:question_id] == @q[:id]},
:assessment_results => true}
end

before(:once) do
course_with_teacher(active_all: 1)
student_in_course(active_all: 1)

@student.update_attribute(:locale, 'es')
@teacher.update_attribute(:locale, 'de')
it "should render" do
course_with_student
view_context

@quiz = @course.quizzes.create!(:title => "new quiz")
@quiz.quiz_questions.create!(
question_data: {
name: 'LTUE',
points_possible: 1,
question_type: 'numerical_question',
answers: {
answer_0: {
numerical_answer_type: 'exact_answer',
answer_exact: 42,
answer_text: '',
answer_weight: '100'
}
}
}
)
@quiz.quiz_questions.create!(:question_data =>
{:name => 'LTUE', :points_possible => 1, 'question_type' => 'numerical_question',
'answers' => {'answer_0' => {'numerical_answer_type' => 'exact_answer',
'answer_exact' => 42, 'answer_text' => '', 'answer_weight' => '100'}}})
@quiz.generate_quiz_data
@quiz.save

@submission = @quiz.generate_submission(@student)
@submission.submission_data = { "question_#{@quiz.quiz_data[0][:id]}" => "42.0" }
Quizzes::SubmissionGrader.new(@submission).grade_submission

@q = @quiz.stored_questions.first
@q[:answers][0].delete(:margin) # sometimes this is missing; see #10785
end

before(:each) do
assigns[:quiz] = @quiz
end

it "should render" do
render_as @student

expect(rendered).not_to be_nil
end

context 'when the student and teacher have different locales' do
it "shows question names in Spanish to the student" do
I18n.locale = @student.locale

render_as @student

expect(rendered).to include('Pregunta')
end

it "shows question names in Spanish to the teacher" do
I18n.locale = @teacher.locale

render_as @teacher

expect(rendered).to include('Frage')
end
q = @quiz.stored_questions.first
q[:answers][0].delete(:margin) # sometimes this is missing; see #10785
render :partial => "quizzes/quizzes/display_question", :object => q, :locals => {
:user_answer => @submission.submission_data.find{|a| a[:question_id] == q[:id]},
:assessment_results => true}
expect(response).not_to be_nil
end
end

0 comments on commit 580e16f

Please sign in to comment.