Skip to content

Commit

Permalink
Mutate session when injecting clearance to fix flash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jan 13, 2012
1 parent bc9281c commit 2085f03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/clearance/rack_session.rb
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions spec/controllers/flashes_controller_spec.rb
@@ -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.