all unit and functional tests are passing

This commit is contained in:
Reinier Balt 2012-04-24 20:47:07 +02:00
parent 96db48dd86
commit 13b58f3a10
40 changed files with 1107 additions and 1494 deletions

View file

@ -1,6 +1,6 @@
Return-Path: <15555555555/TYPE=PLMN@tmomail.net>
Date: Fri, 6 Jun 2008 21:38:26 -0400
From: 15555555555@tmomail.net
From: 5555555555@tmomail.net
To: gtd@tracks.com
Message-ID: <3645873.13759311212802713215.JavaMail.mms@rlyatl28>
Subject: This is the subject

View file

@ -1,30 +1,17 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'feedlist_controller'
# Re-raise errors caught by the controller.
class FeedlistController; def rescue_action(e) raise e end; end
class FeedlistControllerTest < ActionController::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :recurring_todos, :notes
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
@controller = FeedlistController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_get_index_when_not_logged_in
get :index
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_path
end
def test_get_index_by_logged_in_user
login_as :other_user
get :index
assert_response :success
assert_equal "TRACKS::Feeds", assigns['page_title']
assert_equal "TRACKS::Feeds", assigns['page_title']
end
end
end

View file

@ -1,7 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class MessageGatewayTest < ActiveSupport::TestCase
fixtures :users, :contexts, :todos
def setup
@user = users(:sms_user)
@ -14,18 +13,18 @@ class MessageGatewayTest < ActiveSupport::TestCase
def test_sms_with_no_subject
todo_count = Todo.count
load_message('sample_sms.txt')
# assert some stuff about it being created
assert_equal(todo_count+1, Todo.count)
message_todo = Todo.find(:first, :conditions => {:description => "message_content"})
assert_not_nil(message_todo)
assert_equal(@inbox, message_todo.context)
assert_equal(@user, message_todo.user)
end
def test_double_sms
todo_count = Todo.count
load_message('sample_sms.txt')
@ -56,18 +55,18 @@ class MessageGatewayTest < ActiveSupport::TestCase
MessageGateway.receive(badmessage)
assert_equal(todo_count, Todo.count)
end
def test_direct_to_context
message = File.read(File.join(Rails.root, 'test', 'fixtures', 'sample_sms.txt'))
valid_context_msg = message.gsub('message_content', 'this is a task @ anothercontext')
invalid_context_msg = message.gsub('message_content', 'this is also a task @ notacontext')
MessageGateway.receive(valid_context_msg)
valid_context_todo = Todo.find(:first, :conditions => {:description => "this is a task"})
assert_not_nil(valid_context_todo)
assert_equal(contexts(:anothercontext), valid_context_todo.context)
MessageGateway.receive(invalid_context_msg)
invalid_context_todo = Todo.find(:first, :conditions => {:description => 'this is also a task'})
assert_not_nil(invalid_context_todo)

View file

@ -1,9 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class PreferencesControllerTest < ActionController::TestCase
fixtures :users, :preferences
def setup
super
assert_equal "test", Rails.env
assert_equal "change-me", Tracks::Config.salt
end

View file

@ -1,16 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class RecurringTodosControllerTest < ActionController::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings, :recurring_todos
def setup
@controller = RecurringTodosController.new
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
end
def test_get_index_when_not_logged_in
get :index
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_path
end
def test_destroy_recurring_todo

View file

@ -1,21 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'stats_controller'
# Re-raise errors caught by the controller.
class StatsController; def rescue_action(e) raise e end; end
class StatsControllerTest < ActionController::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :recurring_todos, :recurring_todos, :tags, :taggings
def setup
@controller = StatsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_get_index_when_not_logged_in
get :index
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_url
end
def test_get_index

View file

@ -1,21 +0,0 @@
class TodoContainerControllerTestBase < ActionController::TestCase
def setup_controller_request_and_response
# ## override with empty
# TODO: remove these ugly hacks
end
def perform_setup(container_class, controller_class)
@controller = controller_class.new
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
login_as :other_user
@initial_count = container_class.count
@container_class = container_class
end
def test_truth
assert true
end
end

File diff suppressed because it is too large Load diff

View file

