跳至内容 跳至搜索
方法
C
D
T

实例公共方法

controller_class()

# File actionpack/lib/action_controller/test_case.rb, line 393
def controller_class
  if current_controller_class = _controller_class
    current_controller_class
  else
    self.controller_class = determine_default_controller_class(name)
  end
end

controller_class=(new_class)

# File actionpack/lib/action_controller/test_case.rb, line 389
def controller_class=(new_class)
  self._controller_class = new_class
end

determine_default_controller_class(name)

# File actionpack/lib/action_controller/test_case.rb, line 401
def determine_default_controller_class(name)
  determine_constant_from_test_name(name) do |constant|
    Class === constant && constant < ActionController::Metal
  end
end

tests(controller_class)

设置控制器类名。如果无法从测试类推断出名称,此方法很有用。在使用之前,会对 controller_class 进行规范化。

tests WidgetController
tests :widget
tests 'widget'
# File actionpack/lib/action_controller/test_case.rb, line 378
def tests(controller_class)
  case controller_class
  when String, Symbol
    self.controller_class = "#{controller_class.to_s.camelize}Controller".constantize
  when Class
    self.controller_class = controller_class
  else
    raise ArgumentError, "controller class must be a String, Symbol, or Class"
  end
end