2016-08-06 12:26:20 -04:00
|
|
|
require "cases/helper"
|
|
|
|
require "models/post"
|
|
|
|
require "models/comment"
|
2013-09-04 00:46:33 -04:00
|
|
|
|
|
|
|
module ActiveRecord
|
2017-05-05 15:52:59 -04:00
|
|
|
module DelegationWhitelistTests
|
2013-12-13 19:11:39 -05:00
|
|
|
ARRAY_DELEGATES = [
|
2015-12-01 18:41:50 -05:00
|
|
|
:+, :-, :|, :&, :[], :shuffle,
|
2015-05-27 23:37:21 -04:00
|
|
|
:all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
|
2013-12-13 19:11:39 -05:00
|
|
|
:exclude?, :find_all, :flat_map, :group_by, :include?, :length,
|
|
|
|
:map, :none?, :one?, :partition, :reject, :reverse,
|
|
|
|
:sample, :second, :sort, :sort_by, :third,
|
2017-02-04 08:49:47 -05:00
|
|
|
: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
|
2013-12-13 19:11:39 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
ARRAY_DELEGATES.each do |method|
|
2013-12-12 23:10:03 -05:00
|
|
|
define_method "test_delegates_#{method}_to_Array" do
|
2013-12-03 15:30:13 -05:00
|
|
|
assert_respond_to target, method
|
2013-09-04 00:46:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-05 15:52:59 -04:00
|
|
|
class DelegationAssociationTest < ActiveRecord::TestCase
|
|
|
|
include DelegationWhitelistTests
|
|
|
|
|
|
|
|
fixtures :posts
|
2013-11-11 05:43:34 -05:00
|
|
|
|
2013-09-04 00:46:33 -04:00
|
|
|
def target
|
2013-12-12 23:10:03 -05:00
|
|
|
Post.first.comments
|
2013-09-04 00:46:33 -04:00
|
|
|
end
|
2013-12-12 23:10:03 -05:00
|
|
|
end
|
2013-09-04 00:46:33 -04:00
|
|
|
|
2017-05-05 15:52:59 -04:00
|
|
|
class DelegationRelationTest < ActiveRecord::TestCase
|
|
|
|
include DelegationWhitelistTests
|
2013-09-04 00:46:33 -04:00
|
|
|
|
2013-12-12 23:10:03 -05:00
|
|
|
fixtures :comments
|
|
|
|
|
|
|
|
def target
|
|
|
|
Comment.all
|
2013-09-04 00:46:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|