Created
August 29, 2011 13:23
-
-
Save nruth/1178383 to your computer and use it in GitHub Desktop.
Introduce flash messages (notice/alert/error) to the session then hit a path and assert it does (not) render the flash messages; capybara/rspec2/rails3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#assumes use of capybara for request specs | |
require 'spec_helper' | |
describe "StaticPages" do | |
class FlashController < ApplicationController | |
def set_flash | |
flash[:notice] = params[:message] | |
flash[:error] = params[:message] | |
flash[:alert] = params[:message] | |
Rails.application.reload_routes! | |
redirect_to params[:path] | |
end | |
end | |
def set_flash_notice_and_redirect_to(message, path) | |
YourApp::Application.routes.draw do | |
match '/~set_flash' => "flash#set_flash", :defaults => {:path => path, :message => message} | |
end | |
visit "/~set_flash" | |
end | |
specify "should not render flash notices, since they will get cached" do | |
begin | |
set_flash_notice_and_redirect_to('foobar', '/') | |
page.should_not have_content("foobar") | |
set_flash_notice_and_redirect_to('foobar', some_path_which_renders_flash_messages) | |
page.should have_content("foobar") | |
ensure | |
Rails.application.reload_routes! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment