From 3b9a6710d4a5738fa3f44471181a75383017f3d7 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Sat, 6 Jan 2018 23:13:49 +0100 Subject: [PATCH] Move warning helper into admin base helper This helper was never meant to be used outside of Alchemy's admin. --- app/helpers/alchemy/admin/base_helper.rb | 8 ++++++++ app/helpers/alchemy/base_helper.rb | 8 -------- spec/helpers/alchemy/admin/base_helper_spec.rb | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/helpers/alchemy/admin/base_helper.rb b/app/helpers/alchemy/admin/base_helper.rb index decadc59eb..6603fd017f 100644 --- a/app/helpers/alchemy/admin/base_helper.rb +++ b/app/helpers/alchemy/admin/base_helper.rb @@ -413,6 +413,14 @@ def render_message(type = :info, msg = nil, &blk) end end + # Logs a message in the Rails logger (warn level) + # and optionally displays an error message to the user. + def warning(message, text = nil) + Logger.warn(message, caller(0..0)) + return unless text.present? + render_message(:warning, text) + end + # Appends the current controller and action to body as css class. def alchemy_body_class [ diff --git a/app/helpers/alchemy/base_helper.rb b/app/helpers/alchemy/base_helper.rb index 5f5164aa01..702d434333 100644 --- a/app/helpers/alchemy/base_helper.rb +++ b/app/helpers/alchemy/base_helper.rb @@ -8,14 +8,6 @@ def shorten(text, length) text.truncate(length: length) end - # Logs a message in the Rails logger (warn level) - # and optionally displays an error message to the user. - def warning(message, text = nil) - Logger.warn(message, caller(0..0)) - return unless text.present? - render_message(:warning, text) - end - # Renders the flash partial (+alchemy/admin/partials/flash+) # # @param [String] notice The notice you want to display diff --git a/spec/helpers/alchemy/admin/base_helper_spec.rb b/spec/helpers/alchemy/admin/base_helper_spec.rb index 8c6b2c1fae..5a0b806954 100644 --- a/spec/helpers/alchemy/admin/base_helper_spec.rb +++ b/spec/helpers/alchemy/admin/base_helper_spec.rb @@ -276,6 +276,24 @@ module Alchemy end end + describe '#warning' do + subject { helper.warning('my warning') } + + it 'logs a warning' do + expect(Logger).to receive(:warn) + subject + end + + context 'if additional text is passed' do + subject { helper.warning('my warning', 'Something is missing') } + + it 'also renders a warning message' do + expect(helper).to receive(:render_message).with(:warning, 'Something is missing') + subject + end + end + end + describe "#render_icon" do subject { helper.render_icon(:info) }