mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-11 09:54:21 +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
|
|
@ -424,7 +424,6 @@ class StatsControllerTest < ActionController::TestCase
|
|||
assert_equal 2, assigns['count']
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def given_todos_for_stats
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
put :create, :format => "xml", "request" => {
|
||||
"project_name"=>"Build a working time machine",
|
||||
"todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" }
|
||||
assert_response 422
|
||||
assert_response 409
|
||||
assert_xml_select "errors" do
|
||||
assert_xml_select "error", "Context can't be blank"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,28 +1,15 @@
|
|||
require File.expand_path( File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'projects_controller'
|
||||
require 'contexts_controller'
|
||||
require 'todos_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ProjectsController; def rescue_action(e) raise e end; end
|
||||
class ContextsController; def rescue_action(e) raise e end; end
|
||||
class TodosController; def rescue_action(e) raise e end; end
|
||||
|
||||
class FeedSmokeTest < ActionController::IntegrationTest
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :recurring_todos, :notes
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
def test_last_15_actions_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
||||
|
||||
def test_last_15_actions_atom
|
||||
assert_success "/todos.atom?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
||||
|
||||
def test_last_15_actions_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
|
@ -34,39 +21,39 @@ class FeedSmokeTest < ActionController::IntegrationTest
|
|||
def test_all_actions_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_ical
|
||||
assert_success "/todos.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_in_context_rss
|
||||
assert_success "/contexts/1/todos.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_in_context_txt
|
||||
assert_success "/contexts/1/todos.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_in_context_ical
|
||||
assert_success "/contexts/1/todos.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_in_project_rss
|
||||
assert_success "/projects/1/todos.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_in_project_txt
|
||||
assert_success "/projects/1/todos.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_in_project_ical
|
||||
assert_success "/projects/1/todos.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_actions_due_today_or_earlier_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }&due=0"
|
||||
end
|
||||
|
|
@ -98,27 +85,27 @@ class FeedSmokeTest < ActionController::IntegrationTest
|
|||
def test_all_actions_completed_in_last_7_days_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }&done=7"
|
||||
end
|
||||
|
||||
|
||||
def test_all_contexts_rss
|
||||
assert_success "/contexts.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_contexts_txt
|
||||
assert_success "/contexts.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_projects_rss
|
||||
assert_success "/projects.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_projects_txt
|
||||
assert_success "/projects.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_calendar_ics
|
||||
assert_success "/calendar.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
|
||||
def test_all_projects_txt_with_hidden_project
|
||||
p = projects(:timemachine)
|
||||
p.hide!
|
||||
|
|
|
|||
|
|
@ -1,145 +0,0 @@
|
|||
require File.expand_path( File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'tempfile'
|
||||
|
||||
module Tracks
|
||||
class Config
|
||||
def self.salt
|
||||
"change-me"
|
||||
end
|
||||
def self.auth_schemes
|
||||
['database','ldap']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class LdapAuthTest < ActionController::IntegrationTest
|
||||
|
||||
fixtures :users
|
||||
|
||||
RUN_LDAP_TESTS = ENV['RUN_TRACKS_LDAP_TESTS'] || false
|
||||
SLAPD_BIN = "/usr/libexec/slapd" #You may need to adjust this
|
||||
SLAPD_SCHEMA_DIR = "/etc/openldap/schema/" #You may need to adjust this
|
||||
SLAPD_TEST_PORT = 10389
|
||||
OUTPUT_DEBUG_INFO = false
|
||||
|
||||
begin
|
||||
require 'net/ldap' #requires ruby-net-ldap gem be installed
|
||||
require 'simple_ldap_authenticator'
|
||||
end if RUN_LDAP_TESTS
|
||||
|
||||
SimpleLdapAuthenticator.ldap_library = 'net/ldap'
|
||||
SimpleLdapAuthenticator.servers = %w'localhost'
|
||||
SimpleLdapAuthenticator.use_ssl = false
|
||||
SimpleLdapAuthenticator.login_format = 'cn=%s,dc=lukemelia,dc=com'
|
||||
SimpleLdapAuthenticator.port = 10389
|
||||
SimpleLdapAuthenticator.logger = RAILS_DEFAULT_LOGGER
|
||||
|
||||
def setup
|
||||
assert_equal "test", ENV['RAILS_ENV']
|
||||
assert_equal "change-me", Tracks::Config.salt
|
||||
|
||||
if RUN_LDAP_TESTS
|
||||
setup_ldap_server_conf
|
||||
start_ldap_server
|
||||
end
|
||||
end
|
||||
|
||||
def teardown
|
||||
stop_ldap_server if RUN_LDAP_TESTS
|
||||
end
|
||||
|
||||
def test_authenticate_against_ldap
|
||||
add_ldap_user_to_ldap_repository
|
||||
assert SimpleLdapAuthenticator.valid?('john', 'deere')
|
||||
user = User.authenticate('john', 'deere')
|
||||
assert_not_nil(user)
|
||||
assert_equal user.login, 'john'
|
||||
end
|
||||
|
||||
private :test_authenticate_against_ldap unless RUN_LDAP_TESTS
|
||||
|
||||
def setup_ldap_server_conf
|
||||
@slapd_conf = create_slapd_conf()
|
||||
open(@slapd_conf.path) { |f| f.read }
|
||||
unless File.exist?(SLAPD_BIN)
|
||||
assert false, "slapd could not be found at #{SLAPD_BIN}. Adjust the path in #{__FILE__}"
|
||||
end
|
||||
end
|
||||
|
||||
def start_ldap_server
|
||||
t = Thread.new(@slapd_conf.path) do |slapd_conf_path|
|
||||
puts "starting slapd..." if OUTPUT_DEBUG_INFO
|
||||
run_cmd %Q{/usr/libexec/slapd -f #{slapd_conf_path} -h "ldap://127.0.0.1:10389/" -d0}
|
||||
end
|
||||
sleep(2)
|
||||
run_cmd %Q{ldapsearch -H "ldap://127.0.0.1:10389/" -x -b '' -s base '(objectclass=*)' namingContexts}
|
||||
end
|
||||
|
||||
def add_ldap_user_to_ldap_repository
|
||||
ldif_file = create_ldif()
|
||||
run_cmd %Q{ldapadd -H "ldap://127.0.0.1:10389/" -f #{ldif_file.path} -cxv -D "cn=Manager,dc=lukemelia,dc=com" -w secret}
|
||||
puts `cat #{ldif_file.path}` if OUTPUT_DEBUG_INFO
|
||||
end
|
||||
|
||||
def stop_ldap_server
|
||||
pid = open(get_pid_file_path(@slapd_conf)) { |f| f.read }
|
||||
run_cmd "kill -TERM #{pid}"
|
||||
end
|
||||
|
||||
def create_slapd_conf
|
||||
slapd_conf = Tempfile.new("slapd.conf")
|
||||
slapd_conf.path
|
||||
data_dir = slapd_conf.path + '-data'
|
||||
pid_file = get_pid_file_path(slapd_conf)
|
||||
Dir.mkdir(data_dir)
|
||||
encrypted_password = `slappasswd -s secret`
|
||||
open(slapd_conf.path, 'w') do |f|
|
||||
f.puts %Q{include #{SLAPD_SCHEMA_DIR}core.schema
|
||||
pidfile #{pid_file}
|
||||
database ldbm
|
||||
suffix "dc=lukemelia,dc=com"
|
||||
rootdn "cn=Manager,dc=lukemelia,dc=com"
|
||||
rootpw #{encrypted_password}
|
||||
directory #{data_dir}
|
||||
|
||||
access to *
|
||||
by self write
|
||||
by users read
|
||||
by anonymous auth
|
||||
}
|
||||
end
|
||||
puts `cat #{slapd_conf.path}` if OUTPUT_DEBUG_INFO
|
||||
slapd_conf
|
||||
end
|
||||
|
||||
def create_ldif
|
||||
ldif_file = Tempfile.new("ldap_user.ldif")
|
||||
encrypted_password = `slappasswd -s deere`
|
||||
open(ldif_file.path, 'w') do |f|
|
||||
f.puts %Q{dn: dc=lukemelia,dc=com
|
||||
objectclass: dcObject
|
||||
objectclass: organization
|
||||
o: Luke Melia DotCom
|
||||
dc: lukemelia
|
||||
|
||||
dn: cn=john,dc=lukemelia,dc=com
|
||||
cn: john
|
||||
sn: john
|
||||
objectclass: person
|
||||
userPassword: #{encrypted_password}
|
||||
}
|
||||
end
|
||||
ldif_file
|
||||
end
|
||||
|
||||
def run_cmd(cmd)
|
||||
puts cmd if OUTPUT_DEBUG_INFO
|
||||
cmd_out = `#{cmd}`
|
||||
puts cmd_out if OUTPUT_DEBUG_INFO
|
||||
end
|
||||
|
||||
def get_pid_file_path(tempfile)
|
||||
tempfile.path + '.pid'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,21 +1,11 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'projects_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ProjectsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ProjectXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users, :projects
|
||||
|
||||
@@project_name = "My New Project"
|
||||
@@valid_postdata = "<request><project><name>#{@@project_name}</name></project></request>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
@@valid_postdata = "<project><name>#{@@project_name}</name></project>"
|
||||
|
||||
def test_retrieve_project
|
||||
authenticated_get_xml "/projects/1", users(:admin_user).login, 'abracadabra', {}
|
||||
authenticated_get_xml "/projects/1.xml", users(:admin_user).login, 'abracadabra', {}
|
||||
assert_tag :tag => "project"
|
||||
assert_tag :tag => "project", :child => {:tag => "not_done" }
|
||||
assert_tag :tag => "project", :child => {:tag => "deferred" }
|
||||
|
|
@ -32,30 +22,29 @@ class ProjectXmlApiTest < ActionController::IntegrationTest
|
|||
|
||||
def test_fails_with_invalid_xml_format2
|
||||
authenticated_post_xml_to_project_create "<request><project></project></request>"
|
||||
assert_404_invalid_xml
|
||||
assert_responses_with_error 'Name project must have a name'
|
||||
end
|
||||
|
||||
def test_xml_simple_param_parsing
|
||||
authenticated_post_xml_to_project_create
|
||||
assert @controller.params.has_key?(:request)
|
||||
assert @controller.params[:request].has_key?(:project)
|
||||
assert @controller.params[:request][:project].has_key?(:name)
|
||||
assert_equal @@project_name, @controller.params[:request][:project][:name]
|
||||
assert @controller.params.has_key?(:project)
|
||||
assert @controller.params[:project].has_key?(:name)
|
||||
assert_equal @@project_name, @controller.params[:project][:name]
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_project_create @@valid_postdata, 'nobody', 'nohow'
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_fails_with_too_long_name
|
||||
invalid_with_long_name_postdata = "<request><project><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></project></request>"
|
||||
invalid_with_long_name_postdata = "<project><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></project>"
|
||||
authenticated_post_xml_to_project_create invalid_with_long_name_postdata
|
||||
assert_response_and_body 404, "Name project name must be less than 256 characters"
|
||||
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_project_create "<request><project><name>foo,bar</name></project></request>"
|
||||
authenticated_post_xml_to_project_create "<project><name>foo,bar</name></project>"
|
||||
assert_response :created
|
||||
project1 = Project.find_by_name("foo,bar")
|
||||
assert_not_nil project1, "expected project 'foo,bar' to be created"
|
||||
|
|
@ -73,11 +62,11 @@ class ProjectXmlApiTest < ActionController::IntegrationTest
|
|||
private
|
||||
|
||||
def authenticated_post_xml_to_project_create(postdata = @@valid_postdata, user = users(:other_user).login, password = 'sesame')
|
||||
authenticated_post_xml "/projects", user, password, postdata
|
||||
authenticated_post_xml "/projects.xml", user, password, postdata
|
||||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 404, "Expected post format is valid xml like so: <request><project><name>project name</name></project></request>."
|
||||
assert_response_and_body 404, "Expected post format is valid xml like so: <project><name>project name</name></project>."
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'todos_controller'
|
||||
require 'recurring_todos_controller'
|
||||
|
||||
class RecurringTodosTest < ActionController::IntegrationTest
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings, :recurring_todos
|
||||
|
||||
def logs_in_as(user,plain_pass)
|
||||
@user = user
|
||||
|
|
@ -16,22 +13,21 @@ class RecurringTodosTest < ActionController::IntegrationTest
|
|||
assert_template "todos/index"
|
||||
end
|
||||
|
||||
|
||||
def test_deleting_recurring_todo_clears_reference_from_related_todos
|
||||
logs_in_as(users(:admin_user), 'abracadabra')
|
||||
|
||||
rt = RecurringTodo.find(1)
|
||||
assert !rt.nil? # given there is a recurring todo
|
||||
assert rt.todos.size, 1 # and it has one todos referencing it
|
||||
assert_equal 1, rt.todos.size # and it has one todo referencing it
|
||||
|
||||
# when I toggle the todo complete
|
||||
todo = Todo.find_by_recurring_todo_id(1)
|
||||
post "/todos/toggle_check/#{todo.id}", :_source_view => 'todo'
|
||||
put "/todos/#{todo.id}/toggle_check", :_source_view => 'todo'
|
||||
todo.reload
|
||||
assert todo.completed?
|
||||
|
||||
rt.reload # then there should be two todos referencing
|
||||
assert rt.todos.size, 2
|
||||
assert_equal 2, rt.todos.size
|
||||
todo2 = Todo.find(:first, :conditions => {:recurring_todo_id => rt.id, :state => 'active'})
|
||||
assert_not_equal todo2.id, todo.id # and the todos should be different
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class StoriesTest < ActionController::IntegrationTest
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :recurring_todos, :notes
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
# ####################################################
|
||||
# Testing login and signup by different kinds of users
|
||||
|
|
@ -13,7 +8,7 @@ class StoriesTest < ActionController::IntegrationTest
|
|||
def test_signup_new_user_by_admin
|
||||
admin = new_session_as(:admin_user,"abracadabra")
|
||||
admin.goes_to_signup
|
||||
admin.signs_up_with(:user => {:login => "newbie",
|
||||
admin.signs_up_with(:user => {:login => "newbie",
|
||||
:password => "newbiepass",
|
||||
:password_confirmation => "newbiepass"})
|
||||
end
|
||||
|
|
@ -31,8 +26,8 @@ class StoriesTest < ActionController::IntegrationTest
|
|||
|
||||
def logs_in_as(user,plain_pass)
|
||||
@user = user
|
||||
post "/login", :user_login => @user.login,
|
||||
:user_password => plain_pass,
|
||||
post "/login", :user_login => @user.login,
|
||||
:user_password => plain_pass,
|
||||
:user_noexpiry => 'n'
|
||||
assert_response :redirect
|
||||
follow_redirect!
|
||||
|
|
|
|||
|
|
@ -1,19 +1,15 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'todos_controller'
|
||||
|
||||
class TodoXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users, :contexts, :preferences, :todos, :projects
|
||||
|
||||
@@valid_postdata = "<todo><description>this will succeed</description><context_id type='integer'>10</context_id><project_id type='integer'>4</project_id></todo>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
@user = users(:admin_user)
|
||||
@password = 'abracadabra'
|
||||
end
|
||||
|
||||
def test_get_tickler_succeeds
|
||||
authenticated_get_xml "/tickler", @user.login, @password, {}
|
||||
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
|
|
@ -21,18 +17,18 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
get '/tickler.xml', {}, {}
|
||||
assert_response 401
|
||||
|
||||
get "/tickler", {}, {'AUTHORIZATION' => "Basic " + Base64.encode64("wrong:wrong"),'ACCEPT' => 'application/xml'}
|
||||
get "/tickler.xml", {}, {'HTT_AUTHORIZATION' => "Basic " + Base64.encode64("wrong:wrong"),'ACCEPT' => 'application/xml'}
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_get_tickler_returns_all_deferred_and_pending_todos
|
||||
number = @user.todos.deferred.count + @user.todos.pending.count
|
||||
authenticated_get_xml "/tickler", @user.login, @password, {}
|
||||
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
|
||||
assert_tag :tag => "todos", :children => { :count => number }
|
||||
end
|
||||
|
||||
def test_get_tickler_omits_user_id
|
||||
authenticated_get_xml "/tickler", @user.login, @password, {}
|
||||
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
|
||||
assert_no_tag :tag => "user_id"
|
||||
end
|
||||
|
||||
|
|
@ -225,7 +221,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
assert_not_nil todo
|
||||
assert_not_nil todo.project
|
||||
assert_equal projects(:timemachine).name, todo.project.name
|
||||
assert 1, @user.projects.all(:conditions => ["projects.name = ?", projects(:timemachine).name]).count # no duplication of project
|
||||
assert_equal 1, @user.projects.where("projects.name" => projects(:timemachine).name).count # no duplication of project
|
||||
end
|
||||
|
||||
def test_post_create_todo_with_wrong_project_and_context_id
|
||||
|
|
@ -235,7 +231,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
<context_id type='integer'>-16</context_id>
|
||||
<project_id type='integer'>-11</project_id>
|
||||
</todo>"
|
||||
assert_response 422
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 2
|
||||
end
|
||||
|
|
@ -249,7 +245,7 @@ class TodoXmlApiTest < ActionController::IntegrationTest
|
|||
private
|
||||
|
||||
def authenticated_post_xml_to_todo_create(postdata = @@valid_postdata, user = @user.login, password = @password)
|
||||
authenticated_post_xml "/todos", user, password, postdata
|
||||
authenticated_post_xml "/todos.xml", user, password, postdata
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -36,6 +36,14 @@ class ActiveSupport::TestCase
|
|||
assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y")
|
||||
end
|
||||
|
||||
def xml_document
|
||||
@xml_document ||= HTML::Document.new(@response.body, false, true)
|
||||
end
|
||||
|
||||
def assert_xml_select(*args, &block)
|
||||
@html_document = xml_document
|
||||
assert_select(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
class ActionController::TestCase
|
||||
|
|
@ -68,10 +76,6 @@ class ActionController::TestCase
|
|||
|
||||
private
|
||||
|
||||
def xml_document
|
||||
@xml_document ||= HTML::Document.new(@response.body, false, true)
|
||||
end
|
||||
|
||||
def get_model_class
|
||||
@controller.class.to_s.tableize.split("_")[0].camelcase.singularize #don't ask... converts ContextsController to Context
|
||||
end
|
||||
|
|
@ -80,4 +84,49 @@ class ActionController::TestCase
|
|||
eval("#{get_model_class}.count")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ActionController::IntegrationTest
|
||||
|
||||
def authenticated_post_xml(url, username, password, parameters, headers = {})
|
||||
post url, parameters,
|
||||
{ 'HTTP_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,
|
||||
{ 'HTTP_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
|
||||
|
||||
def assert_401_unauthorized_admin
|
||||
assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function."
|
||||
end
|
||||
|
||||
def assert_responses_with_error(error_msg)
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, error_msg
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -120,12 +120,6 @@ class TodoTest < ActiveSupport::TestCase
|
|||
assert_equal :deferred, todo.aasm_current_state
|
||||
end
|
||||
|
||||
def test_feed_options
|
||||
opts = Todo.feed_options(users(:admin_user))
|
||||
assert_equal 'Tracks Actions', opts[:title], 'Unexpected value for :title key of feed_options'
|
||||
assert_equal 'Actions for Admin Schmadmin', opts[:description], 'Unexpected value for :description key of feed_options'
|
||||
end
|
||||
|
||||
def test_toggle_completion
|
||||
t = @not_completed1
|
||||
assert_equal :active, t.aasm_current_state
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue