acts-as-taggable-on 2.0.6 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +10 -0
- data/Gemfile +2 -9
- data/Guardfile +5 -0
- data/README.rdoc +47 -63
- data/Rakefile +9 -55
- data/acts-as-taggable-on.gemspec +28 -0
- data/lib/acts-as-taggable-on/version.rb +4 -0
- data/lib/acts-as-taggable-on.rb +7 -3
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +4 -4
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +38 -43
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +81 -30
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +7 -3
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +23 -15
- data/lib/acts_as_taggable_on/tag.rb +21 -12
- data/lib/acts_as_taggable_on/{acts_as_taggable_on.rb → taggable.rb} +6 -5
- data/lib/acts_as_taggable_on/tagging.rb +12 -2
- data/lib/acts_as_taggable_on/tags_helper.rb +2 -2
- data/lib/acts_as_taggable_on/utils.rb +34 -0
- data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +9 -2
- data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +3 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +242 -54
- data/spec/acts_as_taggable_on/tag_list_spec.rb +4 -0
- data/spec/acts_as_taggable_on/tag_spec.rb +52 -13
- data/spec/acts_as_taggable_on/taggable_spec.rb +131 -35
- data/spec/acts_as_taggable_on/tagger_spec.rb +14 -0
- data/spec/acts_as_taggable_on/tagging_spec.rb +2 -5
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +16 -0
- data/spec/acts_as_taggable_on/utils_spec.rb +21 -0
- data/spec/database.yml.sample +4 -2
- data/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb +22 -0
- data/spec/models.rb +14 -1
- data/spec/schema.rb +13 -0
- data/spec/spec_helper.rb +27 -6
- data/uninstall.rb +1 -0
- metadata +136 -51
- 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/compatibility/Gemfile +0 -8
- data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
- data/lib/acts_as_taggable_on/compatibility/postgresql.rb +0 -44
- data/spec/database.yml +0 -17
- /data/lib/acts_as_taggable_on/{acts_as_tagger.rb → tagger.rb} +0 -0
@@ -4,6 +4,7 @@ describe "Taggable" do
|
|
4
4
|
before(:each) do
|
5
5
|
clean_database!
|
6
6
|
@taggable = TaggableModel.new(:name => "Bob Jones")
|
7
|
+
@taggables = [@taggable, TaggableModel.new(:name => "John Doe")]
|
7
8
|
end
|
8
9
|
|
9
10
|
it "should have tag types" do
|
@@ -24,14 +25,19 @@ describe "Taggable" do
|
|
24
25
|
@taggable.tag_counts_on(:tags).length.should == 2
|
25
26
|
end
|
26
27
|
|
28
|
+
it "should return [] right after create" do
|
29
|
+
blank_taggable = TaggableModel.new(:name => "Bob Jones")
|
30
|
+
blank_taggable.tag_list.should == []
|
31
|
+
end
|
32
|
+
|
27
33
|
it "should be able to create tags" do
|
28
34
|
@taggable.skill_list = "ruby, rails, css"
|
29
35
|
@taggable.instance_variable_get("@skill_list").instance_of?(ActsAsTaggableOn::TagList).should be_true
|
30
|
-
|
36
|
+
|
31
37
|
lambda {
|
32
38
|
@taggable.save
|
33
39
|
}.should change(ActsAsTaggableOn::Tag, :count).by(3)
|
34
|
-
|
40
|
+
|
35
41
|
@taggable.reload
|
36
42
|
@taggable.skill_list.sort.should == %w(ruby rails css).sort
|
37
43
|
end
|
@@ -40,10 +46,10 @@ describe "Taggable" do
|
|
40
46
|
@taggable.tag_list_on(:test).add("hello")
|
41
47
|
@taggable.tag_list_cache_on(:test).should_not be_empty
|
42
48
|
@taggable.tag_list_on(:test).should == ["hello"]
|
43
|
-
|
49
|
+
|
44
50
|
@taggable.save
|
45
51
|
@taggable.save_tags
|
46
|
-
|
52
|
+
|
47
53
|
@taggable.reload
|
48
54
|
@taggable.tag_list_on(:test).should == ["hello"]
|
49
55
|
end
|
@@ -68,6 +74,22 @@ describe "Taggable" do
|
|
68
74
|
@taggable.should have(2).skills
|
69
75
|
end
|
70
76
|
|
77
|
+
it "should be able to select taggables by subset of tags using ActiveRelation methods" do
|
78
|
+
@taggables[0].tag_list = "bob"
|
79
|
+
@taggables[1].tag_list = "charlie"
|
80
|
+
@taggables[0].skill_list = "ruby"
|
81
|
+
@taggables[1].skill_list = "css"
|
82
|
+
@taggables.each{|taggable| taggable.save}
|
83
|
+
|
84
|
+
@found_taggables_by_tag = TaggableModel.joins(:tags).where(:tags => {:name => ["bob"]})
|
85
|
+
@found_taggables_by_skill = TaggableModel.joins(:skills).where(:tags => {:name => ["ruby"]})
|
86
|
+
|
87
|
+
@found_taggables_by_tag.should include @taggables[0]
|
88
|
+
@found_taggables_by_tag.should_not include @taggables[1]
|
89
|
+
@found_taggables_by_skill.should include @taggables[0]
|
90
|
+
@found_taggables_by_skill.should_not include @taggables[1]
|
91
|
+
end
|
92
|
+
|
71
93
|
it "should be able to find by tag" do
|
72
94
|
@taggable.skill_list = "ruby, rails, css"
|
73
95
|
@taggable.save
|
@@ -111,20 +133,18 @@ describe "Taggable" do
|
|
111
133
|
TaggableModel.all_tag_counts(:order => 'tags.id').first.count.should == 3 # ruby
|
112
134
|
end
|
113
135
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
TaggableModel.tagged_with("ruby").first(:readonly => false).should_not be_readonly
|
127
|
-
end
|
136
|
+
it "should be able to use named scopes to chain tag finds by any tags by context" do
|
137
|
+
bob = TaggableModel.create(:name => "Bob", :need_list => "rails", :offering_list => "c++")
|
138
|
+
frank = TaggableModel.create(:name => "Frank", :need_list => "css", :offering_list => "css")
|
139
|
+
steve = TaggableModel.create(:name => 'Steve', :need_list => "c++", :offering_list => "java")
|
140
|
+
|
141
|
+
# Let's only find those who need rails or css and are offering c++ or java
|
142
|
+
TaggableModel.tagged_with(['rails, css'], :on => :needs, :any => true).tagged_with(['c++', 'java'], :on => :offerings, :any => true).to_a.should == [bob]
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not return read-only records" do
|
146
|
+
TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
147
|
+
TaggableModel.tagged_with("ruby").first.should_not be_readonly
|
128
148
|
end
|
129
149
|
|
130
150
|
it "should be able to get scoped tag counts" do
|
@@ -148,10 +168,10 @@ describe "Taggable" do
|
|
148
168
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
149
169
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
150
170
|
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby, java")
|
151
|
-
|
171
|
+
|
152
172
|
TaggableModel.tagged_with('rails').all_tag_counts.should have(3).items
|
153
173
|
TaggableModel.tagged_with('rails').all_tag_counts.any? { |tag| tag.name == 'java' }.should be_false
|
154
|
-
|
174
|
+
|
155
175
|
# Test specific join syntaxes:
|
156
176
|
frank.untaggable_models.create!
|
157
177
|
TaggableModel.tagged_with('rails').scoped(:joins => :untaggable_models).all_tag_counts.should have(2).items
|
@@ -177,15 +197,15 @@ describe "Taggable" do
|
|
177
197
|
TaggableModel.tagged_with("ruby, rails", :order => 'taggable_models.name').to_a.should == [bob, frank]
|
178
198
|
TaggableModel.tagged_with(["ruby", "rails"], :order => 'taggable_models.name').to_a.should == [bob, frank]
|
179
199
|
end
|
180
|
-
|
200
|
+
|
181
201
|
it "should be able to find tagged with quotation marks" do
|
182
202
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive, 'I love the ,comma,'")
|
183
203
|
TaggableModel.tagged_with("'I love the ,comma,'").should include(bob)
|
184
204
|
end
|
185
|
-
|
205
|
+
|
186
206
|
it "should be able to find tagged with invalid tags" do
|
187
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive")
|
188
|
-
TaggableModel.tagged_with("sad, happier").should_not include(bob)
|
207
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive")
|
208
|
+
TaggableModel.tagged_with("sad, happier").should_not include(bob)
|
189
209
|
end
|
190
210
|
|
191
211
|
it "should be able to find tagged with any tag" do
|
@@ -198,12 +218,25 @@ describe "Taggable" do
|
|
198
218
|
TaggableModel.tagged_with(["depressed", "css"], :order => 'taggable_models.name', :any => true).to_a.should == [bob, frank]
|
199
219
|
end
|
200
220
|
|
221
|
+
context "wild: true" do
|
222
|
+
it "should use params as wildcards" do
|
223
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "bob, tricia")
|
224
|
+
frank = TaggableModel.create(:name => "Frank", :tag_list => "bobby, jim")
|
225
|
+
steve = TaggableModel.create(:name => "Steve", :tag_list => "john, patricia")
|
226
|
+
jim = TaggableModel.create(:name => "Jim", :tag_list => "jim, steve")
|
227
|
+
|
228
|
+
|
229
|
+
TaggableModel.tagged_with(["bob", "tricia"], :wild => true, :any => true).to_a.should == [bob, frank, steve]
|
230
|
+
TaggableModel.tagged_with(["bob", "tricia"], :wild => true, :exclude => true).to_a.should == [jim]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
201
234
|
it "should be able to find tagged on a custom tag context" do
|
202
235
|
bob = TaggableModel.create(:name => "Bob")
|
203
236
|
bob.set_tag_list_on(:rotors, "spinning, jumping")
|
204
237
|
bob.tag_list_on(:rotors).should == ["spinning","jumping"]
|
205
238
|
bob.save
|
206
|
-
|
239
|
+
|
207
240
|
TaggableModel.tagged_with("spinning", :on => :rotors).to_a.should == [bob]
|
208
241
|
end
|
209
242
|
|
@@ -235,6 +268,13 @@ describe "Taggable" do
|
|
235
268
|
TaggableModel.tagged_with("lazy", :exclude => true).to_a.should == [frank, steve]
|
236
269
|
end
|
237
270
|
|
271
|
+
it "should return an empty scope for empty tags" do
|
272
|
+
TaggableModel.tagged_with('').should == []
|
273
|
+
TaggableModel.tagged_with(' ').should == []
|
274
|
+
TaggableModel.tagged_with(nil).should == []
|
275
|
+
TaggableModel.tagged_with([]).should == []
|
276
|
+
end
|
277
|
+
|
238
278
|
it "should not create duplicate taggings" do
|
239
279
|
bob = TaggableModel.create(:name => "Bob")
|
240
280
|
lambda {
|
@@ -243,12 +283,12 @@ describe "Taggable" do
|
|
243
283
|
bob.save
|
244
284
|
}.should change(ActsAsTaggableOn::Tagging, :count).by(1)
|
245
285
|
end
|
246
|
-
|
286
|
+
|
247
287
|
describe "Associations" do
|
248
288
|
before(:each) do
|
249
289
|
@taggable = TaggableModel.create(:tag_list => "awesome, epic")
|
250
290
|
end
|
251
|
-
|
291
|
+
|
252
292
|
it "should not remove tags when creating associated objects" do
|
253
293
|
@taggable.untaggable_models.create!
|
254
294
|
@taggable.reload
|
@@ -264,6 +304,10 @@ describe "Taggable" do
|
|
264
304
|
it "should return all column names joined for TaggableModel GROUP clause" do
|
265
305
|
@taggable.grouped_column_names_for(TaggableModel).should == "taggable_models.id, taggable_models.name, taggable_models.type"
|
266
306
|
end
|
307
|
+
|
308
|
+
it "should return all column names joined for NonStandardIdTaggableModel GROUP clause" do
|
309
|
+
@taggable.grouped_column_names_for(TaggableModel).should == "taggable_models.#{TaggableModel.primary_key}, taggable_models.name, taggable_models.type"
|
310
|
+
end
|
267
311
|
end
|
268
312
|
|
269
313
|
describe "Single Table Inheritance" do
|
@@ -272,45 +316,97 @@ describe "Taggable" do
|
|
272
316
|
@inherited_same = InheritingTaggableModel.new(:name => "inherited same")
|
273
317
|
@inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
|
274
318
|
end
|
275
|
-
|
319
|
+
|
276
320
|
it "should be able to save tags for inherited models" do
|
277
321
|
@inherited_same.tag_list = "bob, kelso"
|
278
322
|
@inherited_same.save
|
279
323
|
InheritingTaggableModel.tagged_with("bob").first.should == @inherited_same
|
280
324
|
end
|
281
|
-
|
325
|
+
|
282
326
|
it "should find STI tagged models on the superclass" do
|
283
327
|
@inherited_same.tag_list = "bob, kelso"
|
284
328
|
@inherited_same.save
|
285
329
|
TaggableModel.tagged_with("bob").first.should == @inherited_same
|
286
330
|
end
|
287
|
-
|
331
|
+
|
288
332
|
it "should be able to add on contexts only to some subclasses" do
|
289
333
|
@inherited_different.part_list = "fork, spoon"
|
290
334
|
@inherited_different.save
|
291
335
|
InheritingTaggableModel.tagged_with("fork", :on => :parts).should be_empty
|
292
336
|
AlteredInheritingTaggableModel.tagged_with("fork", :on => :parts).first.should == @inherited_different
|
293
337
|
end
|
294
|
-
|
338
|
+
|
295
339
|
it "should have different tag_counts_on for inherited models" do
|
296
340
|
@inherited_same.tag_list = "bob, kelso"
|
297
341
|
@inherited_same.save!
|
298
342
|
@inherited_different.tag_list = "fork, spoon"
|
299
343
|
@inherited_different.save!
|
300
|
-
|
344
|
+
|
301
345
|
InheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
|
302
346
|
AlteredInheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
|
303
347
|
TaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
|
304
348
|
end
|
305
|
-
|
349
|
+
|
306
350
|
it 'should store same tag without validation conflict' do
|
307
351
|
@taggable.tag_list = 'one'
|
308
352
|
@taggable.save!
|
309
|
-
|
353
|
+
|
310
354
|
@inherited_same.tag_list = 'one'
|
311
355
|
@inherited_same.save!
|
312
|
-
|
356
|
+
|
313
357
|
@inherited_same.update_attributes! :name => 'foo'
|
314
358
|
end
|
315
359
|
end
|
360
|
+
|
361
|
+
describe "NonStandardIdTaggable" do
|
362
|
+
before(:each) do
|
363
|
+
clean_database!
|
364
|
+
@taggable = NonStandardIdTaggableModel.new(:name => "Bob Jones")
|
365
|
+
@taggables = [@taggable, NonStandardIdTaggableModel.new(:name => "John Doe")]
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should have tag types" do
|
369
|
+
[:tags, :languages, :skills, :needs, :offerings].each do |type|
|
370
|
+
NonStandardIdTaggableModel.tag_types.should include type
|
371
|
+
end
|
372
|
+
|
373
|
+
@taggable.tag_types.should == NonStandardIdTaggableModel.tag_types
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should have tag_counts_on" do
|
377
|
+
NonStandardIdTaggableModel.tag_counts_on(:tags).all.should be_empty
|
378
|
+
|
379
|
+
@taggable.tag_list = ["awesome", "epic"]
|
380
|
+
@taggable.save
|
381
|
+
|
382
|
+
NonStandardIdTaggableModel.tag_counts_on(:tags).length.should == 2
|
383
|
+
@taggable.tag_counts_on(:tags).length.should == 2
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should be able to create tags" do
|
387
|
+
@taggable.skill_list = "ruby, rails, css"
|
388
|
+
@taggable.instance_variable_get("@skill_list").instance_of?(ActsAsTaggableOn::TagList).should be_true
|
389
|
+
|
390
|
+
lambda {
|
391
|
+
@taggable.save
|
392
|
+
}.should change(ActsAsTaggableOn::Tag, :count).by(3)
|
393
|
+
|
394
|
+
@taggable.reload
|
395
|
+
@taggable.skill_list.sort.should == %w(ruby rails css).sort
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should be able to create tags through the tag list directly" do
|
399
|
+
@taggable.tag_list_on(:test).add("hello")
|
400
|
+
@taggable.tag_list_cache_on(:test).should_not be_empty
|
401
|
+
@taggable.tag_list_on(:test).should == ["hello"]
|
402
|
+
|
403
|
+
@taggable.save
|
404
|
+
@taggable.save_tags
|
405
|
+
|
406
|
+
@taggable.reload
|
407
|
+
@taggable.tag_list_on(:test).should == ["hello"]
|
408
|
+
end
|
409
|
+
end
|
316
410
|
end
|
411
|
+
|
412
|
+
|
@@ -17,6 +17,20 @@ describe "Tagger" do
|
|
17
17
|
@user.owned_tags.size == 2
|
18
18
|
end
|
19
19
|
|
20
|
+
it "should scope objects returned by tagged_with by owners" do
|
21
|
+
@taggable2 = TaggableModel.create(:name => "Jim Jones")
|
22
|
+
@taggable3 = TaggableModel.create(:name => "Jane Doe")
|
23
|
+
|
24
|
+
@user2 = TaggableUser.new
|
25
|
+
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
|
26
|
+
@user2.tag(@taggable2, :with => 'ruby, scheme', :on => :tags)
|
27
|
+
@user2.tag(@taggable3, :with => 'ruby, scheme', :on => :tags)
|
28
|
+
|
29
|
+
TaggableModel.tagged_with(%w(ruby scheme), :owned_by => @user).count.should == 1
|
30
|
+
TaggableModel.tagged_with(%w(ruby scheme), :owned_by => @user2).count.should == 2
|
31
|
+
|
32
|
+
end
|
33
|
+
|
20
34
|
it "should not overlap tags from different taggers" do
|
21
35
|
@user2 = TaggableUser.new
|
22
36
|
lambda{
|
@@ -13,11 +13,7 @@ describe ActsAsTaggableOn::Tagging do
|
|
13
13
|
|
14
14
|
@tagging.should_not be_valid
|
15
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
|
16
|
+
@tagging.errors[:tag_id].should == ["can't be blank"]
|
21
17
|
end
|
22
18
|
|
23
19
|
it "should not create duplicate taggings" do
|
@@ -28,4 +24,5 @@ describe ActsAsTaggableOn::Tagging do
|
|
28
24
|
2.times { ActsAsTaggableOn::Tagging.create(:taggable => @taggable, :tag => @tag, :context => 'tags') }
|
29
25
|
}.should change(ActsAsTaggableOn::Tagging, :count).by(1)
|
30
26
|
end
|
27
|
+
|
31
28
|
end
|
@@ -25,4 +25,20 @@ describe ActsAsTaggableOn::TagsHelper do
|
|
25
25
|
tags["c++"].should == "sucky"
|
26
26
|
tags["php"].should == "sucky"
|
27
27
|
end
|
28
|
+
|
29
|
+
it "should handle tags with zero counts (build for empty)" do
|
30
|
+
bob = ActsAsTaggableOn::Tag.create(:name => "php")
|
31
|
+
tom = ActsAsTaggableOn::Tag.create(:name => "java")
|
32
|
+
eve = ActsAsTaggableOn::Tag.create(:name => "c++")
|
33
|
+
|
34
|
+
tags = { }
|
35
|
+
|
36
|
+
@helper.tag_cloud(ActsAsTaggableOn::Tag.all, ["sucky", "awesome"]) do |tag, css_class|
|
37
|
+
tags[tag.name] = css_class
|
38
|
+
end
|
39
|
+
|
40
|
+
tags["java"].should == "sucky"
|
41
|
+
tags["c++"].should == "sucky"
|
42
|
+
tags["php"].should == "sucky"
|
43
|
+
end
|
28
44
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe ActsAsTaggableOn::Utils do
|
4
|
+
describe "like_operator" do
|
5
|
+
before(:each) do
|
6
|
+
clean_database!
|
7
|
+
TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
|
8
|
+
@taggable = TaggableModel.new(:name => "Bob Jones")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return 'ILIKE' when the adapter is PostgreSQL" do
|
12
|
+
TaggableModel.connection.stub(:adapter_name).and_return("PostgreSQL")
|
13
|
+
TaggableModel.send(:like_operator).should == "ILIKE"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return 'LIKE' when the adapter is not PostgreSQL" do
|
17
|
+
TaggableModel.connection.stub(:adapter_name).and_return("MySQL")
|
18
|
+
TaggableModel.send(:like_operator).should == "LIKE"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/database.yml.sample
CHANGED
@@ -3,15 +3,17 @@ sqlite3:
|
|
3
3
|
database: acts_as_taggable_on.sqlite3
|
4
4
|
|
5
5
|
mysql:
|
6
|
-
adapter:
|
6
|
+
adapter: mysql2
|
7
7
|
hostname: localhost
|
8
8
|
username: root
|
9
9
|
password:
|
10
10
|
database: acts_as_taggable_on
|
11
|
-
|
11
|
+
charset: utf8
|
12
|
+
|
12
13
|
postgresql:
|
13
14
|
adapter: postgresql
|
14
15
|
hostname: localhost
|
15
16
|
username: postgres
|
16
17
|
password:
|
17
18
|
database: acts_as_taggable_on
|
19
|
+
encoding: utf8
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Generators are not automatically loaded by Rails
|
4
|
+
require 'generators/acts_as_taggable_on/migration/migration_generator'
|
5
|
+
|
6
|
+
describe ActsAsTaggableOn::MigrationGenerator do
|
7
|
+
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
8
|
+
destination File.expand_path("../../../../../tmp", __FILE__)
|
9
|
+
|
10
|
+
before do
|
11
|
+
prepare_destination
|
12
|
+
Rails::Generators.options[:rails][:orm] = :active_record
|
13
|
+
end
|
14
|
+
describe 'no arguments' do
|
15
|
+
before { run_generator }
|
16
|
+
|
17
|
+
describe 'db/migrate/acts_as_taggable_on_migration.rb' do
|
18
|
+
subject { file('db/migrate/acts_as_taggable_on_migration.rb') }
|
19
|
+
it { should be_a_migration }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/models.rb
CHANGED
@@ -10,6 +10,10 @@ class CachedModel < ActiveRecord::Base
|
|
10
10
|
acts_as_taggable
|
11
11
|
end
|
12
12
|
|
13
|
+
class OtherCachedModel < ActiveRecord::Base
|
14
|
+
acts_as_taggable_on :languages, :statuses, :glasses
|
15
|
+
end
|
16
|
+
|
13
17
|
class OtherTaggableModel < ActiveRecord::Base
|
14
18
|
acts_as_taggable_on :tags, :languages
|
15
19
|
acts_as_taggable_on :needs, :offerings
|
@@ -28,4 +32,13 @@ end
|
|
28
32
|
|
29
33
|
class UntaggableModel < ActiveRecord::Base
|
30
34
|
belongs_to :taggable_model
|
31
|
-
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class NonStandardIdTaggableModel < ActiveRecord::Base
|
38
|
+
set_primary_key "an_id"
|
39
|
+
acts_as_taggable
|
40
|
+
acts_as_taggable_on :languages
|
41
|
+
acts_as_taggable_on :skills
|
42
|
+
acts_as_taggable_on :needs, :offerings
|
43
|
+
has_many :untaggable_models
|
44
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -21,6 +21,11 @@ ActiveRecord::Schema.define :version => 0 do
|
|
21
21
|
t.column :type, :string
|
22
22
|
end
|
23
23
|
|
24
|
+
create_table :non_standard_id_taggable_models, :primary_key => "an_id", :force => true do |t|
|
25
|
+
t.column :name, :string
|
26
|
+
t.column :type, :string
|
27
|
+
end
|
28
|
+
|
24
29
|
create_table :untaggable_models, :force => true do |t|
|
25
30
|
t.column :taggable_model_id, :integer
|
26
31
|
t.column :name, :string
|
@@ -32,6 +37,14 @@ ActiveRecord::Schema.define :version => 0 do
|
|
32
37
|
t.column :cached_tag_list, :string
|
33
38
|
end
|
34
39
|
|
40
|
+
create_table :other_cached_models, :force => true do |t|
|
41
|
+
t.column :name, :string
|
42
|
+
t.column :type, :string
|
43
|
+
t.column :cached_language_list, :string
|
44
|
+
t.column :cached_status_list, :string
|
45
|
+
t.column :cached_glass_list, :string
|
46
|
+
end
|
47
|
+
|
35
48
|
create_table :taggable_users, :force => true do |t|
|
36
49
|
t.column :name, :string
|
37
50
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
|
2
|
+
require 'logger'
|
2
3
|
|
3
4
|
begin
|
4
5
|
require "rubygems"
|
@@ -13,11 +14,12 @@ begin
|
|
13
14
|
Bundler.setup
|
14
15
|
rescue Bundler::GemNotFound
|
15
16
|
raise RuntimeError, "Bundler couldn't find some gems." +
|
16
|
-
"Did you run
|
17
|
+
"Did you run \`bundlee install\`?"
|
17
18
|
end
|
18
19
|
|
19
20
|
Bundler.require
|
20
21
|
require File.expand_path('../../lib/acts-as-taggable-on', __FILE__)
|
22
|
+
require 'ammeter/init'
|
21
23
|
|
22
24
|
unless [].respond_to?(:freq)
|
23
25
|
class Array
|
@@ -29,14 +31,33 @@ unless [].respond_to?(:freq)
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
ENV['DB']
|
33
|
-
|
34
|
+
db_name = ENV['DB'] || 'sqlite3'
|
34
35
|
database_yml = File.expand_path('../database.yml', __FILE__)
|
36
|
+
|
35
37
|
if File.exists?(database_yml)
|
36
|
-
active_record_configuration = YAML.load_file(database_yml)
|
38
|
+
active_record_configuration = YAML.load_file(database_yml)
|
37
39
|
|
38
|
-
ActiveRecord::Base.
|
40
|
+
ActiveRecord::Base.configurations = active_record_configuration
|
41
|
+
config = ActiveRecord::Base.configurations[db_name]
|
42
|
+
|
43
|
+
begin
|
44
|
+
ActiveRecord::Base.establish_connection(db_name)
|
45
|
+
ActiveRecord::Base.connection
|
46
|
+
rescue
|
47
|
+
case db_name
|
48
|
+
when /mysql/
|
49
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
50
|
+
ActiveRecord::Base.connection.create_database(config['database'], {:charset => 'utf8', :collation => 'utf8_unicode_ci'})
|
51
|
+
when 'postgresql'
|
52
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
53
|
+
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
|
54
|
+
end
|
55
|
+
|
56
|
+
ActiveRecord::Base.establish_connection(config)
|
57
|
+
end
|
58
|
+
|
39
59
|
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
60
|
+
ActiveRecord::Base.default_timezone = :utc
|
40
61
|
|
41
62
|
ActiveRecord::Base.silence do
|
42
63
|
ActiveRecord::Migration.verbose = false
|
@@ -57,4 +78,4 @@ def clean_database!
|
|
57
78
|
end
|
58
79
|
end
|
59
80
|
|
60
|
-
clean_database!
|
81
|
+
clean_database!
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|