Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Rjsassertions

Rjsassertions

RJS Assertions

RJS Assertions is a collection of assertions useful for testing your RJS templates. RJS Assertions function very similarly to the standard assertions built in to Rails, except that RJS Assertions are capable of parsing the JavaScript produced by an RJS template, and assert various conditions.

Usage: assert_rjs_tag & assert_rjs_no_tag – Same options as assert_tag/assert_no_tag. :rjs option can added to limit scope of assert. Example:

  1. Asserts the content exists in any HTML fragments. assert_rjs_tag :content => ‘Hello World’
  1. Asserts the content exists in HTML fragments being added
  2. to or replacing the greeting_div_id HTML. assert_rjs_tag :rjs => {:block => ‘greeting_div_id’}. :content => ‘Hello World’
assert_rjs_visual_effect:  
- Accepts two arguments, a string representing the id of the block the effect
  should be performed on, and a symbol or string of the effect.
  (Currently only supports "show" and "hide")  Example:
assert_rjs_visual_effect 'greeting_div_id', :show

Example:

Say you have an action that triggers the following RJS template:

page.replace_html 'details_column_left',     :partial => 'field', :collection => @left_column,
    :locals => {:values => @field_hash}
page.replace_html 'details_column_right',     :partial => 'field', :collection => @right_column,
    :locals => {:values => @field_hash}
page.hide 'information_save_button'
page.show 'information_edit_button'
page.hide 'field_errors'

The action JavaScript response sent to the browser might end up looking something like: end

Element.update("details_column_left", "<label for="\"field[35]\""> @joe_schmoe.id, :field => {'1' => 'New Value'}}, logged_in_session
assert_rjs_tag :rjs => {:block => 'details_column_left' }, :tag => 'label', :content => 'Preferred:'
assert_rjs_tag :rjs => {:block => 'details_column_right' }, :tag => 'label', :content => 'Locations:'
assert_rjs_no_tag :rjs => {:block => 'details_column_left' }, :content => 'Left Value One!!!'
assert_rjs_visual_effect 'information_save_button', :hide
assert_rjs_visual_effect 'information_edit_button', :show

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all 2 member details


Membership

+ Join this railsplugin

Record Maintainer

'None'