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

Changeset 7532

Show
Ignore:
Timestamp:
09/21/07 23:31:21 (1 year ago)
Author:
david
Message:

Increase test coverage (closes #8699, #8700) [josh]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activeresource/test/base_errors_test.rb

    r5967 r7532  
    1010    assert_equal @person.save, false 
    1111  end 
    12    
     12 
    1313  def test_should_mark_as_invalid 
    1414    assert !@person.valid? 
    1515  end 
    16    
     16 
    1717  def test_should_parse_xml_errors 
    1818    assert_kind_of ActiveResource::Errors, @person.errors 
     
    2121 
    2222  def test_should_parse_errors_to_individual_attributes 
     23    assert @person.errors.invalid?(:name)     
    2324    assert_equal "can't be blank", @person.errors.on(:age) 
    2425    assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name] 
    2526    assert_equal "Person quota full for today.", @person.errors.on_base 
     27  end 
     28 
     29  def test_should_iterate_over_errors 
     30    errors = [] 
     31    @person.errors.each { |attribute, message| errors << [attribute, message] } 
     32    assert_equal ["name", "can't be blank"], errors.first 
     33  end 
     34 
     35  def test_should_iterate_over_full_errors 
     36    errors = [] 
     37    @person.errors.each_full { |message| errors << message } 
     38    assert_equal "Name can't be blank", errors.first 
    2639  end 
    2740 
  • trunk/activeresource/test/base/custom_methods_test.rb

    r7074 r7532  
    1919      mock.get    "/people/retrieve.xml?name=Matz", {}, @matz_array 
    2020      mock.get    "/people/managers.xml", {}, @matz_array 
     21      mock.post   "/people/hire.xml?name=Matz", {}, nil, 201 
    2122      mock.put    "/people/1/promote.xml?position=Manager", {}, nil, 204 
    2223      mock.put    "/people/promote.xml?name=Matz", {}, nil, 204, {} 
     
    2526      mock.delete "/people/1/deactivate.xml", {}, nil, 200 
    2627      mock.post   "/people/new/register.xml",      {}, @ryan, 201, 'Location' => '/people/5.xml' 
     28      mock.post   "/people/1/register.xml", {}, @matz, 201 
    2729      mock.get    "/people/1/addresses/1.xml", {}, @addy 
    2830      mock.get    "/people/1/addresses/1/deep.xml", {}, @addy_deep 
     
    3638    ActiveResource::HttpMock.reset! 
    3739  end 
    38    
     40 
    3941  def test_custom_collection_method 
    4042    # GET 
    4143    assert_equal([{ "id" => 1, "name" => 'Matz' }], Person.get(:retrieve, :name => 'Matz')) 
    42      
     44 
     45    # POST 
     46    assert_equal(ActiveResource::Response.new("", 201, {}), Person.post(:hire, :name => 'Matz')) 
     47 
    4348    # PUT 
    4449    assert_equal ActiveResource::Response.new("", 204, {}), 
    4550                   Person.put(:promote, {:name => 'Matz'}, 'atestbody') 
    4651    assert_equal ActiveResource::Response.new("", 204, {}), Person.put(:sort, :by => 'name') 
    47      
     52 
    4853    # DELETE 
    4954    Person.delete :deactivate, :name => 'Matz' 
    50      
     55 
    5156    # Nested resource 
    5257    assert_equal ActiveResource::Response.new("", 204, {}), StreetAddress.put(:sort, :person_id => 1, :by => 'name') 
    5358  end 
    54    
     59 
    5560  def test_custom_element_method 
    5661    # Test GET against an element URL 
     
    7075                   StreetAddress.find(1, :params => { :person_id => 1 }).put(:normalize_phone, :locale => 'US') 
    7176  end 
    72    
     77 
    7378  def test_custom_new_element_method 
    7479    # Test POST against a new element URL 
    7580    ryan = Person.new(:name => 'Ryan') 
    7681    assert_equal ActiveResource::Response.new(@ryan, 201, {'Location' => '/people/5.xml'}), ryan.post(:register) 
    77      
     82 
    7883    # Test POST against a nested collection URL 
    7984    addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1) 
     
    8186                   201, {'Location' => '/people/1/addresses/2.xml'}), 
    8287                 addy.post(:link) 
     88 
     89    matz = Person.new(:id => 1, :name => 'Matz') 
     90    assert_equal ActiveResource::Response.new(@matz, 201), matz.post(:register) 
    8391  end 
    84    
     92 
    8593  def test_find_custom_resources 
    8694    assert_equal 'Matz', Person.find(:all, :from => :managers).first.name