acts-as-taggable-on 2.0.0 → 3.2.2

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 (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +23 -0
  4. data/Appraisals +20 -0
  5. data/CHANGELOG.md +112 -0
  6. data/CONTRIBUTING.md +44 -0
  7. data/Gemfile +9 -5
  8. data/Guardfile +5 -0
  9. data/{MIT-LICENSE → LICENSE.md} +1 -1
  10. data/README.md +385 -0
  11. data/Rakefile +13 -53
  12. data/UPGRADING.md +13 -0
  13. data/acts-as-taggable-on.gemspec +38 -0
  14. data/{lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb → db/migrate/1_acts_as_taggable_on_migration.rb} +5 -3
  15. data/db/migrate/2_add_missing_unique_indices.rb +19 -0
  16. data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +14 -0
  17. data/gemfiles/activerecord_3.2.gemfile +15 -0
  18. data/gemfiles/activerecord_4.0.gemfile +15 -0
  19. data/gemfiles/activerecord_4.1.gemfile +15 -0
  20. data/gemfiles/activerecord_edge.gemfile +16 -0
  21. data/lib/acts-as-taggable-on.rb +65 -22
  22. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +53 -24
  23. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +120 -42
  24. data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +35 -0
  25. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +309 -124
  26. data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +36 -0
  27. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +96 -72
  28. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +43 -36
  29. data/lib/acts_as_taggable_on/engine.rb +5 -0
  30. data/lib/acts_as_taggable_on/tag.rb +133 -63
  31. data/lib/acts_as_taggable_on/tag_list.rb +162 -81
  32. data/lib/acts_as_taggable_on/taggable.rb +101 -0
  33. data/lib/acts_as_taggable_on/{acts_as_tagger.rb → tagger.rb} +34 -13
  34. data/lib/acts_as_taggable_on/tagging.rb +28 -18
  35. data/lib/acts_as_taggable_on/tags_helper.rb +12 -14
  36. data/lib/acts_as_taggable_on/utils.rb +62 -0
  37. data/lib/acts_as_taggable_on/version.rb +4 -0
  38. data/lib/acts_as_taggable_on.rb +6 -0
  39. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +189 -195
  40. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +78 -81
  41. data/spec/acts_as_taggable_on/caching_spec.rb +76 -0
  42. data/spec/acts_as_taggable_on/related_spec.rb +89 -0
  43. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +210 -0
  44. data/spec/acts_as_taggable_on/tag_list_spec.rb +149 -61
  45. data/spec/acts_as_taggable_on/tag_spec.rb +245 -65
  46. data/spec/acts_as_taggable_on/taggable_spec.rb +776 -187
  47. data/spec/acts_as_taggable_on/tagger_spec.rb +119 -70
  48. data/spec/acts_as_taggable_on/tagging_spec.rb +17 -21
  49. data/spec/acts_as_taggable_on/tags_helper_spec.rb +38 -22
  50. data/spec/acts_as_taggable_on/utils_spec.rb +15 -0
  51. data/spec/internal/app/models/altered_inheriting_taggable_model.rb +3 -0
  52. data/spec/internal/app/models/cached_model.rb +3 -0
  53. data/spec/internal/app/models/cached_model_with_array.rb +5 -0
  54. data/spec/internal/app/models/company.rb +15 -0
  55. data/spec/internal/app/models/inheriting_taggable_model.rb +2 -0
  56. data/spec/internal/app/models/market.rb +2 -0
  57. data/spec/internal/app/models/models.rb +90 -0
  58. data/spec/internal/app/models/non_standard_id_taggable_model.rb +8 -0
  59. data/spec/internal/app/models/ordered_taggable_model.rb +4 -0
  60. data/spec/internal/app/models/other_cached_model.rb +3 -0
  61. data/spec/internal/app/models/other_taggable_model.rb +4 -0
  62. data/spec/internal/app/models/student.rb +2 -0
  63. data/spec/internal/app/models/taggable_model.rb +13 -0
  64. data/spec/internal/app/models/untaggable_model.rb +3 -0
  65. data/spec/internal/app/models/user.rb +3 -0
  66. data/spec/internal/config/database.yml.sample +19 -0
  67. data/spec/internal/db/schema.rb +97 -0
  68. data/spec/schema.rb +57 -18
  69. data/spec/spec_helper.rb +12 -47
  70. data/spec/support/array.rb +9 -0
  71. data/spec/support/database.rb +42 -0
  72. data/spec/support/database_cleaner.rb +21 -0
  73. metadata +286 -63
  74. data/CHANGELOG +0 -25
  75. data/README.rdoc +0 -221
  76. data/VERSION +0 -1
  77. data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +0 -7
  78. data/generators/acts_as_taggable_on_migration/templates/migration.rb +0 -29
  79. data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +0 -53
  80. data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -6
  81. data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
  82. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -31
  83. data/rails/init.rb +0 -1
  84. data/spec/bm.rb +0 -52
  85. data/spec/models.rb +0 -30
  86. /data/{spec/spec.opts → .rspec} +0 -0
@@ -1,91 +1,140 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe "Tagger" do
3
+ describe 'Tagger' do
4
4
  before(:each) do
5
- clean_database!
6
- @user = TaggableUser.create
7
- @taggable = TaggableModel.create(:name => "Bob Jones")
5
+ @user = User.create
6
+ @taggable = TaggableModel.create(name: 'Bob Jones')
8
7
  end
9
8
 
10
- it "should have taggings" do
11
- @user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
12
- @user.owned_taggings.size == 2
9
+
10
+
11
+ it 'should have taggings' do
12
+ @user.tag(@taggable, with: 'ruby,scheme', on: :tags)
13
+ expect(@user.owned_taggings.size).to eq(2)
14
+ end
15
+
16
+ it 'should have tags' do
17
+ @user.tag(@taggable, with: 'ruby,scheme', on: :tags)
18
+ expect(@user.owned_tags.size).to eq(2)
19
+ end
20
+
21
+ it 'should scope objects returned by tagged_with by owners' do
22
+ @taggable2 = TaggableModel.create(name: 'Jim Jones')
23
+ @taggable3 = TaggableModel.create(name: 'Jane Doe')
24
+
25
+ @user2 = User.new
26
+ @user.tag(@taggable, with: 'ruby, scheme', on: :tags)
27
+ @user2.tag(@taggable2, with: 'ruby, scheme', on: :tags)
28
+ @user2.tag(@taggable3, with: 'ruby, scheme', on: :tags)
29
+
30
+ expect(TaggableModel.tagged_with(%w(ruby scheme), owned_by: @user).count).to eq(1)
31
+ expect(TaggableModel.tagged_with(%w(ruby scheme), owned_by: @user2).count).to eq(2)
13
32
  end
14
33
 
15
- it "should have tags" do
16
- @user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
17
- @user.owned_tags.size == 2
34
+ it 'only returns objects tagged by owned_by when any is true' do
35
+ @user2 = User.new
36
+ @taggable2 = TaggableModel.create(name: 'Jim Jones')
37
+ @taggable3 = TaggableModel.create(name: 'Jane Doe')
38
+
39
+ @user.tag(@taggable, with: 'ruby', on: :tags)
40
+ @user.tag(@taggable2, with: 'java', on: :tags)
41
+ @user2.tag(@taggable3, with: 'ruby', on: :tags)
42
+
43
+ tags = TaggableModel.tagged_with(%w(ruby java), owned_by: @user, any: true)
44
+ expect(tags).to include(@taggable, @taggable2)
45
+ expect(tags.size).to eq(2)
46
+
47
+ end
48
+
49
+ it 'only returns objects tagged by owned_by when exclude is true' do
50
+ @user2 = User.new
51
+ @taggable2 = TaggableModel.create(name: 'Jim Jones')
52
+ @taggable3 = TaggableModel.create(name: 'Jane Doe')
53
+
54
+ @user.tag(@taggable, with: 'ruby', on: :tags)
55
+ @user.tag(@taggable2, with: 'java', on: :tags)
56
+ @user2.tag(@taggable3, with: 'java', on: :tags)
57
+
58
+ tags = TaggableModel.tagged_with(%w(ruby), owned_by: @user, exclude: true)
59
+ expect(tags).to eq([@taggable2])
18
60
  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)
