has_many_polymorphs 2.11 → 2.12
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +3 -1
- data/Manifest +43 -61
- data/README +30 -0
- data/TODO +0 -3
- data/generators/tagging/tagging_generator.rb +2 -0
- data/generators/tagging/templates/tag_test.rb +7 -2
- data/generators/tagging/templates/tagging.rb +2 -2
- data/generators/tagging/templates/tagging_extensions.rb +49 -2
- data/generators/tagging/templates/tagging_test.rb +32 -9
- data/generators/tagging/templates/tags.yml +2 -2
- data/has_many_polymorphs.gemspec +20 -13
- data/lib/has_many_polymorphs.rb +0 -1
- data/lib/has_many_polymorphs/autoload.rb +45 -37
- data/lib/has_many_polymorphs/class_methods.rb +2 -15
- data/lib/has_many_polymorphs/configuration.rb +2 -2
- data/lib/has_many_polymorphs/rake_task_redefine_task.rb +9 -1
- data/test/generator/tagging_generator_test.rb +42 -0
- data/test/integration/app/app/controllers/bones_controller.rb +5 -0
- data/test/integration/app/app/helpers/bones_helper.rb +2 -0
- data/test/integration/app/app/models/bone.rb +2 -0
- data/test/integration/app/app/models/double_sti_parent.rb +2 -0
- data/test/integration/app/app/models/double_sti_parent_relationship.rb +2 -0
- data/test/integration/app/app/models/organic_substance.rb +2 -0
- data/test/integration/app/app/models/single_sti_parent.rb +4 -0
- data/test/integration/app/app/models/single_sti_parent_relationship.rb +4 -0
- data/test/integration/app/app/models/stick.rb +2 -0
- data/test/integration/app/app/models/stone.rb +2 -0
- data/test/integration/app/app/views/bones/index.rhtml +5 -0
- data/test/integration/app/config/boot.rb +97 -32
- data/test/integration/app/config/database.yml +8 -12
- data/test/integration/app/config/environment.rb +9 -3
- data/test/integration/app/config/environment.rb.canonical +19 -0
- data/test/integration/app/config/environments/development.rb +6 -5
- data/test/integration/app/db/migrate/001_create_sticks.rb +11 -0
- data/test/integration/app/db/migrate/002_create_stones.rb +11 -0
- data/test/integration/app/db/migrate/003_create_organic_substances.rb +11 -0
- data/test/integration/app/db/migrate/004_create_bones.rb +8 -0
- data/test/integration/app/db/migrate/005_create_single_sti_parents.rb +11 -0
- data/test/integration/app/db/migrate/006_create_double_sti_parents.rb +11 -0
- data/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb +13 -0
- data/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb +14 -0
- data/test/integration/app/db/migrate/009_create_library_model.rb +11 -0
- data/test/integration/app/db/schema.rb +21 -121
- data/test/integration/app/hmp_development +0 -0
- data/test/integration/app/lib/library_model.rb +2 -0
- data/test/integration/app/test/fixtures/double_sti_parent_relationships.yml +7 -0
- data/test/integration/app/test/fixtures/double_sti_parents.yml +7 -0
- data/test/integration/app/test/fixtures/organic_substances.yml +5 -0
- data/test/integration/app/test/fixtures/single_sti_parent_relationships.yml +7 -0
- data/test/integration/app/test/fixtures/single_sti_parents.yml +7 -0
- data/test/integration/app/test/fixtures/sticks.yml +7 -0
- data/test/integration/app/test/fixtures/stones.yml +7 -0
- data/test/integration/app/test/{unit/user_test.rb → functional/bones_controller_test.rb} +1 -3
- data/test/integration/app/test/test_helper.rb +1 -21
- data/test/integration/app/test/unit/{state_test.rb → bone_test.rb} +1 -3
- data/test/integration/app/test/unit/{seller_test.rb → double_sti_parent_relationship_test.rb} +1 -3
- data/test/integration/app/test/unit/{address_test.rb → double_sti_parent_test.rb} +1 -3
- data/test/integration/app/test/unit/organic_substance_test.rb +8 -0
- data/test/integration/app/test/unit/single_sti_parent_relationship_test.rb +8 -0
- data/test/integration/app/test/unit/single_sti_parent_test.rb +8 -0
- data/test/integration/app/test/unit/stick_test.rb +8 -0
- data/test/integration/app/test/unit/stone_test.rb +8 -0
- data/test/integration/server_test.rb +43 -0
- data/test/patches/symlinked_plugins_1.2.6.diff +46 -0
- data/test/setup.rb +6 -2
- data/test/test_helper.rb +32 -16
- data/test/unit/{polymorph_test.rb → has_many_polymorphs_test.rb} +16 -16
- metadata +49 -65
- metadata.gz.sig +0 -0
- data/generators/commenting/commenting_generator.rb +0 -94
- data/generators/commenting/templates/comment.rb +0 -33
- data/generators/commenting/templates/comment_test.rb +0 -12
- data/generators/commenting/templates/commenting.rb +0 -13
- data/generators/commenting/templates/commenting_extensions.rb +0 -30
- data/generators/commenting/templates/commenting_test.rb +0 -30
- data/generators/commenting/templates/commentings.yml +0 -23
- data/generators/commenting/templates/comments.yml +0 -13
- data/generators/commenting/templates/migration.rb +0 -28
- data/lib/has_many_polymorphs/dependencies.rb +0 -41
- data/test/integration/app/app/controllers/addresses_controller.rb +0 -85
- data/test/integration/app/app/controllers/sellers_controller.rb +0 -85
- data/test/integration/app/app/controllers/states_controller.rb +0 -85
- data/test/integration/app/app/controllers/users_controller.rb +0 -85
- data/test/integration/app/app/models/address.rb +0 -4
- data/test/integration/app/app/models/citation.rb +0 -3
- data/test/integration/app/app/models/citations_item.rb +0 -4
- data/test/integration/app/app/models/seller.rb +0 -4
- data/test/integration/app/app/models/state.rb +0 -3
- data/test/integration/app/app/models/user.rb +0 -4
- data/test/integration/app/db/migrate/001_create_users.rb +0 -16
- data/test/integration/app/db/migrate/002_create_sellers.rb +0 -14
- data/test/integration/app/db/migrate/003_create_addresses.rb +0 -19
- data/test/integration/app/db/migrate/004_create_states.rb +0 -12
- data/test/integration/app/db/migrate/005_add_capitalization_to_seller.rb +0 -9
- data/test/integration/app/db/migrate/006_add_deleted_to_user.rb +0 -9
- data/test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb +0 -11
- data/test/integration/app/db/migrate/008_create_citations.rb +0 -12
- data/test/integration/app/db/migrate/009_create_citations_items.rb +0 -14
- data/test/integration/app/generated_models/aquatic_fish.rb +0 -109
- data/test/integration/app/generated_models/aquatic_pupils_whale.rb +0 -13
- data/test/integration/app/generated_models/aquatic_whale.rb +0 -42
- data/test/integration/app/generated_models/beautiful_fight_relationship.rb +0 -25
- data/test/integration/app/generated_models/citation.rb +0 -40
- data/test/integration/app/generated_models/citations_item.rb +0 -12
- data/test/integration/app/generated_models/dog.rb +0 -183
- data/test/integration/app/generated_models/eaters_foodstuff.rb +0 -13
- data/test/integration/app/generated_models/frog.rb +0 -78
- data/test/integration/app/generated_models/kitten.rb +0 -161
- data/test/integration/app/generated_models/parentship.rb +0 -14
- data/test/integration/app/generated_models/person.rb +0 -53
- data/test/integration/app/generated_models/petfood.rb +0 -125
- data/test/integration/app/generated_models/polymorph_test_some_model.rb +0 -25
- data/test/integration/app/generated_models/seller.rb +0 -30
- data/test/integration/app/generated_models/tabby.rb +0 -26
- data/test/integration/app/generated_models/user.rb +0 -34
- data/test/integration/app/generated_models/wild_boar.rb +0 -87
- data/test/integration/app/test/fixtures/addresses.yml +0 -13
- data/test/integration/app/test/fixtures/citations.yml +0 -9
- data/test/integration/app/test/fixtures/citations_items.yml +0 -9
- data/test/integration/app/test/fixtures/sellers.yml +0 -10
- data/test/integration/app/test/fixtures/states.yml +0 -216
- data/test/integration/app/test/fixtures/users.yml +0 -11
- data/test/integration/app/test/unit/citation_test.rb +0 -10
- data/test/integration/app/test/unit/citations_item_test.rb +0 -10
- data/test/test_all.rb +0 -16
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
|
2
|
-
v2.
|
2
|
+
v2.12. Improvements to the test suite; bugfixes for STI children (rsl). Remove fancy dependency system in favor of using Dispatcher::to_prepare every time.
|
3
|
+
|
4
|
+
v2.11. Rails 1.2.6 tagging generator compatibility; change test suite to use included integration app.
|
3
5
|
|
4
6
|
v2.10. Add :parent_conditions option; bugfix for nullified conditions; bugfix for self-referential tagging generator; allow setting of has_many_polymorphs_options hash in Configuration's after_initialize if you need to adjust the autoload behavior; clear error message on missing or improperly namespaced models; fix .build on double-sided relationships; add :namespace key for easier set up of Camping apps or other unusual class structures.
|
5
7
|
|
data/Manifest
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
examples/hmph.rb
|
3
|
-
generators/commenting/commenting_generator.rb
|
4
|
-
generators/commenting/templates/comment.rb
|
5
|
-
generators/commenting/templates/comment_test.rb
|
6
|
-
generators/commenting/templates/commenting.rb
|
7
|
-
generators/commenting/templates/commenting_extensions.rb
|
8
|
-
generators/commenting/templates/commenting_test.rb
|
9
|
-
generators/commenting/templates/commentings.yml
|
10
|
-
generators/commenting/templates/comments.yml
|
11
|
-
generators/commenting/templates/migration.rb
|
12
3
|
generators/tagging/tagging_generator.rb
|
13
4
|
generators/tagging/templates/migration.rb
|
14
5
|
generators/tagging/templates/tag.rb
|
@@ -25,7 +16,6 @@ lib/has_many_polymorphs/base.rb
|
|
25
16
|
lib/has_many_polymorphs/class_methods.rb
|
26
17
|
lib/has_many_polymorphs/configuration.rb
|
27
18
|
lib/has_many_polymorphs/debugging_tools.rb
|
28
|
-
lib/has_many_polymorphs/dependencies.rb
|
29
19
|
lib/has_many_polymorphs/rake_task_redefine_task.rb
|
30
20
|
lib/has_many_polymorphs/reflection.rb
|
31
21
|
lib/has_many_polymorphs/support_methods.rb
|
@@ -44,26 +34,28 @@ test/fixtures/people.yml
|
|
44
34
|
test/fixtures/petfoods.yml
|
45
35
|
test/fixtures/whales.yml
|
46
36
|
test/fixtures/wild_boars.yml
|
47
|
-
test/
|
37
|
+
test/generator/tagging_generator_test.rb
|
48
38
|
test/integration/app/app/controllers/application.rb
|
49
|
-
test/integration/app/app/controllers/
|
50
|
-
test/integration/app/app/controllers/states_controller.rb
|
51
|
-
test/integration/app/app/controllers/users_controller.rb
|
39
|
+
test/integration/app/app/controllers/bones_controller.rb
|
52
40
|
test/integration/app/app/helpers/addresses_helper.rb
|
53
41
|
test/integration/app/app/helpers/application_helper.rb
|
42
|
+
test/integration/app/app/helpers/bones_helper.rb
|
54
43
|
test/integration/app/app/helpers/sellers_helper.rb
|
55
44
|
test/integration/app/app/helpers/states_helper.rb
|
56
45
|
test/integration/app/app/helpers/users_helper.rb
|
57
|
-
test/integration/app/app/models/
|
58
|
-
test/integration/app/app/models/
|
59
|
-
test/integration/app/app/models/
|
60
|
-
test/integration/app/app/models/
|
61
|
-
test/integration/app/app/models/
|
62
|
-
test/integration/app/app/models/
|
46
|
+
test/integration/app/app/models/bone.rb
|
47
|
+
test/integration/app/app/models/double_sti_parent.rb
|
48
|
+
test/integration/app/app/models/double_sti_parent_relationship.rb
|
49
|
+
test/integration/app/app/models/organic_substance.rb
|
50
|
+
test/integration/app/app/models/single_sti_parent.rb
|
51
|
+
test/integration/app/app/models/single_sti_parent_relationship.rb
|
52
|
+
test/integration/app/app/models/stick.rb
|
53
|
+
test/integration/app/app/models/stone.rb
|
63
54
|
test/integration/app/app/views/addresses/edit.html.erb
|
64
55
|
test/integration/app/app/views/addresses/index.html.erb
|
65
56
|
test/integration/app/app/views/addresses/new.html.erb
|
66
57
|
test/integration/app/app/views/addresses/show.html.erb
|
58
|
+
test/integration/app/app/views/bones/index.rhtml
|
67
59
|
test/integration/app/app/views/layouts/addresses.html.erb
|
68
60
|
test/integration/app/app/views/layouts/sellers.html.erb
|
69
61
|
test/integration/app/app/views/layouts/states.html.erb
|
@@ -83,6 +75,7 @@ test/integration/app/app/views/users/show.html.erb
|
|
83
75
|
test/integration/app/config/boot.rb
|
84
76
|
test/integration/app/config/database.yml
|
85
77
|
test/integration/app/config/environment.rb
|
78
|
+
test/integration/app/config/environment.rb.canonical
|
86
79
|
test/integration/app/config/environments/development.rb
|
87
80
|
test/integration/app/config/environments/production.rb
|
88
81
|
test/integration/app/config/environments/test.rb
|
@@ -90,36 +83,20 @@ test/integration/app/config/locomotive.yml
|
|
90
83
|
test/integration/app/config/routes.rb
|
91
84
|
test/integration/app/config/ultrasphinx/default.base
|
92
85
|
test/integration/app/config/ultrasphinx/development.conf.canonical
|
93
|
-
test/integration/app/db/migrate/
|
94
|
-
test/integration/app/db/migrate/
|
95
|
-
test/integration/app/db/migrate/
|
96
|
-
test/integration/app/db/migrate/
|
97
|
-
test/integration/app/db/migrate/
|
98
|
-
test/integration/app/db/migrate/
|
99
|
-
test/integration/app/db/migrate/
|
100
|
-
test/integration/app/db/migrate/
|
101
|
-
test/integration/app/db/migrate/
|
86
|
+
test/integration/app/db/migrate/001_create_sticks.rb
|
87
|
+
test/integration/app/db/migrate/002_create_stones.rb
|
88
|
+
test/integration/app/db/migrate/003_create_organic_substances.rb
|
89
|
+
test/integration/app/db/migrate/004_create_bones.rb
|
90
|
+
test/integration/app/db/migrate/005_create_single_sti_parents.rb
|
91
|
+
test/integration/app/db/migrate/006_create_double_sti_parents.rb
|
92
|
+
test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb
|
93
|
+
test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb
|
94
|
+
test/integration/app/db/migrate/009_create_library_model.rb
|
102
95
|
test/integration/app/db/schema.rb
|
103
96
|
test/integration/app/doc/README_FOR_APP
|
104
|
-
test/integration/app/generated_models/aquatic_fish.rb
|
105
|
-
test/integration/app/generated_models/aquatic_pupils_whale.rb
|
106
|
-
test/integration/app/generated_models/aquatic_whale.rb
|
107
|
-
test/integration/app/generated_models/beautiful_fight_relationship.rb
|
108
|
-
test/integration/app/generated_models/citation.rb
|
109
|
-
test/integration/app/generated_models/citations_item.rb
|
110
|
-
test/integration/app/generated_models/dog.rb
|
111
|
-
test/integration/app/generated_models/eaters_foodstuff.rb
|
112
|
-
test/integration/app/generated_models/frog.rb
|
113
|
-
test/integration/app/generated_models/kitten.rb
|
114
|
-
test/integration/app/generated_models/parentship.rb
|
115
|
-
test/integration/app/generated_models/person.rb
|
116
|
-
test/integration/app/generated_models/petfood.rb
|
117
|
-
test/integration/app/generated_models/polymorph_test_some_model.rb
|
118
|
-
test/integration/app/generated_models/seller.rb
|
119
|
-
test/integration/app/generated_models/tabby.rb
|
120
|
-
test/integration/app/generated_models/user.rb
|
121
|
-
test/integration/app/generated_models/wild_boar.rb
|
122
97
|
test/integration/app/generators/commenting_generator_test.rb
|
98
|
+
test/integration/app/hmp_development
|
99
|
+
test/integration/app/lib/library_model.rb
|
123
100
|
test/integration/app/public/404.html
|
124
101
|
test/integration/app/public/500.html
|
125
102
|
test/integration/app/public/dispatch.cgi
|
@@ -150,23 +127,28 @@ test/integration/app/script/process/reaper
|
|
150
127
|
test/integration/app/script/process/spawner
|
151
128
|
test/integration/app/script/runner
|
152
129
|
test/integration/app/script/server
|
153
|
-
test/integration/app/test/fixtures/
|
154
|
-
test/integration/app/test/fixtures/
|
155
|
-
test/integration/app/test/fixtures/
|
156
|
-
test/integration/app/test/fixtures/
|
157
|
-
test/integration/app/test/fixtures/
|
158
|
-
test/integration/app/test/fixtures/
|
130
|
+
test/integration/app/test/fixtures/double_sti_parent_relationships.yml
|
131
|
+
test/integration/app/test/fixtures/double_sti_parents.yml
|
132
|
+
test/integration/app/test/fixtures/organic_substances.yml
|
133
|
+
test/integration/app/test/fixtures/single_sti_parent_relationships.yml
|
134
|
+
test/integration/app/test/fixtures/single_sti_parents.yml
|
135
|
+
test/integration/app/test/fixtures/sticks.yml
|
136
|
+
test/integration/app/test/fixtures/stones.yml
|
159
137
|
test/integration/app/test/functional/addresses_controller_test.rb
|
138
|
+
test/integration/app/test/functional/bones_controller_test.rb
|
160
139
|
test/integration/app/test/functional/sellers_controller_test.rb
|
161
140
|
test/integration/app/test/functional/states_controller_test.rb
|
162
141
|
test/integration/app/test/functional/users_controller_test.rb
|
163
142
|
test/integration/app/test/test_helper.rb
|
164
|
-
test/integration/app/test/unit/
|
165
|
-
test/integration/app/test/unit/
|
166
|
-
test/integration/app/test/unit/
|
167
|
-
test/integration/app/test/unit/
|
168
|
-
test/integration/app/test/unit/
|
169
|
-
test/integration/app/test/unit/
|
143
|
+
test/integration/app/test/unit/bone_test.rb
|
144
|
+
test/integration/app/test/unit/double_sti_parent_relationship_test.rb
|
145
|
+
test/integration/app/test/unit/double_sti_parent_test.rb
|
146
|
+
test/integration/app/test/unit/organic_substance_test.rb
|
147
|
+
test/integration/app/test/unit/single_sti_parent_relationship_test.rb
|
148
|
+
test/integration/app/test/unit/single_sti_parent_test.rb
|
149
|
+
test/integration/app/test/unit/stick_test.rb
|
150
|
+
test/integration/app/test/unit/stone_test.rb
|
151
|
+
test/integration/server_test.rb
|
170
152
|
test/models/aquatic/fish.rb
|
171
153
|
test/models/aquatic/pupils_whale.rb
|
172
154
|
test/models/aquatic/whale.rb
|
@@ -184,9 +166,9 @@ test/models/tabby.rb
|
|
184
166
|
test/models/wild_boar.rb
|
185
167
|
test/modules/extension_module.rb
|
186
168
|
test/modules/other_extension_module.rb
|
169
|
+
test/patches/symlinked_plugins_1.2.6.diff
|
187
170
|
test/schema.rb
|
188
171
|
test/setup.rb
|
189
|
-
test/test_all.rb
|
190
172
|
test/test_helper.rb
|
191
|
-
test/unit/
|
173
|
+
test/unit/has_many_polymorphs_test.rb
|
192
174
|
TODO
|
data/README
CHANGED
@@ -63,6 +63,21 @@ One of the child models:
|
|
63
63
|
# nothing
|
64
64
|
end
|
65
65
|
|
66
|
+
For your parent and child models, you don't need any special fields in your migration. For the join model (GuestsKennel), use a migration like so:
|
67
|
+
|
68
|
+
class CreateGuestsKennels < ActiveRecord::Migration
|
69
|
+
def self.up
|
70
|
+
create_table :guests_kennels do |t|
|
71
|
+
t.references :guest, :polymorphic => true
|
72
|
+
t.references :kennel
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.down
|
77
|
+
drop_table :guests_kennels
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
66
81
|
See ActiveRecord::Associations::PolymorphicClassMethods for more configuration options.
|
67
82
|
|
68
83
|
== Helper methods example
|
@@ -113,6 +128,21 @@ Now, dogs and cats can eat birds and cats. Birds can't eat anything (they aren't
|
|
113
128
|
|
114
129
|
In this case, each guest/eaten relationship is called a Devouring.
|
115
130
|
|
131
|
+
In your migration, you need to declare both sides as polymorphic:
|
132
|
+
|
133
|
+
class CreateDevourings < ActiveRecord::Migration
|
134
|
+
def self.up
|
135
|
+
create_table :devourings do |t|
|
136
|
+
t.references :guest, :polymorphic => true
|
137
|
+
t.references :eaten, :polymorphic => true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.down
|
142
|
+
drop_table :devourings
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
116
146
|
See ActiveRecord::Associations::PolymorphicClassMethods for more.
|
117
147
|
|
118
148
|
== Tagging generator
|
data/TODO
CHANGED
@@ -7,6 +7,8 @@ class TaggingGenerator < Rails::Generator::NamedBase
|
|
7
7
|
attr_reader :taggable_models
|
8
8
|
|
9
9
|
def initialize(runtime_args, runtime_options = {})
|
10
|
+
parse!(runtime_args, runtime_options)
|
11
|
+
|
10
12
|
@parent_association_name = (runtime_args.include?("--self-referential") ? "tagger" : "tag")
|
11
13
|
@taggable_models = runtime_args.reject{|opt| opt =~ /^--/}.map do |taggable|
|
12
14
|
":" + taggable.underscore.pluralize
|
@@ -1,10 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
3
|
class TagTest < Test::Unit::TestCase
|
4
|
-
fixtures
|
4
|
+
fixtures <%= taggable_models[0..1].join(", ") -%>
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@obj = <%= model_two %>.find(:first)
|
8
|
+
@obj.tag_with "pale imperial"
|
9
|
+
end
|
5
10
|
|
6
11
|
def test_to_s
|
7
|
-
assert_equal "
|
12
|
+
assert_equal "imperial pale", <%= model_two -%>.find(:first).tags.to_s
|
8
13
|
end
|
9
14
|
|
10
15
|
end
|
@@ -10,7 +10,7 @@ class Tagging < ActiveRecord::Base
|
|
10
10
|
# acts_as_list :scope => :taggable
|
11
11
|
|
12
12
|
# This callback makes sure that an orphaned <tt>Tag</tt> is deleted if it no longer tags anything.
|
13
|
-
def
|
14
|
-
<%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.taggings.count ==
|
13
|
+
def after_destroy
|
14
|
+
<%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.taggings.count == 0
|
15
15
|
end
|
16
16
|
end
|
@@ -99,8 +99,55 @@ class ActiveRecord::Base #:nodoc:
|
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
102
|
+
|
103
|
+
module TaggingFinders
|
104
|
+
#
|
105
|
+
# Find all the objects tagged with the supplied list of tags
|
106
|
+
#
|
107
|
+
# Usage : Model.tagged_with("ruby")
|
108
|
+
# Model.tagged_with("hello", "world")
|
109
|
+
# Model.tagged_with("hello", "world", :limit => 10)
|
110
|
+
#
|
111
|
+
def tagged_with(*tag_list)
|
112
|
+
options = tag_list.last.is_a?(Hash) ? tag_list.pop : {}
|
113
|
+
tag_list = parse_tags(tag_list)
|
114
|
+
|
115
|
+
scope = scope(:find)
|
116
|
+
options[:select] ||= "#{table_name}.*"
|
117
|
+
options[:from] ||= "#{table_name}, tags, taggings"
|
118
|
+
|
119
|
+
sql = "SELECT #{(scope && scope[:select]) || options[:select]} "
|
120
|
+
sql << "FROM #{(scope && scope[:from]) || options[:from]} "
|
102
121
|
|
103
|
-
|
122
|
+
add_joins!(sql, options, scope)
|
123
|
+
|
124
|
+
sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
|
125
|
+
sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
|
126
|
+
sql << "AND taggings.tag_id = tags.id "
|
127
|
+
|
128
|
+
tag_list_condition = tag_list.map {|t| "'#{t}'"}.join(", ")
|
129
|
+
|
130
|
+
sql << "AND (tags.name IN (#{sanitize_sql(tag_list_condition)})) "
|
131
|
+
sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions]
|
132
|
+
sql << "GROUP BY #{table_name}.id "
|
133
|
+
sql << "HAVING COUNT(taggings.tag_id) = #{tag_list.size}"
|
134
|
+
|
135
|
+
add_order!(sql, options[:order], scope)
|
136
|
+
add_limit!(sql, options, scope)
|
137
|
+
add_lock!(sql, options, scope)
|
138
|
+
|
139
|
+
find_by_sql(sql)
|
140
|
+
end
|
141
|
+
|
142
|
+
def parse_tags(tags)
|
143
|
+
return [] if tags.blank?
|
144
|
+
tags = Array(tags).first
|
145
|
+
tags = tags.respond_to?(:flatten) ? tags.flatten : tags.split(Tag::DELIMITER)
|
146
|
+
tags.map { |tag| tag.strip.squeeze(" ") }.flatten.compact.map(&:downcase).uniq
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
104
150
|
|
151
|
+
include TaggingExtensions
|
152
|
+
extend TaggingFinders
|
105
153
|
end
|
106
|
-
|
@@ -1,13 +1,21 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
3
|
class TaggingTest < Test::Unit::TestCase
|
4
|
-
fixtures :
|
4
|
+
fixtures :tags, :taggings, <%= taggable_models[0..1].join(", ") -%>
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@
|
8
|
-
|
7
|
+
@objs = <%= model_two %>.find(:all, :limit => 2)
|
8
|
+
|
9
|
+
@obj1 = @objs[0]
|
10
|
+
@obj1.tag_with("pale")
|
11
|
+
@obj1.reload
|
12
|
+
|
13
|
+
@obj2 = @objs[1]
|
14
|
+
@obj2.tag_with("pale imperial")
|
15
|
+
@obj2.reload
|
16
|
+
|
9
17
|
<% if taggable_models.size > 1 -%>
|
10
|
-
@obj3 = <%= model_one -%>.find(
|
18
|
+
@obj3 = <%= model_one -%>.find(:first)
|
11
19
|
<% end -%>
|
12
20
|
@tag1 = Tag.find(1)
|
13
21
|
@tag2 = Tag.find(2)
|
@@ -15,8 +23,23 @@ class TaggingTest < Test::Unit::TestCase
|
|
15
23
|
end
|
16
24
|
|
17
25
|
def test_tag_with
|
18
|
-
@obj2.tag_with "
|
19
|
-
assert_equal "
|
26
|
+
@obj2.tag_with "hoppy pilsner"
|
27
|
+
assert_equal "hoppy pilsner", @obj2.tag_list
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_find_tagged_with
|
31
|
+
@obj1.tag_with "seasonal lager ipa"
|
32
|
+
@obj2.tag_with ["lager", "stout", "fruity", "seasonal"]
|
33
|
+
|
34
|
+
result1 = [@obj1]
|
35
|
+
assert_equal <%= model_two %>.tagged_with("ipa"), result1
|
36
|
+
assert_equal <%= model_two %>.tagged_with("ipa lager"), result1
|
37
|
+
assert_equal <%= model_two %>.tagged_with("ipa", "lager"), result1
|
38
|
+
|
39
|
+
result2 = [@obj1.id, @obj2.id].sort
|
40
|
+
assert_equal <%= model_two %>.tagged_with("seasonal").map(&:id).sort, result2
|
41
|
+
assert_equal <%= model_two %>.tagged_with("seasonal lager").map(&:id).sort, result2
|
42
|
+
assert_equal <%= model_two %>.tagged_with("seasonal", "lager").map(&:id).sort, result2
|
20
43
|
end
|
21
44
|
|
22
45
|
<% if options[:self_referential] -%>
|
@@ -31,10 +54,10 @@ class TaggingTest < Test::Unit::TestCase
|
|
31
54
|
@obj1._add_tags "porter longneck"
|
32
55
|
assert Tag.find_by_name("porter").taggables.include?(@obj1)
|
33
56
|
assert Tag.find_by_name("longneck").taggables.include?(@obj1)
|
34
|
-
assert_equal "
|
57
|
+
assert_equal "longneck pale porter", @obj1.tag_list
|
35
58
|
|
36
59
|
@obj1._add_tags [2]
|
37
|
-
assert_equal "
|
60
|
+
assert_equal "imperial longneck pale porter", @obj1.tag_list
|
38
61
|
end
|
39
62
|
|
40
63
|
def test__remove_tags
|
@@ -43,7 +66,7 @@ class TaggingTest < Test::Unit::TestCase
|
|
43
66
|
end
|
44
67
|
|
45
68
|
def test_tag_list
|
46
|
-
assert_equal "
|
69
|
+
assert_equal "imperial pale", @obj2.tag_list
|
47
70
|
end
|
48
71
|
|
49
72
|
def test_taggable
|
data/has_many_polymorphs.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Has_many_polymorphs-2.
|
2
|
+
# Gem::Specification for Has_many_polymorphs-2.12
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{has_many_polymorphs}
|
7
|
-
s.version = "2.
|
7
|
+
s.version = "2.12"
|
8
8
|
|
9
9
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = [""]
|
13
|
-
s.date = %q{
|
13
|
+
s.date = %q{2008-01-16}
|
14
14
|
s.description = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.}
|
15
15
|
s.email = %q{}
|
16
|
-
s.files = ["CHANGELOG", "examples/hmph.rb", "generators/
|
16
|
+
s.files = ["CHANGELOG", "examples/hmph.rb", "generators/tagging/tagging_generator.rb", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tag_test.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "generators/tagging/templates/tagging_test.rb", "generators/tagging/templates/taggings.yml", "generators/tagging/templates/tags.yml", "init.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/base.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/debugging_tools.rb", "lib/has_many_polymorphs/rake_task_redefine_task.rb", "lib/has_many_polymorphs/reflection.rb", "lib/has_many_polymorphs/support_methods.rb", "lib/has_many_polymorphs.rb", "LICENSE", "Manifest", "README", "test/fixtures/bow_wows.yml", "test/fixtures/cats.yml", "test/fixtures/eaters_foodstuffs.yml", "test/fixtures/fish.yml", "test/fixtures/frogs.yml", "test/fixtures/keep_your_enemies_close.yml", "test/fixtures/little_whale_pupils.yml", "test/fixtures/people.yml", "test/fixtures/petfoods.yml", "test/fixtures/whales.yml", "test/fixtures/wild_boars.yml", "test/generator/tagging_generator_test.rb", "test/integration/app/app/controllers/application.rb", "test/integration/app/app/controllers/bones_controller.rb", "test/integration/app/app/helpers/addresses_helper.rb", "test/integration/app/app/helpers/application_helper.rb", "test/integration/app/app/helpers/bones_helper.rb", "test/integration/app/app/helpers/sellers_helper.rb", "test/integration/app/app/helpers/states_helper.rb", "test/integration/app/app/helpers/users_helper.rb", "test/integration/app/app/models/bone.rb", "test/integration/app/app/models/double_sti_parent.rb", "test/integration/app/app/models/double_sti_parent_relationship.rb", "test/integration/app/app/models/organic_substance.rb", "test/integration/app/app/models/single_sti_parent.rb", "test/integration/app/app/models/single_sti_parent_relationship.rb", "test/integration/app/app/models/stick.rb", "test/integration/app/app/models/stone.rb", "test/integration/app/app/views/addresses/edit.html.erb", "test/integration/app/app/views/addresses/index.html.erb", "test/integration/app/app/views/addresses/new.html.erb", "test/integration/app/app/views/addresses/show.html.erb", "test/integration/app/app/views/bones/index.rhtml", "test/integration/app/app/views/layouts/addresses.html.erb", "test/integration/app/app/views/layouts/sellers.html.erb", "test/integration/app/app/views/layouts/states.html.erb", "test/integration/app/app/views/layouts/users.html.erb", "test/integration/app/app/views/sellers/edit.html.erb", "test/integration/app/app/views/sellers/index.html.erb", "test/integration/app/app/views/sellers/new.html.erb", "test/integration/app/app/views/sellers/show.html.erb", "test/integration/app/app/views/states/edit.html.erb", "test/integration/app/app/views/states/index.html.erb", "test/integration/app/app/views/states/new.html.erb", "test/integration/app/app/views/states/show.html.erb", "test/integration/app/app/views/users/edit.html.erb", "test/integration/app/app/views/users/index.html.erb", "test/integration/app/app/views/users/new.html.erb", "test/integration/app/app/views/users/show.html.erb", "test/integration/app/config/boot.rb", "test/integration/app/config/database.yml", "test/integration/app/config/environment.rb", "test/integration/app/config/environment.rb.canonical", "test/integration/app/config/environments/development.rb", "test/integration/app/config/environments/production.rb", "test/integration/app/config/environments/test.rb", "test/integration/app/config/locomotive.yml", "test/integration/app/config/routes.rb", "test/integration/app/config/ultrasphinx/default.base", "test/integration/app/config/ultrasphinx/development.conf.canonical", "test/integration/app/db/migrate/001_create_sticks.rb", "test/integration/app/db/migrate/002_create_stones.rb", "test/integration/app/db/migrate/003_create_organic_substances.rb", "test/integration/app/db/migrate/004_create_bones.rb", "test/integration/app/db/migrate/005_create_single_sti_parents.rb", "test/integration/app/db/migrate/006_create_double_sti_parents.rb", "test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb", "test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb", "test/integration/app/db/migrate/009_create_library_model.rb", "test/integration/app/db/schema.rb", "test/integration/app/doc/README_FOR_APP", "test/integration/app/generators/commenting_generator_test.rb", "test/integration/app/hmp_development", "test/integration/app/lib/library_model.rb", "test/integration/app/public/404.html", "test/integration/app/public/500.html", "test/integration/app/public/dispatch.cgi", "test/integration/app/public/dispatch.fcgi", "test/integration/app/public/dispatch.rb", "test/integration/app/public/favicon.ico", "test/integration/app/public/images/rails.png", "test/integration/app/public/index.html", "test/integration/app/public/javascripts/application.js", "test/integration/app/public/javascripts/controls.js", "test/integration/app/public/javascripts/dragdrop.js", "test/integration/app/public/javascripts/effects.js", "test/integration/app/public/javascripts/prototype.js", "test/integration/app/public/robots.txt", "test/integration/app/public/stylesheets/scaffold.css", "test/integration/app/Rakefile", "test/integration/app/README", "test/integration/app/script/about", "test/integration/app/script/breakpointer", "test/integration/app/script/console", "test/integration/app/script/destroy", "test/integration/app/script/generate", "test/integration/app/script/performance/benchmarker", "test/integration/app/script/performance/profiler", "test/integration/app/script/plugin", "test/integration/app/script/process/inspector", "test/integration/app/script/process/reaper", "test/integration/app/script/process/spawner", "test/integration/app/script/runner", "test/integration/app/script/server", "test/integration/app/test/fixtures/double_sti_parent_relationships.yml", "test/integration/app/test/fixtures/double_sti_parents.yml", "test/integration/app/test/fixtures/organic_substances.yml", "test/integration/app/test/fixtures/single_sti_parent_relationships.yml", "test/integration/app/test/fixtures/single_sti_parents.yml", "test/integration/app/test/fixtures/sticks.yml", "test/integration/app/test/fixtures/stones.yml", "test/integration/app/test/functional/addresses_controller_test.rb", "test/integration/app/test/functional/bones_controller_test.rb", "test/integration/app/test/functional/sellers_controller_test.rb", "test/integration/app/test/functional/states_controller_test.rb", "test/integration/app/test/functional/users_controller_test.rb", "test/integration/app/test/test_helper.rb", "test/integration/app/test/unit/bone_test.rb", "test/integration/app/test/unit/double_sti_parent_relationship_test.rb", "test/integration/app/test/unit/double_sti_parent_test.rb", "test/integration/app/test/unit/organic_substance_test.rb", "test/integration/app/test/unit/single_sti_parent_relationship_test.rb", "test/integration/app/test/unit/single_sti_parent_test.rb", "test/integration/app/test/unit/stick_test.rb", "test/integration/app/test/unit/stone_test.rb", "test/integration/server_test.rb", "test/models/aquatic/fish.rb", "test/models/aquatic/pupils_whale.rb", "test/models/aquatic/whale.rb", "test/models/beautiful_fight_relationship.rb", "test/models/canine.rb", "test/models/cat.rb", "test/models/dog.rb", "test/models/eaters_foodstuff.rb", "test/models/frog.rb", "test/models/kitten.rb", "test/models/parentship.rb", "test/models/person.rb", "test/models/petfood.rb", "test/models/tabby.rb", "test/models/wild_boar.rb", "test/modules/extension_module.rb", "test/modules/other_extension_module.rb", "test/patches/symlinked_plugins_1.2.6.diff", "test/schema.rb", "test/setup.rb", "test/test_helper.rb", "test/unit/has_many_polymorphs_test.rb", "TODO", "has_many_polymorphs.gemspec"]
|
17
17
|
s.has_rdoc = true
|
18
18
|
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/}
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.rubyforge_project = %q{fauna}
|
21
|
-
s.rubygems_version = %q{0.
|
21
|
+
s.rubygems_version = %q{1.0.1}
|
22
22
|
s.summary = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.}
|
23
|
-
s.test_files = ["test/
|
23
|
+
s.test_files = ["test/generator/tagging_generator_test.rb", "test/integration/server_test.rb", "test/unit/has_many_polymorphs_test.rb"]
|
24
24
|
|
25
25
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
26
26
|
end
|
@@ -29,10 +29,7 @@ end
|
|
29
29
|
# # Original Rakefile source (requires the Echoe gem):
|
30
30
|
#
|
31
31
|
#
|
32
|
-
# require 'rubygems'
|
33
|
-
# gem 'echoe', '>=2.2'
|
34
32
|
# require 'echoe'
|
35
|
-
# require 'lib/has_many_polymorphs/rake_task_redefine_task'
|
36
33
|
#
|
37
34
|
# Echoe.new("has_many_polymorphs") do |p|
|
38
35
|
# p.project = "fauna"
|
@@ -42,10 +39,20 @@ end
|
|
42
39
|
# p.dependencies = ["activerecord"]
|
43
40
|
# p.rdoc_pattern = /polymorphs\/association|polymorphs\/class_methods|polymorphs\/reflection|polymorphs\/autoload|polymorphs\/configuration|README|CHANGELOG|TODO|LICENSE|templates\/migration\.rb|templates\/tag\.rb|templates\/tagging\.rb|templates\/tagging_extensions\.rb/
|
44
41
|
# p.require_signed = true
|
42
|
+
# p.clean_pattern += ["**/ruby_sess*", "**/generated_models/**"]
|
43
|
+
# p.test_pattern = ["test/unit/*_test.rb", "test/integration/*_test.rb", "test/generator/*_test.rb"]
|
45
44
|
# end
|
46
45
|
#
|
47
|
-
# desc
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
46
|
+
# desc "Run all the tests for every database adapter"
|
47
|
+
# task "test_all" do
|
48
|
+
# ['mysql', 'postgresql', 'sqlite3'].each do |adapter|
|
49
|
+
# ENV['DB'] = adapter
|
50
|
+
# ENV['PRODUCTION'] = nil
|
51
|
+
# STDERR.puts "#{'='*80}\nDevelopment mode for #{adapter}\n#{'='*80}"
|
52
|
+
# system("rake test:multi_rails:all")
|
53
|
+
#
|
54
|
+
# ENV['PRODUCTION'] = '1'
|
55
|
+
# STDERR.puts "#{'='*80}\nProduction mode for #{adapter}\n#{'='*80}"
|
56
|
+
# system("rake test:multi_rails:all")
|
57
|
+
# end
|
51
58
|
# end
|