Skip to content

Commit

Permalink
Ruby 1.9 compat: helpers
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8409 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Dec 15, 2007
1 parent 525cac7 commit ee0ea35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion actionpack/lib/action_controller/helpers.rb
@@ -1,3 +1,4 @@
# FIXME: helper { ... } is broken on Ruby 1.9
module ActionController #:nodoc:
module Helpers #:nodoc:
HELPERS_DIR = (defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/app/helpers" : "app/helpers")
Expand Down Expand Up @@ -120,7 +121,7 @@ def helper(*args, &block)
begin
require_dependency(file_name)
rescue LoadError => load_error
requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1]
requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1]
if requiree == file_name
msg = "Missing helper file helpers/#{file_name}.rb"
raise LoadError.new(msg).copy_blame!(load_error)
Expand Down
14 changes: 8 additions & 6 deletions actionpack/test/controller/helper_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../abstract_unit'

silence_warnings { ActionController::Helpers::HELPERS_DIR = File.dirname(__FILE__) + '/../fixtures/helpers' }
ActionController::Helpers::HELPERS_DIR.replace File.dirname(__FILE__) + '/../fixtures/helpers'

class TestController < ActionController::Base
attr_accessor :delegate_attr
Expand Down Expand Up @@ -130,23 +130,25 @@ def test_helper_for_acronym_controller
end

def test_all_helpers
methods = ApplicationController.master_helper_module.instance_methods.map(&:to_s)

# abc_helper.rb
assert ApplicationController.master_helper_module.instance_methods.include?("bare_a")
assert methods.include?('bare_a')

# fun/games_helper.rb
assert ApplicationController.master_helper_module.instance_methods.include?("stratego")
assert methods.include?('stratego')

# fun/pdf_helper.rb
assert ApplicationController.master_helper_module.instance_methods.include?("foobar")
assert methods.include?('foobar')
end

private
def expected_helper_methods
TestHelper.instance_methods
TestHelper.instance_methods.map(&:to_s)
end

def master_helper_methods
@controller_class.master_helper_module.instance_methods
@controller_class.master_helper_module.instance_methods.map(&:to_s)
end

def missing_methods
Expand Down

0 comments on commit ee0ea35

Please sign in to comment.