61
+
62
+ it 'should not overlap tags from different taggers' do
63
+ @user2 = User.new
64
+ expect(-> {
65
+ @user.tag(@taggable, with: 'ruby, scheme', on: :tags)
66
+ @user2.tag(@taggable, with: 'java, python, lisp, ruby', on: :tags)
67
+ }).to change(ActsAsTaggableOn::Tagging, :count).by(6)
26
68
 
27
69
  [@user, @user2, @taggable].each(&:reload)
28
70
 
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
71
+ expect(@user.owned_tags.map(&:name).sort).to eq(%w(ruby scheme).sort)
72
+ expect(@user2.owned_tags.map(&:name).sort).to eq(%w(java python lisp ruby).sort)
73
+
74
+ expect(@taggable.tags_from(@user).sort).to eq(%w(ruby scheme).sort)
75
+ expect(@taggable.tags_from(@user2).sort).to eq(%w(java lisp python ruby).sort)
76
+
77
+ expect(@taggable.all_tags_list.sort).to eq(%w(ruby scheme java python lisp).sort)
78
+ expect(@taggable.all_tags_on(:tags).size).to eq(5)
37
79
  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)
80
+
81
+ it 'should not lose tags from different taggers' do
82
+ @user2 = User.create
83
+ @user2.tag(@taggable, with: 'java, python, lisp, ruby', on: :tags)
84
+ @user.tag(@taggable, with: 'ruby, scheme', on: :tags)
85
+
86
+ expect(-> {
87
+ @user2.tag(@taggable, with: 'java, python, lisp', on: :tags)
88
+ }).to change(ActsAsTaggableOn::Tagging, :count).by(-1)
47
89
 
