Class: MagicLamp::FixtureCreator

Inherits:
Object
  • Object
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_argumentsObject

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
# File 'lib/magic_lamp/fixture_creator.rb', line 7

def generate_template(controller_class, extensions, &block)
  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
end

#munge_arguments(arguments) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/magic_lamp/fixture_creator.rb', line 25

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



15
16
17
18
19
20
21
22
23
# File 'lib/magic_lamp/fixture_creator.rb', line 15

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_redirect_to(controller)
  redefine_render(controller)
  controller
end