-
Notifications
You must be signed in to change notification settings - Fork 179
Add invalid announcements error widget and add related test (#2568) #5250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,24 @@ | ||
| <% @announcements.select(&:valid?).reject(&:completed?).each do |announcement| %> | ||
| <div id="announcement-<%=announcement.id%>" class="alert alert-<%= announcement.type %> announcement" role="alert"> | ||
| <div class="announcement-body"><%= raw OodAppkit.markdown.render(announcement.msg) %></div> | ||
| <% if announcement.dismissible? %> | ||
| <div class="d-grid gap-2 d-md-flex justify-content-md-end"> | ||
| <%= | ||
| button_to( | ||
| settings_path, | ||
| method: :post, | ||
| form_class: 'announcement-form', | ||
| class: "btn btn-#{announcement.type} me-md-2 announcement-button", | ||
| params: { settings: { announcements: { announcement.id => Time.now.localtime.strftime('%Y-%m-%d %H:%M:%S') } }, back: true } | ||
| ) do | ||
| announcement.button_text | ||
| end | ||
| %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| <% if announcement.parse_error? %> | ||
| <%= render partial: 'shared/announcement_error', locals: { announcement: announcement } %> | ||
| <% else %> | ||
| <div id="announcement-<%=announcement.id%>" class="alert alert-<%= announcement.type %> announcement" role="alert"> | ||
| <div class="announcement-body"><%= raw OodAppkit.markdown.render(announcement.msg) %></div> | ||
| <% if announcement.dismissible? %> | ||
| <div class="d-grid gap-2 d-md-flex justify-content-md-end"> | ||
| <%= | ||
| button_to( | ||
| settings_path, | ||
| method: :post, | ||
| form_class: 'announcement-form', | ||
| class: "btn btn-#{announcement.type} me-md-2 announcement-button", | ||
| params: { settings: { announcements: { announcement.id => Time.now.localtime.strftime('%Y-%m-%d %H:%M:%S') } }, back: true } | ||
| ) do | ||
| announcement.button_text | ||
| end | ||
| %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| <% end %> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <div class="alert alert-danger card"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't have to make a new alert partial for this error, we can use a shared alert structure by calling |
||
| <div class="card-header"> | ||
| Could not render announcement '<%= announcement.source || announcement.id || "unknown" %>' because of error | ||
| </div> | ||
| <div class="card-body"> | ||
| <p><%= announcement.error_message || announcement.msg %></p> | ||
| </div> | ||
| </div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| require 'test_helper' | ||
|
|
||
| class AnnouncementParseErrorTest < ActionDispatch::IntegrationTest | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can just add this to |
||
| test 'parsing error shows danger announcement' do | ||
| f = Tempfile.open(%w[announcement .yml]) | ||
| # write malformed YAML | ||
| f.write("::: this is not yaml: [\n") | ||
| f.close | ||
|
|
||
| stub_user_configuration({ announcement_path: [f.path] }) | ||
|
|
||
| begin | ||
| get '/' | ||
| assert_response :success | ||
|
|
||
| assert_select 'div.alert-danger.card' do | ||
| assert_select 'div.card-header', /Could not render announcement/ | ||
| assert_select 'div.card-body', /mapping values/ | ||
| end | ||
| ensure | ||
| stub_user_configuration({}) | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically want to do error checking in the controller (
ApplicationController#set_announcementsin this case)