48
90
  [@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
91
+
92
+ expect(@taggable.tags_from(@user).sort).to eq(%w(ruby scheme).sort)
93
+ expect(@taggable.tags_from(@user2).sort).to eq(%w(java python lisp).sort)
94
+
95
+ expect(@taggable.all_tags_list.sort).to eq(%w(ruby scheme java python lisp).sort)
96
+ expect(@taggable.all_tags_on(:tags).length).to eq(5)
55
97
  end
56
98
 
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)
99
+ it 'should not lose tags' do
100
+ @user2 = User.create
62
101
 
63
- lambda {
64
- @user2.tag(@taggable, :with => 'epic', :on => :tags)
65
- }.should change(Tagging, :count).by(-1)
102
+ @user.tag(@taggable, with: 'awesome', on: :tags)
103
+ @user2.tag(@taggable, with: 'awesome, epic', on: :tags)
66
104
 
67
- @taggable.reload
68
- @taggable.all_tags_list.should include('awesome')
69
- @taggable.all_tags_list.should include('epic')
105
+ expect(-> {
106
+ @user2.tag(@taggable, with: 'epic', on: :tags)
107
+ }).to change(ActsAsTaggableOn::Tagging, :count).by(-1)
108
+
109
+ @taggable.reload
110
+ expect(@taggable.all_tags_list).to include('awesome')
111
+ expect(@taggable.all_tags_list).to include('epic')
70
112
  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
