123456789_123456789_123456789_123456789_123456789_

Module: ActionView::TestCase::Behavior

Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, ::ActiveSupport::Testing::ConstantLookup, ::ActionView::RoutingUrlFor, ::ActionView::Helpers, ::ActionView::Helpers::TranslationHelper, ::ActionView::Helpers::RenderingHelper, ::ActionView::Helpers::NumberHelper, ::ActionView::Helpers::JavaScriptHelper, ::ActionView::Helpers::FormOptionsHelper, ::ActionView::Helpers::FormHelper, ::ActionView::RecordIdentifier, ::ActionView::ModelNaming, ::ActionView::Helpers::FormTagHelper, ::ActionView::Helpers::TextHelper, ::ActionView::Helpers::SanitizeHelper, ::ActionView::Helpers::UrlHelper, ::ActionView::Helpers::DebugHelper, ::ActionView::Helpers::DateHelper, ::ActionView::Helpers::CsrfHelper, ::ActionView::Helpers::CspHelper, ::ActionView::Helpers::ControllerHelper, ::ActionView::Helpers::ContentExfiltrationPreventionHelper, ::ActionView::Helpers::CacheHelper, ::ActionView::Helpers::AtomFeedHelper, ::ActionView::Helpers::AssetTagHelper, ::ActionView::Helpers::TagHelper, ::ActionView::Helpers::OutputSafetyHelper, ::ActionView::Helpers::CaptureHelper, ::ActionView::Helpers::AssetUrlHelper, ::ActionView::Helpers::ActiveModelHelper, ::ActiveSupport::Benchmarkable, ::AbstractController::Helpers, ::ActionDispatch::Routing::PolymorphicRoutes, ::ActionView::Context, ::ActionController::TemplateAssertions, Rails::Dom::Testing::Assertions, ::ActionDispatch::Assertions, Rails::Dom::Testing::Assertions, ::ActionDispatch::Assertions::RoutingAssertions, ::ActionDispatch::Assertions::ResponseAssertions, ::ActionDispatch::TestProcess, ::ActionDispatch::TestProcess::FixtureFile
Defined in: actionview/lib/action_view/test_case.rb

Constant Summary

  • INTERNAL_IVARS =
    # File 'actionview/lib/action_view/test_case.rb', line 369
    [
      :@NAME,
      :@failures,
      :@assertions,
      :@__io__,
      :@_assertion_wrapped,
      :@_assertions,
      :@_result,
      :@_routes,
      :@controller,
      :@_controller,
      :@_request,
      :@_config,
      :@_default_form_builder,
      :@_layouts,
      :@_files,
      :@_rendered_views,
      :@method_name,
      :@output_buffer,
      :@_partials,
      :@passed,
      :@rendered,
      :@request,
      :@routes,
      :@tagged_logger,
      :@_templates,
      :@options,
      :@test_passed,
      :@view,
      :@view_context_class,
      :@view_flow,
      :@_subscribers,
      :@html_document,
    ]

::ActionDispatch::Assertions::ResponseAssertions - Included

RESPONSE_PREDICATES

::ActionView::Helpers::AssetUrlHelper - Included

ASSET_EXTENSIONS, ASSET_PUBLIC_DIRECTORIES, URI_REGEXP

::ActionView::Helpers::TagHelper - Included

ARIA_PREFIXES, BOOLEAN_ATTRIBUTES, DATA_PREFIXES, PRE_CONTENT_STRINGS, TAG_TYPES

::ActionView::Helpers::AssetTagHelper - Included

MAX_HEADER_SIZE

::ActionView::Helpers::ContentExfiltrationPreventionHelper - Included

CLOSE_CDATA_COMMENT, CLOSE_FORM_TAG, CLOSE_OPTION_TAG, CLOSE_QUOTES_COMMENT, CONTENT_EXFILTRATION_PREVENTION_MARKUP

::ActionView::Helpers::ControllerHelper - Included

CONTROLLER_DELEGATES

::ActionView::Helpers::DateHelper - Included

MINUTES_IN_QUARTER_YEAR, MINUTES_IN_THREE_QUARTERS_YEAR, MINUTES_IN_YEAR

::ActionView::Helpers::UrlHelper - Included

BUTTON_TAG_METHOD_VERBS, STRINGIFIED_COMMON_METHODS

::ActionView::RecordIdentifier - Included

JOIN, NEW

::ActionView::Helpers::JavaScriptHelper - Included

