|
23 | 23 | course_with_student(:active_all => true) |
24 | 24 | end |
25 | 25 |
|
26 | | - def course_announcement |
27 | | - @announcement = @course.announcements.create!( |
| 26 | + def course_announcement(opts = {}) |
| 27 | + @announcement = @course.announcements.create!({ |
28 | 28 | :title => "some announcement", |
29 | 29 | :message => "some message" |
30 | | - ) |
| 30 | + }.merge(opts)) |
31 | 31 | end |
32 | 32 |
|
33 | 33 | describe "GET 'index'" do |
@@ -73,13 +73,40 @@ def course_announcement |
73 | 73 | end |
74 | 74 |
|
75 | 75 | it "shows the 15 most recent announcements" do |
76 | | - announcements = [] |
77 | | - 16.times { announcements << course_announcement.id } |
78 | | - announcements.shift # Drop first announcement so we have the 15 most recent |
| 76 | + announcement_ids = [] |
| 77 | + 16.times { announcement_ids << course_announcement.id } |
| 78 | + announcement_ids.shift # Drop first announcement so we have the 15 most recent |
| 79 | + |
79 | 80 | get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code |
| 81 | + |
| 82 | + feed_entries = Atom::Feed.load_feed(response.body).entries |
| 83 | + feed_entry_ids = feed_entries.map{ |e| e.id.gsub(/.*topic_/, "").to_i } |
| 84 | + expect(feed_entry_ids).to match_array(announcement_ids) |
| 85 | + end |
| 86 | + |
| 87 | + it "only shows announcements that are visible to the caller" do |
| 88 | + normal_ann = @a # from the announcement_model in the before block |
| 89 | + closed_for_comments_ann = course_announcement(locked: true) |
| 90 | + post_delayed_ann = @course.announcements.build({ |
| 91 | + title: 'hi', |
| 92 | + message: 'blah', |
| 93 | + delayed_post_at: 1.day.from_now |
| 94 | + }) |
| 95 | + post_delayed_ann.workflow_state = 'post_delayed' |
| 96 | + post_delayed_ann.save! |
| 97 | + deleted_ann = course_announcement |
| 98 | + deleted_ann.destroy |
| 99 | + |
| 100 | + expect(closed_for_comments_ann).to be_locked |
| 101 | + expect(post_delayed_ann).to be_post_delayed |
| 102 | + expect(deleted_ann).to be_deleted |
| 103 | + visible_announcements = [normal_ann, closed_for_comments_ann] |
| 104 | + |
| 105 | + get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code |
| 106 | + |
80 | 107 | feed_entries = Atom::Feed.load_feed(response.body).entries |
81 | | - feed_entries.map!{ |e| e.id.gsub(/.*topic_/, "").to_i } |
82 | | - expect(feed_entries).to match_array(announcements) |
| 108 | + feed_entry_ids = feed_entries.map{ |e| e.id.gsub(/.*topic_/, "").to_i } |
| 109 | + expect(feed_entry_ids).to match_array(visible_announcements.map(&:id)) |
83 | 110 | end |
84 | 111 | end |
85 | 112 | end |
0 commit comments