forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyllabus_spec.rb
More file actions
165 lines (134 loc) · 5.57 KB
/
Copy pathsyllabus_spec.rb
File metadata and controls
165 lines (134 loc) · 5.57 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#
# Copyright (C) 2011 - 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')
require 'nokogiri'
describe "syllabus" do
def anonymous_syllabus_access_allowed(property, value=true)
course_with_teacher(:course => @course, :active_all => true)
@course.send("#{property}=", value)
@course.save!
get "/courses/#{@course.id}/assignments/syllabus"
expect(response).to be_success
page = Nokogiri::HTML(response.body)
expect(page.css('#identity a[href="/login"]')).not_to be_nil
expect(page.at_css('#syllabusContainer')).not_to be_nil
end
it "should allow access to public courses" do
anonymous_syllabus_access_allowed :is_public
end
it "should allow access to a public syllabus" do
anonymous_syllabus_access_allowed :public_syllabus
end
shared_examples_for "public syllabus file verifiers" do
it "should allow viewing available files in a public syllabus" do
course_factory(active_all: true)
attachment_model
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
@course.public_syllabus = true
@course.save!
get "/courses/#{@course.id}/assignments/syllabus"
expect(response).to be_success
page = Nokogiri::HTML(response.body)
expect(page.css('#identity a[href="/login"]')).not_to be_nil
link = page.at_css('#course_syllabus a')
expect(link.attributes['href'].value).to include("verifier=#{@attachment.uuid}")
end
it "should not allow viewing locked files in a public syllabus" do
course_factory(active_all: true)
attachment_model
@attachment.locked = true
@attachment.save!
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
@course.public_syllabus = true
@course.save!
get "/courses/#{@course.id}/assignments/syllabus"
expect(response).to be_success
page = Nokogiri::HTML(response.body)
expect(page.css('#identity a[href="/login"]')).not_to be_nil
link = page.at_css('#course_syllabus a')
expect(link.attributes['href'].value).to_not include("verifier=#{@attachment.uuid}")
end
end
shared_examples_for "public syllabus for authenticated file verifiers" do
it "should allow viewing available files in a public to authenticated syllabus" do
course_factory(active_all: true)
attachment_model
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
@course.public_syllabus_to_auth = true
@course.public_syllabus = false
@course.save!
get "/courses/#{@course.id}/assignments/syllabus"
expect(response).to be_success
page = Nokogiri::HTML(response.body)
expect(page.css('#identity a[href="/login"]')).not_to be_nil
link = page.at_css('#course_syllabus a')
expect(link.attributes['href'].value).to include("verifier=#{@attachment.uuid}")
end
it "should not allow viewing locked files in a public to authenticated syllabus" do
course_factory(active_all: true)
attachment_model
@attachment.locked = true
@attachment.save!
@course.syllabus_body = "<a href=\"/courses/#{@course.id}/files/#{@attachment.id}/download\">linky</a>"
@course.public_syllabus = false
@course.public_syllabus_to_auth = true
@course.save!
get "/courses/#{@course.id}/assignments/syllabus"
expect(response).to be_success
page = Nokogiri::HTML(response.body)
expect(page.css('#identity a[href="/login"]')).not_to be_nil
link = page.at_css('#course_syllabus a')
expect(link.attributes['href'].value).to_not include("verifier=#{@attachment.uuid}")
end
end
context "as an authenticated non-course user" do
before :each do
user_factory(active_all: true)
user_session(@user)
end
include_examples "public syllabus for authenticated file verifiers"
end
context "as an anonymous user" do
include_examples "public syllabus file verifiers"
end
context "as an authenticated non-course user" do
before :each do
user_factory(active_all: true)
user_session(@user)
end
include_examples "public syllabus file verifiers"
end
it "as an authenticated non-course user with public_syllabus_to_auth true" do
course_factory.public_syllabus_to_auth = true
course_factory.public_syllabus = false
course_factory.save
user_factory(active_user: true)
user_session(@user)
end
it "should display syllabus description on syllabus course home pages" do
course_with_teacher_logged_in(:active_all => true)
syllabus_body = "test syllabus body"
@course.syllabus_body = syllabus_body
@course.default_view = "syllabus"
@course.save!
get "/courses/#{@course.id}"
expect(response).to be_success
page = Nokogiri::HTML(response.body)
expect(page.at_css('#course_syllabus').text).to include(syllabus_body)
end
end