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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +23 -0
- data/Appraisals +20 -0
- data/CHANGELOG.md +112 -0
- data/CONTRIBUTING.md +44 -0
- data/Gemfile +9 -5
- data/Guardfile +5 -0
- data/{MIT-LICENSE → LICENSE.md} +1 -1
- data/README.md +385 -0
- data/Rakefile +13 -53
- data/UPGRADING.md +13 -0
- data/acts-as-taggable-on.gemspec +38 -0
- data/{lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb → db/migrate/1_acts_as_taggable_on_migration.rb} +5 -3
- data/db/migrate/2_add_missing_unique_indices.rb +19 -0
- data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +14 -0
- data/gemfiles/activerecord_3.2.gemfile +15 -0
- data/gemfiles/activerecord_4.0.gemfile +15 -0
- data/gemfiles/activerecord_4.1.gemfile +15 -0
- data/gemfiles/activerecord_edge.gemfile +16 -0
- data/lib/acts-as-taggable-on.rb +65 -22
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +53 -24
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +120 -42
- data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +35 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +309 -124
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +36 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +96 -72
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +43 -36
- data/lib/acts_as_taggable_on/engine.rb +5 -0
- data/lib/acts_as_taggable_on/tag.rb +133 -63
- data/lib/acts_as_taggable_on/tag_list.rb +162 -81
- data/lib/acts_as_taggable_on/taggable.rb +101 -0
- data/lib/acts_as_taggable_on/{acts_as_tagger.rb → tagger.rb} +34 -13
- data/lib/acts_as_taggable_on/tagging.rb +28 -18
- data/lib/acts_as_taggable_on/tags_helper.rb +12 -14
- data/lib/acts_as_taggable_on/utils.rb +62 -0
- data/lib/acts_as_taggable_on/version.rb +4 -0
- data/lib/acts_as_taggable_on.rb +6 -0
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +189 -195
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +78 -81
- data/spec/acts_as_taggable_on/caching_spec.rb +76 -0
- data/spec/acts_as_taggable_on/related_spec.rb +89 -0
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +210 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +149 -61
- data/spec/acts_as_taggable_on/tag_spec.rb +245 -65
- data/spec/acts_as_taggable_on/taggable_spec.rb +776 -187
- data/spec/acts_as_taggable_on/tagger_spec.rb +119 -70
- data/spec/acts_as_taggable_on/tagging_spec.rb +17 -21
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +38 -22
- data/spec/acts_as_taggable_on/utils_spec.rb +15 -0
- data/spec/internal/app/models/altered_inheriting_taggable_model.rb +3 -0
- data/spec/internal/app/models/cached_model.rb +3 -0
- data/spec/internal/app/models/cached_model_with_array.rb +5 -0
- data/spec/internal/app/models/company.rb +15 -0
- data/spec/internal/app/models/inheriting_taggable_model.rb +2 -0
- data/spec/internal/app/models/market.rb +2 -0
- data/spec/internal/app/models/models.rb +90 -0
- data/spec/internal/app/models/non_standard_id_taggable_model.rb +8 -0
- data/spec/internal/app/models/ordered_taggable_model.rb +4 -0
- data/spec/internal/app/models/other_cached_model.rb +3 -0
- data/spec/internal/app/models/other_taggable_model.rb +4 -0
- data/spec/internal/app/models/student.rb +2 -0
- data/spec/internal/app/models/taggable_model.rb +13 -0
- data/spec/internal/app/models/untaggable_model.rb +3 -0
- data/spec/internal/app/models/user.rb +3 -0
- data/spec/internal/config/database.yml.sample +19 -0
- data/spec/internal/db/schema.rb +97 -0
- data/spec/schema.rb +57 -18
- data/spec/spec_helper.rb +12 -47
- data/spec/support/array.rb +9 -0
- data/spec/support/database.rb +42 -0
- data/spec/support/database_cleaner.rb +21 -0
- metadata +286 -63
- data/CHANGELOG +0 -25
- data/README.rdoc +0 -221
- data/VERSION +0 -1
- data/generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb +0 -7
- data/generators/acts_as_taggable_on_migration/templates/migration.rb +0 -29
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +0 -53
- data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -6
- data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
- data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -31
- data/rails/init.rb +0 -1
- data/spec/bm.rb +0 -52
- data/spec/models.rb +0 -30
- /data/{spec/spec.opts → .rspec} +0 -0
|
@@ -1,91 +1,140 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'Tagger' do
|
|
4
4
|
before(:each) do
|
|
5
|
-
|
|
6
|
-
@
|
|
7
|
-
@taggable = TaggableModel.create(:name => "Bob Jones")
|
|
5
|
+
@user = User.create
|
|
6
|
+
@taggable = TaggableModel.create(name: 'Bob Jones')
|
|
8
7
|
end
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
16
|
-
@
|
|
17
|
-
@
|
|
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
|
|
21
|
-
@user2 =
|
|
22
|
-
|
|
23
|
-
@user.tag(@taggable, :
|
|
24
|
-
@user2.tag(@taggable, :
|
|
25
|
-
}.
|
|
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.
|
|
30
|
-
@user2.owned_tags.map(&:name).sort.
|
|
31
|
-
|
|
32
|
-
@taggable.tags_from(@user).sort.
|
|
33
|
-
@taggable.tags_from(@user2).sort.
|
|
34
|
-
|
|
35
|
-
@taggable.all_tags_list.sort.
|
|
36
|
-
@taggable.all_tags_on(:tags).size.
|
|
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
|
|
40
|
-
@user2 =
|
|
41
|
-
@user2.tag(@taggable, :
|
|
42
|
-
@user.tag(@taggable, :
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@user2.tag(@taggable, :
|
|
46
|
-
}.
|
|
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.
|
|
51
|
-
@taggable.tags_from(@user2).sort.
|
|
52
|
-
|
|
53
|
-
@taggable.all_tags_list.sort.
|
|
54
|
-
@taggable.all_tags_on(:tags).length.
|
|
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
|
|
58
|
-
@user2 =
|
|
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
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
73
|
-
@taggable.update_attributes(:
|
|
74
|
-
@user.tag(@taggable, :
|
|
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.
|
|
78
|
-
@taggable.all_tags_list.sort.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@taggable.update_attributes(:
|
|
82
|
-
}.
|
|
83
|
-
|
|
84
|
-
@taggable.tag_list.
|
|
85
|
-
@taggable.all_tags_list.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
|
-
|
|
89
|
-
@user.is_tagger?.should(be_true)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
140
|
+
end
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Tagging do
|
|
3
|
+
describe ActsAsTaggableOn::Tagging do
|
|
4
4
|
before(:each) do
|
|
5
|
-
|
|
6
|
-
@tagging = Tagging.new
|
|
5
|
+
@tagging = ActsAsTaggableOn::Tagging.new
|
|
7
6
|
end
|
|
8
7
|
|
|
9
|
-
it
|
|
10
|
-
@tagging.taggable = TaggableModel.create(:
|
|
11
|
-
@tagging.tag = Tag.new(:
|
|
12
|
-
@tagging.context =
|
|
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.
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
24
|
-
@taggable = TaggableModel.create(:
|
|
25
|
-
@tag = Tag.create(:
|
|
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
|
-
|
|
28
|
-
2.times { Tagging.create(:
|
|
29
|
-
}.
|
|
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
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe TagsHelper do
|
|
3
|
+
describe ActsAsTaggableOn::TagsHelper do
|
|
4
4
|
before(:each) do
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@
|
|
8
|
-
|
|
9
|
-
@
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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[
|
|
24
|
-
tags[
|
|
25
|
-
tags[
|
|
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,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,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,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,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
|