forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmittable_spec.rb
More file actions
97 lines (85 loc) · 3.63 KB
/
Copy pathsubmittable_spec.rb
File metadata and controls
97 lines (85 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#
# Copyright (C) 2016 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
shared_examples_for "submittable" do
describe "visible_ids_by_user" do
before :once do
@course = course_factory(active_course: true)
@item_without_assignment = submittable_without_assignment
@item_with_assignment_and_only_vis, @assignment = submittable_and_assignment(only_visible_to_overrides: true)
@item_with_assignment_and_visible_to_all, @assignment2 = submittable_and_assignment(only_visible_to_overrides: false)
@item_with_override_for_section_with_no_students, @assignment3 = submittable_and_assignment(only_visible_to_overrides: true)
@item_with_no_override, @assignment4 = submittable_and_assignment(only_visible_to_overrides: true)
@course_section = @course.course_sections.create
@student1, @student2, @student3 = create_users(3, return_type: :record)
@course.enroll_student(@student2, enrollment_state: 'active')
@section = @course.course_sections.create!(name: "test section")
@section2 = @course.course_sections.create!(name: "second test section")
student_in_section(@section, user: @student1)
create_section_override_for_assignment(@assignment, {course_section: @section})
create_section_override_for_assignment(@assignment3, {course_section: @section2})
@course.reload
@vis_hash = submittable_class.visible_ids_by_user(course_id: @course.id, user_id: [@student1, @student2, @student3].map(&:id))
end
it "should return both topics for a student with an override" do
expect(@vis_hash[@student1.id].sort).to eq [
@item_without_assignment.id,
@item_with_assignment_and_only_vis.id,
@item_with_assignment_and_visible_to_all.id
].sort
end
it "should not return differentiated topics to a student with no overrides" do
expect(@vis_hash[@student2.id].sort).to eq [
@item_without_assignment.id,
@item_with_assignment_and_visible_to_all.id
].sort
end
end
end
describe DiscussionTopic do
let(:submittable_class) { DiscussionTopic }
include_examples "submittable" do
def submittable_without_assignment
discussion_topic_model(user: @teacher)
end
def submittable_and_assignment(opts = {})
assignment = @course.assignments.create!({
title: "some discussion assignment",
submission_types: 'discussion_topic'
}.merge(opts))
[assignment.discussion_topic, assignment]
end
end
end
describe WikiPage do
let(:submittable_class) { WikiPage }
include_examples "submittable" do
def submittable_without_assignment
wiki_page_model(course: @course)
end
def submittable_and_assignment(opts = {})
assignment = @course.assignments.create!({
title: "glorious page assignment",
submission_types: 'wiki_page'
}.merge(opts))
page = submittable_without_assignment
page.assignment_id = assignment.id
page.save!
[page, assignment]
end
end
end