acts-as-taggable-on 2.0.0.pre5 → 2.0.0.rc1
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/README.rdoc +34 -27
- data/VERSION +1 -1
- data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +7 -0
- data/generators/acts_as_taggable_on_migration/templates/migration.rb +29 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +1 -1
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +1 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +1 -1
- data/lib/acts_as_taggable_on/tag.rb +1 -1
- data/spec/acts_as_taggable_on/taggable_spec.rb +12 -1
- data/spec/acts_as_taggable_on/tagger_spec.rb +16 -0
- data/spec/models.rb +2 -8
- data/spec/schema.rb +5 -4
- data/spec/spec_helper.rb +6 -0
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -15,43 +15,53 @@ was used.
|
|
15
15
|
|
16
16
|
== Installation
|
17
17
|
|
18
|
-
===
|
18
|
+
=== Rails 2.3.x
|
19
|
+
|
20
|
+
Acts As Taggable On is tested to work in Rails 2.3.5.
|
21
|
+
|
22
|
+
==== Plugin
|
19
23
|
|
20
24
|
Acts As Taggable On is available both as a gem and as a traditional plugin. For the
|
21
|
-
traditional plugin you can install like so
|
25
|
+
traditional plugin you can install like so:
|
22
26
|
|
23
27
|
script/plugin install git://github.com/mbleigh/acts-as-taggable-on.git
|
24
|
-
|
25
|
-
=== GemPlugin
|
26
28
|
|
27
29
|
Acts As Taggable On is also available as a gem plugin using Rails 2.1's gem dependencies.
|
28
30
|
To install the gem, add this to your config/environment.rb:
|
29
31
|
|
30
|
-
config.gem "acts-as-taggable-on", :source => "http://gemcutter.org"
|
32
|
+
config.gem "acts-as-taggable-on", :source => "http://gemcutter.org", :version => '2.0.0.rc1'
|
31
33
|
|
32
34
|
After that, you can run "rake gems:install" to install the gem if you don't already have it.
|
33
35
|
|
36
|
+
==== Post Installation
|
37
|
+
|
38
|
+
1. script/generate acts_as_taggable_on_migration
|
39
|
+
2. rake db:migrate
|
40
|
+
|
34
41
|
== Rails 3.0
|
35
42
|
|
36
43
|
Acts As Taggable On is now useable in Rails 3.0, thanks to the excellent work of Szymon Nowak
|
37
|
-
and Jelle Vandebeeck.
|
38
|
-
in the feature/rails3_compatibility branch.
|
44
|
+
and Jelle Vandebeeck.
|
39
45
|
|
40
|
-
|
46
|
+
To use it, add it to your Gemfile:
|
41
47
|
|
42
|
-
gem
|
48
|
+
gem 'acts-as-taggable-on', '2.0.0.rc1'
|
43
49
|
|
44
|
-
=== Post Installation
|
50
|
+
=== Post Installation
|
45
51
|
|
46
|
-
1.
|
52
|
+
1. rails generate acts_as_taggable_on:migration
|
47
53
|
2. rake db:migrate
|
48
54
|
|
49
55
|
=== Testing
|
50
56
|
|
51
57
|
Acts As Taggable On uses RSpec for its test coverage. Inside the plugin
|
52
|
-
directory, you can run the specs with:
|
58
|
+
directory, you can run the specs for RoR 3.0.0 with:
|
59
|
+
|
60
|
+
rake spec
|
61
|
+
|
62
|
+
If you want to test the plugin for Rails 2.3.x, use:
|
53
63
|
|
54
|
-
rake spec
|
64
|
+
rake rails2.3:spec
|
55
65
|
|
56
66
|
If you already have RSpec on your application, the specs will run while using:
|
57
67
|
|
@@ -67,29 +77,21 @@ rake spec:plugins
|
|
67
77
|
@user = User.new(:name => "Bobby")
|
68
78
|
@user.tag_list = "awesome, slick, hefty" # this should be familiar
|
69
79
|
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
|
70
|
-
@user.skill_list
|
80
|
+
@user.skill_list # => ["joking","clowning","boxing"] as TagList
|
71
81
|
@user.save
|
72
82
|
|
73
83
|
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
|
74
84
|
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
|
75
85
|
|
76
|
-
# The old way
|
77
|
-
User.find_tagged_with("awesome", :on => :tags) # => [@user]
|
78
|
-
User.find_tagged_with("awesome", :on => :skills) # => []
|
79
|
-
|
80
|
-
# The better way (utilizes named_scope)
|
81
|
-
User.tagged_with("awesome", :on => :tags) # => [@user]
|
82
|
-
User.tagged_with("awesome", :on => :skills) # => []
|
83
|
-
|
84
86
|
@frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
|
85
87
|
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
|
86
88
|
@frankie.skill_counts
|
87
89
|
|
88
90
|
=== Finding Tagged Objects
|
89
91
|
|
90
|
-
Acts As Taggable On utilizes
|
91
|
-
|
92
|
-
|
92
|
+
Acts As Taggable On utilizes named_scopes to create an association for tags.
|
93
|
+
This way you can mix and match to filter down your results, and it also improves
|
94
|
+
compatibility with the will_paginate gem:
|
93
95
|
|
94
96
|
class User < ActiveRecord::Base
|
95
97
|
acts_as_taggable_on :tags
|
@@ -99,8 +101,11 @@ also improves compatibility with the will_paginate gem:
|
|
99
101
|
User.tagged_with("awesome").by_date
|
100
102
|
User.tagged_with("awesome").by_date.paginate(:page => params[:page], :per_page => 20)
|
101
103
|
|
102
|
-
#Find a user with matching all tags, not just one
|
104
|
+
# Find a user with matching all tags, not just one
|
103
105
|
User.tagged_with(["awesome", "cool"], :match_all => :true)
|
106
|
+
|
107
|
+
# Find a user with any of the tags:
|
108
|
+
User.tagged_with(["awesome", "cool"], :any => true)
|
104
109
|
|
105
110
|
=== Relationships
|
106
111
|
|
@@ -195,6 +200,8 @@ CSS:
|
|
195
200
|
|
196
201
|
* TomEric (i76) - Maintainer
|
197
202
|
* Michael Bleigh - Original Author
|
203
|
+
* Szymon Nowak - Rails 3.0 compatibility
|
204
|
+
* Jelle Vandebeeck - Rails 3.0 compatibility
|
198
205
|
* Brendan Lim - Related Objects
|
199
206
|
* Pradeep Elankumaran - Taggers
|
200
207
|
* Sinclair Bain - Patch King
|
@@ -209,4 +216,4 @@ CSS:
|
|
209
216
|
* lawrencepit - cached tag work
|
210
217
|
* sobrinho - fixed tag_cloud helper
|
211
218
|
|
212
|
-
Copyright (c) 2007-
|
219
|
+
Copyright (c) 2007-2010 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the MIT license
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.
|
1
|
+
2.0.0.rc1
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :tags do |t|
|
4
|
+
t.column :name, :string
|
5
|
+
end
|
6
|
+
|
7
|
+
create_table :taggings do |t|
|
8
|
+
t.column :tag_id, :integer
|
9
|
+
t.column :taggable_id, :integer
|
10
|
+
t.column :tagger_id, :integer
|
11
|
+
t.column :tagger_type, :string
|
12
|
+
|
13
|
+
# You should make sure that the column created is
|
14
|
+
# long enough to store the required class names.
|
15
|
+
t.column :taggable_type, :string
|
16
|
+
t.column :context, :string
|
17
|
+
|
18
|
+
t.column :created_at, :datetime
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :taggings, :tag_id
|
22
|
+
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.down
|
26
|
+
drop_table :taggings
|
27
|
+
drop_table :tags
|
28
|
+
end
|
29
|
+
end
|
@@ -208,7 +208,7 @@ module ActsAsTaggableOn::Taggable
|
|
208
208
|
|
209
209
|
# Create new taggings:
|
210
210
|
new_tags.each do |tag|
|
211
|
-
|
211
|
+
taggings.create!(:tag_id => tag.id, :context => context.to_s, :taggable => self)
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
@@ -90,7 +90,7 @@ module ActsAsTaggableOn::Taggable
|
|
90
90
|
|
91
91
|
# Create new taggings:
|
92
92
|
new_tags.each do |tag|
|
93
|
-
|
93
|
+
taggings.create!(:tag_id => tag.id, :context => context.to_s, :tagger => owner, :taggable => self)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -42,7 +42,7 @@ class Tag < ActiveRecord::Base
|
|
42
42
|
return [] if list.empty?
|
43
43
|
|
44
44
|
existing_tags = Tag.named_any(list).all
|
45
|
-
new_tag_names = list.reject { |name| existing_tags.any? { |tag| tag.name.downcase == name.downcase } }
|
45
|
+
new_tag_names = list.reject { |name| existing_tags.any? { |tag| tag.name.mb_chars.downcase == name.mb_chars.downcase } }
|
46
46
|
created_tags = new_tag_names.map { |name| Tag.create(:name => name) }
|
47
47
|
|
48
48
|
existing_tags + created_tags
|
@@ -215,6 +215,18 @@ describe "Taggable" do
|
|
215
215
|
bob.save
|
216
216
|
}.should change(Tagging, :count).by(1)
|
217
217
|
end
|
218
|
+
|
219
|
+
describe "Associations" do
|
220
|
+
before(:each) do
|
221
|
+
@taggable = TaggableModel.create(:tag_list => "awesome, epic")
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should not remove tags when creating associated objects" do
|
225
|
+
@taggable.untaggable_models.create!
|
226
|
+
@taggable.reload
|
227
|
+
@taggable.tag_list.should have(2).items
|
228
|
+
end
|
229
|
+
end
|
218
230
|
|
219
231
|
describe "grouped_column_names_for method" do
|
220
232
|
it "should return all column names joined for Tag GROUP clause" do
|
@@ -228,7 +240,6 @@ describe "Taggable" do
|
|
228
240
|
|
229
241
|
describe "Single Table Inheritance" do
|
230
242
|
before do
|
231
|
-
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
232
243
|
@taggable = TaggableModel.new(:name => "taggable")
|
233
244
|
@inherited_same = InheritingTaggableModel.new(:name => "inherited same")
|
234
245
|
@inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
|
@@ -68,6 +68,22 @@ describe "Tagger" do
|
|
68
68
|
@taggable.all_tags_list.should include('awesome')
|
69
69
|
@taggable.all_tags_list.should include('epic')
|
70
70
|
end
|
71
|
+
|
72
|
+
it "should not lose tags" do
|
73
|
+
@taggable.update_attributes(:tag_list => 'ruby')
|
74
|
+
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
|
75
|
+
|
76
|
+
[@taggable, @user].each(&:reload)
|
77
|
+
@taggable.tag_list.should == %w(ruby)
|
78
|
+
@taggable.all_tags_list.sort.should == %w(ruby scheme).sort
|
79
|
+
|
80
|
+
lambda {
|
81
|
+
@taggable.update_attributes(:tag_list => "")
|
82
|
+
}.should change(Tagging, :count).by(-1)
|
83
|
+
|
84
|
+
@taggable.tag_list.should == []
|
85
|
+
@taggable.all_tags_list.sort.should == %w(ruby scheme).sort
|
86
|
+
end
|
71
87
|
|
72
88
|
it "is tagger" do
|
73
89
|
@user.is_tagger?.should(be_true)
|
data/spec/models.rb
CHANGED
@@ -3,6 +3,7 @@ class TaggableModel < ActiveRecord::Base
|
|
3
3
|
acts_as_taggable_on :languages
|
4
4
|
acts_as_taggable_on :skills
|
5
5
|
acts_as_taggable_on :needs, :offerings
|
6
|
+
has_many :untaggable_models
|
6
7
|
end
|
7
8
|
|
8
9
|
class CachedModel < ActiveRecord::Base
|
@@ -26,11 +27,4 @@ class TaggableUser < ActiveRecord::Base
|
|
26
27
|
end
|
27
28
|
|
28
29
|
class UntaggableModel < ActiveRecord::Base
|
29
|
-
end
|
30
|
-
|
31
|
-
# if ActiveRecord::VERSION::MAJOR < 3
|
32
|
-
# [TaggableModel, CachedModel, OtherTaggableModel, InheritingTaggableModel,
|
33
|
-
# AlteredInheritingTaggableModel, TaggableUser, UntaggableModel].each do |klass|
|
34
|
-
# klass.send(:include, ActsAsTaggableOn::ActiveRecord::Backports)
|
35
|
-
# end
|
36
|
-
# end
|
30
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -21,6 +21,11 @@ ActiveRecord::Schema.define :version => 0 do
|
|
21
21
|
t.column :type, :string
|
22
22
|
end
|
23
23
|
|
24
|
+
create_table :untaggable_models, :force => true do |t|
|
25
|
+
t.column :taggable_model_id, :integer
|
26
|
+
t.column :name, :string
|
27
|
+
end
|
28
|
+
|
24
29
|
create_table :cached_models, :force => true do |t|
|
25
30
|
t.column :name, :string
|
26
31
|
t.column :type, :string
|
@@ -35,8 +40,4 @@ ActiveRecord::Schema.define :version => 0 do
|
|
35
40
|
t.column :name, :string
|
36
41
|
t.column :type, :string
|
37
42
|
end
|
38
|
-
|
39
|
-
create_table :untaggable_models, :force => true do |t|
|
40
|
-
t.column :name, :string
|
41
|
-
end
|
42
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,6 +28,12 @@ end
|
|
28
28
|
# Setup a database
|
29
29
|
TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
|
30
30
|
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
|
31
|
+
|
32
|
+
ActiveRecord::Base.establish_connection(
|
33
|
+
"adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
|
34
|
+
)
|
35
|
+
|
36
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
31
37
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => TEST_DATABASE_FILE
|
32
38
|
|
33
39
|
ActiveRecord::Base.silence do
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 2
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.0.
|
9
|
+
- rc1
|
10
|
+
version: 2.0.0.rc1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Bleigh
|
@@ -34,6 +34,8 @@ files:
|
|
34
34
|
- README.rdoc
|
35
35
|
- Rakefile
|
36
36
|
- VERSION
|
37
|
+
- generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb
|
38
|
+
- generators/acts_as_taggable_on_migration/templates/migration.rb
|
37
39
|
- lib/acts-as-taggable-on.rb
|
38
40
|
- lib/acts_as_taggable_on/acts_as_taggable_on.rb
|
39
41
|
- lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
|