Changeset 1190
- Timestamp:
- 04/17/05 11:47:54 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/assertions.rb
r1189 r1190 60 60 end 61 61 62 # Asserts that the request was rendered with the appropriate template file 63 def assert_template(expected =nil, message=nil)62 # Asserts that the request was rendered with the appropriate template file. 63 def assert_template(expected = nil, message=nil) 64 64 rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file 65 65 msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered) … … 72 72 end 73 73 end 74 75 alias_method :assert_rendered_file, :assert_template #:nodoc:76 77 # -- routing assertions --------------------------------------------------78 74 79 75 # Asserts that the routing of the given path is handled correctly and that the parsed options match. trunk/actionpack/lib/action_controller/deprecated_assertions.rb
r1189 r1190 5 5 module Test #:nodoc: 6 6 module Unit #:nodoc: 7 module Assertions #:nodoc:8 def assert_success(message=nil) 7 module Assertions 8 def assert_success(message=nil) #:nodoc: 9 9 assert_response(:success, message) 10 10 end 11 11 12 def assert_redirect(message=nil) 12 def assert_redirect(message=nil) #:nodoc: 13 13 assert_response(:redirect, message) 14 14 end 15 15 16 def assert_rendered_file(expected=nil, message=nil) #:nodoc: 17 assert_template(expected, message) 18 end 19 16 20 # ensure that the session has an object with the specified name 17 def assert_session_has(key=nil, message=nil) 21 def assert_session_has(key=nil, message=nil) #:nodoc: 18 22 msg = build_message(message, "<?> is not in the session <?>", key, @response.session) 19 23 assert_block(msg) { @response.has_session_object?(key) } … … 21 25 22 26 # ensure that the session has no object with the specified name 23 def assert_session_has_no(key=nil, message=nil) 27 def assert_session_has_no(key=nil, message=nil) #:nodoc: 24 28 msg = build_message(message, "<?> is in the session <?>", key, @response.session) 25 29 assert_block(msg) { !@response.has_session_object?(key) } 26 30 end 27 31 28 def assert_session_equal(expected = nil, key = nil, message = nil) 32 def assert_session_equal(expected = nil, key = nil, message = nil) #:nodoc: 29 33 msg = build_message(message, "<?> expected in session['?'] but was <?>", expected, key, @response.session[key]) 30 34 assert_block(msg) { expected == @response.session[key] } … … 33 37 # -- cookie assertions --------------------------------------------------- 34 38 35 def assert_no_cookie(key = nil, message = nil) 39 def assert_no_cookie(key = nil, message = nil) #:nodoc: 36 40 actual = @response.cookies[key] 37 41 msg = build_message(message, "<?> not expected in cookies['?']", actual, key) … … 39 43 end 40 44 41 def assert_cookie_equal(expected = nil, key = nil, message = nil) 45 def assert_cookie_equal(expected = nil, key = nil, message = nil) #:nodoc: 42 46 actual = @response.cookies[key] 43 47 actual = actual.first if actual … … 49 53 50 54 # ensure that the flash has an object with the specified name 51 def assert_flash_has(key=nil, message=nil) 55 def assert_flash_has(key=nil, message=nil) #:nodoc: 52 56 msg = build_message(message, "<?> is not in the flash <?>", key, @response.flash) 53 57 assert_block(msg) { @response.has_flash_object?(key) } … … 55 59 56 60 # ensure that the flash has no object with the specified name 57 def assert_flash_has_no(key=nil, message=nil) 61 def assert_flash_has_no(key=nil, message=nil) #:nodoc: 58 62 msg = build_message(message, "<?> is in the flash <?>", key, @response.flash) 59 63 assert_block(msg) { !@response.has_flash_object?(key) } … … 61 65 62 66 # ensure the flash exists 63 def assert_flash_exists(message=nil) 67 def assert_flash_exists(message=nil) #:nodoc: 64 68 msg = build_message(message, "the flash does not exist <?>", @response.session['flash'] ) 65 69 assert_block(msg) { @response.has_flash? } … … 67 71 68 72 # ensure the flash does not exist 69 def assert_flash_not_exists(message=nil) 73 def assert_flash_not_exists(message=nil) #:nodoc: 70 74 msg = build_message(message, "the flash exists <?>", @response.flash) 71 75 assert_block(msg) { !@response.has_flash? } … … 73 77 74 78 # ensure the flash is empty but existent 75 def assert_flash_empty(message=nil) 79 def assert_flash_empty(message=nil) #:nodoc: 76 80 msg = build_message(message, "the flash is not empty <?>", @response.flash) 77 81 assert_block(msg) { !@response.has_flash_with_contents? } … … 79 83 80 84 # ensure the flash is not empty 81 def assert_flash_not_empty(message=nil) 85 def assert_flash_not_empty(message=nil) #:nodoc: 82 86 msg = build_message(message, "the flash is empty") 83 87 assert_block(msg) { @response.has_flash_with_contents? } 84 88 end 85 89 86 def assert_flash_equal(expected = nil, key = nil, message = nil) 90 def assert_flash_equal(expected = nil, key = nil, message = nil) #:nodoc: 87 91 msg = build_message(message, "<?> expected in flash['?'] but was <?>", expected, key, @response.flash[key]) 88 92 assert_block(msg) { expected == @response.flash[key] } … … 91 95 92 96 # ensure our redirection url is an exact match 93 def assert_redirect_url(url=nil, message=nil) 97 def assert_redirect_url(url=nil, message=nil) #:nodoc: 94 98 assert_redirect(message) 95 99 msg = build_message(message, "<?> is not the redirected location <?>", url, @response.redirect_url) … … 98 102 99 103 # ensure our redirection url matches a pattern 100 def assert_redirect_url_match(pattern=nil, message=nil) 104 def assert_redirect_url_match(pattern=nil, message=nil) #:nodoc: 101 105 assert_redirect(message) 102 106 msg = build_message(message, "<?> was not found in the location: <?>", pattern, @response.redirect_url) … … 108 112 109 113 # ensure that a template object with the given name exists 110 def assert_template_has(key=nil, message=nil) 114 def assert_template_has(key=nil, message=nil) #:nodoc: 111 115 msg = build_message(message, "<?> is not a template object", key ) 112 116 assert_block(msg) { @response.has_template_object?(key) } … … 114 118 115 119 # ensure that a template object with the given name does not exist 116 def assert_template_has_no(key=nil,message=nil) 120 def assert_template_has_no(key=nil,message=nil) #:nodoc: 117 121 msg = build_message(message, "<?> is a template object <?>", key, @response.template_objects[key]) 118 122 assert_block(msg) { !@response.has_template_object?(key) } … … 120 124 121 125 # ensures that the object assigned to the template on +key+ is equal to +expected+ object. 122 def assert_template_equal(expected = nil, key = nil, message = nil) 126 def assert_template_equal(expected = nil, key = nil, message = nil) #:nodoc: 123 127 msg = build_message(message, "<?> expected in assigns['?'] but was <?>", expected, key, @response.template.assigns[key.to_s]) 124 128 assert_block(msg) { expected == @response.template.assigns[key.to_s] } … … 128 132 # Asserts that the template returns the +expected+ string or array based on the XPath +expression+. 129 133 # This will only work if the template rendered a valid XML document. 130 def assert_template_xpath_match(expression=nil, expected=nil, message=nil) 134 def assert_template_xpath_match(expression=nil, expected=nil, message=nil) #:nodoc: 131 135 xml, matches = REXML::Document.new(@response.body), [] 132 136 xml.elements.each(expression) { |e| matches << e.text } … … 144 148 145 149 # Assert the template object with the given name is an Active Record descendant and is valid. 146 def assert_valid_record(key = nil, message = nil) 150 def assert_valid_record(key = nil, message = nil) #:nodoc: 147 151 record = find_record_in_template(key) 148 152 msg = build_message(message, "Active Record is invalid <?>)", record.errors.full_messages) … … 151 155 152 156 # Assert the template object with the given name is an Active Record descendant and is invalid. 153 def assert_invalid_record(key = nil, message = nil) 157 def assert_invalid_record(key = nil, message = nil) #:nodoc: 154 158 record = find_record_in_template(key) 155 159 msg = build_message(message, "Active Record is valid)") … … 158 162 159 163 # Assert the template object with the given name is an Active Record descendant and the specified column(s) are valid. 160 def assert_valid_column_on_record(key = nil, columns = "", message = nil) 164 def assert_valid_column_on_record(key = nil, columns = "", message = nil) #:nodoc: 161 165 record = find_record_in_template(key) 162 166 record.send(:validate) … … 169 173 170 174 # Assert the template object with the given name is an Active Record descendant and the specified column(s) are invalid. 171 def assert_invalid_column_on_record(key = nil, columns = "", message = nil) 175 def assert_invalid_column_on_record(key = nil, columns = "", message = nil) #:nodoc: 172 176 record = find_record_in_template(key) 173 177 record.send(:validate)