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



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

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



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

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

.determine_default_controller_class(name) ⇒ Object



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

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

.prepare_controller_class(new_class) ⇒ Object



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

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

.tests(controller_class) ⇒ Object



15
16
17
# File 'lib/action_controller/test_case.rb', line 15

def tests(controller_class)
  self.controller_class = controller_class
end

Instance Method Details

#setupObject



47
48
49
50
51
# File 'lib/action_controller/test_case.rb', line 47

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