Module: ActionController::Assertions::DeprecatedAssertions
- Defined in:
- lib/action_controller/assertions/deprecated_assertions.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#assert_cookie_equal(expected = nil, key = nil, message = nil) ⇒ Object
:nodoc:.
-
#assert_flash_empty(message = nil) ⇒ Object
ensure the flash is empty but existent.
-
#assert_flash_equal(expected = nil, key = nil, message = nil) ⇒ Object
:nodoc:.
-
#assert_flash_exists(message = nil) ⇒ Object
ensure the flash exists.
-
#assert_flash_has(key = nil, message = nil) ⇒ Object
ensure that the flash has an object with the specified name.
-
#assert_flash_has_no(key = nil, message = nil) ⇒ Object
ensure that the flash has no object with the specified name.
-
#assert_flash_not_empty(message = nil) ⇒ Object
ensure the flash is not empty.
-
#assert_flash_not_exists(message = nil) ⇒ Object
ensure the flash does not exist.
-
#assert_invalid_column_on_record(key = nil, columns = "", message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and the specified column(s) are invalid.
-
#assert_invalid_record(key = nil, message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and is invalid.
-
#assert_no_cookie(key = nil, message = nil) ⇒ Object
– cookie assertions —————————————————.
-
#assert_redirect(message = nil) ⇒ Object
:nodoc:.
-
#assert_redirect_url(url = nil, message = nil) ⇒ Object
ensure our redirection url is an exact match.
-
#assert_redirect_url_match(pattern = nil, message = nil) ⇒ Object
ensure our redirection url matches a pattern.
-
#assert_rendered_file(expected = nil, message = nil) ⇒ Object
:nodoc:.
-
#assert_session_equal(expected = nil, key = nil, message = nil) ⇒ Object
:nodoc:.
-
#assert_session_has(key = nil, message = nil) ⇒ Object
ensure that the session has an object with the specified name.
-
#assert_session_has_no(key = nil, message = nil) ⇒ Object
ensure that the session has no object with the specified name.
-
#assert_success(message = nil) ⇒ Object
:nodoc:.
-
#assert_template_equal(expected = nil, key = nil, message = nil) ⇒ Object
(also: #assert_assigned_equal)
ensures that the object assigned to the template on
key
is equal toexpected
object. -
#assert_template_has(key = nil, message = nil) ⇒ Object
ensure that a template object with the given name exists.
-
#assert_template_has_no(key = nil, message = nil) ⇒ Object
ensure that a template object with the given name does not exist.
-
#assert_template_xpath_match(expression = nil, expected = nil, message = nil) ⇒ Object
Asserts that the template returns the
expected
string or array based on the XPathexpression
. -
#assert_valid_column_on_record(key = nil, columns = "", message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and the specified column(s) are valid.
-
#assert_valid_record(key = nil, message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and is valid.
Instance Method Details
#assert_cookie_equal(expected = nil, key = nil, message = nil) ⇒ Object
:nodoc:
50 51 52 53 54 55 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 50 def (expected = nil, key = nil, = nil) #:nodoc: actual = @response.[key] actual = actual.first if actual msg = (, "<?> expected in cookies['?'] but was <?>", expected, key, actual) assert_block(msg) { expected == actual } end |
#assert_flash_empty(message = nil) ⇒ Object
ensure the flash is empty but existent
89 90 91 92 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 89 def assert_flash_empty(=nil) #:nodoc: msg = (, "the flash is not empty <?>", @response.flash) assert_block(msg) { !@response.has_flash_with_contents? } end |
#assert_flash_equal(expected = nil, key = nil, message = nil) ⇒ Object
:nodoc:
102 103 104 105 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 102 def assert_flash_equal(expected = nil, key = nil, = nil) #:nodoc: msg = (, "<?> expected in flash['?'] but was <?>", expected, key, @response.flash[key]) assert_block(msg) { expected == @response.flash[key] } end |
#assert_flash_exists(message = nil) ⇒ Object
ensure the flash exists
75 76 77 78 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 75 def assert_flash_exists(=nil) #:nodoc: msg = (, "the flash does not exist <?>", @response.session['flash'] ) assert_block(msg) { @response.has_flash? } end |
#assert_flash_has(key = nil, message = nil) ⇒ Object
ensure that the flash has an object with the specified name
61 62 63 64 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 61 def assert_flash_has(key=nil, =nil) #:nodoc: msg = (, "<?> is not in the flash <?>", key, @response.flash) assert_block(msg) { @response.has_flash_object?(key) } end |
#assert_flash_has_no(key = nil, message = nil) ⇒ Object
ensure that the flash has no object with the specified name
68 69 70 71 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 68 def assert_flash_has_no(key=nil, =nil) #:nodoc: msg = (, "<?> is in the flash <?>", key, @response.flash) assert_block(msg) { !@response.has_flash_object?(key) } end |
#assert_flash_not_empty(message = nil) ⇒ Object
ensure the flash is not empty
96 97 98 99 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 96 def assert_flash_not_empty(=nil) #:nodoc: msg = (, "the flash is empty") assert_block(msg) { @response.has_flash_with_contents? } end |
#assert_flash_not_exists(message = nil) ⇒ Object
ensure the flash does not exist
82 83 84 85 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 82 def assert_flash_not_exists(=nil) #:nodoc: msg = (, "the flash exists <?>", @response.flash) assert_block(msg) { !@response.has_flash? } end |
#assert_invalid_column_on_record(key = nil, columns = "", message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and the specified column(s) are invalid.
198 199 200 201 202 203 204 205 206 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 198 def assert_invalid_column_on_record(key = nil, columns = "", = nil) #:nodoc: record = find_record_in_template(key) record.send(:validate) cols = glue_columns(columns) cols.delete_if { |col| record.errors.invalid?(col) } msg = (, "Active Record has valid columns <?>)", cols.join(",") ) assert_block(msg) { cols.empty? } end |
#assert_invalid_record(key = nil, message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and is invalid.
178 179 180 181 182 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 178 def assert_invalid_record(key = nil, = nil) #:nodoc: record = find_record_in_template(key) msg = (, "Active Record is valid)") assert_block(msg) { !record.valid? } end |
#assert_no_cookie(key = nil, message = nil) ⇒ Object
– cookie assertions —————————————————
43 44 45 46 47 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 43 def (key = nil, = nil) #:nodoc: actual = @response.[key] msg = (, "<?> not expected in cookies['?']", actual, key) assert_block(msg) { actual.nil? or actual.empty? } end |
#assert_redirect(message = nil) ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 11 def assert_redirect(=nil) #:nodoc: assert_response(:redirect, ) end |
#assert_redirect_url(url = nil, message = nil) ⇒ Object
ensure our redirection url is an exact match
110 111 112 113 114 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 110 def assert_redirect_url(url=nil, =nil) #:nodoc: assert_redirect() msg = (, "<?> is not the redirected location <?>", url, @response.redirect_url) assert_block(msg) { @response.redirect_url == url } end |
#assert_redirect_url_match(pattern = nil, message = nil) ⇒ Object
ensure our redirection url matches a pattern
118 119 120 121 122 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 118 def assert_redirect_url_match(pattern=nil, =nil) #:nodoc: assert_redirect() msg = (, "<?> was not found in the location: <?>", pattern, @response.redirect_url) assert_block(msg) { @response.redirect_url_match?(pattern) } end |
#assert_rendered_file(expected = nil, message = nil) ⇒ Object
:nodoc:
16 17 18 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 16 def assert_rendered_file(expected=nil, =nil) #:nodoc: assert_template(expected, ) end |
#assert_session_equal(expected = nil, key = nil, message = nil) ⇒ Object
:nodoc:
35 36 37 38 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 35 def assert_session_equal(expected = nil, key = nil, = nil) #:nodoc: msg = (, "<?> expected in session['?'] but was <?>", expected, key, @response.session[key]) assert_block(msg) { expected == @response.session[key] } end |
#assert_session_has(key = nil, message = nil) ⇒ Object
ensure that the session has an object with the specified name
22 23 24 25 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 22 def assert_session_has(key=nil, =nil) #:nodoc: msg = (, "<?> is not in the session <?>", key, @response.session) assert_block(msg) { @response.has_session_object?(key) } end |
#assert_session_has_no(key = nil, message = nil) ⇒ Object
ensure that the session has no object with the specified name
29 30 31 32 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 29 def assert_session_has_no(key=nil, =nil) #:nodoc: msg = (, "<?> is in the session <?>", key, @response.session) assert_block(msg) { !@response.has_session_object?(key) } end |
#assert_success(message = nil) ⇒ Object
:nodoc:
6 7 8 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 6 def assert_success(=nil) #:nodoc: assert_response(:success, ) end |
#assert_template_equal(expected = nil, key = nil, message = nil) ⇒ Object Also known as: assert_assigned_equal
ensures that the object assigned to the template on key
is equal to expected
object.
143 144 145 146 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 143 def assert_template_equal(expected = nil, key = nil, = nil) #:nodoc: msg = (, "<?> expected in assigns['?'] but was <?>", expected, key, @response.template.assigns[key.to_s]) assert_block(msg) { expected == @response.template.assigns[key.to_s] } end |
#assert_template_has(key = nil, message = nil) ⇒ Object
ensure that a template object with the given name exists
129 130 131 132 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 129 def assert_template_has(key=nil, =nil) #:nodoc: msg = (, "<?> is not a template object", key ) assert_block(msg) { @response.has_template_object?(key) } end |
#assert_template_has_no(key = nil, message = nil) ⇒ Object
ensure that a template object with the given name does not exist
136 137 138 139 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 136 def assert_template_has_no(key=nil,=nil) #:nodoc: msg = (, "<?> is a template object <?>", key, @response.template_objects[key]) assert_block(msg) { !@response.has_template_object?(key) } end |
#assert_template_xpath_match(expression = nil, expected = nil, message = nil) ⇒ Object
Asserts that the template returns the expected
string or array based on the XPath expression
. This will only work if the template rendered a valid XML document.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 153 def assert_template_xpath_match(expression=nil, expected=nil, =nil) #:nodoc: xml, matches = REXML::Document.new(@response.body), [] xml.elements.each(expression) { |e| matches << e.text } if matches.empty? then msg = (, "<?> not found in document", expression) flunk(msg) return elsif matches.length < 2 then matches = matches.first end msg = (, "<?> found <?>, not <?>", expression, matches, expected) assert_block(msg) { matches == expected } end |
#assert_valid_column_on_record(key = nil, columns = "", message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and the specified column(s) are valid.
186 187 188 189 190 191 192 193 194 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 186 def assert_valid_column_on_record(key = nil, columns = "", = nil) #:nodoc: record = find_record_in_template(key) record.send(:validate) cols = glue_columns(columns) cols.delete_if { |col| !record.errors.invalid?(col) } msg = (, "Active Record has invalid columns <?>)", cols.join(",") ) assert_block(msg) { cols.empty? } end |
#assert_valid_record(key = nil, message = nil) ⇒ Object
Assert the template object with the given name is an Active Record descendant and is valid.
170 171 172 173 174 |
# File 'lib/action_controller/assertions/deprecated_assertions.rb', line 170 def assert_valid_record(key = nil, = nil) #:nodoc: record = find_record_in_template(key) msg = (, "Active Record is invalid <?>)", record.errors.) assert_block(msg) { record.valid? } end |