bborn-acts_as_taggable_on_steroids 2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,384 @@
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class ActsAsTaggableOnSteroidsTest < ActiveSupport::TestCase
4
+ def test_find_related_tags_with
5
+ assert_equivalent [tags(:good), tags(:bad), tags(:question)], Post.find_related_tags("nature")
6
+ assert_equivalent [tags(:nature)], Post.find_related_tags([tags(:good)])
7
+ assert_equivalent [tags(:bad), tags(:question)], Post.find_related_tags(["Very Good", "Nature"])
8
+ assert_equivalent [tags(:bad), tags(:question)], Post.find_related_tags([tags(:good), tags(:nature)])
9
+ end
10
+
11
+ def test_find_tagged_with_include_and_order
12
+ assert_equal photos(:sam_sky, :sam_flower, :jonathan_dog), Photo.find_tagged_with("Nature", :order => "photos.title DESC", :include => :user)
13
+ end
14
+
15
+ def test_find_related_tags_with_non_existent_tags
16
+ assert_equal [], Post.find_related_tags("ABCDEFG")
17
+ assert_equal [], Post.find_related_tags(['HIJKLM'])
18
+ end
19
+
20
+ def test_find_related_tags_with_nothing
21
+ assert_equal [], Post.find_related_tags("")
22
+ assert_equal [], Post.find_related_tags([])
23
+ end
24
+
25
+ def test_find_tagged_with
26
+ assert_equivalent [posts(:jonathan_sky), posts(:sam_flowers)], Post.find_tagged_with('"Very good"')
27
+ assert_equal Post.find_tagged_with('"Very good"'), Post.find_tagged_with(['Very good'])
28
+ assert_equal Post.find_tagged_with('"Very good"'), Post.find_tagged_with([tags(:good)])
29
+
30
+ assert_equivalent [photos(:jonathan_dog), photos(:sam_flower), photos(:sam_sky)], Photo.find_tagged_with('Nature')
31
+ assert_equal Photo.find_tagged_with('Nature'), Photo.find_tagged_with(['Nature'])
32
+ assert_equal Photo.find_tagged_with('Nature'), Photo.find_tagged_with([tags(:nature)])
33
+
34
+ assert_equivalent [photos(:jonathan_bad_cat), photos(:jonathan_dog), photos(:jonathan_questioning_dog)], Photo.find_tagged_with('"Crazy animal" Bad')
35
+ assert_equal Photo.find_tagged_with('"Crazy animal" Bad'), Photo.find_tagged_with(['Crazy animal', 'Bad'])
36
+ assert_equal Photo.find_tagged_with('"Crazy animal" Bad'), Photo.find_tagged_with([tags(:animal), tags(:bad)])
37
+ end
38
+
39
+ def test_find_tagged_with_nothing
40
+ assert_equal [], Post.find_tagged_with("")
41
+ assert_equal [], Post.find_tagged_with([])
42
+ end
43
+
44
+ def test_find_tagged_with_nonexistant_tags
45
+ assert_equal [], Post.find_tagged_with('ABCDEFG')
46
+ assert_equal [], Photo.find_tagged_with(['HIJKLM'])
47
+ assert_equal [], Photo.find_tagged_with([Tag.new(:name => 'unsaved tag')])
48
+ end
49
+
50
+ def test_find_tagged_with_match_all
51
+ assert_equivalent [photos(:jonathan_dog)], Photo.find_tagged_with('Crazy animal, "Nature"', :match_all => true)
52
+ end
53
+
54
+ def test_find_tagged_with_match_all_and_include
55
+ assert_equivalent [posts(:jonathan_sky), posts(:sam_flowers)], Post.find_tagged_with(['Very good', 'Nature'], :match_all => true, :include => :tags)
56
+ end
57
+
58
+ def test_find_tagged_with_conditions
59
+ assert_equal [], Post.find_tagged_with('"Very good", Nature', :conditions => '1=0')
60
+ end
61
+
62
+ def test_find_tagged_with_duplicates_options_hash
63
+ options = { :conditions => '1=1' }.freeze
64
+ assert_nothing_raised { Post.find_tagged_with("Nature", options) }
65
+ end
66
+
67
+ def test_find_tagged_with_exclusions
68
+ assert_equivalent [photos(:jonathan_questioning_dog), photos(:jonathan_bad_cat)], Photo.find_tagged_with("Nature", :exclude => true)
69
+ assert_equivalent [posts(:jonathan_grass), posts(:jonathan_rain), posts(:jonathan_cloudy), posts(:jonathan_still_cloudy)], Post.find_tagged_with("'Very good', Bad", :exclude => true)
70
+ end
71
+
72
+ # def test_find_options_for_find_tagged_with_no_tags_returns_empty_hash
73
+ # assert_equal Hash.new, Post.find_options_for_find_tagged_with("")
74
+ # assert_equal Hash.new, Post.find_options_for_find_tagged_with([nil])
75
+ # end
76
+
77
+ # def test_find_options_for_find_tagged_with_leaves_arguments_unchanged
78
+ # original_tags = photos(:jonathan_questioning_dog).tags.dup
79
+ # Photo.find_options_for_find_tagged_with(photos(:jonathan_questioning_dog).tags)
80
+ # assert_equal original_tags, photos(:jonathan_questioning_dog).tags
81
+ # end
82
+
83
+ # def test_find_options_for_find_tagged_with_respects_custom_table_name
84
+ # Tagging.table_name = "categorisations"
85
+ # Tag.table_name = "categories"
86
+ #
87
+ # options = Photo.find_options_for_find_tagged_with("Hello")
88
+ #
89
+ # assert_no_match(/ taggings /, options[:joins])
90
+ # assert_no_match(/ tags /, options[:joins])
91
+ #
92
+ # assert_match(/ categorisations /, options[:joins])
93
+ # assert_match(/ categories /, options[:joins])
94
+ # ensure
95
+ # Tagging.table_name = "taggings"
96
+ # Tag.table_name = "tags"
97
+ # end
98
+
99
+ def test_include_tags_on_find_tagged_with
100
+ assert_nothing_raised do
101
+ Photo.find_tagged_with('Nature', :include => :tags)
102
+ Photo.find_tagged_with("Nature", :include => { :taggings => :tag })
103
+ end
104
+ end
105
+
106
+ def test_basic_tag_counts_on_class
107
+ assert_tag_counts Post.tag_counts, :good => 2, :nature => 7, :question => 1, :bad => 1
108
+ assert_tag_counts Photo.tag_counts, :good => 1, :nature => 3, :question => 1, :bad => 1, :animal => 3
109
+ end
110
+
111
+ def test_tag_counts_on_class_with_date_conditions
112
+ assert_tag_counts Post.tag_counts(:start_at => Date.new(2006, 8, 4)), :good => 1, :nature => 5, :question => 1, :bad => 1
113
+ assert_tag_counts Post.tag_counts(:end_at => Date.new(2006, 8, 6)), :good => 1, :nature => 4, :question => 1
114
+ assert_tag_counts Post.tag_counts(:start_at => Date.new(2006, 8, 5), :end_at => Date.new(2006, 8, 10)), :good => 1, :nature => 4, :bad => 1
115
+
116
+ assert_tag_counts Photo.tag_counts(:start_at => Date.new(2006, 8, 12), :end_at => Date.new(2006, 8, 19)), :good => 1, :nature => 2, :bad => 1, :question => 1, :animal => 3
117
+ end
118
+
119
+ def test_tag_counts_on_class_with_frequencies
120
+ assert_tag_counts Photo.tag_counts(:at_least => 2), :nature => 3, :animal => 3
121
+ assert_tag_counts Photo.tag_counts(:at_most => 2), :good => 1, :question => 1, :bad => 1
122
+ end
123
+
124
+ def test_tag_counts_on_class_with_frequencies_and_conditions
125
+ assert_tag_counts Photo.tag_counts(:at_least => 2, :conditions => '1=1'), :nature => 3, :animal => 3
126
+ end
127
+
128
+ def test_tag_counts_duplicates_options_hash
129
+ options = { :at_least => 2, :conditions => '1=1' }.freeze
130
+ assert_nothing_raised { Photo.tag_counts(options) }
131
+ end
132
+
133
+ def test_tag_counts_with_limit
134
+ assert_equal 2, Photo.tag_counts(:limit => 2).all.size
135
+ assert_equal 1, Post.tag_counts(:at_least => 4, :limit => 2).all.size
136
+ end
137
+
138
+ def test_tag_counts_with_limit_and_order
139
+ assert_equal [tags(:nature), tags(:good)], Post.tag_counts(:order => 'count desc', :limit => 2)
140
+ end
141
+
142
+ def test_tag_counts_on_association
143
+ assert_tag_counts users(:jonathan).posts.tag_counts, :good => 1, :nature => 5, :question => 1
144
+ assert_tag_counts users(:sam).posts.tag_counts, :good => 1, :nature => 2, :bad => 1
145
+
146
+ assert_tag_counts users(:jonathan).photos.tag_counts, :animal => 3, :nature => 1, :question => 1, :bad => 1
147
+ assert_tag_counts users(:sam).photos.tag_counts, :nature => 2, :good => 1
148
+ end
149
+
150
+ def test_tag_counts_on_association_with_options
151
+ assert_equal [], users(:jonathan).posts.tag_counts(:conditions => '1=0')
152
+ assert_tag_counts users(:jonathan).posts.tag_counts(:at_most => 2), :good => 1, :question => 1
153
+ end
154
+
155
+ def test_tag_counts_on_has_many_through
156
+ assert_tag_counts users(:jonathan).magazines.tag_counts, :good => 1
157
+ end
158
+
159
+ def test_tag_counts_on_model_instance
160
+ assert_tag_counts photos(:jonathan_dog).tag_counts, :animal => 3, :nature => 3
161
+ end
162
+
163
+ def test_tag_counts_on_model_instance_merges_conditions
164
+ assert_tag_counts photos(:jonathan_dog).tag_counts(:conditions => "tags.name = 'Crazy animal'"), :animal => 3
165
+ end
166
+
167
+ def test_tag_counts_on_model_instance_with_no_tags
168
+ photo = Photo.create!
169
+
170
+ assert_tag_counts photo.tag_counts, {}
171
+ end
172
+
173
+ def test_tag_counts_should_sanitize_scope_conditions
174
+ Photo.send :with_scope, :find => { :conditions => ["tags.id = ?", tags(:animal).id] } do
175
+ assert_tag_counts Photo.tag_counts, :animal => 3
176
+ end
177
+ end
178
+
179
+ # # NOTE: the SQL FROM statement won't change when changing table_name dynamically...
180
+ # def test_tag_counts_respects_custom_table_names
181
+ # Tagging.table_name = "categorisations"
182
+ # Tag.table_name = "categories"
183
+ #
184
+ # sql = Photo.tag_counts(:start_at => 2.weeks.ago, :end_at => Date.today).to_sql
185
+ #
186
+ # assert_no_match /taggings/, sql
187
+ # assert_no_match /tags/, sql
188
+ #
189
+ # assert_match /categorisations/, sql
190
+ # assert_match /categories/, sql
191
+ # ensure
192
+ # Tagging.table_name = "taggings"
193
+ # Tag.table_name = "tags"
194
+ # end
195
+
196
+ def test_tag_list_reader
197
+ assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list
198
+ assert_equivalent ["Bad", "Crazy animal"], photos(:jonathan_bad_cat).tag_list
199
+ end
200
+
201
+ def test_reassign_tag_list
202
+ assert_equivalent ["Nature", "Question"], posts(:jonathan_rain).tag_list
203
+ posts(:jonathan_rain).taggings.reload
204
+
205
+ assert_queries ENV['DB'] == 'sqlite3' ? 1 : 3 do
206
+ posts(:jonathan_rain).update_attributes!(:tag_list => posts(:jonathan_rain).tag_list.to_s)
207
+ end
208
+
209
+ assert_equivalent ["Nature", "Question"], posts(:jonathan_rain).tag_list
210
+ end
211
+
212
+ def test_new_tags
213
+ assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list
214
+ posts(:jonathan_sky).update_attributes!(:tag_list => "#{posts(:jonathan_sky).tag_list}, One, Two")
215
+ assert_equivalent ["Very good", "Nature", "One", "Two"], posts(:jonathan_sky).tag_list
216
+ end
217
+
218
+ def test_remove_tag
219
+ assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list
220
+ posts(:jonathan_sky).update_attributes!(:tag_list => "Nature")
221
+ assert_equivalent ["Nature"], posts(:jonathan_sky).tag_list
222
+ end
223
+
224
+ def test_change_case_of_tags
225
+ original_tag_names = photos(:jonathan_questioning_dog).tag_list
226
+ photos(:jonathan_questioning_dog).update_attributes!(:tag_list => photos(:jonathan_questioning_dog).tag_list.to_s.upcase)
227
+
228
+ # The new tag list is not uppercase becuase the AR finders are not case-sensitive
229
+ # and find the old tags when re-tagging with the uppercase tags.
230
+ assert_equivalent original_tag_names, photos(:jonathan_questioning_dog).reload.tag_list
231
+ end
232
+
233
+ def test_remove_and_add_tag
234
+ assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list
235
+ posts(:jonathan_sky).update_attributes!(:tag_list => "Nature, Beautiful")
236
+ assert_equivalent ["Nature", "Beautiful"], posts(:jonathan_sky).tag_list
237
+ end
238
+
239
+ def test_tags_not_saved_if_validation_fails
240
+ assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list
241
+ assert !posts(:jonathan_sky).update_attributes(:tag_list => "One, Two", :text => "")
242
+ assert_equivalent ["Very good", "Nature"], Post.find(posts(:jonathan_sky).id).tag_list
243
+ end
244
+
245
+ def test_tag_list_accessors_on_new_record
246
+ p = Post.new(:text => 'Test')
247
+
248
+ assert p.tag_list.blank?
249
+ p.tag_list = "One, Two"
250
+ assert_equal "One, Two", p.tag_list.to_s
251
+ end
252
+
253
+ def test_clear_tag_list_with_nil
254
+ p = photos(:jonathan_questioning_dog)
255
+
256
+ assert !p.tag_list.blank?
257
+ assert p.update_attributes(:tag_list => nil)
258
+ assert p.tag_list.blank?
259
+
260
+ assert p.reload.tag_list.blank?
261
+ end
262
+
263
+ def test_clear_tag_list_with_string
264
+ p = photos(:jonathan_questioning_dog)
265
+
266
+ assert !p.tag_list.blank?
267
+ assert p.update_attributes(:tag_list => ' ')
268
+ assert p.tag_list.blank?
269
+
270
+ assert p.reload.tag_list.blank?
271
+ end
272
+
273
+ def test_tag_list_reset_on_reload
274
+ p = photos(:jonathan_questioning_dog)
275
+ assert !p.tag_list.blank?
276
+ p.tag_list = nil
277
+ assert p.tag_list.blank?
278
+ assert !p.reload.tag_list.blank?
279
+ end
280
+
281
+ def test_instance_tag_counts
282
+ assert_tag_counts posts(:jonathan_sky).tag_counts, :good => 2, :nature => 7
283
+ end
284
+
285
+ def test_tag_list_populated_when_cache_nil
286
+ assert_nil posts(:jonathan_sky).cached_tag_list
287
+ posts(:jonathan_sky).save!
288
+ assert_equal posts(:jonathan_sky).tag_list.to_s, posts(:jonathan_sky).cached_tag_list
289
+ end
290
+
291
+ def test_cached_tag_list_used
292
+ posts(:jonathan_sky).save!
293
+ posts(:jonathan_sky).reload
294
+
295
+ assert_no_queries do
296
+ assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list
297
+ end
298
+ end
299
+
300
+ def test_cached_tag_list_not_used
301
+ # Load fixture and column information
302
+ posts(:jonathan_sky).taggings(:reload)
303
+
304
+ assert_queries 1 do
305
+ # Tags association will be loaded
306
+ posts(:jonathan_sky).tag_list
307
+ end
308
+ end
309
+
310
+ def test_cached_tag_list_updated
311
+ assert_nil posts(:jonathan_sky).cached_tag_list
312
+ posts(:jonathan_sky).save!
313
+ assert_equivalent ["Very good", "Nature"], TagList.from(posts(:jonathan_sky).cached_tag_list)
314
+ posts(:jonathan_sky).update_attributes!(:tag_list => "None")
315
+
316
+ assert_equal 'None', posts(:jonathan_sky).cached_tag_list
317
+ assert_equal 'None', posts(:jonathan_sky).reload.cached_tag_list
318
+ end
319
+
320
+ def test_clearing_cached_tag_list
321
+ # Generate the cached tag list
322
+ posts(:jonathan_sky).save!
323
+
324
+ posts(:jonathan_sky).update_attributes!(:tag_list => "")
325
+ assert_equal "", posts(:jonathan_sky).cached_tag_list
326
+ end
327
+
328
+ def test_find_tagged_with_using_sti
329
+ special_post = SpecialPost.create!(:text => "Test", :tag_list => "Random")
330
+
331
+ assert_equal [special_post], SpecialPost.find_tagged_with("Random")
332
+ assert Post.find_tagged_with("Random").include?(special_post)
333
+ end
334
+
335
+ def test_tag_counts_using_sti
336
+ SpecialPost.create!(:text => "Test", :tag_list => "Nature")
337
+
338
+ assert_tag_counts SpecialPost.tag_counts, :nature => 1
339
+ end
340
+
341
+ def test_case_insensitivity
342
+ assert_difference "Tag.count", 1 do
343
+ Post.create!(:text => "Test", :tag_list => "one")
344
+ Post.create!(:text => "Test", :tag_list => "One")
345
+ end
346
+
347
+ assert_equal Post.find_tagged_with("Nature").collect(&:id),
348
+ Post.find_tagged_with("nature").collect(&:id)
349
+ end
350
+
351
+ def test_tag_not_destroyed_when_unused
352
+ posts(:jonathan_sky).tag_list.add("Random")
353
+ posts(:jonathan_sky).save!
354
+
355
+ assert_no_difference 'Tag.count' do
356
+ posts(:jonathan_sky).tag_list.remove("Random")
357
+ posts(:jonathan_sky).save!
358
+ end
359
+ end
360
+
361
+ def test_tag_destroyed_when_unused
362
+ Tag.destroy_unused = true
363
+
364
+ posts(:jonathan_sky).tag_list.add("Random")
365
+ posts(:jonathan_sky).save!
366
+
367
+ assert_difference 'Tag.count', -1 do
368
+ posts(:jonathan_sky).tag_list.remove("Random")
369
+ posts(:jonathan_sky).save!
370
+ end
371
+ ensure
372
+ Tag.destroy_unused = false
373
+ end
374
+ end
375
+
376
+ #class ActsAsTaggableOnSteroidsFormTest < ActiveSupport::TestCase
377
+ # include ActionView::Helpers::FormHelper
378
+ #
379
+ # def test_tag_list_contents
380
+ # fields_for :post, posts(:jonathan_sky) do |f|
381
+ # assert_match posts(:jonathan_sky).tag_list.to_s, f.text_field(:tag_list)
382
+ # end
383
+ # end
384
+ #end
data/test/database.yml ADDED
@@ -0,0 +1,11 @@
1
+ mysql:
2
+ adapter: mysql
3
+ host: localhost
4
+ username: root
5
+ password:
6
+ database: rails_plugin_test
7
+
8
+ sqlite3:
9
+ adapter: sqlite3
10
+ database: ':memory:'
11
+
@@ -0,0 +1,3 @@
1
+ class Magazine < ActiveRecord::Base
2
+ acts_as_taggable
3
+ end
@@ -0,0 +1,5 @@
1
+ ruby:
2
+ name: Ruby
3
+
4
+ rails:
5
+ name: Rails
@@ -0,0 +1,8 @@
1
+ class Photo < ActiveRecord::Base
2
+ acts_as_taggable
3
+
4
+ belongs_to :user
5
+ end
6
+
7
+ class SpecialPhoto < Photo
8
+ end
@@ -0,0 +1,19 @@
1
+ jonathan_dog:
2
+ user: jonathan
3
+ title: A small dog
4
+
5
+ jonathan_questioning_dog:
6
+ user: jonathan
7
+ title: What does this dog want?
8
+
9
+ jonathan_bad_cat:
10
+ user: jonathan
11
+ title: Bad cat
12
+
13
+ sam_flower:
14
+ user: sam
15
+ title: Flower
16
+
17
+ sam_sky:
18
+ user: sam
19
+ title: Sky
@@ -0,0 +1,7 @@
1
+ class Post < ActiveRecord::Base
2
+ acts_as_taggable
3
+
4
+ belongs_to :user
5
+
6
+ validates_presence_of :text
7
+ end
@@ -0,0 +1,27 @@
1
+ jonathan_sky:
2
+ user: jonathan
3
+ text: The sky is particularly blue today
4
+
5
+ jonathan_grass:
6
+ user: jonathan
7
+ text: The grass seems very green
8
+
9
+ jonathan_rain:
10
+ user: jonathan
11
+ text: Why does the rain fall?
12
+
13
+ jonathan_cloudy:
14
+ user: jonathan
15
+ text: Is it cloudy?
16
+
17
+ jonathan_still_cloudy:
18
+ user: jonathan
19
+ text: Is it still cloudy?
20
+
21
+ sam_ground:
22
+ user: sam
23
+ text: The ground is looking too brown
24
+
25
+ sam_flowers:
26
+ user: sam
27
+ text: Why are the flowers dead?
@@ -0,0 +1,2 @@
1
+ class SpecialPost < Post
2
+ end
@@ -0,0 +1,4 @@
1
+ class Subscription < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :magazine
4
+ end
@@ -0,0 +1,3 @@
1
+ jonathan_rails:
2
+ user: jonathan
3
+ magazine: ruby
@@ -0,0 +1,107 @@
1
+ # Posts
2
+ jonathan_sky_good:
3
+ tag: good
4
+ taggable: jonathan_sky (Post)
5
+ created_at: 2006-08-01
6
+
7
+ jonathan_sky_nature:
8
+ tag: nature
9
+ taggable: jonathan_sky (Post)
10
+ created_at: 2006-08-02
11
+
12
+ jonathan_grass_nature:
13
+ tag: nature
14
+ taggable: jonathan_grass (Post)
15
+ created_at: 2006-08-03
16
+
17
+ jonathan_rain_question:
18
+ tag: question
19
+ taggable: jonathan_rain (Post)
20
+ created_at: 2006-08-04
21
+
22
+ jonathan_rain_nature:
23
+ tag: nature
24
+ taggable: jonathan_rain (Post)
25
+ created_at: 2006-08-05
26
+
27
+ jonathan_cloudy_nature:
28
+ tag: nature
29
+ taggable: jonathan_cloudy (Post)
30
+ created_at: 2006-08-06
31
+
32
+ jonathan_still_cloudy_nature:
33
+ tag: nature
34
+ taggable: jonathan_still_cloudy (Post)
35
+ created_at: 2006-08-07
36
+
37
+ sam_ground_nature:
38
+ tag: nature
39
+ taggable: sam_ground (Post)
40
+ created_at: 2006-08-08
41
+
42
+ sam_ground_bad:
43
+ tag: bad
44
+ taggable: sam_ground (Post)
45
+ created_at: 2006-08-09
46
+
47
+ sam_flowers_good:
48
+ tag: good
49
+ taggable: sam_flowers (Post)
50
+ created_at: 2006-08-10
51
+
52
+ sam_flowers_nature:
53
+ tag: nature
54
+ taggable: sam_flowers (Post)
55
+ created_at: 2006-08-11
56
+
57
+ # Photos
58
+ jonathan_dog_animal:
59
+ tag: animal
60
+ taggable: jonathan_dog (Photo)
61
+ created_at: 2006-08-12
62
+
63
+ jonathan_dog_nature:
64
+ tag: nature
65
+ taggable: jonathan_dog (Photo)
66
+ created_at: 2006-08-13
67
+
68
+ jonathan_questioning_dog_animal:
69
+ tag: animal
70
+ taggable: jonathan_questioning_dog (Photo)
71
+ created_at: 2006-08-14
72
+
73
+ jonathan_questioning_dog_question:
74
+ tag: question
75
+ taggable: jonathan_questioning_dog (Photo)
76
+ created_at: 2006-08-15
77
+
78
+ jonathan_bad_cat_bad:
79
+ tag: bad
80
+ taggable: jonathan_bad_cat (Photo)
81
+ created_at: 2006-08-16
82
+
83
+ jonathan_bad_cat_animal:
84
+ tag: animal
85
+ taggable: jonathan_bad_cat (Photo)
86
+ created_at: 2006-08-17
87
+
88
+ sam_flower_nature:
89
+ tag: nature
90
+ taggable: sam_flower (Photo)
91
+ created_at: 2006-08-18
92
+
93
+ sam_flower_good:
94
+ tag: good
95
+ taggable: sam_flower (Photo)
96
+ created_at: 2006-08-19
97
+
98
+ sam_sky_nature:
99
+ tag: nature
100
+ taggable: sam_sky (Photo)
101
+ created_at: 2006-08-20
102
+
103
+ # Magazines
104
+ ruby_good:
105
+ tag: good
106
+ taggable: ruby (Magazine)
107
+ created_at: 2007-08-25
@@ -0,0 +1,14 @@
1
+ good:
2
+ name: Very good
3
+
4
+ bad:
5
+ name: Bad
6
+
7
+ nature:
8
+ name: Nature
9
+
10
+ question:
11
+ name: Question
12
+
13
+ animal:
14
+ name: Crazy animal
@@ -0,0 +1,7 @@
1
+ class User < ActiveRecord::Base
2
+ has_many :posts
3
+ has_many :photos
4
+
5
+ has_many :subscriptions
6
+ has_many :magazines, :through => :subscriptions
7
+ end
@@ -0,0 +1,5 @@
1
+ jonathan:
2
+ name: Jonathan
3
+
4
+ sam:
5
+ name: Sam
data/test/schema.rb ADDED
@@ -0,0 +1,48 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table :tags, :force => true do |t|
3
+ t.column :name, :string
4
+ end
5
+
6
+ create_table :taggings, :force => true do |t|
7
+ t.column :tag_id, :integer
8
+ t.column :taggable_id, :integer
9
+ t.column :taggable_type, :string
10
+ t.column :created_at, :datetime
11
+ end
12
+
13
+ create_table :categories, :force => true do |t|
14
+ t.column :name, :string
15
+ end
16
+
17
+ create_table :categorisations, :force => true do |t|
18
+ t.column :tag_id, :integer
19
+ t.column :taggable_id, :integer
20
+ t.column :taggable_type, :string
21
+ t.column :created_at, :datetime
22
+ end
23
+
24
+ create_table :users, :force => true do |t|
25
+ t.column :name, :string
26
+ end
27
+
28
+ create_table :posts, :force => true do |t|
29
+ t.column :text, :text
30
+ t.column :cached_tag_list, :string
31
+ t.column :user_id, :integer
32
+ t.column :type, :string
33
+ end
34
+
35
+ create_table :photos, :force => true do |t|
36
+ t.column :title, :string
37
+ t.column :user_id, :integer
38
+ end
39
+
40
+ create_table :subscriptions, :force => true do |t|
41
+ t.column :user_id, :integer
42
+ t.column :magazine_id, :integer
43
+ end
44
+
45
+ create_table :magazines, :force => true do |t|
46
+ t.column :name, :string
47
+ end
48
+ end