diff --git a/lib/lotus/action/flash.rb b/lib/lotus/action/flash.rb index fa88113a..3c237413 100644 --- a/lib/lotus/action/flash.rb +++ b/lib/lotus/action/flash.rb @@ -1,3 +1,5 @@ +require 'forwardable' + module Lotus module Action # Container useful to transport data with the HTTP session @@ -6,6 +8,11 @@ module Action # @since x.x.x # @api private class Flash + extend Forwardable + + # Delegate iteration to the underlying data storage + def_delegator :data, :each, :each + # Session key where the data is stored # # @since x.x.x diff --git a/test/action/flash_test.rb b/test/action/flash_test.rb new file mode 100644 index 00000000..9ad62e9f --- /dev/null +++ b/test/action/flash_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +describe Lotus::Action::Flash do + let (:flash) { Lotus::Action::Flash.new({},12312) } + + it '#each returns Enumerable' do + assert_kind_of Enumerator, flash.each + end + + describe 'iteration' do + + it '#each yields all flashes to the block' do + flash[:success], flash[:error] = 'Success', 'Error' + accum = [] + flash.each { |k, v| accum << { :"#{k}".to_sym => v} } + assert_equal accum, [{success: 'Success'}, {error: 'Error'}] + end + + after { flash.clear } + end +end