Skip to content

Commit e42a8ef

Browse files
committed
Announcements rss feed - return 15 most recent
Instead of the 15 oldest Fixes CNVS-13022 Test Plan: - Create 16 announcements - Pull the RSS Feed and observe that the most recent 15 are displayed, not the oldest 15 Change-Id: I1e612d7f271ab6d043672fe3a1cf24f1271a3ae4 Reviewed-on: https://gerrit.instructure.com/50334 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Adam Stone <astone@instructure.com> Product-Review: Benjamin Porter <bporter@instructure.com>
1 parent 0bf9d80 commit e42a8ef

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

app/controllers/announcements_controller.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ class AnnouncementsController < ApplicationController
2323
before_filter { |c| c.active_tab = "announcements" }
2424

2525
def index
26-
if authorized_action(@context, @current_user, :read)
27-
return if @context.class.const_defined?('TAB_ANNOUNCEMENTS') && !tab_enabled?(@context.class::TAB_ANNOUNCEMENTS)
28-
log_asset_access("announcements:#{@context.asset_string}", "announcements", "other")
29-
respond_to do |format|
30-
format.html do
31-
add_crumb(t(:announcements_crumb, "Announcements"))
32-
can_create = @context.announcements.scoped.new.grants_right?(@current_user, session, :create)
33-
js_env :permissions => {
34-
:create => can_create,
35-
:moderate => can_create
36-
}
37-
js_env :is_showing_announcements => true
38-
js_env :atom_feed_url => feeds_announcements_format_path((@context_enrollment || @context).feed_code, :atom)
39-
end
26+
return unless authorized_action(@context, @current_user, :read)
27+
return if @context.class.const_defined?('TAB_ANNOUNCEMENTS') && !tab_enabled?(@context.class::TAB_ANNOUNCEMENTS)
28+
29+
log_asset_access("announcements:#{@context.asset_string}", "announcements", "other")
30+
respond_to do |format|
31+
format.html do
32+
add_crumb(t(:announcements_crumb, "Announcements"))
33+
can_create = @context.announcements.scoped.new.grants_right?(@current_user, session, :create)
34+
js_env :permissions => {
35+
:create => can_create,
36+
:moderate => can_create
37+
}
38+
js_env :is_showing_announcements => true
39+
js_env :atom_feed_url => feeds_announcements_format_path((@context_enrollment || @context).feed_code, :atom)
4040
end
4141
end
4242
end
@@ -47,7 +47,8 @@ def show
4747

4848
def public_feed
4949
return unless get_feed_context
50-
announcements = @context.announcements.active.order(:posted_at).limit(15).reject{|a| a.locked_for?(@current_user, :check_policies => true) }
50+
announcements = @context.announcements.active.order('posted_at DESC').limit(15).reject{|a| a.locked_for?(@current_user, :check_policies => true) }
51+
5152
respond_to do |format|
5253
format.atom {
5354
feed = Atom::Feed.new do |f|
@@ -83,5 +84,4 @@ def public_feed
8384
}
8485
end
8586
end
86-
8787
end

spec/controllers/announcements_controller_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,15 @@ def course_announcement
7171
expect(feed.entries).not_to be_empty
7272
expect(feed.entries.all?{|e| e.authors.present?}).to be_truthy
7373
end
74+
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
79+
get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code
80+
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)
83+
end
7484
end
7585
end

0 commit comments

Comments
 (0)