Permalink
Browse files

Mutate session when injecting clearance to fix flash messages

  • Loading branch information...
1 parent bc9281c commit 2085f03cf41a242cbbe51ddf0fbeadf32cb6bb86 @jferris jferris committed Jan 13, 2012
Showing with 34 additions and 2 deletions.
  1. +2 −2 lib/clearance/rack_session.rb
  2. +32 −0 spec/controllers/flashes_controller_spec.rb
@@ -6,8 +6,8 @@ def initialize(app)
def call(env)
session = Clearance::Session.new(env)
- env_with_clearance = env.merge(:clearance => session)
- response = @app.call(env_with_clearance)
+ env[:clearance] = session
+ response = @app.call(env)
session.add_cookie_to_headers response[1]
response
end
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+class FlashesController < ActionController::Base
+ include Clearance::Authentication
+
+ def set_flash
+ flash[:notice] = params[:message]
+ redirect_to view_flash_url
+ end
+
+ def view_flash
+ render :text => "<html><body>#{flash[:notice]}</body></html>"
+ end
+end
+
+describe FlashesController do
+ before do
+ Rails.application.routes.draw do
+ match "set_flash" => "flashes#set_flash"
+ match "view_flash" => "flashes#view_flash"
+ end
+ end
+
+ after do
+ Rails.application.reload_routes!
+ end
+
+ it "sets and views a flash" do
+ visit "/set_flash?message=hello"
+ page.should have_content("hello")
+ end
+end

0 comments on commit 2085f03

Please sign in to comment.