This project is archived and is in readonly mode.
Immediate flash values not accessible in tests
-
josh
- State changed from new to open
- Assigned user set to josh
I think you should have to test it with flash.now not just flash.
assert_equal 'Invalid', request.session["flash"].now["notice"] # but I guess flash_now is okay too assert_equal 'Invalid', request.session["flash_now"].now["notice"]Not sure if that works already or not.
-
Andreas Neuhaus
I modified the test to assert_equal flash.now, but it still doesn't seem to work (patch attached).
I also created a new rails project with a controller action that sets a flash.now message, but wasn't able to access that message in the corresponding functional test. It looks like flash.now is an ActionController::Flash::FlashNow object in the test, but its @flash is empty...
-
Andreas Neuhaus
New patch with git metainfo
-
josh
- State changed from open to invalid
Flash nows aren't store in the session response. They are just pushed directly to the template. So the best way to test them would be with an "assert_select".
If you come up with a clever implementation for testing them, please let me know.
-
Andreas Neuhaus
I dug a little deeper into this problem and found out, that the flash is swept in process_cleanup. A view can display immediate flash values, because it accesses the flash before being swept. However, with test assertions, process_cleanup is done before and therefore the immediate values have been swept already.
So my goal was to make the same flash values available to the test that are used in views. Attached is a patch, that modified flash.rb to do the sweep before processing the request instead on cleanup, plus tests that make sure that normal flash values as well as immediate flash values can be asserted in tests.
-
Andreas Neuhaus
Ouch. Even though all tests pass fine, it seems that the flash isn't swept in real applications with this patch.
-
Andreas Neuhaus
Attached a new patch where flash sweeping is done after assign_shortcuts, so that @_session can be checked. The previous patch had a problem accessing the session since assign_shortcut wasn't run before.
It now works as expected.
Unfortunately, I can't reopen the ticket.
-
Michael Koziarski
- State changed from invalid to open
-
Nathan Wilmes
We took a slightly different approach to the same sorts of problems in ticket 121. Our goal with assert_showing_flash was to confirm that the app uses flash versus flash.now correctly.
-
josh
I'm getting some failing tests now. I have a feeling its related to one of Pratik's deprecate instance variables commits.
1) Failure: test_flash(ComponentsTest) [./test/controller/components_test.rb:114:in `test_flash' ./test/../lib/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:59:in `__send__' ./test/../lib/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:59:in `run']: <"My stoney baby"> expected but was <"no flash">. -
Andreas Neuhaus
Looks like my patched flash.rb wasn't aware of component processing. I'm not used to components, but they seem to work by calling process of the component's controller. Previously, that call swept the flash. I modified flash.rb to not sweep the flash if processing a component. I'm not sure why this didn't occur in earlier revisions of rails, but now it looks correct and all tests pass. New patch attached.
-
Michael Koziarski
Why does the new patch switch to if @_session rather than @_request?
-
Andreas Neuhaus
Mmh, not sure. I guess I accidently mixed it up. I changed it back to @_session (attached patch updated).
I'm not sure if the @_session check is needed anyway (except for a tiny runtime improvement if sessions are disabled because the sweep method isn't run). I tried to remove the @_session check and all tests still passed.
-
Repository
- State changed from open to resolved
(from [74eed6290e63111d1aad2b181692a84f4f040aea]) Fixed flash.now not being accessible in tests. Flash sweeping is now done before action processing instead after
Signed-off-by: Michael Koziarski
[#10 state:resolved]
