Module: ActionView::TestCase::Behavior
Constant Summary
-
INTERNAL_IVARS =
# File 'actionview/lib/action_view/test_case.rb', line 216[ :@NAME, :@failures, :@assertions, :@__io__, :@_assertion_wrapped, :@_assertions, :@_result, :@_routes, :@controller, :@_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 ]
::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::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
::ActionView::Helpers::JavaScriptHelper
- Included
::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. |
Instance Attribute Summary
- #controller rw
- #lookup_context readonly
- #output_buffer rw
- #rendered rw
::ActionView::Helpers::FormHelper
- Included
::ActionView::Helpers::FormTagHelper
- Included
::ActionView::Helpers::AssetTagHelper
- Included
::ActionView::Context
- Included
Instance Method Summary
- #_routes
- #_user_defined_ivars
-
#_view
Alias for #view.
- #config
- #method_missing(selector, *args)
- #render(options = {}, local_assigns = {}, &block)
- #rendered_views
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #setup_with_controller
-
#view
(also: #_view)
The instance of
::ActionView::Base
that is used by #render. -
#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.
::ActionView::RoutingUrlFor
- Included
#url_for | Returns the URL for the set of |
::ActionView::Helpers::RenderingHelper
- Included
#_layout_for | Overwrites _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
#number_to_currency | Formats a |
#number_to_human | Pretty prints (formats and approximates) a number in a way it is more readable by humans (e.g.: 1200000000 becomes “1.2 Billion”). |
#number_to_human_size | Formats the bytes in |
#number_to_percentage | Formats a |
#number_to_phone | Formats a |
#number_with_delimiter | Formats a |
#number_with_precision | Formats a |
::ActionView::Helpers::JavaScriptHelper
- Included
#escape_javascript | Escapes carriage returns and single and double quotes for JavaScript segments. |
#j | Alias for Helpers::JavaScriptHelper#escape_javascript. |
#javascript_tag | Returns a JavaScript tag with the |
::ActionView::Helpers::FormOptionsHelper
- Included
#collection_check_boxes | Returns check box tags for the collection of existing return values of |
#collection_radio_buttons | Returns radio button tags for the collection of existing return values of |
#collection_select | Returns |
#grouped_collection_select | Returns |
#grouped_options_for_select | Returns a string of |
#option_groups_from_collection_for_select | Returns a string of |
#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 |
#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 |
::ActionView::Helpers::FormHelper
- Included
#check_box | Returns a checkbox tag tailored for accessing a specified attribute (identified by |
#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 | Alias for Helpers::FormHelper#datetime_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 |
#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 |
#label | Returns a label tag tailored for labelling an input field for a specified attribute (identified by |
#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 |
#phone_field | Alias for Helpers::FormHelper#telephone_field. |
#radio_button | Returns a radio button tag for accessing a specified attribute (identified by |
#range_field | Returns an input tag of type “range”. |
#search_field | Returns an input of type “search” for accessing a specified attribute (identified by |
#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 |
#text_field | Returns an input tag of the “text” type tailored for accessing a specified attribute (identified by |
#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”. |
::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::Helpers::FormTagHelper
- Included
#button_tag | Creates a button element that defines a |
#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 | Alias for Helpers::FormTagHelper#datetime_field_tag. |
#email_field_tag | Creates a text field of type “email”. |
#field_set_tag | Creates a field set for grouping HTML form elements. |
#file_field_tag | Creates a file upload field. |
#form_tag | Starts a form tag that points the action to a URL configured with |
#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 | Alias for Helpers::FormTagHelper#telephone_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 |
#submit_tag | Creates a submit button with the text |
#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 UTF8 enforcer tag. |
#week_field_tag | Creates a text field of type “week”. |
::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 an excerpt from |
#highlight | Highlights one or more |
#pluralize | Attempts to pluralize the |
#reset_cycle | Resets a cycle so that it starts from the first element the next time it is called. |
#safe_concat, | |
#simple_format | Returns |
#truncate | Truncates a given |
#word_wrap | Wraps the |
::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 |
#strip_tags | Strips all HTML tags from |
::ActionView::Helpers::UrlHelper
- Included
#button_to | Generates a form containing a single button that submits to the URL created by the set of |
#link_to | Creates an anchor element of the given |
#link_to_if | Creates a link tag of the given |
#link_to_unless | Creates a link tag of the given |
#link_to_unless_current | Creates a link tag of the given |
#mail_to | Creates a mailto link tag to the specified |
#phone_to | Creates a TEL anchor link tag to the specified |
#sms_to | Creates an SMS anchor link tag to the specified |
::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 |
#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 |
#distance_of_time_in_words | Reports the approximate distance in time between two |
#distance_of_time_in_words_to_now | Alias for Helpers::DateHelper#time_ago_in_words. |
#select_date | Returns a set of HTML select-tags (one for year, month, and day) pre-selected with the |
#select_datetime | Returns a set of HTML select-tags (one for year, month, day, hour, minute, and second) pre-selected with the |
#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 |
#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 |
#time_tag | Returns an HTML time tag for the given date or time. |
::ActionView::Helpers::AssetTagHelper
- Included
#audio_tag | Returns an HTML audio tag for the |
#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 |
#javascript_include_tag | Returns an HTML script tag for each of the |
#preload_link_tag | Returns a link tag that browsers can use to preload the |
#stylesheet_link_tag | Returns a stylesheet link tag for the sources specified as arguments. |
#video_tag | Returns an HTML video tag for the |
::ActionView::Helpers::TagHelper
- Included
#cdata_section | Returns a CDATA section with the given |
#class_names | Alias for Helpers::TagHelper#token_list. |
#content_tag | Returns an HTML block tag of type |
#escape_once | Returns an escaped version of |
#tag | Returns an HTML tag. |
#token_list | Returns a string of tokens built from |
::ActionView::Helpers::CaptureHelper
- Included
#capture | The capture method extracts part of a template as a |
#content_for | Calling |
#content_for? |
|
#provide | The same as |
::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 | Alias for Helpers::AssetUrlHelper#asset_path. |
#path_to_audio | Alias for Helpers::AssetUrlHelper#audio_path. |
#path_to_font | Alias for Helpers::AssetUrlHelper#font_path. |
#path_to_image | Alias for Helpers::AssetUrlHelper#image_path. |
#path_to_javascript | Alias for Helpers::AssetUrlHelper#javascript_path. |
#path_to_stylesheet | Alias for Helpers::AssetUrlHelper#stylesheet_path. |
#path_to_video | Alias for Helpers::AssetUrlHelper#video_path. |
#public_compute_asset_path | Alias for Helpers::AssetUrlHelper#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 | Alias for Helpers::AssetUrlHelper#asset_url. |
#url_to_audio | Alias for Helpers::AssetUrlHelper#audio_url. |
#url_to_font | Alias for Helpers::AssetUrlHelper#font_url. |
#url_to_image | Alias for Helpers::AssetUrlHelper#image_url. |
#url_to_javascript | Alias for Helpers::AssetUrlHelper#javascript_url. |
#url_to_stylesheet | Alias for Helpers::AssetUrlHelper#stylesheet_url. |
#url_to_video | Alias for Helpers::AssetUrlHelper#video_url. |
#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. |
::ActionView::Context
- Included
#_layout_for | Encapsulates the interaction with the view flow so it returns the correct buffer on |
#_prepare_context | Prepares the context by setting the appropriate instance variables. |
::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 |
#assert_routing | Asserts that path and options match both ways; in other words, it verifies that |
#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. |
::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: |
::ActionDispatch::TestProcess
- Included
::ActionDispatch::TestProcess::FixtureFile
- Included
#fixture_file_upload | Shortcut for |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(selector, *args)
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 261
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
DSL Calls
included
[ GitHub ]162 163 164 165 166 167 168 169 170 171 172 173 174 175
# File 'actionview/lib/action_view/test_case.rb', line 162
included do setup :setup_with_controller 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 10
class_attribute :_helper_methods, default: Array.new
._helper_methods? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionpack/lib/abstract_controller/helpers.rb', line 10
class_attribute :_helper_methods, default: Array.new
Instance Attribute Details
#_helper_methods (rw)
[ GitHub ]# File 'actionpack/lib/abstract_controller/helpers.rb', line 10
class_attribute :_helper_methods, default: Array.new
#_helper_methods? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionpack/lib/abstract_controller/helpers.rb', line 10
class_attribute :_helper_methods, default: Array.new
#controller (rw)
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 56
attr_accessor :controller, :output_buffer, :rendered
#lookup_context (readonly)
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 55
delegate :lookup_context, to: :controller
#output_buffer (rw)
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 56
attr_accessor :controller, :output_buffer, :rendered
#rendered (rw)
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 56
attr_accessor :controller, :output_buffer, :rendered
Instance Method Details
#_routes
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 132
def _routes @controller._routes if @controller.respond_to?(:_routes) end
#_user_defined_ivars
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 247
def _user_defined_ivars instance_variables - INTERNAL_IVARS end
#_view
Alias for #view.
# File 'actionview/lib/action_view/test_case.rb', line 214
alias_method :_view, :view
#config
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 118
def config @controller.config if @controller.respond_to?(:config) end
#render(options = {}, local_assigns = {}, &block)
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 122
def render( = {}, local_assigns = {}, &block) view.assign(view_assigns) @rendered << output = view.render(, local_assigns, &block) output end
#rendered_views
[ GitHub ]# File 'actionview/lib/action_view/test_case.rb', line 128
def rendered_views @_rendered_views ||= RenderedViewsCollection.new end
#respond_to_missing?(name, include_private = false) ⇒ Boolean
# File 'actionview/lib/action_view/test_case.rb', line 277
def respond_to_missing?(name, include_private = false) begin routes = defined?(@controller) && @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 104
def setup_with_controller controller_class = Class.new(ActionView::TestCase::TestController) @controller = controller_class.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 = +"" 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.
# File 'actionview/lib/action_view/test_case.rb', line 203
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.
# File 'actionview/lib/action_view/test_case.rb', line 255
def view_assigns Hash[_user_defined_ivars.map do |ivar| [ivar[1..-1].to_sym, instance_variable_get(ivar)] end] end