canvas-lms/spec/serializers/quizzes/quiz_serializer_spec.rb

585 lines
21 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Quizzes::QuizSerializer do
def quiz_serializer(options={})
options.reverse_merge!({
controller: controller,
scope: @user,
session: @session
})
Quizzes::QuizSerializer.new(@quiz, options)
end
let(:quiz) { @quiz }
let(:context ) { @context }
let(:serializer) { @serializer }
let(:host_name) { 'example.com' }
let(:json) { @json }
let(:session) { @session }
let(:controller) do
ActiveModel::FakeController.new(accepts_jsonapi: true, stringify_json_ids: false)
end
before do
@context = Account.default.courses.new
@context.id = 1
@quiz = Quizzes::Quiz.new title: 'test quiz', description: 'default quiz description'
@quiz.id = 1
@quiz.context = @context
@user = User.new
@quiz.stubs(:locked_for?).returns false
@quiz.stubs(:check_right?).returns true
@session = stub(:[] => nil)
controller.stubs(:session).returns session
controller.stubs(:context).returns context
@quiz.stubs(:grants_right?).at_least_once.returns true
@serializer = quiz_serializer
@json = @serializer.as_json[:quiz]
end
[
:title, :quiz_type, :hide_results, :time_limit,
:shuffle_answers, :show_correct_answers, :scoring_policy,
:allowed_attempts, :one_question_at_a_time, :question_count,
:points_possible, :cant_go_back, :access_code, :ip_filter, :due_at,
:lock_at, :unlock_at, :published, :show_correct_answers_at,
:hide_correct_answers_at, :show_correct_answers_last_attempt, :question_types,
:has_access_code
].each do |attribute|
it "serializes #{attribute}" do
expect(json[attribute]).to eq quiz.send(attribute)
end
end
it "serializes mobile_url" do
expect(json[:mobile_url]).to eq 'http://example.com/courses/1/quizzes/1?force_user=1&persist_headless=1'
end
it "serializes html_url" do
expect(json[:html_url]).to eq 'http://example.com/courses/1/quizzes/1'
end
describe "description" do
it "serializes description with a formatter if given" do
@serializer = quiz_serializer(
serializer_options: {
description_formatter: -> (_) {return "description from formatter"}
}
)
@json = @serializer.as_json[:quiz]
expect(json[:description]).to eq "description from formatter"
end
it "returns desctiption otherwise" do
expect(json[:description]).to eq quiz.description
end
end
it "serializes speed_grader_url" do
# No assignment, so it should be nil
expect(json[:speed_grader_url]).to be_nil
assignment = Assignment.new
assignment.id = 1
assignment.context_id = @context.id
@quiz.stubs(:assignment).returns assignment
# nil when quiz is unpublished
@quiz.stubs(:published?).returns false
expect(@serializer.as_json[:quiz][:speed_grader_url]).to be_nil
# nil when context doesn't allow speedgrader
@quiz.stubs(:published?).returns true
@context.expects(:allows_speed_grader?).returns false
expect(@serializer.as_json[:quiz][:speed_grader_url]).to be_nil
@context.expects(:allows_speed_grader?).returns true
json = @serializer.as_json[:quiz]
expect(json[:speed_grader_url]).to eq(
controller.send(:speed_grader_course_gradebook_url, @quiz.context, assignment_id: @quiz.assignment.id)
)
# Students shouldn't be able to see speed_grader_url
@quiz.stubs(:grants_right?).returns false
expect(@serializer.as_json[:quiz]).not_to have_key :speed_grader_url
end
it "doesn't include the section count unless the user can grade" do
quiz.expects(:grants_right?).with(@user, @session, :grade).
at_least_once.returns true
expect(serializer.as_json[:quiz]).to have_key :section_count
quiz.expects(:grants_right?).with(@user, @session, :grade).
at_least_once.returns false
expect(serializer.as_json[:quiz]).not_to have_key :section_count
end
it "uses available_question_count for question_count" do
quiz.stubs(:available_question_count).returns 5
expect(serializer.as_json[:quiz][:question_count]).to eq 5
end
it "sends the message_students_url when user can grade" do
quiz.expects(:grants_right?).at_least_once.returns true
expect(serializer.as_json[:quiz][:message_students_url]).to eq(
controller.send(:api_v1_course_quiz_submission_users_message_url, quiz, quiz.context)
)
quiz.expects(:grants_right?).at_least_once.returns false
expect(serializer.as_json[:quiz]).not_to have_key :message_students_url
end
describe "access code" do
it "is included if the user can grade" do
quiz.expects(:grants_right?).with(@user, @session, :grade).
at_least_once.returns true
expect(serializer.as_json[:quiz]).to have_key :access_code
end
it "is included if the user can manage" do
quiz.expects(:grants_right?).with(@user, @session, :manage).
at_least_once.returns true
expect(serializer.as_json[:quiz]).to have_key :access_code
end
it "is not included if the user can't grade or manage" do
quiz.expects(:grants_right?).with(@user, @session, :grade).
at_least_once.returns false
quiz.expects(:grants_right?).with(@user, @session, :manage).
at_least_once.returns false
expect(serializer.as_json[:quiz]).not_to have_key :access_code
end
end
describe "id" do
it "stringifys when stringify_json_ids? is true" do
controller.expects(:accepts_jsonapi?).at_least_once.returns false
controller.expects(:stringify_json_ids?).at_least_once.returns true
expect(serializer.as_json[:quiz][:id]).to eq quiz.id.to_s
end
it "when stringify_json_ids? is false" do
controller.expects(:accepts_jsonapi?).at_least_once.returns false
expect(serializer.as_json[:quiz][:id]).to eq quiz.id
expect(serializer.as_json[:quiz][:id].is_a?(Integer)).to be_truthy
end
end
describe "lock_info" do
it "includes lock_info when appropriate" do
quiz.expects(:locked_for?).
with(@user, check_policies: true, context: @context).
returns({due_at: true})
json = quiz_serializer.as_json[:quiz]
expect(json).to have_key :lock_info
expect(json).to have_key :lock_explanation
expect(json[:locked_for_user]).to eq true
quiz.expects(:locked_for?).
with(@user, check_policies: true, context: @context).
returns false
json = quiz_serializer.as_json[:quiz]
expect(json).not_to have_key :lock_info
expect(json).not_to have_key :lock_explanation
expect(json[:locked_for_user]).to eq false
end
quiz index optimizations Closes CNVS-15109, CNVS-15173 CHANGES ------- - "auto-grading" of due submissions that was previously done synchronously in the index action is now done in a DJ - when viewing the index page, you don't get to see due/available dates on load, instead the dates are fetched on the client-side and load progressively - new API endpoint for retrieving assignment overrides for a bunch of quizzes at [GET] /courses/:course_id/quizzes/assignment_overrides - we now cache the user's quiz permissions - Canvas AMS API serializer now accepts a new option, see docs - QuizSerializer behavior changed radically: - "takeable", "submitted_students", "unsubmitted_students" disabled - all associations disabled including the submission, assignment group, and any student participants - it can now utilize preloaded permissions Rationale behind disabling things in the serializer is that these were exclusive for the "show" action, so the next step forwards is to allow the serializer to recognize different "modes" for output (e.g, for index and one for show) and tailor the associations/fields accordingly. Using "#filter" right now isn't cutting it, because assocs get loaded anyway. REFACTORING ----------- - broke down index into three actions for visibility: 1. default, Draft-State version 2. legacy non-DS version that's not reachable in the UI, kept around until we upgrade the tests 3. ember version - legacy non-DS ERB code goes into its own file - moved code that used to grade due submissions inside index to SubmissionGrader in preparation to remove it from there entirely - cleaned up internal docs for the Canvas AMS api serializer TEST PLAN ---- ---- - create ~30 quizzes + make one of them have many questions + make a good number of submissions (i tested with 420 and 20 students) - create multiple sections + specify date overrides for certain sections, and have at least one student enrolled in that section - as a teacher and/or an observer, go to quizzes index + verify the page renders fine + verify that you see "loading indicators" in the due/available field which get replaced with actual dates when they're loaded + verify it's faster than the version in master (should be at least 60% faster) - as a student in the general section, go to quizzes index + verify the page renders + verify you see the same loading behavior for dates as in teacher view - as a student in one of the section with overrides, go to index: + verify you see the overridden date Change-Id: I741d89625da1b858148baa95e881fcc75c1802e5 Reviewed-on: https://gerrit.instructure.com/40350 Reviewed-by: Derek DeVries <ddevries@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-08-31 15:20:52 +08:00
it "doesn't if skip_lock_tests is on" do
quiz.expects(:locked_for?).never
json = quiz_serializer({
serializer_options: {
skip_lock_tests: true
}
}).as_json[:quiz]
expect(json).not_to have_key :lock_info
expect(json).not_to have_key :lock_explanation
expect(json).not_to have_key :locked_for_user
quiz index optimizations Closes CNVS-15109, CNVS-15173 CHANGES ------- - "auto-grading" of due submissions that was previously done synchronously in the index action is now done in a DJ - when viewing the index page, you don't get to see due/available dates on load, instead the dates are fetched on the client-side and load progressively - new API endpoint for retrieving assignment overrides for a bunch of quizzes at [GET] /courses/:course_id/quizzes/assignment_overrides - we now cache the user's quiz permissions - Canvas AMS API serializer now accepts a new option, see docs - QuizSerializer behavior changed radically: - "takeable", "submitted_students", "unsubmitted_students" disabled - all associations disabled including the submission, assignment group, and any student participants - it can now utilize preloaded permissions Rationale behind disabling things in the serializer is that these were exclusive for the "show" action, so the next step forwards is to allow the serializer to recognize different "modes" for output (e.g, for index and one for show) and tailor the associations/fields accordingly. Using "#filter" right now isn't cutting it, because assocs get loaded anyway. REFACTORING ----------- - broke down index into three actions for visibility: 1. default, Draft-State version 2. legacy non-DS version that's not reachable in the UI, kept around until we upgrade the tests 3. ember version - legacy non-DS ERB code goes into its own file - moved code that used to grade due submissions inside index to SubmissionGrader in preparation to remove it from there entirely - cleaned up internal docs for the Canvas AMS api serializer TEST PLAN ---- ---- - create ~30 quizzes + make one of them have many questions + make a good number of submissions (i tested with 420 and 20 students) - create multiple sections + specify date overrides for certain sections, and have at least one student enrolled in that section - as a teacher and/or an observer, go to quizzes index + verify the page renders fine + verify that you see "loading indicators" in the due/available field which get replaced with actual dates when they're loaded + verify it's faster than the version in master (should be at least 60% faster) - as a student in the general section, go to quizzes index + verify the page renders + verify you see the same loading behavior for dates as in teacher view - as a student in one of the section with overrides, go to index: + verify you see the overridden date Change-Id: I741d89625da1b858148baa95e881fcc75c1802e5 Reviewed-on: https://gerrit.instructure.com/40350 Reviewed-by: Derek DeVries <ddevries@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-08-31 15:20:52 +08:00
end
end
describe "unpublishable" do
it "is not present unless the user can manage the quiz's assignments" do
quiz.expects(:grants_right?).with(@user, session, :manage).returns true
expect(serializer.filter(serializer.class._attributes)).to include :unpublishable
add student extension dialogs on new ember quiz moderate page fixes CNVS-12449 test plan: - as a teacher - enable fabulous quizzes - enroll a few students in the course - there is a new quizzes api attribute called 'quiz_extensions_url' - check out the jsonapi quizzes api to make sure this attribute only shows up for teachers (and not students) - create a quiz with no time limit and unlimited attempts - visit the quiz moderate page - click the "edit" icon for a student - the modal dialog should only allow you to "manually unlock" - create a quiz with a time limit - visit the quiz moderate page - click the "edit" icon for a student - the modal dialog should only allow you to "manually unlock" - the modal dialog should only allow you to add "extra time" - create a quiz with a limited number of attempts (1 or more) - visit the quiz moderate page - click the "edit" icon for a student - the modal dialog should only allow you to "manually unlock" - the modal dialog should only allow you to add "extra attempts" - create a quiz with both a time limit and a limited number of attempts - visit the quiz moderate page - click the "edit" icon for a student - the modal dialog should only allow you to "manually unlock" - the modal dialog should only allow you to add "extra attempts" - the modal dialog should only allow you to add "extra time" - change the settings for extra attempts, extra time, and manually unlock - hit submit - it should save these new settings if you reopen the dialog - it should show the extra minutes allowed on the attempt under the username - it should add the extra attempts to the 'attempts left' column value Change-Id: I0e10942ff7a3a80cec200468216ba0641decee2c Reviewed-on: https://gerrit.instructure.com/35089 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Reviewed-by: Ahmad Amireh <ahmad@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-05-22 06:39:53 +08:00
quiz.unstub(:grants_right?)
quiz.expects(:grants_right?).with(@user, session, :grade).at_least_once.returns false
quiz.expects(:grants_right?).with(@user, session, :manage).at_least_once.returns false
expect(serializer.filter(serializer.class._attributes)).not_to include :unpublishable
end
end
describe "takeable" do
before { skip }
before do
course_with_teacher(active_all: true)
course_quiz(true)
quiz_with_graded_submission([], user: @teacher, quiz: @quiz)
@serializer = quiz_serializer(quiz_submissions: { @quiz.id => @quiz_submission })
end
it "is true when there is no quiz submision" do
Quizzes::QuizSubmission.delete_all
expect(quiz_serializer.as_json[:quiz][:takeable]).to eq true
end
it "is true when quiz_submission is present but not completed" do
@quiz_submission.workflow_state = "settings_only"
expect(@serializer.as_json[:quiz][:takeable]).to eq true
end
it "is true when the quiz submission is completed but quiz has unlimited attempts" do
@quiz_submission.workflow_state = "complete"
@quiz.allowed_attempts = -1
expect(@serializer.as_json[:quiz][:takeable]).to eq true
end
it "is true when quiz submission is completed, !quiz.unlimited_attempts" do
@quiz_submission.workflow_state = "complete"
@quiz.allowed_attempts = 2
# false when attempts left attempts is 0
@quiz_submission.expects(:attempts_left).at_least_once.returns 0
expect(@serializer.as_json[:quiz][:takeable]).to eq false
# true when than attempts left greater than 0
@quiz_submission.expects(:attempts_left).at_least_once.returns 1
expect(@serializer.as_json[:quiz][:takeable]).to eq true
end
end
describe "preview_url" do
it "is only present when the user can grade the quiz" do
course_with_teacher(active_all: true)
course_quiz(true)
expect(quiz_serializer(scope: @teacher).as_json[:quiz][:preview_url]).
to eq controller.send(:course_quiz_take_url, @quiz.context, @quiz, preview: '1')
course_with_student(active_all: true, course: @course)
expect(quiz_serializer(scope: @student).as_json[:quiz]).not_to have_key :preview_url
end
end
describe "links" do
describe "assignment_group" do
context "controller accepts_jsonapi?" do
before { skip }
it "serialize the assignment group's url when present" do
@quiz.stubs(:context).returns course = Account.default.courses.new
course.id = 1
@quiz.assignment_group = assignment_group = AssignmentGroup.new
assignment_group.id = 1
expect(serializer.as_json[:quiz]['links']['assignment_group']).to eq(
controller.send(:api_v1_course_assignment_group_url, course.id,
assignment_group.id)
)
end
it "doesn't serialize the assignment group's url if not present" do
expect(serializer.as_json[:quiz]).not_to have_key(:links)
end
end
context "controller doesn't accept jsonapi" do
it "serialized the assignment_group as assignment_group_id" do
controller.expects(:accepts_jsonapi?).at_least_once.returns false
expect(serializer.as_json[:quiz]['assignment_group_id']).to be_nil
group = quiz.assignment_group = AssignmentGroup.new
quiz index optimizations Closes CNVS-15109, CNVS-15173 CHANGES ------- - "auto-grading" of due submissions that was previously done synchronously in the index action is now done in a DJ - when viewing the index page, you don't get to see due/available dates on load, instead the dates are fetched on the client-side and load progressively - new API endpoint for retrieving assignment overrides for a bunch of quizzes at [GET] /courses/:course_id/quizzes/assignment_overrides - we now cache the user's quiz permissions - Canvas AMS API serializer now accepts a new option, see docs - QuizSerializer behavior changed radically: - "takeable", "submitted_students", "unsubmitted_students" disabled - all associations disabled including the submission, assignment group, and any student participants - it can now utilize preloaded permissions Rationale behind disabling things in the serializer is that these were exclusive for the "show" action, so the next step forwards is to allow the serializer to recognize different "modes" for output (e.g, for index and one for show) and tailor the associations/fields accordingly. Using "#filter" right now isn't cutting it, because assocs get loaded anyway. REFACTORING ----------- - broke down index into three actions for visibility: 1. default, Draft-State version 2. legacy non-DS version that's not reachable in the UI, kept around until we upgrade the tests 3. ember version - legacy non-DS ERB code goes into its own file - moved code that used to grade due submissions inside index to SubmissionGrader in preparation to remove it from there entirely - cleaned up internal docs for the Canvas AMS api serializer TEST PLAN ---- ---- - create ~30 quizzes + make one of them have many questions + make a good number of submissions (i tested with 420 and 20 students) - create multiple sections + specify date overrides for certain sections, and have at least one student enrolled in that section - as a teacher and/or an observer, go to quizzes index + verify the page renders fine + verify that you see "loading indicators" in the due/available field which get replaced with actual dates when they're loaded + verify it's faster than the version in master (should be at least 60% faster) - as a student in the general section, go to quizzes index + verify the page renders + verify you see the same loading behavior for dates as in teacher view - as a student in one of the section with overrides, go to index: + verify you see the overridden date Change-Id: I741d89625da1b858148baa95e881fcc75c1802e5 Reviewed-on: https://gerrit.instructure.com/40350 Reviewed-by: Derek DeVries <ddevries@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-08-31 15:20:52 +08:00
group.id = quiz.assignment_group_id = 1
expect(serializer.as_json[:quiz][:assignment_group_id]).to eq 1
end
end
end
describe "student_quiz_submissions" do
before { skip }
context "when user may grade" do
it "sends the url for all submissions" do
course_with_teacher(active_all: true)
quiz_with_graded_submission([], course: @course)
serializer = quiz_serializer(scope: @teacher)
expect(serializer.as_json[:quiz]['links']['student_quiz_submissions']).to eq(
controller.send(:api_v1_course_quiz_submissions_url, @quiz.context.id, @quiz.id)
)
end
it "sends the url when no student_quiz_submissions are present" do
course_with_teacher(active_all: true)
serializer = quiz_serializer(scope: @teacher)
expect(serializer.as_json[:quiz]['links']['student_quiz_submissions']).to eq(
controller.send(:api_v1_course_quiz_submissions_url, @quiz.context.id, @quiz.id)
)
end
end
context "when user may not grade" do
it "sends nil" do
course_with_student(active_all: true)
quiz_with_graded_submission([], user: @student, course: @course)
serializer = quiz_serializer(scope: @student)
expect(serializer.as_json[:quiz]['links']['student_quiz_submissions']).to be_nil
end
end
end
describe "quiz_submission" do
before { skip }
it "includes the quiz_submission in the response if it is present" do
course_with_student(active_all: true)
quiz_with_graded_submission([], user: @student, course: @course)
serializer = quiz_serializer(scope: @student)
json = serializer.as_json
expect(json['quiz_submissions'].length).to eq 1
expect(json[:quiz]['links']['quiz_submission']).to eq @quiz_submission.id.to_s
end
end
Quiz Reports API - Index An endpoint for retrieving all quiz reports for a given quiz. Closes CNVS-12172 CHANGES ------- The biggest effort in this patch was to normalize the way QuizReport objects are interfaced with, and the generation of their CSV attachments in particular: - Quiz#current_statistics_for() now ALWAYS returns a persisted object while still considering the freshness of the stats - Quiz#statistics_csv() is no longer responsible for testing whether the attachment should be generated or not, but instead ensures that the CSV will be generated ASAP - QuizStatistics#generate_csv() now guards against generating multiple attachments - QuizStatistics#generate_csv_in_background() now guards against queueing multiple generation jobs (by testing the status of the Progress object) QuizReport API changes: - new property: "generatable" - new property: "readable_type" - new property: "url" - now accepts JSON-API format for all endpoints: - JSON-API allows you to embed file and progress objects directly in the QuizReport document, just pass ?include=file,progress Quizzes API changes: - new property (JSON): "quiz_reports_url" - new property (JSON-API): "links.quiz_reports" Some AMS changes: - added support for accepting side-loading requests from controllers by passing an :includes array to the serializer initializer - added support for embedding objects in root, using `embed: :object and embed_in_root: true` for has_one associations - also, in that same scenario, AMS's default behavior is to wrap single objects (has_one) in an array, which didn't work for me, so I added a new option called "wrap_in_array" which you can set to false when defining the association to override this behavior Other changes: - covered the front-end/javascript that utilizes the reports and allows teachers to generate them - QuizReport in the front-end no longer relies on magical course_id exposed in window.ENV, but instead uses its URL to construct the generation URL (see QuizReport#baseURL) - Attachment now has a shallow-AMSerializer that proxies to the legacy one in lib/api/v1 which allows us to at least side-load them - Progress now has an AMS - QuizReport legacy serializer in lib/api/v1 removed entirely, replaced by the new AMS one TEST PLAN ---- ---- Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports - as a teacher, make a request to the endpoint above: - it should return a set of two quiz report objects - add a parameter "includes_all_versions=true" to the query parameters and verify that the "student_analysis" report in the returned set now reflects the new value (the reports have a field called "includes_all_versions" which should be true in this case, false otherwise) - as a student, make the request and verify that it rejects you Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id - turn on JSON-API mode - as a teacher: - don't generate the report from the UI yet - make the request, and verify that you get only the report - generate - repeat the request, verify that you still get only the report - add a ?include=file query parameter - you should read the file document now - add a ?include=progress query parameter - you should read the progress document now - turn off JSON-API mode - as a teacher: - make the request, and verify you get the "progress_url" field and that the file document is embedded automatically without having to specify the ?include= parameter Front-end testing: - go to the statistics page - generate all reports: - verify that the progress bar updates - verify that you can download them - verify that auto-download occurs unless you refresh the page before the report is generated - toggle on the "Count All Attempts" button and repeat the above: - verify that Item Analysis is not generatable anymore since it's not affected by that parameter Please note that "item_analysis" reports will always have "includes_all_versions" as true. Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d Reviewed-on: https://gerrit.instructure.com/32731 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
describe 'quiz_reports' do
it 'sends the url' do
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
expect(serializer.as_json[:quiz]['links']['quiz_reports']).to eq(
Quiz Reports API - Index An endpoint for retrieving all quiz reports for a given quiz. Closes CNVS-12172 CHANGES ------- The biggest effort in this patch was to normalize the way QuizReport objects are interfaced with, and the generation of their CSV attachments in particular: - Quiz#current_statistics_for() now ALWAYS returns a persisted object while still considering the freshness of the stats - Quiz#statistics_csv() is no longer responsible for testing whether the attachment should be generated or not, but instead ensures that the CSV will be generated ASAP - QuizStatistics#generate_csv() now guards against generating multiple attachments - QuizStatistics#generate_csv_in_background() now guards against queueing multiple generation jobs (by testing the status of the Progress object) QuizReport API changes: - new property: "generatable" - new property: "readable_type" - new property: "url" - now accepts JSON-API format for all endpoints: - JSON-API allows you to embed file and progress objects directly in the QuizReport document, just pass ?include=file,progress Quizzes API changes: - new property (JSON): "quiz_reports_url" - new property (JSON-API): "links.quiz_reports" Some AMS changes: - added support for accepting side-loading requests from controllers by passing an :includes array to the serializer initializer - added support for embedding objects in root, using `embed: :object and embed_in_root: true` for has_one associations - also, in that same scenario, AMS's default behavior is to wrap single objects (has_one) in an array, which didn't work for me, so I added a new option called "wrap_in_array" which you can set to false when defining the association to override this behavior Other changes: - covered the front-end/javascript that utilizes the reports and allows teachers to generate them - QuizReport in the front-end no longer relies on magical course_id exposed in window.ENV, but instead uses its URL to construct the generation URL (see QuizReport#baseURL) - Attachment now has a shallow-AMSerializer that proxies to the legacy one in lib/api/v1 which allows us to at least side-load them - Progress now has an AMS - QuizReport legacy serializer in lib/api/v1 removed entirely, replaced by the new AMS one TEST PLAN ---- ---- Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports - as a teacher, make a request to the endpoint above: - it should return a set of two quiz report objects - add a parameter "includes_all_versions=true" to the query parameters and verify that the "student_analysis" report in the returned set now reflects the new value (the reports have a field called "includes_all_versions" which should be true in this case, false otherwise) - as a student, make the request and verify that it rejects you Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id - turn on JSON-API mode - as a teacher: - don't generate the report from the UI yet - make the request, and verify that you get only the report - generate - repeat the request, verify that you still get only the report - add a ?include=file query parameter - you should read the file document now - add a ?include=progress query parameter - you should read the progress document now - turn off JSON-API mode - as a teacher: - make the request, and verify you get the "progress_url" field and that the file document is embedded automatically without having to specify the ?include= parameter Front-end testing: - go to the statistics page - generate all reports: - verify that the progress bar updates - verify that you can download them - verify that auto-download occurs unless you refresh the page before the report is generated - toggle on the "Count All Attempts" button and repeat the above: - verify that Item Analysis is not generatable anymore since it's not affected by that parameter Please note that "item_analysis" reports will always have "includes_all_versions" as true. Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d Reviewed-on: https://gerrit.instructure.com/32731 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
controller.send(:api_v1_course_quiz_reports_url, 3, quiz.id)
)
Quiz Reports API - Index An endpoint for retrieving all quiz reports for a given quiz. Closes CNVS-12172 CHANGES ------- The biggest effort in this patch was to normalize the way QuizReport objects are interfaced with, and the generation of their CSV attachments in particular: - Quiz#current_statistics_for() now ALWAYS returns a persisted object while still considering the freshness of the stats - Quiz#statistics_csv() is no longer responsible for testing whether the attachment should be generated or not, but instead ensures that the CSV will be generated ASAP - QuizStatistics#generate_csv() now guards against generating multiple attachments - QuizStatistics#generate_csv_in_background() now guards against queueing multiple generation jobs (by testing the status of the Progress object) QuizReport API changes: - new property: "generatable" - new property: "readable_type" - new property: "url" - now accepts JSON-API format for all endpoints: - JSON-API allows you to embed file and progress objects directly in the QuizReport document, just pass ?include=file,progress Quizzes API changes: - new property (JSON): "quiz_reports_url" - new property (JSON-API): "links.quiz_reports" Some AMS changes: - added support for accepting side-loading requests from controllers by passing an :includes array to the serializer initializer - added support for embedding objects in root, using `embed: :object and embed_in_root: true` for has_one associations - also, in that same scenario, AMS's default behavior is to wrap single objects (has_one) in an array, which didn't work for me, so I added a new option called "wrap_in_array" which you can set to false when defining the association to override this behavior Other changes: - covered the front-end/javascript that utilizes the reports and allows teachers to generate them - QuizReport in the front-end no longer relies on magical course_id exposed in window.ENV, but instead uses its URL to construct the generation URL (see QuizReport#baseURL) - Attachment now has a shallow-AMSerializer that proxies to the legacy one in lib/api/v1 which allows us to at least side-load them - Progress now has an AMS - QuizReport legacy serializer in lib/api/v1 removed entirely, replaced by the new AMS one TEST PLAN ---- ---- Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports - as a teacher, make a request to the endpoint above: - it should return a set of two quiz report objects - add a parameter "includes_all_versions=true" to the query parameters and verify that the "student_analysis" report in the returned set now reflects the new value (the reports have a field called "includes_all_versions" which should be true in this case, false otherwise) - as a student, make the request and verify that it rejects you Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id - turn on JSON-API mode - as a teacher: - don't generate the report from the UI yet - make the request, and verify that you get only the report - generate - repeat the request, verify that you still get only the report - add a ?include=file query parameter - you should read the file document now - add a ?include=progress query parameter - you should read the progress document now - turn off JSON-API mode - as a teacher: - make the request, and verify you get the "progress_url" field and that the file document is embedded automatically without having to specify the ?include= parameter Front-end testing: - go to the statistics page - generate all reports: - verify that the progress bar updates - verify that you can download them - verify that auto-download occurs unless you refresh the page before the report is generated - toggle on the "Count All Attempts" button and repeat the above: - verify that Item Analysis is not generatable anymore since it's not affected by that parameter Please note that "item_analysis" reports will always have "includes_all_versions" as true. Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d Reviewed-on: https://gerrit.instructure.com/32731 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
end
it 'sends the url as quiz_reports_url' do
controller.expects(:accepts_jsonapi?).at_least_once.returns false
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
expect(serializer.as_json[:quiz][:quiz_reports_url]).to eq(
Quiz Reports API - Index An endpoint for retrieving all quiz reports for a given quiz. Closes CNVS-12172 CHANGES ------- The biggest effort in this patch was to normalize the way QuizReport objects are interfaced with, and the generation of their CSV attachments in particular: - Quiz#current_statistics_for() now ALWAYS returns a persisted object while still considering the freshness of the stats - Quiz#statistics_csv() is no longer responsible for testing whether the attachment should be generated or not, but instead ensures that the CSV will be generated ASAP - QuizStatistics#generate_csv() now guards against generating multiple attachments - QuizStatistics#generate_csv_in_background() now guards against queueing multiple generation jobs (by testing the status of the Progress object) QuizReport API changes: - new property: "generatable" - new property: "readable_type" - new property: "url" - now accepts JSON-API format for all endpoints: - JSON-API allows you to embed file and progress objects directly in the QuizReport document, just pass ?include=file,progress Quizzes API changes: - new property (JSON): "quiz_reports_url" - new property (JSON-API): "links.quiz_reports" Some AMS changes: - added support for accepting side-loading requests from controllers by passing an :includes array to the serializer initializer - added support for embedding objects in root, using `embed: :object and embed_in_root: true` for has_one associations - also, in that same scenario, AMS's default behavior is to wrap single objects (has_one) in an array, which didn't work for me, so I added a new option called "wrap_in_array" which you can set to false when defining the association to override this behavior Other changes: - covered the front-end/javascript that utilizes the reports and allows teachers to generate them - QuizReport in the front-end no longer relies on magical course_id exposed in window.ENV, but instead uses its URL to construct the generation URL (see QuizReport#baseURL) - Attachment now has a shallow-AMSerializer that proxies to the legacy one in lib/api/v1 which allows us to at least side-load them - Progress now has an AMS - QuizReport legacy serializer in lib/api/v1 removed entirely, replaced by the new AMS one TEST PLAN ---- ---- Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports - as a teacher, make a request to the endpoint above: - it should return a set of two quiz report objects - add a parameter "includes_all_versions=true" to the query parameters and verify that the "student_analysis" report in the returned set now reflects the new value (the reports have a field called "includes_all_versions" which should be true in this case, false otherwise) - as a student, make the request and verify that it rejects you Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id - turn on JSON-API mode - as a teacher: - don't generate the report from the UI yet - make the request, and verify that you get only the report - generate - repeat the request, verify that you still get only the report - add a ?include=file query parameter - you should read the file document now - add a ?include=progress query parameter - you should read the progress document now - turn off JSON-API mode - as a teacher: - make the request, and verify you get the "progress_url" field and that the file document is embedded automatically without having to specify the ?include= parameter Front-end testing: - go to the statistics page - generate all reports: - verify that the progress bar updates - verify that you can download them - verify that auto-download occurs unless you refresh the page before the report is generated - toggle on the "Count All Attempts" button and repeat the above: - verify that Item Analysis is not generatable anymore since it's not affected by that parameter Please note that "item_analysis" reports will always have "includes_all_versions" as true. Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d Reviewed-on: https://gerrit.instructure.com/32731 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
controller.send(:api_v1_course_quiz_reports_url, 3, quiz.id)
)
Quiz Reports API - Index An endpoint for retrieving all quiz reports for a given quiz. Closes CNVS-12172 CHANGES ------- The biggest effort in this patch was to normalize the way QuizReport objects are interfaced with, and the generation of their CSV attachments in particular: - Quiz#current_statistics_for() now ALWAYS returns a persisted object while still considering the freshness of the stats - Quiz#statistics_csv() is no longer responsible for testing whether the attachment should be generated or not, but instead ensures that the CSV will be generated ASAP - QuizStatistics#generate_csv() now guards against generating multiple attachments - QuizStatistics#generate_csv_in_background() now guards against queueing multiple generation jobs (by testing the status of the Progress object) QuizReport API changes: - new property: "generatable" - new property: "readable_type" - new property: "url" - now accepts JSON-API format for all endpoints: - JSON-API allows you to embed file and progress objects directly in the QuizReport document, just pass ?include=file,progress Quizzes API changes: - new property (JSON): "quiz_reports_url" - new property (JSON-API): "links.quiz_reports" Some AMS changes: - added support for accepting side-loading requests from controllers by passing an :includes array to the serializer initializer - added support for embedding objects in root, using `embed: :object and embed_in_root: true` for has_one associations - also, in that same scenario, AMS's default behavior is to wrap single objects (has_one) in an array, which didn't work for me, so I added a new option called "wrap_in_array" which you can set to false when defining the association to override this behavior Other changes: - covered the front-end/javascript that utilizes the reports and allows teachers to generate them - QuizReport in the front-end no longer relies on magical course_id exposed in window.ENV, but instead uses its URL to construct the generation URL (see QuizReport#baseURL) - Attachment now has a shallow-AMSerializer that proxies to the legacy one in lib/api/v1 which allows us to at least side-load them - Progress now has an AMS - QuizReport legacy serializer in lib/api/v1 removed entirely, replaced by the new AMS one TEST PLAN ---- ---- Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports - as a teacher, make a request to the endpoint above: - it should return a set of two quiz report objects - add a parameter "includes_all_versions=true" to the query parameters and verify that the "student_analysis" report in the returned set now reflects the new value (the reports have a field called "includes_all_versions" which should be true in this case, false otherwise) - as a student, make the request and verify that it rejects you Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id - turn on JSON-API mode - as a teacher: - don't generate the report from the UI yet - make the request, and verify that you get only the report - generate - repeat the request, verify that you still get only the report - add a ?include=file query parameter - you should read the file document now - add a ?include=progress query parameter - you should read the progress document now - turn off JSON-API mode - as a teacher: - make the request, and verify you get the "progress_url" field and that the file document is embedded automatically without having to specify the ?include= parameter Front-end testing: - go to the statistics page - generate all reports: - verify that the progress bar updates - verify that you can download them - verify that auto-download occurs unless you refresh the page before the report is generated - toggle on the "Count All Attempts" button and repeat the above: - verify that Item Analysis is not generatable anymore since it's not affected by that parameter Please note that "item_analysis" reports will always have "includes_all_versions" as true. Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d Reviewed-on: https://gerrit.instructure.com/32731 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
end
end
describe "quiz_statistics" do
it "sends the url" do
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
expect(serializer.as_json[:quiz]['links']['quiz_statistics']).to eq(
controller.send(:api_v1_course_quiz_statistics_url, 3, quiz.id)
)
end
it "sends the url in non-JSONAPI too" do
controller.expects(:accepts_jsonapi?).at_least_once.returns false
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
expect(serializer.as_json[:quiz][:quiz_statistics_url]).to eq(
controller.send(:api_v1_course_quiz_statistics_url, 3, quiz.id)
)
end
end
describe "submitted_students" do
before { skip }
it "sends nil if user can't grade" do
course_with_student(active_all: true)
@quiz.unstub(:check_right?)
@quiz.unstub(:grants_right?)
serializer = quiz_serializer(scope: @student)
expect(serializer.as_json[:quiz]['links']).not_to have_key 'unsubmitted_students'
end
it "sends a url if there are submissions and user can grade" do
course_with_teacher(active_all: true)
course_with_student(active_all: true, course: @course)
quiz_with_graded_submission([], user: @student, course: @course)
serializer = quiz_serializer(scope: @teacher)
expect(serializer.as_json[:quiz]['links']['submitted_students']).
to eq controller.send(:api_v1_course_quiz_submission_users_url,
@quiz.context,
@quiz,
submitted: true)
end
end
describe "unsubmitted_students" do
before { skip }
it "sends nil if user can't grade" do
@quiz.unstub(:check_right?)
@quiz.unstub(:grants_right?)
course_with_student(active_all: true)
serializer = quiz_serializer(scope: @student)
expect(serializer.as_json[:quiz]['links']).not_to have_key 'unsubmitted_students'
end
it "sends a url if there are submissions and user can grade" do
course_with_teacher(active_all: true)
course_with_student(active_all: true, course: @course)
course_with_student(active_all: true, course: @course)
quiz_with_graded_submission([], user: @student, course: @course)
serializer = quiz_serializer(scope: @teacher)
expect(serializer.as_json[:quiz]['links']['unsubmitted_students']).
to eq controller.send(:api_v1_course_quiz_submission_users_url,
@quiz.context,
@quiz,
submitted: 'false')
end
end
end
describe "quiz_submission_html_url" do
it "includes a url to the quiz_submission html only if JSONAPI request" do
expect(serializer.as_json[:quiz][:quiz_submission_html_url]).to eq(
controller.send(:course_quiz_submission_html_url, context.id, quiz.id)
)
controller.expects(:accepts_jsonapi?).at_least_once.returns false
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submission_html_url
end
end
describe "quiz_submissions_zip_url" do
it "includes a url to download all files" do
controller.expects(:accepts_jsonapi?).at_least_once.returns true
serializer.expects(:user_may_grade?).at_least_once.returns true
serializer.expects(:has_file_uploads?).at_least_once.returns true
expect(serializer.as_json[:quiz][:quiz_submissions_zip_url]).to eq(
'http://example.com/courses/1/quizzes/1/submissions?zip=1'
)
end
it "doesn't if it's not a JSON-API request" do
controller.expects(:accepts_jsonapi?).at_least_once.returns false
serializer.expects(:user_may_grade?).at_least_once.returns true
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submissions_zip_url
end
it "doesn't if the user may not grade" do
controller.expects(:accepts_jsonapi?).at_least_once.returns true
serializer.expects(:user_may_grade?).at_least_once.returns false
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submissions_zip_url
end
it "doesn't if the quiz has no file upload questions" do
controller.expects(:accepts_jsonapi?).at_least_once.returns true
serializer.expects(:user_may_grade?).at_least_once.returns true
serializer.expects(:has_file_uploads?).at_least_once.returns false
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submissions_zip_url
end
end
describe "permissions" do
it "serializes permissions" do
expect(serializer.as_json[:quiz][:permissions]).to eq({
read: true,
submit: true,
review_grades: true,
create: true,
update: true,
read_statistics: true,
QLA - Table view / answer matrix A table view that lists all the answers to all questions with lots of options. The view is restricted to Support SiteAdmins only. Closes CNVS-17165 Backend/API Changes: - QuizSubmissionEvents#index is now paginated - Added a new account-level permission :view_quiz_answer_audits to control the visiblity of the answer matrix. You can test this on the quiz using "quiz.grants_right?(user, :view_answer_audits)" Client app changes: - Fixed a race issue when loading environment-specific config; sometimes would cause the tests to fail because the test suite would run before the test config was loaded - Moved the decoration of QUESTION_ANSWERED events to a separate module and now it is done only once at fetch-time, instead of once per render - Simplified a lot of book-keeping that was done in the Events store by using query & URL parameters - A global loading indicator prop "isLoading" which is managed by the root route in routes/app.jsx - if you want to create a nicer loading indicator, this would be the place to edit - Moved all "devDependencies" into "dependencies" in package.json so now we can just do "npm shrinkwrap" without any flags to generate the shrinkwrap. - grunt watch task is now smart enough to pick up the current app we're working on. Doing `grunt server:events` will watch all the files in /apps/events and run the test suite only for that app. :) Doc changes: - Defined a new JSDuck tag @seed that allows us to inspect React components in real-time in the docs! Every @seed tag you define will accept a JSON construct (or a file that contains JSON) and will inject that into the rendered component, so you can show off different states and usages in the documentation itself. TEST PLAN ---- ---- - create a large quiz with a lot of questions and multiple attempts - take it a few times, do many things like answering questions, tabbing out and back in, flagging/unflagging questions, etc. - go to the log view + make sure you enable the new permission for your user from the "Manage Permissions" page in the SiteAdmin settings + verify you see the "View Table" button + click it, and verify the table works as expected - go back to the Stream View - click on a question link + in the question page, verify that the answers are rendered in a friendly version (e.g, MultipleChoice answers are shown as radio buttons, with the student's answer selected) + hop to other questions/types and verify the same thing Change-Id: I0529b08becbf7dead86c959254faab55761db8df Reviewed-on: https://gerrit.instructure.com/45883 Reviewed-by: Derek DeVries <ddevries@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-12-03 01:59:53 +08:00
view_answer_audits: true,
manage: true,
delete: true,
grade: true,
preview: true
})
end
end
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
it 'displays overridden dates for students' do
course_with_student(active_all: true)
course_quiz(true)
serializer = quiz_serializer(scope: @student)
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
student_overrides = {
due_at: 5.minutes.from_now,
lock_at: nil,
unlock_at: 3.minutes.from_now
}
serializer.stubs(:due_dates).returns [student_overrides]
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
output = serializer.as_json[:quiz]
expect(output).not_to have_key :all_dates
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
[ :due_at, :lock_at, :unlock_at ].each do |key|
expect(output[key]).to eq student_overrides[key]
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
end
end
it 'displays quiz dates for students if not overridden' do
student_overrides = []
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
quiz.expects(:due_at).at_least_once.returns 5.minutes.from_now
quiz.expects(:lock_at).at_least_once.returns nil
quiz.expects(:unlock_at).at_least_once.returns 3.minutes.from_now
serializer.stubs(:due_dates).returns student_overrides
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
output = serializer.as_json[:quiz]
[ :due_at, :lock_at, :unlock_at ].each do |key|
expect(output[key]).to eq quiz.send(key)
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
end
end
it 'includes all_dates for teachers and observers' do
quiz.due_at = 1.hour.from_now
teacher_overrides = [{
due_at: quiz.due_at,
lock_at: nil,
unlock_at: nil,
base: true
}, {
due_at: 30.minutes.from_now,
lock_at: 1.hour.from_now,
unlock_at: 10.minutes.from_now,
title: 'Some Section'
}]
quiz.expects(:due_at).at_least_once
serializer.stubs(:all_dates).returns teacher_overrides
serializer.stubs(:include_all_dates?).returns true
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
output = serializer.as_json[:quiz]
expect(output).to have_key :all_dates
expect(output[:all_dates].length).to eq 2
expect(output[:all_dates].detect { |e| e[:base] }).to eq teacher_overrides[0]
expect(output[:all_dates].detect { |e| !e[:base] }).to eq teacher_overrides[1]
expect(output[:due_at]).to eq quiz.due_at
Draft State Quizzes: show multiple due dates Closes CNVS-9880 This patch enables observers watching students across multiple sections to see each section's due date for a quiz in the quizzes index page, it also fixes the dates students get to see when they're in a section other than the base one. (BREAKING?) API CHANGES ----------- --- ------- - when a student queries a quiz, the `due_at`, `lock_at`, and `unlock_at` dates they receive are that of the section they're in as oppossed to the quiz's global dates - when an observer queries a quiz, they receive the dates for the sections they're bound to in the `all_dates` field like teachers do TEST PLAN ---- ---- Two ways to test this patch: a simple way that tests only the case described by the ticket, or the comprehensive way. > The simple way - turn DS on - create a course with multiple sections - create a quiz and assign a due date to each section - as an observer who's watching more than 1 student in different sections, go to the quizzes index: - verify that you see "Multiple Dates" for due dates (and availability if you set them) - hover over the link and verify that you see the proper dates in the tooltip > The comprehensive way Check this out: https://gist.github.com/amireh/375171767da8303e1b71 Change-Id: I934cb47f0229a43713dc6b4a6d280c047a2263b9 Reviewed-on: https://gerrit.instructure.com/30083 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-02-13 17:23:06 +08:00
end
describe "only_visible_to_overrides" do
context "as a teacher" do
before :once do
course_with_teacher(active_all: true)
course_quiz(true)
end
it "returns the value for DA" do
@quiz.only_visible_to_overrides = true
json = quiz_serializer(scope: @teacher).as_json
expect(json[:quiz][:only_visible_to_overrides]).to be_truthy
@quiz.only_visible_to_overrides = false
json = quiz_serializer(scope: @teacher).as_json
expect(json[:quiz]).to have_key :only_visible_to_overrides
expect(json[:quiz][:only_visible_to_overrides]).to be_falsey
end
end
context "as a student" do
before :once do
course_with_student(active_all: true)
course_quiz(true)
end
it "is not in the hash" do
@quiz.only_visible_to_overrides = true
json = quiz_serializer(scope: @student).as_json
expect(json[:quiz]).not_to have_key :only_visible_to_overrides
end
end
end
end