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

@ -7,5 +7,5 @@ class Tag < ActiveRecord::Base
def on(taggable, user)
tagging = taggings.create :taggable => taggable, :user => user
end
end

View file

@ -5,15 +5,14 @@
ActiveRecord::Schema.define(:version => 27) do
create_table "contexts", :force => true do |t|
t.column "name", :string, :default => "", :null => false
t.column "hide", :integer, :limit => 4, :default => 0, :null => false
t.column "position", :integer, :default => 0, :null => false
t.column "user_id", :integer, :default => 0, :null => false
t.column "name", :string, :default => "", :null => false
t.column "position", :integer, :default => 0, :null => false
t.column "hide", :boolean, :default => false
t.column "user_id", :integer, :default => 1
t.column "created_at", :datetime
t.column "updated_at", :datetime
end
add_index "contexts", ["user_id"], :name => "index_contexts_on_user_id"
add_index "contexts", ["user_id", "name"], :name => "index_contexts_on_user_id_and_name"
create_table "notes", :force => true do |t|
@ -64,14 +63,13 @@ ActiveRecord::Schema.define(:version => 27) do
create_table "projects", :force => true do |t|
t.column "name", :string, :default => "", :null => false
t.column "position", :integer, :default => 0, :null => false
t.column "user_id", :integer, :default => 0, :null => false
t.column "user_id", :integer, :default => 1
t.column "description", :text
t.column "state", :string, :limit => 20, :default => "active", :null => false
t.column "created_at", :datetime
t.column "updated_at", :datetime
end
add_index "projects", ["user_id"], :name => "index_projects_on_user_id"
add_index "projects", ["user_id", "name"], :name => "index_projects_on_user_id_and_name"
create_table "sessions", :force => true do |t|
@ -100,16 +98,16 @@ ActiveRecord::Schema.define(:version => 27) do
add_index "tags", ["name"], :name => "index_tags_on_name"
create_table "todos", :force => true do |t|
t.column "context_id", :integer, :default => 0, :null => false
t.column "description", :string, :limit => 100, :default => "", :null => false
t.column "context_id", :integer, :default => 0, :null => false
t.column "project_id", :integer
t.column "description", :string, :default => "", :null => false
t.column "notes", :text
t.column "created_at", :datetime
t.column "due", :date
t.column "completed_at", :datetime
t.column "project_id", :integer
t.column "user_id", :integer, :default => 0, :null => false
t.column "user_id", :integer, :default => 1
t.column "show_from", :date
t.column "state", :string, :limit => 20, :default => "immediate", :null => false
t.column "state", :string, :limit => 20, :default => "immediate", :null => false
end
add_index "todos", ["user_id", "state"], :name => "index_todos_on_user_id_and_state"
@ -119,10 +117,10 @@ ActiveRecord::Schema.define(:version => 27) do
add_index "todos", ["user_id", "context_id"], :name => "index_todos_on_user_id_and_context_id"
create_table "users", :force => true do |t|
t.column "login", :string, :limit => 80
t.column "password", :string, :limit => 40
t.column "login", :string, :limit => 80, :default => "", :null => false
t.column "password", :string, :limit => 40, :default => "", :null => false
t.column "word", :string
t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false
t.column "is_admin", :boolean, :default => false, :null => false
t.column "first_name", :string
t.column "last_name", :string
t.column "auth_type", :string, :default => "database", :null => false

View file

@ -7,7 +7,7 @@ class ActiveRecord::Base
# If you submit an empty tags text field, all the tags are removed.
def tag_with(tags, user)
Tag.transaction do
Tagging.delete_all(" taggable_id = #{self.id} and taggable_type = '#{self.class}' and user_id = #{user.id}")
Tagging.delete_all("taggable_id = #{self.id} and taggable_type = '#{self.class}' and user_id = #{user.id}")
tags.downcase.split(", ").each do |tag|
Tag.find_or_create_by_name(tag).on(self, user)
end
@ -19,7 +19,7 @@ class ActiveRecord::Base
end
def delete_tags tag_string
split = tag_string.downcase.split(" ")
split = tag_string.downcase.split(", ")
tags.delete tags.select{|t| split.include? t.name}
end

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'