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

Defined in:
lib/action_controller/test_case.rb

Instance Method Summary collapse

Instance Method Details

#controller_classObject



387
388
389
390
391
392
393
# File 'lib/action_controller/test_case.rb', line 387

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



382
383
384
385
# File 'lib/action_controller/test_case.rb', line 382

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



395
396
397
# File 'lib/action_controller/test_case.rb', line 395

def determine_default_controller_class(name)
  name.sub(/Test$/, '').safe_constantize
end

#prepare_controller_class(new_class) ⇒ Object



399
400
401
# File 'lib/action_controller/test_case.rb', line 399

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. Examples:

tests WidgetController
tests :widget
tests 'widget'


371
372
373
374
375
376
377
378
379
380
# File 'lib/action_controller/test_case.rb', line 371

def tests(controller_class)
  case controller_class
  when String, Symbol
    self.controller_class = "#{controller_class.to_s.underscore}_controller".camelize.constantize
  when Class
    self.controller_class = controller_class
  else
    raise ArgumentError, "controller class must be a String, Symbol, or Class"
  end
end