litmus-acts-as-taggable-on 2.0.4

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 (39) hide show
  1. data/CHANGELOG +25 -0
  2. data/Gemfile +6 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +227 -0
  5. data/Rakefile +59 -0
  6. data/VERSION +1 -0
  7. data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +7 -0
  8. data/generators/acts_as_taggable_on_migration/templates/migration.rb +29 -0
  9. data/lib/acts-as-taggable-on.rb +32 -0
  10. data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +53 -0
  11. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +53 -0
  12. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +130 -0
  13. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +237 -0
  14. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +101 -0
  15. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +65 -0
  16. data/lib/acts_as_taggable_on/acts_as_tagger.rb +67 -0
  17. data/lib/acts_as_taggable_on/compatibility/Gemfile +6 -0
  18. data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +17 -0
  19. data/lib/acts_as_taggable_on/tag.rb +67 -0
  20. data/lib/acts_as_taggable_on/tag_list.rb +95 -0
  21. data/lib/acts_as_taggable_on/tagging.rb +23 -0
  22. data/lib/acts_as_taggable_on/tags_helper.rb +17 -0
  23. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +31 -0
  24. data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +28 -0
  25. data/rails/init.rb +1 -0
  26. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +266 -0
  27. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +114 -0
  28. data/spec/acts_as_taggable_on/tag_list_spec.rb +70 -0
  29. data/spec/acts_as_taggable_on/tag_spec.rb +115 -0
  30. data/spec/acts_as_taggable_on/taggable_spec.rb +306 -0
  31. data/spec/acts_as_taggable_on/tagger_spec.rb +91 -0
  32. data/spec/acts_as_taggable_on/tagging_spec.rb +31 -0
  33. data/spec/acts_as_taggable_on/tags_helper_spec.rb +28 -0
  34. data/spec/bm.rb +52 -0
  35. data/spec/models.rb +31 -0
  36. data/spec/schema.rb +43 -0
  37. data/spec/spec.opts +2 -0
  38. data/spec/spec_helper.rb +53 -0
  39. metadata +115 -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,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: litmus-acts-as-taggable-on
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease:
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: 2010-03-30 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: With ActsAsTaggableOn, you could tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality.
23
+ email: michael@intridea.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - CHANGELOG
32
+ - Gemfile
33
+ - MIT-LICENSE
34
+ - README.rdoc
35
+ - Rakefile
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
39
+ - lib/acts-as-taggable-on.rb
40
+ - lib/acts_as_taggable_on/acts_as_taggable_on.rb
41
+ - lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
42
+ - lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
43
+ - lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
44
+ - lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
45
+ - lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
46
+ - lib/acts_as_taggable_on/acts_as_tagger.rb
47
+ - lib/acts_as_taggable_on/compatibility/Gemfile
48
+ - lib/acts_as_taggable_on/compatibility/active_record_backports.rb
49
+ - lib/acts_as_taggable_on/tag.rb
50
+ - lib/acts_as_taggable_on/tag_list.rb
51
+ - lib/acts_as_taggable_on/tagging.rb
52
+ - lib/acts_as_taggable_on/tags_helper.rb
53
+ - lib/generators/acts_as_taggable_on/migration/migration_generator.rb
54
+ - lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
55
+ - rails/init.rb
56
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
57
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
58
+ - spec/acts_as_taggable_on/tag_list_spec.rb
59
+ - spec/acts_as_taggable_on/tag_spec.rb
60
+ - spec/acts_as_taggable_on/taggable_spec.rb
61
+ - spec/acts_as_taggable_on/tagger_spec.rb
62
+ - spec/acts_as_taggable_on/tagging_spec.rb
63
+ - spec/acts_as_taggable_on/tags_helper_spec.rb
64
+ - spec/bm.rb
65
+ - spec/models.rb
66
+ - spec/schema.rb
67
+ - spec/spec.opts
68
+ - spec/spec_helper.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/mbleigh/acts-as-taggable-on
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.5.0
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.
103
+ test_files:
104
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
105
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
106
+ - spec/acts_as_taggable_on/tag_list_spec.rb
107
+ - spec/acts_as_taggable_on/tag_spec.rb
108
+ - spec/acts_as_taggable_on/taggable_spec.rb
109
+ - spec/acts_as_taggable_on/tagger_spec.rb
110
+ - spec/acts_as_taggable_on/tagging_spec.rb
111
+ - spec/acts_as_taggable_on/tags_helper_spec.rb
112
+ - spec/bm.rb
113
+ - spec/models.rb
114
+ - spec/schema.rb
115
+ - spec/spec_helper.rb