Removed superfluous 'tracks' directory at the root of the repository.

Testing commits to github.
This commit is contained in:
bsag 2008-05-20 21:28:26 +01:00
parent 6a42901514
commit 4cbf5a34d3
2269 changed files with 0 additions and 0 deletions

115
test/fixtures/contexts.yml vendored Normal file
View file

@ -0,0 +1,115 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
Time.now.utc.to_s(:db)
end
%>
agenda:
id: 1
name: agenda
position: 1
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
call:
id: 2
name: call
position: 2
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
email:
id: 3
name: email
position: 3
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
errand:
id: 4
name: errand
position: 4
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
lab:
id: 5
name: lab
position: 5
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
library:
id: 6
name: library
position: 6
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
freetime:
id: 7
name: freetime
position: 7
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
office:
id: 8
name: office
position: 8
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
waitingfor:
id: 9
name: waiting for
position: 9
hide: false
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
office_otheruser:
id: 10
name: office
position: 1
hide: false
user_id: 2
created_at: <%= today %>
updated_at: <%= today %>
waitingfor_otheruser:
id: 11
name: waiting for
position: 2
hide: false
user_id: 2
created_at: <%= today %>
updated_at: <%= today %>
someday_maybe:
id: 12
name: someday maybe
position: 10
hide: true
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>

29
test/fixtures/notes.yml vendored Normal file
View file

@ -0,0 +1,29 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
Time.now.utc.to_s(:db)
end
def next_week
1.week.from_now.utc.to_s(:db)
end
def last_week
1.week.ago.utc.to_s(:db)
end
%>
first_notes:
id: 1
user_id: 1
project_id: 1
body: Need to collect a catalogue from Time Machines R Us
created_at: <%= today %>
updated_at: <%= today %>
another_notes:
id: 2
user_id: 1
project_id: 1
body: Should I go for a swirly effect or a whooshy one?
created_at: <%= today %>
updated_at: <%= today %>

36
test/fixtures/preferences.yml vendored Normal file
View file

@ -0,0 +1,36 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
admin_user_prefs:
id: 1
user_id: 1
staleness_starts: 7
date_format: "%d/%m/%Y"
title_date_format: "%A, %d %B %Y"
show_number_completed: 5
show_completed_projects_in_sidebar: true
show_hidden_contexts_in_sidebar: true
show_hidden_projects_in_sidebar: true
admin_email: butshesagirl@rousette.org.uk
week_starts: 1
due_style: 0
refresh: 0
time_zone: "London"
verbose_action_descriptors: true
show_project_on_todo_done: false
other_user_prefs:
id: 2
user_id: 2
staleness_starts: 7
date_format: "%d/%m/%Y"
title_date_format: "%A, %d %B %Y"
show_number_completed: 5
show_completed_projects_in_sidebar: true
show_hidden_contexts_in_sidebar: true
show_hidden_projects_in_sidebar: true
admin_email: butshesagirl@rousette.org.uk
week_starts: 1
due_style: 0
refresh: 0
time_zone: "London"
verbose_action_descriptors: false
show_project_on_todo_done: true

47
test/fixtures/projects.yml vendored Normal file
View file

@ -0,0 +1,47 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
Time.now.utc.beginning_of_day.to_s(:db)
end
%>
timemachine:
id: 1
name: Build a working time machine
description: ''
position: 1
state: 'active'
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
default_context_id: 5
moremoney:
id: 2
name: Make more money than Billy Gates
description: ''
position: 2
state: 'active'
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
gardenclean:
id: 3
name: Evict dinosaurs from the garden
description: ''
position: 3
state: 'active'
user_id: 1
created_at: <%= today %>
updated_at: <%= today %>
attendrailsconf:
id: 4
name: Attend RailsConf
description: ''
position: 1
state: 'active'
user_id: 2
created_at: <%= today %>
updated_at: <%= today %>

29
test/fixtures/taggings.yml vendored Normal file
View file

@ -0,0 +1,29 @@
# Todo 1 should be tagged with foo and bar
foo_bar1:
id: 1
tag_id: 1
taggable_id: 1 # Call Bill Gates
taggable_type: Todo
user_id: 1
foo_bar2:
id: 2
tag_id: 2
taggable_id: 1 # Call Bill Gates
taggable_type: Todo
user_id: 1
# Todo 2 should be tagged with foo
foo1:
id: 3
tag_id: 1
taggable_id: 2 # Call dinosaur exterminator
taggable_type: Todo
user_id: 1
foo2:
id: 4
tag_id: 1
taggable_id: 3 # Buy milk - completed
taggable_type: Todo
user_id: 1

17
test/fixtures/tags.yml vendored Normal file
View file

@ -0,0 +1,17 @@
foo:
id: 1
name: foo
created_at: <%= Time.now.utc.to_s(:db) %>
updated_at: <%= Time.now.utc.to_s(:db) %>
bar:
id: 2
name: bar
created_at: <%= Time.now.utc.to_s(:db) %>
updated_at: <%= Time.now.utc.to_s(:db) %>
baz:
id: 3
name: baz
created_at: <%= Time.now.utc.to_s(:db) %>
updated_at: <%= Time.now.utc.to_s(:db) %>

232
test/fixtures/todos.yml vendored Normal file
View file

@ -0,0 +1,232 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
Time.now.utc.beginning_of_day.to_s(:db)
end
def next_week
1.week.from_now.beginning_of_day.utc.to_s(:db)
end
def last_week
1.week.ago.utc.beginning_of_day.to_s(:db)
end
def two_weeks_ago
2.weeks.ago.utc.beginning_of_day.to_s(:db)
end
def two_weeks_hence
2.weeks.from_now.utc.beginning_of_day.to_s(:db)
end
%>
1:
id: 1
context_id: 1
project_id: 2
description: Call Bill Gates to find out how much he makes per day
notes: ~
state: active
created_at: <%= last_week %>
due: <%= two_weeks_hence %>
completed_at: ~
user_id: 1
2:
id: 2
context_id: 2
project_id: 3
description: Call dinosaur exterminator
notes: Ask him if I need to hire a skip for the corpses.
state: active
created_at: <%= today %>
due: <%= two_weeks_hence %>
completed_at: ~
user_id: 1
3:
id: 3
context_id: 4
project_id: ~
description: Buy milk
notes: ~
state: completed
created_at: <%= today %>
due: ~
completed_at: <%= today %>
user_id: 1
4:
id: 4
context_id: 4
project_id: ~
description: Buy bread
notes: ~
state: completed
created_at: <%= today %>
due: ~
completed_at: <%= today %>
user_id: 1
5:
id: 5
context_id: 5
project_id: 1
description: Construct time dilation device
notes: ~
state: active
created_at: <%= today %>
due: ~
completed_at: ~
user_id: 1
6:
id: 6
context_id: 2
project_id: 1
description: Phone Grandfather to ask about the paradox
notes: Added some _notes_.
state: active
created_at: <%= today %>
due: <%= last_week %>
completed_at: ~
user_id: 1
7:
id: 7
context_id: 6
project_id: 3
description: Get a book out of the library
notes: 'Dinosaurs''R'
state: active
created_at: <%= today %>
due: ~
completed_at: ~
user_id: 1
8:
id: 8
context_id: 4
project_id: ~
description: Upgrade to Rails 0.9.1
notes: ~
state: completed
created_at: <%= today %>
due: <%= today %>
completed_at: <%= today %>
user_id: 1
9:
id: 9
context_id: 1
project_id: ~
description: This should be due today
notes: ~
state: active
created_at: <%= today %>
due: <%= today %>
completed_at: ~
user_id: 1
10:
id: 10
context_id: 1
project_id: ~
description: foo
notes: ~
state: completed
created_at: <%= two_weeks_ago %>
due: <%= two_weeks_hence %>
completed_at: <%= last_week %>
user_id: 1
11:
id: 11
context_id: 1
project_id: 2
description: Buy shares
notes: ~
state: active
created_at: <%= today %>
due: <%= next_week %>
completed_at: ~
user_id: 1
12:
id: 12
context_id: 1
project_id: 3
description: Buy stegosaurus bait
notes: ~
state: active
created_at: <%= today %>
due: <%= next_week %>
completed_at: ~
user_id: 1
13:
id: 13
context_id: 1
project_id: 3
description: New action in context
notes: Some notes
state: active
created_at: <%= today %>
due: <%= next_week %>
completed_at: ~
user_id: 1
14:
id: 14
context_id: 2
project_id: 2
description: Call stock broker
notes: 'tel: 12345'
state: active
created_at: <%= last_week %>
due: ~
completed_at: ~
user_id: 1
15:
id: 15
context_id: 6
project_id: 1
description: Select Delorean model
notes: ~
state: deferred
created_at: <%= today %>
due: ~
completed_at: ~
show_from: <%= next_week %>
user_id: 1
16:
id: 16
context_id: 10
project_id: 4
description: Buy tix
notes: ~
state: active
created_at: <%= today %>
due: ~
completed_at: ~
show_from: <%= next_week %>
user_id: 2
17:
id: 17
context_id: 11
project_id: 4
description: Confirmation from pal
notes: ~
state: active
created_at: <%= today %>
due: ~
completed_at: ~
show_from: <%= next_week %>
user_id: 2

30
test/fixtures/users.yml vendored Normal file
View file

@ -0,0 +1,30 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
admin_user:
id: 1
login: admin
crypted_password: <%= Digest::SHA1.hexdigest("#{Tracks::Config.salt}--abracadabra--") %>
token: <%= Digest::SHA1.hexdigest("adminSat Feb 25 17:14:00 GMT 20060.236961325863376") %>
is_admin: true
first_name: Admin
last_name: Schmadmin
auth_type: database
other_user:
id: 2
login: jane
crypted_password: <%= Digest::SHA1.hexdigest("#{Tracks::Config.salt}--sesame--") %>
token: <%= Digest::SHA1.hexdigest("janeSun Feb 19 14:42:45 GMT 20060.408173979260027") %>
is_admin: false
first_name: Jane
last_name: Doe
auth_type: database
ldap_user:
id: 3
login: john
crypted_password: test
token: <%= Digest::SHA1.hexdigest("johnSun Feb 19 14:42:45 GMT 20060.408173979260027") %>
is_admin: false
first_name: John
last_name: Deere
auth_type: ldap

View file

@ -0,0 +1,81 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'backend_controller'
# Re-raise errors caught by the controller.
class BackendController; def rescue_action(e) raise e end; end
class BackendControllerTest < Test::Rails::TestCase
fixtures :users, :projects, :contexts, :todos, :notes
def setup
@controller = BackendController.new
request, response = ActionController::TestRequest.new, ActionController::TestResponse.new
assert_equal "change-me", Tracks::Config.salt
end
def test_new_todo_fails_with_incorrect_token
assert_raises_invalid_token { @controller.new_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test', 'test') }
end
def test_new_todo_fails_with_context_that_does_not_belong_to_user
assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_todo(users('other_user').login, users('other_user').token, contexts('agenda').id, 'test', 'test') }
end
def test_new_rich_todo_fails_with_incorrect_token
assert_raises_invalid_token { @controller.new_rich_todo('admin', 'notthecorrecttoken', contexts('agenda').id, 'test', 'test') }
end
#"Call mfox @call > Build a working time machine" should create the "Call mfox" todo in the 'call' context and the 'Build a working time machine' project.
def test_new_rich_todo_creates_todo_with_exact_match
assert_new_rich_todo_creates_mfox_todo("Call mfox @call > Build a working time machine")
end
#"Call mfox @cal > Build" should create the "Call mfox" todo in the 'call' context and the 'Build a working time machine' project.
def test_new_rich_todo_creates_todo_with_starts_with_match
assert_new_rich_todo_creates_mfox_todo("Call mfox @cal > Build")
end
#"Call mfox @call > new:Run for president" should create the 'Run for president' project, create the "Call mfox" todo in the 'call' context and the new project.
def test_new_rich_todo_creates_todo_with_new_project
max_todo_id = Todo.maximum('id')
max_project_id = Project.maximum('id')
@controller.new_rich_todo(users(:admin_user).login, users(:admin_user).token, contexts(:agenda).id, 'Call mfox @call > new:Run for president', 'test')
todo = Todo.find(:first, :conditions => ["id > ?", max_todo_id])
new_project = Project.find(:first, :conditions => ["id > ?", max_project_id])
assert_equal(users(:admin_user).id, todo.user_id)
assert_equal(contexts(:call).id, todo.context_id)
assert_equal(new_project.id, todo.project_id)
assert_equal("Call mfox", todo.description)
assert_equal("test", todo.notes)
end
def assert_new_rich_todo_creates_mfox_todo(description_input)
max_id = Todo.maximum('id')
@controller.new_rich_todo(users(:admin_user).login, users(:admin_user).token, contexts(:agenda).id, 'Call mfox @cal > Build', 'test')
todo = Todo.find(:first, :conditions => ["id > ?", max_id])
assert_equal(users(:admin_user).id, todo.user_id)
assert_equal(contexts(:call).id, todo.context_id)
assert_equal(projects(:timemachine).id, todo.project_id)
assert_equal('test', todo.notes)
assert_equal("Call mfox", todo.description)
end
def test_new_rich_todo_fails_with_context_that_does_not_belong_to_user
assert_raise(CannotAccessContext, "Cannot access a context that does not belong to this user.") { @controller.new_rich_todo(users('other_user').login, users('other_user').token, contexts('agenda').id, 'test', 'test') }
end
def test_list_projects_fails_with_incorrect_token
assert_raises_invalid_token { @controller.list_projects('admin', 'notthecorrecttoken') }
end
def test_list_contexts_fails_with_incorrect_token
assert_raises_invalid_token { @controller.list_contexts('admin', 'notthecorrecttoken') }
end
private
def assert_raises_invalid_token
assert_raise(InvalidToken, "Sorry, you don't have permission to perform this action.") { yield }
end
end

View file

