axtro-acts-as-taggable-on 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +25 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +95 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +221 -0
  6. data/Rakefile +59 -0
  7. data/VERSION +1 -0
  8. data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +7 -0
  9. data/generators/acts_as_taggable_on_migration/templates/migration.rb +29 -0
  10. data/lib/acts-as-taggable-on.rb +30 -0
  11. data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +53 -0
  12. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +53 -0
  13. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +130 -0
  14. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +237 -0
  15. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +101 -0
  16. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +65 -0
  17. data/lib/acts_as_taggable_on/acts_as_tagger.rb +67 -0
  18. data/lib/acts_as_taggable_on/compatibility/Gemfile +6 -0
  19. data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +17 -0
  20. data/lib/acts_as_taggable_on/tag.rb +65 -0
  21. data/lib/acts_as_taggable_on/tag_list.rb +95 -0
  22. data/lib/acts_as_taggable_on/tagging.rb +23 -0
  23. data/lib/acts_as_taggable_on/tags_helper.rb +17 -0
  24. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +31 -0
  25. data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +28 -0
  26. data/rails/init.rb +1 -0
  27. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +266 -0
  28. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +114 -0
  29. data/spec/acts_as_taggable_on/tag_list_spec.rb +70 -0
  30. data/spec/acts_as_taggable_on/tag_spec.rb +115 -0
  31. data/spec/acts_as_taggable_on/taggable_spec.rb +311 -0
  32. data/spec/acts_as_taggable_on/tagger_spec.rb +91 -0
  33. data/spec/acts_as_taggable_on/tagging_spec.rb +31 -0
  34. data/spec/acts_as_taggable_on/tags_helper_spec.rb +28 -0
  35. data/spec/bm.rb +52 -0
  36. data/spec/models.rb +31 -0
  37. data/spec/schema.rb +43 -0
  38. data/spec/spec.opts +2 -0
  39. data/spec/spec_helper.rb +53 -0
  40. metadata +169 -0
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Tagger" do
4
+ before(:each) do
5
+ clean_database!
6
+ @user = TaggableUser.create
7
+ @taggable = TaggableModel.create(: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 "should not overlap tags from different taggers" do
21
+ @user2 = TaggableUser.new
22
+ lambda{
23
+ @user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
24
+ @user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
25
+ }.should change(Tagging, :count).by(6)
26
+
27
+ [@user, @user2, @taggable].each(&:reload)
28
+
29
+ @user.owned_tags.map(&:name).sort.should == %w(ruby scheme).sort
30
+ @user2.owned_tags.map(&:name).sort.should == %w(java python lisp ruby).sort
31
+
32
+ @taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
33
+ @taggable.tags_from(@user2).sort.should == %w(java lisp python ruby).sort
34
+
35
+ @taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
36
+ @taggable.all_tags_on(:tags).size.should == 5
37
+ end
38
+
39
+ it "should not lose tags from different taggers" do
40
+ @user2 = TaggableUser.create
41
+ @user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
42
+ @user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
43
+
44
+ lambda {
45
+ @user2.tag(@taggable, :with => 'java, python, lisp', :on => :tags)
46
+ }.should change(Tagging, :count).by(-1)
47
+
48
+ [@user, @user2, @taggable].each(&:reload)
49
+
50
+ @taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
51
+ @taggable.tags_from(@user2).sort.should == %w(java python lisp).sort
52
+
53
+ @taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
54
+ @taggable.all_tags_on(:tags).length.should == 5
55
+ end
56
+
57
+ it "should not lose tags" do
58
+ @user2 = TaggableUser.create
59
+
60
+ @user.tag(@taggable, :with => 'awesome', :on => :tags)
61
+ @user2.tag(@taggable, :with => 'awesome, epic', :on => :tags)
62
+
63
+ lambda {
64
+ @user2.tag(@taggable, :with => 'epic', :on => :tags)
65
+ }.should change(Tagging, :count).by(-1)
66
+
67
+ @taggable.reload
68
+ @taggable.all_tags_list.should include('awesome')
69
+ @taggable.all_tags_list.should include('epic')
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
87
+
88
+ it "is tagger" do
89
+ @user.is_tagger?.should(be_true)
90
+ end
91
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Tagging do
4
+ before(:each) do
5
+ clean_database!
6
+ @tagging = Tagging.new
7
+ end
8
+
9
+ it "should not be valid with a invalid tag" do
10
+ @tagging.taggable = TaggableModel.create(:name => "Bob Jones")
11
+ @tagging.tag = Tag.new(:name => "")
12
+ @tagging.context = "tags"
13
+
14
+ @tagging.should_not be_valid
15
+
16
+ if ActiveRecord::VERSION::MAJOR >= 3
17
+ @tagging.errors[:tag_id].should == ["can't be blank"]
18
+ else
19
+ @tagging.errors[:tag_id].should == "can't be blank"
20
+ end
21
+ end
22
+
23
+ it "should not create duplicate taggings" do
24
+ @taggable = TaggableModel.create(:name => "Bob Jones")
25
+ @tag = Tag.create(:name => "awesome")
26
+
27
+ lambda {
28
+ 2.times { Tagging.create(:taggable => @taggable, :tag => @tag, :context => 'tags') }
29
+ }.should change(Tagging, :count).by(1)
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe TagsHelper do
4
+ before(:each) do
5
+ clean_database!
6
+
7
+ @bob = TaggableModel.create(:name => "Bob Jones", :language_list => "ruby, php")
8
+ @tom = TaggableModel.create(:name => "Tom Marley", :language_list => "ruby, java")
9
+ @eve = TaggableModel.create(:name => "Eve Nodd", :language_list => "ruby, c++")
10
+
11
+ @helper = class Helper
12
+ include TagsHelper
13
+ end.new
14
+ end
15
+
16
+ it "should yield the proper css classes" do
17
+ tags = { }
18
+
19
+ @helper.tag_cloud(TaggableModel.tag_counts_on(:languages), ["sucky", "awesome"]) do |tag, css_class|
20
+ tags[tag.name] = css_class
21
+ end
22
+
23
+ tags["ruby"].should == "awesome"
24
+ tags["java"].should == "sucky"
25
+ tags["c++"].should == "sucky"
26
+ tags["php"].should == "sucky"
27
+ end
28
+ end
@@ -0,0 +1,52 @@
1
+ require 'active_record'
2
+ require 'action_view'
3
+ require File.expand_path('../../lib/acts-as-taggable-on', __FILE__)
4
+
5
+ if defined?(ActiveRecord::Acts::TaggableOn)
6
+ ActiveRecord::Base.send :include, ActiveRecord::Acts::TaggableOn
7
+ ActiveRecord::Base.send :include, ActiveRecord::Acts::Tagger
8
+ ActionView::Base.send :include, TagsHelper if defined?(ActionView::Base)
9
+ end
10
+
11
+ TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
12
+ File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
13
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => TEST_DATABASE_FILE
14
+
15
+ ActiveRecord::Base.silence do
16
+ ActiveRecord::Migration.verbose = false
17
+ ActiveRecord::Schema.define :version => 0 do
18
+ create_table "taggings", :force => true do |t|
19
+ t.integer "tag_id", :limit => 11
20
+ t.integer "taggable_id", :limit => 11
21
+ t.string "taggable_type"
22
+ t.string "context"
23
+ t.datetime "created_at"
24
+ t.integer "tagger_id", :limit => 11
25
+ t.string "tagger_type"
26
+ end
27
+
28
+ add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
29
+ add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
30
+
31
+ create_table "tags", :force => true do |t|
32
+ t.string "name"
33
+ end
34
+
35
+ create_table :taggable_models, :force => true do |t|
36
+ t.column :name, :string
37
+ t.column :type, :string
38
+ t.column :cached_tag_list, :string
39
+ end
40
+ end
41
+
42
+ class TaggableModel < ActiveRecord::Base
43
+ acts_as_taggable
44
+ acts_as_taggable_on :languages
45
+ acts_as_taggable_on :skills
46
+ acts_as_taggable_on :needs, :offerings
47
+ end
48
+ end
49
+
50
+ puts Benchmark.measure {
51
+ 1000.times { TaggableModel.create :tag_list => "awesome, epic, neat" }
52
+ }
@@ -0,0 +1,31 @@
1
+ class TaggableModel < ActiveRecord::Base
2
+ acts_as_taggable
3
+ acts_as_taggable_on :languages
4
+ acts_as_taggable_on :skills
5
+ acts_as_taggable_on :needs, :offerings
6
+ has_many :untaggable_models
7
+ end
8
+
9
+ class CachedModel < ActiveRecord::Base
10
+ acts_as_taggable
11
+ end
12
+
13
+ class OtherTaggableModel < ActiveRecord::Base
14
+ acts_as_taggable_on :tags, :languages
15
+ acts_as_taggable_on :needs, :offerings
16
+ end
17
+
18
+ class InheritingTaggableModel < TaggableModel
19
+ end
20
+
21
+ class AlteredInheritingTaggableModel < TaggableModel
22
+ acts_as_taggable_on :parts
23
+ end
24
+
25
+ class TaggableUser < ActiveRecord::Base
26
+ acts_as_tagger
27
+ end
28
+
29
+ class UntaggableModel < ActiveRecord::Base
30
+ belongs_to :taggable_model
31
+ end
@@ -0,0 +1,43 @@
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
+ end
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
+
29
+ create_table :cached_models, :force => true do |t|
30
+ t.column :name, :string
31
+ t.column :type, :string
32
+ t.column :cached_tag_list, :string
33
+ end
34
+
35
+ create_table :taggable_users, :force => true do |t|
36
+ t.column :name, :string
37
+ end
38
+
39
+ create_table :other_taggable_models, :force => true do |t|
40
+ t.column :name, :string
41
+ t.column :type, :string
42
+ end
43
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --backtrace
@@ -0,0 +1,53 @@
1
+ begin
2
+ # Try to require the preresolved locked set of gems.
3
+ require File.expand_path("../.bundle/environment", __FILE__)
4
+ rescue LoadError
5
+ # Fall back on doing an unlocked resolve at runtime.
6
+ require "rubygems" unless RUBY_VERSION >= "1.9"
7
+ require "bundler"
8
+ Bundler.setup
9
+ end
10
+
11
+ Bundler.require
12
+ require File.expand_path('../../lib/acts-as-taggable-on', __FILE__)
13
+
14
+ if defined?(Rspec::Core::ExampleGroupSubject)
15
+ module Rspec::Core::ExampleGroupSubject
16
+ alias :context :describe
17
+ end
18
+ end
19
+
20
+ class Array
21
+ def freq
22
+ k=Hash.new(0)
23
+ each {|e| k[e]+=1}
24
+ k
25
+ end
26
+ end
27
+
28
+ # Setup a database
29
+ TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
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"))
37
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => TEST_DATABASE_FILE
38
+
39
+ ActiveRecord::Base.silence do
40
+ ActiveRecord::Migration.verbose = false
41
+ load(File.dirname(__FILE__) + '/schema.rb')
42
+ load(File.dirname(__FILE__) + '/models.rb')
43
+ end
44
+
45
+ def clean_database!
46
+ models = [Tag, Tagging, TaggableModel, OtherTaggableModel, InheritingTaggableModel,
47
+ AlteredInheritingTaggableModel, TaggableUser, UntaggableModel]
48
+ models.each do |model|
49
+ model.destroy_all
50
+ end
51
+ end
52
+
53
+ clean_database!
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: axtro-acts-as-taggable-on
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 4
10
+ version: 2.0.4
11
+ platform: ruby
12
+ authors:
13
+ - Michael Bleigh
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-10 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ hash: -1848230022
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ - beta2
33
+ version: 3.0.0.beta2
34
+ requirement: *id001
35
+ name: rails
36
+ prerelease: false
37
+ type: :runtime
38
+ - !ruby/object:Gem::Dependency
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 62196457
45
+ segments:
46
+ - 2
47
+ - 0
48
+ - 0
49
+ - beta
50
+ - 5
51
+ version: 2.0.0.beta.5
52
+ requirement: *id002
53
+ name: rspec
54
+ prerelease: false
55
+ type: :runtime
56
+ - !ruby/object:Gem::Dependency
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - "="
61
+ - !ruby/object:Gem::Version
62
+ hash: 21
63
+ segments:
64
+ - 1
65
+ - 2
66
+ - 5
67
+ version: 1.2.5
68
+ requirement: *id003
69
+ name: sqlite3-ruby
70
+ prerelease: false
71
+ type: :runtime
72
+ - !ruby/object:Gem::Dependency
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirement: *id004
83
+ name: jeweler
84
+ prerelease: false
85
+ type: :runtime
86
+ description: With ActsAsTaggableOn, you could tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality.
87
+ email: michael@intridea.com
88
+ executables: []
89
+
90
+ extensions: []
91
+
92
+ extra_rdoc_files:
93
+ - README.rdoc
94
+ files:
95
+ - CHANGELOG
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - MIT-LICENSE
99
+ - README.rdoc
100
+ - Rakefile
101
+ - VERSION
102
+ - generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb
103
+ - generators/acts_as_taggable_on_migration/templates/migration.rb
104
+ - lib/acts-as-taggable-on.rb
105
+ - lib/acts_as_taggable_on/acts_as_taggable_on.rb
106
+ - lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
107
+ - lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
108
+ - lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
109
+ - lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
110
+ - lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
111
+ - lib/acts_as_taggable_on/acts_as_tagger.rb
112
+ - lib/acts_as_taggable_on/compatibility/Gemfile
113
+ - lib/acts_as_taggable_on/compatibility/active_record_backports.rb
114
+ - lib/acts_as_taggable_on/tag.rb
115
+ - lib/acts_as_taggable_on/tag_list.rb
116
+ - lib/acts_as_taggable_on/tagging.rb
117
+ - lib/acts_as_taggable_on/tags_helper.rb
118
+ - lib/generators/acts_as_taggable_on/migration/migration_generator.rb
119
+ - lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
120
+ - rails/init.rb
121
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
122
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
123
+ - spec/acts_as_taggable_on/tag_list_spec.rb
124
+ - spec/acts_as_taggable_on/tag_spec.rb
125
+ - spec/acts_as_taggable_on/taggable_spec.rb
126
+ - spec/acts_as_taggable_on/tagger_spec.rb
127
+ - spec/acts_as_taggable_on/tagging_spec.rb
128
+ - spec/acts_as_taggable_on/tags_helper_spec.rb
129
+ - spec/bm.rb
130
+ - spec/models.rb
131
+ - spec/schema.rb
132
+ - spec/spec.opts
133
+ - spec/spec_helper.rb
134
+ has_rdoc: true
135
+ homepage: http://github.com/mbleigh/acts-as-taggable-on
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project:
164
+ rubygems_version: 1.3.7
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.
168
+ test_files: []
169
+