forked from browsermedia/browsercms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine_controller_hacks.rb
36 lines (30 loc) · 1.38 KB
/
engine_controller_hacks.rb
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
# Rewrite test methods to avoid need to repeat :use_route => :cms in EVERY functional test call
# See http://edgeguides.rubyonrails.org/engines.html#testing-an-engine for why this would be necessary.
module EngineControllerHacks
def get(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "GET")
end
# Executes a request simulating POST HTTP method and set/volley the response
def post(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "POST")
end
# Executes a request simulating PUT HTTP method and set/volley the response
def put(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "PUT")
end
# Executes a request simulating DELETE HTTP method and set/volley the response
def delete(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "DELETE")
end
private
def process_action(action, parameters = nil, session = nil, flash = nil, method = "GET")
parameters ||= {}
merge = { :use_route => :cms }
if parameters[:use_route] == false
parameters.delete(:use_route)
merge = {}
end
process(action, parameters.merge!(merge), session, flash, method)
end
end
ActionController::TestCase.send(:include, EngineControllerHacks)