@ -1,23 +1,10 @@
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 UsersControllerTest < ActionController::TestCase
fixtures :preferences, :users
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
@controller = UsersController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_get_index_when_not_logged_in
get :index
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_path
end
def test_get_index_by_nonadmin
@ -32,7 +19,7 @@ class UsersControllerTest < ActionController::TestCase
assert_response :success
assert_equal "TRACKS::Manage Users", assigns['page_title']
assert_equal 5, assigns['total_users']
assert_equal "/users", session['return-to']
assert_equal users_url, session['return-to']
end
def test_index_pagination_page_1
@ -59,7 +46,7 @@ class UsersControllerTest < ActionController::TestCase
def test_update_password_successful
get :change_password # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_path
login_as :admin_user
@user = @request.session['user_id']
get :change_password # should now pass because we're logged in
@ -74,21 +61,19 @@ class UsersControllerTest < ActionController::TestCase
def test_update_password_no_confirmation
post :update_password # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_path
login_as :admin_user
post :update_password, :user => {:password => 'newpassword', :password_confirmation => 'wrong'}
assert_redirected_to :controller => 'users', :action => 'change_password'
assert users(:admin_user).save, false
assert_redirected_to change_password_user_path(users(:admin_user))
assert_equal 'Validation failed: Password doesn\'t match confirmation', flash[:error]
end
def test_update_password_validation_errors
post :update_password # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
assert_redirected_to login_path
login_as :admin_user
post :update_password, :user => {:password => 'ba', :password_confirmation => 'ba'}
assert_redirected_to :controller => 'users', :action => 'change_password'
assert users(:admin_user).save, false
assert_redirected_to change_password_user_path(User.find(users(:admin_user).id))
# For some reason, no errors are being raised now.
#assert_equal 1, users(:admin_user).errors.count
#assert_equal users(:admin_user).errors.on(:password), "is too short (min is 5 characters)"

View file

@ -2,7 +2,8 @@ ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
{ :salt => "change-me", :authentication_schemes => ["database", "open_id"], :prefered_auth => "database"}.each{|k,v| SITE_CONFIG[k]=v}
# set config for tests. Overwrite those read from config/site.yml. Use inject to avoid warning about changing CONSTANT
{"salt" => "change-me", "authentication_schemes" => ["database", "open_id", "ldap"], "prefered_auth" => "database"}.inject( SITE_CONFIG ) { |h, elem| h[elem[0]] = elem[1]; h }
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
@ -10,17 +11,35 @@ class ActiveSupport::TestCase
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
def assert_value_changed(object, method = nil)
initial_value = object.send(method)
yield
assert_not_equal initial_value, object.send(method), "#{object}##{method}"
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
def assert_equal_dmy(date1, date2)
assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y")
end
end
class ActionController::TestCase
def login_as(user)
@request.session['user_id'] = user ? users(user).id : nil
end
@ -61,26 +80,4 @@ class ActionController::TestCase
eval("#{get_model_class}.count")
end
end
class ActiveSupport::TestCase
# 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
def assert_equal_dmy(date1, date2)
assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y")
end
end

View file

@ -54,12 +54,6 @@ class ContextTest < ActiveSupport::TestCase
assert_equal @agenda.name, @agenda.title
end
def test_feed_options
opts = Context.feed_options(users(:admin_user))
assert_equal 'Tracks Contexts', opts[:title], 'Unexpected value for :title key of feed_options'
assert_equal 'Lists all the contexts for Admin Schmadmin', opts[:description], 'Unexpected value for :description key of feed_options'
end
def test_hidden_attr_reader
assert !@agenda.hidden?
@agenda.hide = true

View file

@ -128,12 +128,6 @@ class ProjectTest < ActiveSupport::TestCase
assert p.nil?
assert_nil p.id
end
def test_feed_options
opts = Project.feed_options(users(:admin_user))
assert_equal 'Tracks Projects', opts[:title], 'Unexpected value for :title key of feed_options'
assert_equal 'Lists all the projects for Admin Schmadmin', opts[:description], 'Unexpected value for :description key of feed_options'
end
def test_name_removes_extra_spaces
newproj = Project.new

View file

@ -1,5 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'date'
class TodoTest < ActiveSupport::TestCase
fixtures :todos, :recurring_todos, :users, :contexts, :preferences, :tags, :taggings, :projects

View file

@ -1,13 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
module Tracks
class Config
def self.auth_schemes
['database', 'ldap']
end
end
end
class SimpleLdapAuthenticator
cattr_accessor :fake_success
@ -22,7 +14,7 @@ class UserTest < ActiveSupport::TestCase
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
assert_equal ['database', 'ldap'], Tracks::Config.auth_schemes
assert Tracks::Config.auth_schemes.include?('ldap')
@admin_user = User.find(1)
@other_user = User.find(2)
end