diff --git a/tracks/app/models/tag.rb b/tracks/app/models/tag.rb index 009c8f0b..d3105eeb 100644 --- a/tracks/app/models/tag.rb +++ b/tracks/app/models/tag.rb @@ -7,5 +7,5 @@ class Tag < ActiveRecord::Base def on(taggable, user) tagging = taggings.create :taggable => taggable, :user => user end - + end \ No newline at end of file diff --git a/tracks/db/schema.rb b/tracks/db/schema.rb index 5afc62ac..a937bdbb 100644 --- a/tracks/db/schema.rb +++ b/tracks/db/schema.rb @@ -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 diff --git a/tracks/lib/activerecord_base_tag_extensions.rb b/tracks/lib/activerecord_base_tag_extensions.rb index 8c068190..b3443cbc 100644 --- a/tracks/lib/activerecord_base_tag_extensions.rb +++ b/tracks/lib/activerecord_base_tag_extensions.rb @@ -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 diff --git a/tracks/test/functional/todos_controller_test.rb b/tracks/test/functional/todos_controller_test.rb index a1473ad6..0a3ac54c 100644 --- a/tracks/test/functional/todos_controller_test.rb +++ b/tracks/test/functional/todos_controller_test.rb @@ -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 diff --git a/tracks/test/selenium/tags/find_tagged.rsel b/tracks/test/selenium/tags/find_tagged.rsel new file mode 100644 index 00000000..ee7d1445 --- /dev/null +++ b/tracks/test/selenium/tags/find_tagged.rsel @@ -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' \ No newline at end of file