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 }
|
week: (Time.zone.today + 7.days).cweek }
|
||||||
end)
|
end)
|
||||||
|
|
||||||
before_action :set_week, if: -> { params[:period] }
|
before_action :set_week, if: -> { params[:period].present? }
|
||||||
before_action :set_events, only: [:show]
|
before_action :set_events, only: [:show]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ -20,7 +20,7 @@ class DigestsController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def set_week
|
def set_week
|
||||||
return unless params[:period][:week].present?
|
return if params[:period][:week].blank?
|
||||||
|
|
||||||
@week = Date.commercial params[:period][:year].to_i,
|
@week = Date.commercial params[:period][:year].to_i,
|
||||||
params[:period][:week].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
|
# Using kramdown, let's parse the html and render it as markdown text
|
||||||
# No idea why, but also needs to remove extraneous quote encoding :(
|
# No idea why, but also needs to remove extraneous quote encoding :(
|
||||||
def to_markdown(description, line_width = -1)
|
def to_markdown(desc, line_width = -1)
|
||||||
desc = sanitize description,
|
return '' if desc.blank?
|
||||||
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]
|
|
||||||
Kramdown::Document.new(spaces(desc), input: :html, line_width: line_width)
|
Kramdown::Document.new(spaces(desc), input: :html, line_width: line_width)
|
||||||
.to_kramdown
|
.to_kramdown
|
||||||
.gsub(/^#+\s+(.*)/, '**\1**')
|
.gsub(/^#+\s+(.*)/, '**\1**')
|
||||||
|
.gsub(/\*\*\*\*/, '**')
|
||||||
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
|
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
|
||||||
.remove(/[[:blank:]]+$/) # Remove extraneous spaces
|
.remove(/[[:blank:]]+$/) # Remove extraneous spaces
|
||||||
.remove(/{::}/) # Markdown artefact
|
.remove(/{::}/) # Markdown artefact
|
||||||
@ -74,6 +73,11 @@ module EventsHelper
|
|||||||
|
|
||||||
# Cleaner html elements, to correct things like <em> test</em>
|
# Cleaner html elements, to correct things like <em> test</em>
|
||||||
def spaces(desc)
|
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>')
|
desc.gsub(/<(strong|em|b|i)> /, ' <\1>')
|
||||||
.gsub(%r{ </(strong|em|b|i)>}, '</\1> ')
|
.gsub(%r{ </(strong|em|b|i)>}, '</\1> ')
|
||||||
.gsub(/[[:space:]]([,.])/, '\1')
|
.gsub(/[[:space:]]([,.])/, '\1')
|
||||||
|
@ -56,6 +56,21 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_redirected_to assigns(:orga)
|
assert_redirected_to assigns(:orga)
|
||||||
end
|
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
|
test 'should not create orga' do
|
||||||
assert_no_difference 'Orga.count' do
|
assert_no_difference 'Orga.count' do
|
||||||
post orgas_url, params: {
|
post orgas_url, params: {
|
||||||
|
@ -20,13 +20,15 @@ class EventsHelperTest < ActionView::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test 'HTML titles too strong' do
|
test 'HTML titles too strong' do
|
||||||
assert_equal '### Big
|
assert_equal '**Big**
|
||||||
|
|
||||||
', to_markdown('<h1>Big</h1>')
|
', to_markdown('<h1>Big</h1>')
|
||||||
assert_equal '### Big again
|
|
||||||
|
assert_equal '**Big again**
|
||||||
|
|
||||||
', to_markdown('<h2>Big again</h2>')
|
', to_markdown('<h2>Big again</h2>')
|
||||||
assert_equal '### **Too**
|
|
||||||
|
assert_equal '**Too**
|
||||||
|
|
||||||
', to_markdown('<h3><strong>Too</strong></h3>')
|
', to_markdown('<h3><strong>Too</strong></h3>')
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user