1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
require 'action_controller'
require 'action_view/base'
begin
require 'ruby-debug'
Debugger.settings[:autoeval] = true
Debugger.start
rescue LoadError
# Debugging disabled. `gem install ruby-debug` to enable.
end
require 'action_controller/abstract'
require 'action_controller/new_base'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
require 'rubygems'
require 'rack/test'
module ActionController
class Base2 < AbstractBase
include AbstractController::Callbacks
include AbstractController::Renderer
include AbstractController::Helpers
include AbstractController::Layouts
include AbstractController::Logger
include ActionController::HideActions
include ActionController::UrlFor
include ActionController::Layouts
include ActionController::Renderer
def self.inherited(klass)
@subclasses ||= []
@subclasses << klass.to_s
end
def self.subclasses
@subclasses
end
# append_view_path File.join(File.dirname(__FILE__), '..', 'fixtures')
CORE_METHODS = self.public_instance_methods
end
end
module ActionView #:nodoc:
class FixtureTemplate < Template
class FixturePath < Template::Path
def initialize(hash = {})
@hash = {}
hash.each do |k, v|
@hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self)
end
super("fixtures://root")
end
def find_template(path)
@hash[path]
end
end
def initialize(body, *args)
@body = body
super(*args)
end
def source
@body
end
private
def find_full_path(path, load_paths)
return '/', path
end
end
end
# Temporary base class
class Rack::TestCase < ActiveSupport::TestCase
include Rack::Test::Methods
setup do
ActionController::Base.session_options[:key] = "abc"
ActionController::Base.session_options[:secret] = ("*" * 30)
controllers = ActionController::Base2.subclasses.map do |k|
k.underscore.sub(/_controller$/, '')
end
ActionController::Routing.use_controllers!(controllers)
end
def self.describe(text)
class_eval <<-RUBY_EVAL
def self.name
"#{text}"
end
RUBY_EVAL
end
def app
@app ||= ActionController::Dispatcher.new
end
def self.get(url)
setup do |test|
test.get url
end
end
def assert_body(body)
assert_equal [body], last_response.body
end
def self.assert_body(body)
test "body is set to '#{body}'" do
assert_body body
end
end
def assert_status(code)
assert_equal code, last_response.status
end
def self.assert_status(code)
test "status code is set to #{code}" do
assert_status code
end
end
def assert_content_type(type)
assert_equal type, last_response.headers["Content-Type"]
end
def self.assert_content_type(type)
test "content type is set to #{type}" do
assert_content_type(type)
end
end
def assert_header(name, value)
assert_equal value, last_response.headers[name]
end
def self.assert_header(name, value)
test "'#{name}' header is set to #{value.inspect}" do
assert_header(name, value)
end
end
end
class SimpleRouteCase < Rack::TestCase
setup do
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
end
end
|