rotuka-taggable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +167 -0
- data/MIT-LICENSE +20 -0
- data/README +146 -0
- data/Rakefile +22 -0
- data/generators/tags/USAGE +1 -0
- data/generators/tags/tags_generator.rb +14 -0
- data/generators/tags/templates/migration.rb +26 -0
- data/generators/tags/templates/tag.rb +26 -0
- data/generators/tags/templates/tagging.rb +12 -0
- data/generators/tags/templates/tags_helper.rb +13 -0
- data/init.rb +1 -0
- data/lib/tag_list.rb +91 -0
- data/lib/taggable.rb +215 -0
- data/test/abstract_unit.rb +97 -0
- data/test/acts_as_taggable_test.rb +347 -0
- data/test/database.yml +10 -0
- data/test/fixtures/magazine.rb +3 -0
- data/test/fixtures/magazines.yml +7 -0
- data/test/fixtures/photo.rb +8 -0
- data/test/fixtures/photos.yml +24 -0
- data/test/fixtures/post.rb +7 -0
- data/test/fixtures/posts.yml +34 -0
- data/test/fixtures/special_post.rb +2 -0
- data/test/fixtures/subscription.rb +4 -0
- data/test/fixtures/subscriptions.yml +3 -0
- data/test/fixtures/taggings.yml +149 -0
- data/test/fixtures/tags.yml +19 -0
- data/test/fixtures/user.rb +7 -0
- data/test/fixtures/users.yml +7 -0
- data/test/schema.rb +37 -0
- data/test/tag_list_test.rb +106 -0
- data/test/tag_test.rb +34 -0
- data/test/tagging_test.rb +13 -0
- data/test/tags_helper_test.rb +28 -0
- metadata +87 -0
data/test/database.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
jonathan_dog:
|
2
|
+
id: 1
|
3
|
+
user_id: 1
|
4
|
+
title: A small dog
|
5
|
+
|
6
|
+
jonathan_questioning_dog:
|
7
|
+
id: 2
|
8
|
+
user_id: 1
|
9
|
+
title: What does this dog want?
|
10
|
+
|
11
|
+
jonathan_bad_cat:
|
12
|
+
id: 3
|
13
|
+
user_id: 1
|
14
|
+
title: Bad cat
|
15
|
+
|
16
|
+
sam_flower:
|
17
|
+
id: 4
|
18
|
+
user_id: 2
|
19
|
+
title: Flower
|
20
|
+
|
21
|
+
sam_sky:
|
22
|
+
id: 5
|
23
|
+
user_id: 2
|
24
|
+
title: Sky
|
@@ -0,0 +1,34 @@
|
|
1
|
+
jonathan_sky:
|
2
|
+
id: 1
|
3
|
+
user_id: 1
|
4
|
+
text: The sky is particularly blue today
|
5
|
+
|
6
|
+
jonathan_grass:
|
7
|
+
id: 2
|
8
|
+
user_id: 1
|
9
|
+
text: The grass seems very green
|
10
|
+
|
11
|
+
jonathan_rain:
|
12
|
+
id: 3
|
13
|
+
user_id: 1
|
14
|
+
text: Why does the rain fall?
|
15
|
+
|
16
|
+
jonathan_cloudy:
|
17
|
+
id: 4
|
18
|
+
user_id: 1
|
19
|
+
text: Is it cloudy?
|
20
|
+
|
21
|
+
jonathan_still_cloudy:
|
22
|
+
id: 5
|
23
|
+
user_id: 1
|
24
|
+
text: Is it still cloudy?
|
25
|
+
|
26
|
+
sam_ground:
|
27
|
+
id: 6
|
28
|
+
user_id: 2
|
29
|
+
text: The ground is looking too brown
|
30
|
+
|
31
|
+
sam_flowers:
|
32
|
+
id: 7
|
33
|
+
user_id: 2
|
34
|
+
text: Why are the flowers dead?
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# Posts
|
2
|
+
jonathan_sky_good:
|
3
|
+
id: 1
|
4
|
+
tag_id: 1
|
5
|
+
taggable_id: 1
|
6
|
+
taggable_type: Post
|
7
|
+
created_at: 2006-08-01
|
8
|
+
|
9
|
+
jonathan_sky_nature:
|
10
|
+
id: 2
|
11
|
+
tag_id: 3
|
12
|
+
taggable_id: 1
|
13
|
+
taggable_type: Post
|
14
|
+
created_at: 2006-08-02
|
15
|
+
|
16
|
+
jonathan_grass_nature:
|
17
|
+
id: 3
|
18
|
+
tag_id: 3
|
19
|
+
taggable_id: 2
|
20
|
+
taggable_type: Post
|
21
|
+
created_at: 2006-08-03
|
22
|
+
|
23
|
+
jonathan_rain_question:
|
24
|
+
id: 4
|
25
|
+
tag_id: 4
|
26
|
+
taggable_id: 3
|
27
|
+
taggable_type: Post
|
28
|
+
created_at: 2006-08-04
|
29
|
+
|
30
|
+
jonathan_rain_nature:
|
31
|
+
id: 5
|
32
|
+
tag_id: 3
|
33
|
+
taggable_id: 3
|
34
|
+
taggable_type: Post
|
35
|
+
created_at: 2006-08-05
|
36
|
+
|
37
|
+
jonathan_cloudy_nature:
|
38
|
+
id: 6
|
39
|
+
tag_id: 3
|
40
|
+
taggable_id: 4
|
41
|
+
taggable_type: Post
|
42
|
+
created_at: 2006-08-06
|
43
|
+
|
44
|
+
jonathan_still_cloudy_nature:
|
45
|
+
id: 7
|
46
|
+
tag_id: 3
|
47
|
+
taggable_id: 5
|
48
|
+
taggable_type: Post
|
49
|
+
created_at: 2006-08-07
|
50
|
+
|
51
|
+
sam_ground_nature:
|
52
|
+
id: 8
|
53
|
+
tag_id: 3
|
54
|
+
taggable_id: 6
|
55
|
+
taggable_type: Post
|
56
|
+
created_at: 2006-08-08
|
57
|
+
|
58
|
+
sam_ground_bad:
|
59
|
+
id: 9
|
60
|
+
tag_id: 2
|
61
|
+
taggable_id: 6
|
62
|
+
taggable_type: Post
|
63
|
+
created_at: 2006-08-09
|
64
|
+
|
65
|
+
sam_flowers_good:
|
66
|
+
id: 10
|
67
|
+
tag_id: 1
|
68
|
+
taggable_id: 7
|
69
|
+
taggable_type: Post
|
70
|
+
created_at: 2006-08-10
|
71
|
+
|
72
|
+
sam_flowers_nature:
|
73
|
+
id: 11
|
74
|
+
tag_id: 3
|
75
|
+
taggable_id: 7
|
76
|
+
taggable_type: Post
|
77
|
+
created_at: 2006-08-11
|
78
|
+
|
79
|
+
# Photos
|
80
|
+
jonathan_dog_animal:
|
81
|
+
id: 12
|
82
|
+
tag_id: 5
|
83
|
+
taggable_id: 1
|
84
|
+
taggable_type: Photo
|
85
|
+
created_at: 2006-08-12
|
86
|
+
|
87
|
+
jonathan_dog_nature:
|
88
|
+
id: 13
|
89
|
+
tag_id: 3
|
90
|
+
taggable_id: 1
|
91
|
+
taggable_type: Photo
|
92
|
+
created_at: 2006-08-13
|
93
|
+
|
94
|
+
jonathan_questioning_dog_animal:
|
95
|
+
id: 14
|
96
|
+
tag_id: 5
|
97
|
+
taggable_id: 2
|
98
|
+
taggable_type: Photo
|
99
|
+
created_at: 2006-08-14
|
100
|
+
|
101
|
+
jonathan_questioning_dog_question:
|
102
|
+
id: 15
|
103
|
+
tag_id: 4
|
104
|
+
taggable_id: 2
|
105
|
+
taggable_type: Photo
|
106
|
+
created_at: 2006-08-15
|
107
|
+
|
108
|
+
jonathan_bad_cat_bad:
|
109
|
+
id: 16
|
110
|
+
tag_id: 2
|
111
|
+
taggable_id: 3
|
112
|
+
taggable_type: Photo
|
113
|
+
created_at: 2006-08-16
|
114
|
+
|
115
|
+
jonathan_bad_cat_animal:
|
116
|
+
id: 17
|
117
|
+
tag_id: 5
|
118
|
+
taggable_id: 3
|
119
|
+
taggable_type: Photo
|
120
|
+
created_at: 2006-08-17
|
121
|
+
|
122
|
+
sam_flower_nature:
|
123
|
+
id: 18
|
124
|
+
tag_id: 3
|
125
|
+
taggable_id: 4
|
126
|
+
taggable_type: Photo
|
127
|
+
created_at: 2006-08-18
|
128
|
+
|
129
|
+
sam_flower_good:
|
130
|
+
id: 19
|
131
|
+
tag_id: 1
|
132
|
+
taggable_id: 4
|
133
|
+
taggable_type: Photo
|
134
|
+
created_at: 2006-08-19
|
135
|
+
|
136
|
+
sam_sky_nature:
|
137
|
+
id: 20
|
138
|
+
tag_id: 3
|
139
|
+
taggable_id: 5
|
140
|
+
taggable_type: Photo
|
141
|
+
created_at: 2006-08-20
|
142
|
+
|
143
|
+
# Magazines
|
144
|
+
ruby_good:
|
145
|
+
id: 50
|
146
|
+
tag_id: 1
|
147
|
+
taggable_id: 1
|
148
|
+
taggable_type: Magazine
|
149
|
+
created_at: 2007-08-25
|
data/test/schema.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
create_table :tags, :force => true do |t|
|
3
|
+
t.column :name, :string
|
4
|
+
end
|
5
|
+
|
6
|
+
create_table :taggings, :force => true do |t|
|
7
|
+
t.column :tag_id, :integer
|
8
|
+
t.column :taggable_id, :integer
|
9
|
+
t.column :taggable_type, :string
|
10
|
+
t.column :created_at, :datetime
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :users, :force => true do |t|
|
14
|
+
t.column :name, :string
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :posts, :force => true do |t|
|
18
|
+
t.column :text, :text
|
19
|
+
t.column :cached_tag_list, :string
|
20
|
+
t.column :user_id, :integer
|
21
|
+
t.column :type, :string
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table :photos, :force => true do |t|
|
25
|
+
t.column :title, :string
|
26
|
+
t.column :user_id, :integer
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :subscriptions, :force => true do |t|
|
30
|
+
t.column :user_id, :integer
|
31
|
+
t.column :magazine_id, :integer
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :magazines, :force => true do |t|
|
35
|
+
t.column :name, :string
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
|
3
|
+
class TagListTest < Test::Unit::TestCase
|
4
|
+
def test_from_leaves_string_unchanged
|
5
|
+
tags = '"One ", Two'
|
6
|
+
original = tags.dup
|
7
|
+
TagList.from(tags)
|
8
|
+
assert_equal tags, original
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_from_single_name
|
12
|
+
assert_equal %w(Fun), TagList.from("Fun")
|
13
|
+
assert_equal %w(Fun), TagList.from('"Fun"')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_from_blank
|
17
|
+
assert_equal [], TagList.from(nil)
|
18
|
+
assert_equal [], TagList.from("")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_from_single_quoted_tag
|
22
|
+
assert_equal ['with, comma'], TagList.from('"with, comma"')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_spaces_do_not_delineate
|
26
|
+
assert_equal ['A B', 'C'], TagList.from('A B, C')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_from_multiple_tags
|
30
|
+
assert_equivalent %w(Alpha Beta Delta Gamma), TagList.from("Alpha, Beta, Delta, Gamma")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_from_multiple_tags_with_quotes
|
34
|
+
assert_equivalent %w(Alpha Beta Delta Gamma), TagList.from('Alpha, "Beta", Gamma , "Delta"')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_from_with_single_quotes
|
38
|
+
assert_equivalent ['A B', 'C'], TagList.from("'A B', C")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_from_multiple_tags_with_quote_and_commas
|
42
|
+
assert_equivalent ['Alpha, Beta', 'Delta', 'Gamma, something'], TagList.from('"Alpha, Beta", Delta, "Gamma, something"')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_from_removes_white_space
|
46
|
+
assert_equivalent %w(Alpha Beta), TagList.from('" Alpha ", "Beta "')
|
47
|
+
assert_equivalent %w(Alpha Beta), TagList.from(' Alpha, Beta ')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_from_removes_dots
|
51
|
+
assert_equivalent %w(Alpha Beta), TagList.from('Alpha., Beta')
|
52
|
+
assert_equivalent %w(Alpha Beta), TagList.from('Alpha, Be.ta')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_alternative_delimiter
|
56
|
+
TagList.delimiter = " "
|
57
|
+
|
58
|
+
assert_equal %w(One Two), TagList.from("One Two")
|
59
|
+
assert_equal ['One two', 'three', 'four'], TagList.from('"One two" three four')
|
60
|
+
ensure
|
61
|
+
TagList.delimiter = ","
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_duplicate_tags_removed
|
65
|
+
assert_equal %w(One), TagList.from("One, One")
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_to_s_with_commas
|
69
|
+
assert_equal "Question, Crazy Animal", TagList.new("Question", "Crazy Animal").to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_to_s_with_alternative_delimiter
|
73
|
+
TagList.delimiter = " "
|
74
|
+
|
75
|
+
assert_equal '"Crazy Animal" Question', TagList.new("Crazy Animal", "Question").to_s
|
76
|
+
ensure
|
77
|
+
TagList.delimiter = ","
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_add
|
81
|
+
tag_list = TagList.new("One")
|
82
|
+
assert_equal %w(One), tag_list
|
83
|
+
|
84
|
+
assert_equal %w(One Two), tag_list.add("Two")
|
85
|
+
assert_equal %w(One Two Three), tag_list.add(["Three"])
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_remove
|
89
|
+
tag_list = TagList.new("One", "Two")
|
90
|
+
assert_equal %w(Two), tag_list.remove("One")
|
91
|
+
assert_equal %w(), tag_list.remove(["Two"])
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_new_with_parsing
|
95
|
+
assert_equal %w(One Two), TagList.new("One, Two", :parse => true)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_add_with_parsing
|
99
|
+
assert_equal %w(One Two), TagList.new.add("One, Two", :parse => true)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_remove_with_parsing
|
103
|
+
tag_list = TagList.from("Three, Four, Five")
|
104
|
+
assert_equal %w(Four), tag_list.remove("Three, Five", :parse => true)
|
105
|
+
end
|
106
|
+
end
|