diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2013-12-12 21:10:03 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2013-12-12 21:10:03 -0700 |
commit | 0b142a6f842051e3f1f3c146d1e1318050274352 (patch) | |
tree | 525e83b0d925617f0634e3f7f38a84e885abfe34 /activerecord/test/cases/relation | |
parent | b474d06d5ea646c8145b07c8acbf1181c9e0b2aa (diff) | |
download | rails-0b142a6f842051e3f1f3c146d1e1318050274352.tar.gz rails-0b142a6f842051e3f1f3c146d1e1318050274352.tar.bz2 rails-0b142a6f842051e3f1f3c146d1e1318050274352.zip |
Add a bunch of Relation -> Array delegate methods to the whitelist. This won't last - aim to switch back to a blacklist for mutator methods.
Diffstat (limited to 'activerecord/test/cases/relation')
-rw-r--r-- | activerecord/test/cases/relation/delegation_test.rb | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/activerecord/test/cases/relation/delegation_test.rb b/activerecord/test/cases/relation/delegation_test.rb index b56dd5e5db..f295ccbc6a 100644 --- a/activerecord/test/cases/relation/delegation_test.rb +++ b/activerecord/test/cases/relation/delegation_test.rb @@ -25,16 +25,9 @@ module ActiveRecord end end - class DelegationAssociationTest < DelegationTest - def target - Post.first.comments - end - - [:&, :+, :[], :all?, :collect, :detect, :each, :each_cons, - :each_with_index, :flat_map, :group_by, :include?, :length, - :map, :none?, :one?, :reverse, :sample, :second, :sort, :sort_by, - :to_ary, :to_set, :to_xml, :to_yaml].each do |method| - test "association delegates #{method} to Array" do + module DelegationWhitelistBlacklistTests + ActiveRecord::Delegation::ARRAY_DELEGATES.each do |method| + define_method "test_delegates_#{method}_to_Array" do assert_respond_to target, method end end @@ -42,34 +35,27 @@ module ActiveRecord [:compact!, :flatten!, :reject!, :reverse!, :rotate!, :shuffle!, :slice!, :sort!, :sort_by!, :delete_if, :keep_if, :pop, :shift, :delete_at, :compact].each do |method| - test "#{method} is not delegated to Array" do + define_method "test_#{method}_is_not_delegated_to_Array" do assert_raises(NoMethodError) { call_method(target, method) } end end end - class DelegationRelationTest < DelegationTest - fixtures :comments + class DelegationAssociationTest < DelegationTest + include DelegationWhitelistBlacklistTests def target - Comment.all + Post.first.comments end + end - [:&, :+, :[], :all?, :collect, :detect, :each, :each_cons, - :each_with_index, :flat_map, :group_by, :include?, :length, - :map, :none?, :one?, :reverse, :sample, :second, :sort, :sort_by, - :to_ary, :to_set, :to_xml, :to_yaml].each do |method| - test "relation delegates #{method} to Array" do - assert_respond_to target, method - end - end + class DelegationRelationTest < DelegationTest + include DelegationWhitelistBlacklistTests - [:compact!, :flatten!, :reject!, :reverse!, :rotate!, - :shuffle!, :slice!, :sort!, :sort_by!, :delete_if, - :keep_if, :pop, :shift, :delete_at, :compact].each do |method| - test "#{method} is not delegated to Array" do - assert_raises(NoMethodError) { call_method(target, method) } - end + fixtures :comments + + def target + Comment.all end end end |