Class: MagicLamp::FixtureCreator
- Inherits:
-
Object
- Object
- MagicLamp::FixtureCreator
show all
- Includes:
- Callbacks
- Defined in:
- lib/magic_lamp/fixture_creator.rb
Instance Attribute Summary collapse
Attributes included from Callbacks
#configuration
Instance Method Summary
collapse
Methods included from Callbacks
#execute_after_each_callback, #execute_before_each_callback, #execute_callbacks_around, #initialize
Instance Attribute Details
#render_arguments ⇒ Object
Returns the value of attribute render_arguments.
7
8
9
|
# File 'lib/magic_lamp/fixture_creator.rb', line 7
def render_arguments
@render_arguments
end
|
Instance Method Details
#generate_template(controller_class, extensions, &block) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/magic_lamp/fixture_creator.rb', line 9
def generate_template(controller_class, extensions, &block)
fixture = execute_callbacks_around do
controller = new_controller(controller_class, extensions, &block)
controller.request.env["action_dispatch.request.path_parameters"] = { action: "index", controller: controller.controller_name }
fetch_rendered(controller, block)
end
if fixture.empty?
raise EmptyFixtureError, "Fixture was an empty string. This is probably not what you meant to have happen."
end
fixture
end
|
#munge_arguments(arguments) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/magic_lamp/fixture_creator.rb', line 34
def munge_arguments(arguments)
first_arg, second_arg = arguments
if first_arg.is_a?(Hash)
first_arg[:layout] ||= false
elsif second_arg.is_a?(Hash)
second_arg[:layout] ||= false
else
arguments << { layout: false }
end
arguments
end
|
#new_controller(controller_class, extensions, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/magic_lamp/fixture_creator.rb', line 23
def new_controller(controller_class, extensions, &block)
controller = controller_class.new
redefine_view_context(controller, extensions)
extensions.each { |extension| controller.extend(extension) }
test_request_class = ActionDispatch::TestRequest
controller.request = test_request_class.respond_to?(:create) ? test_request_class.create : test_request_class.new
redefine_redirect_to(controller)
redefine_render(controller)
controller
end
|