forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendars_controller_spec.rb
More file actions
151 lines (133 loc) · 6.33 KB
/
Copy pathcalendars_controller_spec.rb
File metadata and controls
151 lines (133 loc) · 6.33 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
#
# 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__) + '/../sharding_spec_helper')
describe CalendarsController do
def course_event(date=nil)
date = Date.parse(date) if date
@event = @course.calendar_events.create(:title => "some assignment", :start_at => date, :end_at => date)
end
before(:once) { course_with_student(active_all: true) }
before(:each) { user_session(@student) }
describe "GET 'show2'" do
it "should not redirect to the old calendar even with default settings" do
get 'show2', :user_id => @user.id
expect(response).not_to redirect_to(calendar_url(anchor: ' '))
end
it "should assign variables" do
course_event
get 'show2', :user_id => @user.id
expect(response).to be_success
expect(assigns[:contexts]).not_to be_nil
expect(assigns[:contexts]).not_to be_empty
expect(assigns[:contexts][0]).to eql(@user)
expect(assigns[:contexts][1]).to eql(@course)
end
specs_require_sharding
it "should set permissions using contexts from the correct shard" do
# non-shard-aware code could use a shard2 id on shard1. this could grab the wrong course,
# or no course at all. this sort of aliasing used to break a permission check in show2
invalid_shard1_course_id = (Course.maximum(:id) || 0) + 1
@shard2.activate do
account = Account.create!
@course = account.courses.build
@course.id = invalid_shard1_course_id
@course.save!
@course.offer!
student_in_course(:active_all => true, :user => @user)
end
get 'show2', :user_id => @user.id
expect(response).to be_success
end
end
end
describe CalendarEventsApiController do
def course_event(date=Time.now)
@event = @course.calendar_events.create(:title => "some assignment", :start_at => date, :end_at => date)
end
describe "GET 'public_feed'" do
before(:once) do
course_with_student(:active_all => true)
course_event
@course.is_public = true
@course.save!
@course.assignments.create!(:title => "some assignment")
end
it "should assign variables" do
get 'public_feed', :feed_code => "course_#{@course.uuid}", :format => 'ics'
expect(response).to be_success
expect(assigns[:events]).to be_present
expect(assigns[:events][0]).to eql(@event)
end
it "should use the relevant event for that section, in the course feed" do
skip "requires changing the format of the course feed url to include user information"
s2 = @course.course_sections.create!(:name => 's2')
c1 = factory_with_protected_attributes(@event.child_events, :description => @event.description, :title => @event.title, :context => @course.default_section, :start_at => 2.hours.ago, :end_at => 1.hour.ago)
c2 = factory_with_protected_attributes(@event.child_events, :description => @event.description, :title => @event.title, :context => s2, :start_at => 3.hours.ago, :end_at => 2.hours.ago)
get 'public_feed', :feed_code => "course_#{@course.uuid}", :format => 'ics'
expect(response).to be_success
expect(assigns[:events]).to be_present
expect(assigns[:events]).to eq [c1]
end
context "for a user context" do
it "should use the relevant event for that section" do
s2 = @course.course_sections.create!(:name => 's2')
c1 = factory_with_protected_attributes(@event.child_events, :description => @event.description, :title => @event.title, :context => @course.default_section, :start_at => 2.hours.ago, :end_at => 1.hour.ago)
c2 = factory_with_protected_attributes(@event.child_events, :description => @event.description, :title => @event.title, :context => s2, :start_at => 3.hours.ago, :end_at => 2.hours.ago)
get 'public_feed', :feed_code => "user_#{@user.uuid}", :format => 'ics'
expect(response).to be_success
expect(assigns[:events]).to be_present
expect(assigns[:events]).to eq [c1]
end
it "should require authorization" do
get 'public_feed', :format => 'atom', :feed_code => @user.feed_code + 'x'
expect(response).to render_template('shared/unauthorized_feed')
end
it "should include absolute path for rel='self' link" do
get 'public_feed', :format => 'atom', :feed_code => @user.feed_code
feed = Atom::Feed.load_feed(response.body) rescue nil
expect(feed).not_to be_nil
expect(feed.links.first.rel).to match(/self/)
expect(feed.links.first.href).to match(/http:\/\//)
end
it "should include an author for each entry" do
get 'public_feed', :format => 'atom', :feed_code => @user.feed_code
feed = Atom::Feed.load_feed(response.body) rescue nil
expect(feed).not_to be_nil
expect(feed.entries).not_to be_empty
expect(feed.entries.all?{|e| e.authors.present?}).to be_truthy
end
it "should include description in event for unlocked assignment" do
assignment = @course.assignments.create!({
title: "assignment event test",
description: "foo",
due_at: Time.zone.now + (60 * 5)})
get 'public_feed', :format => 'ics', :feed_code => @user.feed_code
expect(response.body).to include("DESCRIPTION:#{assignment.description}")
end
it "should not include description in event for locked assignment" do
assignment = @course.assignments.create!({
title: "assignment event test",
description: "foo",
due_at: Time.zone.now + (60 * 10),
unlock_at: Time.zone.now + (60 * 5)})
get 'public_feed', :format => 'ics', :feed_code => @user.feed_code
expect(response.body).not_to include("DESCRIPTION:#{assignment.description}")
end
end
end
end