@ -0,0 +1,189 @@
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/todo_container_controller_test_base'
require 'contexts_controller'
# Re-raise errors caught by the controller.
class ContextsController; def rescue_action(e) raise e end; end
class ContextsControllerTest < TodoContainerControllerTestBase
fixtures :users, :preferences, :contexts
def setup
perform_setup(Context, ContextsController)
end
def test_contexts_list
login_as :admin_user
get :index
end
def test_create_context_via_ajax_increments_number_of_context
assert_ajax_create_increments_count '@newcontext'
end
def test_create_context_with_ajax_success_rjs
ajax_create '@newcontext'
assert_rjs :insert_html, :bottom, "list-contexts"
assert_rjs :sortable, 'list-contexts', { :tag => 'div', :handle => 'handle', :complete => visual_effect(:highlight, 'list-contexts'), :url => order_contexts_path }
# not yet sure how to write the following properly...
assert_rjs :call, "Form.reset", "context-form"
assert_rjs :call, "Form.focusFirstElement", "context-form"
end
def test_create_via_ajax_with_comma_in_name_does_not_increment_number_of_contexts
assert_ajax_create_does_not_increment_count 'foo,bar'
end
def test_create_with_comma_in_name_fails_with_rjs
ajax_create 'foo,bar'
assert_rjs :show, 'status'
# Not working with Rails 2.0 upgrade
# assert_rjs :update, 'status', "<div class=\"ErrorExplanation\" id=\"ErrorExplanation\"><h2>1 error prohibited this record from being saved</h2><p>There were problems with the following fields:</p><ul>Name cannot contain the comma (',') character</ul></div>"
end
def test_rss_feed_content
login_as :admin_user
get :index, { :format => "rss" }
assert_equal 'application/rss+xml', @response.content_type
#puts @response.body
assert_xml_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Contexts'
assert_select '>description', "Lists all the contexts for #{users(:admin_user).display_name}"
assert_select 'language', 'en-us'
assert_select 'ttl', '40'
end
assert_select 'item', 10 do
assert_select 'title', /.+/
assert_select 'description' do
assert_select_encoded do
assert_select 'p', /\d+&nbsp;actions. Context is (Active|Hidden)./
end
end
%w(guid link).each do |node|
assert_select node, /http:\/\/test.host\/contexts\/.+/
end
assert_select 'pubDate', contexts(:agenda).created_at.to_s(:rfc822)
end
end
end
def test_rss_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "rss" }
assert_response 401
end
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "rss", :token => 'foo' }
assert_response 401
end
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "rss", :token => users(:admin_user).token }
assert_response :ok
end
def test_atom_feed_content
login_as :admin_user
get :index, { :format => "atom" }
assert_equal 'application/atom+xml', @response.content_type
#puts @response.body
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select '>title', 'Tracks Contexts'
assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}"
assert_select 'entry', 10 do
assert_select 'title', /.+/
assert_select 'content[type="html"]' do
assert_select_encoded do
assert_select 'p', /\d+&nbsp;actions. Context is (Active|Hidden)./
end
end
assert_select 'published', /(#{contexts(:agenda).created_at.xmlschema}|#{contexts(:library).created_at.xmlschema})/
end
end
end
def test_atom_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "atom" }
assert_response 401
end
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "atom", :token => 'foo' }
assert_response 401
end
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "atom", :token => users(:admin_user).token }
assert_response :ok
end
def test_text_feed_content
login_as :admin_user
get :index, { :format => "txt" }
assert_equal 'text/plain', @response.content_type
assert !(/&nbsp;/.match(@response.body))
end
def test_text_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "txt" }
assert_response 401
end
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "txt", :token => 'foo' }
assert_response 401
end
def test_text_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "txt", :token => users(:admin_user).token }
assert_response :ok
end
def test_show_sets_title
login_as :admin_user
get :show, { :id => "1" }
assert_equal 'TRACKS::Context: agenda', assigns['page_title']
end
def test_show_renders_show_template
login_as :admin_user
get :show, { :id => "1" }
assert_template "contexts/show"
end
def test_show_xml_renders_context_to_xml
login_as :admin_user
get :show, { :id => "1", :format => 'xml' }
assert_equal contexts(:agenda).to_xml( :except => :user_id ), @response.body
end
def test_show_with_nil_context_returns_404
login_as :admin_user
get :show, { :id => "0" }
assert_equal 'Context not found', @response.body
assert_response 404
end
def test_show_xml_with_nil_context_returns_404
login_as :admin_user
get :show, { :id => "0", :format => 'xml' }
assert_response 404
assert_xml_select 'error', 'Context not found'
end
def protect_against_forgery?
false
end
end

View file

@ -0,0 +1,21 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'data_controller'
# Re-raise errors caught by the controller.
class DataController; def rescue_action(e) raise e end; end
class DataControllerTest < Test::Rails::TestCase
fixtures :users, :preferences, :projects, :notes
def setup
@controller = DataController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_csv_export_completes_without_error
login_as :admin_user
get :csv_notes
end
end

View file

@ -0,0 +1,30 @@
require 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 < Test::Rails::TestCase
fixtures :users, :preferences, :projects, :contexts, :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'
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']
end
end

View file

@ -0,0 +1,27 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'integrations_controller'
# Re-raise errors caught by the controller.
class IntegrationsController; def rescue_action(e) raise e end; end
class IntegrationsControllerTest < Test::Unit::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings
def setup
@controller = IntegrationsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_truth
assert true
end
def test_page_load
login_as(:admin_user)
get :rest_api
assert_response :success
end
end

View file

@ -0,0 +1,146 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'login_controller'
require_dependency "login_system"
# Re-raise errors caught by the controller.
class LoginController; def rescue_action(e) raise e end; end
class LoginControllerTest < Test::Rails::TestCase
fixtures :preferences, :users
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
@controller = LoginController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
#============================================
#Login and logout
#============================================
def test_invalid_login
post :login, {:user_login => 'cracker', :user_password => 'secret', :user_noexpiry => 'on'}
assert_response :success
assert(!@response.has_session_object?(:user_id))
assert_template "login"
end
def test_login_with_valid_admin_user
@request.session['return-to'] = "/bogus/location"
post :login, {:user_login => 'admin', :user_password => 'abracadabra', :user_noexpiry => 'on'}
user = User.find(session['user_id'])
assert_equal user.id, @response.session['user_id']
assert_equal user.login, "admin"
assert user.is_admin
assert_equal "Login successful: session will not expire.", flash[:notice]
assert_equal("http://#{@request.host}/bogus/location", @response.redirect_url)
end
def test_login_with_valid_standard_user
post :login, {:user_login => 'jane', :user_password => 'sesame', :user_noexpiry => 'off'}
user = User.find(session['user_id'])
assert_equal user.id, @response.session['user_id']
assert_equal user.login, "jane"
assert user.is_admin == false || user.is_admin == 0
assert_equal "Login successful: session will expire after 1 hour of inactivity.", flash[:notice]
assert_redirected_to home_url
end
def test_login_with_no_users_redirects_to_signup
User.delete_all
get :login
assert_redirected_to :controller => 'users', :action => 'new'
end
def test_logout
login_as :admin_user
get :logout
assert_nil(session['user_id'])
assert_redirected_to :controller => 'login', :action => 'login'
end
# Test login with a bad password for existing user
#
def test_login_bad_password
post :login, {:user_login => 'jane', :user_password => 'wrong', :user_noexpiry => 'on'}
assert(!@response.has_session_object?(:user))
assert_equal "Login unsuccessful", flash[:warning]
assert_response :success
end
def test_login_bad_login
post :login, {:user_login => 'blah', :user_password => 'sesame', :user_noexpiry => 'on'}
assert(!@response.has_session_object?(:user))
assert_equal "Login unsuccessful", flash[:warning]
assert_response :success
end
def test_should_remember_me
post :login, :user_login => 'jane', :user_password => 'sesame', :user_noexpiry => "on"
assert_not_nil @response.cookies["auth_token"]
end
def test_should_not_remember_me
post :login, :user_login => 'jane', :user_password => 'sesame', :user_noexpiry => "off"
assert_nil @response.cookies["auth_token"]
end
def test_should_delete_token_on_logout
login_as :other_user
get :logout
assert_equal @response.cookies["auth_token"], []
end
def test_should_login_with_cookie
users(:other_user).remember_me
@request.cookies["auth_token"] = auth_token_cookie_for(:other_user)
get :login
assert @controller.send(:logged_in?)
end
def test_should_fail_expired_cookie_login
users(:other_user).remember_me
users(:other_user).update_attribute :remember_token_expires_at, 5.minutes.ago.utc
@request.cookies["auth_token"] = auth_token_cookie_for(:other_user)
get :login
assert !@controller.send(:logged_in?)
end
def test_should_fail_cookie_login
users(:other_user).remember_me
@request.cookies["auth_token"] = CGI::Cookie.new('name' => 'auth_token', 'value' => 'invalid_auth_token')
get :login
assert !@controller.send(:logged_in?)
end
def test_current_user_nil
get :login
assert_nil @controller.current_user
end
def test_current_user_correct
post :login, {:user_login => 'jane', :user_password => 'sesame', :user_noexpiry => 'off'}
assert_equal users(:other_user), @controller.current_user
end
def test_prefs_nil
login_as nil
get :login
assert_nil @controller.prefs
end
def test_prefs_correct
post :login, {:user_login => 'jane', :user_password => 'sesame', :user_noexpiry => 'off'}
assert_equal users(:other_user).prefs, @controller.prefs
end
private
def auth_token_cookie_for(user)
CGI::Cookie.new('name' => 'auth_token', 'value' => users(user).remember_token)
end
end

View file

@ -0,0 +1,18 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'notes_controller'
# Re-raise errors caught by the controller.
class NotesController; def rescue_action(e) raise e end; end
class NotesControllerTest < Test::Rails::TestCase
def setup
@controller = NotesController.new
request = ActionController::TestRequest.new
response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_truth
assert true
end
end

View file

@ -0,0 +1,50 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'preferences_controller'
require 'preference'
# Re-raise errors caught by the controller.
class PreferencesController; def rescue_action(e) raise e end; end
class PreferencesControllerTest < Test::Rails::TestCase
fixtures :users, :preferences
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
@controller = PreferencesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_preferences
get :index # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
login_as :admin_user
get :index
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Preferences"
assert_not_nil assigns['prefs']
end
def test_edit_preferences
get :edit # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
login_as :admin_user
get :edit
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Edit Preferences"
assert_not_nil assigns['prefs']
assert_template 'preferences/edit'
end
def test_update_preferences
login_as :admin_user
post :update, {:user => { :first_name => 'Jane', :last_name => 'Doe'}, :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }}
updated_admin_user = users(:admin_user).reload
assert_not_nil updated_admin_user.preference
assert_equal 'Jane', updated_admin_user.first_name
assert_equal 'Doe', updated_admin_user.last_name
assert_redirected_to :action => 'index'
end
end

View file

@ -0,0 +1,250 @@
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/todo_container_controller_test_base'
require 'projects_controller'
# Re-raise errors caught by the controller.
class ProjectsController; def rescue_action(e) raise e end; end
class ProjectsControllerTest < TodoContainerControllerTestBase
fixtures :users, :todos, :preferences, :projects, :contexts
def setup
perform_setup(Project, ProjectsController)
end
def test_projects_list
login_as :admin_user
get :index
end
def test_show_exposes_deferred_todos
p = projects(:timemachine)
login_as :admin_user
get :show, :id => p.to_param
assert_not_nil assigns['deferred']
assert_equal 1, assigns['deferred'].size
t = p.not_done_todos[0]
t.show_from = 1.days.from_now.utc.to_date
t.save!
get :show, :id => p.to_param
assert_equal 2, assigns['deferred'].size
end
def test_show_exposes_next_project_in_same_state
login_as :admin_user
get :show, :id => projects(:timemachine).to_param
assert_equal(projects(:moremoney), assigns['next_project'])
end
def test_show_exposes_previous_project_in_same_state
login_as :admin_user
get :show, :id => projects(:moremoney).to_param
assert_equal(projects(:timemachine), assigns['previous_project'])
end
def test_create_project_via_ajax_increments_number_of_projects
assert_ajax_create_increments_count 'My New Project'
end
def test_create_project_with_ajax_success_rjs
ajax_create 'My New Project'
assert_rjs :insert_html, :bottom, "list-active-projects"
assert_rjs :sortable, 'list-active-projects', { :tag => 'div', :handle => 'handle', :complete => visual_effect(:highlight, 'list-active-projects'), :url => order_projects_path }
# not yet sure how to write the following properly...
assert_rjs :call, "Form.reset", "project-form"
assert_rjs :call, "Form.focusFirstElement", "project-form"
end
def test_create_project_and_go_to_project_page
num_projects = Project.count
xhr :post, :create, { :project => {:name => 'Immediate Project Planning Required'}, :go_to_project => 1}
assert_js_redirected_to %r{/?projects/\d+}
assert_equal num_projects + 1, Project.count
end
def test_create_with_comma_in_name_does_not_increment_number_of_projects
assert_ajax_create_does_not_increment_count 'foo,bar'
end
def test_create_with_comma_in_name_fails_with_rjs
ajax_create 'foo,bar'
assert_rjs :show, 'status'
# Not working with Rails 2.0 upgrade
# assert_rjs :update, 'status', "<div class=\"ErrorExplanation\" id=\"ErrorExplanation\"><h2>1 error prohibited this record from being saved</h2><p>There were problems with the following fields:</p><ul>Name cannot contain the comma (',') character</ul></div>"
end
def test_todo_state_is_project_hidden_after_hiding_project
p = projects(:timemachine)
todos = p.todos.find_in_state(:all, :active)
login_as(:admin_user)
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"hidden"}
todos.each do |t|
assert_equal :project_hidden, t.reload().current_state
end
assert p.reload().hidden?
end
def test_not_done_counts_after_hiding_and_unhiding_project
p = projects(:timemachine)
todos = p.todos.find_in_state(:all, :active)
login_as(:admin_user)
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"hidden"}
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"active"}
todos.each do |t|
assert_equal :active, t.reload().current_state
end
assert p.reload().active?
end
def test_rss_feed_content
login_as(:admin_user)
get :index, { :format => "rss" }
assert_equal 'application/rss+xml', @response.content_type
#puts @response.body
assert_xml_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Projects'
assert_select '>description', "Lists all the projects for #{users(:admin_user).display_name}"
assert_select 'language', 'en-us'
assert_select 'ttl', '40'
end
assert_select 'item', 3 do
assert_select 'title', /.+/
assert_select 'description' do
assert_select_encoded do
assert_select 'p', /^\d+&nbsp;actions\. Project is (active|hidden|completed)\.$/
end
end
%w(guid link).each do |node|
assert_select node, /http:\/\/test.host\/projects\/.+/
end
assert_select 'pubDate', projects(:timemachine).updated_at.to_s(:rfc822)
end
end
end
def test_rss_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "rss" }
assert_response 401
end
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "rss", :token => 'foo' }
assert_response 401
end
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "rss", :token => users(:admin_user).token }
assert_response :ok
end
def test_atom_feed_content
login_as :admin_user
get :index, { :format => "atom" }
assert_equal 'application/atom+xml', @response.content_type
#puts @response.body
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select '>title', 'Tracks Projects'
assert_select '>subtitle', "Lists all the projects for #{users(:admin_user).display_name}"
assert_select 'entry', 3 do
assert_select 'title', /.+/
assert_select 'content[type="html"]' do
assert_select_encoded do
assert_select 'p', /\d+&nbsp;actions. Project is (active|hidden|completed)./
end
end
assert_select 'published', /(#{projects(:timemachine).updated_at.xmlschema}|#{projects(:moremoney).updated_at.xmlschema})/
end
end
end
def test_atom_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "atom" }
assert_response 401
end
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "atom", :token => 'foo' }
assert_response 401
end
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "atom", :token => users(:admin_user).token }
assert_response :ok
end
def test_text_feed_content
login_as :admin_user
get :index, { :format => "txt" }
assert_equal 'text/plain', @response.content_type
assert !(/&nbsp;/.match(@response.body))
#puts @response.body
end
def test_text_feed_content_for_projects_with_no_actions
login_as :admin_user
p = projects(:timemachine)
p.todos.each { |t| t.destroy }
get :index, { :format => "txt", :only_active_with_no_next_actions => true }
assert (/^\s*BUILD A WORKING TIME MACHINE\s+0 actions. Project is active.\s*$/.match(@response.body))
assert !(/[1-9] actions/.match(@response.body))
end
def test_text_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "txt" }
assert_response 401
end
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "txt", :token => 'foo' }
assert_response 401
end
def test_text_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "txt", :token => users(:admin_user).token }
assert_response :ok
end
def test_alphabetize_sorts_active_projects_alphabetically
login_as :admin_user
u = users(:admin_user)
post :alphabetize, :state => "active", :format => 'js'
assert_equal 1, projects(:timemachine).position
assert_equal 2, projects(:gardenclean).position
assert_equal 3, projects(:moremoney).position
end
def test_alphabetize_assigns_state
login_as :admin_user
post :alphabetize, :state => "active", :format => 'js'
assert_equal "active", assigns['state']
end
def test_alphabetize_assigns_projects
login_as :admin_user
post :alphabetize, :state => "active", :format => 'js'
exposed_projects = assigns['projects']
assert_equal 3, exposed_projects.length
assert_equal projects(:timemachine), exposed_projects[0]
assert_equal projects(:gardenclean), exposed_projects[1]
assert_equal projects(:moremoney), exposed_projects[2]
end
def protect_against_forgery?
false
end
end

View file

@ -0,0 +1,94 @@
require 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 < Test::Unit::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings
def setup
@controller = StatsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_truth
assert true
end
def test_get_index_when_not_logged_in
get :index
assert_redirected_to :controller => 'login', :action => 'login'
end
def test_get_index
login_as(:admin_user)
get :index
assert_response :success
end
def test_get_charts
login_as(:admin_user)
%w{ actions_done_last30days_data
actions_done_last12months_data
actions_completion_time_data
actions_visible_running_time_data
actions_running_time_data
actions_day_of_week_all_data
actions_day_of_week_30days_data
actions_time_of_day_all_data
actions_time_of_day_30days_data
context_total_actions_data
context_running_actions_data
}.each do |action|
get action
assert_response :success
assert_template "stats/"+action
end
end
def test_totals
login_as(:admin_user)
get :index
assert_response :success
assert_equal 3, assigns['projects'].count
assert_equal 3, assigns['projects'].count(:conditions => "state = 'active'")
assert_equal 10, assigns['contexts'].count
assert_equal 15, assigns['actions'].count
assert_equal 4, assigns['tags'].count
assert_equal 2, assigns['unique_tags'].size
assert_equal 2.week.ago.utc.beginning_of_day, assigns['first_action'].created_at
end
def test_downdrill
login_as(:admin_user)
# drill down without parameters
get :show_selected_actions_from_chart
assert_response :not_found
assert_template nil
# get week 0-1 for actions visible running
get :show_selected_actions_from_chart, :id => 'avrt', :index => 0
assert_response :success
assert_template "stats/show_selection_from_chart"
# get week 0 and further for actions visible running
get :show_selected_actions_from_chart, :id => 'avrt_end', :index => 0
assert_response :success
assert_template "stats/show_selection_from_chart"
# get week 0-1 for actions running
get :show_selected_actions_from_chart, :id => 'art', :index => 0
assert_response :success
assert_template "stats/show_selection_from_chart"
# get week 0 and further for actions running
get :show_selected_actions_from_chart, :id => 'art_end', :index => 0
assert_response :success
assert_template "stats/show_selection_from_chart"
end
end

View file

@ -0,0 +1,32 @@
class TodoContainerControllerTestBase < Test::Rails::TestCase
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
def assert_ajax_create_increments_count(name)
assert_count_after_ajax_create(name, @initial_count + 1)
end
def assert_ajax_create_does_not_increment_count(name)
assert_count_after_ajax_create(name, @initial_count)
end
def assert_count_after_ajax_create(name, expected_count)
ajax_create(name)
assert_equal(expected_count, @container_class.count)
end
def ajax_create(name)
xhr :post, :create, @container_class.name.downcase.to_sym => {:name => name}
end
end

View file

@ -0,0 +1,360 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'todos_controller'
# Re-raise errors caught by the controller.
class TodosController; def rescue_action(e) raise e end; end
class TodosControllerTest < Test::Rails::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :tags, :taggings
def setup
@controller = TodosController.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'
end
def test_not_done_counts
login_as(:admin_user)
get :index
assert_equal 2, assigns['project_not_done_counts'][projects(:timemachine).id]
assert_equal 3, assigns['context_not_done_counts'][contexts(:call).id]
assert_equal 1, assigns['context_not_done_counts'][contexts(:lab).id]
end
def test_tag_is_retrieved_properly
login_as(:admin_user)
get :index
t = assigns['not_done_todos'].find{|t| t.id == 2}
assert_equal 1, t.tags.count
assert_equal 'foo', t.tags[0].name
assert !t.starred?
end
def test_not_done_counts_after_hiding_project
p = Project.find(1)
p.hide!
p.save!
login_as(:admin_user)
get :index
assert_equal nil, assigns['project_not_done_counts'][projects(:timemachine).id]
assert_equal 2, assigns['context_not_done_counts'][contexts(:call).id]
assert_equal nil, assigns['context_not_done_counts'][contexts(:lab).id]
end
def test_not_done_counts_after_hiding_and_unhiding_project
p = Project.find(1)
p.hide!
p.save!
p.activate!
p.save!
login_as(:admin_user)
get :index
assert_equal 2, assigns['project_not_done_counts'][projects(:timemachine).id]
assert_equal 3, assigns['context_not_done_counts'][contexts(:call).id]
assert_equal 1, assigns['context_not_done_counts'][contexts(:lab).id]
end
def test_deferred_count_for_project_source_view
login_as(:admin_user)
xhr :post, :toggle_check, :id => 5, :_source_view => 'project'
assert_equal 1, assigns['deferred_count']
xhr :post, :toggle_check, :id => 15, :_source_view => 'project'
assert_equal 0, assigns['deferred_count']
end
def test_destroy_todo
login_as(:admin_user)
xhr :post, :destroy, :id => 1, :_source_view => 'todo'
assert_rjs :page, "todo_1", :remove
#assert_rjs :replace_html, "badge-count", '9'
end
def test_create_todo
assert_difference Todo, :count do
login_as(:admin_user)
put :create, :_source_view => 'todo', "context_name"=>"library", "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"
end
end
def test_create_todo_via_xml
login_as(:admin_user)
assert_difference Todo, :count do
put :create, :format => "xml", "request" => { "context_name"=>"library", "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 201
end
end
def test_fail_to_create_todo_via_xml
login_as(:admin_user)
#try to create with no context, which is not valid
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_xml_select "errors" do
assert_xml_select "error", "Context can't be blank"
end
end
def test_create_deferred_todo
original_todo_count = Todo.count
login_as(:admin_user)
put :create, :_source_view => 'todo', "context_name"=>"library", "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/2026", 'show_from' => '30/10/2026'}, "tag_list"=>"foo bar"
assert_equal original_todo_count + 1, Todo.count
end
def test_update_todo_project
t = Todo.find(1)
login_as(:admin_user)
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Build a working time machine", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
t = Todo.find(1)
assert_equal 1, t.project_id
end
def test_update_todo_project_to_none
t = Todo.find(1)
login_as(:admin_user)
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"None", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar"
t = Todo.find(1)
assert_nil t.project_id
end
def test_update_todo_to_deferred_is_reflected_in_badge_count
login_as(:admin_user)
get :index
assert_equal 10, assigns['count']
xhr :post, :update, :id => 1, :_source_view => 'todo', "context_name"=>"library", "project_name"=>"Make more money than Billy Gates", "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006", "show_from"=>"30/11/2030"}, "tag_list"=>"foo bar"
assert_equal 9, assigns['down_count']
end
def test_update_todo
t = Todo.find(1)
login_as(:admin_user)
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo, bar"
t = Todo.find(1)
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
assert_equal "foo, bar", t.tag_list
expected = Date.new(2006,11,30)
actual = t.due
assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
end
def test_update_todos_with_blank_project_name
t = Todo.find(1)
login_as(:admin_user)
xhr :post, :update, :id => 1, :_source_view => 'todo', :project_name => '', "todo"=>{"id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo, bar"
t.reload
assert t.project.nil?
end
def test_update_todo_tags_to_none
t = Todo.find(1)
login_as(:admin_user)
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>""
t = Todo.find(1)
assert_equal true, t.tag_list.empty?
end
def test_update_todo_tags_with_whitespace_and_dots
t = Todo.find(1)
login_as(:admin_user)
taglist = " one , two,three ,four, 8.1.2, version1.5"
xhr :post, :update, :id => 1, :_source_view => 'todo', "todo"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>taglist
t = Todo.find(1)
assert_equal "one, two, three, four, 8.1.2, version1.5", t.tag_list
end
def test_find_tagged_with
login_as(:admin_user)
@user = User.find(@request.session['user_id'])
tag = Tag.find_by_name('foo').todos
@tagged = tag.find(:all, :conditions => ['taggings.user_id = ?', @user.id]).size
get :tag, :name => 'foo'
assert_response :success
assert_equal 3, @tagged
end
def test_rss_feed
login_as(:admin_user)
get :index, { :format => "rss" }
assert_equal 'application/rss+xml', @response.content_type
#puts @response.body
assert_xml_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Actions'
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
assert_select 'language', 'en-us'
assert_select 'ttl', '40'
assert_select 'item', 10 do
assert_select 'title', /.+/
assert_select 'description', /.*/
assert_select 'link', %r{http://test.host/contexts/.+}
assert_select 'guid', %r{http://test.host/todos/.+}
assert_select 'pubDate', projects(:timemachine).updated_at.to_s(:rfc822)
end
end
end
end
def test_rss_feed_with_limit
login_as(:admin_user)
get :index, { :format => "rss", :limit => '5' }
assert_xml_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Actions'
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
assert_select 'item', 5 do
assert_select 'title', /.+/
assert_select 'description', /.*/
end
end
end
end
def test_rss_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "rss" }
assert_response 401
end
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "rss", :token => 'foo' }
assert_response 401
end
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "rss", :token => users(:admin_user).token }
assert_response :ok
end
def test_atom_feed_content
login_as :admin_user
get :index, { :format => "atom" }
assert_equal 'application/atom+xml', @response.content_type
#puts @response.body
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_xml_select '>title', 'Tracks Actions'
assert_xml_select '>subtitle', "Actions for #{users(:admin_user).display_name}"
assert_xml_select 'entry', 10 do
assert_xml_select 'title', /.+/
assert_xml_select 'content[type="html"]', /.*/
assert_xml_select 'published', /(#{projects(:timemachine).updated_at.xmlschema}|#{projects(:moremoney).updated_at.xmlschema})/
end
end
end
def test_atom_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "atom" }
assert_response 401
end
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "atom", :token => 'foo' }
assert_response 401
end
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "atom", :token => users(:admin_user).token }
assert_response :ok
end
def test_text_feed_content
login_as(:admin_user)
get :index, { :format => "txt" }
assert_equal 'text/plain', @response.content_type
assert !(/&nbsp;/.match(@response.body))
#puts @response.body
end
def test_text_feed_not_accessible_to_anonymous_user_without_token
login_as nil
get :index, { :format => "txt" }
assert_response 401
end
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
login_as nil
get :index, { :format => "txt", :token => 'foo' }
assert_response 401
end
def test_text_feed_accessible_to_anonymous_user_with_valid_token
login_as nil
get :index, { :format => "txt", :token => users(:admin_user).token }
assert_response :ok
end
def test_ical_feed_content
login_as :admin_user
get :index, { :format => "ics" }
assert_equal 'text/calendar', @response.content_type
assert !(/&nbsp;/.match(@response.body))
#puts @response.body
end
def test_mobile_index_uses_text_html_content_type
login_as(:admin_user)
get :index, { :format => "m" }
assert_equal 'text/html', @response.content_type
end
def test_mobile_index_assigns_down_count
login_as(:admin_user)
get :index, { :format => "m" }
assert_equal 10, assigns['down_count']
end
def test_mobile_create_action_creates_a_new_todo
login_as(:admin_user)
post :create, {"format"=>"m", "todo"=>{"context_id"=>"2",
"due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
"show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
"project_id"=>"1",
"notes"=>"test notes", "description"=>"test_mobile_create_action", "state"=>"0"}}
t = Todo.find_by_description("test_mobile_create_action")
assert_not_nil t
assert_equal 2, t.context_id
assert_equal 1, t.project_id
assert t.active?
assert_equal 'test notes', t.notes
assert_nil t.show_from
assert_equal Date.new(2007,1,2).to_s, t.due.to_s
end
def test_mobile_create_action_redirects_to_mobile_home_page_when_successful
login_as(:admin_user)
post :create, {"format"=>"m", "todo"=>{"context_id"=>"2",
"due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
"show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
"project_id"=>"1",
"notes"=>"test notes", "description"=>"test_mobile_create_action", "state"=>"0"}}
assert_redirected_to '/m'
end
def test_mobile_create_action_renders_new_template_when_save_fails
login_as(:admin_user)
post :create, {"format"=>"m", "todo"=>{"context_id"=>"2",
"due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
"show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
"project_id"=>"1",
"notes"=>"test notes", "state"=>"0"}}
assert_template 'todos/new'
end
def test_index_html_assigns_default_project_name_map
login_as(:admin_user)
get :index, {"format"=>"html"}
assert_equal '"{\\"Build a working time machine\\": \\"lab\\"}"', assigns(:default_project_context_name_map)
end
end

