diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-11-19 11:54:19 -0800 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-11-19 12:11:26 -0800 |
commit | cafed35b610d830049b7dffd924cbcdeedab72bb (patch) | |
tree | ab617d9d93f2e3e8e32fd1ed2a4861cdb58b837d /activerecord/test | |
parent | e0c938759fdb2f82057aa46a8410533a60424114 (diff) | |
download | rails-cafed35b610d830049b7dffd924cbcdeedab72bb.tar.gz rails-cafed35b610d830049b7dffd924cbcdeedab72bb.tar.bz2 rails-cafed35b610d830049b7dffd924cbcdeedab72bb.zip |
Add tests for `TypeMap#fetch` and push up to `TypeMap`
It doesn't make sense for the subclass to implement this method, and not
have it on the parent. We can also DRY up the implementation of
`#lookup` to be defined in terms of fetch, which will give us a single
point of entry
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/type/type_map_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/type/type_map_test.rb b/activerecord/test/cases/type/type_map_test.rb index 4e32f92dd0..1e4eba1961 100644 --- a/activerecord/test/cases/type/type_map_test.rb +++ b/activerecord/test/cases/type/type_map_test.rb @@ -124,6 +124,21 @@ module ActiveRecord assert_equal mapping.lookup(3), 'string' assert_kind_of Type::Value, mapping.lookup(4) end + + def test_fetch + mapping = TypeMap.new + mapping.register_type(1, "string") + + assert_equal "string", mapping.fetch(1) { "int" } + assert_equal "int", mapping.fetch(2) { "int" } + end + + def test_fetch_yields_args + mapping = TypeMap.new + + assert_equal "foo-1-2-3", mapping.fetch("foo", 1, 2, 3) { |*args| args.join("-") } + assert_equal "bar-1-2-3", mapping.fetch("bar", 1, 2, 3) { |*args| args.join("-") } + end end end end |