Skip to content

Commit

Permalink
correctly read RSS feeds from a url (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom authored Mar 21, 2023
1 parent b83dc55 commit bb08d6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 44 deletions.
12 changes: 11 additions & 1 deletion apps/dashboard/app/models/motd_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ def exist?
private

def load(motd_uri)
motd_uri ? open(motd_uri).read : nil
uri = URI.parse(motd_uri)

case uri.scheme
when 'http', 'https'
uri.read
when nil
File.read(uri.to_s)
else
Rails.logger.warn("Unknown scheme for #{motd_uri}. No MOTD is loaded")
nil
end
rescue Errno::ENOENT
Rails.logger.warn "MOTD File is missing; it was expected at #{motd_uri}"
nil
Expand Down
9 changes: 9 additions & 0 deletions apps/dashboard/test/models/motd_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ class MotdFileTest < ActiveSupport::TestCase
assert_equal '', motd_file.content
end

test 'when rss is a remote source' do
with_modified_env({ MOTD_PATH: 'https://www.osc.edu/rss.xml', MOTD_FORMAT: 'rss' }) do
formatter = MotdFile.new.formatter
assert_not_nil(formatter.title)
assert_not_nil(formatter.content)
assert_not_nil(formatter.content.items)
end
end

end
43 changes: 0 additions & 43 deletions apps/dashboard/test/models/motd_test.rb

This file was deleted.

0 comments on commit bb08d6e

Please sign in to comment.