提交 166c6381 编写于 作者: B Bob Aman 提交者: Pratik Naik

Improve exception handling when Location header is invalid. [#1192 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 91eeb0ff
...@@ -1006,7 +1006,7 @@ def load_attributes_from_response(response) ...@@ -1006,7 +1006,7 @@ def load_attributes_from_response(response)
# Takes a response from a typical create post and pulls the ID out # Takes a response from a typical create post and pulls the ID out
def id_from_response(response) def id_from_response(response)
response['Location'][/\/([^\/]*?)(\.\w+)?$/, 1] response['Location'][/\/([^\/]*?)(\.\w+)?$/, 1] if response['Location']
end end
def element_path(options = nil) def element_path(options = nil)
......
...@@ -627,6 +627,12 @@ def test_id_from_response ...@@ -627,6 +627,12 @@ def test_id_from_response
assert_equal '1', p.__send__(:id_from_response, resp) assert_equal '1', p.__send__(:id_from_response, resp)
end end
def test_id_from_response_without_location
p = Person.new
resp = {}
assert_equal nil, p.__send__(:id_from_response, resp)
end
def test_create_with_custom_prefix def test_create_with_custom_prefix
matzs_house = StreetAddress.new(:person_id => 1) matzs_house = StreetAddress.new(:person_id => 1)
matzs_house.save matzs_house.save
...@@ -670,7 +676,6 @@ def test_reload_works_without_prefix_options ...@@ -670,7 +676,6 @@ def test_reload_works_without_prefix_options
assert_equal person, person.reload assert_equal person, person.reload
end end
def test_create def test_create
rick = Person.create(:name => 'Rick') rick = Person.create(:name => 'Rick')
assert rick.valid? assert rick.valid?
...@@ -687,6 +692,14 @@ def test_create ...@@ -687,6 +692,14 @@ def test_create
assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') } assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') }
end end
def test_create_without_location
ActiveResource::HttpMock.respond_to do |mock|
mock.post "/people.xml", {}, nil, 201
end
person = Person.create(:name => 'Rick')
assert_equal nil, person.id
end
def test_clone def test_clone
matz = Person.find(1) matz = Person.find(1)
matz_c = matz.clone matz_c = matz.clone
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册