minor refactoring of flash messages

This commit is contained in:
Hauke Klement
2015-03-23 16:42:57 +01:00
parent 2e596110fd
commit 4eef3d70d5
12 changed files with 46 additions and 49 deletions

View File

@ -24,7 +24,7 @@ end
def expect_flash_message(type, message = nil)
it 'displays a flash message' do
if message
expect(flash[type]).to eq(message.is_a?(String) ? message : I18n.t(message))
expect(flash[type]).to eq(obtain_message(message))
else
expect(flash[type]).to be_present
end
@ -59,13 +59,25 @@ def expect_template(template)
end
end
def obtain_object(value)
case value
def obtain_object(object)
case object
when Proc
value.call
object.call
when Symbol
send(value)
send(object)
else
value
object
end
end
private :obtain_object
def obtain_message(object)
if object.is_a?(String)
object
elsif I18n.translation_present?(object)
I18n.t(object)
else
send(object)
end
end
private :obtain_message