JS_ESCAPE_MAP

::ActionView::Helpers::TranslationHelper - Included

MISSING_TRANSLATION, NO_DEFAULT

::AbstractController::Helpers - Attributes & Methods

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Attribute Summary

Instance Method Summary

::ActionView::RoutingUrlFor - Included

#url_for

Returns the URL for the set of options provided.

#_generate_paths_by_default, #_routes_context, #ensure_only_path_option, #url_options

::ActionView::Helpers::TranslationHelper - Included

#l
#localize

Delegates to I18n.localize with no additional functionality.

#t
#translate

Delegates to I18n#translate but also performs three additional functions.

#missing_translation, #scope_key_by_partial

::ActionView::Helpers::RenderingHelper - Included

#_layout_for

Overrides _layout_for in the context object so it supports the case a block is passed to a partial.

#render

Returns the result of a render that’s dictated by the options hash.

::ActionView::Helpers::NumberHelper - Included

::ActionView::Helpers::JavaScriptHelper - Included

#escape_javascript

Escapes carriage returns and single and double quotes for JavaScript segments.

#j
#javascript_tag

Returns a JavaScript tag with the content inside.

#javascript_cdata_section

::ActionView::Helpers::FormOptionsHelper - Included

#collection_check_boxes

Returns check box tags for the collection of existing return values of method for object‘s class.

#collection_radio_buttons

Returns radio button tags for the collection of existing return values of method for object‘s class.

#collection_select

Returns <select> and <option> tags for the collection of existing return values of method for object‘s class.

#grouped_collection_select

Returns <select>, <optgroup> and <option> tags for the collection of existing return values of method for object‘s class.

#grouped_options_for_select

Returns a string of <option> tags, like options_for_select, but wraps them with <optgroup> tags:

#option_groups_from_collection_for_select

Returns a string of <option> tags, like options_from_collection_for_select, but groups them by <optgroup> tags based on the object relationships of the arguments.

#options_for_select

Accepts a container (hash, array, enumerable, your type) and returns a string of option tags.

#options_from_collection_for_select

Returns a string of option tags that have been compiled by iterating over the collection and assigning the result of a call to the value_method as the option value and the text_method as the option text.

#select

Create a select tag and a series of contained option tags for the provided object and method.

#time_zone_options_for_select

Returns a string of option tags for pretty much any time zone in the world.

#time_zone_select

Returns select and option tags for the given object and method, using #time_zone_options_for_select to generate the list of option tags.

#weekday_options_for_select

Returns a string of option tags for the days of the week.

#weekday_select

Returns select and option tags for the given object and method, using weekday_options_for_select to generate the list of option tags.

#extract_selected_and_disabled, #extract_values_from_collection, #option_html_attributes, #option_text_and_value, #option_value_selected?, #prompt_text, #value_for_collection

::ActionView::Helpers::FormHelper - Included

#check_box

Returns a checkbox tag tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#color_field

Returns a text_field of type “color”.

#date_field

Returns a text_field of type “date”.

#datetime_field

Returns a text_field of type “datetime-local”.

#datetime_local_field
#email_field

Returns a text_field of type “email”.

#fields

Scopes input fields with either an explicit scope or model.

#fields_for

Creates a scope around a specific model object like form_for, but doesn’t create the form tags themselves.

#file_field

Returns a file upload input tag tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#form_for

Creates a form that allows the user to create or update the attributes of a specific model object.

#form_with

Creates a form tag based on mixing URLs, scopes, or models.

#hidden_field

Returns a hidden input tag tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#label

Returns a label tag tailored for labelling an input field for a specified attribute (identified by method) on an object assigned to the template (identified by object).

#month_field

Returns a text_field of type “month”.

#number_field

Returns an input tag of type “number”.

#password_field

Returns an input tag of the “password” type tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#phone_field
#radio_button

Returns a radio button tag for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#range_field

Returns an input tag of type “range”.

#search_field

Returns an input of type “search” for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object_name).

#telephone_field

Returns a text_field of type “tel”.

#text_area

Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#text_field

Returns an input tag of the “text” type tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object).

#time_field

Returns a text_field of type “time”.

#url_field

Returns a text_field of type “url”.

#week_field

Returns a text_field of type “week”.

#default_form_builder_class, #html_options_for_form_with, #instantiate_builder, #_object_for_form_builder, #apply_form_for_options!

::ActionView::RecordIdentifier - Included

#dom_class

