Skip to content

Commit

Permalink
Move warning helper into admin base helper
Browse files Browse the repository at this point in the history
This helper was never meant to be used outside of Alchemy's admin.
  • Loading branch information
tvdeyen committed Jan 6, 2018
1 parent d6adca6 commit 3b9a671
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions app/helpers/alchemy/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/alchemy/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/alchemy/admin/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit 3b9a671

Please sign in to comment.