forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor Reference to a ClassCache object, fix lazy lookup in Middlew…
…are so that anonymous classes are supported
- Loading branch information
1 parent
50ed1a2
commit 7b6bfe8
Showing
7 changed files
with
185 additions
and
19 deletions.
There are no files selected for viewing
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
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
50 changes: 50 additions & 0 deletions
50
actionpack/test/dispatch/middleware_stack/middleware_test.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'abstract_unit' | ||
require 'action_dispatch/middleware/stack' | ||
|
||
module ActionDispatch | ||
class MiddlewareStack | ||
class MiddlewareTest < ActiveSupport::TestCase | ||
class Omg; end | ||
|
||
{ | ||
'concrete' => Omg, | ||
'anonymous' => Class.new | ||
}.each do |name, klass| | ||
|
||
define_method("test_#{name}_klass") do | ||
mw = Middleware.new klass | ||
assert_equal klass, mw.klass | ||
end | ||
|
||
define_method("test_#{name}_==") do | ||
mw1 = Middleware.new klass | ||
mw2 = Middleware.new klass | ||
assert_equal mw1, mw2 | ||
end | ||
|
||
end | ||
|
||
def test_string_class | ||
mw = Middleware.new Omg.name | ||
assert_equal Omg, mw.klass | ||
end | ||
|
||
def test_double_equal_works_with_classes | ||
k = Class.new | ||
mw = Middleware.new k | ||
assert_operator mw, :==, k | ||
assert_operator mw, :!=, Class.new | ||
end | ||
|
||
def test_double_equal_works_with_strings | ||
mw = Middleware.new Omg | ||
assert_operator mw, :==, Omg.name | ||
end | ||
|
||
def test_double_equal_normalizes_strings | ||
mw = Middleware.new Omg | ||
assert_operator mw, :==, "::#{Omg.name}" | ||
end | ||
end | ||
end | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'abstract_unit' | ||
require 'active_support/dependencies' | ||
|
||
module ActiveSupport | ||
module Dependencies | ||
class ClassCacheTest < ActiveSupport::TestCase | ||
def setup | ||
@cache = ClassCache.new | ||
end | ||
|
||
def test_empty? | ||
assert @cache.empty? | ||
@cache[ClassCacheTest] = ClassCacheTest | ||
assert !@cache.empty? | ||
end | ||
|
||
def test_clear! | ||
assert @cache.empty? | ||
@cache[ClassCacheTest] = ClassCacheTest | ||
assert !@cache.empty? | ||
@cache.clear! | ||
assert @cache.empty? | ||
end | ||
|
||
def test_set_key | ||
@cache[ClassCacheTest] = ClassCacheTest | ||
assert @cache.key?(ClassCacheTest.name) | ||
end | ||
|
||
def test_set_rejects_strings | ||
@cache[ClassCacheTest.name] = ClassCacheTest | ||
assert @cache.empty? | ||
end | ||
|
||
def test_get_with_class | ||
@cache[ClassCacheTest] = ClassCacheTest | ||
assert_equal ClassCacheTest, @cache[ClassCacheTest] | ||
end | ||
|
||
def test_get_with_name | ||
@cache[ClassCacheTest] = ClassCacheTest | ||
assert_equal ClassCacheTest, @cache[ClassCacheTest.name] | ||
end | ||
|
||
def test_get_constantizes | ||
assert @cache.empty? | ||
assert_equal ClassCacheTest, @cache[ClassCacheTest.name] | ||
end | ||
|
||
def test_get_is_an_alias | ||
assert_equal @cache[ClassCacheTest], @cache.get(ClassCacheTest.name) | ||
end | ||
|
||
def test_new | ||
@cache.new ClassCacheTest | ||
assert @cache.key?(ClassCacheTest.name) | ||
end | ||
|
||
def test_new_rejects_strings | ||
@cache.new ClassCacheTest.name | ||
assert !@cache.key?(ClassCacheTest.name) | ||
end | ||
|
||
def test_new_returns_self | ||
v = @cache.new ClassCacheTest.name | ||
assert_equal @cache, v | ||
end | ||
|
||
def test_anonymous_class_fail | ||
assert_raises(ArgumentError) do | ||
@cache.new Class.new | ||
end | ||
|
||
assert_raises(ArgumentError) do | ||
x = Class.new | ||
@cache[x] = x | ||
end | ||
end | ||
end | ||
end | ||
end |
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