mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
all non-cucumber tests are passing
This commit is contained in:
parent
13b58f3a10
commit
63175c115b
46 changed files with 248 additions and 505 deletions
|
|
@ -1,60 +1,39 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'contexts_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ContextsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ContextXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users, :contexts, :preferences
|
||||
|
||||
@@context_name = "@newcontext"
|
||||
@@valid_postdata = "<request><context><name>#{@@context_name}</name></context></request>"
|
||||
@@valid_postdata = "<context><name>#{@@context_name}</name></context>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format
|
||||
# Fails too hard for test to catch
|
||||
# authenticated_post_xml_to_context_create "<foo></bar>"
|
||||
# assert_equal 500, @integration_session.status
|
||||
end
|
||||
# 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
|
||||
|
||||
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]
|
||||
assert @controller.params.has_key?(:context)
|
||||
assert @controller.params[:context].has_key?(:name)
|
||||
assert_equal @@context_name, @controller.params[:context][:name]
|
||||
end
|
||||
|
||||
def test_fails_gracefully_with_invalid_xml_format
|
||||
authenticated_post_xml_to_context_create "<context_name></context_name>"
|
||||
assert_responses_with_error 'Name context must have a name'
|
||||
end
|
||||
|
||||
def test_fails_with_too_long_name
|
||||
invalid_with_long_name_postdata = "<request><context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context></request>"
|
||||
invalid_with_long_name_postdata = "<context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context>"
|
||||
authenticated_post_xml_to_context_create invalid_with_long_name_postdata
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, 'Name context name must be less than 256 characters'
|
||||
end
|
||||
assert_responses_with_error 'Name context name must be less than 256 characters'
|
||||
end
|
||||
|
||||
def test_fails_with_comma_in_name
|
||||
authenticated_post_xml_to_context_create "<request><context><name>foo,bar</name></context></request>"
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, 'Name cannot contain the comma (\',\') character'
|
||||
end
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_context_create @@valid_postdata, 'nobody', 'nohow'
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
|
||||
def test_creates_new_context
|
||||
assert_difference 'Context.count' do
|
||||
authenticated_post_xml_to_context_create
|
||||
|
|
@ -67,11 +46,7 @@ class ContextXmlApiTest < ActionController::IntegrationTest
|
|||
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
|
||||
authenticated_post_xml "/contexts.xml", user, password, postdata
|
||||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 400, "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue