forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannouncements_controller_spec.rb
More file actions
112 lines (96 loc) · 4.05 KB
/
Copy pathannouncements_controller_spec.rb
File metadata and controls
112 lines (96 loc) · 4.05 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
#
# 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 AnnouncementsController do
before :once do
course_with_student(:active_all => true)
end
def course_announcement(opts = {})
@announcement = @course.announcements.create!({
:title => "some announcement",
:message => "some message"
}.merge(opts))
end
describe "GET 'index'" do
it "should return unauthorized without a valid session" do
get 'index', :course_id => @course.id
assert_unauthorized
end
it "should redirect 'disabled', if disabled by the teacher" do
user_session(@user)
@course.update_attribute(:tab_configuration, [{'id'=>14,'hidden'=>true}])
get 'index', :course_id => @course.id
expect(response).to be_redirect
expect(flash[:notice]).to match(/That page has been disabled/)
end
end
describe "GET 'public_feed.atom'" do
before :once do
@context = @course
announcement_model
end
it "should require authorization" do
get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code + 'x'
expect(assigns[:problem]).to match /The verification code does not match/
end
it "should include absolute path for rel='self' link" do
get 'public_feed', :format => 'atom', :feed_code => @enrollment.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 => @enrollment.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 "shows the 15 most recent announcements" do
announcement_ids = []
16.times { announcement_ids << course_announcement.id }
announcement_ids.shift # Drop first announcement so we have the 15 most recent
get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code
feed_entries = Atom::Feed.load_feed(response.body).entries
feed_entry_ids = feed_entries.map{ |e| e.id.gsub(/.*topic_/, "").to_i }
expect(feed_entry_ids).to match_array(announcement_ids)
end
it "only shows announcements that are visible to the caller" do
normal_ann = @a # from the announcement_model in the before block
closed_for_comments_ann = course_announcement(locked: true)
post_delayed_ann = @course.announcements.build({
title: 'hi',
message: 'blah',
delayed_post_at: 1.day.from_now
})
post_delayed_ann.workflow_state = 'post_delayed'
post_delayed_ann.save!
deleted_ann = course_announcement
deleted_ann.destroy
expect(closed_for_comments_ann).to be_locked
expect(post_delayed_ann).to be_post_delayed
expect(deleted_ann).to be_deleted
visible_announcements = [normal_ann, closed_for_comments_ann]
get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code
feed_entries = Atom::Feed.load_feed(response.body).entries
feed_entry_ids = feed_entries.map{ |e| e.id.gsub(/.*topic_/, "").to_i }
expect(feed_entry_ids).to match_array(visible_announcements.map(&:id))
end
end
end