2014-05-16 18:03:13 -04:00
|
|
|
require 'test_helper'
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2013-05-11 23:13:16 +02:00
|
|
|
class ContextXmlApiTest < ActionDispatch::IntegrationTest
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
@@context_name = "@newcontext"
|
2012-04-27 14:22:16 +02:00
|
|
|
@@valid_postdata = "<context><name>#{@@context_name}</name></context>"
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2012-04-27 14:22:16 +02:00
|
|
|
# def test_fails_with_invalid_xml_format
|
|
|
|
|
# # Fails too hard for test to catch
|
|
|
|
|
# authenticated_post_xml_to_context_create "<foo></bar>"
|
|
|
|
|
# assert_response 500
|
|
|
|
|
# end
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
def test_xml_simple_param_parsing
|
|
|
|
|
authenticated_post_xml_to_context_create
|
2012-04-27 14:22:16 +02:00
|
|
|
assert @controller.params.has_key?(:context)
|
|
|
|
|
assert @controller.params[:context].has_key?(:name)
|
|
|
|
|
assert_equal @@context_name, @controller.params[:context][:name]
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2012-04-27 14:22:16 +02:00
|
|
|
def test_fails_gracefully_with_invalid_xml_format
|
2013-05-27 12:44:31 +02:00
|
|
|
authenticated_post_xml_to_context_create "<context><name></name></context>"
|
2012-04-27 14:22:16 +02:00
|
|
|
assert_responses_with_error 'Name context must have a name'
|
|
|
|
|
end
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def test_fails_with_too_long_name
|
2012-04-27 14:22:16 +02:00
|
|
|
invalid_with_long_name_postdata = "<context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context>"
|
2007-03-30 04:36:52 +00:00
|
|
|
authenticated_post_xml_to_context_create invalid_with_long_name_postdata
|
2012-04-27 14:22:16 +02:00
|
|
|
assert_responses_with_error 'Name context name must be less than 256 characters'
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2012-04-27 14:22:16 +02:00
|
|
|
def test_fails_with_401_if_not_authorized_user
|
2011-10-06 21:13:31 +02:00
|
|
|
authenticated_post_xml_to_context_create @@valid_postdata, 'nobody', 'nohow'
|
|
|
|
|
assert_response 401
|
|
|
|
|
end
|
2012-04-27 14:22:16 +02:00
|
|
|
|
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
|
2013-02-27 11:50:49 +01:00
|
|
|
context1 = Context.where(:name => @@context_name).first
|
2007-03-30 04:36:52 +00:00
|
|
|
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')
|
2012-04-27 14:22:16 +02:00
|
|
|
authenticated_post_xml "/contexts.xml", user, password, postdata
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2009-12-07 18:41:23 -05:00
|
|
|
end
|