mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-19 16:50:12 +01:00
fix tags and fix tests
This commit is contained in:
parent
c618d35d3a
commit
0e68ded56a
8 changed files with 856 additions and 836 deletions
|
|
@ -362,7 +362,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def starred?
|
def starred?
|
||||||
tags.any? {|tag| tag.name == Todo::STARRED_TAG_NAME}
|
tags.any? {|tag| tag.name == Todo::STARRED_TAG_NAME }
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_due_date(previous)
|
def get_due_date(previous)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
class Tag < ActiveRecord::Base
|
class Tag < ActiveRecord::Base
|
||||||
|
|
||||||
DELIMITER = "," # Controls how to split and join tagnames from strings. You may need to change the <tt>validates_format_of parameters</tt> if you change this.
|
DELIMITER = "," # Controls how to split and join tagnames from strings. You may need to change the <tt>validates_format_of parameters</tt> if you change this.
|
||||||
|
JOIN_DELIMITER = ", "
|
||||||
|
|
||||||
# If database speed becomes an issue, you could remove these validations and
|
# If database speed becomes an issue, you could remove these validations and
|
||||||
# rescue the ActiveRecord database constraint errors instead.
|
# rescue the ActiveRecord database constraint errors instead.
|
||||||
|
|
@ -12,7 +13,7 @@ class Tag < ActiveRecord::Base
|
||||||
validates_uniqueness_of :name, :case_sensitive => false
|
validates_uniqueness_of :name, :case_sensitive => false
|
||||||
|
|
||||||
# Change this validation if you need more complex tag names.
|
# Change this validation if you need more complex tag names.
|
||||||
validates_format_of :name, :with => /^[a-zA-Z0-9\_\-]+$/, :message => "can not contain special characters"
|
# validates_format_of :name, :with => /^[a-zA-Z0-9\_\-]+$/, :message => "can not contain special characters"
|
||||||
|
|
||||||
# Set up the polymorphic relationship.
|
# Set up the polymorphic relationship.
|
||||||
has_many_polymorphs :taggables,
|
has_many_polymorphs :taggables,
|
||||||
|
|
@ -24,7 +25,7 @@ class Tag < ActiveRecord::Base
|
||||||
# Defined on the taggable models, not on Tag itself. Return the tagnames
|
# Defined on the taggable models, not on Tag itself. Return the tagnames
|
||||||
# associated with this record as a string.
|
# associated with this record as a string.
|
||||||
def to_s
|
def to_s
|
||||||
self.map(&:name).sort.join(Tag::DELIMITER)
|
self.map(&:name).sort.join(Tag::JOIN_DELIMITER)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ class Tagging < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :tag
|
belongs_to :tag
|
||||||
belongs_to :taggable, :polymorphic => true
|
belongs_to :taggable, :polymorphic => true
|
||||||
belongs_to :user
|
# belongs_to :user
|
||||||
|
|
||||||
# If you also need to use <tt>acts_as_list</tt>, you will have to manage the tagging positions manually by creating decorated join records when you associate Tags with taggables.
|
# If you also need to use <tt>acts_as_list</tt>, you will have to manage the tagging positions manually by creating decorated join records when you associate Tags with taggables.
|
||||||
# acts_as_list :scope => :taggable
|
# acts_as_list :scope => :taggable
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ class ActiveRecord::Base #:nodoc:
|
||||||
when Array
|
when Array
|
||||||
obj.map! do |item|
|
obj.map! do |item|
|
||||||
case item
|
case item
|
||||||
when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot.
|
# removed next line: its prevents adding numbers as tags
|
||||||
|
# when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot.
|
||||||
when Tag then item.name
|
when Tag then item.name
|
||||||
when String then item
|
when String then item
|
||||||
else
|
else
|
||||||
|
|
@ -78,7 +79,6 @@ class ActiveRecord::Base #:nodoc:
|
||||||
when String
|
when String
|
||||||
obj = obj.split(Tag::DELIMITER).map do |tag_name|
|
obj = obj.split(Tag::DELIMITER).map do |tag_name|
|
||||||
tag_name.strip.squeeze(" ")
|
tag_name.strip.squeeze(" ")
|
||||||
puts "tn=#{tag_name.strip.squeeze(" ")}"
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise "Invalid object of class #{obj.class} as tagging method parameter"
|
raise "Invalid object of class #{obj.class} as tagging method parameter"
|
||||||
|
|
|
||||||
|
|
@ -223,8 +223,8 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
u = users(:admin_user)
|
u = users(:admin_user)
|
||||||
post :actionize, :state => "active", :format => 'js'
|
post :actionize, :state => "active", :format => 'js'
|
||||||
assert_equal 2, projects(:gardenclean).position
|
assert_equal 1, projects(:gardenclean).position
|
||||||
assert_equal 1, projects(:moremoney).position
|
assert_equal 2, projects(:moremoney).position
|
||||||
assert_equal 3, projects(:timemachine).position
|
assert_equal 3, projects(:timemachine).position
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ class TodosControllerTest < Test::Rails::TestCase
|
||||||
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)
|
t = Todo.find(1)
|
||||||
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
|
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
|
||||||
assert_equal "foo, bar", t.tag_list
|
assert_equal "bar, foo", t.tag_list
|
||||||
expected = Date.new(2006,11,30)
|
expected = Date.new(2006,11,30)
|
||||||
actual = t.due.to_date
|
actual = t.due.to_date
|
||||||
assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
|
assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
|
||||||
|
|
@ -163,7 +163,7 @@ class TodosControllerTest < Test::Rails::TestCase
|
||||||
taglist = " one , two,three ,four, 8.1.2, version1.5"
|
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
|
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)
|
t = Todo.find(1)
|
||||||
assert_equal "one, two, three, four, 8.1.2, version1.5", t.tag_list
|
assert_equal "8.1.2, four, one, three, two, version1.5", t.tag_list
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_tagged_with
|
def test_find_tagged_with
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ login :as => 'admin'
|
||||||
open '/m'
|
open '/m'
|
||||||
wait_for_text 'css=h1 span.count', '11'
|
wait_for_text 'css=h1 span.count', '11'
|
||||||
|
|
||||||
click_and_wait "link=0-Add new action"
|
click_and_wait "link=0-New action"
|
||||||
|
|
||||||
type "todo_notes", "test notes"
|
type "todo_notes", "test notes"
|
||||||
type "todo_description", "test name"
|
type "todo_description", "test name"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,26 @@ class TagTest < Test::Rails::TestCase
|
||||||
fixtures :tags
|
fixtures :tags
|
||||||
|
|
||||||
# Replace this with your real tests.
|
# Replace this with your real tests.
|
||||||
def test_truth
|
def test_find_or_create_with_single_word
|
||||||
assert true
|
tag = Tag.find_or_create_by_name("test")
|
||||||
|
assert !tag.new_record?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_or_create_with_space
|
||||||
|
tag = Tag.find_or_create_by_name("test test")
|
||||||
|
assert !tag.new_record?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_or_create_with_dot
|
||||||
|
tag = Tag.find_or_create_by_name("a.b.c")
|
||||||
|
assert !tag.new_record?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_or_create_with_number_as_string
|
||||||
|
tag = Tag.find_or_create_by_name("12343")
|
||||||
|
assert !tag.new_record?
|
||||||
|
|
||||||
|
tag = Tag.find_or_create_by_name("8.1.2")
|
||||||
|
assert !tag.new_record?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue