acts-as-taggable-on 0.0.0

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.
Files changed (38) hide show
  1. data/CHANGELOG +25 -0
  2. data/Gemfile +6 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +212 -0
  5. data/Rakefile +59 -0
  6. data/VERSION +1 -0
  7. data/lib/acts-as-taggable-on.rb +30 -0
  8. data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +41 -0
  9. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +56 -0
  10. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +97 -0
  11. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +220 -0
  12. data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +29 -0
  13. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +101 -0
  14. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +64 -0
  15. data/lib/acts_as_taggable_on/acts_as_tagger.rb +47 -0
  16. data/lib/acts_as_taggable_on/compatibility/Gemfile +6 -0
  17. data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +17 -0
  18. data/lib/acts_as_taggable_on/tag.rb +65 -0
  19. data/lib/acts_as_taggable_on/tag_list.rb +95 -0
  20. data/lib/acts_as_taggable_on/tagging.rb +23 -0
  21. data/lib/acts_as_taggable_on/tags_helper.rb +17 -0
  22. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +31 -0
  23. data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +28 -0
  24. data/rails/init.rb +1 -0
  25. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +266 -0
  26. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +114 -0
  27. data/spec/acts_as_taggable_on/tag_list_spec.rb +70 -0
  28. data/spec/acts_as_taggable_on/tag_spec.rb +115 -0
  29. data/spec/acts_as_taggable_on/taggable_spec.rb +277 -0
  30. data/spec/acts_as_taggable_on/tagger_spec.rb +75 -0
  31. data/spec/acts_as_taggable_on/tagging_spec.rb +31 -0
  32. data/spec/acts_as_taggable_on/tags_helper_spec.rb +28 -0
  33. data/spec/bm.rb +52 -0
  34. data/spec/models.rb +36 -0
  35. data/spec/schema.rb +42 -0
  36. data/spec/spec.opts +2 -0
  37. data/spec/spec_helper.rb +47 -0
  38. metadata +109 -0
@@ -0,0 +1,75 @@
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 "is tagger" do
73
+ @user.is_tagger?.should(be_true)
74
+ end
75
+ 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,36 @@
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
+ end
7
+
8
+ class CachedModel < ActiveRecord::Base
9
+ acts_as_taggable
10
+ end
11
+
12
+ class OtherTaggableModel < ActiveRecord::Base
13
+ acts_as_taggable_on :tags, :languages
14
+ acts_as_taggable_on :needs, :offerings
15
+ end
16
+
17
+ class InheritingTaggableModel < TaggableModel
18
+ end
19
+
20
+ class AlteredInheritingTaggableModel < TaggableModel
21
+ acts_as_taggable_on :parts
22
+ end
23
+
24
+ class TaggableUser < ActiveRecord::Base
25
+ acts_as_tagger
26
+ end
27
+
28
+ 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
@@ -0,0 +1,42 @@
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 :cached_models, :force => true do |t|
25
+ t.column :name, :string
26
+ t.column :type, :string
27
+ t.column :cached_tag_list, :string
28
+ end
29
+
30
+ create_table :taggable_users, :force => true do |t|
31
+ t.column :name, :string
32
+ end
33
+
34
+ create_table :other_taggable_models, :force => true do |t|
35
+ t.column :name, :string
36
+ t.column :type, :string
37
+ end
38
+
39
+ create_table :untaggable_models, :force => true do |t|
40
+ t.column :name, :string
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --backtrace
@@ -0,0 +1,47 @@
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
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => TEST_DATABASE_FILE
32
+
33
+ ActiveRecord::Base.silence do
34
+ ActiveRecord::Migration.verbose = false
35
+ load(File.dirname(__FILE__) + '/schema.rb')
36
+ load(File.dirname(__FILE__) + '/models.rb')
37
+ end
38
+
39
+ def clean_database!
40
+ models = [Tag, Tagging, TaggableModel, OtherTaggableModel, InheritingTaggableModel,
41
+ AlteredInheritingTaggableModel, TaggableUser, UntaggableModel]
42
+ models.each do |model|
43
+ model.destroy_all
44
+ end
45
+ end
46
+
47
+ clean_database!
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts-as-taggable-on
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Michael Bleigh
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-25 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: With ActsAsTaggableOn, you could tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality.
22
+ email: michael@intridea.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - CHANGELOG
31
+ - Gemfile
32
+ - MIT-LICENSE
33
+ - README.rdoc
34
+ - Rakefile
35
+ - VERSION
36
+ - lib/acts-as-taggable-on.rb
37
+ - lib/acts_as_taggable_on/acts_as_taggable_on.rb
38
+ - lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
39
+ - lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
40
+ - lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
41
+ - lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
42
+ - lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
43
+ - lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
44
+ - lib/acts_as_taggable_on/acts_as_tagger.rb
45
+ - lib/acts_as_taggable_on/compatibility/Gemfile
46
+ - lib/acts_as_taggable_on/compatibility/active_record_backports.rb
47
+ - lib/acts_as_taggable_on/tag.rb
48
+ - lib/acts_as_taggable_on/tag_list.rb
49
+ - lib/acts_as_taggable_on/tagging.rb
50
+ - lib/acts_as_taggable_on/tags_helper.rb
51
+ - lib/generators/acts_as_taggable_on/migration/migration_generator.rb
52
+ - lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
53
+ - rails/init.rb
54
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
55
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
56
+ - spec/acts_as_taggable_on/tag_list_spec.rb
57
+ - spec/acts_as_taggable_on/tag_spec.rb
58
+ - spec/acts_as_taggable_on/taggable_spec.rb
59
+ - spec/acts_as_taggable_on/tagger_spec.rb
60
+ - spec/acts_as_taggable_on/tagging_spec.rb
61
+ - spec/acts_as_taggable_on/tags_helper_spec.rb
62
+ - spec/bm.rb
63
+ - spec/models.rb
64
+ - spec/schema.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/mbleigh/acts-as-taggable-on
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.6
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.
97
+ test_files:
98
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
99
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
100
+ - spec/acts_as_taggable_on/tag_list_spec.rb
101
+ - spec/acts_as_taggable_on/tag_spec.rb
102
+ - spec/acts_as_taggable_on/taggable_spec.rb
103
+ - spec/acts_as_taggable_on/tagger_spec.rb
104
+ - spec/acts_as_taggable_on/tagging_spec.rb
105
+ - spec/acts_as_taggable_on/tags_helper_spec.rb
106
+ - spec/bm.rb
107
+ - spec/models.rb
108
+ - spec/schema.rb
109
+ - spec/spec_helper.rb