Class: ActionController::TestCase

Inherits:
ActiveSupport::TestCase
  • Object
show all
Defined in:
lib/action_controller/test_case.rb

Constant Summary collapse

@@controller_class =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.controller_classObject



30
31
32
33
34
35
36
# File 'lib/action_controller/test_case.rb', line 30

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

.controller_class=(new_class) ⇒ Object



25
26
27
28
# File 'lib/action_controller/test_case.rb', line 25

def controller_class=(new_class)
  prepare_controller_class(new_class)
  write_inheritable_attribute(:controller_class, new_class)
end

.determine_default_controller_class(name) ⇒ Object



38
39
40
41
42
# File 'lib/action_controller/test_case.rb', line 38

def determine_default_controller_class(name)
  name.sub(/Test$/, '').constantize
rescue NameError
  raise NonInferrableControllerError.new(name)
end

.method_added(method) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/action_controller/test_case.rb', line 60

def self.method_added(method)
  if method.to_s == 'setup'
    unless method_defined?(:setup_without_controller)
      alias_method :setup_without_controller, :setup
      define_method(:setup) do
        setup_with_fixtures if respond_to?(:setup_with_fixtures)
        setup_with_controller
        setup_without_controller
      end
    end
  end
end

.prepare_controller_class(new_class) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/action_controller/test_case.rb', line 44

def prepare_controller_class(new_class)
  new_class.class_eval do
    def rescue_action(e)
      raise e
    end
  end
end

.tests(controller_class) ⇒ Object



21
22
23
# File 'lib/action_controller/test_case.rb', line 21

def tests(controller_class)
  self.controller_class = controller_class
end

Instance Method Details

#setup_with_controllerObject Also known as: setup



53
54
55
56
57
# File 'lib/action_controller/test_case.rb', line 53

def setup_with_controller
  @controller = self.class.controller_class.new
  @request    = TestRequest.new
  @response   = TestResponse.new
end