mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
added assert_valid to AP
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2635 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
5e5c332c3e
commit
0279949b05
4 changed files with 61 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added assert_vaild. Reports the proper AR error messages as fail message when the passed record is invalid [Tobias Luetke]
|
||||
|
||||
* Add temporary support for passing locals to render using string keys [Nicholas Seckar]
|
||||
|
||||
* Clean up error pages by providing better backtraces [Nicholas Seckar]
|
||||
|
|
|
@ -284,6 +284,13 @@ module Test #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
# ensures that the passed record is valid by active record standards. returns the error messages if not
|
||||
def assert_valid(record)
|
||||
clean_backtrace do
|
||||
assert record.valid?, record.errors.full_messages
|
||||
end
|
||||
end
|
||||
|
||||
def clean_backtrace(&block)
|
||||
begin
|
||||
yield
|
||||
|
|
|
@ -79,6 +79,41 @@ class ActionPackAssertionsController < ActionController::Base
|
|||
render_text "request method: #{@request.env['REQUEST_METHOD']}"
|
||||
end
|
||||
|
||||
def get_valid_record
|
||||
@record = Class.new do
|
||||
def valid?
|
||||
true
|
||||
end
|
||||
|
||||
def errors
|
||||
Class.new do
|
||||
def full_messages; '...stuff...'; end
|
||||
end.new
|
||||
end
|
||||
|
||||
end.new
|
||||
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
def get_invalid_record
|
||||
@record = Class.new do
|
||||
|
||||
def valid?
|
||||
false
|
||||
end
|
||||
|
||||
def errors
|
||||
Class.new do
|
||||
def full_messages; '...stuff...'; end
|
||||
end.new
|
||||
end
|
||||
end.new
|
||||
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
# 911
|
||||
def rescue_action(e) raise; end
|
||||
end
|
||||
|
@ -421,6 +456,21 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
|||
get :redirect_to_fellow_controller
|
||||
assert_redirected_to :controller => 'admin/user'
|
||||
end
|
||||
|
||||
def test_assert_valid
|
||||
get :get_valid_record
|
||||
assert_valid assigns('record')
|
||||
end
|
||||
|
||||
def test_assert_valid_failing
|
||||
get :get_invalid_record
|
||||
|
||||
begin
|
||||
assert_valid assigns('record')
|
||||
assert false
|
||||
rescue Test::Unit::AssertionFailedError => e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ActionPackHeaderTest < Test::Unit::TestCase
|
||||
|
|
|
@ -76,7 +76,6 @@ class ActiveRecordAssertionsController < ActionController::Base
|
|||
def rescue_action(e) raise; end
|
||||
end
|
||||
|
||||
|
||||
class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@request = ActionController::TestRequest.new
|
||||
|
|
Loading…
Reference in a new issue