Added to todo controller tests to test adding and removing tags from a todo, and also finding todos tagged with a tag.

Also added a Selenium test for finding todos tagged with a tag.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@436 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2007-02-10 19:11:22 +00:00
parent 08290efdf5
commit da7408387d
5 changed files with 41 additions and 27 deletions

View file

@ -97,22 +97,32 @@ class TodosControllerTest < Test::Unit::TestCase
def test_update_todo
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
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"
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).to_time.utc.to_date
actual = t.due
assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
end
# def test_tag
# @request.session['user_id'] = users(:admin_user).id
# @user = User.find(@request.session['user_id'])
# @tagged = Todo.find_tagged_with('foo', @user).size
# get :tag, :id => 'foo'
# assert_response :success
# assert_equal 2, @tagged
# end
def test_update_todo_tags_to_none
t = Todo.find(1)
@request.session['user_id'] = users(:admin_user).id
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_find_tagged_with
@request.session['user_id'] = users(:admin_user).id
@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 2, @tagged
end
end

View file

@ -0,0 +1,6 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
open "/todos/tag/foo"
wait_for_element_present "xpath=//div[@id='t'] //h2"
assert_not_visible "t_empty-nd"
assert_text 'badge_count', '2'