helpers: don't crash on unknown flash level
Errors generated by the `invisible-catcha` gem are reported as `flash[:error]` (which differs from Rail's usual `flash[:alert]`). Avoid crashing when the flash level passed to this helper is not known.
This commit is contained in:
parent
ad91ed362c
commit
68b112e00a
2 changed files with 12 additions and 3 deletions
|
@ -8,12 +8,15 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def flash_class(level, sticky: false, fixed: false)
|
def flash_class(level, sticky: false, fixed: false)
|
||||||
class_names = case level
|
class_names = []
|
||||||
|
|
||||||
|
case level
|
||||||
when 'notice'
|
when 'notice'
|
||||||
['alert-success']
|
class_names << 'alert-success'
|
||||||
when 'alert'
|
when 'alert'
|
||||||
['alert-danger']
|
class_names << 'alert-danger'
|
||||||
end
|
end
|
||||||
|
|
||||||
if sticky
|
if sticky
|
||||||
class_names << 'sticky'
|
class_names << 'sticky'
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,12 @@ describe ApplicationHelper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#flash_class" do
|
||||||
|
it { expect(flash_class('notice')).to eq 'alert-success' }
|
||||||
|
it { expect(flash_class('alert', sticky: true, fixed: true)).to eq 'alert-danger sticky alert-fixed' }
|
||||||
|
it { expect(flash_class('unknown-level')).to eq '' }
|
||||||
|
end
|
||||||
|
|
||||||
describe "#try_format_date" do
|
describe "#try_format_date" do
|
||||||
subject { try_format_date(date) }
|
subject { try_format_date(date) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue