acts-as-taggable-on 2.3.3 → 2.4.1
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 +3 -3
- data/Appraisals +7 -0
- data/Gemfile +3 -1
- data/{MIT-LICENSE → LICENSE.md} +1 -1
- data/README.md +303 -0
- data/Rakefile +2 -2
- data/acts-as-taggable-on.gemspec +25 -18
- data/gemfiles/rails_3.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +8 -0
- data/lib/acts-as-taggable-on.rb +5 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +2 -2
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +64 -7
- data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +34 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +86 -55
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +3 -3
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +24 -15
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +32 -21
- data/lib/acts_as_taggable_on/tag.rb +37 -15
- data/lib/acts_as_taggable_on/tag_list.rb +2 -2
- data/lib/acts_as_taggable_on/taggable.rb +10 -7
- data/lib/acts_as_taggable_on/tagger.rb +12 -3
- data/lib/acts_as_taggable_on/tagging.rb +2 -2
- data/lib/acts_as_taggable_on/tags_helper.rb +0 -2
- data/lib/{acts-as-taggable-on → acts_as_taggable_on}/version.rb +1 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +1 -183
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +8 -8
- data/spec/acts_as_taggable_on/related_spec.rb +143 -0
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +187 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +4 -4
- data/spec/acts_as_taggable_on/tag_spec.rb +61 -3
- data/spec/acts_as_taggable_on/taggable_spec.rb +178 -98
- data/spec/acts_as_taggable_on/tagger_spec.rb +32 -33
- data/spec/acts_as_taggable_on/tagging_spec.rb +1 -1
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +2 -2
- data/spec/acts_as_taggable_on/utils_spec.rb +2 -2
- data/spec/models.rb +8 -2
- data/spec/schema.rb +1 -1
- data/spec/spec_helper.rb +7 -4
- metadata +101 -56
- data/CHANGELOG +0 -35
- data/README.rdoc +0 -244
- data/rails/init.rb +0 -1
- data/uninstall.rb +0 -1
@@ -8,7 +8,7 @@ module ActsAsTaggableOn
|
|
8
8
|
:taggable_id,
|
9
9
|
:tagger,
|
10
10
|
:tagger_type,
|
11
|
-
:tagger_id
|
11
|
+
:tagger_id if defined?(ActiveModel::MassAssignmentSecurity)
|
12
12
|
|
13
13
|
belongs_to :tag, :class_name => 'ActsAsTaggableOn::Tag'
|
14
14
|
belongs_to :taggable, :polymorphic => true
|
@@ -31,4 +31,4 @@ module ActsAsTaggableOn
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Acts As Taggable On" do
|
4
4
|
before(:each) do
|
@@ -77,23 +77,6 @@ describe "Acts As Taggable On" do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe "Single Table Inheritance" do
|
81
|
-
before do
|
82
|
-
@taggable = TaggableModel.new(:name => "taggable")
|
83
|
-
@inherited_same = InheritingTaggableModel.new(:name => "inherited same")
|
84
|
-
@inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should pass on tag contexts to STI-inherited models" do
|
88
|
-
@inherited_same.should respond_to(:tag_list, :skill_list, :language_list)
|
89
|
-
@inherited_different.should respond_to(:tag_list, :skill_list, :language_list)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should have tag contexts added in altered STI models" do
|
93
|
-
@inherited_different.should respond_to(:part_list)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
80
|
describe "Reloading" do
|
98
81
|
it "should save a model instantiated by Model.find" do
|
99
82
|
taggable = TaggableModel.create!(:name => "Taggable")
|
@@ -102,128 +85,6 @@ describe "Acts As Taggable On" do
|
|
102
85
|
end
|
103
86
|
end
|
104
87
|
|
105
|
-
describe "Related Objects" do
|
106
|
-
it "should find related objects based on tag names on context" do
|
107
|
-
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
108
|
-
taggable2 = TaggableModel.create!(:name => "Taggable 2")
|
109
|
-
taggable3 = TaggableModel.create!(:name => "Taggable 3")
|
110
|
-
|
111
|
-
taggable1.tag_list = "one, two"
|
112
|
-
taggable1.save
|
113
|
-
|
114
|
-
taggable2.tag_list = "three, four"
|
115
|
-
taggable2.save
|
116
|
-
|
117
|
-
taggable3.tag_list = "one, four"
|
118
|
-
taggable3.save
|
119
|
-
|
120
|
-
taggable1.find_related_tags.should include(taggable3)
|
121
|
-
taggable1.find_related_tags.should_not include(taggable2)
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should find related objects based on tag names on context - non standard id" do
|
125
|
-
taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
|
126
|
-
taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
|
127
|
-
taggable3 = NonStandardIdTaggableModel.create!(:name => "Taggable 3")
|
128
|
-
|
129
|
-
taggable1.tag_list = "one, two"
|
130
|
-
taggable1.save
|
131
|
-
|
132
|
-
taggable2.tag_list = "three, four"
|
133
|
-
taggable2.save
|
134
|
-
|
135
|
-
taggable3.tag_list = "one, four"
|
136
|
-
taggable3.save
|
137
|
-
|
138
|
-
taggable1.find_related_tags.should include(taggable3)
|
139
|
-
taggable1.find_related_tags.should_not include(taggable2)
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should find other related objects based on tag names on context" do
|
143
|
-
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
144
|
-
taggable2 = OtherTaggableModel.create!(:name => "Taggable 2")
|
145
|
-
taggable3 = OtherTaggableModel.create!(:name => "Taggable 3")
|
146
|
-
|
147
|
-
taggable1.tag_list = "one, two"
|
148
|
-
taggable1.save
|
149
|
-
|
150
|
-
taggable2.tag_list = "three, four"
|
151
|
-
taggable2.save
|
152
|
-
|
153
|
-
taggable3.tag_list = "one, four"
|
154
|
-
taggable3.save
|
155
|
-
|
156
|
-
taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
|
157
|
-
taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should not include the object itself in the list of related objects" do
|
161
|
-
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
162
|
-
taggable2 = TaggableModel.create!(:name => "Taggable 2")
|
163
|
-
|
164
|
-
taggable1.tag_list = "one"
|
165
|
-
taggable1.save
|
166
|
-
|
167
|
-
taggable2.tag_list = "one, two"
|
168
|
-
taggable2.save
|
169
|
-
|
170
|
-
taggable1.find_related_tags.should include(taggable2)
|
171
|
-
taggable1.find_related_tags.should_not include(taggable1)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should not include the object itself in the list of related objects - non standard id" do
|
175
|
-
taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
|
176
|
-
taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
|
177
|
-
|
178
|
-
taggable1.tag_list = "one"
|
179
|
-
taggable1.save
|
180
|
-
|
181
|
-
taggable2.tag_list = "one, two"
|
182
|
-
taggable2.save
|
183
|
-
|
184
|
-
taggable1.find_related_tags.should include(taggable2)
|
185
|
-
taggable1.find_related_tags.should_not include(taggable1)
|
186
|
-
end
|
187
|
-
|
188
|
-
context "Inherited Models" do
|
189
|
-
before do
|
190
|
-
@taggable1 = InheritingTaggableModel.create!(:name => "InheritingTaggable 1")
|
191
|
-
@taggable2 = InheritingTaggableModel.create!(:name => "InheritingTaggable 2")
|
192
|
-
@taggable3 = InheritingTaggableModel.create!(:name => "InheritingTaggable 3")
|
193
|
-
@taggable4 = TaggableModel.create!(:name => "Taggable 4")
|
194
|
-
|
195
|
-
@taggable1.tag_list = "one, two"
|
196
|
-
@taggable1.save
|
197
|
-
|
198
|
-
@taggable2.tag_list = "three, four"
|
199
|
-
@taggable2.save
|
200
|
-
|
201
|
-
@taggable3.tag_list = "one, four"
|
202
|
-
@taggable3.save
|
203
|
-
|
204
|
-
@taggable4.tag_list = "one, two, three, four"
|
205
|
-
@taggable4.save
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should find related objects based on tag names on context" do
|
209
|
-
@taggable1.find_related_tags.should include(@taggable3)
|
210
|
-
@taggable1.find_related_tags.should_not include(@taggable2)
|
211
|
-
@taggable1.find_related_tags.should_not include(@taggable4)
|
212
|
-
|
213
|
-
@taggable1.find_related_tags_for(TaggableModel).should include(@taggable3)
|
214
|
-
@taggable1.find_related_tags_for(TaggableModel).should_not include(@taggable2)
|
215
|
-
@taggable1.find_related_tags_for(TaggableModel).should include(@taggable4)
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should not include the object itself in the list of related objects" do
|
219
|
-
@taggable1.find_related_tags.should_not include(@taggable1)
|
220
|
-
@taggable1.find_related_tags_for(InheritingTaggableModel).should_not include(@taggable1)
|
221
|
-
@taggable1.find_related_tags_for(TaggableModel).should_not include(@taggable1)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
88
|
describe "Matching Contexts" do
|
228
89
|
it "should find objects with tags of matching contexts" do
|
229
90
|
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
@@ -276,49 +137,6 @@ describe "Acts As Taggable On" do
|
|
276
137
|
taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(taggable1)
|
277
138
|
end
|
278
139
|
|
279
|
-
context "Inherited Models" do
|
280
|
-
before do
|
281
|
-
@taggable1 = InheritingTaggableModel.create!(:name => "InheritingTaggable 1")
|
282
|
-
@taggable2 = InheritingTaggableModel.create!(:name => "InheritingTaggable 2")
|
283
|
-
@taggable3 = InheritingTaggableModel.create!(:name => "InheritingTaggable 3")
|
284
|
-
@taggable4 = InheritingTaggableModel.create!(:name => "InheritingTaggable 4")
|
285
|
-
@taggable5 = TaggableModel.create!(:name => "Taggable 5")
|
286
|
-
|
287
|
-
@taggable1.offering_list = "one, two"
|
288
|
-
@taggable1.need_list = "one, two"
|
289
|
-
@taggable1.save!
|
290
|
-
|
291
|
-
@taggable2.need_list = "one, two"
|
292
|
-
@taggable2.save!
|
293
|
-
|
294
|
-
@taggable3.offering_list = "one, two"
|
295
|
-
@taggable3.save!
|
296
|
-
|
297
|
-
@taggable4.tag_list = "one, two, three, four"
|
298
|
-
@taggable4.save!
|
299
|
-
|
300
|
-
@taggable5.need_list = "one, two"
|
301
|
-
@taggable5.save!
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should find objects with tags of matching contexts" do
|
305
|
-
@taggable1.find_matching_contexts(:offerings, :needs).should include(@taggable2)
|
306
|
-
@taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable3)
|
307
|
-
@taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable4)
|
308
|
-
@taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable5)
|
309
|
-
|
310
|
-
@taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(@taggable2)
|
311
|
-
@taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(@taggable3)
|
312
|
-
@taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(@taggable4)
|
313
|
-
@taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(@taggable5)
|
314
|
-
end
|
315
|
-
|
316
|
-
it "should not include the object itself in the list of related objects with tags of matching contexts" do
|
317
|
-
@taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable1)
|
318
|
-
@taggable1.find_matching_contexts_for(InheritingTaggableModel, :offerings, :needs).should_not include(@taggable1)
|
319
|
-
@taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(@taggable1)
|
320
|
-
end
|
321
|
-
end
|
322
140
|
end
|
323
141
|
|
324
142
|
describe 'Tagging Contexts' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "acts_as_tagger" do
|
4
4
|
before(:each) do
|
@@ -7,15 +7,15 @@ describe "acts_as_tagger" do
|
|
7
7
|
|
8
8
|
describe "Tagger Method Generation" do
|
9
9
|
before(:each) do
|
10
|
-
@tagger =
|
10
|
+
@tagger = User.new
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should add #is_tagger? query method to the class-side" do
|
14
|
-
|
14
|
+
User.should respond_to(:is_tagger?)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should return true from the class-side #is_tagger?" do
|
18
|
-
|
18
|
+
User.is_tagger?.should be_true
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return false from the base #is_tagger?" do
|
@@ -38,7 +38,7 @@ describe "acts_as_tagger" do
|
|
38
38
|
describe "#tag" do
|
39
39
|
context 'when called with a non-existent tag context' do
|
40
40
|
before(:each) do
|
41
|
-
@tagger =
|
41
|
+
@tagger = User.new
|
42
42
|
@taggable = TaggableModel.new(:name=>"Richard Prior")
|
43
43
|
end
|
44
44
|
|
@@ -86,8 +86,8 @@ describe "acts_as_tagger" do
|
|
86
86
|
|
87
87
|
describe "when called by multiple tagger's" do
|
88
88
|
before(:each) do
|
89
|
-
@user_x =
|
90
|
-
@user_y =
|
89
|
+
@user_x = User.create(:name => "User X")
|
90
|
+
@user_y = User.create(:name => "User Y")
|
91
91
|
@taggable = TaggableModel.create(:name => 'acts_as_taggable_on', :tag_list => 'plugin')
|
92
92
|
|
93
93
|
@user_x.tag(@taggable, :with => 'ruby, rails', :on => :tags)
|
@@ -111,4 +111,4 @@ describe "acts_as_tagger" do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
end
|
114
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Acts As Taggable On" do
|
4
|
+
before(:each) do
|
5
|
+
clean_database!
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Related Objects" do
|
9
|
+
it "should find related objects based on tag names on context" do
|
10
|
+
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
11
|
+
taggable2 = TaggableModel.create!(:name => "Taggable 2")
|
12
|
+
taggable3 = TaggableModel.create!(:name => "Taggable 3")
|
13
|
+
|
14
|
+
taggable1.tag_list = "one, two"
|
15
|
+
taggable1.save
|
16
|
+
|
17
|
+
taggable2.tag_list = "three, four"
|
18
|
+
taggable2.save
|
19
|
+
|
20
|
+
taggable3.tag_list = "one, four"
|
21
|
+
taggable3.save
|
22
|
+
|
23
|
+
taggable1.find_related_tags.should include(taggable3)
|
24
|
+
taggable1.find_related_tags.should_not include(taggable2)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "finds related tags for ordered taggable on" do
|
28
|
+
taggable1 = OrderedTaggableModel.create!(:name => "Taggable 1")
|
29
|
+
taggable2 = OrderedTaggableModel.create!(:name => "Taggable 2")
|
30
|
+
taggable3 = OrderedTaggableModel.create!(:name => "Taggable 3")
|
31
|
+
|
32
|
+
taggable1.colour_list = "one, two"
|
33
|
+
taggable1.save
|
34
|
+
|
35
|
+
taggable2.colour_list = "three, four"
|
36
|
+
taggable2.save
|
37
|
+
|
38
|
+
taggable3.colour_list = "one, four"
|
39
|
+
taggable3.save
|
40
|
+
|
41
|
+
taggable1.find_related_colours.should include(taggable3)
|
42
|
+
taggable1.find_related_colours.should_not include(taggable2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should find related objects based on tag names on context - non standard id" do
|
46
|
+
taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
|
47
|
+
taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
|
48
|
+
taggable3 = NonStandardIdTaggableModel.create!(:name => "Taggable 3")
|
49
|
+
|
50
|
+
taggable1.tag_list = "one, two"
|
51
|
+
taggable1.save
|
52
|
+
|
53
|
+
taggable2.tag_list = "three, four"
|
54
|
+
taggable2.save
|
55
|
+
|
56
|
+
taggable3.tag_list = "one, four"
|
57
|
+
taggable3.save
|
58
|
+
|
59
|
+
taggable1.find_related_tags.should include(taggable3)
|
60
|
+
taggable1.find_related_tags.should_not include(taggable2)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should find other related objects based on tag names on context" do
|
64
|
+
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
65
|
+
taggable2 = OtherTaggableModel.create!(:name => "Taggable 2")
|
66
|
+
taggable3 = OtherTaggableModel.create!(:name => "Taggable 3")
|
67
|
+
|
68
|
+
taggable1.tag_list = "one, two"
|
69
|
+
taggable1.save
|
70
|
+
|
71
|
+
taggable2.tag_list = "three, four"
|
72
|
+
taggable2.save
|
73
|
+
|
74
|
+
taggable3.tag_list = "one, four"
|
75
|
+
taggable3.save
|
76
|
+
|
77
|
+
taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
|
78
|
+
taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not include the object itself in the list of related objects" do
|
82
|
+
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
83
|
+
taggable2 = TaggableModel.create!(:name => "Taggable 2")
|
84
|
+
|
85
|
+
taggable1.tag_list = "one"
|
86
|
+
taggable1.save
|
87
|
+
|
88
|
+
taggable2.tag_list = "one, two"
|
89
|
+
taggable2.save
|
90
|
+
|
91
|
+
taggable1.find_related_tags.should include(taggable2)
|
92
|
+
taggable1.find_related_tags.should_not include(taggable1)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not include the object itself in the list of related objects - non standard id" do
|
96
|
+
taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
|
97
|
+
taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
|
98
|
+
|
99
|
+
taggable1.tag_list = "one"
|
100
|
+
taggable1.save
|
101
|
+
|
102
|
+
taggable2.tag_list = "one, two"
|
103
|
+
taggable2.save
|
104
|
+
|
105
|
+
taggable1.find_related_tags.should include(taggable2)
|
106
|
+
taggable1.find_related_tags.should_not include(taggable1)
|
107
|
+
end
|
108
|
+
|
109
|
+
context "Ignored Tags" do
|
110
|
+
let(:taggable1) { TaggableModel.create!(:name => "Taggable 1") }
|
111
|
+
let(:taggable2) { TaggableModel.create!(:name => "Taggable 2") }
|
112
|
+
let(:taggable3) { TaggableModel.create!(:name => "Taggable 3") }
|
113
|
+
before(:each) do
|
114
|
+
taggable1.tag_list = "one, two, four"
|
115
|
+
taggable1.save
|
116
|
+
|
117
|
+
taggable2.tag_list = "two, three"
|
118
|
+
taggable2.save
|
119
|
+
|
120
|
+
taggable3.tag_list = "one, three"
|
121
|
+
taggable3.save
|
122
|
+
end
|
123
|
+
it "should not include ignored tags in related search" do
|
124
|
+
taggable1.find_related_tags(:ignore => 'two').should_not include(taggable2)
|
125
|
+
taggable1.find_related_tags(:ignore => 'two').should include(taggable3)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should accept array of ignored tags" do
|
129
|
+
taggable4 = TaggableModel.create!(:name => "Taggable 4")
|
130
|
+
taggable4.tag_list = "four"
|
131
|
+
taggable4.save
|
132
|
+
|
133
|
+
taggable1.find_related_tags(:ignore => ['two', 'four']).should_not include(taggable2)
|
134
|
+
taggable1.find_related_tags(:ignore => ['two', 'four']).should_not include(taggable4)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should accept symbols as ignored tags" do
|
138
|
+
taggable1.find_related_tags(:ignore => :two).should_not include(taggable2)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Single Table Inheritance" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
clean_database!
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:taggable) { TaggableModel.new(:name => "taggable model") }
|
10
|
+
|
11
|
+
let(:inheriting_model) { InheritingTaggableModel.new(:name => "Inheriting Taggable Model") }
|
12
|
+
let(:altered_inheriting) { AlteredInheritingTaggableModel.new(:name => "Altered Inheriting Model") }
|
13
|
+
|
14
|
+
1.upto(4) do |n|
|
15
|
+
let(:"inheriting_#{n}") { InheritingTaggableModel.new(:name => "Inheriting Model #{n}") }
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:student) { Student.create! }
|
19
|
+
|
20
|
+
describe "tag contexts" do
|
21
|
+
it "should pass on to STI-inherited models" do
|
22
|
+
inheriting_model.should respond_to(:tag_list, :skill_list, :language_list)
|
23
|
+
altered_inheriting.should respond_to(:tag_list, :skill_list, :language_list)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should pass on to altered STI models" do
|
27
|
+
altered_inheriting.should respond_to(:part_list)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "matching contexts" do
|
32
|
+
|
33
|
+
before do
|
34
|
+
inheriting_1.offering_list = "one, two"
|
35
|
+
inheriting_1.need_list = "one, two"
|
36
|
+
inheriting_1.save!
|
37
|
+
|
38
|
+
inheriting_2.need_list = "one, two"
|
39
|
+
inheriting_2.save!
|
40
|
+
|
41
|
+
inheriting_3.offering_list = "one, two"
|
42
|
+
inheriting_3.save!
|
43
|
+
|
44
|
+
inheriting_4.tag_list = "one, two, three, four"
|
45
|
+
inheriting_4.save!
|
46
|
+
|
47
|
+
taggable.need_list = "one, two"
|
48
|
+
taggable.save!
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should find objects with tags of matching contexts" do
|
52
|
+
inheriting_1.find_matching_contexts(:offerings, :needs).should include(inheriting_2)
|
53
|
+
inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(inheriting_3)
|
54
|
+
inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(inheriting_4)
|
55
|
+
inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(taggable)
|
56
|
+
|
57
|
+
inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(inheriting_2)
|
58
|
+
inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(inheriting_3)
|
59
|
+
inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(inheriting_4)
|
60
|
+
inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(taggable)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not include the object itself in the list of related objects with tags of matching contexts" do
|
64
|
+
inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(inheriting_1)
|
65
|
+
inheriting_1.find_matching_contexts_for(InheritingTaggableModel, :offerings, :needs).should_not include(inheriting_1)
|
66
|
+
inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(inheriting_1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "find related tags" do
|
71
|
+
before do
|
72
|
+
inheriting_1.tag_list = "one, two"
|
73
|
+
inheriting_1.save
|
74
|
+
|
75
|
+
inheriting_2.tag_list = "three, four"
|
76
|
+
inheriting_2.save
|
77
|
+
|
78
|
+
inheriting_3.tag_list = "one, four"
|
79
|
+
inheriting_3.save
|
80
|
+
|
81
|
+
taggable.tag_list = "one, two, three, four"
|
82
|
+
taggable.save
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should find related objects based on tag names on context" do
|
86
|
+
inheriting_1.find_related_tags.should include(inheriting_3)
|
87
|
+
inheriting_1.find_related_tags.should_not include(inheriting_2)
|
88
|
+
inheriting_1.find_related_tags.should_not include(taggable)
|
89
|
+
|
90
|
+
inheriting_1.find_related_tags_for(TaggableModel).should include(inheriting_3)
|
91
|
+
inheriting_1.find_related_tags_for(TaggableModel).should_not include(inheriting_2)
|
92
|
+
inheriting_1.find_related_tags_for(TaggableModel).should include(taggable)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not include the object itself in the list of related objects" do
|
96
|
+
inheriting_1.find_related_tags.should_not include(inheriting_1)
|
97
|
+
inheriting_1.find_related_tags_for(InheritingTaggableModel).should_not include(inheriting_1)
|
98
|
+
inheriting_1.find_related_tags_for(TaggableModel).should_not include(inheriting_1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "tag list" do
|
103
|
+
before do
|
104
|
+
@inherited_same = InheritingTaggableModel.new(:name => "inherited same")
|
105
|
+
@inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should be able to save tags for inherited models" do
|
109
|
+
inheriting_model.tag_list = "bob, kelso"
|
110
|
+
inheriting_model.save
|
111
|
+
InheritingTaggableModel.tagged_with("bob").first.should == inheriting_model
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should find STI tagged models on the superclass" do
|
115
|
+
inheriting_model.tag_list = "bob, kelso"
|
116
|
+
inheriting_model.save
|
117
|
+
TaggableModel.tagged_with("bob").first.should == inheriting_model
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should be able to add on contexts only to some subclasses" do
|
121
|
+
altered_inheriting.part_list = "fork, spoon"
|
122
|
+
altered_inheriting.save
|
123
|
+
InheritingTaggableModel.tagged_with("fork", :on => :parts).should be_empty
|
124
|
+
AlteredInheritingTaggableModel.tagged_with("fork", :on => :parts).first.should == altered_inheriting
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should have different tag_counts_on for inherited models" do
|
128
|
+
inheriting_model.tag_list = "bob, kelso"
|
129
|
+
inheriting_model.save!
|
130
|
+
altered_inheriting.tag_list = "fork, spoon"
|
131
|
+
altered_inheriting.save!
|
132
|
+
|
133
|
+
InheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
|
134
|
+
AlteredInheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
|
135
|
+
TaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should have different tags_on for inherited models" do
|
139
|
+
inheriting_model.tag_list = "bob, kelso"
|
140
|
+
inheriting_model.save!
|
141
|
+
altered_inheriting.tag_list = "fork, spoon"
|
142
|
+
altered_inheriting.save!
|
143
|
+
|
144
|
+
InheritingTaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
|
145
|
+
AlteredInheritingTaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
|
146
|
+
TaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should store same tag without validation conflict' do
|
150
|
+
taggable.tag_list = 'one'
|
151
|
+
taggable.save!
|
152
|
+
|
153
|
+
inheriting_model.tag_list = 'one'
|
154
|
+
inheriting_model.save!
|
155
|
+
|
156
|
+
inheriting_model.update_attributes! :name => 'foo'
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "ownership" do
|
161
|
+
it "should have taggings" do
|
162
|
+
student.tag(taggable, :with=>'ruby,scheme', :on=>:tags)
|
163
|
+
student.owned_taggings.should have(2).tags
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should have tags" do
|
167
|
+
student.tag(taggable, :with=>'ruby,scheme', :on=>:tags)
|
168
|
+
student.owned_tags.should have(2).tags
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return tags for the inheriting tagger" do
|
172
|
+
student.tag(taggable, :with => 'ruby, scheme', :on => :tags)
|
173
|
+
taggable.tags_from(student).should match_array(%w(ruby scheme))
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns owner tags on the tagger" do
|
177
|
+
student.tag(taggable, :with => 'ruby, scheme', :on => :tags)
|
178
|
+
taggable.owner_tags_on(student, :tags).should have(2).tags
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should scope objects returned by tagged_with by owners" do
|
182
|
+
student.tag(taggable, :with => 'ruby, scheme', :on => :tags)
|
183
|
+
TaggableModel.tagged_with(%w(ruby scheme), :owned_by => student).should have(1).tag
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe ActsAsTaggableOn::TagList do
|
5
5
|
let(:tag_list) { ActsAsTaggableOn::TagList.new("awesome","radical") }
|
@@ -84,8 +84,8 @@ describe ActsAsTaggableOn::TagList do
|
|
84
84
|
it "should lowercase if force_lowercase is set to true" do
|
85
85
|
ActsAsTaggableOn.force_lowercase = true
|
86
86
|
|
87
|
-
tag_list = ActsAsTaggableOn::TagList.new("aweSomE","RaDicaL")
|
88
|
-
tag_list.to_s.should == "awesome, radical"
|
87
|
+
tag_list = ActsAsTaggableOn::TagList.new("aweSomE","RaDicaL","Entrée")
|
88
|
+
tag_list.to_s.should == "awesome, radical, entrée"
|
89
89
|
|
90
90
|
ActsAsTaggableOn.force_lowercase = false
|
91
91
|
end
|