Module: ActionController::TestCase::Behavior::ClassMethods

Defined in:
lib/action_controller/test_case.rb

Instance Method Summary collapse

Instance Method Details

#controller_classObject



460
461
462
463
464
465
466
# File 'lib/action_controller/test_case.rb', line 460

def controller_class
  if current_controller_class = self._controller_class
    current_controller_class
  else
    self.controller_class = determine_default_controller_class(name)
  end
end

#controller_class=(new_class) ⇒ Object



455
456
457
458
# File 'lib/action_controller/test_case.rb', line 455

def controller_class=(new_class)
  prepare_controller_class(new_class) if new_class
  self._controller_class = new_class
end

#determine_default_controller_class(name) ⇒ Object



468
469
470
471
472
# File 'lib/action_controller/test_case.rb', line 468

def determine_default_controller_class(name)
  determine_constant_from_test_name(name) do |constant|
    Class === constant && constant < ActionController::Metal
  end
end

#prepare_controller_class(new_class) ⇒ Object



474
475
476
# File 'lib/action_controller/test_case.rb', line 474

def prepare_controller_class(new_class)
  new_class.send :include, ActionController::TestCase::RaiseActionExceptions
end

#tests(controller_class) ⇒ Object

Sets the controller class name. Useful if the name can’t be inferred from test class. Normalizes controller_class before using.

tests WidgetController
tests :widget
tests 'widget'


444
445
446
447
448
449
450
451
452
453
# File 'lib/action_controller/test_case.rb', line 444

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