1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/relation/delegation_test.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

require "cases/helper"
require "models/post"
require "models/comment"
module ActiveRecord
module DelegationWhitelistTests
ARRAY_DELEGATES = [
:+, :-, :|, :&, :[], :shuffle,
2015-05-27 23:37:21 -04:00
:all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
:exclude?, :find_all, :flat_map, :group_by, :include?, :length,
:map, :none?, :one?, :partition, :reject, :reverse,
:sample, :second, :sort, :sort_by, :third,
:to_ary, :to_set, :to_xml, :to_yaml, :join,
2017-03-10 09:32:05 -05:00
:in_groups, :in_groups_of, :to_sentence, :to_formatted_s, :as_json
]
ARRAY_DELEGATES.each do |method|
define_method "test_delegates_#{method}_to_Array" do
assert_respond_to target, method
end
end
end
class DelegationAssociationTest < ActiveRecord::TestCase
include DelegationWhitelistTests
fixtures :posts
def target
Post.first.comments
end
end
class DelegationRelationTest < ActiveRecord::TestCase
include DelegationWhitelistTests
fixtures :comments
def target
Comment.all
end
end
end