diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-10-14 15:11:06 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-11-19 19:08:42 -0300 |
commit | 4da31d21bc0fe10fc329eb6d89ba52b27f8ed25e (patch) | |
tree | 7a924446d4429756ac06dd4574e15a87e00b8872 /activesupport/test | |
parent | 96cc08f24b0d1576573e09500faa4a9fd106f44e (diff) | |
download | rails-4da31d21bc0fe10fc329eb6d89ba52b27f8ed25e.tar.gz rails-4da31d21bc0fe10fc329eb6d89ba52b27f8ed25e.tar.bz2 rails-4da31d21bc0fe10fc329eb6d89ba52b27f8ed25e.zip |
Add initial tests for WeakHash.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/weak_hash_test.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/activesupport/test/weak_hash_test.rb b/activesupport/test/weak_hash_test.rb new file mode 100644 index 0000000000..7d1620dc34 --- /dev/null +++ b/activesupport/test/weak_hash_test.rb @@ -0,0 +1,33 @@ +require 'abstract_unit' +require 'active_support/weak_hash' + +class WeakHashTest < ActiveSupport::TestCase + + def setup + @weak_hash = ActiveSupport::WeakHash.new + @str = "A"; + @obj = Object.new + end + + test "allows us to assign value, and return assigned value" do + a = @str; b = @obj + assert_equal @weak_hash[a] = b, b + end + + test "should allow us to assign and read value" do + a = @str; b = @obj + assert_equal @weak_hash[a] = b, b + assert_equal @weak_hash[a], b + end + + test "should use object_id to identify objects" do + a = Object.new + @weak_hash[a] = "b" + assert_nil @weak_hash[a.dup] + end + + test "should find objects that have same hash" do + @weak_hash["a"] = "b" + assert_equal "b", @weak_hash["a"] + end +end |