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

Changeset 8827

Show
Ignore:
Timestamp:
02/09/08 22:21:55 (1 year ago)
Author:
nzkoz
Message:

Use HEAD instead of GET inside exists? Closes #11062 [bscofield]

Files:

Legend:

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

    r8528 r8827  
    11*SVN* 
     2 
     3* Use HEAD instead of GET in exists? [bscofield] 
    24 
    35* Fix small documentation typo.  Closes #10670 [l.guidi] 
  • trunk/activeresource/lib/active_resource/base.rb

    r8528 r8827  
    437437      #   # => false 
    438438      def exists?(id, options = {}) 
    439         id && !find_single(id, options).nil? 
     439        if id 
     440          prefix_options, query_options = split_options(options[:params]) 
     441          path = element_path(id, prefix_options, query_options) 
     442          response = connection.head(path, headers) 
     443          response.code == 200 
     444        end 
     445        # id && !find_single(id, options).nil? 
    440446      rescue ActiveResource::ResourceNotFound 
    441447        false 
  • trunk/activeresource/lib/active_resource/connection.rb

    r8390 r8827  
    102102    end 
    103103 
     104    # Execute a HEAD request. 
     105    # Used to ... 
     106    def head(path, headers= {}) 
     107      request(:head, path, build_request_headers(headers)) 
     108    end 
     109 
    104110 
    105111    private 
  • trunk/activeresource/lib/active_resource/http_mock.rb

    r8462 r8827  
    1010      end 
    1111 
    12       for method in [ :post, :put, :get, :delete
     12      for method in [ :post, :put, :get, :delete, :head
    1313        module_eval <<-EOE, __FILE__, __LINE__ 
    1414          def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {}) 
     
    5757    end 
    5858 
    59     for method in [ :get, :delete
     59    for method in [ :get, :delete, :head
    6060      module_eval <<-EOE, __FILE__, __LINE__ 
    6161        def #{method}(path, headers) 
  • trunk/activeresource/test/base_test.rb

    r8566 r8827  
    3737      mock.delete "/people//addresses/1.xml",  {}, nil, 404 
    3838      mock.post   "/people//addresses.xml",    {}, nil, 404 
     39      mock.head   "/people/1.xml",             {}, nil, 200 
     40      mock.head   "/people/99.xml",            {}, nil, 404 
     41      mock.head   "/people/1/addresses/1.xml", {}, nil, 200 
     42      mock.head   "/people/1/addresses/2.xml", {}, nil, 404 
     43      mock.head   "/people/2/addresses/1.xml", {}, nil, 404 
    3944    end 
    4045  end 
  • trunk/activeresource/test/connection_test.rb

    r8566 r8827  
    2828      mock.post   "/people.xml",   {}, nil, 201, 'Location' => '/people/5.xml' 
    2929      mock.post   "/members.xml",  {}, @header, 201, 'Location' => '/people/6.xml' 
     30      mock.head   "/people/1.xml", {}, nil, 200 
    3031    end 
    3132  end 
     
    106107  end 
    107108 
     109  def test_head 
     110    response = @conn.head("/people/1.xml") 
     111    assert response.body.blank? 
     112    assert_equal 200, response.code 
     113  end 
     114 
    108115  def test_get_with_header 
    109116    david = @conn.get("/people/2.xml", @header)