has_many_polymorphs 2.10 → 2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +2 -0
  3. data/Manifest +191 -56
  4. data/TODO +1 -0
  5. data/examples/hmph.rb +69 -0
  6. data/generators/commenting/commenting_generator.rb +94 -0
  7. data/generators/commenting/templates/comment.rb +33 -0
  8. data/generators/commenting/templates/comment_test.rb +12 -0
  9. data/generators/commenting/templates/commenting.rb +13 -0
  10. data/generators/commenting/templates/commenting_extensions.rb +30 -0
  11. data/generators/commenting/templates/commenting_test.rb +30 -0
  12. data/generators/commenting/templates/commentings.yml +23 -0
  13. data/generators/commenting/templates/comments.yml +13 -0
  14. data/generators/commenting/templates/migration.rb +28 -0
  15. data/generators/tagging/templates/tagging_extensions.rb +4 -8
  16. data/has_many_polymorphs.gemspec +19 -12
  17. data/lib/has_many_polymorphs.rb +3 -4
  18. data/lib/has_many_polymorphs/autoload.rb +4 -4
  19. data/lib/has_many_polymorphs/class_methods.rb +8 -8
  20. data/lib/has_many_polymorphs/debugging_tools.rb +2 -0
  21. data/lib/has_many_polymorphs/dependencies.rb +9 -4
  22. data/lib/has_many_polymorphs/support_methods.rb +3 -1
  23. data/test/fixtures/{aquatic/fish.yml → fish.yml} +0 -0
  24. data/test/fixtures/{aquatic/little_whale_pupils.yml → little_whale_pupils.yml} +0 -0
  25. data/test/fixtures/{aquatic/whales.yml → whales.yml} +0 -0
  26. data/test/integration/app/README +182 -0
  27. data/test/integration/app/Rakefile +19 -0
  28. data/test/integration/app/app/controllers/addresses_controller.rb +85 -0
  29. data/test/integration/app/app/controllers/application.rb +7 -0
  30. data/test/integration/app/app/controllers/sellers_controller.rb +85 -0
  31. data/test/integration/app/app/controllers/states_controller.rb +85 -0
  32. data/test/integration/app/app/controllers/users_controller.rb +85 -0
  33. data/test/integration/app/app/helpers/addresses_helper.rb +2 -0
  34. data/test/integration/app/app/helpers/application_helper.rb +3 -0
  35. data/test/integration/app/app/helpers/sellers_helper.rb +28 -0
  36. data/test/integration/app/app/helpers/states_helper.rb +2 -0
  37. data/test/integration/app/app/helpers/users_helper.rb +2 -0
  38. data/test/integration/app/app/models/address.rb +4 -0
  39. data/test/integration/app/app/models/citation.rb +3 -0
  40. data/test/integration/app/app/models/citations_item.rb +4 -0
  41. data/test/integration/app/app/models/seller.rb +4 -0
  42. data/test/integration/app/app/models/state.rb +3 -0
  43. data/test/integration/app/app/models/user.rb +4 -0
  44. data/test/integration/app/app/views/addresses/edit.html.erb +12 -0
  45. data/test/integration/app/app/views/addresses/index.html.erb +18 -0
  46. data/test/integration/app/app/views/addresses/new.html.erb +11 -0
  47. data/test/integration/app/app/views/addresses/show.html.erb +3 -0
  48. data/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
  49. data/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
  50. data/test/integration/app/app/views/layouts/states.html.erb +17 -0
  51. data/test/integration/app/app/views/layouts/users.html.erb +17 -0
  52. data/test/integration/app/app/views/sellers/edit.html.erb +12 -0
  53. data/test/integration/app/app/views/sellers/index.html.erb +20 -0
  54. data/test/integration/app/app/views/sellers/new.html.erb +11 -0
  55. data/test/integration/app/app/views/sellers/show.html.erb +3 -0
  56. data/test/integration/app/app/views/states/edit.html.erb +12 -0
  57. data/test/integration/app/app/views/states/index.html.erb +19 -0
  58. data/test/integration/app/app/views/states/new.html.erb +11 -0
  59. data/test/integration/app/app/views/states/show.html.erb +3 -0
  60. data/test/integration/app/app/views/users/edit.html.erb +12 -0
  61. data/test/integration/app/app/views/users/index.html.erb +22 -0
  62. data/test/integration/app/app/views/users/new.html.erb +11 -0
  63. data/test/integration/app/app/views/users/show.html.erb +3 -0
  64. data/test/integration/app/config/boot.rb +45 -0
  65. data/test/integration/app/config/database.yml +21 -0
  66. data/test/integration/app/config/environment.rb +13 -0
  67. data/test/integration/app/config/environments/development.rb +7 -0
  68. data/test/integration/app/config/environments/production.rb +18 -0
  69. data/test/integration/app/config/environments/test.rb +19 -0
  70. data/test/integration/app/config/locomotive.yml +6 -0
  71. data/test/integration/app/config/routes.rb +33 -0
  72. data/test/integration/app/config/ultrasphinx/default.base +56 -0
  73. data/test/integration/app/config/ultrasphinx/development.conf.canonical +155 -0
  74. data/test/integration/app/db/migrate/001_create_users.rb +16 -0
  75. data/test/integration/app/db/migrate/002_create_sellers.rb +14 -0
  76. data/test/integration/app/db/migrate/003_create_addresses.rb +19 -0
  77. data/test/integration/app/db/migrate/004_create_states.rb +12 -0
  78. data/test/integration/app/db/migrate/005_add_capitalization_to_seller.rb +9 -0
  79. data/test/integration/app/db/migrate/006_add_deleted_to_user.rb +9 -0
  80. data/test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb +11 -0
  81. data/test/integration/app/db/migrate/008_create_citations.rb +12 -0
  82. data/test/integration/app/db/migrate/009_create_citations_items.rb +14 -0
  83. data/test/integration/app/db/schema.rb +144 -0
  84. data/test/integration/app/doc/README_FOR_APP +2 -0
  85. data/test/integration/app/generated_models/aquatic_fish.rb +109 -0
  86. data/test/integration/app/generated_models/aquatic_pupils_whale.rb +13 -0
  87. data/test/integration/app/generated_models/aquatic_whale.rb +42 -0
  88. data/test/integration/app/generated_models/beautiful_fight_relationship.rb +25 -0
  89. data/test/integration/app/generated_models/citation.rb +40 -0
  90. data/test/integration/app/generated_models/citations_item.rb +12 -0
  91. data/test/integration/app/generated_models/dog.rb +183 -0
  92. data/test/integration/app/generated_models/eaters_foodstuff.rb +13 -0
  93. data/test/integration/app/generated_models/frog.rb +78 -0
  94. data/test/integration/app/generated_models/kitten.rb +161 -0
  95. data/test/integration/app/generated_models/parentship.rb +14 -0
  96. data/test/integration/app/generated_models/person.rb +53 -0
  97. data/test/integration/app/generated_models/petfood.rb +125 -0
  98. data/test/integration/app/generated_models/polymorph_test_some_model.rb +25 -0
  99. data/test/integration/app/generated_models/seller.rb +30 -0
  100. data/test/integration/app/generated_models/tabby.rb +26 -0
  101. data/test/integration/app/generated_models/user.rb +34 -0
  102. data/test/integration/app/generated_models/wild_boar.rb +87 -0
  103. data/test/integration/app/generators/commenting_generator_test.rb +83 -0
  104. data/test/integration/app/public/404.html +30 -0
  105. data/test/integration/app/public/500.html +30 -0
  106. data/test/integration/app/public/dispatch.cgi +10 -0
  107. data/test/integration/app/public/dispatch.fcgi +24 -0
  108. data/test/integration/app/public/dispatch.rb +10 -0
  109. data/test/integration/app/public/favicon.ico +0 -0
  110. data/test/integration/app/public/images/rails.png +0 -0
  111. data/test/integration/app/public/index.html +277 -0
  112. data/test/integration/app/public/javascripts/application.js +2 -0
  113. data/test/integration/app/public/javascripts/controls.js +833 -0
  114. data/test/integration/app/public/javascripts/dragdrop.js +942 -0
  115. data/test/integration/app/public/javascripts/effects.js +1088 -0
  116. data/test/integration/app/public/javascripts/prototype.js +2515 -0
  117. data/test/integration/app/public/robots.txt +1 -0
  118. data/test/integration/app/public/stylesheets/scaffold.css +74 -0
  119. data/test/integration/app/script/about +3 -0
  120. data/test/integration/app/script/breakpointer +3 -0
  121. data/test/integration/app/script/console +3 -0
  122. data/test/integration/app/script/destroy +3 -0
  123. data/test/integration/app/script/generate +3 -0
  124. data/test/integration/app/script/performance/benchmarker +3 -0
  125. data/test/integration/app/script/performance/profiler +3 -0
  126. data/test/integration/app/script/plugin +3 -0
  127. data/test/integration/app/script/process/inspector +3 -0
  128. data/test/integration/app/script/process/reaper +3 -0
  129. data/test/integration/app/script/process/spawner +3 -0
  130. data/test/integration/app/script/runner +3 -0
  131. data/test/integration/app/script/server +3 -0
  132. data/test/integration/app/test/fixtures/addresses.yml +13 -0
  133. data/test/integration/app/test/fixtures/citations.yml +9 -0
  134. data/test/integration/app/test/fixtures/citations_items.yml +9 -0
  135. data/test/integration/app/test/fixtures/sellers.yml +10 -0
  136. data/test/integration/app/test/fixtures/states.yml +216 -0
  137. data/test/integration/app/test/fixtures/users.yml +11 -0
  138. data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
  139. data/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
  140. data/test/integration/app/test/functional/states_controller_test.rb +57 -0
  141. data/test/integration/app/test/functional/users_controller_test.rb +57 -0
  142. data/test/integration/app/test/test_helper.rb +28 -0
  143. data/test/integration/app/test/unit/address_test.rb +10 -0
  144. data/test/integration/app/test/unit/citation_test.rb +10 -0
  145. data/test/integration/app/test/unit/citations_item_test.rb +10 -0
  146. data/test/integration/app/test/unit/seller_test.rb +10 -0
  147. data/test/integration/app/test/unit/state_test.rb +10 -0
  148. data/test/integration/app/test/unit/user_test.rb +10 -0
  149. data/test/models/aquatic/fish.rb +2 -1
  150. data/test/models/aquatic/whale.rb +2 -0
  151. data/test/setup.rb +10 -0
  152. data/test/test_all.rb +16 -0
  153. data/test/test_helper.rb +16 -12
  154. data/test/unit/polymorph_test.rb +35 -34
  155. metadata +239 -98
  156. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ v2.11. Rails 1.2.6 tagging generator compatibility; change test suite to use included integration app; include commenting generator (not well tested) [Josh Stephenson].
