提交 edee2c7b 编写于 作者: A Akira Matsuda

stop `to_s`ing method names

Module#methods are Symbols in Ruby >= 1.9
上级 9fb70033
......@@ -109,13 +109,13 @@ def test_helper
def test_helper_method
assert_nothing_raised { @controller_class.helper_method :delegate_method }
assert master_helper_methods.include?('delegate_method')
assert master_helper_methods.include?(:delegate_method)
end
def test_helper_attr
assert_nothing_raised { @controller_class.helper_attr :delegate_attr }
assert master_helper_methods.include?('delegate_attr')
assert master_helper_methods.include?('delegate_attr=')
assert master_helper_methods.include?(:delegate_attr)
assert master_helper_methods.include?(:delegate_attr=)
end
def call_controller(klass, action)
......@@ -160,16 +160,16 @@ def test_lib_helper_methods_after_clear_helpers
end
def test_all_helpers
methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s}
methods = AllHelpersController._helpers.instance_methods
# abc_helper.rb
assert methods.include?('bare_a')
assert methods.include?(:bare_a)
# fun/games_helper.rb
assert methods.include?('stratego')
assert methods.include?(:stratego)
# fun/pdf_helper.rb
assert methods.include?('foobar')
assert methods.include?(:foobar)
end
def test_all_helpers_with_alternate_helper_dir
......@@ -180,35 +180,35 @@ def test_all_helpers_with_alternate_helper_dir
@controller_class.helper :all
# helpers/abc_helper.rb should not be included
assert !master_helper_methods.include?('bare_a')
assert !master_helper_methods.include?(:bare_a)
# alternate_helpers/foo_helper.rb
assert master_helper_methods.include?('baz')
assert master_helper_methods.include?(:baz)
end
def test_helper_proxy
methods = AllHelpersController.helpers.methods.map(&:to_s)
methods = AllHelpersController.helpers.methods
# Action View
assert methods.include?('pluralize')
assert methods.include?(:pluralize)
# abc_helper.rb
assert methods.include?('bare_a')
assert methods.include?(:bare_a)
# fun/games_helper.rb
assert methods.include?('stratego')
assert methods.include?(:stratego)
# fun/pdf_helper.rb
assert methods.include?('foobar')
assert methods.include?(:foobar)
end
private
def expected_helper_methods
TestHelper.instance_methods.map {|m| m.to_s }
TestHelper.instance_methods
end
def master_helper_methods
@controller_class._helpers.instance_methods.map {|m| m.to_s }
@controller_class._helpers.instance_methods
end
def missing_methods
......
......@@ -80,7 +80,6 @@ def test_should_not_respond_to_find_by_invalid_method_syntax
private
def ensure_topic_method_is_not_cached(method_id)
class << Topic; self; end.send(:remove_method, method_id) if Topic.public_methods.any? { |m| m.to_s == method_id.to_s }
class << Topic; self; end.send(:remove_method, method_id) if Topic.public_methods.include? method_id
end
end
......@@ -629,7 +629,7 @@ def test_find_by_two_attributes_with_one_being_an_aggregate
def test_dynamic_finder_on_one_attribute_with_conditions_returns_same_results_after_caching
# ensure this test can run independently of order
class << Account; self; end.send(:remove_method, :find_by_credit_limit) if Account.public_methods.any? { |m| m.to_s == 'find_by_credit_limit' }
class << Account; self; end.send(:remove_method, :find_by_credit_limit) if Account.public_methods.include?(:find_by_credit_limit)
a = Account.where('firm_id = ?', 6).find_by_credit_limit(50)
assert_equal a, Account.where('firm_id = ?', 6).find_by_credit_limit(50) # find_by_credit_limit has been cached
end
......
......@@ -39,7 +39,7 @@ def to_formatted_s(format = :default)
to_default_s
end
end
alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty?
alias_method :to_default_s, :to_s if instance_methods(false).include?(:to_s)
alias_method :to_s, :to_formatted_s
#
......
......@@ -61,7 +61,7 @@ def attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notificatio
@@flushable_loggers = nil
log_subscriber.public_methods(false).each do |event|
next if 'call' == event.to_s
next if :call == event
notifier.subscribe("#{event}.#{namespace}", log_subscriber)
end
......
......@@ -1009,9 +1009,7 @@ def baz
boot_rails
methods = Bukkits::Engine.helpers.public_instance_methods.collect(&:to_s).sort
expected = ["bar", "baz"]
assert_equal expected, methods
assert_equal [:bar, :baz], Bukkits::Engine.helpers.public_instance_methods.sort
end
test "setting priority for engines with config.railties_order" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册