module ActionView::TestCase::Behavior
Constants
- INTERNAL_IVARS
Attributes
controller[RW]
output_buffer[RW]
rendered[RW]
Public Instance Methods
_routes()
click to toggle source
# File lib/action_view/test_case.rb, line 130 def _routes @controller._routes if @controller.respond_to?(:_routes) end
config()
click to toggle source
# File lib/action_view/test_case.rb, line 116 def config @controller.config if @controller.respond_to?(:config) end
render(options = {}, local_assigns = {}, &block)
click to toggle source
# File lib/action_view/test_case.rb, line 120 def render(options = {}, local_assigns = {}, &block) view.assign(view_assigns) @rendered << output = view.render(options, local_assigns, &block) output end
rendered_views()
click to toggle source
# File lib/action_view/test_case.rb, line 126 def rendered_views @_rendered_views ||= RenderedViewsCollection.new end
setup_with_controller()
click to toggle source
# File lib/action_view/test_case.rb, line 103 def setup_with_controller @controller = ActionView::TestCase::TestController.new @request = @controller.request @view_flow = ActionView::OutputFlow.new # empty string ensures buffer has UTF-8 encoding as # new without arguments returns ASCII-8BIT encoded buffer like String#new @output_buffer = ActiveSupport::SafeBuffer.new "" @rendered = +"" make_test_case_available_to_view! say_no_to_protect_against_forgery! end
Private Instance Methods
_user_defined_ivars()
click to toggle source
# File lib/action_view/test_case.rb, line 254 def _user_defined_ivars instance_variables - INTERNAL_IVARS end
document_root_element()
click to toggle source
Need to experiment if this priority is the best one: rendered => output_buffer
# File lib/action_view/test_case.rb, line 167 def document_root_element Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root end
make_test_case_available_to_view!()
click to toggle source
# File lib/action_view/test_case.rb, line 180 def make_test_case_available_to_view! test_case_instance = self _helpers.module_eval do unless private_method_defined?(:_test_case) define_method(:_test_case) { test_case_instance } private :_test_case end end end
method_missing(selector, *args)
click to toggle source
Calls superclass method
# File lib/action_view/test_case.rb, line 268 def method_missing(selector, *args) begin routes = @controller.respond_to?(:_routes) && @controller._routes rescue # Don't call routes, if there is an error on _routes call end if routes && (routes.named_routes.route_defined?(selector) || routes.mounted_helpers.method_defined?(selector)) @controller.__send__(selector, *args) else super end end
protect_against_forgery?()
click to toggle source
# File lib/action_view/test_case.rb, line 174 def protect_against_forgery? false end
respond_to_missing?(name, include_private = false)
click to toggle source
# File lib/action_view/test_case.rb, line 284 def respond_to_missing?(name, include_private = false) begin routes = @controller.respond_to?(:_routes) && @controller._routes rescue # Don't call routes, if there is an error on _routes call end routes && (routes.named_routes.route_defined?(name) || routes.mounted_helpers.method_defined?(name)) end
say_no_to_protect_against_forgery!()
click to toggle source
# File lib/action_view/test_case.rb, line 171 def say_no_to_protect_against_forgery! _helpers.module_eval do silence_redefinition_of_method :protect_against_forgery? def protect_against_forgery? false end end end
view()
click to toggle source
The instance of ActionView::Base
that is used by render
.
# File lib/action_view/test_case.rb, line 210 def view @view ||= begin view = @controller.view_context view.singleton_class.include(_helpers) view.extend(Locals) view.rendered_views = rendered_views view.output_buffer = output_buffer view end end
Also aliased as: _view
view_assigns()
click to toggle source
Returns a Hash of instance variables and their values, as defined by the user in the test case, which are then assigned to the view being rendered. This is generally intended for internal use and extension frameworks.
# File lib/action_view/test_case.rb, line 262 def view_assigns Hash[_user_defined_ivars.map do |ivar| [ivar[1..-1].to_sym, instance_variable_get(ivar)] end] end