The DOM class convention is to use the singular form of an object or class.

#dom_id

The DOM id convention is to use the singular form of an object or class with the id following an underscore.

#record_key_for_dom_id

Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.

::ActionView::ModelNaming - Included

#convert_to_model

Converts the given object to an Active Model compliant one.

#model_name_from_record_or_class

::ActionView::Helpers::FormTagHelper - Included

#button_tag

Creates a button element that defines a submit button, reset button or a generic button which can be used in JavaScript, for example.

#check_box_tag

Creates a check box form input tag.

#color_field_tag

Creates a text field of type “color”.

#date_field_tag

Creates a text field of type “date”.

#datetime_field_tag

Creates a text field of type “datetime-local”.

#datetime_local_field_tag
#email_field_tag

Creates a text field of type “email”.

#field_id

Generate an HTML id attribute value for the given name and field combination.

#field_name

Generate an HTML name attribute value for the given name and field combination.

#field_set_tag

Creates a field set for grouping HTML form elements.

#fieldset_tag
#file_field_tag

Creates a file upload field.

#form_tag

Starts a form tag that points the action to a URL configured with url_for_options just like ActionController::Base#url_for.

#hidden_field_tag

Creates a hidden form input field used to transmit data that would be lost due to HTTP’s statelessness or data that should be hidden from the user.

#image_submit_tag

Displays an image which when clicked will submit the form.

#label_tag

Creates a label element.

#month_field_tag

Creates a text field of type “month”.

#number_field_tag

Creates a number field.

#password_field_tag

Creates a password field, a masked text field that will hide the users input behind a mask character.

#phone_field_tag
#radio_button_tag

Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options.

#range_field_tag

Creates a range form element.

#search_field_tag

Creates a text field of type “search”.

#select_tag

Creates a dropdown selection box, or if the :multiple option is set to true, a multiple choice selection box.

#submit_tag

Creates a submit button with the text value as the caption.

#telephone_field_tag

Creates a text field of type “tel”.

#text_area_tag

Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions.

#text_field_tag

Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query.

#time_field_tag

Creates a text field of type “time”.

#url_field_tag

Creates a text field of type “url”.

#utf8_enforcer_tag

Creates the hidden UTF-8 enforcer tag.

#week_field_tag

Creates a text field of type “week”.

#convert_direct_upload_option_to_url, #extra_tags_for_form, #form_tag_html, #form_tag_with_body, #html_options_for_form,
#sanitize_to_id
#set_default_disable_with

::ActionView::Helpers::TextHelper - Included

#concat

The preferred method of outputting text in your views is to use the <%= "text" %> eRuby syntax.

#current_cycle

Returns the current cycle string after a cycle has been started.

#cycle

Creates a Cycle object whose to_s method cycles through elements of an array every time it is called.

#excerpt

Extracts the first occurrence of phrase plus surrounding text from text.

#highlight

Highlights occurrences of phrases in text by formatting them with a highlighter string.

#pluralize

Attempts to pluralize the singular word unless count is 1.

#reset_cycle

Resets a cycle so that it starts from the first element the next time it is called.

#safe_concat,
#simple_format

Returns text transformed into HTML using simple formatting rules.

#truncate

Truncates text if it is longer than a specified :length.

#word_wrap

Wraps the text into lines no longer than line_width width.

#cut_excerpt_part,
#get_cycle

The cycle helpers need to store the cycles in a place that is guaranteed to be reset every time a page is rendered, so it uses an instance variable of ::ActionView::Base.

#set_cycle, #split_paragraphs

::ActionView::Helpers::SanitizeHelper - Included

#sanitize

Sanitizes HTML input, stripping all but known-safe tags and attributes.

#sanitize_css

Sanitizes a block of CSS code.

#strip_links

Strips all link tags from html leaving just the link text.

#strip_tags

Strips all HTML tags from html, including comments and special characters.

::ActionView::Helpers::UrlHelper - Included

#button_to

Generates a form containing a single button that submits to the URL created by the set of options.

#current_page?

True if the current request URI was generated by the given options.

#link_to

Creates an anchor element of the given name using a URL created by the set of options.

#link_to_if

Creates a link tag of the given name using a URL created by the set of options if condition is true, otherwise only the name is returned.

#link_to_unless

Creates a link tag of the given name using a URL created by the set of options unless condition is true, in which case only the name is returned.

#link_to_unless_current

