aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorLauro Caetano <laurocaetano1@gmail.com>2013-12-13 22:11:39 -0200
committerLauro Caetano <laurocaetano1@gmail.com>2013-12-17 13:43:10 -0200
commitd4ee09cda135da9c36a5ddadd2d8c2d35c116be3 (patch)
tree469e6dcb73930059b59e911defaee4a98ca44f43 /activerecord/test/cases
parent5d77edf0cf1ed653ed3f7729d77eeb8de219d0b3 (diff)
downloadrails-d4ee09cda135da9c36a5ddadd2d8c2d35c116be3.tar.gz
rails-d4ee09cda135da9c36a5ddadd2d8c2d35c116be3.tar.bz2
rails-d4ee09cda135da9c36a5ddadd2d8c2d35c116be3.zip
Create a blacklist to disallow mutator methods to be delegated to `Array`.
This change was necessary because the whitelist wouldn't work. It would be painful for users trying to update their applications. This blacklist intent to prevent odd bugs and confusion in code that call mutator methods directely on the `Relation`.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/relation/delegation_test.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/test/cases/relation/delegation_test.rb b/activerecord/test/cases/relation/delegation_test.rb
index f295ccbc6a..9b2bfed039 100644
--- a/activerecord/test/cases/relation/delegation_test.rb
+++ b/activerecord/test/cases/relation/delegation_test.rb
@@ -26,15 +26,22 @@ module ActiveRecord
end
module DelegationWhitelistBlacklistTests
- ActiveRecord::Delegation::ARRAY_DELEGATES.each do |method|
+ ARRAY_DELEGATES = [
+ :+, :-, :|, :&, :[],
+ :all?, :collect, :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
+ ]
+
+ ARRAY_DELEGATES.each do |method|
define_method "test_delegates_#{method}_to_Array" do
assert_respond_to target, method
end
end
- [:compact!, :flatten!, :reject!, :reverse!, :rotate!,
- :shuffle!, :slice!, :sort!, :sort_by!, :delete_if,
- :keep_if, :pop, :shift, :delete_at, :compact].each do |method|
+ ActiveRecord::Delegation::BLACKLISTED_ARRAY_METHODS.each do |method|
define_method "test_#{method}_is_not_delegated_to_Array" do
assert_raises(NoMethodError) { call_method(target, method) }
end