Skip to content

Commit

Permalink
Use freeze instead of close!
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Apr 6, 2011
1 parent 0ca69ca commit 29592a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
7 changes: 2 additions & 5 deletions actionpack/lib/action_dispatch/middleware/cookies.rb
Expand Up @@ -115,13 +115,10 @@ def initialize(secret = nil, host = nil, secure = false)
@delete_cookies = {}
@host = host
@secure = secure
@closed = false
@cookies = {}
end

attr_reader :closed
alias :closed? :closed
def close!; @closed = true end
alias :closed? :frozen?

# Returns the value of the cookie by +name+, or +nil+ if no such cookie exists.
def [](name)
Expand Down Expand Up @@ -330,7 +327,7 @@ def call(env)
[status, headers, body]
ensure
cookie_jar = ActionDispatch::Request.new(env).cookie_jar unless cookie_jar
cookie_jar.close!
cookie_jar.freeze
end
end
end
12 changes: 3 additions & 9 deletions actionpack/lib/action_dispatch/middleware/flash.rb
Expand Up @@ -43,12 +43,9 @@ class Flash
class FlashNow #:nodoc:
def initialize(flash)
@flash = flash
@closed = false
end

attr_reader :closed
alias :closed? :closed
def close!; @closed = true end
alias :closed? :frozen?

def []=(k, v)
raise ClosedError, :flash if closed?
Expand Down Expand Up @@ -76,12 +73,9 @@ class FlashHash < Hash
def initialize #:nodoc:
super
@used = Set.new
@closed = false
end

attr_reader :closed
alias :closed? :closed
def close!; @closed = true end
alias :closed? :frozen?

def []=(k, v) #:nodoc:
raise ClosedError, :flash if closed?
Expand Down Expand Up @@ -200,7 +194,7 @@ def call(env)
if !flash_hash.empty? || session.key?('flash')
session["flash"] = flash_hash
end
flash_hash.close!
flash_hash.freeze
end

if session.key?('flash') && session['flash'].empty?
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/dispatch/cookies_test.rb
Expand Up @@ -502,10 +502,16 @@ class CookiesIntegrationTest < ActionDispatch::IntegrationTest

class TestController < ActionController::Base
def dont_set_cookies
# initialize lazy loaded objects
cookies.permanent
cookies.signed
head :ok
end

def set_cookies
# initialize lazy loaded objects
cookies.permanent
cookies.signed
cookies["that"] = "hello"
head :ok
end
Expand Down

0 comments on commit 29592a7

Please sign in to comment.