mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-18 05:08:09 +01:00
also removes deprecated methods. All tests pass (at least on my machine!) and raise no deprecation warnings. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@365 a4c988fc-2ded-0310-b66e-134b36920a42
90 lines
No EOL
2.7 KiB
Ruby
90 lines
No EOL
2.7 KiB
Ruby
ENV["RAILS_ENV"] = "test"
|
|
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
|
require 'test_help'
|
|
|
|
module Tracks
|
|
class Config
|
|
def self.salt
|
|
"change-me"
|
|
end
|
|
end
|
|
end
|
|
|
|
class Test::Unit::TestCase
|
|
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
|
|
self.use_transactional_fixtures = true
|
|
|
|
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
|
|
self.use_instantiated_fixtures = false
|
|
|
|
# Add more helper methods to be used by all tests here...
|
|
# Logs in a user and returns the user object found in the session object
|
|
#
|
|
def login(login,password,expiry)
|
|
post :login, {:user_login => login, :user_password => password, :user_noexpiry => expiry}
|
|
assert_not_nil(session['user_id'])
|
|
return User.find(session['user_id'])
|
|
end
|
|
|
|
# Creates a new users with the login and password given
|
|
def create(login,password)
|
|
post :create, :user => {:login => login, :password => password, :password_confirmation => password}
|
|
return User.find_by_login(login)
|
|
end
|
|
|
|
|
|
# Generates a random string of ascii characters (a-z, "1 0")
|
|
# of a given length for testing assignment to fields
|
|
# for validation purposes
|
|
#
|
|
def generate_random_string(length)
|
|
string = ""
|
|
characters = %w(a b c d e f g h i j k l m n o p q r s t u v w z y z 1\ 0)
|
|
length.times do
|
|
pick = characters[rand(26)]
|
|
string << pick
|
|
end
|
|
return string
|
|
end
|
|
end
|
|
|
|
class ActionController::IntegrationTest
|
|
|
|
def assert_test_environment_ok
|
|
assert_equal "test", ENV['RAILS_ENV']
|
|
assert_equal "change-me", Tracks::Config.salt
|
|
end
|
|
|
|
def authenticated_post_xml(url, username, password, parameters, headers = {})
|
|
post url,
|
|
parameters,
|
|
{'AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}"),
|
|
'ACCEPT' => 'application/xml',
|
|
'CONTENT_TYPE' => 'application/xml'
|
|
}.merge(headers)
|
|
end
|
|
|
|
def authenticated_get_xml(url, username, password, parameters, headers = {})
|
|
get url,
|
|
parameters,
|
|
{'AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}"),
|
|
'ACCEPT' => 'application/xml',
|
|
'CONTENT_TYPE' => 'application/xml'
|
|
}.merge(headers)
|
|
end
|
|
|
|
def assert_response_and_body(type, body, message = nil)
|
|
assert_equal body, @response.body, message
|
|
assert_response type, message
|
|
end
|
|
|
|
def assert_response_and_body_matches(type, body_regex, message = nil)
|
|
assert_response type, message
|
|
assert_match body_regex, @response.body, message
|
|
end
|
|
|
|
def assert_401_unauthorized
|
|
assert_response_and_body 401, "401 Unauthorized: You are not authorized to interact with Tracks."
|
|
end
|
|
|
|
end |