Organisation and event description can be empty and won't generate an error
This commit is contained in:
parent
70d55e0c26
commit
e137a8c45b
@ -10,7 +10,7 @@ class DigestsController < ApplicationController
|
||||
week: (Time.zone.today + 7.days).cweek }
|
||||
end)
|
||||
|
||||
before_action :set_week, if: -> { params[:period] }
|
||||
before_action :set_week, if: -> { params[:period].present? }
|
||||
before_action :set_events, only: [:show]
|
||||
|
||||
def show
|
||||
@ -20,7 +20,7 @@ class DigestsController < ApplicationController
|
||||
private
|
||||
|
||||
def set_week
|
||||
return unless params[:period][:week].present?
|
||||
return if params[:period][:week].blank?
|
||||
|
||||
@week = Date.commercial params[:period][:year].to_i,
|
||||
params[:period][:week].to_i
|
||||
|
@ -57,14 +57,13 @@ module EventsHelper
|
||||
|
||||
# Using kramdown, let's parse the html and render it as markdown text
|
||||
# No idea why, but also needs to remove extraneous quote encoding :(
|
||||
def to_markdown(description, line_width = -1)
|
||||
desc = sanitize description,
|
||||
tags: %w[p br h1 h2 h3 h4 table tr th td ul ol li a strong
|
||||
b em i sub sup],
|
||||
attributes: %w[href]
|
||||
def to_markdown(desc, line_width = -1)
|
||||
return '' if desc.blank?
|
||||
|
||||
Kramdown::Document.new(spaces(desc), input: :html, line_width: line_width)
|
||||
.to_kramdown
|
||||
.gsub(/^#+\s+(.*)/, '**\1**')
|
||||
.gsub(/\*\*\*\*/, '**')
|
||||
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
|
||||
.remove(/[[:blank:]]+$/) # Remove extraneous spaces
|
||||
.remove(/{::}/) # Markdown artefact
|
||||
@ -74,6 +73,11 @@ module EventsHelper
|
||||
|
||||
# Cleaner html elements, to correct things like <em> test</em>
|
||||
def spaces(desc)
|
||||
desc = sanitize desc,
|
||||
tags: %w[p br h1 h2 h3 h4 table tr th td ul ol li a strong
|
||||
b em i sub sup],
|
||||
attributes: %w[href]
|
||||
|
||||
desc.gsub(/<(strong|em|b|i)> /, ' <\1>')
|
||||
.gsub(%r{ </(strong|em|b|i)>}, '</\1> ')
|
||||
.gsub(/[[:space:]]([,.])/, '\1')
|
||||
|
@ -56,6 +56,21 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to assigns(:orga)
|
||||
end
|
||||
|
||||
test 'should create orga without content' do
|
||||
assert_difference 'Orga.count' do
|
||||
post orgas_url, params: {
|
||||
orga: {
|
||||
kind_id: @orga.kind_id,
|
||||
name: @orga.name,
|
||||
region_id: @orga.region.id,
|
||||
url: @orga.url
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to assigns(:orga)
|
||||
end
|
||||
|
||||
test 'should not create orga' do
|
||||
assert_no_difference 'Orga.count' do
|
||||
post orgas_url, params: {
|
||||
|
@ -20,13 +20,15 @@ class EventsHelperTest < ActionView::TestCase
|
||||
end
|
||||
|
||||
test 'HTML titles too strong' do
|
||||
assert_equal '### Big
|
||||
assert_equal '**Big**
|
||||
|
||||
', to_markdown('<h1>Big</h1>')
|
||||
assert_equal '### Big again
|
||||
|
||||
assert_equal '**Big again**
|
||||
|
||||
', to_markdown('<h2>Big again</h2>')
|
||||
assert_equal '### **Too**
|
||||
|
||||
assert_equal '**Too**
|
||||
|
||||
', to_markdown('<h3><strong>Too</strong></h3>')
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user