View file

@ -0,0 +1,170 @@
require 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 < Test::Rails::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'
end
def test_get_index_by_nonadmin
login_as :other_user
get :index
assert_response 401
end
def test_get_index_by_admin
login_as :admin_user
get :index
assert_response :success
assert_equal "TRACKS::Manage Users", assigns['page_title']
assert_equal 3, assigns['total_users']
assert_equal "/users", session['return-to']
end
def test_destroy_user
login_as :admin_user
@no_users_before = User.find(:all).size
xhr :post, :destroy, :id => 3
assert_rjs :page, "user-3", :remove
assert_equal @no_users_before-1, User.find(:all).size
end
def test_update_password_successful
get :change_password # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
login_as :admin_user
@user = @request.session['user_id']
get :change_password # should now pass because we're logged in
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Change password"
post :update_password, :updateuser => {:password => 'newpassword', :password_confirmation => 'newpassword'}
assert_redirected_to preferences_path
@updated_user = User.find(users(:admin_user).id)
assert_equal @updated_user.crypted_password, Digest::SHA1.hexdigest("#{Tracks::Config.salt}--newpassword--")
assert_equal "Password updated.", flash[:notice]
end
def test_update_password_no_confirmation
post :update_password # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
login_as :admin_user
post :update_password, :updateuser => {:password => 'newpassword', :password_confirmation => 'wrong'}
assert_redirected_to :controller => 'users', :action => 'change_password'
assert users(:admin_user).save, false
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'
login_as :admin_user
post :update_password, :updateuser => {:password => 'ba', :password_confirmation => 'ba'}
assert_redirected_to :controller => 'users', :action => 'change_password'
assert users(:admin_user).save, false
# 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)"
assert_equal 'Validation failed: Password is too short (minimum is 5 characters)', flash[:error]
end
# ============================================
# Signup and creation of new users
# ============================================
def test_create_adds_a_new_nonadmin_user
login_as :admin_user
post :create, :user => {:login => 'newbie', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
newbie = User.find_by_login('newbie')
assert_equal newbie.login, "newbie"
assert newbie.is_admin == false || newbie.is_admin == 0
assert_not_nil newbie.preference # have user preferences been created?
assert_not_nil User.authenticate('newbie', 'newbiepass')
end
def test_create_redirects_to_home_page
login_as :admin_user
post :create, :user => {:login => 'newbie', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
assert_redirected_to home_url
end
def test_create_sets_flash_message
login_as :admin_user
post :create, :user => {:login => 'newbie', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
assert_equal "Signup successful for user newbie.", flash[:notice], "expected flash notice not found"
end
def test_create_adds_a_user
login_as :admin_user
assert_difference(User, :count) do
post :create, :user => {:login => 'newbie', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
end
end
# Test whether signup of new users is denied to a non-admin user
#
def test_create_by_non_admin
login_as :other_user
assert_no_difference(User, :count) do
post :create, :user => {:login => 'newbie2', :password => 'newbiepass2', :password_confirmation => 'newbiepass2'}
end
assert_response :success
assert_template 'users/nosignup'
end
# ============================================
# Test validations
# ============================================
def test_create_with_invalid_password_does_not_add_a_new_user
login_as :admin_user
assert_no_difference(User, :count) do
post :create, :user => {:login => 'newbie', :password => '', :password_confirmation => ''}
end
end
def test_create_with_invalid_password_redirects_to_new_user_page
login_as :admin_user
post :create, :user => {:login => 'newbie', :password => '', :password_confirmation => ''}
assert_redirected_to :controller => 'users', :action => 'new'
end
def test_create_with_invalid_login_does_not_add_a_new_user
login_as :admin_user
post :create, :user => {:login => 'n', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
assert_redirected_to :controller => 'users', :action => 'new'
end
def test_create_with_invalid_login_redirects_to_new_user_page
login_as :admin_user
post :create, :user => {:login => 'n', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
assert_redirected_to :controller => 'users', :action => 'new'
end
def test_create_with_duplicate_login_does_not_add_a_new_user
login_as :admin_user
assert_no_difference(User, :count) do
post :create, :user => {:login => 'jane', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
end
end
def test_create_with_duplicate_login_redirects_to_new_user_page
login_as :admin_user
post :create, :user => {:login => 'jane', :password => 'newbiepass', :password_confirmation => 'newbiepass'}
assert_redirected_to :controller => 'users', :action => 'new'
end
end

View file

@ -0,0 +1,76 @@
require 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
@@context_name = "@newcontext"
@@valid_postdata = "<request><context><name>#{@@context_name}</name></context></request>"
def setup
assert_test_environment_ok
end
def test_fails_with_401_if_not_authorized_user
authenticated_post_xml_to_context_create @@valid_postdata, 'nobody', 'nohow'
assert_401_unauthorized
end
def test_fails_with_invalid_xml_format
authenticated_post_xml_to_context_create "<foo></bar>"
assert_equal 500, @integration_session.status
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]
end
def test_fails_with_too_long_name
invalid_with_long_name_postdata = "<request><context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context></request>"
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
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_creates_new_context
assert_difference Context, :count do
authenticated_post_xml_to_context_create
assert_response 201
end
context1 = Context.find_by_name(@@context_name)
assert_not_nil context1, "expected context '#{@@context_name}' to be created"
end
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
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

View file

@ -0,0 +1,132 @@
require 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, :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
def test_last_15_actions_ical
assert_success "/todos.ics?token=#{ users(:admin_user).token }&limit=15"
end
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
def test_all_actions_due_today_or_earlier_txt
assert_success "/todos.txt?token=#{ users(:admin_user).token }&due=0"
end
def test_all_actions_due_today_or_earlier_ical
assert_success "/todos.ics?token=#{ users(:admin_user).token }&due=0"
end
def test_all_actions_due_in_7_days_or_earlier_rss
assert_success "/todos.rss?token=#{ users(:admin_user).token }&due=6"
end
def test_all_actions_due_in_7_days_or_earlier_txt
assert_success "/todos.txt?token=#{ users(:admin_user).token }&due=6"
end
def test_all_actions_due_in_7_days_or_earlier_ical
assert_success "/todos.ics?token=#{ users(:admin_user).token }&due=6"
end
def test_all_actions_completed_in_last_7_days_rss
assert_success "/todos.rss?token=#{ users(:admin_user).token }&done=7"
end
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_all_projects_txt_with_hidden_project
p = projects(:timemachine)
p.hide!
assert_success "/projects.txt?token=#{ users(:admin_user).token }"
end
private
def assert_success(url)
get url
assert_response :success
#puts @response.body
end
end

View file

@ -0,0 +1,145 @@
require "#{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

View file

@ -0,0 +1,70 @@
require 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
def test_fails_with_401_if_not_authorized_user
authenticated_post_xml_to_project_create @@valid_postdata, 'nobody', 'nohow'
assert_401_unauthorized
end
def test_fails_with_invalid_xml_format
authenticated_post_xml_to_project_create "<foo></bar>"
assert_equal 500, @integration_session.status
end
def test_fails_with_invalid_xml_format2
authenticated_post_xml_to_project_create "<request><project></project></request>"
assert_404_invalid_xml
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]
end
def test_fails_with_too_long_name
invalid_with_long_name_postdata = "<request><project><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></project></request>"
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"
end
def test_fails_with_comma_in_name
authenticated_post_xml_to_project_create "<request><project><name>foo,bar</name></project></request>"
assert_response_and_body 404, "Name cannot contain the comma (',') character"
end
def test_creates_new_project
assert_difference Project, :count do
authenticated_post_xml_to_project_create
assert_response :created
end
project1 = Project.find_by_name(@@project_name)
assert_not_nil project1, "expected project '#{@@project_name}' to be created"
end
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
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>."
end
end

View file

@ -0,0 +1,80 @@
require "#{File.dirname(__FILE__)}/../test_helper"
class StoriesTest < ActionController::IntegrationTest
fixtures :users, :preferences, :projects, :contexts, :todos, :notes
def setup
assert_test_environment_ok
end
# ####################################################
# Testing login and signup by different kinds of users
# ####################################################
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",
:password => "newbiepass",
:password_confirmation => "newbiepass"})
end
def test_signup_new_user_by_nonadmin
other_user = new_session_as(:other_user,"sesame")
other_user.goes_to_signup_as_nonadmin
end
private
module CustomAssertions
attr_reader :user
def logs_in_as(user,plain_pass)
@user = users(user)
post "/login", :user_login => @user.login,
:user_password => plain_pass,
:user_noexpiry => 'n'
assert_response :redirect
follow_redirect!
assert_response :success
assert_template "todos/index"
end
def goes_to_login
get "/login"
assert_response :success
assert_template "login/login"
end
def goes_to_signup
get "/signup"
assert_response :success
assert_template "users/new"
end
def goes_to_signup_as_nonadmin
get "/signup"
assert_response :success
assert_template "users/nosignup"
end
def signs_up_with(options)
post "/users", options
assert_response :redirect
follow_redirect!
assert_response :success
assert_template "todos/index"
end
end
def new_session_as(user,plainpass)
open_session do |sess|
sess.extend(CustomAssertions)
sess.goes_to_login
sess.logs_in_as(user,plainpass)
yield sess if block_given?
end
end
end

View file

@ -0,0 +1,106 @@
require 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
def test_fails_with_401_if_not_authorized_user
authenticated_post_xml_to_user_create @@foobar_postdata, 'nobody', 'nohow'
assert_401_unauthorized_admin
end
def test_fails_with_401_if_not_admin_user
authenticated_post_xml_to_user_create @@foobar_postdata, users(:other_user).login, 'sesame'
assert_401_unauthorized_admin
end
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
end
def test_fails_with_invalid_xml_format
authenticated_post_xml_to_user_create "<foo></bar>"
assert_equal 500, @integration_session.status
end
def test_fails_with_invalid_xml_format2
authenticated_post_xml_to_user_create "<request><username>foo</username></request>"
assert_404_invalid_xml
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]
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"
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"
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
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"
end
def test_fails_with_get_verb
authenticated_get_xml "/users", users(:admin_user).login, 'abracadabra', {}
end
def test_get_users_as_xml
get '/users.xml', {}, basic_auth_headers()
assert_response :success
assert_tag :tag => "users",
:children => { :count => 3, :only => { :tag => "user" } }
assert_no_tag :tag => "password"
end
def test_get_user_as_xml
get "/users/#{users(:other_user).login}.xml", {}, basic_auth_headers()
assert_response :success
assert_tag :tag => "user"
assert_no_tag :tag => "password"
end
private
def basic_auth_headers(username = users(:admin_user).login, password = 'abracadabra')
{'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
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

View file

@ -0,0 +1,10 @@
setup :fixtures => :all
login :as => 'admin'
open "/contexts/1"
click "context_name_in_place_editor"
wait_for_element_present "css=#context_name_in_place_editor-inplaceeditor input.editor_field"
type "css=#context_name_in_place_editor-inplaceeditor input.editor_field", "Test Foo"
click "css=#context_name_in_place_editor-inplaceeditor input.editor_ok_button"
wait_for_text "context_name_in_place_editor", "Test Foo"
open "/contexts/1"
wait_for_text "context_name_in_place_editor", "Test Foo"

View file

@ -0,0 +1,6 @@
setup :fixtures => :all
login :as => 'admin'
open "/contexts"
click "css=#context_3 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the context 'email'?"
wait_for_element_not_present "context_3"

View file

@ -0,0 +1,15 @@
setup :fixtures => :all
login :as => 'admin'
open "/contexts"
click "css=#context_3 .buttons img.edit_item"
wait_for_visible "edit_context_3"
wait_for_not_visible "context_3"
type "//div[@id='edit_context_3'] //input[@name='context[name]']", "telegraph"
click "//div[@id='edit_context_3'] //button"
wait_for_not_visible "edit_context_3"
wait_for_visible "context_3"
click "css=#context_3 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the context 'telegraph'?"
wait_for_visible "flash"
wait_for_text "flash", "Deleted context 'telegraph'"
wait_for_element_not_present "context_3"

View file

@ -0,0 +1,19 @@
setup :fixtures => :all
login :as => 'admin'
open "/contexts"
click "css=#context_3 .buttons img.edit_item"
wait_for_visible "edit_context_3"
wait_for_not_visible "context_3"
type "//div[@id='edit_context_3'] //input[@name='context[name]']", "telegraph"
click "//div[@id='edit_context_3'] //button"
wait_for_not_visible "edit_context_3"
wait_for_visible "context_3"
assert_text 'css=#context_3 .data a', 'telegraph'
click "css=#context_3 .buttons img.edit_item"
wait_for_visible "edit_context_3"
wait_for_not_visible "context_3"
type "//div[@id='edit_context_3'] //input[@name='context[name]']", "email"
click "//div[@id='edit_context_3'] //button"
wait_for_not_visible "edit_context_3"
wait_for_visible "context_3"
assert_text 'css=#context_3 .data a', 'email'

View file

@ -0,0 +1,8 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
click "edit_icon_todo_12"
wait_for_visible "context_name_todo_12"
type "context_name_todo_12", "someday maybe"
click "submit_todo_12"
wait_for_element_not_present "todo_12"

View file

@ -0,0 +1,21 @@
# when you change a todo to a new context, the new context must show with
# the new todo
setup :fixtures => :all
login :as => 'admin'
open "/"
# change context of todo to new context
click "edit_icon_todo_12"
wait_for_visible "context_name_todo_12"
type "context_name_todo_12", "new context"
click "submit_todo_12"
# check that todo is removed from old context
wait_for_element_not_present "css=#c1 #todo_12"
# check if new context is shown and that the todo is also shown
wait_for_text_present 'new context'
# TODO: this check only looks for todo_12 but does not check if it is contained
# within the new context.
wait_for_element_not_present "#todo_12"

View file

@ -0,0 +1,11 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
click "edit_icon_todo_12"
wait_for_visible "context_name_todo_12"
type "context_name_todo_12", "errand"
click "submit_todo_12"
wait_for_element_not_present "css=#c1 #todo_12"
wait_for_visible "c4"
wait_for_visible "css=#c4 #todo_12"
assert_not_visible "c4empty-nd"

View file

@ -0,0 +1,8 @@
setup :fixtures => :users, :clear_tables => [:projects, :contexts, :todos]
login :as => 'admin'
open "/"
assert_context_count_incremented do
type "todo_description", "a new action"
type "todo_context_name", "Brand new context"
click "css=#todo-form-new-action .submit_box button"
end

View file

@ -0,0 +1,21 @@
# adding a new action to context and collapsing context should remove
# all actions in context including the newly added one
setup :fixtures => :all
login :as => 'admin'
open "/"
assert_element_present "todo_9"
# add new action to existing context
type "todo_description", "a new action"
type "todo_context_name", "Agenda"
click "css=#todo-form-new-action .submit_box button"
wait_for_visible "flash"
# toggle Agenda context c1 and wait until the context has collapsed
click "css=#toggle_c1"
wait_for_not_visible "todo_9"
# check that newly added action is not there
wait_for_not_visible "xpath=//span[text()='a new action']"

View file

@ -0,0 +1,9 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
assert_context_count_incremented do
type "todo_description", "tttt"
type "todo_project_name", "pppp"
type "todo_context_name", "cccc"
click "css=#todo-form-new-action .submit_box button"
end

View file

@ -0,0 +1,8 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
assert_context_count_incremented do
type "todo_description", "a new action"
type "todo_context_name", "Brand new context"
click "css=#todo-form-new-action .submit_box button"
end

View file

@ -0,0 +1,31 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
# we should start with 10 actions on home page
assert_text 'badge_count', '10'
# set project to hidden state
open "/projects/2"
click 'project_state_completed'
# wait for flash before navigating away from project page
wait_for_visible "flash"
# monitor badge count on home page. It should be 7 at the start
open "/"
wait_for_visible 'badge_count'
assert_text 'badge_count', '7'
# add todo to hidden project
type "todo_description", "should be hidden"
type "todo_project_name", "Make more money than Billy Gates"
type "todo_context_name", "agenda"
click "css=#todo-form-new-action .submit_box button"
# wait for flash to appear
wait_for_visible "flash"
verify_text_not_present 'should be hidden'
# badge count should still be same
assert_text 'badge_count', '7'

View file

@ -0,0 +1,27 @@
setup :fixtures => :all
login :as => 'admin'
# set project to hidden state
open "/projects/2"
click 'project_state_hidden'
# wait for flash before navigating away from project page to make sure that
# the changes have been saved
wait_for_visible "flash"
# monitor badge count on home page. It should be 7 at the start
open "/"
assert_text 'badge_count', '7'
# add todo to hidden project
type "todo_description", "should be hidden"
type "todo_project_name", "Make more money than Billy Gates"
type "todo_context_name", "agenda"
click "css=#todo-form-new-action .submit_box button"
# wait for flash to (dis)appear
wait_for_visible "flash"
verify_text_not_present 'should be hidden'
# badge count should still be same
assert_text 'badge_count', '7'

View file

@ -0,0 +1,9 @@
setup :fixtures => :all
login :as => 'admin'
open "/"
click "edit_icon_todo_9"
wait_for_element_present "show_from_todo_9"
type "show_from_todo_9", "1/1/2030"
click "css=#submit_todo_9"
wait_for_element_not_present "todo_9"
assert_text 'badge_count', '9'

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open '/'
click "xpath=//div[@id='c1'] //div[@id='todo_9'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_9']"

View file

@ -0,0 +1,6 @@
setup :fixtures => :all
login :as => 'admin'
open '/'
click "xpath=//div[@id='c5'] //div[@id='todo_5'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_5']"
wait_for_not_visible 'c5'

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'jane'
open '/'
click_and_wait "xpath=//div[@id='c10'] //div[@id='todo_16'] //input[@class='item-checkbox']"
assert_title "TRACKS::Project: Attend RailsConf"

View file

@ -0,0 +1,6 @@
setup :fixtures => :all
login :as => 'admin'
open '/'
click "xpath=//div[@id='completed'] //div[@id='todo_3'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='c4'] //div[@id='todo_3']"
assert_not_visible "c4empty-nd"

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open '/'
click "css=#c1 #todo_9 a.star_item"
wait_for_element_present "css=#c1 #todo_9 img.starred_todo"

View file

@ -0,0 +1,4 @@
setup :fixtures => :all
login :as => 'admin'
open '/'
assert_element_present "css=#c2 #todo_2 img.unstarred_todo"

View file

@ -0,0 +1,14 @@
setup :fixtures => :users, :clear_tables => [:projects, :contexts, :todos]
login :as => 'admin'
open "/integrations"
wait_for_element_present "no_context_msg"
open "/contexts"
type "context_name", "my first context"
click "context_new_submit"
# wait for new context to appear before navigating away from project page to
# make sure that the changes have been saved
wait_for_text_present 'DRAG'
open "/integrations"
wait_for_element_present "applescript1-contexts"

View file

@ -0,0 +1,5 @@
open :controller => 'login', :action => 'logout'
open :controller => 'login'
type "user_login", username
type "user_password", password
click_and_wait "login"

View file

@ -0,0 +1,8 @@
setup :clear_tables => [:users, :preferences]
open '/'
assert_title 'exact:TRACKS::Sign up as the admin user'
type "user_login", "admin"
type "user_password", "abracadabra"
type "user_password_confirmation", "abracadabra"
click_and_wait "signup"
assert_title 'exact:TRACKS::List tasks'

View file

@ -0,0 +1,9 @@
setup :fixtures => :all
open :controller => 'login', :action => 'logout'
open :controller => 'login'
assert_title 'exact:TRACKS::Login'
type "user_login", "admin"
type "user_password", "incorrect_password"
click_and_wait "login"
assert_title 'exact:TRACKS::Login'
verify_text_present 'Login unsuccessful'

View file

@ -0,0 +1,12 @@
setup :fixtures => :all
open :controller => 'login', :action => 'logout'
open :controller => 'login'
assert_title 'exact:TRACKS::Login'
type "user_login", "admin"
type "user_password", "abracadabra"
click_and_wait "login"
assert_title 'exact:TRACKS::List tasks'
wait_for_visible "flash"
wait_for_text "flash", "Login successful: session will not expire."
#next line slows down the test unacceptably, but is useful in ensuring that the message disappears.
#wait_for_not_visible "flash"

View file

@ -0,0 +1,18 @@
setup :fixtures => :all
login :as => 'admin'
open '/m'
wait_for_text 'css=h1 span.count', '10'
click_and_wait "link=Add new action"
type "todo_notes", "test notes"
type "todo_description", "test name"
select "todo_context_id", "label=call"
select "todo_project_id", "label=Make more money than Billy Gates"
select "todo_due_3i", "label=1"
select "todo_due_2i", "label=January"
select "todo_due_1i", "label=2009"
click_and_wait "//input[@value='Create']"
wait_for_text 'css=h1 span.count', '11'

View file

@ -0,0 +1,11 @@
setup :fixtures => :all
login :as => 'admin'
open '/m'
wait_for_text 'css=h1 span.count', '10'
open_and_wait '/todos/6.m'
click "done"
click_and_wait "//input[@value='Update']"
wait_for_text 'css=h1 span.count', '9'

View file

@ -0,0 +1,35 @@
setup :fixtures => :all
login :as => 'admin'
# open home page
open '/m'
wait_for_title "All actions"
wait_for_text 'css=h1 span.count', '10'
# open context page
click_and_wait "link=Contexts"
# verify_title "All actions in context agenda"
# choose agenda context
click_and_wait "link=agenda"
wait_for_text 'css=h1 span.count', '5'
# click on tag foo to go to tag page
click_and_wait "link=foo"
verify_title "TRACKS::Tagged with 'foo'"
wait_for_text 'css=h1 span.count', '2'
click_and_wait "link=Projects"
wait_for_text 'css=h1 span.count', '3'
click_and_wait "link=Build a working time machine"
wait_for_text 'css=h1 span.count', '3'
# follow link of action to edit form and mark done
click_and_wait "link=Select Delorean model"
click "done"
click_and_wait "//input[@value='Update']"
wait_for_text 'css=h1 span.count', '2'
# just test the navigation.
click_and_wait "link=Tickler"
wait_for_text 'css=h1 span.count', '0'
click_and_wait "link=Feeds"

View file

@ -0,0 +1,27 @@
setup :fixtures => :all
login :as => 'admin'
open "/notes/"
assert_text 'badge_count', '2'
# add new note
open "/projects/1"
click "css=#add_note_href"
type "css=#new_note_body", "new note"
click "add-new-note"
# wait until new note is saved
wait_for_text_not_present "new note"
wait_for_text_present "new note"
# check badge count is one more
open "/notes/"
assert_text 'badge_count', '3'
# delete note
click "css=#delete_note_1"
assert_confirmation "Are you sure that you want to delete the note '1'?"
# check badge decreased
wait_for_visible "flash"
wait_for_element_not_present "container_note_1"
assert_text 'badge_count', '2'

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click_and_wait "css=#note_1 .link_to_notes"
assert_element_present "note_1"

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/notes/"
assert_element_present "note_1"
assert_element_present "note_2"

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/notes"
click "css=#toggle-notes-nav"
wait_for_element_present "css=body.notes"

View file

@ -0,0 +1,5 @@
type "todo_description", "choose era"
type "todo_show_from", "1/1/2030"
click "css=#todo-form-new-action .submit_box button"
wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container']"
wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container'] //a[@title='01/01/2030']"

View file

@ -0,0 +1,20 @@
setup :fixtures => :all
login :as => 'admin'
#first, defer a todo
open "/projects/1"
click "edit_icon_todo_5"
wait_for_element_present "show_from_todo_5"
type "show_from_todo_5", "1/1/2030"
click "css=#submit_todo_5"
wait_for_element_present "xpath=//div[@id='tickler'] //div[@id='todo_5']"
#now activate the other deferred one
open "/projects/1"
click "edit_icon_todo_15"
wait_for_element_present "show_from_todo_15"
type "show_from_todo_15", ""
click "css=#submit_todo_15"
wait_for_element_present "xpath=//div[@id='p1'] //div[@id='todo_15']"
assert_not_visible "tickler-empty-nd"
assert_text 'badge_count', '2'

View file

@ -0,0 +1,9 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click "edit_icon_todo_15"
wait_for_element_present "show_from_todo_15"
type "show_from_todo_15", ""
click "css=#submit_todo_15"
wait_for_element_present "xpath=//div[@id='p1'] //div[@id='todo_15']"
wait_for_visible "tickler-empty-nd"

View file

@ -0,0 +1,12 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
# add new todo
type "todo_description", "a brand new todo"
click "css=#todo-form-new-action .submit_box button"
wait_for_element_present "xpath=//div[@id='p1'] //div[@class='item-container']"
# wait for flash to mention that todo was added and verify existence of new todo
wait_for_visible "flash"
verify_text_present 'a brand new todo'

View file

@ -0,0 +1,24 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/2"
# change default context
type "project[default_context_name]", "errand"
click "commit"
wait_for_visible "flash"
# add actions
type "todo_description", "test1"
click "css=#todo-form-new-action .submit_box button"
wait_for_visible "flash"
wait_for_not_visible "flash"
type "todo_description", "test2"
click "css=#todo-form-new-action .submit_box button"
wait_for_visible "flash"
# check that context errand now contains 2 todos
open "/contexts/4"
assert_text "badge_count", "2"

View file

@ -0,0 +1,14 @@
setup :fixtures => :all
login :as => 'admin'
open '/projects/1'
assert_checked 'project_state_active', 'ignored'
assert_attribute 'css=#project_status .active span', 'class', 'active_state'
assert_attribute 'css=#project_status .hidden span', 'class', 'inactive_state'
assert_text 'badge_count', '2'
click 'project_state_hidden'
wait_for_attribute 'css=#project_status .active span', 'class', 'inactive_state'
wait_for_attribute 'css=#project_status .hidden span', 'class', 'active_state'
assert_text 'badge_count', '2'
open '/projects/1'
assert_text 'badge_count', '2'
assert_checked 'project_state_hidden', 'ignored'

View file

@ -0,0 +1,9 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click "edit_icon_todo_5"
wait_for_element_present "show_from_todo_5"
type "project_name_todo_5", ""
click "css=#submit_todo_5"
wait_for_element_not_present "todo_5"
assert_text 'badge_count', '1'

View file

@ -0,0 +1,23 @@
setup :fixtures => :all
login :as => 'admin'
open '/projects/1'
assert_text 'badge_count', '2'
click 'project_state_hidden'
wait_for_attribute 'css=#project_status .active span', 'class', 'inactive_state'
wait_for_attribute 'css=#project_status .hidden span', 'class', 'active_state'
assert_text 'badge_count', '2'
type "todo_description", "add one to hidden project 1"
click "css=#todo-form-new-action .submit_box button"
wait_for_visible "flash"
wait_for_not_visible "flash"
type "todo_description", "add one to hidden project 2"
click "css=#todo-form-new-action .submit_box button"
wait_for_visible "flash"
assert_text 'badge_count', '4'
open '/projects/1'
assert_text 'badge_count', '4'
assert_checked 'project_state_hidden', 'ignored'

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/2"
include_partial 'project_detail/add_deferred_todo'
assert_not_visible "tickler-empty-nd"

View file

@ -0,0 +1,10 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click "edit_icon_todo_5"
wait_for_element_present "show_from_todo_5"
type "show_from_todo_5", "1/1/2030"
click "css=#submit_todo_5"
wait_for_element_present "xpath=//div[@id='tickler'] //div[@id='todo_5']"
assert_not_visible "tickler-empty-nd"
assert_text 'badge_count', '1'

View file

@ -0,0 +1,10 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click "project_name_in_place_editor"
wait_for_element_present "css=#project_name_in_place_editor-inplaceeditor input.editor_field"
type "css=#project_name_in_place_editor-inplaceeditor input.editor_field", "Test Foo"
click "css=#project_name_in_place_editor-inplaceeditor input.editor_ok_button"
wait_for_text "project_name_in_place_editor", "Test Foo"
open "/projects/1"
wait_for_text "project_name_in_place_editor", "Test Foo"

View file

@ -0,0 +1,7 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
include_partial 'project_detail/add_deferred_todo'
click "xpath=//div[@id='tickler'] //div[@id='todo_15'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_15']"
assert_not_visible "tickler-empty-nd"

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click "xpath=//div[@id='tickler'] //div[@id='todo_15'] //input[@class='item-checkbox']"
wait_for_visible "tickler-empty-nd"

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects/1"
click "css=#toggle-notes-nav"
wait_for_element_present "notes_todo_6"

View file

@ -0,0 +1,6 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects"
click "css=#project_2 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the project 'Make more money than Billy Gates'?"
wait_for_element_not_present "project_2"

View file

@ -0,0 +1,17 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects"
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"
wait_for_not_visible "project_2"
type "//div[@id='edit_project_2'] //input[@name='project[name]']", "become a billionaire"
click "//div[@id='edit_project_2'] //button"
wait_for_not_visible "edit_project_2"
wait_for_visible "project_2"
wait_for_visible "flash"
wait_for_not_visible "flash"
click "css=#project_2 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the project 'become a billionaire'?"
wait_for_visible "flash"
assert_text "flash", "Deleted project 'become a billionaire'"
wait_for_element_not_present "project_2"

View file

@ -0,0 +1,19 @@
setup :fixtures => :all
login :as => 'admin'
open "/projects"
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"
wait_for_not_visible "project_2"
type "//div[@id='edit_project_2'] //input[@name='project[name]']", "become a billionaire"
click "//div[@id='edit_project_2'] //button"
wait_for_not_visible "edit_project_2"
wait_for_visible "project_2"
assert_text 'css=#project_2 .data a', 'become a billionaire'
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"
wait_for_not_visible "project_2"
type "//div[@id='edit_project_2'] //input[@name='project[name]']", "become a multi-millionaire"
click "//div[@id='edit_project_2'] //button"
wait_for_not_visible "edit_project_2"
wait_for_visible "project_2"
assert_text 'css=#project_2 .data a', 'become a multi-millionaire'

View file

@ -0,0 +1,16 @@
setup :fixtures => :all
login :as => 'admin'
open "/todos/tag/foo"
assert_text 'badge_count', '2'
click "css=#delete_icon_2"
assert_confirmation "Are you sure that you want to delete the action 'Call dinosaur exterminator'?"
wait_for_element_not_present "todo_2"
assert_text 'badge_count', '1'
# mark one complete
click "xpath=//div[@id='c1'] //div[@id='todo_1'] //input[@class='item-checkbox']"
wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_1']"
assert_text 'badge_count', '0'

View file

@ -0,0 +1,5 @@
setup :fixtures => :all
login :as => 'admin'
open "/todos/tag/foo"
wait_for_element_present "xpath=//div[@id='c1'] //h2"
wait_for_text 'badge_count', '2'

View file

@ -0,0 +1,6 @@
setup :fixtures => [:users, :projects, :contexts, :todos, :notes]
login :as => 'admin'
open "/"
click_and_wait "xpath=//ul[@id='navlist'] //a[@title='See your starred actions']"
assert_title "exact:TRACKS::Tagged with 'starred'"
verify_text_present "Currently there are no incomplete actions with the tag 'starred'"

View file

@ -0,0 +1,12 @@
setup :fixtures => :all
login :as => 'admin'
open "/tickler"
click "edit_icon_todo_15"
wait_for_visible "context_name_todo_15"
type "context_name_todo_15", "lab"
click "submit_todo_15"
wait_for_element_not_present "css=#c6 #todo_15"
wait_for_visible "c5"
wait_for_visible "css=#c5 #todo_15"
assert_not_visible "c5empty-nd"
wait_for_not_visible "c6"

View file

@ -0,0 +1,12 @@
setup :fixtures => [:users, :preferences, :contexts, :projects], :clear_tables => [:todos]
login :as => 'admin'
open "/tickler"
assert_context_count_incremented do
type "todo_description", "a new action"
type "todo_context_name", "errands"
type "todo_project_name", "None"
type "todo_show_from", "1/1/2030"
click "css=#todo-form-new-action .submit_box button"
end
wait_for_not_visible "tickler-empty-nd"
wait_for_element_present "xpath=//div[@class='item-container'] //a[@title='01/01/2030']"

View file

@ -0,0 +1,9 @@
setup :fixtures => :all
login :as => 'admin'
open "/tickler"
assert_context_count_incremented do
type "todo_description", "a new action"
type "todo_context_name", "Brand new context"
type "todo_show_from", "1/1/2030"
click "css=#todo-form-new-action .submit_box button"
end

View file

@ -0,0 +1,4 @@
setup :fixtures => :all
login :as => 'admin'
open "/tickler/"
assert_element_present "todo_15"

56
test/selenium_helper.rb Normal file
View file

@ -0,0 +1,56 @@
class SeleniumHelperController < ActionController::Base
def login
if params[:as]
user = User.find_by_login(params[:as].to_s)
session['user_id'] = user
user.contexts.each do |c|
cookies["tracks_#{user.login}_context_c#{c.id}_collapsed"] = nil
end
end
render :text => "Logged in as #{params[:as]}"
end
end
ActionController::Routing::Routes.add_route '/selenium_helper/login', :controller => 'selenium_helper', :action => 'login'
module SeleniumOnRails::TestBuilderActions
def login options = {}
options = {options => nil} unless options.is_a? Hash
opts = {:controller => 'selenium_helper', :action => 'login'}.merge(options)
open opts
end
end
# The accessors available for SeleniumOnRails::TestBuilder tests.
#
# For each +store_foo+ there's +assert_foo+, +assert_not_foo+, +verify_foo+,
# +verify_not_foo+, +wait_for_foo+, +wait_for_not_foo+.
module SeleniumOnRails::TestBuilderAccessors
# How many elements with the class "context" are present on the page?
#
# Related Assertions, automatically generated:
# * +assert_context_count+
# * +assert_not_context_count+
# * +verify_context_count+
# * +verify_not_context_count+
# * +wait_for_context_count+
# * +wait_for_not_context_count+
def store_context_count variable_name
command 'storeContextCount', variable_name
end
each_assertion 'store_context_count' do |assertion_method, command_name|
define_method assertion_method do |expected_count|
command command_name, expected_count
end
end
def assert_context_count_incremented(&block)
store_context_count 'initial_context_count'
store_eval "${initial_context_count} + 1", 'expected_context_count'
yield
wait_for_context_count "${expected_context_count}"
end
end

147
test/test_helper.rb Normal file
View file

@ -0,0 +1,147 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require File.expand_path(File.dirname(__FILE__) + "/../app/controllers/application")
require 'test/rails' #you need the zentest gem installed
require 'test_help'
require 'flexmock/test_unit' #and the flexmock gem, too!
require 'action_web_service/test_invoke'
module Tracks
class Config
def self.salt
"change-me"
end
end
end
class Test::Unit::TestCase
include AuthenticatedTestHelper
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
def assert_error_on(model_instance, attribute, expected_error)
actual_error = model_instance.errors.on attribute.to_sym
assert_equal expected_error, actual_error
end
alias_method :assert_errors_on, :assert_error_on
def assert_value_changed(object, method = nil)
initial_value = object.send(method)
yield
assert_not_equal initial_value, object.send(method), "#{object}##{method}"
end
end
class Test::Rails::HelperTestCase
self.use_transactional_fixtures = false
self.use_instantiated_fixtures = false
end
class Test::Rails::TestCase < 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
# 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 next_week
1.week.from_now.utc.to_date
end
# Courtesy of http://habtm.com/articles/2006/02/20/assert-yourself-man-redirecting-with-rjs
def assert_js_redirected_to(options={}, message=nil)
clean_backtrace do
assert_response(:success, message)
assert_equal 'text/javascript', @response.content_type, 'Response should be Javascript content-type';
js_regexp = %r{(\w+://)?.*?(/|$|\\\?)(.*)}
url_regexp = %r{^window\.location\.href [=] ['"]#{js_regexp}['"][;]$}
redirected_to = @response.body.match(url_regexp)
assert_not_nil(redirected_to, message)
redirected_to = redirected_to[3]
msg = build_message(message, "expected a JS redirect to <?>, found one to <?>", options, redirected_to)
if options.is_a?(String)
assert_equal(options.gsub(/^\//, ''), redirected_to, message)
elsif options.is_a?(Regexp)
assert(options =~ redirected_to, "#{message} #{options} #{redirected_to}")
else
msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)", redirected_to)
assert_equal(@controller.url_for(options).match(js_regexp)[3], redirected_to, msg)
end
end
end
end
class ActionController::IntegrationTest
Tag #avoid errors in integration tests
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
def assert_401_unauthorized_admin
assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function."
end
end

117
test/unit/context_test.rb Normal file
View file

@ -0,0 +1,117 @@
require File.dirname(__FILE__) + '/../test_helper'
class ContextTest < Test::Rails::TestCase
fixtures :contexts, :todos, :users, :preferences
def setup
@agenda = contexts(:agenda)
@email = contexts(:email)
@library = contexts(:library)
end
def test_validate_presence_of_name
@agenda.name = ""
assert !@agenda.save
assert_equal 1, @agenda.errors.count
assert_equal "context must have a name", @agenda.errors.on(:name)
end
def test_validate_name_is_less_than_256
@agenda.name = "a"*256
assert !@agenda.save
assert_equal 1, @agenda.errors.count
assert_equal "context name must be less than 256 characters", @agenda.errors.on(:name)
end
def test_validate_name_is_unique
newcontext = Context.new
newcontext.name = contexts(:agenda).name
newcontext.user_id = contexts(:agenda).user_id
assert !newcontext.save
assert_equal 1, newcontext.errors.count
assert_equal "already exists", newcontext.errors.on(:name)
end
def test_validate_name_does_not_contain_comma
newcontext = Context.new
newcontext.name = "phone,telegraph"
assert !newcontext.save
assert_equal 1, newcontext.errors.count
assert_equal "cannot contain the comma (',') character", newcontext.errors.on(:name)
end
def test_find_by_namepart_with_exact_match
c = Context.find_by_namepart('agenda')
assert_not_nil c
assert_equal @agenda.id, c.id
end
def test_find_by_namepart_with_starts_with
c = Context.find_by_namepart('agen')
assert_not_nil c
assert_equal @agenda.id, c.id
end
def test_delete_context_deletes_todos_within_it
assert_equal 6, @agenda.todos.count
agenda_todo_ids = @agenda.todos.collect{|t| t.id }
@agenda.destroy
agenda_todo_ids.each do |todo_id|
assert !Todo.exists?(todo_id)
end
end
def test_not_done_todos
assert_equal 5, @agenda.not_done_todos.size
t = @agenda.not_done_todos[0]
t.complete!
t.save!
assert_equal 4, Context.find(@agenda.id).not_done_todos.size
end
def test_done_todos
assert_equal 1, @agenda.done_todos.size
t = @agenda.not_done_todos[0]
t.complete!
t.save!
assert_equal 2, Context.find(@agenda.id).done_todos.size
end
def test_to_param_returns_id
assert_equal '1', @agenda.to_param
end
def test_title_reader_returns_name
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
@agenda.save!
@agenda.reload
assert_equal true, @agenda.hidden?
end
def test_summary
undone_todo_count = '5 actions'
assert_equal "<p>#{undone_todo_count}. Context is Active.</p>", @agenda.summary(undone_todo_count)
@agenda.hide = true
@agenda.save!
assert_equal "<p>#{undone_todo_count}. Context is Hidden.</p>", @agenda.summary(undone_todo_count)
end
def test_null_object
c = Context.null_object
assert c.nil?
assert_nil c.id
assert_equal '', c.name
end
end

14
test/unit/notes_test.rb Normal file
View file

@ -0,0 +1,14 @@
require File.dirname(__FILE__) + '/../test_helper'
class NotesTest < Test::Rails::TestCase
fixtures :notes
def setup
@notes = Note.find(1)
end
# Replace this with your real tests.
def test_truth
assert_kind_of Note, @notes
end
end

View file

@ -0,0 +1,35 @@
require File.dirname(__FILE__) + '/../test_helper'
class PreferenceTest < Test::Rails::TestCase
fixtures :users, :preferences
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
@admin_user = User.find(1)
@other_user = User.find(2)
end
def test_time_zone
assert_equal 'London', @admin_user.preference.time_zone
assert_equal @admin_user.preference.tz, TimeZone['London']
end
def test_show_project_on_todo_done
assert @other_user.preference.show_project_on_todo_done
assert !@admin_user.preference.show_project_on_todo_done
end
def test_parse_date
assert_equal Date.new(2007, 5, 20).to_s, @admin_user.preference.parse_date('20/5/2007').to_s
end
def test_parse_date_returns_nil_if_string_is_empty
assert_nil @admin_user.preference.parse_date('')
end
def test_parse_date_returns_nil_if_string_is_nil
assert_nil @admin_user.preference.parse_date(nil)
end
end

187
test/unit/project_test.rb Normal file
View file

@ -0,0 +1,187 @@
require File.dirname(__FILE__) + '/../test_helper'
class ProjectTest < Test::Rails::TestCase
fixtures :projects, :contexts, :todos, :users, :preferences
def setup
@timemachine = projects(:timemachine)
@moremoney = projects(:moremoney)
end
def test_validate_presence_of_name
@timemachine.name = ""
assert !@timemachine.save
assert_equal 1, @timemachine.errors.count
assert_equal "project must have a name", @timemachine.errors.on(:name)
end
def test_validate_name_is_less_than_256
@timemachine.name = "a"*256
assert !@timemachine.save
assert_equal 1, @timemachine.errors.count
assert_equal "project name must be less than 256 characters", @timemachine.errors.on(:name)
end
def test_validate_name_is_unique
newproj = Project.new
newproj.name = projects(:timemachine).name
newproj.user_id = projects(:timemachine).user_id
assert !newproj.save
assert_equal 1, newproj.errors.count
assert_equal "already exists", newproj.errors.on(:name)
end
def test_validate_name_does_not_contain_comma
newproj = Project.new
newproj.name = "Buy iPhones for Luke,bsag,David Allen"
assert !newproj.save
assert_equal 1, newproj.errors.count
assert_equal "cannot contain the comma (',') character", newproj.errors.on(:name)
end
def test_name_removes_extra_spaces
newproj = Project.new
newproj.name = "These Words Have Proximity Issues "
assert newproj.save
assert_equal 0, newproj.errors.count
assert_equal "These Words Have Proximity Issues", newproj.name
# and on update...
@timemachine.name = " a time machine needs lots of spaaaaaaace "
assert @timemachine.save
assert_equal "a time machine needs lots of spaaaaaaace", @timemachine.name
end
def test_project_initial_state_is_active
assert_equal :active, @timemachine.current_state
assert @timemachine.active?
end
def test_hide_project
@timemachine.hide!
assert_equal :hidden, @timemachine.current_state
assert @timemachine.hidden?
end
def test_activate_project
@timemachine.activate!
assert_equal :active, @timemachine.current_state
assert @timemachine.active?
end
def test_complete_project
assert_nil @timemachine.completed_at
@timemachine.complete!
assert_equal :completed, @timemachine.current_state
assert @timemachine.completed?
assert_not_nil @timemachine.completed_at, "completed_at not expected to be nil"
assert_in_delta Time.now, @timemachine.completed_at, 1
end
def test_find_project_by_namepart_with_exact_match
p = Project.find_by_namepart('Build a working time machine')
assert_not_nil p
assert_equal @timemachine.id, p.id
end
def test_find_project_by_namepart_with_starts_with
p = Project.find_by_namepart('Build a')
assert_not_nil p
assert_equal @timemachine.id, p.id
end
def test_delete_project_deletes_todos_within_it
assert_equal 3, @timemachine.todos.count
timemachine_todo_ids = @timemachine.todos.map{ |t| t.id }
@timemachine.destroy
timemachine_todo_ids.each do |t_id|
assert !Todo.exists?(t_id)
end
end
def test_not_done_todos
assert_equal 2, @timemachine.not_done_todos.size
t = @timemachine.not_done_todos[0]
t.complete!
t.save!
assert_equal 1, Project.find(@timemachine.id).not_done_todos.size
end
def test_done_todos
assert_equal 0, @timemachine.done_todos.size
t = @timemachine.not_done_todos[0]
t.complete!
t.save!
assert_equal 1, Project.find(@timemachine.id).done_todos.size
end
def test_deferred_todos
assert_equal 1, @timemachine.deferred_todos.size
t = @timemachine.not_done_todos[0]
t.show_from = 1.days.from_now.utc.to_date
t.save!
assert_equal 2, Project.find(@timemachine.id).deferred_todos.size
end
def test_to_param_returns_id
assert_equal '1', @timemachine.to_param
end
def test_null_object
p = Project.null_object
assert !p.hidden?
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_transition_to_another_state
assert_equal :active, @timemachine.current_state
@timemachine.transition_to(:hidden)
assert_equal :hidden, @timemachine.current_state
@timemachine.transition_to(:completed)
assert_equal :completed, @timemachine.current_state
@timemachine.transition_to(:active)
assert_equal :active, @timemachine.current_state
end
def test_transition_to_same_state
assert_equal :active, @timemachine.current_state
@timemachine.transition_to(:active)
assert_equal :active, @timemachine.current_state
end
def test_deferred_todo_count
assert_equal 1, @timemachine.deferred_todo_count
assert_equal 0, @moremoney.deferred_todo_count
@moremoney.todos[0].show_from = next_week
assert_equal 1, @moremoney.deferred_todo_count
end
def test_done_todo_count
assert_equal 0, @timemachine.done_todo_count
assert_equal 0, @moremoney.done_todo_count
@moremoney.todos[0].complete!
assert_equal 1, @moremoney.done_todo_count
end
def test_not_done_todo_count
assert_equal 2, @timemachine.not_done_todo_count
assert_equal 3, @moremoney.not_done_todo_count
@moremoney.todos[0].complete!
assert_equal 2, @moremoney.not_done_todo_count
end
def test_default_context_name
p = Project.new
assert_equal '', p.default_context.name
p.default_context = contexts(:agenda)
assert_equal 'agenda', p.default_context.name
end
end

View file

@ -0,0 +1,72 @@
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/../../lib/prototype_helper_extensions'
class PrototypeHelperExtensionsTest < Test::Unit::TestCase
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::PrototypeHelper
include ActionView::Helpers::ScriptaculousHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormHelper
include ActionView::Helpers::CaptureHelper
def setup
@template = nil
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
if options.is_a?(String)
options
elsif options.is_a?(Hash)
url = "http://www.example.com/"
url << options[:action].to_s if options and options[:action]
url << "?a=#{options[:a]}" if options && options[:a]
url << "&b=#{options[:b]}" if options && options[:a] && options[:b]
url
elsif options.is_a?(JavaScriptRef)
url = options.to_json
else
raise 'unhandled type' + options.class.inspect
end
end
end.new
@generator = create_generator
end
def test_confirming
@generator.confirming("Please confirm.") do
@generator.alert 'foo'
end
assert_equal "if (confirm('Please confirm.')) {\nalert(\"foo\");\n}", @generator.to_s
end
def test_confirming_with_javascript
@generator.confirming("'Please confirm ' + this.title + '.'") do
@generator.alert 'foo'
end
assert_equal "if (confirm('Please confirm ' + this.title + '.')) {\nalert(\"foo\");\n}", @generator.to_s
end
def test_remote_to_href
assert_equal "new Ajax.Request(this.href, {asynchronous:true, evalScripts:true})\n", remote_to_href
end
def test_remote_to_href_with_options
assert_equal "new Ajax.Request(this.href, {asynchronous:true, evalScripts:true, method:'put'})\n", remote_to_href(:method => 'put')
end
protected
def create_generator
block = Proc.new { |*args| yield *args if block_given? }
JavaScriptGenerator.new self, &block
end
def protect_against_forgery?
false
end
end

10
test/unit/tag_test.rb Normal file
View file

@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../test_helper'
class TagTest < Test::Rails::TestCase
fixtures :tags
# Replace this with your real tests.
def test_truth
assert true
end
end

10
test/unit/tagging_test.rb Normal file
View file

@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../test_helper'
class TaggingTest < Test::Rails::TestCase
fixtures :taggings
# Replace this with your real tests.
def test_truth
assert true
end
end

View file

@ -0,0 +1,136 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'todos_controller'
class TodoCreateParamsHelperTest < Test::Rails::TestCase
def test_works_with_request_as_root_hash_entry
params = {'request' => { 'todo' => { 'description' => 'foo'}}}
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal({'description' => 'foo'}, params_helper.attributes)
end
def test_works_with_todo_as_root_hash_entry
params = { 'todo' => { 'description' => 'foo'}}
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal({'description' => 'foo'}, params_helper.attributes)
end
def test_show_from_accessor
expected_date = Time.now.to_date
params = { 'todo' => { 'show_from' => expected_date}}
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal(expected_date, params_helper.show_from)
end
def test_due_accessor
expected_date = Time.now.to_date
params = { 'todo' => { 'due' => expected_date}}
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal(expected_date, params_helper.due)
end
def test_tag_list_accessor
params = { 'todo' => { }, 'tag_list' => 'foo, bar'}
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal('foo, bar', params_helper.tag_list)
end
def test_parse_dates_parses_show_from_date_based_on_prefs
params = { 'todo' => { 'show_from' => '5/20/07', 'due' => '5/23/07'}}
prefs = flexmock()
prefs.should_receive(:parse_date).with('5/20/07').and_return(Date.new(2007, 5, 20))
prefs.should_receive(:parse_date).with('5/23/07').and_return(Date.new(2007, 5, 23))
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
params_helper.parse_dates()
assert_equal Date.new(2007, 5, 20), params_helper.show_from
end
def test_parse_dates_parses_due_date_based_on_prefs
params = { 'todo' => { 'show_from' => '5/20/07', 'due' => '5/23/07'}}
prefs = flexmock()
prefs.should_receive(:parse_date).with('5/20/07').and_return(Date.new(2007, 5, 20))
prefs.should_receive(:parse_date).with('5/23/07').and_return(Date.new(2007, 5, 23))
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
params_helper.parse_dates()
assert_equal Date.new(2007, 5, 23), params_helper.due
end
def test_parse_dates_sets_due_to_empty_string_if_nil
params = { 'todo' => { 'show_from' => '5/20/07', 'due' => nil}}
prefs = flexmock()
prefs.should_receive(:parse_date).with('5/20/07').and_return(Date.new(2007, 5, 20))
prefs.should_receive(:parse_date).with(nil).and_return(nil)
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
params_helper.parse_dates()
assert_equal '', params_helper.due
end
def test_project_name_is_stripped_of_leading_and_trailing_whitespace
params = { 'project_name' => ' Visit New Orleans ' }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal 'Visit New Orleans', params_helper.project_name
end
def test_project_name_is_nil_when_unspecified
params = { }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_nil params_helper.project_name
end
def test_context_name_is_stripped_of_leading_and_trailing_whitespace
params = { 'context_name' => ' mobile phone ' }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal 'mobile phone', params_helper.context_name
end
def test_context_name_is_nil_when_unspecified
params = { }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_nil params_helper.context_name
end
def test_project_specified_by_name_is_false_when_project_id_is_specified
params = { 'todo' => { 'project_id' => 2 } }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal false, params_helper.project_specified_by_name?
end
def test_project_specified_by_name_is_false_when_project_name_is_blank
params = { 'project_name' => nil, 'todo' => {} }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal false, params_helper.project_specified_by_name?
end
def test_project_specified_by_name_is_false_when_project_name_is_none
params = { 'project_name' => 'None', 'todo' => {} }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal false, params_helper.project_specified_by_name?
end
def test_context_specified_by_name_is_false_when_context_id_is_specified
params = { 'todo' => { 'context_id' => 3 } }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal false, params_helper.context_specified_by_name?
end
def test_context_specified_by_name_is_false_when_context_name_is_blank
params = { 'context_name' => nil, 'todo' => {} }
prefs = flexmock()
params_helper = TodosController::TodoCreateParamsHelper.new(params, prefs)
assert_equal false, params_helper.context_specified_by_name?
end
end

182
test/unit/todo_test.rb Normal file
View file

@ -0,0 +1,182 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'date'
class TodoTest < Test::Rails::TestCase
fixtures :todos, :users, :contexts, :preferences, :tags, :taggings
def setup
@not_completed1 = Todo.find(1).reload
@not_completed2 = Todo.find(2).reload
@completed = Todo.find(8).reload
end
# Test loading a todo item
def test_load
assert_kind_of Todo, @not_completed1
assert_equal 1, @not_completed1.id
assert_equal 1, @not_completed1.context_id
assert_equal 2, @not_completed1.project_id
assert_equal "Call Bill Gates to find out how much he makes per day", @not_completed1.description
assert_nil @not_completed1.notes
assert @not_completed1.completed? == false
assert_equal 1.week.ago.utc.beginning_of_day.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.strftime("%Y-%m-%d %H:%M")
assert_equal 2.week.from_now.utc.beginning_of_day.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d")
assert_nil @not_completed1.completed_at
assert_equal 1, @not_completed1.user_id
end
def test_completed
assert_kind_of Todo, @completed
assert @completed.completed?
assert_not_nil @completed.completed_at
end
def test_completed_at_cleared_after_toggle_to_active
assert_kind_of Todo, @completed
assert @completed.completed?
@completed.toggle_completion!
assert @completed.active?
assert_nil @completed.completed_at
end
# Validation tests
#
def test_validate_presence_of_description
assert_equal "Call dinosaur exterminator", @not_completed2.description
@not_completed2.description = ""
assert !@not_completed2.save
assert_equal 1, @not_completed2.errors.count
assert_equal "can't be blank", @not_completed2.errors.on(:description)
end
def test_validate_length_of_description
assert_equal "Call dinosaur exterminator", @not_completed2.description
@not_completed2.description = generate_random_string(101)
assert !@not_completed2.save
assert_equal 1, @not_completed2.errors.count
assert_equal "is too long (maximum is 100 characters)", @not_completed2.errors.on(:description)
end
def test_validate_length_of_notes
assert_equal "Ask him if I need to hire a skip for the corpses.", @not_completed2.notes
@not_completed2.notes = generate_random_string(60001)
assert !@not_completed2.save
assert_equal 1, @not_completed2.errors.count
assert_equal "is too long (maximum is 60000 characters)", @not_completed2.errors.on(:notes)
end
def test_validate_show_from_must_be_a_date_in_the_future
t = @not_completed2
t[:show_from] = 1.week.ago.to_date # we have to set this via the indexer because show_from=() updates the state
# and actual show_from value appropriately based on the date
assert_equal 1.week.ago.to_date, t.show_from
assert !t.save
assert_equal 1, t.errors.count
assert_equal "must be a date in the future", t.errors.on(:show_from)
end
def test_defer_an_existing_todo
@not_completed2
assert_equal :active, @not_completed2.current_state
@not_completed2.show_from = next_week
assert @not_completed2.save, "should have saved successfully" + @not_completed2.errors.to_xml
assert_equal :deferred, @not_completed2.current_state
end
def test_create_a_new_deferred_todo
user = users(:other_user)
todo = user.todos.build
todo.show_from = next_week
todo.context_id = 1
todo.description = 'foo'
assert todo.save, "should have saved successfully" + todo.errors.to_xml
assert_equal :deferred, todo.current_state
end
def test_create_a_new_deferred_todo_by_passing_attributes
user = users(:other_user)
todo = user.todos.build(:show_from => next_week, :context_id => 1, :description => 'foo')
assert todo.save, "should have saved successfully" + todo.errors.to_xml
assert_equal :deferred, todo.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.current_state
t.toggle_completion!
assert_equal :completed, t.current_state
t.toggle_completion!
assert_equal :active, t.current_state
end
def test_activate_also_saves
t = @not_completed1
t.show_from = 1.week.from_now.to_date
t.save!
assert t.deferred?
t.reload
t.activate!
assert t.active?
t.reload
assert t.active?
end
def test_project_returns_null_object_when_nil
t = @not_completed1
assert !t.project.is_a?(NullProject)
t.project = nil
assert t.project.is_a?(NullProject)
end
def test_initial_state_defaults_to_active
t = Todo.new
t.description = 'foo'
t.context_id = 1
t.save!
t.reload
assert_equal :active, t.current_state
end
def test_initial_state_is_deferred_when_show_from_in_future
t = Todo.new
t.user = users(:admin_user)
t.description = 'foo'
t.context_id = 1
t.show_from = 1.week.from_now.to_date
t.save!
t.reload
assert_equal :deferred, t.current_state
end
def test_todo_is_not_starred
assert !@not_completed1.starred?
end
def test_todo_2_is_not_starred
assert !Todo.find(2).starred?
end
def test_todo_is_starred_after_starred_tag_is_added
@not_completed1.add_tag('starred')
assert @not_completed1.starred?
end
def test_todo_is_starred_after_toggle_starred
@not_completed1.toggle_star!
assert @not_completed1.starred?
end
def test_todo_is_not_starred_after_toggle_starred_twice
@not_completed1.toggle_star!
@not_completed1.toggle_star!
assert !@not_completed1.starred?
end
end

358
test/unit/user_test.rb Normal file
View file

@ -0,0 +1,358 @@
require File.dirname(__FILE__) + '/../test_helper'
module Tracks
class Config
def self.auth_schemes
['database', 'ldap']
end
end
end
class SimpleLdapAuthenticator
cattr_accessor :fake_success
def self.valid?(login, pass)
fake_success
end
end
class UserTest < Test::Rails::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
assert_equal ['database', 'ldap'], Tracks::Config.auth_schemes
@admin_user = User.find(1)
@other_user = User.find(2)
end
# Test an admin user model
#
def test_admin
assert_kind_of User, @admin_user
assert_equal 1, @admin_user.id
assert_equal "admin", @admin_user.login
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--abracadabra--")}", @admin_user.crypted_password
assert_not_nil @admin_user.token
assert @admin_user.is_admin
end
# Test a non-admin user model
def test_non_admin
assert_kind_of User, @other_user
assert_equal 2, @other_user.id
assert_equal "jane", @other_user.login
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--sesame--")}", @other_user.crypted_password
assert_not_nil @other_user.token
assert @other_user.is_admin == false || @other_user.is_admin == 0
end
# ============================================
# Validations
# ============================================
# Test a password shorter than 5 characters
#
def test_validate_short_password
assert_no_difference User, :count do
u = create_user :password => generate_random_string(4)
assert_error_on u, :password, "is too short (minimum is 5 characters)"
end
end
def test_validate_long_password
assert_no_difference User, :count do
u = create_user :password => generate_random_string(41)
assert_error_on u, :password, "is too long (maximum is 40 characters)"
end
end
def test_validate_correct_length_password
assert_difference User, :count do
create_user :password => generate_random_string(6)
end
end
def test_validate_missing_password
assert_no_difference User, :count do
u = create_user :password => ''
assert_errors_on u, :password, ["can't be blank", "is too short (minimum is 5 characters)"]
end
end
def test_validate_short_login
assert_no_difference User, :count do
u = create_user :login => 'ba'
assert_error_on u, :login, "is too short (minimum is 3 characters)"
end
end
def test_validate_long_login
assert_no_difference User, :count do
u = create_user :login => generate_random_string(81)
assert_error_on u, :login, "is too long (maximum is 80 characters)"
end
end
def test_validate_correct_length_login
assert_difference User, :count do
create_user :login => generate_random_string(6)
end
end
def test_validate_missing_login
assert_no_difference User, :count do
u = create_user :login => ''
assert_errors_on u, :login, ["can't be blank", "is too short (minimum is 3 characters)"]
end
end
def test_display_name_with_first_and_last_name_set
@other_user.first_name = "Jane"
@other_user.last_name = "Doe"
assert_equal "Jane Doe", @other_user.display_name
end
def test_display_name_with_first_name_set
@other_user.first_name = "Jane"
@other_user.last_name = nil
assert_equal "Jane", @other_user.display_name
end
def test_display_name_with_last_name_set
@other_user.first_name = nil
@other_user.last_name = "Doe"
assert_equal "Doe", @other_user.display_name
end
def test_display_name_with_neither_first_nor_last_name_set
@other_user.first_name = nil
@other_user.last_name = nil
assert_equal @other_user.login, @other_user.display_name
end
def test_prefs_is_short_for_preference
assert_equal @admin_user.preference, @admin_user.prefs
end
def test_to_param_returns_login
assert_equal @admin_user.login, @admin_user.to_param
end
def test_change_password
assert_not_nil User.authenticate(@admin_user.login, "abracadabra")
@admin_user.change_password("foobar", "foobar")
@admin_user.reload
assert_nil User.authenticate(@admin_user.login, "abracadabra")
assert_not_nil User.authenticate(@admin_user.login, "foobar")
end
def test_projects_next_project
moremoney = projects(:moremoney)
next_project = @admin_user.projects.next_from(moremoney)
assert_equal projects(:gardenclean), next_project
end
def test_projects_previous_project
moremoney = projects(:moremoney)
previous_project = @admin_user.projects.previous_from(moremoney)
assert_equal projects(:timemachine), previous_project
end
def test_projects_next_project_nil
gardenclean = projects(:gardenclean)
next_project = @admin_user.projects.next_from(gardenclean)
assert_nil next_project
end
def test_projects_previous_project_nil
timemachine = projects(:timemachine)
previous_project = @admin_user.projects.previous_from(timemachine)
assert_nil previous_project
end
def test_no_users_yet
assert !User.no_users_yet?
User.delete_all
assert User.no_users_yet?
end
def test_generate_token_updates_token
assert_value_changed @admin_user, :token do
@admin_user.send :generate_token
end
end
def test_find_admin
assert_equal @admin_user, User.find_admin
end
def test_validates_auth_type
@other_user.auth_type = 'dnacheck'
assert !@other_user.save
assert_equal 1, @other_user.errors.count
assert_equal "not a valid authentication type (dnacheck)", @other_user.errors.on(:auth_type)
end
def test_authenticate_can_use_ldap
u = @other_user
u.auth_type = 'ldap'
u.save!
SimpleLdapAuthenticator.fake_success = false
assert_nil User.authenticate(u.login, 'foobar')
SimpleLdapAuthenticator.fake_success = true
assert_equal @other_user, User.authenticate(u.login, 'foobar')
end
def test_find_context_by_params
u = @admin_user
c = u.contexts.find_by_params('id' => '1')
assert_equal contexts(:agenda), c
c = u.contexts.find_by_params('context_id' => '1')
assert_equal contexts(:agenda), c
end
def test_find_project_by_params
u = @admin_user
p = u.projects.find_by_params('id' => '1')
assert_equal projects(:timemachine), p
p = u.projects.find_by_params('project_id' => '1')
assert_equal projects(:timemachine), p
end
def test_update_project_positions
assert_equal 1, Project.find(1).position
assert_equal 2, Project.find(2).position
assert_equal 3, Project.find(3).position
@admin_user.projects.update_positions([2,1,3])
assert_equal 2, Project.find(1).position
assert_equal 1, Project.find(2).position
assert_equal 3, Project.find(3).position
end
def test_find_and_activate_deferred_todos_that_are_ready
assert_equal 1, @admin_user.deferred_todos.count
@admin_user.deferred_todos[0].show_from = @admin_user.time.to_date
@admin_user.deferred_todos[0].save
@admin_user.deferred_todos.reload
@admin_user.deferred_todos.find_and_activate_ready
@admin_user.deferred_todos.reload
assert_equal 0, @admin_user.deferred_todos.count
end
def test_completed_todos_completed_within
todos = @admin_user.completed_todos.completed_within(@admin_user.time - 1.day)
assert_equal 3, todos.length
end
def test_completed_todos_complete_more_than
todos = @admin_user.completed_todos.completed_more_than(@admin_user.time - 1.day)
assert_equal 1, todos.length
end
def test_sort_active_projects_alphabetically
u = users(:admin_user)
u.projects.alphabetize(:state => "active")
assert_equal 1, projects(:timemachine).position
assert_equal 2, projects(:gardenclean).position
assert_equal 3, projects(:moremoney).position
end
def test_sort_active_projects_alphabetically_case_insensitive
u = users(:admin_user)
projects(:timemachine).name = projects(:timemachine).name.downcase
projects(:timemachine).save!
u.projects.alphabetize(:state => "active")
assert_equal 1, projects(:timemachine).position
assert_equal 2, projects(:gardenclean).position
assert_equal 3, projects(:moremoney).position
end
def test_should_create_user
assert_difference User, :count do
user = create_user
assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
end
end
def test_should_require_login
assert_no_difference User, :count do
u = create_user(:login => nil)
assert u.errors.on(:login)
end
end
def test_should_require_password
assert_no_difference User, :count do
u = create_user(:password => nil)
assert u.errors.on(:password)
end
end
def test_should_require_password_confirmation
assert_no_difference User, :count do
u = create_user(:password_confirmation => nil)
assert u.errors.on(:password_confirmation)
end
end
def test_should_reset_password
users(:other_user).update_attributes(:password => 'new password', :password_confirmation => 'new password')
assert_equal users(:other_user), User.authenticate('jane', 'new password')
end
def test_should_not_rehash_password
users(:other_user).update_attributes(:login => 'jane2')
assert_equal users(:other_user), User.authenticate('jane2', 'sesame')
end
def test_should_authenticate_user
assert_equal users(:other_user), User.authenticate('jane', 'sesame')
end
def test_should_set_remember_token
users(:other_user).remember_me
assert_not_nil users(:other_user).remember_token
assert_not_nil users(:other_user).remember_token_expires_at
end
def test_should_unset_remember_token
users(:other_user).remember_me
assert_not_nil users(:other_user).remember_token
users(:other_user).forget_me
assert_nil users(:other_user).remember_token
end
def test_normalizes_open_id_url_on_save
['www.johndoe.com', 'WWW.JOHNDOE.COM', 'http://www.johndoe.com/', 'http://www.johndoe.com'].each do |initial|
assert_open_id_url_normalized_on_save initial, 'http://www.johndoe.com'
end
end
def test_normalizes_open_id_url_on_find
u = users(:other_user)
u.open_id_url = 'http://www.johndoe.com'
u.save
['www.johndoe.com', 'WWW.JOHNDOE.COM', 'http://www.johndoe.com/', 'http://www.johndoe.com'].each do |raw_open_id_url|
assert_equal u.id, User.find_by_open_id_url(raw_open_id_url).id
end
end
protected
def create_user(options = {})
options[:password_confirmation] = options[:password] unless options.has_key?(:password_confirmation) || !options.has_key?(:password)
User.create({ :login => 'quire', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
end
def assert_open_id_url_normalized_on_save(initial, expected)
u = users(:other_user)
u.open_id_url = initial
u.save
assert_equal expected, u.open_id_url
end
end

View file

@ -0,0 +1,87 @@
require File.dirname(__FILE__) + '/../test_helper'
class TodosHelperTest < Test::Rails::HelperTestCase
def setup
super
end
include ActionView::Helpers::DateHelper
include ApplicationHelper
include TodosHelper
def user_time
Time.now
end
def format_date(date)
if date
date_format = "%d/%m/%Y"
date.strftime("#{date_format}")
else
''
end
end
def test_show_date_in_past
date = 3.days.ago.to_date
html = show_date(date)
formatted_date = format_date(date)
assert_equal %Q{<a title="#{formatted_date}"><span class="red">Scheduled to show 3 days ago</span></a> }, html
end
def test_show_date_today
date = Time.now.to_date
html = show_date(date)
formatted_date = format_date(date)
assert_equal %Q{<a title="#{formatted_date}"><span class="amber">Show Today</span></a> }, html
end
def test_show_date_tomorrow
date = 1.day.from_now.to_date
html = show_date(date)
formatted_date = format_date(date)
assert_equal %Q{<a title="#{formatted_date}"><span class="amber">Show Tomorrow</span></a> }, html
end
def test_show_date_future
date = 10.days.from_now.to_date
html = show_date(date)
formatted_date = format_date(date)
assert_equal %Q{<a title="#{formatted_date}"><span class="green">Show in 10 days</span></a> }, html
end
def test_remote_star_icon_unstarred
@todo = flexmock(:id => 1, :to_param => 1, :description => 'Get gas', :starred? => false)
assert_remote_star_icon_helper_matches %r{<a href="/todos/1/toggle_star" class="icon star_item" title="star the action 'Get gas'"><img alt="Blank" class="unstarred_todo" src="/images/blank.png[?0-9]*" title="Star action" /></a>}
assert_behavior_registered
end
def test_remote_star_icon_starred
@todo = flexmock(:id => 1, :to_param => 1, :description => 'Get gas', :starred? => true)
assert_remote_star_icon_helper_matches %r{<a href="/todos/1/toggle_star" class="icon star_item" title="star the action 'Get gas'"><img alt="Blank" class="starred_todo" src="/images/blank.png[?0-9]*" title="Star action" /></a>}
assert_behavior_registered
end
def assert_remote_star_icon_helper_matches(regex)
@controller.send :initialise_js_behaviours #simulate before filter
output = remote_star_icon
#puts output
assert output =~ regex
@controller.send :store_js_behaviours #simulate after filter
end
def assert_behavior_registered
behaviors = @controller.session[:js_behaviours]
assert behaviors[:options][:reapply_after_ajax]
assert_equal 1, behaviors[:rules].length
rule = behaviors[:rules][0]
assert_equal ".item-container a.star_item:click", rule[0]
assert_equal "new Ajax.Request(this.href, {asynchronous:true, evalScripts:true, method:'put', parameters:{ _source_view : '' }})\n; return false;",
rule[1]
end
def protect_against_forgery?
false
end
end