acts-as-taggable-on 3.1.1 → 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 +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +9 -7
- data/Appraisals +13 -8
- data/CHANGELOG.md +27 -7
- data/Gemfile +1 -2
- data/README.md +36 -19
- data/Rakefile +5 -17
- data/UPGRADING.md +6 -0
- data/acts-as-taggable-on.gemspec +15 -15
- data/db/migrate/1_acts_as_taggable_on_migration.rb +3 -3
- data/db/migrate/2_add_missing_unique_indices.rb +3 -5
- data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +1 -1
- 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 +23 -21
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +2 -4
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +29 -20
- data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +11 -10
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +103 -85
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +5 -12
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +11 -11
- data/lib/acts_as_taggable_on/engine.rb +0 -1
- data/lib/acts_as_taggable_on/tag.rb +24 -19
- data/lib/acts_as_taggable_on/tag_list.rb +97 -22
- data/lib/acts_as_taggable_on/taggable.rb +26 -30
- data/lib/acts_as_taggable_on/tagger.rb +30 -18
- data/lib/acts_as_taggable_on/tagging.rb +7 -8
- data/lib/acts_as_taggable_on/tags_helper.rb +1 -1
- data/lib/acts_as_taggable_on/utils.rb +57 -35
- data/lib/acts_as_taggable_on/version.rb +1 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +133 -138
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +55 -58
- data/spec/acts_as_taggable_on/caching_spec.rb +34 -35
- data/spec/acts_as_taggable_on/related_spec.rb +59 -113
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +118 -95
- data/spec/acts_as_taggable_on/tag_list_spec.rb +89 -57
- data/spec/acts_as_taggable_on/tag_spec.rb +129 -116
- data/spec/acts_as_taggable_on/taggable_spec.rb +539 -352
- data/spec/acts_as_taggable_on/tagger_spec.rb +81 -78
- data/spec/acts_as_taggable_on/tagging_spec.rb +13 -14
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +25 -25
- data/spec/acts_as_taggable_on/utils_spec.rb +7 -13
- 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/{models.rb → internal/app/models/models.rb} +34 -2
- 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/{database.yml.sample → internal/config/database.yml.sample} +2 -2
- data/spec/internal/db/schema.rb +97 -0
- data/spec/schema.rb +11 -0
- data/spec/spec_helper.rb +9 -62
- data/spec/support/array.rb +9 -0
- data/spec/support/database.rb +42 -0
- data/spec/support/database_cleaner.rb +21 -0
- metadata +105 -43
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -7
- data/spec/bm.rb +0 -52
|
@@ -1,141 +1,136 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
before(:each) do
|
|
6
|
-
clean_database!
|
|
7
|
-
end
|
|
4
|
+
describe 'Acts As Taggable On' do
|
|
8
5
|
|
|
9
6
|
it "should provide a class method 'taggable?' that is false for untaggable models" do
|
|
10
|
-
UntaggableModel.
|
|
7
|
+
expect(UntaggableModel).to_not be_taggable
|
|
11
8
|
end
|
|
12
9
|
|
|
13
|
-
describe
|
|
10
|
+
describe 'Taggable Method Generation To Preserve Order' do
|
|
14
11
|
before(:each) do
|
|
15
|
-
clean_database!
|
|
16
12
|
TaggableModel.tag_types = []
|
|
17
13
|
TaggableModel.preserve_tag_order = false
|
|
18
14
|
TaggableModel.acts_as_ordered_taggable_on(:ordered_tags)
|
|
19
|
-
@taggable = TaggableModel.new(:
|
|
15
|
+
@taggable = TaggableModel.new(name: 'Bob Jones')
|
|
20
16
|
end
|
|
21
17
|
|
|
22
18
|
it "should respond 'true' to preserve_tag_order?" do
|
|
23
|
-
@taggable.class.preserve_tag_order
|
|
19
|
+
expect(@taggable.class.preserve_tag_order?).to be_truthy
|
|
24
20
|
end
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
describe
|
|
23
|
+
describe 'Taggable Method Generation' do
|
|
28
24
|
before(:each) do
|
|
29
|
-
clean_database!
|
|
30
25
|
TaggableModel.tag_types = []
|
|
31
26
|
TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
|
|
32
|
-
@taggable = TaggableModel.new(:
|
|
27
|
+
@taggable = TaggableModel.new(name: 'Bob Jones')
|
|
33
28
|
end
|
|
34
29
|
|
|
35
30
|
it "should respond 'true' to taggable?" do
|
|
36
|
-
@taggable.class.
|
|
31
|
+
expect(@taggable.class).to be_taggable
|
|
37
32
|
end
|
|
38
33
|
|
|
39
|
-
it
|
|
40
|
-
@taggable.class.
|
|
34
|
+
it 'should create a class attribute for tag types' do
|
|
35
|
+
expect(@taggable.class).to respond_to(:tag_types)
|
|
41
36
|
end
|
|
42
37
|
|
|
43
|
-
it
|
|
44
|
-
@taggable.
|
|
38
|
+
it 'should create an instance attribute for tag types' do
|
|
39
|
+
expect(@taggable).to respond_to(:tag_types)
|
|
45
40
|
end
|
|
46
41
|
|
|
47
|
-
it
|
|
48
|
-
@taggable.tag_types.
|
|
42
|
+
it 'should have all tag types' do
|
|
43
|
+
expect(@taggable.tag_types).to eq([:tags, :languages, :skills, :needs, :offerings])
|
|
49
44
|
end
|
|
50
45
|
|
|
51
|
-
it
|
|
52
|
-
@taggable.class.
|
|
46
|
+
it 'should create a class attribute for preserve tag order' do
|
|
47
|
+
expect(@taggable.class).to respond_to(:preserve_tag_order?)
|
|
53
48
|
end
|
|
54
49
|
|
|
55
|
-
it
|
|
56
|
-
@taggable.
|
|
50
|
+
it 'should create an instance attribute for preserve tag order' do
|
|
51
|
+
expect(@taggable).to respond_to(:preserve_tag_order?)
|
|
57
52
|
end
|
|
58
53
|
|
|
59
54
|
it "should respond 'false' to preserve_tag_order?" do
|
|
60
|
-
@taggable.class.preserve_tag_order
|
|
55
|
+
expect(@taggable.class.preserve_tag_order?).to be_falsy
|
|
61
56
|
end
|
|
62
57
|
|
|
63
|
-
it
|
|
64
|
-
@taggable.
|
|
58
|
+
it 'should generate an association for each tag type' do
|
|
59
|
+
expect(@taggable).to respond_to(:tags, :skills, :languages)
|
|
65
60
|
end
|
|
66
61
|
|
|
67
|
-
it
|
|
68
|
-
TaggableModel.
|
|
62
|
+
it 'should add tagged_with and tag_counts to singleton' do
|
|
63
|
+
expect(TaggableModel).to respond_to(:tagged_with, :tag_counts)
|
|
69
64
|
end
|
|
70
65
|
|
|
71
|
-
it
|
|
72
|
-
@taggable.
|
|
73
|
-
@taggable.
|
|
66
|
+
it 'should generate a tag_list accessor/setter for each tag type' do
|
|
67
|
+
expect(@taggable).to respond_to(:tag_list, :skill_list, :language_list)
|
|
68
|
+
expect(@taggable).to respond_to(:tag_list=, :skill_list=, :language_list=)
|
|
74
69
|
end
|
|
75
70
|
|
|
76
|
-
it
|
|
77
|
-
@taggable.
|
|
71
|
+
it 'should generate a tag_list accessor, that includes owned tags, for each tag type' do
|
|
72
|
+
expect(@taggable).to respond_to(:all_tags_list, :all_skills_list, :all_languages_list)
|
|
78
73
|
end
|
|
79
74
|
end
|
|
80
75
|
|
|
81
|
-
describe
|
|
82
|
-
it
|
|
83
|
-
taggable = TaggableModel.create!(:
|
|
76
|
+
describe 'Reloading' do
|
|
77
|
+
it 'should save a model instantiated by Model.find' do
|
|
78
|
+
taggable = TaggableModel.create!(name: 'Taggable')
|
|
84
79
|
found_taggable = TaggableModel.find(taggable.id)
|
|
85
80
|
found_taggable.save
|
|
86
81
|
end
|
|
87
82
|
end
|
|
88
83
|
|
|
89
|
-
describe
|
|
90
|
-
it
|
|
91
|
-
taggable1 = TaggableModel.create!(:
|
|
92
|
-
taggable2 = TaggableModel.create!(:
|
|
93
|
-
taggable3 = TaggableModel.create!(:
|
|
84
|
+
describe 'Matching Contexts' do
|
|
85
|
+
it 'should find objects with tags of matching contexts' do
|
|
86
|
+
taggable1 = TaggableModel.create!(name: 'Taggable 1')
|
|
87
|
+
taggable2 = TaggableModel.create!(name: 'Taggable 2')
|
|
88
|
+
taggable3 = TaggableModel.create!(name: 'Taggable 3')
|
|
94
89
|
|
|
95
|
-
taggable1.offering_list =
|
|
90
|
+
taggable1.offering_list = 'one, two'
|
|
96
91
|
taggable1.save!
|
|
97
92
|
|
|
98
|
-
taggable2.need_list =
|
|
93
|
+
taggable2.need_list = 'one, two'
|
|
99
94
|
taggable2.save!
|
|
100
95
|
|
|
101
|
-
taggable3.offering_list =
|
|
96
|
+
taggable3.offering_list = 'one, two'
|
|
102
97
|
taggable3.save!
|
|
103
98
|
|
|
104
|
-
taggable1.find_matching_contexts(:offerings, :needs).
|
|
105
|
-
taggable1.find_matching_contexts(:offerings, :needs).
|
|
99
|
+
expect(taggable1.find_matching_contexts(:offerings, :needs)).to include(taggable2)
|
|
100
|
+
expect(taggable1.find_matching_contexts(:offerings, :needs)).to_not include(taggable3)
|
|
106
101
|
end
|
|
107
102
|
|
|
108
|
-
it
|
|
109
|
-
taggable1 = TaggableModel.create!(:
|
|
110
|
-
taggable2 = OtherTaggableModel.create!(:
|
|
111
|
-
taggable3 = OtherTaggableModel.create!(:
|
|
103
|
+
it 'should find other related objects with tags of matching contexts' do
|
|
104
|
+
taggable1 = TaggableModel.create!(name: 'Taggable 1')
|
|
105
|
+
taggable2 = OtherTaggableModel.create!(name: 'Taggable 2')
|
|
106
|
+
taggable3 = OtherTaggableModel.create!(name: 'Taggable 3')
|
|
112
107
|
|
|
113
|
-
taggable1.offering_list =
|
|
108
|
+
taggable1.offering_list = 'one, two'
|
|
114
109
|
taggable1.save
|
|
115
110
|
|
|
116
|
-
taggable2.need_list =
|
|
111
|
+
taggable2.need_list = 'one, two'
|
|
117
112
|
taggable2.save
|
|
118
113
|
|
|
119
|
-
taggable3.offering_list =
|
|
114
|
+
taggable3.offering_list = 'one, two'
|
|
120
115
|
taggable3.save
|
|
121
116
|
|
|
122
|
-
taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs).
|
|
123
|
-
taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs).
|
|
117
|
+
expect(taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs)).to include(taggable2)
|
|
118
|
+
expect(taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs)).to_not include(taggable3)
|
|
124
119
|
end
|
|
125
120
|
|
|
126
|
-
it
|
|
127
|
-
taggable1 = TaggableModel.create!(:
|
|
128
|
-
taggable2 = TaggableModel.create!(:
|
|
121
|
+
it 'should not include the object itself in the list of related objects with tags of matching contexts' do
|
|
122
|
+
taggable1 = TaggableModel.create!(name: 'Taggable 1')
|
|
123
|
+
taggable2 = TaggableModel.create!(name: 'Taggable 2')
|
|
129
124
|
|
|
130
|
-
taggable1.offering_list =
|
|
131
|
-
taggable1.need_list =
|
|
125
|
+
taggable1.offering_list = 'one, two'
|
|
126
|
+
taggable1.need_list = 'one, two'
|
|
132
127
|
taggable1.save
|
|
133
128
|
|
|
134
|
-
taggable2.need_list =
|
|
129
|
+
taggable2.need_list = 'one, two'
|
|
135
130
|
taggable2.save
|
|
136
131
|
|
|
137
|
-
taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).
|
|
138
|
-
taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).
|
|
132
|
+
expect(taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to include(taggable2)
|
|
133
|
+
expect(taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to_not include(taggable1)
|
|
139
134
|
end
|
|
140
135
|
|
|
141
136
|
end
|
|
@@ -143,121 +138,121 @@ describe "Acts As Taggable On" do
|
|
|
143
138
|
describe 'Tagging Contexts' do
|
|
144
139
|
it 'should eliminate duplicate tagging contexts ' do
|
|
145
140
|
TaggableModel.acts_as_taggable_on(:skills, :skills)
|
|
146
|
-
TaggableModel.tag_types.freq[:skills].
|
|
141
|
+
expect(TaggableModel.tag_types.freq[:skills]).to_not eq(3)
|
|
147
142
|
end
|
|
148
143
|
|
|
149
|
-
it
|
|
144
|
+
it 'should not contain embedded/nested arrays' do
|
|
150
145
|
TaggableModel.acts_as_taggable_on([:array], [:array])
|
|
151
|
-
TaggableModel.tag_types.freq[[:array]].
|
|
146
|
+
expect(TaggableModel.tag_types.freq[[:array]]).to eq(0)
|
|
152
147
|
end
|
|
153
148
|
|
|
154
|
-
it
|
|
149
|
+
it 'should _flatten_ the content of arrays' do
|
|
155
150
|
TaggableModel.acts_as_taggable_on([:array], [:array])
|
|
156
|
-
TaggableModel.tag_types.freq[:array].
|
|
151
|
+
expect(TaggableModel.tag_types.freq[:array]).to eq(1)
|
|
157
152
|
end
|
|
158
153
|
|
|
159
|
-
it
|
|
160
|
-
|
|
161
|
-
TaggableModel.acts_as_taggable_on
|
|
162
|
-
}.
|
|
154
|
+
it 'should not raise an error when passed nil' do
|
|
155
|
+
expect(-> {
|
|
156
|
+
TaggableModel.acts_as_taggable_on
|
|
157
|
+
}).to_not raise_error
|
|
163
158
|
end
|
|
164
159
|
|
|
165
|
-
it
|
|
166
|
-
|
|
160
|
+
it 'should not raise an error when passed [nil]' do
|
|
161
|
+
expect(-> {
|
|
167
162
|
TaggableModel.acts_as_taggable_on([nil])
|
|
168
|
-
}.
|
|
163
|
+
}).to_not raise_error
|
|
169
164
|
end
|
|
170
165
|
end
|
|
171
166
|
|
|
172
167
|
context 'when tagging context ends in an "s" when singular (ex. "status", "glass", etc.)' do
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
168
|
+
describe 'caching' do
|
|
169
|
+
before { @taggable = OtherCachedModel.new(name: 'John Smith') }
|
|
170
|
+
subject { @taggable }
|
|
171
|
+
|
|
172
|
+
it { should respond_to(:save_cached_tag_list) }
|
|
173
|
+
its(:cached_language_list) { should be_blank }
|
|
174
|
+
its(:cached_status_list) { should be_blank }
|
|
175
|
+
its(:cached_glass_list) { should be_blank }
|
|
176
|
+
|
|
177
|
+
context 'language taggings cache after update' do
|
|
178
|
+
before { @taggable.update_attributes(language_list: 'ruby, .net') }
|
|
179
|
+
subject { @taggable }
|
|
180
|
+
|
|
181
|
+
its(:language_list) { should == ['ruby', '.net']}
|
|
182
|
+
its(:cached_language_list) { should == 'ruby, .net' } # passes
|
|
183
|
+
its(:instance_variables) { should include((RUBY_VERSION < '1.9' ? '@language_list' : :@language_list)) }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
context 'status taggings cache after update' do
|
|
187
|
+
before { @taggable.update_attributes(status_list: 'happy, married') }
|
|
188
|
+
subject { @taggable }
|
|
189
|
+
|
|
190
|
+
its(:status_list) { should == ['happy', 'married'] }
|
|
191
|
+
its(:cached_status_list) { should == 'happy, married' } # fails
|
|
192
|
+
its(:cached_status_list) { should_not == '' } # fails, is blank
|
|
193
|
+
its(:instance_variables) { should include((RUBY_VERSION < '1.9' ? '@status_list' : :@status_list)) }
|
|
194
|
+
its(:instance_variables) { should_not include((RUBY_VERSION < '1.9' ? '@statu_list' : :@statu_list)) } # fails, note: one "s"
|
|
195
|
+
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
context 'glass taggings cache after update' do
|
|
199
|
+
before do
|
|
200
|
+
@taggable.update_attributes(glass_list: 'rectangle, aviator')
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
subject { @taggable }
|
|
204
|
+
its(:glass_list) { should == ['rectangle', 'aviator'] }
|
|
205
|
+
its(:cached_glass_list) { should == 'rectangle, aviator' } # fails
|
|
206
|
+
its(:cached_glass_list) { should_not == '' } # fails, is blank
|
|
207
|
+
if RUBY_VERSION < '1.9'
|
|
208
|
+
its(:instance_variables) { should include('@glass_list') }
|
|
209
|
+
its(:instance_variables) { should_not include('@glas_list') } # fails, note: one "s"
|
|
210
|
+
else
|
|
211
|
+
its(:instance_variables) { should include(:@glass_list) }
|
|
212
|
+
its(:instance_variables) { should_not include(:@glas_list) } # fails, note: one "s"
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
end
|
|
216
|
+
end
|
|
222
217
|
end
|
|
223
218
|
|
|
224
|
-
describe
|
|
219
|
+
describe 'taggings' do
|
|
225
220
|
before(:each) do
|
|
226
|
-
@taggable = TaggableModel.new(:
|
|
221
|
+
@taggable = TaggableModel.new(name: 'Art Kram')
|
|
227
222
|
end
|
|
228
223
|
|
|
229
|
-
it 'should return
|
|
230
|
-
@taggable.taggings.
|
|
224
|
+
it 'should return no taggings' do
|
|
225
|
+
expect(@taggable.taggings).to be_empty
|
|
231
226
|
end
|
|
232
227
|
end
|
|
233
228
|
|
|
234
|
-
describe
|
|
229
|
+
describe '@@remove_unused_tags' do
|
|
235
230
|
before do
|
|
236
|
-
@taggable = TaggableModel.create(:
|
|
237
|
-
@tag = ActsAsTaggableOn::Tag.create(:
|
|
231
|
+
@taggable = TaggableModel.create(name: 'Bob Jones')
|
|
232
|
+
@tag = ActsAsTaggableOn::Tag.create(name: 'awesome')
|
|
238
233
|
|
|
239
|
-
@tagging = ActsAsTaggableOn::Tagging.create(:
|
|
234
|
+
@tagging = ActsAsTaggableOn::Tagging.create(taggable: @taggable, tag: @tag, context: 'tags')
|
|
240
235
|
end
|
|
241
236
|
|
|
242
|
-
context
|
|
237
|
+
context 'if set to true' do
|
|
243
238
|
before do
|
|
244
239
|
ActsAsTaggableOn.remove_unused_tags = true
|
|
245
240
|
end
|
|
246
241
|
|
|
247
|
-
it
|
|
242
|
+
it 'should remove unused tags after removing taggings' do
|
|
248
243
|
@tagging.destroy
|
|
249
|
-
ActsAsTaggableOn::Tag.find_by_name(
|
|
244
|
+
expect(ActsAsTaggableOn::Tag.find_by_name('awesome')).to be_nil
|
|
250
245
|
end
|
|
251
246
|
end
|
|
252
247
|
|
|
253
|
-
context
|
|
248
|
+
context 'if set to false' do
|
|
254
249
|
before do
|
|
255
250
|
ActsAsTaggableOn.remove_unused_tags = false
|
|
256
251
|
end
|
|
257
252
|
|
|
258
|
-
it
|
|
253
|
+
it 'should not remove unused tags after removing taggings' do
|
|
259
254
|
@tagging.destroy
|
|
260
|
-
ActsAsTaggableOn::Tag.find_by_name(
|
|
255
|
+
expect(ActsAsTaggableOn::Tag.find_by_name('awesome')).to eq(@tag)
|
|
261
256
|
end
|
|
262
257
|
end
|
|
263
258
|
end
|
|
@@ -1,112 +1,109 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
before(:each) do
|
|
5
|
-
clean_database!
|
|
6
|
-
end
|
|
3
|
+
describe 'acts_as_tagger' do
|
|
7
4
|
|
|
8
|
-
describe
|
|
5
|
+
describe 'Tagger Method Generation' do
|
|
9
6
|
before(:each) do
|
|
10
7
|
@tagger = User.new
|
|
11
8
|
end
|
|
12
9
|
|
|
13
|
-
it
|
|
14
|
-
User.
|
|
10
|
+
it 'should add #is_tagger? query method to the class-side' do
|
|
11
|
+
expect(User).to respond_to(:is_tagger?)
|
|
15
12
|
end
|
|
16
13
|
|
|
17
|
-
it
|
|
18
|
-
User.is_tagger
|
|
14
|
+
it 'should return true from the class-side #is_tagger?' do
|
|
15
|
+
expect(User.is_tagger?).to be_truthy
|
|
19
16
|
end
|
|
20
17
|
|
|
21
|
-
it
|
|
22
|
-
ActiveRecord::Base.is_tagger
|
|
18
|
+
it 'should return false from the base #is_tagger?' do
|
|
19
|
+
expect(ActiveRecord::Base.is_tagger?).to be_falsy
|
|
23
20
|
end
|
|
24
21
|
|
|
25
|
-
it
|
|
26
|
-
@tagger.
|
|
22
|
+
it 'should add #is_tagger? query method to the singleton' do
|
|
23
|
+
expect(@tagger).to respond_to(:is_tagger?)
|
|
27
24
|
end
|
|
28
25
|
|
|
29
|
-
it
|
|
30
|
-
@tagger.
|
|
26
|
+
it 'should add #tag method on the instance-side' do
|
|
27
|
+
expect(@tagger).to respond_to(:tag)
|
|
31
28
|
end
|
|
32
29
|
|
|
33
|
-
it
|
|
34
|
-
@tagger.
|
|
30
|
+
it 'should generate an association for #owned_taggings and #owned_tags' do
|
|
31
|
+
expect(@tagger).to respond_to(:owned_taggings, :owned_tags)
|
|
35
32
|
end
|
|
36
33
|
end
|
|
37
34
|
|
|
38
|
-
describe
|
|
35
|
+
describe '#tag' do
|
|
39
36
|
context 'when called with a non-existent tag context' do
|
|
40
37
|
before(:each) do
|
|
41
38
|
@tagger = User.new
|
|
42
|
-
@taggable = TaggableModel.new(:
|
|
39
|
+
@taggable = TaggableModel.new(name: 'Richard Prior')
|
|
43
40
|
end
|
|
44
41
|
|
|
45
|
-
it
|
|
46
|
-
@taggable.tag_list_on(:foo).
|
|
47
|
-
|
|
48
|
-
@tagger.tag(@taggable, :
|
|
49
|
-
}.
|
|
42
|
+
it 'should by default not throw an exception ' do
|
|
43
|
+
expect(@taggable.tag_list_on(:foo)).to be_empty
|
|
44
|
+
expect(-> {
|
|
45
|
+
@tagger.tag(@taggable, with: 'this, and, that', on: :foo)
|
|
46
|
+
}).to_not raise_error
|
|
50
47
|
end
|
|
51
48
|
|
|
52
49
|
it 'should by default create the tag context on-the-fly' do
|
|
53
|
-
@taggable.tag_list_on(:here_ond_now).
|
|
54
|
-
@tagger.tag(@taggable, :
|
|
55
|
-
@taggable.tag_list_on(:here_ond_now).
|
|
56
|
-
@taggable.all_tags_list_on(:here_ond_now).
|
|
50
|
+
expect(@taggable.tag_list_on(:here_ond_now)).to be_empty
|
|
51
|
+
@tagger.tag(@taggable, with: 'that', on: :here_ond_now)
|
|
52
|
+
expect(@taggable.tag_list_on(:here_ond_now)).to_not include('that')
|
|
53
|
+
expect(@taggable.all_tags_list_on(:here_ond_now)).to include('that')
|
|
57
54
|
end
|
|
58
55
|
|
|
59
|
-
it
|
|
56
|
+
it 'should show all the tag list when both public and owned tags exist' do
|
|
60
57
|
@taggable.tag_list = 'ruby, python'
|
|
61
|
-
@tagger.tag(@taggable, :
|
|
62
|
-
@taggable.all_tags_on(:tags).map(&:name).sort.
|
|
58
|
+
@tagger.tag(@taggable, with: 'java, lisp', on: :tags)
|
|
59
|
+
expect(@taggable.all_tags_on(:tags).map(&:name).sort).to eq(%w(ruby python java lisp).sort)
|
|
63
60
|
end
|
|
64
61
|
|
|
65
|
-
it
|
|
62
|
+
it 'should not add owned tags to the common list' do
|
|
66
63
|
@taggable.tag_list = 'ruby, python'
|
|
67
|
-
@tagger.tag(@taggable, :
|
|
68
|
-
@taggable.tag_list.
|
|
69
|
-
@tagger.tag(@taggable, :
|
|
70
|
-
@taggable.tag_list.
|
|
64
|
+
@tagger.tag(@taggable, with: 'java, lisp', on: :tags)
|
|
65
|
+
expect(@taggable.tag_list).to eq(%w(ruby python))
|
|
66
|
+
@tagger.tag(@taggable, with: '', on: :tags)
|
|
67
|
+
expect(@taggable.tag_list).to eq(%w(ruby python))
|
|
71
68
|
end
|
|
72
69
|
|
|
73
|
-
it
|
|
74
|
-
@taggable.tag_list_on(:foo_boo).
|
|
75
|
-
|
|
76
|
-
@tagger.tag(@taggable, :
|
|
77
|
-
}.
|
|
70
|
+
it 'should throw an exception when the default is over-ridden' do
|
|
71
|
+
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
|
|
72
|
+
expect(-> {
|
|
73
|
+
@tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false)
|
|
74
|
+
}).to raise_error
|
|
78
75
|
end
|
|
79
76
|
|
|
80
|
-
it
|
|
81
|
-
@taggable.tag_list_on(:foo_boo).
|
|
82
|
-
@tagger.tag(@taggable, :
|
|
83
|
-
|
|
77
|
+
it 'should not create the tag context on-the-fly when the default is over-ridden' do
|
|
78
|
+
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
|
|
79
|
+
@tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false) rescue
|
|
80
|
+
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
|
|
84
81
|
end
|
|
85
82
|
end
|
|
86
83
|
|
|
87
84
|
describe "when called by multiple tagger's" do
|
|
88
85
|
before(:each) do
|
|
89
|
-
@user_x = User.create(:
|
|
90
|
-
@user_y = User.create(:
|
|
91
|
-
@taggable = TaggableModel.create(:
|
|
86
|
+
@user_x = User.create(name: 'User X')
|
|
87
|
+
@user_y = User.create(name: 'User Y')
|
|
88
|
+
@taggable = TaggableModel.create(name: 'acts_as_taggable_on', tag_list: 'plugin')
|
|
92
89
|
|
|
93
|
-
@user_x.tag(@taggable, :
|
|
94
|
-
@user_y.tag(@taggable, :
|
|
90
|
+
@user_x.tag(@taggable, with: 'ruby, rails', on: :tags)
|
|
91
|
+
@user_y.tag(@taggable, with: 'ruby, plugin', on: :tags)
|
|
95
92
|
|
|
96
|
-
@user_y.tag(@taggable, :
|
|
97
|
-
@user_y.tag(@taggable, :
|
|
93
|
+
@user_y.tag(@taggable, with: '', on: :tags)
|
|
94
|
+
@user_y.tag(@taggable, with: '', on: :tags)
|
|
98
95
|
end
|
|
99
96
|
|
|
100
|
-
it
|
|
101
|
-
@user_y.owned_tags.
|
|
97
|
+
it 'should delete owned tags' do
|
|
98
|
+
expect(@user_y.owned_tags).to be_empty
|
|
102
99
|
end
|
|
103
100
|
|
|
104
|
-
it
|
|
105
|
-
@user_x.owned_tags.
|
|
101
|
+
it 'should not delete other taggers tags' do
|
|
102
|
+
expect(@user_x.owned_tags.count).to eq(2)
|
|
106
103
|
end
|
|
107
104
|
|
|
108
|
-
it
|
|
109
|
-
@taggable.all_tags_list_on(:tags).
|
|
105
|
+
it 'should not delete original tags' do
|
|
106
|
+
expect(@taggable.all_tags_list_on(:tags)).to include('plugin')
|
|
110
107
|
end
|
|
111
108
|
end
|
|
112
109
|
end
|