Rails 2.1.1
Among other things, a security fix.
This commit is contained in:
parent
d2c4c8737c
commit
d4f97345db
354 changed files with 21027 additions and 3072 deletions
34
vendor/rails/activeresource/test/format_test.rb
vendored
34
vendor/rails/activeresource/test/format_test.rb
vendored
|
@ -5,14 +5,22 @@ class FormatTest < Test::Unit::TestCase
|
|||
def setup
|
||||
@matz = { :id => 1, :name => 'Matz' }
|
||||
@david = { :id => 2, :name => 'David' }
|
||||
|
||||
|
||||
@programmers = [ @matz, @david ]
|
||||
end
|
||||
|
||||
|
||||
def test_http_format_header_name
|
||||
header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:get]
|
||||
assert_equal 'Accept', header_name
|
||||
|
||||
headers_names = [ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:put], ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:post]]
|
||||
headers_names.each{|header_name| assert_equal 'Content-Type', header_name}
|
||||
end
|
||||
|
||||
def test_formats_on_single_element
|
||||
for format in [ :json, :xml ]
|
||||
using_format(Person, format) do
|
||||
ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {}, ActiveResource::Formats[format].encode(@david)
|
||||
ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
|
||||
assert_equal @david[:name], Person.find(1).name
|
||||
end
|
||||
end
|
||||
|
@ -21,7 +29,7 @@ class FormatTest < Test::Unit::TestCase
|
|||
def test_formats_on_collection
|
||||
for format in [ :json, :xml ]
|
||||
using_format(Person, format) do
|
||||
ActiveResource::HttpMock.respond_to.get "/people.#{format}", {}, ActiveResource::Formats[format].encode(@programmers)
|
||||
ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers)
|
||||
remote_programmers = Person.find(:all)
|
||||
assert_equal 2, remote_programmers.size
|
||||
assert remote_programmers.select { |p| p.name == 'David' }
|
||||
|
@ -32,7 +40,7 @@ class FormatTest < Test::Unit::TestCase
|
|||
def test_formats_on_custom_collection_method
|
||||
for format in [ :json, :xml ]
|
||||
using_format(Person, format) do
|
||||
ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {}, ActiveResource::Formats[format].encode([@david])
|
||||
ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode([@david])
|
||||
remote_programmers = Person.get(:retrieve, :name => 'David')
|
||||
assert_equal 1, remote_programmers.size
|
||||
assert_equal @david[:id], remote_programmers[0]['id']
|
||||
|
@ -40,13 +48,13 @@ class FormatTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_formats_on_custom_element_method
|
||||
for format in [ :json, :xml ]
|
||||
using_format(Person, format) do
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.get "/people/2.#{format}", {}, ActiveResource::Formats[format].encode(@david)
|
||||
mock.get "/people/2/shallow.#{format}", {}, ActiveResource::Formats[format].encode(@david)
|
||||
mock.get "/people/2.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
|
||||
mock.get "/people/2/shallow.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
|
||||
end
|
||||
remote_programmer = Person.find(2).get(:shallow)
|
||||
assert_equal @david[:id], remote_programmer['id']
|
||||
|
@ -57,20 +65,24 @@ class FormatTest < Test::Unit::TestCase
|
|||
for format in [ :json, :xml ]
|
||||
ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' })
|
||||
using_format(Person, format) do
|
||||
ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {}, ryan, 201, 'Location' => "/people/5.#{format}"
|
||||
remote_ryan = Person.new(:name => 'Ryan')
|
||||
ActiveResource::HttpMock.respond_to.post "/people.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, ryan, 201, {'Location' => "/people/5.#{format}"}
|
||||
remote_ryan.save
|
||||
|
||||
remote_ryan = Person.new(:name => 'Ryan')
|
||||
ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, ryan, 201, {'Location' => "/people/5.#{format}"}
|
||||
assert_equal ActiveResource::Response.new(ryan, 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_setting_format_before_site
|
||||
resource = Class.new(ActiveResource::Base)
|
||||
resource.format = :json
|
||||
resource.site = 'http://37s.sunrise.i:3000'
|
||||
assert_equal ActiveResource::Formats[:json], resource.connection.format
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def using_format(klass, mime_type_reference)
|
||||
previous_format = klass.format
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue