Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2635

Show
Ignore:
Timestamp:
10/16/05 02:20:53 (3 years ago)
Author:
xal
Message:

added assert_valid to AP

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r2630 r2635  
    11*SVN* 
     2 
     3* Added assert_vaild. Reports the proper AR error messages as fail message when the passed record is invalid [Tobias Luetke] 
    24 
    35* Add temporary support for passing locals to render using string keys [Nicholas Seckar] 
  • trunk/actionpack/lib/action_controller/assertions.rb

    r2611 r2635  
    284284        end 
    285285      end 
     286 
     287      # ensures that the passed record is valid by active record standards. returns the error messages if not 
     288      def assert_valid(record)                                    
     289        clean_backtrace do 
     290          assert record.valid?, record.errors.full_messages         
     291        end 
     292      end              
    286293       
    287294      def clean_backtrace(&block) 
  • trunk/actionpack/test/controller/action_pack_assertions_test.rb

    r1971 r2635  
    7878    raise "post" if @request.post? 
    7979    render_text "request method: #{@request.env['REQUEST_METHOD']}" 
     80  end        
     81   
     82  def get_valid_record 
     83    @record = Class.new do        
     84      def valid? 
     85        true 
     86      end 
     87 
     88      def errors 
     89        Class.new do  
     90           def full_messages; '...stuff...'; end           
     91        end.new 
     92      end     
     93     
     94    end.new 
     95         
     96    render :nothing => true     
     97  end 
     98 
     99 
     100  def get_invalid_record 
     101    @record = Class.new do  
     102       
     103      def valid? 
     104        false 
     105      end 
     106       
     107      def errors 
     108        Class.new do  
     109           def full_messages; '...stuff...'; end           
     110        end.new 
     111      end 
     112    end.new                 
     113     
     114    render :nothing => true     
    80115  end 
    81116 
     
    421456    get :redirect_to_fellow_controller 
    422457    assert_redirected_to :controller => 'admin/user' 
     458  end                  
     459   
     460  def test_assert_valid 
     461    get :get_valid_record 
     462    assert_valid assigns('record')     
     463  end                 
     464   
     465  def test_assert_valid_failing 
     466    get :get_invalid_record 
     467     
     468    begin 
     469      assert_valid assigns('record')     
     470      assert false 
     471    rescue Test::Unit::AssertionFailedError => e              
     472    end 
    423473  end 
    424474end 
  • trunk/actionpack/test/controller/active_record_assertions_test.rb

    r1915 r2635  
    7676  def rescue_action(e) raise; end 
    7777end 
    78  
    79  
     78                     
    8079class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase 
    8180  def setup