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,18 +1,9 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'users_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class UsersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class UsersXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users
|
||||
|
||||
@@foobar_postdata = "<request><login>foo</login><password>bar</password></request>"
|
||||
@@johnny_postdata = "<request><login>johnny</login><password>barracuda</password></request>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
@@foobar_postdata = "<user><login>foo</login><password>bar</password></user>"
|
||||
@@johnny_postdata = "<user><login>johnny</login><password>barracuda</password></user>"
|
||||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_user_create @@foobar_postdata, 'nobody', 'nohow'
|
||||
|
|
@ -26,7 +17,7 @@ class UsersXmlApiTest < ActionController::IntegrationTest
|
|||
|
||||
def test_content_type_must_be_xml
|
||||
authenticated_post_xml_to_user_create @@foobar_postdata, users(:admin_user).login, 'abracadabra', {'CONTENT_TYPE' => "application/x-www-form-urlencoded"}
|
||||
assert_404_invalid_xml
|
||||
assert_response 400, "Expected response 400"
|
||||
end
|
||||
|
||||
# Fails too hard for test to catch
|
||||
|
|
@ -36,43 +27,43 @@ class UsersXmlApiTest < ActionController::IntegrationTest
|
|||
# end
|
||||
|
||||
def test_fails_with_invalid_xml_format2
|
||||
authenticated_post_xml_to_user_create "<request><username>foo</username></request>"
|
||||
assert_404_invalid_xml
|
||||
authenticated_post_xml_to_user_create "<username>foo</username>"
|
||||
assert_response_and_body 400, "Expected post format is valid xml like so: <user><login>username</login><password>abc123</password></user>."
|
||||
end
|
||||
|
||||
def test_xml_simple_param_parsing
|
||||
authenticated_post_xml_to_user_create
|
||||
assert @controller.params.has_key?(:request)
|
||||
assert @controller.params[:request].has_key?(:login)
|
||||
assert @controller.params[:request].has_key?(:password)
|
||||
assert_equal 'foo', @controller.params[:request][:login]
|
||||
assert_equal 'bar', @controller.params[:request][:password]
|
||||
assert @controller.params.has_key?(:user)
|
||||
assert @controller.params['user'].has_key?(:login)
|
||||
assert @controller.params['user'].has_key?(:password)
|
||||
assert_equal 'foo', @controller.params['user'][:login]
|
||||
assert_equal 'bar', @controller.params['user'][:password]
|
||||
end
|
||||
|
||||
def test_fails_with_too_short_password
|
||||
authenticated_post_xml_to_user_create
|
||||
assert_response_and_body 404, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>\n <error>Password is too short (minimum is 5 characters)</error>\n</errors>\n"
|
||||
assert_responses_with_error "Password is too short (minimum is 5 characters"
|
||||
end
|
||||
|
||||
def test_fails_with_nonunique_login
|
||||
existing_login = users(:other_user).login
|
||||
authenticated_post_xml_to_user_create "<request><login>#{existing_login}</login><password>barracuda</password></request>"
|
||||
assert_response_and_body 404, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>\n <error>Login has already been taken</error>\n</errors>\n"
|
||||
authenticated_post_xml_to_user_create "<user><login>#{existing_login}</login><password>barracuda</password></user>"
|
||||
assert_responses_with_error "Login has already been taken"
|
||||
end
|
||||
|
||||
def test_creates_new_user
|
||||
initial_count = User.count
|
||||
authenticated_post_xml_to_user_create @@johnny_postdata
|
||||
assert_response_and_body 200, "User created."
|
||||
assert_equal initial_count + 1, User.count
|
||||
assert_difference 'User.count' do
|
||||
authenticated_post_xml_to_user_create @@johnny_postdata
|
||||
assert_response_and_body 200, "User created."
|
||||
end
|
||||
johnny1 = User.find_by_login('johnny')
|
||||
assert_not_nil johnny1, "expected user johnny to be created"
|
||||
johnny2 = User.authenticate('johnny','barracuda')
|
||||
assert_not_nil johnny2, "expected user johnny to be created"
|
||||
assert_not_nil johnny2, "expected user johnny to be authenticated"
|
||||
end
|
||||
|
||||
def test_fails_with_get_verb
|
||||
authenticated_get_xml "/users", users(:admin_user).login, 'abracadabra', {}
|
||||
authenticated_get_xml "/users.xml", users(:admin_user).login, 'abracadabra', {}
|
||||
end
|
||||
|
||||
def test_get_users_as_xml
|
||||
|
|
@ -93,15 +84,10 @@ class UsersXmlApiTest < ActionController::IntegrationTest
|
|||
private
|
||||
|
||||
def basic_auth_headers(username = users(:admin_user).login, password = 'abracadabra')
|
||||
{'AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}") }
|
||||
{'HTTP_AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}") }
|
||||
end
|
||||
|
||||
def authenticated_post_xml_to_user_create(postdata = @@foobar_postdata, user = users(:admin_user).login, password = 'abracadabra', headers = {})
|
||||
authenticated_post_xml "/users", user, password, postdata, headers
|
||||
authenticated_post_xml "/users.xml", user, password, postdata, headers
|
||||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 404, "Expected post format is valid xml like so: <request><login>username</login><password>abc123</password></request>."
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue