acts_as_taggable3 2.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +212 -0
- data/MIT-LICENSE +20 -0
- data/README +157 -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/fixtures/magazine.rb +3 -0
- data/test/fixtures/photo.rb +8 -0
- data/test/fixtures/post.rb +7 -0
- data/test/fixtures/special_post.rb +2 -0
- data/test/fixtures/subscription.rb +4 -0
- data/test/fixtures/user.rb +7 -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 +121 -0
data/test/schema.rb
ADDED
@@ -0,0 +1,48 @@
|
|
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 :categories, :force => true do |t|
|
14
|
+
t.column :name, :string
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :categorisations, :force => true do |t|
|
18
|
+
t.column :tag_id, :integer
|
19
|
+
t.column :taggable_id, :integer
|
20
|
+
t.column :taggable_type, :string
|
21
|
+
t.column :created_at, :datetime
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table :users, :force => true do |t|
|
25
|
+
t.column :name, :string
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table :posts, :force => true do |t|
|
29
|
+
t.column :text, :text
|
30
|
+
t.column :cached_tag_list, :string
|
31
|
+
t.column :user_id, :integer
|
32
|
+
t.column :type, :string
|
33
|
+
end
|
34
|
+
|
35
|
+
create_table :photos, :force => true do |t|
|
36
|
+
t.column :title, :string
|
37
|
+
t.column :user_id, :integer
|
38
|
+
end
|
39
|
+
|
40
|
+
create_table :subscriptions, :force => true do |t|
|
41
|
+
t.column :user_id, :integer
|
42
|
+
t.column :magazine_id, :integer
|
43
|
+
end
|
44
|
+
|
45
|
+
create_table :magazines, :force => true do |t|
|
46
|
+
t.column :name, :string
|
47
|
+
end
|
48
|
+
end
|
@@ -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,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_taggable3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 62196343
|
5
|
+
prerelease: 4
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- beta
|
10
|
+
- 2
|
11
|
+
version: 2.0.beta2
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Jonathan Viney
|
15
|
+
- Julien Portalier
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2011-09-17 00:00:00 +02:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: rails
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 7
|
32
|
+
segments:
|
33
|
+
- 3
|
34
|
+
- 0
|
35
|
+
version: "3.0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
description: Rails 3 plugin that is based on acts_as_taggable_on_steroids by jviney that is based on acts_as_taggable by DHH.
|
39
|
+
email: ysbaddaden@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- CHANGELOG
|
46
|
+
- MIT-LICENSE
|
47
|
+
- README
|
48
|
+
files:
|
49
|
+
- CHANGELOG
|
50
|
+
- MIT-LICENSE
|
51
|
+
- README
|
52
|
+
- lib/acts_as_taggable.rb
|
53
|
+
- lib/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb
|
54
|
+
- lib/generators/acts_as_taggable_migration/templates/migration.rb
|
55
|
+
- lib/tag.rb
|
56
|
+
- lib/tag_list.rb
|
57
|
+
- lib/tagging.rb
|
58
|
+
- lib/tags_helper.rb
|
59
|
+
- test/abstract_unit.rb
|
60
|
+
- test/acts_as_taggable_test.rb
|
61
|
+
- test/fixtures/magazine.rb
|
62
|
+
- test/fixtures/photo.rb
|
63
|
+
- test/fixtures/post.rb
|
64
|
+
- test/fixtures/special_post.rb
|
65
|
+
- test/fixtures/subscription.rb
|
66
|
+
- test/fixtures/user.rb
|
67
|
+
- test/schema.rb
|
68
|
+
- test/tag_list_test.rb
|
69
|
+
- test/tag_test.rb
|
70
|
+
- test/tagging_test.rb
|
71
|
+
- test/tags_helper_test.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/ysbaddaden/acts_as_taggable_on_steroids
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 25
|
96
|
+
segments:
|
97
|
+
- 1
|
98
|
+
- 3
|
99
|
+
- 1
|
100
|
+
version: 1.3.1
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.6.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Rails 3 plugin to stick tags on ActiveRecords.
|
108
|
+
test_files:
|
109
|
+
- test/abstract_unit.rb
|
110
|
+
- test/acts_as_taggable_test.rb
|
111
|
+
- test/fixtures/magazine.rb
|
112
|
+
- test/fixtures/photo.rb
|
113
|
+
- test/fixtures/post.rb
|
114
|
+
- test/fixtures/special_post.rb
|
115
|
+
- test/fixtures/subscription.rb
|
116
|
+
- test/fixtures/user.rb
|
117
|
+
- test/schema.rb
|
118
|
+
- test/tag_list_test.rb
|
119
|
+
- test/tag_test.rb
|
120
|
+
- test/tagging_test.rb
|
121
|
+
- test/tags_helper_test.rb
|