forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_view_spec.rb
More file actions
84 lines (72 loc) · 3.26 KB
/
Copy pathpage_view_spec.rb
File metadata and controls
84 lines (72 loc) · 3.26 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
#
# 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')
describe "page views" do
before(:each) do
Setting.set('enable_page_views', 'db')
end
it "should record the context when commenting on a discussion" do
user_with_pseudonym(active_all: 1)
course_with_teacher_logged_in(active_all: 1, user: @user)
@topic = @course.discussion_topics.create!
post "/api/v1/courses/#{@course.id}/discussion_topics/#{@topic.id}/entries", :message => 'hello'
expect(response).to be_success
pv = PageView.last
expect(pv.context).to eq @course
expect(pv.controller).to eq 'discussion_topics_api'
expect(pv.action).to eq 'add_entry'
end
it "should record get request for api request" do
course_with_teacher(active_all: 1, user: user_with_pseudonym)
@topic = @course.discussion_topics.create!
get "/api/v1/courses/#{@course.id}/discussion_topics/#{@topic.id}/entries", access_token: @user.access_tokens.create!.full_token
pv = PageView.last
expect(pv.http_method).to eq 'get'
end
it "should not record gets for api request when setting disabled" do
Setting.set('create_get_api_page_views', 'false')
course_with_teacher(active_all: 1, user: user_with_pseudonym)
@topic = @course.discussion_topics.create!
PageView.any_instance.expects(:store).never
get "/api/v1/courses/#{@course.id}/discussion_topics/#{@topic.id}/entries", access_token: @user.access_tokens.create!.full_token
end
it "records the developer key when an access token was used" do
user_with_pseudonym(active_all: 1)
course_with_teacher(active_all: 1, user: @user)
@topic = @course.discussion_topics.create!
post "/api/v1/courses/#{@course.id}/discussion_topics/#{@topic.id}/entries", :message => 'hello', access_token: @user.access_tokens.create!.full_token
expect(response).to be_success
pv = PageView.last
expect(pv.context).to eq @course
expect(pv.controller).to eq 'discussion_topics_api'
expect(pv.action).to eq 'add_entry'
expect(pv.developer_key).to eq DeveloperKey.default
end
describe "update" do
it "should set the canvas meta header on interaction_seconds update" do
course_with_teacher_logged_in(:active_all => 1)
page_view = PageView.new
page_view.request_id = rand(10000000).to_s
page_view.user = @user
page_view.save
xhr :put, "/page_views/#{page_view.id}", :page_view_token => page_view.token, :interaction_seconds => 42
expect(response).to be_success
expect(response['X-Canvas-Meta']).to match(/r=#{page_view.request_id}\|#{page_view.created_at.iso8601(2)}\|42;/)
end
end
end