3
+
2
4
  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.
3
5
 
4
6
  v2.9. Gem version renumbering; my apologies if this messes anyone up.
data/Manifest CHANGED
@@ -1,57 +1,192 @@
1
- TODO
2
- test/unit/polymorph_test.rb
3
- test/test_helper.rb
4
- test/schema.rb
5
- test/modules/other_extension_module.rb
6
- test/modules/extension_module.rb
7
- test/models/wild_boar.rb
8
- test/models/tabby.rb
9
- test/models/petfood.rb
10
- test/models/person.rb
11
- test/models/parentship.rb
12
- test/models/kitten.rb
13
- test/models/frog.rb
14
- test/models/eaters_foodstuff.rb
15
- test/models/dog.rb
16
- test/models/cat.rb
17
- test/models/canine.rb
18
- test/models/beautiful_fight_relationship.rb
19
- test/models/aquatic/whale.rb
20
- test/models/aquatic/pupils_whale.rb
21
- test/models/aquatic/fish.rb
22
- test/fixtures/wild_boars.yml
23
- test/fixtures/petfoods.yml
24
- test/fixtures/people.yml
25
- test/fixtures/keep_your_enemies_close.yml
26
- test/fixtures/frogs.yml
27
- test/fixtures/eaters_foodstuffs.yml
28
- test/fixtures/cats.yml
29
- test/fixtures/bow_wows.yml
30
- test/fixtures/aquatic/whales.yml
31
- test/fixtures/aquatic/little_whale_pupils.yml
32
- test/fixtures/aquatic/fish.yml
33
- README
34
- Manifest
35
- LICENSE
36
- lib/has_many_polymorphs.rb
37
- lib/has_many_polymorphs/support_methods.rb
38
- lib/has_many_polymorphs/reflection.rb
39
- lib/has_many_polymorphs/rake_task_redefine_task.rb
40
- lib/has_many_polymorphs/dependencies.rb
41
- lib/has_many_polymorphs/debugging_tools.rb
42
- lib/has_many_polymorphs/configuration.rb
43
- lib/has_many_polymorphs/class_methods.rb
44
- lib/has_many_polymorphs/base.rb
45
- lib/has_many_polymorphs/autoload.rb
46
- lib/has_many_polymorphs/association.rb
47
- init.rb
48
- generators/tagging/templates/tags.yml
49
- generators/tagging/templates/taggings.yml
50
- generators/tagging/templates/tagging_test.rb
51
- generators/tagging/templates/tagging_extensions.rb
52
- generators/tagging/templates/tagging.rb
53
- generators/tagging/templates/tag_test.rb
54
- generators/tagging/templates/tag.rb
55
- generators/tagging/templates/migration.rb
56
- generators/tagging/tagging_generator.rb
57
1
  CHANGELOG
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
+ generators/tagging/tagging_generator.rb
13
+ generators/tagging/templates/migration.rb
14
+ generators/tagging/templates/tag.rb
15
+ generators/tagging/templates/tag_test.rb
16
+ generators/tagging/templates/tagging.rb
17
+ generators/tagging/templates/tagging_extensions.rb
18
+ generators/tagging/templates/tagging_test.rb
19
+ generators/tagging/templates/taggings.yml
20
+ generators/tagging/templates/tags.yml
21
+ init.rb
22
+ lib/has_many_polymorphs/association.rb
23
+ lib/has_many_polymorphs/autoload.rb
24
+ lib/has_many_polymorphs/base.rb
25
+ lib/has_many_polymorphs/class_methods.rb
26
+ lib/has_many_polymorphs/configuration.rb
27
+ lib/has_many_polymorphs/debugging_tools.rb
28
+ lib/has_many_polymorphs/dependencies.rb
29
+ lib/has_many_polymorphs/rake_task_redefine_task.rb
30
+ lib/has_many_polymorphs/reflection.rb
31
+ lib/has_many_polymorphs/support_methods.rb
32
+ lib/has_many_polymorphs.rb
33
+ LICENSE
34
+ Manifest
35
+ README
36
+ test/fixtures/bow_wows.yml
37
+ test/fixtures/cats.yml
38
+ test/fixtures/eaters_foodstuffs.yml
39
+ test/fixtures/fish.yml
40
+ test/fixtures/frogs.yml
41
+ test/fixtures/keep_your_enemies_close.yml
42
+ test/fixtures/little_whale_pupils.yml
43
+ test/fixtures/people.yml
44
+ test/fixtures/petfoods.yml
45
+ test/fixtures/whales.yml
46
+ test/fixtures/wild_boars.yml
47
+ test/integration/app/app/controllers/addresses_controller.rb
48
+ test/integration/app/app/controllers/application.rb
49
+ test/integration/app/app/controllers/sellers_controller.rb
50
+ test/integration/app/app/controllers/states_controller.rb
51
+ test/integration/app/app/controllers/users_controller.rb
52
+ test/integration/app/app/helpers/addresses_helper.rb
53
+ test/integration/app/app/helpers/application_helper.rb
54
+ test/integration/app/app/helpers/sellers_helper.rb
55
+ test/integration/app/app/helpers/states_helper.rb
56
+ test/integration/app/app/helpers/users_helper.rb
57
+ test/integration/app/app/models/address.rb
58
+ test/integration/app/app/models/citation.rb
59
+ test/integration/app/app/models/citations_item.rb
60
+ test/integration/app/app/models/seller.rb
61
+ test/integration/app/app/models/state.rb
62
+ test/integration/app/app/models/user.rb
63
+ test/integration/app/app/views/addresses/edit.html.erb
64
+ test/integration/app/app/views/addresses/index.html.erb
65
+ test/integration/app/app/views/addresses/new.html.erb
66
+ test/integration/app/app/views/addresses/show.html.erb
67
+ test/integration/app/app/views/layouts/addresses.html.erb
68
+ test/integration/app/app/views/layouts/sellers.html.erb
69
+ test/integration/app/app/views/layouts/states.html.erb
70
+ test/integration/app/app/views/layouts/users.html.erb
71
+ test/integration/app/app/views/sellers/edit.html.erb
72
+ test/integration/app/app/views/sellers/index.html.erb
73
+ test/integration/app/app/views/sellers/new.html.erb
74
+ test/integration/app/app/views/sellers/show.html.erb
75
+ test/integration/app/app/views/states/edit.html.erb
76
+ test/integration/app/app/views/states/index.html.erb
77
+ test/integration/app/app/views/states/new.html.erb
78
+ test/integration/app/app/views/states/show.html.erb
79
+ test/integration/app/app/views/users/edit.html.erb
80
+ test/integration/app/app/views/users/index.html.erb
81
+ test/integration/app/app/views/users/new.html.erb
82
+ test/integration/app/app/views/users/show.html.erb
83
+ test/integration/app/config/boot.rb
84
+ test/integration/app/config/database.yml
85
+ test/integration/app/config/environment.rb
86
+ test/integration/app/config/environments/development.rb
87
+ test/integration/app/config/environments/production.rb
88
+ test/integration/app/config/environments/test.rb
89
+ test/integration/app/config/locomotive.yml
90
+ test/integration/app/config/routes.rb
91
+ test/integration/app/config/ultrasphinx/default.base
92
+ test/integration/app/config/ultrasphinx/development.conf.canonical
93
+ test/integration/app/db/migrate/001_create_users.rb
94
+ test/integration/app/db/migrate/002_create_sellers.rb
95
+ test/integration/app/db/migrate/003_create_addresses.rb
96
+ test/integration/app/db/migrate/004_create_states.rb
97
+ test/integration/app/db/migrate/005_add_capitalization_to_seller.rb
98
+ test/integration/app/db/migrate/006_add_deleted_to_user.rb
99
+ test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb
100
+ test/integration/app/db/migrate/008_create_citations.rb
101
+ test/integration/app/db/migrate/009_create_citations_items.rb
102
+ test/integration/app/db/schema.rb
103
+ 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
+ test/integration/app/generators/commenting_generator_test.rb
123
+ test/integration/app/public/404.html
124
+ test/integration/app/public/500.html
125
+ test/integration/app/public/dispatch.cgi
126
+ test/integration/app/public/dispatch.fcgi
127
+ test/integration/app/public/dispatch.rb
128
+ test/integration/app/public/favicon.ico
129
+ test/integration/app/public/images/rails.png
130
+ test/integration/app/public/index.html
131
+ test/integration/app/public/javascripts/application.js
132
+ test/integration/app/public/javascripts/controls.js
133
+ test/integration/app/public/javascripts/dragdrop.js
134
+ test/integration/app/public/javascripts/effects.js
135
+ test/integration/app/public/javascripts/prototype.js
136
+ test/integration/app/public/robots.txt
137
+ test/integration/app/public/stylesheets/scaffold.css
138
+ test/integration/app/Rakefile
139
+ test/integration/app/README
140
+ test/integration/app/script/about
141
+ test/integration/app/script/breakpointer
142
+ test/integration/app/script/console
143
+ test/integration/app/script/destroy
144
+ test/integration/app/script/generate
145
+ test/integration/app/script/performance/benchmarker
146
+ test/integration/app/script/performance/profiler
147
+ test/integration/app/script/plugin
148
+ test/integration/app/script/process/inspector
149
+ test/integration/app/script/process/reaper
150
+ test/integration/app/script/process/spawner
151
+ test/integration/app/script/runner
152
+ test/integration/app/script/server
153
+ test/integration/app/test/fixtures/addresses.yml
154
+ test/integration/app/test/fixtures/citations.yml
155
+ test/integration/app/test/fixtures/citations_items.yml
156
+ test/integration/app/test/fixtures/sellers.yml
157
+ test/integration/app/test/fixtures/states.yml
158
+ test/integration/app/test/fixtures/users.yml
159
+ test/integration/app/test/functional/addresses_controller_test.rb
160
+ test/integration/app/test/functional/sellers_controller_test.rb
161
+ test/integration/app/test/functional/states_controller_test.rb
162
+ test/integration/app/test/functional/users_controller_test.rb
163
+ test/integration/app/test/test_helper.rb
164
+ test/integration/app/test/unit/address_test.rb
165
+ test/integration/app/test/unit/citation_test.rb
166
+ test/integration/app/test/unit/citations_item_test.rb
167
+ test/integration/app/test/unit/seller_test.rb
168
+ test/integration/app/test/unit/state_test.rb
169
+ test/integration/app/test/unit/user_test.rb
170
+ test/models/aquatic/fish.rb
171
+ test/models/aquatic/pupils_whale.rb
172
+ test/models/aquatic/whale.rb
173
+ test/models/beautiful_fight_relationship.rb
174
+ test/models/canine.rb
175
+ test/models/cat.rb
176
+ test/models/dog.rb
177
+ test/models/eaters_foodstuff.rb
178
+ test/models/frog.rb
179
+ test/models/kitten.rb
180
+ test/models/parentship.rb
181
+ test/models/person.rb
182
+ test/models/petfood.rb
183
+ test/models/tabby.rb
184
+ test/models/wild_boar.rb
185
+ test/modules/extension_module.rb
186
+ test/modules/other_extension_module.rb
187
+ test/schema.rb
188
+ test/setup.rb
189
+ test/test_all.rb
190
+ test/test_helper.rb
191
+ test/unit/polymorph_test.rb
192
+ TODO
data/TODO CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
+ * Does :namespace key definitely work with doubles?
2
3
  * Migration examples in docs
