Ciao a tutti,
con Rails 2.0 ho fatto dei test che impostano il contenuto del Flash:
def test_show_should_redirect_to_title_and_keep_flash
flash_hash = ActionController::Flash::FlashHash.new
flash_hash.now[:par1] = ‘val1’
flash_hash.now[:par2] = ‘val2’
get :show, { :id => pages(:correct).id }, { :flash => flash_hash }
assert_redirected_to :action => ‘title’, :id => ‘correct-page’
assert_not_nil flash[:par1], ‘par1’
assert_not_nil flash[:par2], ‘par2’
end
Come si puo vedere creo un FlasHash (è l’oggetto che contiene i messaggi
Flash), ci metto dentro 2 valori, passo questo oggetto nell’hash delle
variabili di sessione e quindi controllo che, dopo la chiamata del
metodo
sooot test, il contenuto del Flash sia rimasto invariato.
Tutto questo funziona bene con Rails 2.0, ma da il seguente errore con
Rails
2.1
- Failure:
test_show_should_redirect_to_title_and_keep_flash(PagesControllerTest)
[/home/gimmi/workspace/webnotes/test/functional/pages_controller_test.rb:90:in
`test_show_should_redirect_to_title_and_keep_flash’
/home/gimmi/workspace/webnotes/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/testing/setup_and_teardown.rb:59:in
`send’
/home/gimmi/workspace/webnotes/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/testing/setup_and_teardown.rb:59:in
`run’]:
par1.
expected to not be nil.
Sembra che l’oggetto FlashHash non arrivi piu al metodo sotto test…
qualche
idea??
Grazie!