2011-05-31 23:07:20 +02:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2007-03-30 04:36:52 +00:00
|
|
|
require 'contexts_controller'
|
|
|
|
|
|
|
|
|
|
# Re-raise errors caught by the controller.
|
|
|
|
|
class ContextsController; def rescue_action(e) raise e end; end
|
|
|
|
|
|
|
|
|
|
class ContextXmlApiTest < ActionController::IntegrationTest
|
2008-06-17 12:35:36 -04:00
|
|
|
fixtures :users, :contexts, :preferences
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
@@context_name = "@newcontext"
|
|
|
|
|
@@valid_postdata = "<request><context><name>#{@@context_name}</name></context></request>"
|
|
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
assert_test_environment_ok
|
|
|
|
|
end
|
2009-12-08 12:36:00 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def test_fails_with_invalid_xml_format
|
2008-11-29 12:00:06 -05:00
|
|
|
# Fails too hard for test to catch
|
|
|
|
|
# authenticated_post_xml_to_context_create "<foo></bar>"
|
|
|
|
|
# assert_equal 500, @integration_session.status
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_fails_with_invalid_xml_format2
|
|
|
|
|
authenticated_post_xml_to_context_create "<request><context></context></request>"
|
|
|
|
|
assert_404_invalid_xml
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_xml_simple_param_parsing
|
|
|
|
|
authenticated_post_xml_to_context_create
|
|
|
|
|
assert @controller.params.has_key?(:request)
|
|
|
|
|
assert @controller.params[:request].has_key?(:context)
|
|
|
|
|
assert @controller.params[:request][:context].has_key?(:name)
|
|
|
|
|
assert_equal @@context_name, @controller.params[:request][:context][:name]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_fails_with_too_long_name
|
|
|
|
|
invalid_with_long_name_postdata = "<request><context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context></request>"
|
|
|
|
|
authenticated_post_xml_to_context_create invalid_with_long_name_postdata
|
2007-05-21 06:12:55 +00:00
|
|
|
assert_response 409
|
2007-03-30 04:36:52 +00:00
|
|
|
assert_xml_select 'errors' do
|
|
|
|
|
assert_select 'error', 1, 'Name context name must be less than 256 characters'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2007-04-06 03:30:20 +00:00
|
|
|
def test_fails_with_comma_in_name
|
|
|
|
|
authenticated_post_xml_to_context_create "<request><context><name>foo,bar</name></context></request>"
|
2007-05-21 06:12:55 +00:00
|
|
|
assert_response 409
|
2007-03-30 04:36:52 +00:00
|
|
|
assert_xml_select 'errors' do
|
2007-04-06 03:30:20 +00:00
|
|
|
assert_select 'error', 1, 'Name cannot contain the comma (\',\') character'
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-10-06 21:13:31 +02:00
|
|
|
|
|
|
|
|
def test_fails_with_401_if_not_authorized_user
|
|
|
|
|
authenticated_post_xml_to_context_create @@valid_postdata, 'nobody', 'nohow'
|
|
|
|
|
assert_response 401
|
|
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
def test_creates_new_context
|
2009-12-07 18:41:23 -05:00
|
|
|
assert_difference 'Context.count' do
|
2007-12-04 06:24:23 +00:00
|
|
|
authenticated_post_xml_to_context_create
|
|
|
|
|
assert_response 201
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
context1 = Context.find_by_name(@@context_name)
|
|
|
|
|
assert_not_nil context1, "expected context '#{@@context_name}' to be created"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def authenticated_post_xml_to_context_create(postdata = @@valid_postdata, user = users(:other_user).login, password = 'sesame')
|
|
|
|
|
authenticated_post_xml "/contexts", user, password, postdata
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def assert_404_invalid_xml
|
2007-05-21 06:12:55 +00:00
|
|
|
assert_response_and_body 400, "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2009-12-07 18:41:23 -05:00
|
|
|
end
|