3
4
  * Controller for tagging generator
4
5
  * Tag cloud method
@@ -0,0 +1,69 @@
1
+ require 'camping'
2
+ require 'has_many_polymorphs'
3
+
4
+ Camping.goes :Hmph
5
+
6
+ module Hmph::Models
7
+ class GuestsKennel < Base
8
+ belongs_to :kennel
9
+ belongs_to :guest, :polymorphic => true
10
+ end
11
+
12
+ class Dog < Base
13
+ end
14
+
15
+ class Cat < Base
16
+ end
17
+
18
+ class Bird < Base
19
+ end
20
+
21
+ class Kennel < Base
22
+ has_many_polymorphs :guests,
23
+ :from => [:dogs, :cats, :birds],
24
+ :through => :guests_kennels,
25
+ :namespace => :"hmph/models/"
26
+ end
27
+
28
+ class InitialSchema < V 1.0
29
+ def self.up
30
+ create_table :hmph_kennels do |t|
31
+ t.column :created_at, :datetime
32
+ t.column :modified_at, :datetime
33
+ t.column :name, :string, :default => 'Anonymous Kennel'
34
+ end
35
+
36
+ create_table :hmph_guests_kennels do |t|
37
+ t.column :guest_id, :integer
38
+ t.column :guest_type, :string
39
+ t.column :kennel_id, :integer
40
+ end
41
+
42
+ create_table :hmph_dogs do |t|
43
+ t.column :name, :string, :default => 'Fido'
44
+ end
45
+
46
+ create_table :hmph_cats do |t|
47
+ t.column :name, :string, :default => 'Morris'
48
+ end
49
+
50
+ create_table :hmph_birds do |t|
51
+ t.column :name, :string, :default => 'Polly'
52
+ end
53
+ end
54
+
55
+ def self.down
56
+ drop_table :hmph_kennels
57
+ drop_table :hmph_guests_kennels
58
+ drop_table :hmph_dogs
59
+ drop_table :hmph_cats
60
+ drop_table :hmph_birds
61
+ end
62
+ end
63
+ end
64
+
65
+ module Hmph::Controllers
66
+ end
67
+
68
+ module Hmph::Views
69
+ end
@@ -0,0 +1,94 @@
1
+
2
+ class CommentingGenerator < Rails::Generator::NamedBase
3
+ default_options :skip_migration => false
4
+ default_options :self_referential => false
5
+ attr_reader :parent_association_name
6
+ attr_reader :commentable_models
7
+
8
+ def initialize(runtime_args, runtime_options = {})
9
+ @parent_association_name = (runtime_args.include?("--self-referential") ? "commenter" : "comment")
10
+ @commentable_models = runtime_args.reject{|opt| opt =~ /^--/}.map do |commentable|
11
+ ":" + commentable.underscore.pluralize
12
+ end
13
+ @commentable_models += [":comments"] if runtime_args.include?("--self-referential")
14
+ @commentable_models.uniq!
15
+
16
+ verify @commentable_models
17
+ hacks
18
+ runtime_args.unshift("placeholder")
19
+ super
20
+ end
21
+
22
+ def verify models
23
+ puts "** Warning: only one commentable model specified; tests may not run properly." if models.size < 2
24
+ models.each do |model|
25
+ model = model[1..-1].classify
26
+ next if model == "Comment" # don't load ourselves when --self-referential is used
27
+ self.class.const_get(model) rescue puts "** Error: model #{model[1..-1].classify} could not be loaded." or exit
28
+ end
29
+ end
30
+
31
+ def hacks
32
+ # add the extension require in environment.rb
33
+ phrase = "require 'commenting_extensions'"
34
+ filename = "#{RAILS_ROOT}/config/environment.rb"
35
+ unless (open(filename) do |file|
36
+ file.grep(/#{Regexp.escape phrase}/).any?
37
+ end)
38
+ open(filename, 'a+') do |file|
39
+ file.puts "\n" + phrase + "\n"
40
+ end
41
+ end
42
+ end
43
+
44
+ def manifest
45
+ record do |m|
46
+ m.class_collisions class_path, class_name, "#{class_name}Test"
47
+
48
+ m.directory File.join('app/models', class_path)
49
+ m.directory File.join('test/unit', class_path)
50
+ m.directory File.join('test/fixtures', class_path)
51
+ m.directory File.join('test/fixtures', class_path)
52
+ m.directory File.join('lib')
53
+
54
+ m.template 'comment.rb', File.join('app/models', class_path, "comment.rb")
55
+ m.template 'comment_test.rb', File.join('test/unit', class_path, "comment_test.rb")
56
+ m.template 'comments.yml', File.join('test/fixtures', class_path, "comments.yml")
57
+
58
+ m.template 'commenting.rb', File.join('app/models', class_path, "commenting.rb")
59
+ m.template 'commenting_test.rb', File.join('test/unit', class_path, "commenting_test.rb")
60
+ m.template 'commentings.yml', File.join('test/fixtures', class_path, "commentings.yml")
61
+
62
+ m.template 'commenting_extensions.rb', File.join('lib', 'commenting_extensions.rb')
63
+
64
+ unless options[:skip_migration]
65
+ m.migration_template 'migration.rb', 'db/migrate',
66
+ :migration_file_name => "create_comments_and_commentings"
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ protected
73
+ def banner
74
+ "Usage: #{$0} generate commenting [CommentableModelA CommentableModelB ...]"
75
+ end
76
+
77
+ def add_options!(opt)
78
+ opt.separator ''
79
+ opt.separator 'Options:'
80
+ opt.on("--skip-migration",
81
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
82
+ opt.on("--self-referential",
83
+ "Allow comments to comment themselves.") { |v| options[:self_referential] = v }
84
+ end
85
+
86
+ # Useful for generating tests/fixtures
87
+ def model_one
88
+ commentable_models[0][1..-1].classify
89
+ end
90
+
91
+ def model_two
92
+ commentable_models[1][1..-1].classify rescue model_one
93
+ end
94
+ end
@@ -0,0 +1,33 @@
1
+
2
+ # The Comment model. This model is automatically generated and added to your app if you run the commenting generator.
3
+
4
+ class Comment < ActiveRecord::Base
5
+
6
+ # If database speed becomes an issue, you could remove these validations and rescue the ActiveRecord database constraint errors instead.
7
+ validates_presence_of :name, :email, :body
8
+ validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
9
+
10
+ after_validation :prepend_url
11
+
12
+ # Set up the polymorphic relationship.
13
+ has_many_polymorphs :commentables,
14
+ :from => [<%= commentable_models.join(", ") %>],
15
+ :through => :commentings,
16
+ :dependent => :destroy,
17
+ <% if options[:self_referential] -%> :as => :<%= parent_association_name -%>,
18
+ <% end -%>
19
+ :parent_extend => proc {
20
+ }
21
+
22
+ # Tag::Error class. Raised by ActiveRecord::Base::TaggingExtensions if something goes wrong.
23
+ class Error < StandardError
24
+ end
25
+
26
+ protected
27
+ def prepend_url
28
+ return if self[:url].blank?
29
+ if self[:url] !~ /^http(s):\/\//i
30
+ self.url = 'http://' + self[:url]
31
+ end
32
+ end
33
+ end