diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-28 07:00:43 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-28 07:00:43 +0000 |
commit | dde527440a52317e2e7eb4a928009c036cdf772b (patch) | |
tree | 38d2074137aebb8f89911576f05d48e639f21d07 /actionpack | |
parent | b7df9162492383e2186762d85586b27ca120a1dd (diff) | |
download | rails-dde527440a52317e2e7eb4a928009c036cdf772b.tar.gz rails-dde527440a52317e2e7eb4a928009c036cdf772b.tar.bz2 rails-dde527440a52317e2e7eb4a928009c036cdf772b.zip |
Remove deprecated assertions.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6055 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/assertions.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/assertions/deprecated_assertions.rb | 228 | ||||
-rw-r--r-- | actionpack/test/activerecord/active_record_assertions_test.rb | 92 | ||||
-rw-r--r-- | actionpack/test/controller/action_pack_assertions_test.rb | 130 |
5 files changed, 3 insertions, 453 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 0819d3f9da..c9ab508ff4 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Remove deprecated assertions. [Jeremy Kemper] + * Change session restoration to allow namespaced models to be autoloaded. Closes #6348. [Nicholas Seckar] * Fix doubly appearing parameters due to string and symbol mixups. Closes #2551. [aeden] diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index f3d4558e92..f52076e863 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -52,7 +52,6 @@ module ActionController #:nodoc: include ActionController::Assertions::TagAssertions include ActionController::Assertions::DomAssertions include ActionController::Assertions::ModelAssertions - include ActionController::Assertions::DeprecatedAssertions end end @@ -71,7 +70,6 @@ require File.dirname(__FILE__) + '/assertions/tag_assertions' require File.dirname(__FILE__) + '/assertions/dom_assertions' require File.dirname(__FILE__) + '/assertions/routing_assertions' require File.dirname(__FILE__) + '/assertions/model_assertions' -require File.dirname(__FILE__) + '/assertions/deprecated_assertions' module Test #:nodoc: module Unit #:nodoc: @@ -79,4 +77,4 @@ module Test #:nodoc: include ActionController::Assertions end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/assertions/deprecated_assertions.rb b/actionpack/lib/action_controller/assertions/deprecated_assertions.rb deleted file mode 100644 index 5fd187933f..0000000000 --- a/actionpack/lib/action_controller/assertions/deprecated_assertions.rb +++ /dev/null @@ -1,228 +0,0 @@ -require 'rexml/document' - -module ActionController #:nodoc: - module Assertions #:nodoc: - module DeprecatedAssertions #:nodoc: - def assert_success(message=nil) #:nodoc: - assert_response(:success, message) - end - deprecate :assert_success => "use assert_response(:success)" - - def assert_redirect(message=nil) #:nodoc: - assert_response(:redirect, message) - end - deprecate :assert_redirect => "use assert_response(:redirect)" - - def assert_rendered_file(expected=nil, message=nil) #:nodoc: - assert_template(expected, message) - end - deprecate :assert_rendered_file => :assert_template - - # ensure that the session has an object with the specified name - def assert_session_has(key=nil, message=nil) #:nodoc: - msg = build_message(message, "<?> is not in the session <?>", key, @response.session) - assert_block(msg) { @response.has_session_object?(key) } - end - deprecate :assert_session_has => "use assert(@response.has_session_object?(key))" - - # ensure that the session has no object with the specified name - def assert_session_has_no(key=nil, message=nil) #:nodoc: - msg = build_message(message, "<?> is in the session <?>", key, @response.session) - assert_block(msg) { !@response.has_session_object?(key) } - end - deprecate :assert_session_has_no => "use assert(!@response.has_session_object?(key))" - - def assert_session_equal(expected = nil, key = nil, message = nil) #:nodoc: - msg = build_message(message, "<?> expected in session['?'] but was <?>", expected, key, @response.session[key]) - assert_block(msg) { expected == @response.session[key] } - end - deprecate :assert_session_equal => "use assert_equal(expected, @response[key])" - - # -- cookie assertions --------------------------------------------------- - - def assert_no_cookie(key = nil, message = nil) #:nodoc: - actual = @response.cookies[key] - msg = build_message(message, "<?> not expected in cookies['?']", actual, key) - assert_block(msg) { actual.nil? or actual.empty? } - end - deprecate :assert_no_cookie => "use assert(!@response.cookies.key?(key))" - - def assert_cookie_equal(expected = nil, key = nil, message = nil) #:nodoc: - actual = @response.cookies[key] - actual = actual.first if actual - msg = build_message(message, "<?> expected in cookies['?'] but was <?>", expected, key, actual) - assert_block(msg) { expected == actual } - end - deprecate :assert_cookie_equal => "use assert(@response.cookies.key?(key))" - - # -- flash assertions --------------------------------------------------- - - # ensure that the flash has an object with the specified name - def assert_flash_has(key=nil, message=nil) #:nodoc: - msg = build_message(message, "<?> is not in the flash <?>", key, @response.flash) - assert_block(msg) { @response.has_flash_object?(key) } - end - deprecate :assert_flash_has => "use assert(@response.has_flash_object?(key))" - - # ensure that the flash has no object with the specified name - def assert_flash_has_no(key=nil, message=nil) #:nodoc: - msg = build_message(message, "<?> is in the flash <?>", key, @response.flash) - assert_block(msg) { !@response.has_flash_object?(key) } - end - deprecate :assert_flash_has_no => "use assert(!@response.has_flash_object?(key))" - - # ensure the flash exists - def assert_flash_exists(message=nil) #:nodoc: - msg = build_message(message, "the flash does not exist <?>", @response.session['flash'] ) - assert_block(msg) { @response.has_flash? } - end - deprecate :assert_flash_exists => "use assert(@response.has_flash?)" - - # ensure the flash does not exist - def assert_flash_not_exists(message=nil) #:nodoc: - msg = build_message(message, "the flash exists <?>", @response.flash) - assert_block(msg) { !@response.has_flash? } - end - deprecate :assert_flash_not_exists => "use assert(!@response.has_flash?)" - - # ensure the flash is empty but existent - def assert_flash_empty(message=nil) #:nodoc: - msg = build_message(message, "the flash is not empty <?>", @response.flash) - assert_block(msg) { !@response.has_flash_with_contents? } - end - deprecate :assert_flash_empty => "use assert(!@response.has_flash_with_contents?)" - - # ensure the flash is not empty - def assert_flash_not_empty(message=nil) #:nodoc: - msg = build_message(message, "the flash is empty") - assert_block(msg) { @response.has_flash_with_contents? } - end - deprecate :assert_flash_not_empty => "use assert(@response.has_flash_with_contents?)" - - def assert_flash_equal(expected = nil, key = nil, message = nil) #:nodoc: - msg = build_message(message, "<?> expected in flash['?'] but was <?>", expected, key, @response.flash[key]) - assert_block(msg) { expected == @response.flash[key] } - end - deprecate :assert_flash_equal => "use assert_equal(expected, @response.flash[key])" - - - # ensure our redirection url is an exact match - def assert_redirect_url(url=nil, message=nil) #:nodoc: - assert_redirect(message) - msg = build_message(message, "<?> is not the redirected location <?>", url, @response.redirect_url) - assert_block(msg) { @response.redirect_url == url } - end - deprecate :assert_redirect_url => "use assert_equal(url, @response.redirect_url)" - - # ensure our redirection url matches a pattern - def assert_redirect_url_match(pattern=nil, message=nil) #:nodoc: - assert_redirect(message) - msg = build_message(message, "<?> was not found in the location: <?>", pattern, @response.redirect_url) - assert_block(msg) { @response.redirect_url_match?(pattern) } - end - deprecate :assert_redirect_url_match => "use assert(@response.redirect_url_match?(pattern))" - - - # -- template assertions ------------------------------------------------ - - # ensure that a template object with the given name exists - def assert_template_has(key=nil, message=nil) #:nodoc: - msg = build_message(message, "<?> is not a template object", key ) - assert_block(msg) { @response.has_template_object?(key) } - end - deprecate :assert_template_has => "use assert(@response.has_template_object?(key))" - - # ensure that a template object with the given name does not exist - def assert_template_has_no(key=nil,message=nil) #:nodoc: - msg = build_message(message, "<?> is a template object <?>", key, @response.template_objects[key]) - assert_block(msg) { !@response.has_template_object?(key) } - end - deprecate :assert_template_has_no => "use assert(!@response.has_template_object?(key))" - - # ensures that the object assigned to the template on +key+ is equal to +expected+ object. - def assert_template_equal(expected = nil, key = nil, message = nil) #:nodoc: - msg = build_message(message, "<?> expected in assigns['?'] but was <?>", expected, key, @response.template.assigns[key.to_s]) - assert_block(msg) { expected == @response.template.assigns[key.to_s] } - end - alias_method :assert_assigned_equal, :assert_template_equal - deprecate :assert_assigned_equal => "use assert_equal(expected, @response.template.assigns[key.to_s])" - deprecate :assert_template_equal => "use assert_equal(expected, @response.template.assigns[key.to_s])" - - # 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. - def assert_template_xpath_match(expression=nil, expected=nil, message=nil) #:nodoc: - xml, matches = REXML::Document.new(@response.body), [] - xml.elements.each(expression) { |e| matches << e.text } - if matches.empty? then - msg = build_message(message, "<?> not found in document", expression) - flunk(msg) - return - elsif matches.length < 2 then - matches = matches.first - end - - msg = build_message(message, "<?> found <?>, not <?>", expression, matches, expected) - assert_block(msg) { matches == expected } - end - deprecate :assert_template_xpath_match => "you should use assert_tag, instead" - - # Assert the template object with the given name is an Active Record descendant and is valid. - def assert_valid_record(key = nil, message = nil) #:nodoc: - record = find_record_in_template(key) - msg = build_message(message, "Active Record is invalid <?>)", record.errors.full_messages) - assert_block(msg) { record.valid? } - end - deprecate :assert_valid_record => "use assert(assigns(key).valid?)" - - # Assert the template object with the given name is an Active Record descendant and is invalid. - def assert_invalid_record(key = nil, message = nil) #:nodoc: - record = find_record_in_template(key) - msg = build_message(message, "Active Record is valid)") - assert_block(msg) { !record.valid? } - end - deprecate :assert_invalid_record => "use assert(!assigns(key).valid?)" - - # Assert the template object with the given name is an Active Record descendant and the specified column(s) are valid. - def assert_valid_column_on_record(key = nil, columns = "", message = nil) #:nodoc: - record = find_record_in_template(key) - record.send(:validate) - - cols = glue_columns(columns) - cols.delete_if { |col| !record.errors.invalid?(col) } - msg = build_message(message, "Active Record has invalid columns <?>)", cols.join(",") ) - assert_block(msg) { cols.empty? } - end - deprecate :assert_valid_column_on_record => "use assert(!record.errors.invalid?(column)) instead" - - # Assert the template object with the given name is an Active Record descendant and the specified column(s) are invalid. - def assert_invalid_column_on_record(key = nil, columns = "", message = nil) #:nodoc: - record = find_record_in_template(key) - record.send(:validate) - - cols = glue_columns(columns) - cols.delete_if { |col| record.errors.invalid?(col) } - msg = build_message(message, "Active Record has valid columns <?>)", cols.join(",") ) - assert_block(msg) { cols.empty? } - end - deprecate :assert_invalid_column_on_record => "use assert(record.errors.invalid?(column)) instead" - - private - def glue_columns(columns) - cols = [] - cols << columns if columns.class == String - cols += columns if columns.class == Array - cols - end - - def find_record_in_template(key = nil) - assert_not_nil assigns(key) - record = @response.template_objects[key] - - assert_not_nil(record) - assert_kind_of ActiveRecord::Base, record - - return record - end - end - end -end diff --git a/actionpack/test/activerecord/active_record_assertions_test.rb b/actionpack/test/activerecord/active_record_assertions_test.rb deleted file mode 100644 index 9a3c1127a2..0000000000 --- a/actionpack/test/activerecord/active_record_assertions_test.rb +++ /dev/null @@ -1,92 +0,0 @@ -require "#{File.dirname(__FILE__)}/../active_record_unit" - -class ActiveRecordAssertionsController < ActionController::Base - self.template_root = "#{File.dirname(__FILE__)}/../fixtures/" - - # fail with 1 bad column - def nasty_columns_1 - @company = Company.new - @company.name = "B" - @company.rating = 2 - render :inline => "snicker...." - end - - # fail with 2 bad columns - def nasty_columns_2 - @company = Company.new - @company.name = "" - @company.rating = 2 - render :inline => "double snicker...." - end - - # this will pass validation - def good_company - @company = Company.new - @company.name = "A" - @company.rating = 69 - render :inline => "Goodness Gracious!" - end - - # this will fail validation - def bad_company - @company = Company.new - render :inline => "Who's Bad?" - end - - # the safety dance...... - def rescue_action(e) raise; end -end - -class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase - fixtures :companies - - def setup - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @controller = ActiveRecordAssertionsController.new - super - end - - # test for 1 bad apple column - def test_some_invalid_columns - process :nasty_columns_1 - assert_response :success - - assert_deprecated_assertion { assert_invalid_record 'company' } - assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'rating' } - assert_deprecated_assertion { assert_valid_column_on_record 'company', 'name' } - assert_deprecated_assertion { assert_valid_column_on_record 'company', %w(name id) } - end - - # test for 2 bad apples columns - def test_all_invalid_columns - process :nasty_columns_2 - assert_response :success - - assert_deprecated_assertion { assert_invalid_record 'company' } - assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'rating' } - assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'name' } - assert_deprecated_assertion { assert_invalid_column_on_record 'company', %w(name rating) } - end - - # ensure we have no problems with an ActiveRecord - def test_valid_record - process :good_company - assert_response :success - - assert_deprecated_assertion { assert_valid_record 'company' } - end - - # ensure we have problems with an ActiveRecord - def test_invalid_record - process :bad_company - assert_response :success - - assert_deprecated_assertion { assert_invalid_record 'company' } - end - - protected - def assert_deprecated_assertion(message = nil, &block) - assert_deprecated(/assert_.*from test_/, &block) - end -end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 21930aa061..d9cfe18ae5 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -175,13 +175,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_tag :content => "/action_pack_assertions/flash_me" end - # test the session assertion to make sure something is there. - def test_assert_session_has - process :session_stuffing - assert_deprecated_assertion { assert_session_has 'xmas' } - assert_deprecated_assertion { assert_session_has_no 'halloween' } - end - # test the get method, make sure the request really was a get def test_get assert_raise(RuntimeError) { get :raise_on_get } @@ -209,49 +202,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase # assert_equal @response.body, 'request method: GET' # end - # test the assertion of goodies in the template - def test_assert_template_has - process :assign_this - assert_deprecated_assertion { assert_template_has 'howdy' } - end - - # test the assertion for goodies that shouldn't exist in the template - def test_assert_template_has_no - process :nothing - assert_deprecated_assertion { assert_template_has_no 'maple syrup' } - assert_deprecated_assertion { assert_template_has_no 'howdy' } - end - - # test the redirection assertions - def test_assert_redirect - process :redirect_internal - assert_deprecated_assertion { assert_redirect } - end - - # test the redirect url string - def test_assert_redirect_url - process :redirect_external - assert_deprecated_assertion do - assert_redirect_url 'http://www.rubyonrails.org' - end - end - - # test the redirection pattern matching on a string - def test_assert_redirect_url_match_string - process :redirect_external - assert_deprecated_assertion do - assert_redirect_url_match 'rails.org' - end - end - - # test the redirection pattern matching on a pattern - def test_assert_redirect_url_match_pattern - process :redirect_external - assert_deprecated_assertion do - assert_redirect_url_match /ruby/ - end - end - # test the redirection to a named route def test_assert_redirect_to_named_route with_routing do |set| @@ -317,47 +267,8 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase end end - # test the flash-based assertions with something is in the flash - def test_flash_assertions_full - process :flash_me - assert @response.has_flash_with_contents? - assert_deprecated_assertion { assert_flash_exists } - assert_deprecated_assertion { assert_flash_not_empty } - assert_deprecated_assertion { assert_flash_has 'hello' } - assert_deprecated_assertion { assert_flash_has_no 'stds' } - end - - # test the flash-based assertions with no flash at all - def test_flash_assertions_negative - process :nothing - assert_deprecated_assertion { assert_flash_empty } - assert_deprecated_assertion { assert_flash_has_no 'hello' } - assert_deprecated_assertion { assert_flash_has_no 'qwerty' } - end - - # test the assert_rendered_file - def test_assert_rendered_file - assert_deprecated(/render/) { process :hello_world } - assert_deprecated_assertion { assert_rendered_file 'test/hello_world' } - assert_deprecated_assertion { assert_rendered_file 'hello_world' } - end - - # test the assert_success assertion - def test_assert_success - process :nothing - assert_deprecated_assertion { assert_success } - end - # -- standard request/response object testing -------------------------------- - # ensure our session is working properly - def test_session_objects - process :session_stuffing - assert @response.has_session_object?('xmas') - assert_deprecated_assertion { assert_session_equal 'turkey', 'xmas' } - assert !@response.has_session_object?('easter') - end - # make sure that the template objects exist def test_template_objects_alive process :assign_this @@ -371,11 +282,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_nil @response.template_objects['howdy'] end - def test_assigned_equal - process :assign_this - assert_deprecated_assertion { assert_assigned_equal "ho", :howdy } - end - # check the empty flashing def test_flash_me_naked process :flash_me_naked @@ -399,14 +305,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_nil @response.flash['hello'] end - # examine that the flash objects are what we expect - def test_flash_equals - process :flash_me - assert_deprecated_assertion do - assert_flash_equal 'my name is inigo montoya...', 'hello' - end - end - # check if we were rendered by a file-based template? def test_rendered_action process :nothing @@ -489,29 +387,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_equal "Mr. David", @response.body end - def test_assert_template_xpath_match_no_matches - assert_deprecated(/render/) { process :hello_xml_world } - assert_raises Test::Unit::AssertionFailedError do - assert_deprecated_assertion do - assert_template_xpath_match('/no/such/node/in/document') - end - end - end - - def test_simple_one_element_xpath_match - assert_deprecated(/render/) { process :hello_xml_world } - assert_deprecated_assertion do - assert_template_xpath_match('//title', "Hello World") - end - end - - def test_array_of_elements_in_xpath_match - assert_deprecated(/render/) { process :hello_xml_world } - assert_deprecated_assertion do - assert_template_xpath_match('//p', %w( abes monks wiseguys )) - end - end - def test_follow_redirect process :redirect_to_action assert_redirected_to :action => "flash_me" @@ -577,11 +452,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase rescue Test::Unit::AssertionFailedError => e end end - - protected - def assert_deprecated_assertion(&block) - assert_deprecated(/assert/, &block) - end end class ActionPackHeaderTest < Test::Unit::TestCase |