Creates a link tag of the given name using a URL created by the set of options unless the current request URI is the same as the links, in which case only the name is returned (or the given block is yielded, if one exists).

#mail_to

Creates a mailto link tag to the specified email_address, which is also used as the name of the link unless name is specified.

#phone_to

Creates a TEL anchor link tag to the specified phone_number.

#sms_to

Creates an SMS anchor link tag to the specified phone_number.

#add_method_to_attributes!, #convert_options_to_data_attributes, #link_to_remote_options?, #method_for_options, #method_not_get_method?, #method_tag, #remove_trailing_slash!,
#to_form_params

Returns an array of hashes each containing :name and :value keys suitable for use as the names and values of form input fields:

#token_tag, #url_target,
#url_for

Basic implementation of url_for to allow use helpers without routes existence.

#_back_url, #_filtered_referrer

::ActionView::Helpers::DebugHelper - Included

#debug

Returns a YAML representation of object wrapped with <pre> and </pre>.

::ActionView::Helpers::DateHelper - Included

#date_select

Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute (identified by method) on an object assigned to the template (identified by object).

#datetime_select

Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based attribute (identified by method) on an object assigned to the template (identified by object).

#distance_of_time_in_words

Reports the approximate distance in time between two ::Time, ::Date, or ::DateTime objects or integers as seconds.

#distance_of_time_in_words_to_now
#select_date

Returns a set of HTML select-tags (one for year, month, and day) pre-selected with the date.

#select_datetime

Returns a set of HTML select-tags (one for year, month, day, hour, minute, and second) pre-selected with the datetime.

#select_day

Returns a select tag with options for each of the days 1 through 31 with the current day selected.

#select_hour

Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.

#select_minute

Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected.

#select_month

Returns a select tag with options for each of the months January through December with the current month selected.

#select_second

Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.

#select_time

Returns a set of HTML select-tags (one for hour and minute).

#select_year

Returns a select tag with options for each of the five years on each side of the current, which is selected.

#time_ago_in_words

Like distance_of_time_in_words, but where to_time is fixed to Time.now.

#time_select

Returns a set of select tags (one for hour, minute, and optionally second) pre-selected for accessing a specified time-based attribute (identified by method) on an object assigned to the template (identified by object).

#time_tag

Returns an HTML time tag for the given date or time.

#normalize_distance_of_time_argument_to_time

::ActionView::Helpers::CsrfHelper - Included

#csrf_meta_tag
#csrf_meta_tags

Returns meta tags “csrf-param” and “csrf-token” with the name of the cross-site request forgery protection parameter and token, respectively.

::ActionView::Helpers::CspHelper - Included

#csp_meta_tag

Returns a meta tag “csp-nonce” with the per-session nonce value for allowing inline <script> tags.

::ActionView::Helpers::ControllerHelper - Included

::ActionView::Helpers::ContentExfiltrationPreventionHelper - Included

::ActionView::Helpers::CacheHelper - Included

#cache

This helper exposes a method for caching fragments of a view rather than an entire action or page.

#cache_fragment_name

This helper returns the name of a cache key for a given fragment cache call.

#cache_if

Cache fragments of a view if condition is true.

#cache_unless

Cache fragments of a view unless condition is true.

#uncacheable!

Raises UncacheableFragmentError when called from within a cache block.

#fragment_for, #fragment_name_with_digest, #read_fragment_for, #write_fragment_for, #digest_path_from_template

::ActionView::Helpers::AtomFeedHelper - Included

#atom_feed

Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ::ERB or any other template languages).

::ActionView::Helpers::AssetTagHelper - Included

#audio_tag

Returns an HTML audio tag for the sources.

#auto_discovery_link_tag

Returns a link tag that browsers and feed readers can use to auto-detect an RSS, Atom, or JSON feed.

#favicon_link_tag

Returns a link tag for a favicon managed by the asset pipeline.

#image_tag

Returns an HTML image tag for the source.

#javascript_include_tag

Returns an HTML script tag for each of the sources provided.

#picture_tag

Returns an HTML picture tag for the sources.

#preload_link_tag

Returns a link tag that browsers can use to preload the source.

#stylesheet_link_tag

Returns a stylesheet link tag for the sources specified as arguments.

#video_tag

Returns an HTML video tag for the sources.

#check_for_image_tag_errors, #extract_dimensions, #multiple_sources_tag_builder, #resolve_asset_source, #resolve_link_as, #send_preload_links_header

::ActionView::Helpers::TagHelper - Included

#cdata_section

