forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfo_controller_spec.rb
More file actions
98 lines (89 loc) · 3.34 KB
/
Copy pathinfo_controller_spec.rb
File metadata and controls
98 lines (89 loc) · 3.34 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
#
# Copyright (C) 2011 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')
describe InfoController do
describe "GET 'health_check'" do
it "should work" do
get 'health_check'
expect(response).to be_success
expect(response.body).to eq 'canvas ok'
end
it "should respond_to json" do
request.accept = "application/json"
Canvas.stubs(:revision).returns("Test Proc")
get "health_check"
expect(response).to be_success
json = JSON.parse(response.body)
expect(json).to have_key('installation_uuid')
json.delete('installation_uuid')
expect(json).to eq({ "status" => "canvas ok", "revision" => "Test Proc" })
end
end
describe "GET 'help_links'" do
it "should work" do
get 'help_links'
expect(response).to be_success
end
it "should set the locale for translated help link text from the current user" do
user = User.create!(locale: 'es')
user_session(user)
# create and save account instance so that we don't invoke I18n's
# localizer lambda in a request filter prior to loading necessary
# users, accounts, context etc.
Account.default
get 'help_links'
expect(I18n.locale.to_s).to eq 'es'
end
it "should filter the links based on the current user's role" do
account = Account.create!
Account::HelpLinks.stubs(:default_links).returns([
{
:available_to => ['student'],
:text => 'Ask Your Instructor a Question',
:subtext => 'Questions are submitted to your instructor',
:url => '#teacher_feedback',
:is_default => 'true'
},
{
:available_to => ['user', 'student', 'teacher', 'admin'],
:text => 'Search the Canvas Guides',
:subtext => 'Find answers to common questions',
:url => 'http://community.canvaslms.com/community/answers/guides',
:is_default => 'true'
},
{
:available_to => ['user', 'student', 'teacher', 'admin'],
:text => 'Report a Problem',
:subtext => 'If Canvas misbehaves, tell us about it',
:url => '#create_ticket',
:is_default => 'true'
}
])
LoadAccount.stubs(:default_domain_root_account).returns(account)
admin = account_admin_user active_all: true
user_session(admin)
get 'help_links'
# because this is a normal application session, the response is prepended
# with our anti-csrf measure
json = response.body
anti_csrf = 'while(1);'
links = JSON.parse(json[anti_csrf.length..json.length-1])
expect(links.select {|link| link[:text] == 'Ask Your Instructor a Question'}.size).to eq 0
end
end
end