bborn-acts_as_taggable_on_steroids 2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +212 -0
- data/MIT-LICENSE +20 -0
- data/README +157 -0
- data/Rakefile +22 -0
- data/acts_as_taggable_on_steroids.gemspec +54 -0
- data/init.rb +1 -0
- data/lib/acts_as_taggable.rb +246 -0
- data/lib/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb +24 -0
- data/lib/generators/acts_as_taggable_migration/templates/migration.rb +22 -0
- data/lib/tag.rb +59 -0
- data/lib/tag_list.rb +109 -0
- data/lib/tagging.rb +16 -0
- data/lib/tags_helper.rb +13 -0
- data/test/abstract_unit.rb +106 -0
- data/test/acts_as_taggable_test.rb +384 -0
- data/test/database.yml +11 -0
- data/test/fixtures/magazine.rb +3 -0
- data/test/fixtures/magazines.yml +5 -0
- data/test/fixtures/photo.rb +8 -0
- data/test/fixtures/photos.yml +19 -0
- data/test/fixtures/post.rb +7 -0
- data/test/fixtures/posts.yml +27 -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 +107 -0
- data/test/fixtures/tags.yml +14 -0
- data/test/fixtures/user.rb +7 -0
- data/test/fixtures/users.yml +5 -0
- data/test/schema.rb +48 -0
- data/test/tag_list_test.rb +119 -0
- data/test/tag_test.rb +63 -0
- data/test/tagging_test.rb +11 -0
- data/test/tags_helper_test.rb +25 -0
- metadata +104 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TagListTest < ActiveSupport::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_with_inner_quotes
|
46
|
+
assert_equivalent ["House", "Drum 'n' Bass", "Trance"], TagList.from("House, Drum 'n' Bass, Trance")
|
47
|
+
assert_equivalent ["House", "Drum'n'Bass", "Trance"], TagList.from("House, Drum'n'Bass, Trance")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_from_removes_white_space
|
51
|
+
assert_equivalent %w(Alpha Beta), TagList.from('" Alpha ", "Beta "')
|
52
|
+
assert_equivalent %w(Alpha Beta), TagList.from(' Alpha, Beta ')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_from_and_new_treat_both_accept_arrays
|
56
|
+
tags = ["One", "Two"]
|
57
|
+
|
58
|
+
assert_equal TagList.from(tags), TagList.new(tags)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_alternative_delimiter
|
62
|
+
TagList.delimiter = " "
|
63
|
+
|
64
|
+
assert_equal %w(One Two), TagList.from("One Two")
|
65
|
+
assert_equal ['One two', 'three', 'four'], TagList.from('"One two" three four')
|
66
|
+
ensure
|
67
|
+
TagList.delimiter = ","
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_duplicate_tags_removed
|
71
|
+
assert_equal %w(One), TagList.from("One, One")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_to_s_with_commas
|
75
|
+
assert_equal "Question, Crazy Animal", TagList.new("Question", "Crazy Animal").to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_to_s_with_alternative_delimiter
|
79
|
+
TagList.delimiter = " "
|
80
|
+
|
81
|
+
assert_equal '"Crazy Animal" Question', TagList.new("Crazy Animal", "Question").to_s
|
82
|
+
ensure
|
83
|
+
TagList.delimiter = ","
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_add
|
87
|
+
tag_list = TagList.new("One")
|
88
|
+
assert_equal %w(One), tag_list
|
89
|
+
|
90
|
+
assert_equal %w(One Two), tag_list.add("Two")
|
91
|
+
assert_equal %w(One Two Three), tag_list.add(["Three"])
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_remove
|
95
|
+
tag_list = TagList.new("One", "Two")
|
96
|
+
assert_equal %w(Two), tag_list.remove("One")
|
97
|
+
assert_equal %w(), tag_list.remove(["Two"])
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_new_with_parsing
|
101
|
+
assert_equal %w(One Two), TagList.new("One, Two", :parse => true)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_add_with_parsing
|
105
|
+
assert_equal %w(One Two), TagList.new.add("One, Two", :parse => true)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_remove_with_parsing
|
109
|
+
tag_list = TagList.from("Three, Four, Five")
|
110
|
+
assert_equal %w(Four), tag_list.remove("Three, Five", :parse => true)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_toggle
|
114
|
+
tag_list = TagList.new("One", "Two")
|
115
|
+
assert_equal %w(One Three), tag_list.toggle("Two", "Three")
|
116
|
+
assert_equal %w(), tag_list.toggle("One", "Three")
|
117
|
+
assert_equal %w(Four), tag_list.toggle("Four")
|
118
|
+
end
|
119
|
+
end
|
data/test/tag_test.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TagTest < ActiveSupport::TestCase
|
4
|
+
def test_name_required
|
5
|
+
t = Tag.create
|
6
|
+
assert_match /blank/, t.errors[:name].to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_name_unique
|
10
|
+
t = Tag.create!(:name => "My tag")
|
11
|
+
duplicate = t.clone
|
12
|
+
|
13
|
+
assert !duplicate.save
|
14
|
+
assert_match /taken/, duplicate.errors[:name].to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_taggings
|
18
|
+
assert_equivalent [taggings(:jonathan_sky_good), taggings(:sam_flowers_good), taggings(:sam_flower_good), taggings(:ruby_good)], tags(:good).taggings
|
19
|
+
assert_equivalent [taggings(:sam_ground_bad), taggings(:jonathan_bad_cat_bad)], tags(:bad).taggings
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_to_s
|
23
|
+
assert_equal tags(:good).name, tags(:good).to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_equality
|
27
|
+
assert_equal tags(:good), tags(:good)
|
28
|
+
assert_equal Tag.find(tags(:good).id), Tag.find(tags(:good).id)
|
29
|
+
assert_equal Tag.new(:name => 'A'), Tag.new(:name => 'A')
|
30
|
+
assert_not_equal Tag.new(:name => 'A'), Tag.new(:name => 'B')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_taggings_removed_when_tag_destroyed
|
34
|
+
assert_difference "Tagging.count", -Tagging.count(:conditions => { :tag_id => tags(:good).id }) do
|
35
|
+
assert tags(:good).destroy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_all_counts
|
40
|
+
assert_tag_counts(Tag.counts,
|
41
|
+
{:good => 4, :bad => 2, :nature => 10, :question => 2, :animal => 3})
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_all_counts_with_string_conditions
|
45
|
+
assert_tag_counts Tag.counts(:conditions => 'taggings.created_at >= \'2006-08-15\''),
|
46
|
+
:question => 1, :bad => 1, :animal => 1, :nature => 2, :good => 2
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_all_counts_with_array_conditions
|
50
|
+
assert_tag_counts Tag.counts(:conditions => ['taggings.created_at >= ?', '2006-08-15']),
|
51
|
+
:question => 1, :bad => 1, :animal => 1, :nature => 2, :good => 2
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_all_counts_with_hash_conditions
|
55
|
+
tag_counts = Tag.counts(
|
56
|
+
:conditions => {
|
57
|
+
:taggings => { :created_at => (DateTime.parse('2006-08-14 23:59') .. DateTime.parse('4000-01-01')) }
|
58
|
+
}
|
59
|
+
)
|
60
|
+
|
61
|
+
assert_tag_counts tag_counts, :question => 1, :bad => 1, :animal => 1, :nature => 2, :good => 2
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TaggingTest < ActiveSupport::TestCase
|
4
|
+
def test_tag
|
5
|
+
assert_equal tags(:good), taggings(:jonathan_sky_good).tag
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_taggable
|
9
|
+
assert_equal posts(:jonathan_sky), taggings(:jonathan_sky_good).taggable
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TagsHelperTest < ActiveSupport::TestCase
|
4
|
+
include TagsHelper
|
5
|
+
|
6
|
+
def test_tag_cloud
|
7
|
+
cloud_elements = []
|
8
|
+
|
9
|
+
tag_cloud Post.tag_counts, %w(css1 css2 css3 css4) do |tag, css_class|
|
10
|
+
cloud_elements << [tag, css_class]
|
11
|
+
end
|
12
|
+
|
13
|
+
assert cloud_elements.include?([tags(:good), "css2"])
|
14
|
+
assert cloud_elements.include?([tags(:bad), "css1"])
|
15
|
+
assert cloud_elements.include?([tags(:nature), "css4"])
|
16
|
+
assert cloud_elements.include?([tags(:question), "css1"])
|
17
|
+
assert_equal 4, cloud_elements.size
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_tag_cloud_when_no_tags
|
21
|
+
tag_cloud SpecialPost.tag_counts, %w(css1) do
|
22
|
+
assert false, "tag_cloud should not yield"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bborn-acts_as_taggable_on_steroids
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.beta2
|
5
|
+
prerelease: 4
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Viney
|
9
|
+
- Julien Portalier
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-02-07 00:00:00.000000000Z
|
14
|
+
dependencies: []
|
15
|
+
description: Rails plugin that is based on acts_as_taggable by jviney that is based
|
16
|
+
on acts_as_taggable by DHH.
|
17
|
+
email: ysbaddaden@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- acts_as_taggable_on_steroids.gemspec
|
23
|
+
- CHANGELOG
|
24
|
+
- init.rb
|
25
|
+
- lib/acts_as_taggable.rb
|
26
|
+
- lib/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb
|
27
|
+
- lib/generators/acts_as_taggable_migration/templates/migration.rb
|
28
|
+
- lib/tag.rb
|
29
|
+
- lib/tag_list.rb
|
30
|
+
- lib/tagging.rb
|
31
|
+
- lib/tags_helper.rb
|
32
|
+
- MIT-LICENSE
|
33
|
+
- Rakefile
|
34
|
+
- README
|
35
|
+
- test/abstract_unit.rb
|
36
|
+
- test/acts_as_taggable_test.rb
|
37
|
+
- test/database.yml
|
38
|
+
- test/fixtures/magazine.rb
|
39
|
+
- test/fixtures/magazines.yml
|
40
|
+
- test/fixtures/photo.rb
|
41
|
+
- test/fixtures/photos.yml
|
42
|
+
- test/fixtures/post.rb
|
43
|
+
- test/fixtures/posts.yml
|
44
|
+
- test/fixtures/special_post.rb
|
45
|
+
- test/fixtures/subscription.rb
|
46
|
+
- test/fixtures/subscriptions.yml
|
47
|
+
- test/fixtures/taggings.yml
|
48
|
+
- test/fixtures/tags.yml
|
49
|
+
- test/fixtures/user.rb
|
50
|
+
- test/fixtures/users.yml
|
51
|
+
- test/schema.rb
|
52
|
+
- test/tag_list_test.rb
|
53
|
+
- test/tag_test.rb
|
54
|
+
- test/tagging_test.rb
|
55
|
+
- test/tags_helper_test.rb
|
56
|
+
homepage: http://github.com/ysbaddaden/acts_as_taggable_on_steroids
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --inline-source
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>'
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.1
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project: acts_as_taggable_on_steroids
|
78
|
+
rubygems_version: 1.8.10
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Rails 3 plugin that is based on acts_as_taggable by jviney that is based
|
82
|
+
on acts_as_taggable by DHH.
|
83
|
+
test_files:
|
84
|
+
- test/abstract_unit.rb
|
85
|
+
- test/acts_as_taggable_test.rb
|
86
|
+
- test/database.yml
|
87
|
+
- test/fixtures/magazine.rb
|
88
|
+
- test/fixtures/magazines.yml
|
89
|
+
- test/fixtures/photo.rb
|
90
|
+
- test/fixtures/photos.yml
|
91
|
+
- test/fixtures/post.rb
|
92
|
+
- test/fixtures/posts.yml
|
93
|
+
- test/fixtures/special_post.rb
|
94
|
+
- test/fixtures/subscription.rb
|
95
|
+
- test/fixtures/subscriptions.yml
|
96
|
+
- test/fixtures/taggings.yml
|
97
|
+
- test/fixtures/tags.yml
|
98
|
+
- test/fixtures/user.rb
|
99
|
+
- test/fixtures/users.yml
|
100
|
+
- test/schema.rb
|
101
|
+
- test/tag_list_test.rb
|
102
|
+
- test/tag_test.rb
|
103
|
+
- test/tagging_test.rb
|
104
|
+
- test/tags_helper_test.rb
|