Returns a CDATA section with the given content.

#class_names
#content_tag

Returns an HTML block tag of type name surrounding the content.

#escape_once

Returns an escaped version of html without affecting existing escaped entities.

#tag

Returns an HTML tag.

#token_list

Returns a string of tokens built from args.

#build_tag_values, #ensure_valid_html5_tag_name, #tag_builder

::ActionView::Helpers::OutputSafetyHelper - Included

#raw

This method outputs without escaping a string.

#safe_join

This method returns an HTML safe string similar to what Array#join would return.

#to_sentence

Converts the array to a comma-separated sentence where the last element is joined by the connector word.

::ActionView::Helpers::CaptureHelper - Included

#capture

The capture method extracts part of a template as a string object.

#content_for

Calling content_for stores a block of markup in an identifier for later use.

#content_for?

content_for? checks whether any content has been captured yet using content_for.

#provide

The same as content_for but when used with streaming flushes straight back to the layout.

#with_output_buffer

Use an alternate output buffer for the duration of the block.

::ActionView::Helpers::AssetUrlHelper - Included

#asset_path

This is the entry point for all assets.

#asset_url

Computes the full URL to an asset in the public directory.

#audio_path

Computes the path to an audio asset in the public audios directory.

#audio_url

Computes the full URL to an audio asset in the public audios directory.

#compute_asset_extname

Compute extname to append to asset path.

#compute_asset_host

Pick an asset host for this source.

#compute_asset_path

Computes asset path to public directory.

#font_path

Computes the path to a font asset.

#font_url

Computes the full URL to a font asset.

#image_path

Computes the path to an image asset.

#image_url

Computes the full URL to an image asset.

#javascript_path

Computes the path to a JavaScript asset in the public javascripts directory.

#javascript_url

Computes the full URL to a JavaScript asset in the public javascripts directory.

#path_to_asset
#path_to_audio
#path_to_font
#path_to_image
#path_to_javascript
#path_to_stylesheet
#path_to_video
#public_compute_asset_path
#stylesheet_path

Computes the path to a stylesheet asset in the public stylesheets directory.

#stylesheet_url

Computes the full URL to a stylesheet asset in the public stylesheets directory.

#url_to_asset
#url_to_audio
#url_to_font
#url_to_image
#url_to_javascript
#url_to_stylesheet
#url_to_video
#video_path

Computes the path to a video asset in the public videos directory.

#video_url

Computes the full URL to a video asset in the public videos directory.

::ActiveSupport::Benchmarkable - Included

#benchmark

Allows you to measure the execution time of a block in a template and records the result to the log.

::AbstractController::Helpers - Included

::ActionDispatch::Routing::PolymorphicRoutes - Included

#polymorphic_path

Returns the path component of a URL for the given record.

#polymorphic_url

Constructs a call to a named RESTful route for the given record and returns the resulting URL string.

#polymorphic_mapping, #polymorphic_path_for_action, #polymorphic_url_for_action

::ActionView::Context - Included

#_layout_for

Encapsulates the interaction with the view flow so it returns the correct buffer on yield.

#_prepare_context

Prepares the context by setting the appropriate instance variables.

::ActionController::TemplateAssertions - Included

::ActionDispatch::Assertions - Included

::ActionDispatch::Assertions::RoutingAssertions - Included

#assert_generates

Asserts that the provided options can be used to generate the provided path.

#assert_recognizes

Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path.

#assert_routing

Asserts that path and options match both ways; in other words, it verifies that path generates options and then that options generates path.

#method_missing

ROUTES TODO: These assertions should really work in an integration context.

#with_routing

A helper to make it easier to test different route configurations.

#create_routes, #fail_on,
#recognized_request_for

Recognizes the route for a given path.

#reset_routes, #setup

::ActionDispatch::Assertions::ResponseAssertions - Included

#assert_redirected_to

Asserts that the response is a redirect to a URL matching the given options.

#assert_response

Asserts that the response is one of the following types:

#code_with_name, #generate_response_message, #location_if_redirected, #normalize_argument_to_redirection,
#parameterize

Proxy to to_param if the object will respond to it.

#response_body_if_short

::ActionDispatch::TestProcess - Included

::ActionDispatch::TestProcess::FixtureFile - Included

#file_fixture_upload

Shortcut for ‘Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_f ixture_path, path), type)`:

#fixture_file_upload

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(selector)

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 418

def method_missing(selector, ...)
  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, ...)
  else
    super
  end
end

DSL Calls

included

[ GitHub ]


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'actionview/lib/action_view/test_case.rb', line 199

included do
  class_attribute :content_class, instance_accessor: false, default: RenderedViewContent

  setup :setup_with_controller

  register_parser :html, -> rendered { Rails::Dom::Testing.html_document_fragment.parse(rendered) }
  register_parser :json, -> rendered { JSON.parse(rendered, object_class: ActiveSupport::HashWithIndifferentAccess) }

  ActiveSupport.run_load_hooks(:action_view_test_case, self)

  helper do
    def protect_against_forgery?
      false
    end

    def _test_case
      controller._test_case
    end
  end
end

Class Attribute Details

._helper_methods (rw)

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/helpers.rb', line 13

class_attribute :_helper_methods, default: Array.new

._helper_methods?Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/helpers.rb', line 13

class_attribute :_helper_methods, default: Array.new

Instance Attribute Details

#_helper_methods (rw)

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/helpers.rb', line 13

class_attribute :_helper_methods, default: Array.new

#_helper_methods?Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/helpers.rb', line 13

class_attribute :_helper_methods, default: Array.new

#controller (rw)

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 63

attr_accessor :controller, :request, :output_buffer, :rendered

#lookup_context (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 62

delegate :lookup_context, to: :controller

#output_buffer (rw)

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 63

attr_accessor :controller, :request, :output_buffer, :rendered

#rendered (rw)

Returns the content rendered by the last #render call.

The returned object behaves like a string but also exposes a number of methods that allows you to parse the content string in formats registered using .register_parser.

By default includes the following parsers:

.html

Parse the rendered content ::String into HTML. By default, this means a Nokogiri::XML::Node.

test "renders HTML" do
  article = Article.create!(title: "Hello, world")

  render partial: "articles/article", locals: { article: article }

  assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
end

To parse the rendered content into a Capybara::Simple::Node, re-register an :html parser with a call to Capybara.string:

register_parser :html, -> rendered { Capybara.string(rendered) }

test "renders HTML" do
  article = Article.create!(title: "Hello, world")

  render partial: article

  rendered.html.assert_css "h1", text: "Hello, world"
end

.json

Parse the rendered content ::String into JSON. By default, this means a ::ActiveSupport::HashWithIndifferentAccess.

test "renders JSON" do
  article = Article.create!(title: "Hello, world")

  render formats: :json, partial: "articles/article", locals: { article: article }

  assert_pattern { rendered.json => { title: "Hello, world" } }
end
[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 297

RDoc directive :method: rendered

#request (rw)

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 63

attr_accessor :controller, :request, :output_buffer, :rendered

Instance Method Details

#_routes

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 297

def _routes
  @controller._routes if @controller.respond_to?(:_routes)
end

#_user_defined_ivars

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 404

def _user_defined_ivars
  instance_variables - INTERNAL_IVARS
end

#_view

Alias for #view.

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 367

alias_method :_view, :view

#config

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 232

def config
  @controller.config if @controller.respond_to?(:config)
end

#document_root_element (private)

Need to experiment if this priority is the best one: rendered => output_buffer

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 332

def document_root_element
  Rails::Dom::Testing.html_document.parse(@rendered.blank? ? @output_buffer.to_str : @rendered).root
end

#render(options = {}, local_assigns = {}, &block)

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 236

def render(options = {}, local_assigns = {}, &block)
  view.assign(view_assigns)
  @rendered << output = view.render(options, local_assigns, &block)
  output
end

#rendered_views

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 242

def rendered_views
  @_rendered_views ||= RenderedViewsCollection.new
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 434

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

#setup_with_controller

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 220

def setup_with_controller
  controller_class = Class.new(ActionView::TestCase::TestController)
  @controller = controller_class.new
  @request = @controller.request
  @view_flow = ActionView::OutputFlow.new
  @output_buffer = ActionView::OutputBuffer.new
  @rendered = self.class.content_class.new(+"")

  test_case_instance = self
  controller_class.define_method(:_test_case) { test_case_instance }
end

#view Also known as: #_view

The instance of ::ActionView::Base that is used by #render.

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 356

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

#view_assigns

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.

[ GitHub ]

  
# File 'actionview/lib/action_view/test_case.rb', line 412

def view_assigns
  Hash[_user_defined_ivars.map do |ivar|
    [ivar[1..-1].to_sym, instance_variable_get(ivar)]
  end]
end