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, #initialize
Instance Attribute Details
#render_arguments ⇒ Object
Returns the value of attribute render_arguments.
5
6
7
|
# File 'lib/magic_lamp/fixture_creator.rb', line 5
def render_arguments
@render_arguments
end
|
Instance Method Details
#generate_template(controller_class, extensions, &block) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/magic_lamp/fixture_creator.rb', line 7
def generate_template(controller_class, extensions, &block)
execute_before_each_callback
controller = new_controller(controller_class, extensions, &block)
munged_arguments = munge_arguments(render_arguments)
rendered = controller.render_to_string(*munged_arguments)
execute_after_each_callback
rendered
end
|
#munge_arguments(arguments) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/magic_lamp/fixture_creator.rb', line 26
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
16
17
18
19
20
21
22
23
24
|
# File 'lib/magic_lamp/fixture_creator.rb', line 16
def new_controller(controller_class, extensions, &block)
controller = controller_class.new
redefine_view_context(controller, extensions)
extensions.each { |extension| controller.extend(extension) }
controller.request = ActionDispatch::TestRequest.new
redefine_render(controller)
controller.instance_eval(&block)
controller
end
|