lwe-acts-as-taggable-on 1.0.7.lwe
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +18 -0
- data/MIT-LICENSE +20 -0
- data/README +194 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/lib/acts-as-taggable-on.rb +6 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +339 -0
- data/lib/acts_as_taggable_on/acts_as_tagger.rb +52 -0
- data/lib/acts_as_taggable_on/tag.rb +23 -0
- data/lib/acts_as_taggable_on/tag_list.rb +93 -0
- data/lib/acts_as_taggable_on/tagging.rb +6 -0
- data/lib/acts_as_taggable_on/tags_helper.rb +11 -0
- data/rails/init.rb +4 -0
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +165 -0
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +72 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +41 -0
- data/spec/acts_as_taggable_on/tag_spec.rb +27 -0
- data/spec/acts_as_taggable_on/taggable_spec.rb +159 -0
- data/spec/acts_as_taggable_on/tagger_spec.rb +23 -0
- data/spec/acts_as_taggable_on/tagging_spec.rb +7 -0
- data/spec/schema.rb +32 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +46 -0
- metadata +85 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Tag do
|
4
|
+
before(:each) do
|
5
|
+
@tag = Tag.new
|
6
|
+
@user = TaggableModel.create(:name => "Pablo")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should require a name" do
|
10
|
+
@tag.valid?
|
11
|
+
@tag.errors.on(:name).should == "can't be blank"
|
12
|
+
@tag.name = "something"
|
13
|
+
@tag.valid?
|
14
|
+
@tag.errors.on(:name).should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should equal a tag with the same name" do
|
18
|
+
@tag.name = "awesome"
|
19
|
+
new_tag = Tag.new(:name => "awesome")
|
20
|
+
new_tag.should == @tag
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return its name when to_s is called" do
|
24
|
+
@tag.name = "cool"
|
25
|
+
@tag.to_s.should == "cool"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Taggable" do
|
4
|
+
before(:each) do
|
5
|
+
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
6
|
+
@taggable = TaggableModel.new(:name => "Bob Jones")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be able to create tags" do
|
10
|
+
@taggable.skill_list = "ruby, rails, css"
|
11
|
+
@taggable.instance_variable_get("@skill_list").instance_of?(TagList).should be_true
|
12
|
+
@taggable.save
|
13
|
+
|
14
|
+
Tag.find(:all).size.should == 3
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to create tags through the tag list directly" do
|
18
|
+
@taggable.tag_list_on(:test).add("hello")
|
19
|
+
@taggable.save
|
20
|
+
@taggable.reload
|
21
|
+
@taggable.tag_list_on(:test).should == ["hello"]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should differentiate between contexts" do
|
25
|
+
@taggable.skill_list = "ruby, rails, css"
|
26
|
+
@taggable.tag_list = "ruby, bob, charlie"
|
27
|
+
@taggable.save
|
28
|
+
@taggable.reload
|
29
|
+
@taggable.skill_list.include?("ruby").should be_true
|
30
|
+
@taggable.skill_list.include?("bob").should be_false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be able to remove tags through list alone" do
|
34
|
+
@taggable.skill_list = "ruby, rails, css"
|
35
|
+
@taggable.save
|
36
|
+
@taggable.reload
|
37
|
+
@taggable.should have(3).skills
|
38
|
+
@taggable.skill_list = "ruby, rails"
|
39
|
+
@taggable.save
|
40
|
+
@taggable.reload
|
41
|
+
@taggable.should have(2).skills
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to find by tag" do
|
45
|
+
@taggable.skill_list = "ruby, rails, css"
|
46
|
+
@taggable.save
|
47
|
+
TaggableModel.find_tagged_with("ruby").first.should == @taggable
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to find by tag with context" do
|
51
|
+
@taggable.skill_list = "ruby, rails, css"
|
52
|
+
@taggable.tag_list = "bob, charlie"
|
53
|
+
@taggable.save
|
54
|
+
TaggableModel.find_tagged_with("ruby").first.should == @taggable
|
55
|
+
TaggableModel.find_tagged_with("bob", :on => :skills).first.should_not == @taggable
|
56
|
+
TaggableModel.find_tagged_with("bob", :on => :tags).first.should == @taggable
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be able to use the tagged_with named scope" do
|
60
|
+
@taggable.skill_list = "ruby, rails, css"
|
61
|
+
@taggable.tag_list = "bob, charlie"
|
62
|
+
@taggable.save
|
63
|
+
TaggableModel.tagged_with("ruby", {}).first.should == @taggable
|
64
|
+
TaggableModel.tagged_with("bob", :on => :skills).first.should_not == @taggable
|
65
|
+
TaggableModel.tagged_with("bob", :on => :tags).first.should == @taggable
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not care about case" do
|
69
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby")
|
70
|
+
frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
|
71
|
+
|
72
|
+
Tag.find(:all).size.should == 1
|
73
|
+
TaggableModel.find_tagged_with("ruby").should == TaggableModel.find_tagged_with("Ruby")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be able to get tag counts on model as a whole" do
|
77
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
78
|
+
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
79
|
+
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
80
|
+
TaggableModel.tag_counts.should_not be_empty
|
81
|
+
TaggableModel.skill_counts.should_not be_empty
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be able to get tag counts on an association" do
|
85
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
86
|
+
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
87
|
+
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
88
|
+
TaggableModel.tag_counts.first.count.should == 2
|
89
|
+
charlie.skill_counts.first.count.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be able to set a custom tag context list" do
|
93
|
+
bob = TaggableModel.create(:name => "Bob")
|
94
|
+
bob.set_tag_list_on(:rotors, "spinning, jumping")
|
95
|
+
bob.tag_list_on(:rotors).should == ["spinning","jumping"]
|
96
|
+
bob.save
|
97
|
+
bob.reload
|
98
|
+
bob.tags_on(:rotors).should_not be_empty
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should be able to find tagged on a custom tag context" do
|
102
|
+
bob = TaggableModel.create(:name => "Bob")
|
103
|
+
bob.set_tag_list_on(:rotors, "spinning, jumping")
|
104
|
+
bob.tag_list_on(:rotors).should == ["spinning","jumping"]
|
105
|
+
bob.save
|
106
|
+
TaggableModel.find_tagged_with("spinning", :on => :rotors).should_not be_empty
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should be able to use named scopes to chain tag finds" do
|
110
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
|
111
|
+
frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
|
112
|
+
steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, python')
|
113
|
+
|
114
|
+
# Let's only find those productive Rails developers
|
115
|
+
TaggableModel.tagged_with('rails', :on => :skills).all(:order => 'taggable_models.name').should == [bob, frank]
|
116
|
+
TaggableModel.tagged_with('happier', :on => :tags).all(:order => 'taggable_models.name').should == [bob, steve]
|
117
|
+
# FIXME: fails!!!
|
118
|
+
#TaggableModel.tagged_with('rails', :on => :skills).tagged_with('happier', :on => :tags).should == [bob]
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "Single Table Inheritance" do
|
122
|
+
before do
|
123
|
+
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
124
|
+
@taggable = TaggableModel.new(:name => "taggable")
|
125
|
+
@inherited_same = InheritingTaggableModel.new(:name => "inherited same")
|
126
|
+
@inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should be able to save tags for inherited models" do
|
130
|
+
@inherited_same.tag_list = "bob, kelso"
|
131
|
+
@inherited_same.save
|
132
|
+
InheritingTaggableModel.find_tagged_with("bob").first.should == @inherited_same
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should find STI tagged models on the superclass" do
|
136
|
+
@inherited_same.tag_list = "bob, kelso"
|
137
|
+
@inherited_same.save
|
138
|
+
TaggableModel.find_tagged_with("bob").first.should == @inherited_same
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should be able to add on contexts only to some subclasses" do
|
142
|
+
@inherited_different.part_list = "fork, spoon"
|
143
|
+
@inherited_different.save
|
144
|
+
InheritingTaggableModel.find_tagged_with("fork", :on => :parts).should be_empty
|
145
|
+
AlteredInheritingTaggableModel.find_tagged_with("fork", :on => :parts).first.should == @inherited_different
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should have different tag_counts_on for inherited models" do
|
149
|
+
@inherited_same.tag_list = "bob, kelso"
|
150
|
+
@inherited_same.save!
|
151
|
+
@inherited_different.tag_list = "fork, spoon"
|
152
|
+
@inherited_different.save!
|
153
|
+
|
154
|
+
InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
|
155
|
+
AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
|
156
|
+
TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Tagger" do
|
4
|
+
before(:each) do
|
5
|
+
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
6
|
+
@user = TaggableUser.new
|
7
|
+
@taggable = TaggableModel.new(:name => "Bob Jones")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have taggings" do
|
11
|
+
@user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
|
12
|
+
@user.owned_taggings.size == 2
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have tags" do
|
16
|
+
@user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
|
17
|
+
@user.owned_tags.size == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "is tagger" do
|
21
|
+
@user.is_tagger?.should(be_true)
|
22
|
+
end
|
23
|
+
end
|
data/spec/schema.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
create_table "taggings", :force => true do |t|
|
3
|
+
t.integer "tag_id", :limit => 11
|
4
|
+
t.integer "taggable_id", :limit => 11
|
5
|
+
t.string "taggable_type"
|
6
|
+
t.string "context"
|
7
|
+
t.datetime "created_at"
|
8
|
+
t.integer "tagger_id", :limit => 11
|
9
|
+
t.string "tagger_type"
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
|
13
|
+
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
|
14
|
+
|
15
|
+
create_table "tags", :force => true do |t|
|
16
|
+
t.string "name"
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :taggable_models, :force => true do |t|
|
20
|
+
t.column :name, :string
|
21
|
+
t.column :type, :string
|
22
|
+
#t.column :cached_tag_list, :string
|
23
|
+
end
|
24
|
+
create_table :taggable_users, :force => true do |t|
|
25
|
+
t.column :name, :string
|
26
|
+
end
|
27
|
+
create_table :other_taggable_models, :force => true do |t|
|
28
|
+
t.column :name, :string
|
29
|
+
t.column :type, :string
|
30
|
+
#t.column :cached_tag_list, :string
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
module Spec::Example::ExampleGroupMethods
|
8
|
+
alias :context :describe
|
9
|
+
end
|
10
|
+
|
11
|
+
TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
|
12
|
+
|
13
|
+
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
|
14
|
+
RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
15
|
+
ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
|
16
|
+
ActiveRecord::Base.establish_connection(
|
17
|
+
"adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
|
18
|
+
)
|
19
|
+
|
20
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
21
|
+
|
22
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
23
|
+
require File.join(File.dirname(__FILE__), '..', 'init')
|
24
|
+
|
25
|
+
class TaggableModel < ActiveRecord::Base
|
26
|
+
acts_as_taggable_on :tags, :languages
|
27
|
+
acts_as_taggable_on :skills
|
28
|
+
end
|
29
|
+
|
30
|
+
class OtherTaggableModel < ActiveRecord::Base
|
31
|
+
acts_as_taggable_on :tags, :languages
|
32
|
+
end
|
33
|
+
|
34
|
+
class InheritingTaggableModel < TaggableModel
|
35
|
+
end
|
36
|
+
|
37
|
+
class AlteredInheritingTaggableModel < TaggableModel
|
38
|
+
acts_as_taggable_on :parts
|
39
|
+
end
|
40
|
+
|
41
|
+
class TaggableUser < ActiveRecord::Base
|
42
|
+
acts_as_tagger
|
43
|
+
end
|
44
|
+
|
45
|
+
class UntaggableModel < ActiveRecord::Base
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lwe-acts-as-taggable-on
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.7.lwe
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Bleigh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-11 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: With ActsAsTaggableOn, you could tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality.
|
17
|
+
email: michael@intridea.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- MIT-LICENSE
|
27
|
+
- README
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- lib/acts-as-taggable-on.rb
|
31
|
+
- lib/acts_as_taggable_on/acts_as_taggable_on.rb
|
32
|
+
- lib/acts_as_taggable_on/acts_as_tagger.rb
|
33
|
+
- lib/acts_as_taggable_on/tag.rb
|
34
|
+
- lib/acts_as_taggable_on/tag_list.rb
|
35
|
+
- lib/acts_as_taggable_on/tagging.rb
|
36
|
+
- lib/acts_as_taggable_on/tags_helper.rb
|
37
|
+
- rails/init.rb
|
38
|
+
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
39
|
+
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
40
|
+
- spec/acts_as_taggable_on/tag_list_spec.rb
|
41
|
+
- spec/acts_as_taggable_on/tag_spec.rb
|
42
|
+
- spec/acts_as_taggable_on/taggable_spec.rb
|
43
|
+
- spec/acts_as_taggable_on/tagger_spec.rb
|
44
|
+
- spec/acts_as_taggable_on/tagging_spec.rb
|
45
|
+
- spec/schema.rb
|
46
|
+
- spec/spec.opts
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/lwe/acts-as-taggable-on
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.3.1
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.
|
76
|
+
test_files:
|
77
|
+
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
78
|
+
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
79
|
+
- spec/acts_as_taggable_on/tag_list_spec.rb
|
80
|
+
- spec/acts_as_taggable_on/tag_spec.rb
|
81
|
+
- spec/acts_as_taggable_on/taggable_spec.rb
|
82
|
+
- spec/acts_as_taggable_on/tagger_spec.rb
|
83
|
+
- spec/acts_as_taggable_on/tagging_spec.rb
|
84
|
+
- spec/schema.rb
|
85
|
+
- spec/spec_helper.rb
|