-
113
+
114
+ it 'should not lose tags' do
115
+ @taggable.update_attributes(tag_list: 'ruby')
116
+ @user.tag(@taggable, with: 'ruby, scheme', on: :tags)
117
+
76
118
  [@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
119
+ expect(@taggable.tag_list).to eq(%w(ruby))
120
+ expect(@taggable.all_tags_list.sort).to eq(%w(ruby scheme).sort)
121
+
122
+ expect(-> {
123
+ @taggable.update_attributes(tag_list: '')
124
+ }).to change(ActsAsTaggableOn::Tagging, :count).by(-1)
125
+
126
+ expect(@taggable.tag_list).to be_empty
127
+ expect(@taggable.all_tags_list.sort).to eq(%w(ruby scheme).sort)
128
+ end
129
+
130
+ it 'is tagger' do
131
+ expect(@user.is_tagger?).to be_truthy
132
+ end
133
+
134
+ it 'should skip save if skip_save is passed as option' do
135
+ expect(-> {
136
+ @user.tag(@taggable, with: 'epic', on: :tags, skip_save: true)
137
+ }).to_not change(ActsAsTaggableOn::Tagging, :count)
86
138
  end
87
139
 
88
- it "is tagger" do
89
- @user.is_tagger?.should(be_true)
90
- end
91
- end
140
+ end
@@ -1,31 +1,27 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Tagging do
3
+ describe ActsAsTaggableOn::Tagging do
4
4
  before(:each) do
5
- clean_database!
6
- @tagging = Tagging.new
5
+ @tagging = ActsAsTaggableOn::Tagging.new
7
6
  end
8
7
 
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"
8
+ it 'should not be valid with a invalid tag' do
9
+ @tagging.taggable = TaggableModel.create(name: 'Bob Jones')
10
+ @tagging.tag = ActsAsTaggableOn::Tag.new(name: '')
11
+ @tagging.context = 'tags'
13
12
 
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
13
+ expect(@tagging).to_not be_valid
14
+
15
+ expect(@tagging.errors[:tag_id]).to eq(['can\'t be blank'])
21
16
  end
22
17
 
23
- it "should not create duplicate taggings" do
24
- @taggable = TaggableModel.create(:name => "Bob Jones")
25
- @tag = Tag.create(:name => "awesome")
18
+ it 'should not create duplicate taggings' do
19
+ @taggable = TaggableModel.create(name: 'Bob Jones')
20
+ @tag = ActsAsTaggableOn::Tag.create(name: 'awesome')
26
21
 
27
- lambda {
28
- 2.times { Tagging.create(:taggable => @taggable, :tag => @tag, :context => 'tags') }
29
- }.should change(Tagging, :count).by(1)
22
+ expect(-> {
23
+ 2.times { ActsAsTaggableOn::Tagging.create(taggable: @taggable, tag: @tag, context: 'tags') }
24
+ }).to change(ActsAsTaggableOn::Tagging, :count).by(1)
30
25
  end
26
+
31
27
  end
@@ -1,28 +1,44 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe TagsHelper do
3
+ describe ActsAsTaggableOn::TagsHelper do
4
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
5
+ @bob = TaggableModel.create(name: 'Bob Jones', language_list: 'ruby, php')
6
+ @tom = TaggableModel.create(name: 'Tom Marley', language_list: 'ruby, java')
7
+ @eve = TaggableModel.create(name: 'Eve Nodd', language_list: 'ruby, c++')
8
+
9
+ @helper =
10
+ class Helper
11
+ include ActsAsTaggableOn::TagsHelper
12
+ end.new
13
+ end
14
+
15
+
16
+ it 'should yield the proper css classes' do
17
+ tags = {}
18
+
19
+ @helper.tag_cloud(TaggableModel.tag_counts_on(:languages), %w(sucky awesome)) do |tag, css_class|
20
+ tags[tag.name] = css_class
21
+ end
22
+
23
+ expect(tags['ruby']).to eq('awesome')
24
+ expect(tags['java']).to eq('sucky')
25
+ expect(tags['c++']).to eq('sucky')
26
+ expect(tags['php']).to eq('sucky')
14
27
  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|
28
+
29
+ it 'should handle tags with zero counts (build for empty)' do
30
+ ActsAsTaggableOn::Tag.create(name: 'php')
31
+ ActsAsTaggableOn::Tag.create(name: 'java')
32
+ ActsAsTaggableOn::Tag.create(name: 'c++')
33
+
34
+ tags = {}
35
+
36
+ @helper.tag_cloud(ActsAsTaggableOn::Tag.all, %w(sucky awesome)) do |tag, css_class|
20
37
  tags[tag.name] = css_class
21
38
  end
22
-
23
- tags["ruby"].should == "awesome"
24
- tags["java"].should == "sucky"
25
- tags["c++"].should == "sucky"
26
- tags["php"].should == "sucky"
39
+
40
+ expect(tags['java']).to eq('sucky')
41
+ expect(tags['c++']).to eq('sucky')
42
+ expect(tags['php']).to eq('sucky')
27
43
  end
28
- end
44
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActsAsTaggableOn::Utils do
4
+ describe '#like_operator' do
5
+ it 'should return \'ILIKE\' when the adapter is PostgreSQL' do
6
+ allow(ActsAsTaggableOn::Utils.connection).to receive(:adapter_name) { 'PostgreSQL' }
7
+ expect(ActsAsTaggableOn::Utils.like_operator).to eq('ILIKE')
8
+ end
9
+
10
+ it 'should return \'LIKE\' when the adapter is not PostgreSQL' do
11
+ allow(ActsAsTaggableOn::Utils.connection).to receive(:adapter_name) { 'MySQL' }
12
+ expect(ActsAsTaggableOn::Utils.like_operator).to eq('LIKE')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class AlteredInheritingTaggableModel < TaggableModel
2
+ acts_as_taggable_on :parts
3
+ end
@@ -0,0 +1,3 @@
1
+ class CachedModel < ActiveRecord::Base
2
+ acts_as_taggable
3
+ end
@@ -0,0 +1,5 @@
1
+ if ActsAsTaggableOn::Utils.using_postgresql?
2
+ class CachedModelWithArray < ActiveRecord::Base
3
+ acts_as_taggable
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class Company < ActiveRecord::Base
2
+ acts_as_taggable_on :locations, :markets
3
+
4
+ has_many :markets, :through => :market_taggings, :source => :tag
5
+
6
+ private
7
+
8
+ def find_or_create_tags_from_list_with_context(tag_list, context)
9
+ if context.to_sym == :markets
10
+ Market.find_or_create_all_with_like_by_name(tag_list)
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ class InheritingTaggableModel < TaggableModel
2
+ end
@@ -0,0 +1,2 @@
1
+ class Market < ActsAsTaggableOn::Tag
2
+ end
@@ -0,0 +1,90 @@
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
+
8
+ attr_reader :tag_list_submethod_called
9
+
10
+ def tag_list=(v)
11
+ @tag_list_submethod_called = true
12
+ super
13
+ end
14
+ end
15
+
16
+ class CachedModel < ActiveRecord::Base
17
+ acts_as_taggable
18
+ end
19
+
20
+ class OtherCachedModel < ActiveRecord::Base
21
+ acts_as_taggable_on :languages, :statuses, :glasses
22
+ end
23
+
24
+ class OtherTaggableModel < ActiveRecord::Base
25
+ acts_as_taggable_on :tags, :languages
26
+ acts_as_taggable_on :needs, :offerings
27
+ end
28
+
29
+ class InheritingTaggableModel < TaggableModel
30
+ end
31
+
32
+ class AlteredInheritingTaggableModel < TaggableModel
33
+ acts_as_taggable_on :parts
34
+ end
35
+
36
+ class Market < ActsAsTaggableOn::Tag
37
+ end
38
+
39
+ class Company < ActiveRecord::Base
40
+ acts_as_taggable_on :locations, :markets
41
+
42
+ has_many :markets, :through => :market_taggings, :source => :tag
43
+
44
+ private
45
+
46
+ def find_or_create_tags_from_list_with_context(tag_list, context)
47
+ if context.to_sym == :markets
48
+ Market.find_or_create_all_with_like_by_name(tag_list)
49
+ else
50
+ super
51
+ end
52
+ end
53
+ end
54
+
55
+ class User < ActiveRecord::Base
56
+ acts_as_tagger
57
+ end
58
+
59
+ class Student < User
60
+ end
61
+
62
+ class UntaggableModel < ActiveRecord::Base
63
+ belongs_to :taggable_model
64
+ end
65
+
66
+ class NonStandardIdTaggableModel < ActiveRecord::Base
67
+ self.primary_key = :an_id
68
+ acts_as_taggable
69
+ acts_as_taggable_on :languages
70
+ acts_as_taggable_on :skills
71
+ acts_as_taggable_on :needs, :offerings
72
+ has_many :untaggable_models
73
+ end
74
+
75
+ class OrderedTaggableModel < ActiveRecord::Base
76
+ acts_as_ordered_taggable
77
+ acts_as_ordered_taggable_on :colours
78
+ end
79
+
80
+ if ActsAsTaggableOn::Utils.using_postgresql?
81
+ class CachedModelWithArray < ActiveRecord::Base
82
+ acts_as_taggable
83
+ end
84
+ if ActsAsTaggableOn::Utils.postgresql_support_json?
85
+ class TaggableModelWithJson < ActiveRecord::Base
86
+ acts_as_taggable
87
+ acts_as_taggable_on :skills
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,8 @@
1
+ class NonStandardIdTaggableModel < ActiveRecord::Base
2
+ self.primary_key = 'an_id'
3
+ acts_as_taggable
4
+ acts_as_taggable_on :languages
5
+ acts_as_taggable_on :skills
6
+ acts_as_taggable_on :needs, :offerings
7
+ has_many :untaggable_models
8
+ end
@@ -0,0 +1,4 @@
1
+ class OrderedTaggableModel < ActiveRecord::Base
2
+ acts_as_ordered_taggable
3
+ acts_as_ordered_taggable_on :colours
4
+ end
@@ -0,0 +1,3 @@
1
+ class OtherCachedModel < ActiveRecord::Base
2
+ acts_as_taggable_on :languages, :statuses, :glasses
3
+ end
@@ -0,0 +1,4 @@
1
+ class OtherTaggableModel < ActiveRecord::Base
2
+ acts_as_taggable_on :tags, :languages
3
+ acts_as_taggable_on :needs, :offerings
4
+ end
@@ -0,0 +1,2 @@
1
+ class Student < User
2
+ end
@@ -0,0 +1,13 @@
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
+
8
+ attr_reader :tag_list_submethod_called
9
+ def tag_list=(v)
10
+ @tag_list_submethod_called = true
11
+ super
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class UntaggableModel < ActiveRecord::Base
2
+ belongs_to :taggable_model
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_tagger
3
+ end
@@ -0,0 +1,19 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: ':memory:'
4
+
5
+ mysql:
6
+ adapter: mysql2
7
+ host: localhost
8
+ username: root
9
+ password:
10
+ database: acts_as_taggable_on
11
+ charset: utf8
12
+
13
+ postgresql:
14
+ adapter: postgresql
15
+ hostname: localhost
16
+ username: postgres
17
+ password:
18
+ database: acts_as_taggable_on
19
+ encoding: utf8
@@ -0,0 +1,97 @@
1
+ ActiveRecord::Schema.define version: 0 do
2
+ create_table :tags, force: true do |t|
3
+ t.string :name
4
+ t.integer :taggings_count, default: 0
5
+ t.string :type
6
+ end
7
+ add_index 'tags', ['name'], name: 'index_tags_on_name', unique: true
8
+
9
+ create_table :taggings, force: true do |t|
10
+ t.references :tag
11
+
12
+ # You should make sure that the column created is
13
+ # long enough to store the required class names.
14
+ t.references :taggable, polymorphic: true
15
+ t.references :tagger, polymorphic: true
16
+
17
+ # Limit is created to prevent MySQL error on index
18
+ # length for MyISAM table type: http://bit.ly/vgW2Ql
19
+ t.string :context, limit: 128
20
+
21
+ t.datetime :created_at
22
+ end
23
+ add_index 'taggings',
24
+ ['tag_id', 'taggable_id', 'taggable_type', 'context', 'tagger_id', 'tagger_type'],
25
+ unique: true, name: 'taggings_idx'
26
+
27
+ # above copied from
28
+ # generators/acts_as_taggable_on/migration/migration_generator
29
+
30
+ create_table :taggable_models, force: true do |t|
31
+ t.column :name, :string
32
+ t.column :type, :string
33
+ end
34
+
35
+ create_table :non_standard_id_taggable_models, primary_key: 'an_id', force: true do |t|
36
+ t.column :name, :string
37
+ t.column :type, :string
38
+ end
39
+
40
+ create_table :untaggable_models, force: true do |t|
41
+ t.column :taggable_model_id, :integer
42
+ t.column :name, :string
43
+ end
44
+
45
+ create_table :cached_models, force: true do |t|
46
+ t.column :name, :string
47
+ t.column :type, :string
48
+ t.column :cached_tag_list, :string
49
+ end
50
+
51
+ create_table :other_cached_models, force: true do |t|
52
+ t.column :name, :string
53
+ t.column :type, :string
54
+ t.column :cached_language_list, :string
55
+ t.column :cached_status_list, :string
56
+ t.column :cached_glass_list, :string
57
+ end
58
+
59
+ create_table :companies, force: true do |t|
60
+ t.column :name, :string
61
+ end
62
+
63
+ create_table :users, force: true do |t|
64
+ t.column :name, :string
65
+ end
66
+
67
+ create_table :other_taggable_models, force: true do |t|
68
+ t.column :name, :string
69
+ t.column :type, :string
70
+ end
71
+
72
+ create_table :ordered_taggable_models, force: true do |t|
73
+ t.column :name, :string
74
+ t.column :type, :string
75
+ end
76
+
77
+
78
+ # Special cases for postgresql
79
+ if ActsAsTaggableOn::Utils.using_postgresql?
80
+
81
+ create_table :other_cached_with_array_models, force: true do |t|
82
+ t.column :name, :string
83
+ t.column :type, :string
84
+ t.column :cached_language_list, :string, array: true
85
+ t.column :cached_status_list, :string, array: true
86
+ t.column :cached_glass_list, :string, array: true
87
+ end
88
+
89
+ if ActsAsTaggableOn::Utils.postgresql_support_json?
90
+ create_table :taggable_model_with_jsons, :force => true do |t|
91
+ t.column :name, :string
92
+ t.column :type, :string
93
+ t.column :opts, :json
94
+ end
95
+ end
96
+ end
97
+ end