radiant 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of radiant might be problematic. Click here for more details.

Files changed (513) hide show
  1. data/CHANGELOG +33 -1
  2. data/CONTRIBUTORS +15 -2
  3. data/INSTALL +9 -7
  4. data/README +11 -7
  5. data/app/controllers/admin/layouts_controller.rb +5 -2
  6. data/app/controllers/admin/pages_controller.rb +8 -5
  7. data/app/controllers/admin/snippets_controller.rb +5 -2
  8. data/app/controllers/application_controller.rb +7 -0
  9. data/app/helpers/admin/node_helper.rb +2 -2
  10. data/app/helpers/application_helper.rb +2 -2
  11. data/app/models/radiant/config.rb +36 -4
  12. data/app/models/standard_tags.rb +1 -1
  13. data/app/views/admin/layouts/index.html.haml +15 -12
  14. data/app/views/admin/page_parts/_page_part.html.haml +2 -2
  15. data/app/views/admin/pages/index.html.haml +1 -1
  16. data/app/views/admin/snippets/_form.html.haml +1 -1
  17. data/app/views/admin/snippets/index.html.haml +14 -10
  18. data/config/database.db2.yml +20 -0
  19. data/config/environment.rb +4 -4
  20. data/config/environments/test.rb +1 -2
  21. data/features/support/env.rb +2 -1
  22. data/lib/generators/extension/extension_generator.rb +5 -0
  23. data/lib/generators/extension/templates/RSpecRakefile +11 -8
  24. data/lib/generators/extension/templates/cucumber.yml +1 -0
  25. data/lib/generators/extension/templates/cucumber_env.rb +16 -0
  26. data/lib/generators/extension/templates/cucumber_paths.rb +14 -0
  27. data/lib/generators/extension/templates/extension.rb +1 -1
  28. data/lib/generators/instance/instance_generator.rb +1 -1
  29. data/lib/generators/instance/templates/databases/db2.yml +40 -0
  30. data/lib/generators/instance/templates/instance_environment.rb +6 -6
  31. data/lib/local_time.rb +3 -9
  32. data/lib/radiant.rb +1 -1
  33. data/lib/radiant/cache.rb +10 -8
  34. data/lib/radiant/extension.rb +36 -0
  35. data/lib/radiant/extension/script.rb +1 -1
  36. data/lib/radiant/extension_loader.rb +5 -1
  37. data/lib/radiant/initializer.rb +52 -4
  38. data/lib/task_support.rb +33 -0
  39. data/lib/tasks/cucumber.rake +5 -1
  40. data/lib/tasks/radiant_config.rake +18 -0
  41. data/lib/tasks/release.rake +1 -0
  42. data/public/javascripts/admin/admin.js +1 -1
  43. data/spec/controllers/admin/layouts_controller_spec.rb +18 -12
  44. data/spec/controllers/admin/pages_controller_spec.rb +35 -29
  45. data/spec/controllers/admin/snippets_controller_spec.rb +11 -5
  46. data/spec/controllers/admin/welcome_controller_spec.rb +1 -1
  47. data/spec/controllers/application_controller_spec.rb +18 -0
  48. data/spec/fixtures/radiant_config.yml +10 -0
  49. data/spec/generators/extension_generator_spec.rb +12 -0
  50. data/spec/helpers/admin/node_helper_spec.rb +6 -0
  51. data/spec/helpers/application_helper_spec.rb +1 -1
  52. data/spec/lib/radiant/extension_loader_spec.rb +17 -0
  53. data/spec/lib/radiant/extension_spec.rb +28 -0
  54. data/spec/lib/radiant/initializer_spec.rb +34 -0
  55. data/spec/lib/task_support_spec.rb +42 -0
  56. data/spec/models/page_spec.rb +6 -2
  57. data/spec/models/radiant/config_spec.rb +42 -1
  58. data/spec/models/standard_tags_spec.rb +2 -2
  59. data/test/fixtures/extensions/01_basic/app/metal/basic_metal.rb +9 -0
  60. data/test/fixtures/extensions/02_overriding/app/metal/basic_metal.rb +9 -0
  61. data/vendor/extensions/textile_filter/textile.html +2 -2
  62. data/vendor/plugins/dataset/CHANGELOG +2 -1
  63. data/vendor/plugins/dataset/Rakefile +3 -0
  64. data/vendor/plugins/dataset/VERSION.yml +2 -2
  65. data/vendor/plugins/dataset/dataset.gemspec +9 -3
  66. data/vendor/plugins/dataset/lib/dataset.rb +3 -0
  67. data/vendor/radius/lib/radius.rb +5 -0
  68. data/vendor/radius/test/radius_test.rb +6 -0
  69. data/vendor/rails/actionmailer/CHANGELOG +8 -0
  70. data/vendor/rails/actionmailer/Rakefile +3 -2
  71. data/vendor/rails/actionmailer/lib/action_mailer/base.rb +2 -1
  72. data/vendor/rails/actionmailer/lib/action_mailer/version.rb +1 -1
  73. data/vendor/rails/actionmailer/test/abstract_unit.rb +0 -3
  74. data/vendor/rails/actionmailer/test/mail_service_test.rb +3 -2
  75. data/vendor/rails/actionpack/CHANGELOG +16 -0
  76. data/vendor/rails/actionpack/Rakefile +5 -3
  77. data/vendor/rails/actionpack/lib/action_controller.rb +2 -7
  78. data/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb +13 -3
  79. data/vendor/rails/actionpack/lib/action_controller/base.rb +12 -3
  80. data/vendor/rails/actionpack/lib/action_controller/caching.rb +1 -1
  81. data/vendor/rails/actionpack/lib/action_controller/caching/actions.rb +9 -1
  82. data/vendor/rails/actionpack/lib/action_controller/caching/sweeper.rb +45 -0
  83. data/vendor/rails/actionpack/lib/action_controller/caching/sweeping.rb +0 -42
  84. data/vendor/rails/actionpack/lib/action_controller/cookies.rb +1 -1
  85. data/vendor/rails/actionpack/lib/action_controller/dispatcher.rb +21 -6
  86. data/vendor/rails/actionpack/lib/action_controller/failsafe.rb +40 -6
  87. data/vendor/rails/actionpack/lib/action_controller/flash.rb +11 -3
  88. data/vendor/rails/actionpack/lib/action_controller/http_authentication.rb +7 -3
  89. data/vendor/rails/actionpack/lib/action_controller/integration.rb +5 -12
  90. data/vendor/rails/actionpack/lib/action_controller/middlewares.rb +0 -1
  91. data/vendor/rails/actionpack/lib/action_controller/params_parser.rb +6 -0
  92. data/vendor/rails/actionpack/lib/action_controller/reloader.rb +47 -7
  93. data/vendor/rails/actionpack/lib/action_controller/request.rb +6 -2
  94. data/vendor/rails/actionpack/lib/action_controller/request_forgery_protection.rb +2 -1
  95. data/vendor/rails/actionpack/lib/action_controller/resources.rb +17 -13
  96. data/vendor/rails/actionpack/lib/action_controller/response.rb +8 -2
  97. data/vendor/rails/actionpack/lib/action_controller/routing.rb +3 -0
  98. data/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb +20 -6
  99. data/vendor/rails/actionpack/lib/action_controller/streaming.rb +4 -2
  100. data/vendor/rails/actionpack/lib/action_controller/test_process.rb +9 -1
  101. data/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb +1 -1
  102. data/vendor/rails/actionpack/lib/action_pack/version.rb +1 -1
  103. data/vendor/rails/actionpack/lib/action_view/helpers.rb +1 -1
  104. data/vendor/rails/actionpack/lib/action_view/helpers/asset_tag_helper.rb +21 -9
  105. data/vendor/rails/actionpack/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  106. data/vendor/rails/actionpack/lib/action_view/helpers/date_helper.rb +2 -2
  107. data/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb +26 -12
  108. data/vendor/rails/actionpack/lib/action_view/helpers/form_options_helper.rb +71 -1
  109. data/vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb +10 -4
  110. data/vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb +1 -1
  111. data/vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb +7 -7
  112. data/vendor/rails/actionpack/lib/action_view/helpers/scriptaculous_helper.rb +5 -5
  113. data/vendor/rails/actionpack/lib/action_view/helpers/tag_helper.rb +1 -1
  114. data/vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb +23 -14
  115. data/vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb +2 -2
  116. data/vendor/rails/actionpack/lib/action_view/locale/en.yml +4 -0
  117. data/vendor/rails/actionpack/lib/action_view/paths.rb +1 -1
  118. data/vendor/rails/actionpack/lib/action_view/template.rb +22 -33
  119. data/vendor/rails/actionpack/test/abstract_unit.rb +17 -1
  120. data/vendor/rails/actionpack/test/activerecord/active_record_store_test.rb +3 -3
  121. data/vendor/rails/actionpack/test/controller/action_pack_assertions_test.rb +27 -0
  122. data/vendor/rails/actionpack/test/controller/caching_test.rb +40 -1
  123. data/vendor/rails/actionpack/test/controller/cookie_test.rb +16 -0
  124. data/vendor/rails/actionpack/test/controller/dispatcher_test.rb +59 -18
  125. data/vendor/rails/actionpack/test/controller/failsafe_test.rb +60 -0
  126. data/vendor/rails/actionpack/test/controller/filter_params_test.rb +3 -1
  127. data/vendor/rails/actionpack/test/controller/flash_test.rb +6 -1
  128. data/vendor/rails/actionpack/test/controller/http_basic_authentication_test.rb +25 -0
  129. data/vendor/rails/actionpack/test/controller/http_digest_authentication_test.rb +63 -9
  130. data/vendor/rails/actionpack/test/controller/integration_test.rb +31 -3
  131. data/vendor/rails/actionpack/test/controller/rack_test.rb +18 -1
  132. data/vendor/rails/actionpack/test/controller/redirect_test.rb +4 -1
  133. data/vendor/rails/actionpack/test/controller/reloader_test.rb +124 -0
  134. data/vendor/rails/actionpack/test/controller/render_test.rb +19 -9
  135. data/vendor/rails/actionpack/test/controller/request/json_params_parsing_test.rb +24 -4
  136. data/vendor/rails/actionpack/test/controller/request/multipart_params_parsing_test.rb +1 -62
  137. data/vendor/rails/actionpack/test/controller/request/test_request_test.rb +35 -0
  138. data/vendor/rails/actionpack/test/controller/request/url_encoded_params_parsing_test.rb +0 -38
  139. data/vendor/rails/actionpack/test/controller/request/xml_params_parsing_test.rb +15 -0
  140. data/vendor/rails/actionpack/test/controller/request_forgery_protection_test.rb +6 -5
  141. data/vendor/rails/actionpack/test/controller/request_test.rb +218 -230
  142. data/vendor/rails/actionpack/test/controller/resources_test.rb +52 -0
  143. data/vendor/rails/actionpack/test/controller/routing_test.rb +28 -2
  144. data/vendor/rails/actionpack/test/controller/send_file_test.rb +12 -2
  145. data/vendor/rails/actionpack/test/controller/session/cookie_store_test.rb +9 -32
  146. data/vendor/rails/actionpack/test/controller/test_test.rb +8 -0
  147. data/vendor/rails/actionpack/test/controller/url_rewriter_test.rb +29 -3
  148. data/vendor/rails/actionpack/test/fixtures/failsafe/500.html +1 -0
  149. data/vendor/rails/actionpack/test/fixtures/public/absolute/test.css +23 -0
  150. data/vendor/rails/actionpack/test/fixtures/public/absolute/test.js +63 -0
  151. data/vendor/rails/actionpack/test/template/active_record_helper_test.rb +1 -1
  152. data/vendor/rails/actionpack/test/template/asset_tag_helper_test.rb +46 -0
  153. data/vendor/rails/actionpack/test/template/atom_feed_helper_test.rb +29 -0
  154. data/vendor/rails/actionpack/test/template/form_helper_test.rb +143 -6
  155. data/vendor/rails/actionpack/test/template/form_options_helper_i18n_test.rb +27 -0
  156. data/vendor/rails/actionpack/test/template/form_options_helper_test.rb +56 -0
  157. data/vendor/rails/actionpack/test/template/form_tag_helper_test.rb +23 -6
  158. data/vendor/rails/actionpack/test/template/prototype_helper_test.rb +11 -11
  159. data/vendor/rails/actionpack/test/template/template_test.rb +32 -0
  160. data/vendor/rails/actionpack/test/template/text_helper_test.rb +23 -0
  161. data/vendor/rails/actionpack/test/template/url_helper_test.rb +8 -0
  162. data/vendor/rails/activerecord/CHANGELOG +18 -0
  163. data/vendor/rails/activerecord/Rakefile +26 -9
  164. data/vendor/rails/activerecord/examples/performance.rb +162 -0
  165. data/vendor/rails/activerecord/lib/active_record/associations.rb +104 -35
  166. data/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb +10 -5
  167. data/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb +2 -2
  168. data/vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb +22 -4
  169. data/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +5 -1
  170. data/vendor/rails/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +16 -0
  171. data/vendor/rails/activerecord/lib/active_record/associations/has_many_association.rb +1 -0
  172. data/vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb +13 -3
  173. data/vendor/rails/activerecord/lib/active_record/associations/has_one_through_association.rb +15 -9
  174. data/vendor/rails/activerecord/lib/active_record/autosave_association.rb +15 -9
  175. data/vendor/rails/activerecord/lib/active_record/base.rb +34 -31
  176. data/vendor/rails/activerecord/lib/active_record/batches.rb +23 -15
  177. data/vendor/rails/activerecord/lib/active_record/calculations.rb +7 -13
  178. data/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +16 -2
  179. data/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +2 -2
  180. data/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +7 -0
  181. data/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +17 -8
  182. data/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +98 -35
  183. data/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +15 -0
  184. data/vendor/rails/activerecord/lib/active_record/dirty.rb +1 -1
  185. data/vendor/rails/activerecord/lib/active_record/fixtures.rb +14 -11
  186. data/vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb +1 -1
  187. data/vendor/rails/activerecord/lib/active_record/locale/en.yml +4 -0
  188. data/vendor/rails/activerecord/lib/active_record/named_scope.rb +3 -8
  189. data/vendor/rails/activerecord/lib/active_record/reflection.rb +1 -1
  190. data/vendor/rails/activerecord/lib/active_record/schema_dumper.rb +6 -3
  191. data/vendor/rails/activerecord/lib/active_record/serialization.rb +3 -2
  192. data/vendor/rails/activerecord/lib/active_record/serializers/json_serializer.rb +10 -18
  193. data/vendor/rails/activerecord/lib/active_record/serializers/xml_serializer.rb +6 -2
  194. data/vendor/rails/activerecord/lib/active_record/session_store.rb +9 -1
  195. data/vendor/rails/activerecord/lib/active_record/timestamp.rb +39 -9
  196. data/vendor/rails/activerecord/lib/active_record/validations.rb +149 -80
  197. data/vendor/rails/activerecord/lib/active_record/version.rb +1 -1
  198. data/vendor/rails/activerecord/test/cases/adapter_test.rb +12 -0
  199. data/vendor/rails/activerecord/test/cases/associations/belongs_to_associations_test.rb +102 -22
  200. data/vendor/rails/activerecord/test/cases/associations/eager_load_nested_include_test.rb +5 -5
  201. data/vendor/rails/activerecord/test/cases/associations/eager_test.rb +12 -0
  202. data/vendor/rails/activerecord/test/cases/associations/habtm_join_table_test.rb +56 -0
  203. data/vendor/rails/activerecord/test/cases/associations/has_many_associations_test.rb +62 -2
  204. data/vendor/rails/activerecord/test/cases/associations/has_many_through_associations_test.rb +46 -1
  205. data/vendor/rails/activerecord/test/cases/associations/has_one_through_associations_test.rb +18 -1
  206. data/vendor/rails/activerecord/test/cases/associations/inner_join_association_test.rb +5 -0
  207. data/vendor/rails/activerecord/test/cases/associations/join_model_test.rb +4 -4
  208. data/vendor/rails/activerecord/test/cases/autosave_association_test.rb +22 -0
  209. data/vendor/rails/activerecord/test/cases/base_test.rb +51 -6
  210. data/vendor/rails/activerecord/test/cases/calculations_test.rb +14 -14
  211. data/vendor/rails/activerecord/test/cases/column_definition_test.rb +34 -0
  212. data/vendor/rails/activerecord/test/cases/copy_table_test_sqlite.rb +5 -5
  213. data/vendor/rails/activerecord/test/cases/dirty_test.rb +10 -0
  214. data/vendor/rails/activerecord/test/cases/finder_test.rb +21 -50
  215. data/vendor/rails/activerecord/test/cases/fixtures_test.rb +6 -1
  216. data/vendor/rails/activerecord/test/cases/helper.rb +1 -2
  217. data/vendor/rails/activerecord/test/cases/i18n_test.rb +5 -0
  218. data/vendor/rails/activerecord/test/cases/json_serialization_test.rb +57 -57
  219. data/vendor/rails/activerecord/test/cases/method_scoping_test.rb +14 -4
  220. data/vendor/rails/activerecord/test/cases/migration_test.rb +39 -11
  221. data/vendor/rails/activerecord/test/cases/modules_test.rb +42 -0
  222. data/vendor/rails/activerecord/test/cases/named_scope_test.rb +6 -4
  223. data/vendor/rails/activerecord/test/cases/pk_test.rb +18 -0
  224. data/vendor/rails/activerecord/test/cases/reflection_test.rb +7 -7
  225. data/vendor/rails/activerecord/test/cases/schema_dumper_test.rb +35 -7
  226. data/vendor/rails/activerecord/test/cases/schema_test_postgresql.rb +76 -0
  227. data/vendor/rails/activerecord/test/cases/timestamp_test.rb +75 -0
  228. data/vendor/rails/activerecord/test/cases/validations_i18n_test.rb +656 -624
  229. data/vendor/rails/activerecord/test/cases/validations_test.rb +12 -2
  230. data/vendor/rails/activerecord/test/cases/xml_serialization_test.rb +20 -0
  231. data/vendor/rails/activerecord/test/fixtures/fixture_database.sqlite +0 -0
  232. data/vendor/rails/activerecord/test/fixtures/fixture_database.sqlite3 +0 -0
  233. data/vendor/rails/activerecord/test/fixtures/fixture_database_2.sqlite +0 -0
  234. data/vendor/rails/activerecord/test/fixtures/fixture_database_2.sqlite3 +0 -0
  235. data/vendor/rails/activerecord/test/fixtures/posts.yml +3 -0
  236. data/vendor/rails/activerecord/test/models/author.rb +5 -0
  237. data/vendor/rails/activerecord/test/models/comment.rb +5 -1
  238. data/vendor/rails/activerecord/test/models/company.rb +9 -7
  239. data/vendor/rails/activerecord/test/models/company_in_module.rb +1 -1
  240. data/vendor/rails/activerecord/test/models/contract.rb +5 -0
  241. data/vendor/rails/activerecord/test/models/developer.rb +10 -0
  242. data/vendor/rails/activerecord/test/models/essay.rb +3 -0
  243. data/vendor/rails/activerecord/test/models/organization.rb +2 -0
  244. data/vendor/rails/activerecord/test/models/pet.rb +1 -1
  245. data/vendor/rails/activerecord/test/models/project.rb +1 -1
  246. data/vendor/rails/activerecord/test/models/reply.rb +2 -1
  247. data/vendor/rails/activerecord/test/models/topic.rb +1 -2
  248. data/vendor/rails/activerecord/test/models/toy.rb +2 -0
  249. data/vendor/rails/activerecord/test/schema/postgresql_specific_schema.rb +13 -2
  250. data/vendor/rails/activerecord/test/schema/schema.rb +19 -0
  251. data/vendor/rails/activeresource/CHANGELOG +16 -0
  252. data/vendor/rails/activeresource/Rakefile +3 -2
  253. data/vendor/rails/activeresource/lib/active_resource/base.rb +89 -9
  254. data/vendor/rails/activeresource/lib/active_resource/connection.rb +73 -8
  255. data/vendor/rails/activeresource/lib/active_resource/exceptions.rb +66 -0
  256. data/vendor/rails/activeresource/lib/active_resource/formats/json_format.rb +2 -2
  257. data/vendor/rails/activeresource/lib/active_resource/validations.rb +20 -4
  258. data/vendor/rails/activeresource/lib/active_resource/version.rb +1 -1
  259. data/vendor/rails/activeresource/test/abstract_unit.rb +1 -3
  260. data/vendor/rails/activeresource/test/base/load_test.rb +16 -1
  261. data/vendor/rails/activeresource/test/base_errors_test.rb +56 -19
  262. data/vendor/rails/activeresource/test/base_test.rb +147 -0
  263. data/vendor/rails/activeresource/test/connection_test.rb +42 -0
  264. data/vendor/rails/activeresource/test/debug.log +7974 -0
  265. data/vendor/rails/activeresource/test/fixtures/proxy.rb +4 -0
  266. data/vendor/rails/activesupport/CHANGELOG +13 -0
  267. data/vendor/rails/activesupport/lib/active_support/all.rb +8 -0
  268. data/vendor/rails/activesupport/lib/active_support/cache.rb +14 -1
  269. data/vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb +16 -10
  270. data/vendor/rails/activesupport/lib/active_support/cache/strategy/local_cache.rb +1 -1
  271. data/vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb +1 -0
  272. data/vendor/rails/activesupport/lib/active_support/core_ext/date/calculations.rb +2 -1
  273. data/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb +2 -4
  274. data/vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb +14 -4
  275. data/vendor/rails/activesupport/lib/active_support/core_ext/kernel/debugger.rb +4 -2
  276. data/vendor/rails/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +2 -0
  277. data/vendor/rails/activesupport/lib/active_support/core_ext/module/delegation.rb +19 -5
  278. data/vendor/rails/activesupport/lib/active_support/core_ext/module/model_naming.rb +8 -6
  279. data/vendor/rails/activesupport/lib/active_support/core_ext/numeric/bytes.rb +15 -9
  280. data/vendor/rails/activesupport/lib/active_support/core_ext/string.rb +1 -0
  281. data/vendor/rails/activesupport/lib/active_support/core_ext/string/access.rb +29 -5
  282. data/vendor/rails/activesupport/lib/active_support/core_ext/string/bytesize.rb +5 -0
  283. data/vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb +7 -7
  284. data/vendor/rails/activesupport/lib/active_support/deprecation.rb +9 -9
  285. data/vendor/rails/activesupport/lib/active_support/duration.rb +4 -2
  286. data/vendor/rails/activesupport/lib/active_support/json.rb +1 -22
  287. data/vendor/rails/activesupport/lib/active_support/json/backends/jsongem.rb +38 -0
  288. data/vendor/rails/activesupport/lib/active_support/json/backends/yaml.rb +88 -0
  289. data/vendor/rails/activesupport/lib/active_support/json/decoding.rb +23 -72
  290. data/vendor/rails/activesupport/lib/active_support/json/encoders/date.rb +9 -8
  291. data/vendor/rails/activesupport/lib/active_support/json/encoders/date_time.rb +9 -8
  292. data/vendor/rails/activesupport/lib/active_support/json/encoders/enumerable.rb +14 -9
  293. data/vendor/rails/activesupport/lib/active_support/json/encoders/false_class.rb +4 -2
  294. data/vendor/rails/activesupport/lib/active_support/json/encoders/hash.rb +21 -11
  295. data/vendor/rails/activesupport/lib/active_support/json/encoders/nil_class.rb +4 -2
  296. data/vendor/rails/activesupport/lib/active_support/json/encoders/numeric.rb +16 -0
  297. data/vendor/rails/activesupport/lib/active_support/json/encoders/object.rb +6 -2
  298. data/vendor/rails/activesupport/lib/active_support/json/encoders/regexp.rb +4 -0
  299. data/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb +5 -32
  300. data/vendor/rails/activesupport/lib/active_support/json/encoders/symbol.rb +2 -2
  301. data/vendor/rails/activesupport/lib/active_support/json/encoders/time.rb +9 -8
  302. data/vendor/rails/activesupport/lib/active_support/json/encoders/true_class.rb +4 -2
  303. data/vendor/rails/activesupport/lib/active_support/json/encoding.rb +80 -9
  304. data/vendor/rails/activesupport/lib/active_support/memoizable.rb +1 -1
  305. data/vendor/rails/activesupport/lib/active_support/message_verifier.rb +16 -3
  306. data/vendor/rails/activesupport/lib/active_support/multibyte.rb +30 -6
  307. data/vendor/rails/activesupport/lib/active_support/multibyte/chars.rb +23 -17
  308. data/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb +61 -0
  309. data/vendor/rails/activesupport/lib/active_support/ordered_hash.rb +28 -0
  310. data/vendor/rails/activesupport/lib/active_support/test_case.rb +9 -8
  311. data/vendor/rails/activesupport/lib/active_support/testing/deprecation.rb +2 -0
  312. data/vendor/rails/activesupport/lib/active_support/time_with_zone.rb +9 -8
  313. data/vendor/rails/activesupport/lib/active_support/vendor.rb +6 -7
  314. data/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -1
  315. data/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -1
  316. data/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -1
  317. data/vendor/rails/activesupport/lib/active_support/vendor/{memcache-client-1.6.5 → memcache-client-1.7.4}/memcache.rb +242 -70
  318. data/vendor/rails/activesupport/lib/active_support/version.rb +1 -1
  319. data/vendor/rails/activesupport/lib/active_support/xml_mini/jdom.rb +162 -0
  320. data/vendor/rails/railties/CHANGELOG +10 -0
  321. data/vendor/rails/railties/Rakefile +13 -9
  322. data/vendor/rails/railties/bin/about +2 -2
  323. data/vendor/rails/railties/bin/console +1 -1
  324. data/vendor/rails/railties/bin/dbconsole +1 -1
  325. data/vendor/rails/railties/bin/destroy +1 -1
  326. data/vendor/rails/railties/bin/generate +1 -1
  327. data/vendor/rails/railties/bin/performance/benchmarker +1 -1
  328. data/vendor/rails/railties/bin/performance/profiler +1 -1
  329. data/vendor/rails/railties/bin/plugin +1 -1
  330. data/vendor/rails/railties/bin/runner +1 -1
  331. data/vendor/rails/railties/bin/server +1 -1
  332. data/vendor/rails/railties/builtin/rails_info/rails/info.rb +4 -2
  333. data/vendor/rails/railties/configs/initializers/new_rails_defaults.rb +2 -0
  334. data/vendor/rails/railties/configs/routes.rb +1 -1
  335. data/vendor/rails/railties/configs/seeds.rb +7 -0
  336. data/vendor/rails/railties/environments/boot.rb +1 -1
  337. data/vendor/rails/railties/guides/files/javascripts/code_highlighter.js +188 -0
  338. data/vendor/rails/railties/guides/files/javascripts/guides.js +8 -0
  339. data/vendor/rails/railties/guides/files/javascripts/highlighters.js +90 -0
  340. data/vendor/rails/railties/guides/files/stylesheets/main.css +441 -0
  341. data/vendor/rails/railties/guides/files/stylesheets/print.css +52 -0
  342. data/vendor/rails/railties/guides/files/stylesheets/reset.css +43 -0
  343. data/vendor/rails/railties/guides/files/stylesheets/style.css +13 -0
  344. data/vendor/rails/railties/guides/files/stylesheets/syntax.css +31 -0
  345. data/vendor/rails/railties/guides/images/belongs_to.png +0 -0
  346. data/vendor/rails/railties/guides/images/book_icon.gif +0 -0
  347. data/vendor/rails/railties/guides/images/bullet.gif +0 -0
  348. data/vendor/rails/railties/guides/images/chapters_icon.gif +0 -0
  349. data/vendor/rails/railties/guides/images/check_bullet.gif +0 -0
  350. data/vendor/rails/railties/guides/images/credits_pic_blank.gif +0 -0
  351. data/vendor/rails/railties/guides/images/csrf.png +0 -0
  352. data/vendor/rails/railties/guides/images/customized_error_messages.png +0 -0
  353. data/vendor/rails/railties/guides/images/error_messages.png +0 -0
  354. data/vendor/rails/railties/guides/images/feature_tile.gif +0 -0
  355. data/vendor/rails/railties/guides/images/footer_tile.gif +0 -0
  356. data/vendor/rails/railties/guides/images/fxn.jpg +0 -0
  357. data/vendor/rails/railties/guides/images/grey_bullet.gif +0 -0
  358. data/vendor/rails/railties/guides/images/habtm.png +0 -0
  359. data/vendor/rails/railties/guides/images/has_many.png +0 -0
  360. data/vendor/rails/railties/guides/images/has_many_through.png +0 -0
  361. data/vendor/rails/railties/guides/images/has_one.png +0 -0
  362. data/vendor/rails/railties/guides/images/has_one_through.png +0 -0
  363. data/vendor/rails/railties/guides/images/header_backdrop.png +0 -0
  364. data/vendor/rails/railties/guides/images/header_tile.gif +0 -0
  365. data/vendor/rails/railties/guides/images/i18n/demo_localized_pirate.png +0 -0
  366. data/vendor/rails/railties/guides/images/i18n/demo_translated_en.png +0 -0
  367. data/vendor/rails/railties/guides/images/i18n/demo_translated_pirate.png +0 -0
  368. data/vendor/rails/railties/guides/images/i18n/demo_translation_missing.png +0 -0
  369. data/vendor/rails/railties/guides/images/i18n/demo_untranslated.png +0 -0
  370. data/vendor/rails/railties/guides/images/icons/README +5 -0
  371. data/vendor/rails/railties/guides/images/icons/callouts/1.png +0 -0
  372. data/vendor/rails/railties/guides/images/icons/callouts/10.png +0 -0
  373. data/vendor/rails/railties/guides/images/icons/callouts/11.png +0 -0
  374. data/vendor/rails/railties/guides/images/icons/callouts/12.png +0 -0
  375. data/vendor/rails/railties/guides/images/icons/callouts/13.png +0 -0
  376. data/vendor/rails/railties/guides/images/icons/callouts/14.png +0 -0
  377. data/vendor/rails/railties/guides/images/icons/callouts/15.png +0 -0
  378. data/vendor/rails/railties/guides/images/icons/callouts/2.png +0 -0
  379. data/vendor/rails/railties/guides/images/icons/callouts/3.png +0 -0
  380. data/vendor/rails/railties/guides/images/icons/callouts/4.png +0 -0
  381. data/vendor/rails/railties/guides/images/icons/callouts/5.png +0 -0
  382. data/vendor/rails/railties/guides/images/icons/callouts/6.png +0 -0
  383. data/vendor/rails/railties/guides/images/icons/callouts/7.png +0 -0
  384. data/vendor/rails/railties/guides/images/icons/callouts/8.png +0 -0
  385. data/vendor/rails/railties/guides/images/icons/callouts/9.png +0 -0
  386. data/vendor/rails/railties/guides/images/icons/caution.png +0 -0
  387. data/vendor/rails/railties/guides/images/icons/example.png +0 -0
  388. data/vendor/rails/railties/guides/images/icons/home.png +0 -0
  389. data/vendor/rails/railties/guides/images/icons/important.png +0 -0
  390. data/vendor/rails/railties/guides/images/icons/next.png +0 -0
  391. data/vendor/rails/railties/guides/images/icons/note.png +0 -0
  392. data/vendor/rails/railties/guides/images/icons/prev.png +0 -0
  393. data/vendor/rails/railties/guides/images/icons/tip.png +0 -0
  394. data/vendor/rails/railties/guides/images/icons/up.png +0 -0
  395. data/vendor/rails/railties/guides/images/icons/warning.png +0 -0
  396. data/vendor/rails/railties/guides/images/nav_arrow.gif +0 -0
  397. data/vendor/rails/railties/guides/images/polymorphic.png +0 -0
  398. data/vendor/rails/railties/guides/images/posts_index.png +0 -0
  399. data/vendor/rails/railties/guides/images/rails_guides_logo.gif +0 -0
  400. data/vendor/rails/railties/guides/images/rails_logo_remix.gif +0 -0
  401. data/vendor/rails/railties/guides/images/rails_welcome.png +0 -0
  402. data/vendor/rails/railties/guides/images/session_fixation.png +0 -0
  403. data/vendor/rails/railties/guides/images/tab_grey.gif +0 -0
  404. data/vendor/rails/railties/guides/images/tab_info.gif +0 -0
  405. data/vendor/rails/railties/guides/images/tab_note.gif +0 -0
  406. data/vendor/rails/railties/guides/images/tab_red.gif +0 -0
  407. data/vendor/rails/railties/guides/images/tab_yellow.gif +0 -0
  408. data/vendor/rails/railties/guides/images/tab_yellow.png +0 -0
  409. data/vendor/rails/railties/guides/images/validation_error_messages.png +0 -0
  410. data/vendor/rails/railties/guides/rails_guides.rb +42 -0
  411. data/vendor/rails/railties/guides/rails_guides/generator.rb +138 -0
  412. data/vendor/rails/railties/guides/rails_guides/helpers.rb +34 -0
  413. data/vendor/rails/railties/guides/rails_guides/indexer.rb +55 -0
  414. data/vendor/rails/railties/guides/rails_guides/textile_extensions.rb +41 -0
  415. data/vendor/rails/railties/guides/source/2_2_release_notes.textile +422 -0
  416. data/vendor/rails/railties/guides/source/2_3_release_notes.textile +610 -0
  417. data/vendor/rails/railties/guides/source/action_controller_overview.textile +776 -0
  418. data/vendor/rails/railties/guides/source/action_mailer_basics.textile +424 -0
  419. data/vendor/rails/railties/guides/source/active_record_basics.textile +135 -0
  420. data/vendor/rails/railties/guides/source/active_record_querying.textile +969 -0
  421. data/vendor/rails/railties/guides/source/activerecord_validations_callbacks.textile +1086 -0
  422. data/vendor/rails/railties/guides/source/association_basics.textile +1781 -0
  423. data/vendor/rails/railties/guides/source/caching_with_rails.textile +524 -0
  424. data/vendor/rails/railties/guides/source/command_line.textile +589 -0
  425. data/vendor/rails/railties/guides/source/configuring.textile +234 -0
  426. data/vendor/rails/railties/guides/source/contribute.textile +71 -0
  427. data/vendor/rails/railties/guides/source/contributing_to_rails.textile +239 -0
  428. data/vendor/rails/railties/guides/source/credits.erb.textile +52 -0
  429. data/vendor/rails/railties/guides/source/debugging_rails_applications.textile +709 -0
  430. data/vendor/rails/railties/guides/source/form_helpers.textile +766 -0
  431. data/vendor/rails/railties/guides/source/getting_started.textile +1297 -0
  432. data/vendor/rails/railties/guides/source/i18n.textile +912 -0
  433. data/vendor/rails/railties/guides/source/index.erb.textile +124 -0
  434. data/vendor/rails/railties/guides/source/layout.html.erb +103 -0
  435. data/vendor/rails/railties/guides/source/layouts_and_rendering.textile +979 -0
  436. data/vendor/rails/railties/guides/source/migrations.textile +591 -0
  437. data/vendor/rails/railties/guides/source/nested_model_forms.textile +222 -0
  438. data/vendor/rails/railties/guides/source/performance_testing.textile +531 -0
  439. data/vendor/rails/railties/guides/source/plugins.textile +1512 -0
  440. data/vendor/rails/railties/guides/source/rails_on_rack.textile +309 -0
  441. data/vendor/rails/railties/guides/source/routing.textile +903 -0
  442. data/vendor/rails/railties/guides/source/security.textile +986 -0
  443. data/vendor/rails/railties/guides/source/testing.textile +951 -0
  444. data/vendor/rails/railties/lib/commands/dbconsole.rb +8 -4
  445. data/vendor/rails/railties/lib/commands/performance/profiler.rb +1 -1
  446. data/vendor/rails/railties/lib/initializer.rb +27 -4
  447. data/vendor/rails/railties/lib/rails/gem_dependency.rb +35 -6
  448. data/vendor/rails/railties/lib/rails/plugin.rb +12 -0
  449. data/vendor/rails/railties/lib/rails/plugin/loader.rb +7 -0
  450. data/vendor/rails/railties/lib/rails/rack/metal.rb +1 -1
  451. data/vendor/rails/railties/lib/rails/version.rb +1 -1
  452. data/vendor/rails/railties/lib/rails_generator/base.rb +1 -1
  453. data/vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb +5 -0
  454. data/vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb +1 -1
  455. data/vendor/rails/railties/lib/rails_generator/generators/components/model/model_generator.rb +9 -2
  456. data/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +1 -0
  457. data/vendor/rails/railties/lib/tasks/databases.rake +17 -4
  458. data/vendor/rails/railties/lib/tasks/gems.rake +19 -6
  459. data/vendor/rails/railties/lib/tasks/routes.rake +4 -3
  460. data/vendor/rails/railties/lib/test_help.rb +4 -1
  461. metadata +158 -58
  462. data/spec/lib/local_time_spec.rb +0 -40
  463. data/vendor/rails/actionpack/lib/action_controller/rewindable_input.rb +0 -28
  464. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack.rb +0 -89
  465. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +0 -22
  466. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +0 -37
  467. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +0 -37
  468. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +0 -58
  469. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +0 -124
  470. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +0 -51
  471. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +0 -55
  472. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +0 -40
  473. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +0 -480
  474. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/builder.rb +0 -63
  475. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +0 -36
  476. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +0 -49
  477. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +0 -61
  478. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +0 -45
  479. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +0 -29
  480. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +0 -23
  481. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +0 -85
  482. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/directory.rb +0 -153
  483. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/file.rb +0 -88
  484. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler.rb +0 -48
  485. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +0 -61
  486. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +0 -8
  487. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +0 -89
  488. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +0 -55
  489. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +0 -84
  490. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +0 -59
  491. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +0 -8
  492. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +0 -18
  493. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +0 -67
  494. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/head.rb +0 -19
  495. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/lint.rb +0 -462
  496. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +0 -65
  497. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/lock.rb +0 -16
  498. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +0 -27
  499. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/mime.rb +0 -204
  500. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/mock.rb +0 -160
  501. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +0 -57
  502. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +0 -64
  503. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/request.rb +0 -241
  504. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/response.rb +0 -179
  505. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +0 -142
  506. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +0 -91
  507. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +0 -109
  508. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +0 -100
  509. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +0 -349
  510. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +0 -106
  511. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/static.rb +0 -38
  512. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +0 -55
  513. data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/utils.rb +0 -392
@@ -319,10 +319,6 @@ class NamedScopeTest < ActiveRecord::TestCase
319
319
  assert_equal [posts(:sti_comments)], Post.with_special_comments.with_post(4).all.uniq
320
320
  end
321
321
 
322
- def test_methods_invoked_within_scopes_should_respect_scope
323
- assert_equal [], Topic.approved.by_rejected_ids.proxy_options[:conditions][:id]
324
- end
325
-
326
322
  def test_named_scopes_batch_finders
327
323
  assert_equal 3, Topic.approved.count
328
324
 
@@ -336,6 +332,12 @@ class NamedScopeTest < ActiveRecord::TestCase
336
332
  end
337
333
  end
338
334
  end
335
+
336
+ def test_table_names_for_chaining_scopes_with_and_without_table_name_included
337
+ assert_nothing_raised do
338
+ Comment.for_first_post.for_first_author.all
339
+ end
340
+ end
339
341
  end
340
342
 
341
343
  class DynamicScopeMatchTest < ActiveRecord::TestCase
@@ -98,4 +98,22 @@ class PrimaryKeysTest < ActiveRecord::TestCase
98
98
  def test_instance_destroy_should_quote_pkey
99
99
  assert_nothing_raised { MixedCaseMonkey.find(1).destroy }
100
100
  end
101
+
102
+ def test_supports_primary_key
103
+ assert_nothing_raised NoMethodError do
104
+ ActiveRecord::Base.connection.supports_primary_key?
105
+ end
106
+ end
107
+
108
+ def test_primary_key_returns_value_if_it_exists
109
+ if ActiveRecord::Base.connection.supports_primary_key?
110
+ assert_equal 'id', ActiveRecord::Base.connection.primary_key('developers')
111
+ end
112
+ end
113
+
114
+ def test_primary_key_returns_nil_if_it_does_not_exist
115
+ if ActiveRecord::Base.connection.supports_primary_key?
116
+ assert_nil ActiveRecord::Base.connection.primary_key('developers_projects')
117
+ end
118
+ end
101
119
  end
@@ -21,25 +21,25 @@ class ReflectionTest < ActiveRecord::TestCase
21
21
 
22
22
  def test_read_attribute_names
23
23
  assert_equal(
24
- %w( id title author_name author_email_address bonus_time written_on last_read content approved replies_count parent_id type ).sort,
24
+ %w( id title author_name author_email_address bonus_time written_on last_read content approved replies_count parent_id parent_title type ).sort,
25
25
  @first.attribute_names
26
26
  )
27
27
  end
28
28
 
29
29
  def test_columns
30
- assert_equal 12, Topic.columns.length
30
+ assert_equal 13, Topic.columns.length
31
31
  end
32
32
 
33
33
  def test_columns_are_returned_in_the_order_they_were_declared
34
34
  column_names = Topic.columns.map { |column| column.name }
35
- assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content approved replies_count parent_id type), column_names
35
+ assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content approved replies_count parent_id parent_title type), column_names
36
36
  end
37
37
 
38
38
  def test_content_columns
39
39
  content_columns = Topic.content_columns
40
40
  content_column_names = content_columns.map {|column| column.name}
41
- assert_equal 8, content_columns.length
42
- assert_equal %w(title author_name author_email_address written_on bonus_time last_read content approved).sort, content_column_names.sort
41
+ assert_equal 9, content_columns.length
42
+ assert_equal %w(title author_name author_email_address written_on bonus_time last_read content approved parent_title).sort, content_column_names.sort
43
43
  end
44
44
 
45
45
  def test_column_string_type_and_limit
@@ -170,8 +170,8 @@ class ReflectionTest < ActiveRecord::TestCase
170
170
 
171
171
  def test_reflection_of_all_associations
172
172
  # FIXME these assertions bust a lot
173
- assert_equal 28, Firm.reflect_on_all_associations.size
174
- assert_equal 21, Firm.reflect_on_all_associations(:has_many).size
173
+ assert_equal 30, Firm.reflect_on_all_associations.size
174
+ assert_equal 23, Firm.reflect_on_all_associations(:has_many).size
175
175
  assert_equal 7, Firm.reflect_on_all_associations(:has_one).size
176
176
  assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
177
177
  end
@@ -22,6 +22,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
22
22
  assert_no_match %r{create_table "sqlite_sequence"}, output
23
23
  end
24
24
 
25
+ def test_schema_dump_includes_camelcase_table_name
26
+ output = standard_dump
27
+ assert_match %r{create_table "CamelCase"}, output
28
+ end
29
+
25
30
  def assert_line_up(lines, pattern, required = false)
26
31
  return assert(true) if lines.empty?
27
32
  matches = lines.map { |line| line.match(pattern) }
@@ -147,19 +152,24 @@ class SchemaDumperTest < ActiveRecord::TestCase
147
152
  end
148
153
  end
149
154
 
155
+ def test_schema_dumps_index_columns_in_right_order
156
+ index_definition = standard_dump.split(/\n/).grep(/add_index.*companies/).first.strip
157
+ assert_equal 'add_index "companies", ["firm_id", "type", "rating", "ruby_type"], :name => "company_index"', index_definition
158
+ end
159
+
160
+ def test_schema_dump_should_honor_nonstandard_primary_keys
161
+ output = standard_dump
162
+ match = output.match(%r{create_table "movies"(.*)do})
163
+ assert_not_nil(match, "nonstandardpk table not found")
164
+ assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
165
+ end
166
+
150
167
  if current_adapter?(:MysqlAdapter)
151
168
  def test_schema_dump_should_not_add_default_value_for_mysql_text_field
152
169
  output = standard_dump
153
170
  assert_match %r{t.text\s+"body",\s+:null => false$}, output
154
171
  end
155
172
 
156
- def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
157
- output = standard_dump
158
- match = output.match(%r{create_table "movies"(.*)do})
159
- assert_not_nil(match, "nonstandardpk table not found")
160
- assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
161
- end
162
-
163
173
  def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
164
174
  output = standard_dump
165
175
  assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output
@@ -180,4 +190,22 @@ class SchemaDumperTest < ActiveRecord::TestCase
180
190
  output = stream.string
181
191
  assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output
182
192
  end
193
+
194
+ if current_adapter?(:PostgreSQLAdapter)
195
+ def test_schema_dump_includes_xml_shorthand_definition
196
+ output = standard_dump
197
+ if %r{create_table "postgresql_xml_data_type"} =~ output
198
+ assert_match %r{t.xml "data"}, output
199
+ end
200
+ end
201
+ end
202
+
203
+ def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
204
+ output = standard_dump
205
+ match = output.match(%r{create_table "goofy_string_id"(.*)do.*\n(.*)\n})
206
+ assert_not_nil(match, "goofy_string_id table not found")
207
+ assert_match %r(:id => false), match[1], "no table id not preserved"
208
+ assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
209
+ end
183
210
  end
211
+
@@ -6,6 +6,7 @@ class SchemaTest < ActiveRecord::TestCase
6
6
  SCHEMA_NAME = 'test_schema'
7
7
  SCHEMA2_NAME = 'test_schema2'
8
8
  TABLE_NAME = 'things'
9
+ CAPITALIZED_TABLE_NAME = 'Things'
9
10
  INDEX_A_NAME = 'a_index_things_on_name'
10
11
  INDEX_B_NAME = 'b_index_things_on_different_columns_in_each_schema'
11
12
  INDEX_A_COLUMN = 'name'
@@ -18,9 +19,27 @@ class SchemaTest < ActiveRecord::TestCase
18
19
  'moment timestamp without time zone default now()'
19
20
  ]
20
21
 
22
+ class Thing1 < ActiveRecord::Base
23
+ set_table_name "test_schema.things"
24
+ end
25
+
26
+ class Thing2 < ActiveRecord::Base
27
+ set_table_name "test_schema2.things"
28
+ end
29
+
30
+ class Thing3 < ActiveRecord::Base
31
+ set_table_name 'test_schema."things.table"'
32
+ end
33
+
34
+ class Thing4 < ActiveRecord::Base
35
+ set_table_name 'test_schema."Things"'
36
+ end
37
+
21
38
  def setup
22
39
  @connection = ActiveRecord::Base.connection
23
40
  @connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
41
+ @connection.execute "CREATE TABLE #{SCHEMA_NAME}.\"#{TABLE_NAME}.table\" (#{COLUMNS.join(',')})"
42
+ @connection.execute "CREATE TABLE #{SCHEMA_NAME}.\"#{CAPITALIZED_TABLE_NAME}\" (#{COLUMNS.join(',')})"
24
43
  @connection.execute "CREATE SCHEMA #{SCHEMA2_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
25
44
  @connection.execute "CREATE INDEX #{INDEX_A_NAME} ON #{SCHEMA_NAME}.#{TABLE_NAME} USING btree (#{INDEX_A_COLUMN});"
26
45
  @connection.execute "CREATE INDEX #{INDEX_A_NAME} ON #{SCHEMA2_NAME}.#{TABLE_NAME} USING btree (#{INDEX_A_COLUMN});"
@@ -39,6 +58,12 @@ class SchemaTest < ActiveRecord::TestCase
39
58
  end
40
59
  end
41
60
 
61
+ def test_with_schema_prefixed_capitalized_table_name
62
+ assert_nothing_raised do
63
+ assert_equal COLUMNS, columns("#{SCHEMA_NAME}.#{CAPITALIZED_TABLE_NAME}")
64
+ end
65
+ end
66
+
42
67
  def test_with_schema_search_path
43
68
  assert_nothing_raised do
44
69
  with_schema_search_path(SCHEMA_NAME) do
@@ -47,6 +72,47 @@ class SchemaTest < ActiveRecord::TestCase
47
72
  end
48
73
  end
49
74
 
75
+
76
+ def test_proper_encoding_of_table_name
77
+ assert_equal '"table_name"', @connection.quote_table_name('table_name')
78
+ assert_equal '"table.name"', @connection.quote_table_name('"table.name"')
79
+ assert_equal '"schema_name"."table_name"', @connection.quote_table_name('schema_name.table_name')
80
+ assert_equal '"schema_name"."table.name"', @connection.quote_table_name('schema_name."table.name"')
81
+ assert_equal '"schema.name"."table_name"', @connection.quote_table_name('"schema.name".table_name')
82
+ assert_equal '"schema.name"."table.name"', @connection.quote_table_name('"schema.name"."table.name"')
83
+ end
84
+
85
+ def test_classes_with_qualified_schema_name
86
+ assert_equal 0, Thing1.count
87
+ assert_equal 0, Thing2.count
88
+ assert_equal 0, Thing3.count
89
+ assert_equal 0, Thing4.count
90
+
91
+ Thing1.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
92
+ assert_equal 1, Thing1.count
93
+ assert_equal 0, Thing2.count
94
+ assert_equal 0, Thing3.count
95
+ assert_equal 0, Thing4.count
96
+
97
+ Thing2.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
98
+ assert_equal 1, Thing1.count
99
+ assert_equal 1, Thing2.count
100
+ assert_equal 0, Thing3.count
101
+ assert_equal 0, Thing4.count
102
+
103
+ Thing3.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
104
+ assert_equal 1, Thing1.count
105
+ assert_equal 1, Thing2.count
106
+ assert_equal 1, Thing3.count
107
+ assert_equal 0, Thing4.count
108
+
109
+ Thing4.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
110
+ assert_equal 1, Thing1.count
111
+ assert_equal 1, Thing2.count
112
+ assert_equal 1, Thing3.count
113
+ assert_equal 1, Thing4.count
114
+ end
115
+
50
116
  def test_raise_on_unquoted_schema_name
51
117
  assert_raise(ActiveRecord::StatementInvalid) do
52
118
  with_schema_search_path '$user,public'
@@ -69,6 +135,16 @@ class SchemaTest < ActiveRecord::TestCase
69
135
  do_dump_index_tests_for_schema(SCHEMA2_NAME, INDEX_A_COLUMN, INDEX_B_COLUMN_S2)
70
136
  end
71
137
 
138
+ def test_with_uppercase_index_name
139
+ ActiveRecord::Base.connection.execute "CREATE INDEX \"things_Index\" ON #{SCHEMA_NAME}.things (name)"
140
+ assert_nothing_raised { ActiveRecord::Base.connection.remove_index :things, :name => "#{SCHEMA_NAME}.things_Index"}
141
+
142
+ ActiveRecord::Base.connection.execute "CREATE INDEX \"things_Index\" ON #{SCHEMA_NAME}.things (name)"
143
+ ActiveRecord::Base.connection.schema_search_path = SCHEMA_NAME
144
+ assert_nothing_raised { ActiveRecord::Base.connection.remove_index :things, :name => "things_Index"}
145
+ ActiveRecord::Base.connection.schema_search_path = "public"
146
+ end
147
+
72
148
  private
73
149
  def columns(table_name)
74
150
  @connection.send(:column_definitions, table_name).map do |name, type, default|
@@ -0,0 +1,75 @@
1
+ require 'cases/helper'
2
+ require 'models/developer'
3
+ require 'models/owner'
4
+ require 'models/pet'
5
+
6
+ class TimestampTest < ActiveRecord::TestCase
7
+ fixtures :developers, :owners, :pets
8
+
9
+ def setup
10
+ @developer = Developer.first
11
+ @previously_updated_at = @developer.updated_at
12
+ end
13
+
14
+ def test_saving_a_changed_record_updates_its_timestamp
15
+ @developer.name = "Jack Bauer"
16
+ @developer.save!
17
+
18
+ assert @previously_updated_at != @developer.updated_at
19
+ end
20
+
21
+ def test_saving_a_unchanged_record_doesnt_update_its_timestamp
22
+ @developer.save!
23
+
24
+ assert @previously_updated_at == @developer.updated_at
25
+ end
26
+
27
+ def test_touching_a_record_updates_its_timestamp
28
+ @developer.touch
29
+
30
+ assert @previously_updated_at != @developer.updated_at
31
+ end
32
+
33
+ def test_touching_a_different_attribute
34
+ previously_created_at = @developer.created_at
35
+ @developer.touch(:created_at)
36
+
37
+ assert previously_created_at != @developer.created_at
38
+ end
39
+
40
+ def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
41
+ pet = Pet.first
42
+ owner = pet.owner
43
+ previously_owner_updated_at = owner.updated_at
44
+
45
+ pet.name = "Fluffy the Third"
46
+ pet.save
47
+
48
+ assert previously_owner_updated_at != pet.owner.updated_at
49
+ end
50
+
51
+ def test_destroying_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
52
+ pet = Pet.first
53
+ owner = pet.owner
54
+ previously_owner_updated_at = owner.updated_at
55
+
56
+ pet.destroy
57
+
58
+ assert previously_owner_updated_at != pet.owner.updated_at
59
+ end
60
+
61
+ def test_saving_a_record_with_a_belongs_to_that_specifies_touching_a_specific_attribute_the_parent_should_update_that_attribute
62
+ Pet.belongs_to :owner, :touch => :happy_at
63
+
64
+ pet = Pet.first
65
+ owner = pet.owner
66
+ previously_owner_happy_at = owner.happy_at
67
+
68
+ pet.name = "Fluffy the Third"
69
+ pet.save
70
+
71
+ assert previously_owner_happy_at != pet.owner.happy_at
72
+ ensure
73
+ Pet.belongs_to :owner, :touch => true
74
+ end
75
+ end
@@ -1,32 +1,20 @@
1
1
  require "cases/helper"
2
2
  require 'models/topic'
3
3
  require 'models/reply'
4
+ require 'models/person'
4
5
 
5
- class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
6
- def setup
7
- reset_callbacks Topic
8
- @topic = Topic.new
9
- @old_load_path, @old_backend = I18n.load_path, I18n.backend
10
- I18n.load_path.clear
11
- I18n.backend = I18n::Backend::Simple.new
12
- I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}})
13
- end
14
-
15
- def teardown
16
- reset_callbacks Topic
17
- I18n.load_path.replace @old_load_path
18
- I18n.backend = @old_backend
19
- end
20
-
21
- def unique_topic
22
- @unique ||= Topic.create :title => 'unique!'
6
+ module ActiveRecordValidationsI18nTestHelper
7
+ def store_translations(*args)
8
+ data = args.extract_options!
9
+ locale = args.shift || 'en'
10
+ I18n.backend.send(:init_translations)
11
+ I18n.backend.store_translations(locale, :activerecord => data)
23
12
  end
24
13
 
25
- def replied_topic
26
- @replied_topic ||= begin
27
- topic = Topic.create(:title => "topic")
28
- topic.replies << Reply.new
29
- topic
14
+ def delete_translation(key)
15
+ I18n.backend.instance_eval do
16
+ keys = I18n.send(:normalize_translation_keys, 'en', key, nil)
17
+ keys.inject(translations) { |result, k| keys.last == k ? result.delete(k.to_sym) : result[k.to_sym] }
30
18
  end
31
19
  end
32
20
 
@@ -37,879 +25,923 @@ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
37
25
  model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
38
26
  end
39
27
  end
28
+ end
29
+
30
+ # DEPRECATIONS
40
31
 
41
- def test_default_error_messages_is_deprecated
32
+ class ActiveRecordValidationsI18nDeprecationsTests < ActiveSupport::TestCase
33
+ test "default_error_messages is deprecated and can be removed in Rails 3 / ActiveModel" do
42
34
  assert_deprecated('ActiveRecord::Errors.default_error_messages') do
43
35
  ActiveRecord::Errors.default_error_messages
44
36
  end
45
37
  end
46
38
 
47
- def test_percent_s_interpolation_syntax_in_error_messages_still_works
39
+ test "%s interpolation syntax in error messages still works" do
48
40
  ActiveSupport::Deprecation.silence do
49
41
  result = I18n.t :does_not_exist, :default => "%s interpolation syntax is deprecated", :value => 'this'
50
42
  assert_equal result, "this interpolation syntax is deprecated"
51
43
  end
52
44
  end
53
45
 
54
- def test_percent_s_interpolation_syntax_in_error_messages_is_deprecated
46
+ test "%s interpolation syntax in error messages is deprecated" do
55
47
  assert_deprecated('using %s in messages') do
56
48
  I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this'
57
49
  end
58
50
  end
59
51
 
60
- def test_percent_d_interpolation_syntax_in_error_messages_still_works
52
+ test "%d interpolation syntax in error messages still works" do
61
53
  ActiveSupport::Deprecation.silence do
62
54
  result = I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprecated", :count => 2
63
55
  assert_equal result, "2 interpolation syntaxes are deprecated"
64
56
  end
65
57
  end
66
58
 
67
- def test_percent_d_interpolation_syntax_in_error_messages_is_deprecated
59
+ test "%d interpolation syntax in error messages is deprecated" do
68
60
  assert_deprecated('using %d in messages') do
69
61
  I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprected", :count => 2
70
62
  end
71
63
  end
64
+ end
72
65
 
73
- # ActiveRecord::Errors
74
- def test_errors_generate_message_translates_custom_model_attribute_key
75
-
76
- I18n.expects(:translate).with(
77
- :topic,
78
- { :count => 1,
79
- :default => ['Topic'],
80
- :scope => [:activerecord, :models]
81
- }
82
- ).returns('Topic')
83
-
84
- I18n.expects(:translate).with(
85
- :"topic.title",
86
- { :count => 1,
87
- :default => ['Title'],
88
- :scope => [:activerecord, :attributes]
89
- }
90
- ).returns('Title')
91
-
92
- I18n.expects(:translate).with(
93
- :"models.topic.attributes.title.invalid",
94
- :value => nil,
95
- :scope => [:activerecord, :errors],
96
- :default => [
97
- :"models.topic.invalid",
98
- 'default from class def error 1',
99
- :"messages.invalid"],
100
- :attribute => "Title",
101
- :model => "Topic"
102
- ).returns('default from class def error 1')
103
-
104
- @topic.errors.generate_message :title, :invalid, :default => 'default from class def error 1'
105
- end
106
-
107
- def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti
108
-
109
- I18n.expects(:translate).with(
110
- :reply,
111
- { :count => 1,
112
- :default => [:topic, 'Reply'],
113
- :scope => [:activerecord, :models]
114
- }
115
- ).returns('Reply')
116
-
117
- I18n.expects(:translate).with(
118
- :"reply.title",
119
- { :count => 1,
120
- :default => [:'topic.title', 'Title'],
121
- :scope => [:activerecord, :attributes]
122
- }
123
- ).returns('Title')
124
66
 
125
- I18n.expects(:translate).with(
126
- :"models.reply.attributes.title.invalid",
127
- :value => nil,
128
- :scope => [:activerecord, :errors],
129
- :default => [
130
- :"models.reply.invalid",
131
- :"models.topic.attributes.title.invalid",
132
- :"models.topic.invalid",
133
- 'default from class def',
134
- :"messages.invalid"],
135
- :model => 'Reply',
136
- :attribute => 'Title'
137
- ).returns("default from class def")
67
+ # ACTIVERECORD VALIDATIONS
68
+ #
69
+ # For each validation:
70
+ #
71
+ # * test expect that it adds an error with the appropriate arguments
72
+ # * test that it looks up the correct default message
138
73
 
139
- Reply.new.errors.generate_message :title, :invalid, :default => 'default from class def'
74
+ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
75
+ include ActiveRecordValidationsI18nTestHelper
140
76
 
77
+ def setup
78
+ reset_callbacks(Topic)
79
+ @topic = Topic.new
80
+ @reply = Reply.new
81
+ @old_load_path, @old_backend = I18n.load_path, I18n.backend
82
+ I18n.load_path.clear
83
+ I18n.backend = I18n::Backend::Simple.new
84
+ I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}})
141
85
  end
142
86
 
143
- def test_errors_add_on_empty_generates_message
144
- @topic.errors.expects(:generate_message).with(:title, :empty, {:default => nil})
145
- @topic.errors.add_on_empty :title
87
+ def teardown
88
+ reset_callbacks(Topic)
89
+ I18n.load_path.replace(@old_load_path)
90
+ I18n.backend = @old_backend
146
91
  end
147
92
 
148
- def test_errors_add_on_empty_generates_message_with_custom_default_message
149
- @topic.errors.expects(:generate_message).with(:title, :empty, {:default => 'custom'})
150
- @topic.errors.add_on_empty :title, 'custom'
93
+ def expect_error_added(model, attribute, type, options)
94
+ model.errors.expects(:add).with(attribute, type, options)
95
+ yield
96
+ model.valid?
151
97
  end
152
98
 
153
- def test_errors_add_on_blank_generates_message
154
- @topic.errors.expects(:generate_message).with(:title, :blank, {:default => nil})
155
- @topic.errors.add_on_blank :title
99
+ def assert_message_translations(model, attribute, type, &block)
100
+ assert_default_message_translation(model, attribute, type, &block)
101
+ reset_callbacks(model.class)
102
+ model.errors.clear
103
+ assert_custom_message_translation(model, attribute, type, &block)
156
104
  end
157
105
 
158
- def test_errors_add_on_blank_generates_message_with_custom_default_message
159
- @topic.errors.expects(:generate_message).with(:title, :blank, {:default => 'custom'})
160
- @topic.errors.add_on_blank :title, 'custom'
106
+ def assert_custom_message_translation(model, attribute, type)
107
+ store_translations(:errors => { :models => { model.class.name.underscore => { :attributes => { attribute => { type => 'custom message' } } } } })
108
+ yield
109
+ model.valid?
110
+ assert_equal 'custom message', model.errors.on(attribute)
161
111
  end
162
112
 
163
- def test_errors_full_messages_translates_human_attribute_name_for_model_attributes
164
- @topic.errors.instance_variable_set :@errors, { 'title' => ['empty'] }
165
- I18n.expects(:translate).with(:"topic.title", :default => ['Title'], :scope => [:activerecord, :attributes], :count => 1).returns('Title')
166
- @topic.errors.full_messages :locale => 'en'
113
+ def assert_default_message_translation(model, attribute, type)
114
+ store_translations(:errors => { :messages => { type => 'default message' } })
115
+ yield
116
+ model.valid?
117
+ assert_equal 'default message', model.errors.on(attribute)
167
118
  end
168
119
 
169
- # ActiveRecord::Validations
170
- # validates_confirmation_of w/ mocha
171
- def test_validates_confirmation_of_generates_message
172
- Topic.validates_confirmation_of :title
173
- @topic.title_confirmation = 'foo'
174
- @topic.errors.expects(:generate_message).with(:title, :confirmation, {:default => nil})
175
- @topic.valid?
120
+ def unique_topic
121
+ @unique ||= Topic.create(:title => 'unique!')
176
122
  end
177
123
 
178
- def test_validates_confirmation_of_generates_message_with_custom_default_message
179
- Topic.validates_confirmation_of :title, :message => 'custom'
180
- @topic.title_confirmation = 'foo'
181
- @topic.errors.expects(:generate_message).with(:title, :confirmation, {:default => 'custom'})
182
- @topic.valid?
124
+ def replied_topic
125
+ @replied_topic ||= begin
126
+ topic = Topic.create(:title => "topic")
127
+ topic.replies << Reply.new
128
+ topic
129
+ end
183
130
  end
184
131
 
185
- # validates_acceptance_of w/ mocha
132
+ # validates_confirmation_of
186
133
 
187
- def test_validates_acceptance_of_generates_message
188
- Topic.validates_acceptance_of :title, :allow_nil => false
189
- @topic.errors.expects(:generate_message).with(:title, :accepted, {:default => nil})
190
- @topic.valid?
191
- end
192
-
193
- def test_validates_acceptance_of_generates_message_with_custom_default_message
194
- Topic.validates_acceptance_of :title, :message => 'custom', :allow_nil => false
195
- @topic.errors.expects(:generate_message).with(:title, :accepted, {:default => 'custom'})
196
- @topic.valid?
134
+ test "#validates_confirmation_of given no custom message" do
135
+ expect_error_added(@topic, :title, :confirmation, :default => nil) do
136
+ Topic.validates_confirmation_of :title
137
+ @topic.title = 'title'
138
+ @topic.title_confirmation = 'foo'
139
+ end
197
140
  end
198
141
 
199
- # validates_presence_of w/ mocha
200
-
201
- def test_validates_presence_of_generates_message
202
- Topic.validates_presence_of :title
203
- @topic.errors.expects(:generate_message).with(:title, :blank, {:default => nil})
204
- @topic.valid?
142
+ test "#validates_confirmation_of given a custom message" do
143
+ expect_error_added(@topic, :title, :confirmation, :default => 'custom') do
144
+ Topic.validates_confirmation_of :title, :message => 'custom'
145
+ @topic.title_confirmation = 'foo'
146
+ end
205
147
  end
206
148
 
207
- def test_validates_presence_of_generates_message_with_custom_default_message
208
- Topic.validates_presence_of :title, :message => 'custom'
209
- @topic.errors.expects(:generate_message).with(:title, :blank, {:default => 'custom'})
210
- @topic.valid?
149
+ test "#validates_confirmation_of finds the correct message translations" do
150
+ assert_message_translations(@topic, :title, :confirmation) do
151
+ Topic.validates_confirmation_of :title
152
+ @topic.title_confirmation = 'foo'
153
+ end
211
154
  end
212
155
 
213
- def test_validates_length_of_within_generates_message_with_title_too_short
214
- Topic.validates_length_of :title, :within => 3..5
215
- @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
216
- @topic.valid?
217
- end
156
+ # validates_acceptance_of
218
157
 
219
- def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message
220
- Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom'
221
- @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'})
222
- @topic.valid?
158
+ test "#validates_acceptance_of given no custom message" do
159
+ expect_error_added(@topic, :title, :accepted, :default => nil) do
160
+ Topic.validates_acceptance_of :title, :allow_nil => false
161
+ end
223
162
  end
224
163
 
225
- def test_validates_length_of_within_generates_message_with_title_too_long
226
- Topic.validates_length_of :title, :within => 3..5
227
- @topic.title = 'this title is too long'
228
- @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil})
229
- @topic.valid?
164
+ test "#validates_acceptance_of given a custom message" do
165
+ expect_error_added(@topic, :title, :accepted, :default => 'custom') do
166
+ Topic.validates_acceptance_of :title, :message => 'custom', :allow_nil => false
167
+ end
230
168
  end
231
169
 
232
- def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message
233
- Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom'
234
- @topic.title = 'this title is too long'
235
- @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'})
236
- @topic.valid?
170
+ test "#validates_acceptance_of finds the correct message translations" do
171
+ assert_message_translations(@topic, :title, :accepted) do
172
+ Topic.validates_acceptance_of :title, :allow_nil => false
173
+ end
237
174
  end
238
175
 
239
- # validates_length_of :within w/ mocha
240
-
241
- def test_validates_length_of_within_generates_message_with_title_too_short
242
- Topic.validates_length_of :title, :within => 3..5
243
- @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
244
- @topic.valid?
245
- end
176
+ # validates_presence_of
246
177
 
247
- def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message
248
- Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom'
249
- @topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'})
250
- @topic.valid?
178
+ test "#validates_presence_of given no custom message" do
179
+ expect_error_added(@topic, :title, :blank, :default => nil) do
180
+ Topic.validates_presence_of :title
181
+ end
251
182
  end
252
183
 
253
- def test_validates_length_of_within_generates_message_with_title_too_long
254
- Topic.validates_length_of :title, :within => 3..5
255
- @topic.title = 'this title is too long'
256
- @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil})
257
- @topic.valid?
184
+ test "#validates_presence_of given a custom message" do
185
+ expect_error_added(@topic, :title, :blank, :default => 'custom') do
186
+ Topic.validates_presence_of :title, :message => 'custom'
187
+ end
258
188
  end
259
189
 
260
- def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message
261
- Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom'
262
- @topic.title = 'this title is too long'
263
- @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'})
264
- @topic.valid?
190
+ test "#validates_presence_of finds the correct message translations" do
191
+ assert_message_translations(@topic, :title, :blank) do
192
+ Topic.validates_presence_of :title
193
+ end
265
194
  end
266
195
 
267
- # validates_length_of :is w/ mocha
196
+ # validates_length_of :too_short
268
197
 
269
- def test_validates_length_of_is_generates_message
270
- Topic.validates_length_of :title, :is => 5
271
- @topic.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :default => nil})
272
- @topic.valid?
198
+ test "#validates_length_of (:too_short) and no custom message" do
199
+ expect_error_added(@topic, :title, :too_short, :default => nil, :count => 3) do
200
+ Topic.validates_length_of :title, :within => 3..5
201
+ end
273
202
  end
274
203
 
275
- def test_validates_length_of_is_generates_message_with_custom_default_message
276
- Topic.validates_length_of :title, :is => 5, :message => 'custom'
277
- @topic.errors.expects(:generate_message).with(:title, :wrong_length, {:count => 5, :default => 'custom'})
278
- @topic.valid?
204
+ test "#validates_length_of (:too_short) and a custom message" do
205
+ expect_error_added(@topic, :title, :too_short, :default => 'custom', :count => 3) do
206
+ Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom'
207
+ end
279
208
  end
280
209
 
281
- # validates_uniqueness_of w/ mocha
282
-
283
- def test_validates_uniqueness_of_generates_message
284
- Topic.validates_uniqueness_of :title
285
- @topic.title = unique_topic.title
286
- @topic.errors.expects(:generate_message).with(:title, :taken, {:default => nil, :value => 'unique!'})
287
- @topic.valid?
210
+ test "#validates_length_of (:too_short) finds the correct message translations" do
211
+ assert_message_translations(@topic, :title, :too_short) do
212
+ Topic.validates_length_of :title, :within => 3..5
213
+ end
288
214
  end
289
215
 
290
- def test_validates_uniqueness_of_generates_message_with_custom_default_message
291
- Topic.validates_uniqueness_of :title, :message => 'custom'
292
- @topic.title = unique_topic.title
293
- @topic.errors.expects(:generate_message).with(:title, :taken, {:default => 'custom', :value => 'unique!'})
294
- @topic.valid?
295
- end
216
+ # validates_length_of :too_long
296
217
 
297
- # validates_format_of w/ mocha
218
+ test "#validates_length_of (:too_long) and no custom message" do
219
+ expect_error_added(@topic, :title, :too_long, :default => nil, :count => 5) do
220
+ Topic.validates_length_of :title, :within => 3..5
221
+ @topic.title = 'this title is too long'
222
+ end
223
+ end
298
224
 
299
- def test_validates_format_of_generates_message
300
- Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
301
- @topic.title = '72x'
302
- @topic.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :default => nil})
303
- @topic.valid?
225
+ test "#validates_length_of (:too_long) and a custom message" do
226
+ expect_error_added(@topic, :title, :too_long, :default => 'custom', :count => 5) do
227
+ Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom'
228
+ @topic.title = 'this title is too long'
229
+ end
304
230
  end
305
231
 
306
- def test_validates_format_of_generates_message_with_custom_default_message
307
- Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/, :message => 'custom'
308
- @topic.title = '72x'
309
- @topic.errors.expects(:generate_message).with(:title, :invalid, {:value => '72x', :default => 'custom'})
310
- @topic.valid?
232
+ test "#validates_length_of (:too_long) finds the correct message translations" do
233
+ assert_message_translations(@topic, :title, :too_long) do
234
+ Topic.validates_length_of :title, :within => 3..5
235
+ @topic.title = 'this title is too long'
236
+ end
311
237
  end
312
238
 
313
- # validates_inclusion_of w/ mocha
239
+ # validates_length_of :is
314
240
 
315
- def test_validates_inclusion_of_generates_message
316
- Topic.validates_inclusion_of :title, :in => %w(a b c)
317
- @topic.title = 'z'
318
- @topic.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :default => nil})
319
- @topic.valid?
241
+ test "#validates_length_of (:is) and no custom message" do
242
+ expect_error_added(@topic, :title, :wrong_length, :default => nil, :count => 5) do
243
+ Topic.validates_length_of :title, :is => 5
244
+ @topic.title = 'this title has the wrong length'
245
+ end
320
246
  end
321
247
 
322
- def test_validates_inclusion_of_generates_message_with_custom_default_message
323
- Topic.validates_inclusion_of :title, :in => %w(a b c), :message => 'custom'
324
- @topic.title = 'z'
325
- @topic.errors.expects(:generate_message).with(:title, :inclusion, {:value => 'z', :default => 'custom'})
326
- @topic.valid?
248
+ test "#validates_length_of (:is) and a custom message" do
249
+ expect_error_added(@topic, :title, :wrong_length, :default => 'custom', :count => 5) do
250
+ Topic.validates_length_of :title, :is => 5, :wrong_length => 'custom'
251
+ @topic.title = 'this title has the wrong length'
252
+ end
327
253
  end
328
254
 
329
- # validates_exclusion_of w/ mocha
330
-
331
- def test_validates_exclusion_of_generates_message
332
- Topic.validates_exclusion_of :title, :in => %w(a b c)
333
- @topic.title = 'a'
334
- @topic.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => nil})
335
- @topic.valid?
255
+ test "#validates_length_of (:is) finds the correct message translations" do
256
+ assert_message_translations(@topic, :title, :wrong_length) do
257
+ Topic.validates_length_of :title, :is => 5
258
+ @topic.title = 'this title has the wrong length'
259
+ end
336
260
  end
337
261
 
338
- def test_validates_exclusion_of_generates_message_with_custom_default_message
339
- Topic.validates_exclusion_of :title, :in => %w(a b c), :message => 'custom'
340
- @topic.title = 'a'
341
- @topic.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => 'custom'})
342
- @topic.valid?
343
- end
262
+ # validates_uniqueness_of
344
263
 
345
- # validates_numericality_of without :only_integer w/ mocha
264
+ test "#validates_uniqueness_of and no custom message" do
265
+ expect_error_added(@topic, :title, :taken, :default => nil, :value => 'unique!') do
266
+ Topic.validates_uniqueness_of :title
267
+ @topic.title = unique_topic.title
268
+ end
269
+ end
346
270
 
347
- def test_validates_numericality_of_generates_message
348
- Topic.validates_numericality_of :title
349
- @topic.title = 'a'
350
- @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => nil})
351
- @topic.valid?
271
+ test "#validates_uniqueness_of and a custom message" do
272
+ expect_error_added(@topic, :title, :taken, :default => 'custom', :value => 'unique!') do
273
+ Topic.validates_uniqueness_of :title, :message => 'custom'
274
+ @topic.title = unique_topic.title
275
+ end
352
276
  end
353
277
 
354
- def test_validates_numericality_of_generates_message_with_custom_default_message
355
- Topic.validates_numericality_of :title, :message => 'custom'
356
- @topic.title = 'a'
357
- @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => 'custom'})
358
- @topic.valid?
278
+ test "#validates_uniqueness_of finds the correct message translations" do
279
+ assert_message_translations(@topic, :title, :taken) do
280
+ Topic.validates_uniqueness_of :title
281
+ @topic.title = unique_topic.title
282
+ end
359
283
  end
360
284
 
361
- # validates_numericality_of with :only_integer w/ mocha
285
+ # validates_format_of
362
286
 
363
- def test_validates_numericality_of_only_integer_generates_message
364
- Topic.validates_numericality_of :title, :only_integer => true
365
- @topic.title = 'a'
366
- @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => nil})
367
- @topic.valid?
287
+ test "#validates_format_of and no custom message" do
288
+ expect_error_added(@topic, :title, :invalid, :default => nil, :value => '72x') do
289
+ Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
290
+ @topic.title = '72x'
291
+ end
368
292
  end
369
293
 
370
- def test_validates_numericality_of_only_integer_generates_message_with_custom_default_message
371
- Topic.validates_numericality_of :title, :only_integer => true, :message => 'custom'
372
- @topic.title = 'a'
373
- @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => 'custom'})
374
- @topic.valid?
294
+ test "#validates_format_of and a custom message" do
295
+ expect_error_added(@topic, :title, :invalid, :default => 'custom', :value => '72x') do
296
+ Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/, :message => 'custom'
297
+ @topic.title = '72x'
298
+ end
375
299
  end
376
300
 
377
- # validates_numericality_of :odd w/ mocha
378
-
379
- def test_validates_numericality_of_odd_generates_message
380
- Topic.validates_numericality_of :title, :only_integer => true, :odd => true
381
- @topic.title = 0
382
- @topic.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => nil})
383
- @topic.valid?
301
+ test "#validates_format_of finds the correct message translations" do
302
+ assert_message_translations(@topic, :title, :invalid) do
303
+ Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
304
+ @topic.title = '72x'
305
+ end
384
306
  end
385
307
 
386
- def test_validates_numericality_of_odd_generates_message_with_custom_default_message
387
- Topic.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom'
388
- @topic.title = 0
389
- @topic.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => 'custom'})
390
- @topic.valid?
391
- end
308
+ # validates_inclusion_of
392
309
 
393
- # validates_numericality_of :less_than w/ mocha
310
+ test "#validates_inclusion_of and no custom message" do
311
+ list = %w(a b c)
312
+ expect_error_added(@topic, :title, :inclusion, :default => nil, :value => 'z') do
313
+ Topic.validates_inclusion_of :title, :in => list
314
+ @topic.title = 'z'
315
+ end
316
+ end
394
317
 
395
- def test_validates_numericality_of_less_than_generates_message
396
- Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
397
- @topic.title = 1
398
- @topic.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => nil})
399
- @topic.valid?
318
+ test "#validates_inclusion_of and a custom message" do
319
+ list = %w(a b c)
320
+ expect_error_added(@topic, :title, :inclusion, :default => 'custom', :value => 'z') do
321
+ Topic.validates_inclusion_of :title, :in => list, :message => 'custom'
322
+ @topic.title = 'z'
323
+ end
400
324
  end
401
325
 
402
- def test_validates_numericality_of_odd_generates_message_with_custom_default_message
403
- Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom'
404
- @topic.title = 1
405
- @topic.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => 'custom'})
406
- @topic.valid?
326
+ test "#validates_inclusion_of finds the correct message translations" do
327
+ list = %w(a b c)
328
+ assert_message_translations(@topic, :title, :inclusion) do
329
+ Topic.validates_inclusion_of :title, :in => list
330
+ @topic.title = 'z'
331
+ end
407
332
  end
408
333
 
409
- # validates_associated w/ mocha
334
+ # validates_exclusion_of
410
335
 
411
- def test_validates_associated_generates_message
412
- Topic.validates_associated :replies
413
- replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil})
414
- replied_topic.valid?
336
+ test "#validates_exclusion_of and no custom message" do
337
+ list = %w(a b c)
338
+ expect_error_added(@topic, :title, :exclusion, :default => nil, :value => 'a') do
339
+ Topic.validates_exclusion_of :title, :in => list
340
+ @topic.title = 'a'
341
+ end
415
342
  end
416
343
 
417
- def test_validates_associated_generates_message_with_custom_default_message
418
- Topic.validates_associated :replies
419
- replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil})
420
- replied_topic.valid?
344
+ test "#validates_exclusion_of and a custom message" do
345
+ list = %w(a b c)
346
+ expect_error_added(@topic, :title, :exclusion, :default => 'custom', :value => 'a') do
347
+ Topic.validates_exclusion_of :title, :in => list, :message => 'custom'
348
+ @topic.title = 'a'
349
+ end
421
350
  end
422
351
 
423
- # validates_confirmation_of w/o mocha
352
+ test "#validates_exclusion_of finds the correct message translations" do
353
+ list = %w(a b c)
354
+ assert_message_translations(@topic, :title, :exclusion) do
355
+ Topic.validates_exclusion_of :title, :in => list
356
+ @topic.title = 'a'
357
+ end
358
+ end
424
359
 
425
- def test_validates_confirmation_of_finds_custom_model_key_translation
426
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:confirmation => 'custom message'}}}}}}
427
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
360
+ # validates_numericality_of :not_a_number, without :only_integer
428
361
 
429
- Topic.validates_confirmation_of :title
430
- @topic.title_confirmation = 'foo'
431
- @topic.valid?
432
- assert_equal 'custom message', @topic.errors.on(:title)
362
+ test "#validates_numericality_of (:not_a_number, w/o :only_integer) no custom message" do
363
+ expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do
364
+ Topic.validates_numericality_of :title
365
+ @topic.title = 'a'
366
+ end
433
367
  end
434
368
 
435
- def test_validates_confirmation_of_finds_global_default_translation
436
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
437
-
438
- Topic.validates_confirmation_of :title
439
- @topic.title_confirmation = 'foo'
440
- @topic.valid?
441
- assert_equal 'global message', @topic.errors.on(:title)
369
+ test "#validates_numericality_of (:not_a_number, w/o :only_integer) and a custom message" do
370
+ expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do
371
+ Topic.validates_numericality_of :title, :message => 'custom'
372
+ @topic.title = 'a'
373
+ end
442
374
  end
443
375
 
444
- # validates_acceptance_of w/o mocha
376
+ test "#validates_numericality_of (:not_a_number, w/o :only_integer) finds the correct message translations" do
377
+ assert_message_translations(@topic, :title, :not_a_number) do
378
+ Topic.validates_numericality_of :title
379
+ @topic.title = 'a'
380
+ end
381
+ end
445
382
 
446
- def test_validates_acceptance_of_finds_custom_model_key_translation
447
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:accepted => 'custom message'}}}}}}
448
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
383
+ # validates_numericality_of :not_a_number, with :only_integer
449
384
 
450
- Topic.validates_acceptance_of :title, :allow_nil => false
451
- @topic.valid?
452
- assert_equal 'custom message', @topic.errors.on(:title)
385
+ test "#validates_numericality_of (:not_a_number, with :only_integer) no custom message" do
386
+ expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do
387
+ Topic.validates_numericality_of :title, :only_integer => true
388
+ @topic.title = 'a'
389
+ end
453
390
  end
454
391
 
455
- def test_validates_acceptance_of_finds_global_default_translation
456
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
457
-
458
- Topic.validates_acceptance_of :title, :allow_nil => false
459
- @topic.valid?
460
- assert_equal 'global message', @topic.errors.on(:title)
392
+ test "#validates_numericality_of (:not_a_number, with :only_integer) and a custom message" do
393
+ expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do
394
+ Topic.validates_numericality_of :title, :only_integer => true, :message => 'custom'
395
+ @topic.title = 'a'
396
+ end
461
397
  end
462
398
 
463
- # validates_presence_of w/o mocha
399
+ test "#validates_numericality_of (:not_a_number, with :only_integer) finds the correct message translations" do
400
+ assert_message_translations(@topic, :title, :not_a_number) do
401
+ Topic.validates_numericality_of :title, :only_integer => true
402
+ @topic.title = 'a'
403
+ end
404
+ end
464
405
 
465
- def test_validates_presence_of_finds_custom_model_key_translation
466
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:blank => 'custom message'}}}}}}
467
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
406
+ # validates_numericality_of :odd
468
407
 
469
- Topic.validates_presence_of :title
470
- @topic.valid?
471
- assert_equal 'custom message', @topic.errors.on(:title)
408
+ test "#validates_numericality_of (:odd) no custom message" do
409
+ expect_error_added(@topic, :title, :odd, :default => nil, :value => 0) do
410
+ Topic.validates_numericality_of :title, :only_integer => true, :odd => true
411
+ @topic.title = 0
412
+ end
472
413
  end
473
414
 
474
- def test_validates_presence_of_finds_global_default_translation
475
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
476
-
477
- Topic.validates_presence_of :title
478
- @topic.valid?
479
- assert_equal 'global message', @topic.errors.on(:title)
415
+ test "#validates_numericality_of (:odd) and a custom message" do
416
+ expect_error_added(@topic, :title, :odd, :default => 'custom', :value => 0) do
417
+ Topic.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom'
418
+ @topic.title = 0
419
+ end
480
420
  end
481
421
 
482
- # validates_length_of :within w/o mocha
422
+ test "#validates_numericality_of (:odd) finds the correct message translations" do
423
+ assert_message_translations(@topic, :title, :odd) do
424
+ Topic.validates_numericality_of :title, :only_integer => true, :odd => true
425
+ @topic.title = 0
426
+ end
427
+ end
483
428
 
484
- def test_validates_length_of_within_finds_custom_model_key_translation
485
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:too_short => 'custom message'}}}}}}
486
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
429
+ # validates_numericality_of :even
487
430
 
488
- Topic.validates_length_of :title, :within => 3..5
489
- @topic.valid?
490
- assert_equal 'custom message', @topic.errors.on(:title)
431
+ test "#validates_numericality_of (:even) no custom message" do
432
+ expect_error_added(@topic, :title, :even, :default => nil, :value => 1) do
433
+ Topic.validates_numericality_of :title, :only_integer => true, :even => true
434
+ @topic.title = 1
435
+ end
491
436
  end
492
437
 
493
- def test_validates_length_of_within_finds_global_default_translation
494
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
495
-
496
- Topic.validates_length_of :title, :within => 3..5
497
- @topic.valid?
498
- assert_equal 'global message', @topic.errors.on(:title)
438
+ test "#validates_numericality_of (:even) and a custom message" do
439
+ expect_error_added(@topic, :title, :even, :default => 'custom', :value => 1) do
440
+ Topic.validates_numericality_of :title, :only_integer => true, :even => true, :message => 'custom'
441
+ @topic.title = 1
442
+ end
499
443
  end
500
444
 
501
- # validates_length_of :is w/o mocha
445
+ test "#validates_numericality_of (:even) finds the correct message translations" do
446
+ assert_message_translations(@topic, :title, :even) do
447
+ Topic.validates_numericality_of :title, :only_integer => true, :even => true
448
+ @topic.title = 1
449
+ end
450
+ end
502
451
 
503
- def test_validates_length_of_is_finds_custom_model_key_translation
504
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
505
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
452
+ # validates_numericality_of :less_than
506
453
 
507
- Topic.validates_length_of :title, :is => 5
508
- @topic.valid?
509
- assert_equal 'custom message', @topic.errors.on(:title)
454
+ test "#validates_numericality_of (:less_than) no custom message" do
455
+ expect_error_added(@topic, :title, :less_than, :default => nil, :value => 1, :count => 0) do
456
+ Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
457
+ @topic.title = 1
458
+ end
510
459
  end
511
460
 
512
- def test_validates_length_of_is_finds_global_default_translation
513
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
514
-
515
- Topic.validates_length_of :title, :is => 5
516
- @topic.valid?
517
- assert_equal 'global message', @topic.errors.on(:title)
461
+ test "#validates_numericality_of (:less_than) and a custom message" do
462
+ expect_error_added(@topic, :title, :less_than, :default => 'custom', :value => 1, :count => 0) do
463
+ Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom'
464
+ @topic.title = 1
465
+ end
518
466
  end
519
467
 
520
- # validates_uniqueness_of w/o mocha
468
+ test "#validates_numericality_of (:less_than) finds the correct message translations" do
469
+ assert_message_translations(@topic, :title, :less_than) do
470
+ Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
471
+ @topic.title = 1
472
+ end
473
+ end
521
474
 
522
- def test_validates_length_of_is_finds_custom_model_key_translation
523
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
524
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
475
+ # validates_associated
525
476
 
526
- Topic.validates_length_of :title, :is => 5
527
- @topic.valid?
528
- assert_equal 'custom message', @topic.errors.on(:title)
477
+ test "#validates_associated no custom message" do
478
+ expect_error_added(replied_topic, :replies, :invalid, :default => nil, :value => replied_topic.replies) do
479
+ Topic.validates_associated :replies
480
+ end
529
481
  end
530
482
 
531
- def test_validates_length_of_is_finds_global_default_translation
532
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
483
+ test "#validates_associated and a custom message" do
484
+ expect_error_added(replied_topic, :replies, :invalid, :default => 'custom', :value => replied_topic.replies) do
485
+ Topic.validates_associated :replies, :message => 'custom'
486
+ end
487
+ end
533
488
 
534
- Topic.validates_length_of :title, :is => 5
535
- @topic.valid?
536
- assert_equal 'global message', @topic.errors.on(:title)
489
+ test "#validates_associated finds the correct message translations" do
490
+ assert_message_translations(replied_topic, :replies, :invalid) do
491
+ Topic.validates_associated :replies
492
+ end
537
493
  end
494
+ end
538
495
 
539
496
 
540
- # validates_format_of w/o mocha
497
+ # ACTIVERECORD ERROR
498
+ #
499
+ # * test that it passes given interpolation arguments, the human model name and human attribute name
500
+ # * test that it looks messages up with the the correct keys
501
+ # * test that it looks up the correct default messages
541
502
 
542
- def test_validates_format_of_finds_custom_model_key_translation
543
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:invalid => 'custom message'}}}}}}
544
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
503
+ class ActiveRecordErrorI18nTests < ActiveSupport::TestCase
504
+ include ActiveRecordValidationsI18nTestHelper
545
505
 
546
- Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
547
- @topic.valid?
548
- assert_equal 'custom message', @topic.errors.on(:title)
506
+ def setup
507
+ @reply = Reply.new
508
+ @old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
549
509
  end
550
510
 
551
- def test_validates_format_of_finds_global_default_translation
552
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
553
-
554
- Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
555
- @topic.valid?
556
- assert_equal 'global message', @topic.errors.on(:title)
511
+ def teardown
512
+ I18n.backend = @old_backend
513
+ I18n.locale = nil
557
514
  end
558
515
 
559
- # validates_inclusion_of w/o mocha
560
-
561
- def test_validates_inclusion_of_finds_custom_model_key_translation
562
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:inclusion => 'custom message'}}}}}}
563
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
516
+ def assert_error_message(message, *args)
517
+ assert_equal message, ActiveRecord::Error.new(@reply, *args).message
518
+ end
564
519
 
565
- Topic.validates_inclusion_of :title, :in => %w(a b c)
566
- @topic.valid?
567
- assert_equal 'custom message', @topic.errors.on(:title)
520
+ def assert_full_message(message, *args)
521
+ assert_equal message, ActiveRecord::Error.new(@reply, *args).full_message
568
522
  end
569
523
 
570
- def test_validates_inclusion_of_finds_global_default_translation
571
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
524
+ test "#generate_message passes the model attribute value for interpolation" do
525
+ store_translations(:errors => { :messages => { :foo => "You fooed: {{value}}." } })
526
+ @reply.title = "da title"
527
+ assert_error_message 'You fooed: da title.', :title, :foo
528
+ end
572
529
 
573
- Topic.validates_inclusion_of :title, :in => %w(a b c)
574
- @topic.valid?
575
- assert_equal 'global message', @topic.errors.on(:title)
530
+ test "#generate_message passes the human_name of the model for interpolation" do
531
+ store_translations(
532
+ :errors => { :messages => { :foo => "You fooed: {{model}}." } },
533
+ :models => { :topic => 'da topic' }
534
+ )
535
+ assert_error_message 'You fooed: da topic.', :title, :foo
576
536
  end
577
537
 
578
- # validates_exclusion_of w/o mocha
538
+ test "#generate_message passes the human_name of the attribute for interpolation" do
539
+ store_translations(
540
+ :errors => { :messages => { :foo => "You fooed: {{attribute}}." } },
541
+ :attributes => { :topic => { :title => 'da topic title' } }
542
+ )
543
+ assert_error_message 'You fooed: da topic title.', :title, :foo
544
+ end
579
545
 
580
- def test_validates_exclusion_of_finds_custom_model_key_translation
581
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:exclusion => 'custom message'}}}}}}
582
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
546
+ # generate_message will look up the key for the error message (e.g. :blank) in these namespaces:
547
+ #
548
+ # activerecord.errors.models.reply.attributes.title
549
+ # activerecord.errors.models.reply
550
+ # activerecord.errors.models.topic.attributes.title
551
+ # activerecord.errors.models.topic
552
+ # [default from class level :validates_foo statement if this is a String]
553
+ # activerecord.errors.messages
583
554
 
584
- Topic.validates_exclusion_of :title, :in => %w(a b c)
585
- @topic.title = 'a'
586
- @topic.valid?
587
- assert_equal 'custom message', @topic.errors.on(:title)
588
- end
555
+ test "#generate_message key fallbacks (given a String as key)" do
556
+ store_translations(
557
+ :errors => {
558
+ :models => {
559
+ :reply => {
560
+ :attributes => { :title => { :custom => 'activerecord.errors.models.reply.attributes.title.custom' } },
561
+ :custom => 'activerecord.errors.models.reply.custom'
562
+ },
563
+ :topic => {
564
+ :attributes => { :title => { :custom => 'activerecord.errors.models.topic.attributes.title.custom' } },
565
+ :custom => 'activerecord.errors.models.topic.custom'
566
+ }
567
+ },
568
+ :messages => {
569
+ :custom => 'activerecord.errors.messages.custom',
570
+ :kaputt => 'activerecord.errors.messages.kaputt'
571
+ }
572
+ }
573
+ )
589
574
 
590
- def test_validates_exclusion_of_finds_global_default_translation
591
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
575
+ assert_error_message 'activerecord.errors.models.reply.attributes.title.custom', :title, :kaputt, :message => 'custom'
576
+ delete_translation :'activerecord.errors.models.reply.attributes.title.custom'
592
577
 
593
- Topic.validates_exclusion_of :title, :in => %w(a b c)
594
- @topic.title = 'a'
595
- @topic.valid?
596
- assert_equal 'global message', @topic.errors.on(:title)
597
- end
578
+ assert_error_message 'activerecord.errors.models.reply.custom', :title, :kaputt, :message => 'custom'
579
+ delete_translation :'activerecord.errors.models.reply.custom'
598
580
 
599
- # validates_numericality_of without :only_integer w/o mocha
581
+ assert_error_message 'activerecord.errors.models.topic.attributes.title.custom', :title, :kaputt, :message => 'custom'
582
+ delete_translation :'activerecord.errors.models.topic.attributes.title.custom'
600
583
 
601
- def test_validates_numericality_of_finds_custom_model_key_translation
602
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
603
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
584
+ assert_error_message 'activerecord.errors.models.topic.custom', :title, :kaputt, :message => 'custom'
585
+ delete_translation :'activerecord.errors.models.topic.custom'
604
586
 
605
- Topic.validates_numericality_of :title
606
- @topic.title = 'a'
607
- @topic.valid?
608
- assert_equal 'custom message', @topic.errors.on(:title)
609
- end
587
+ assert_error_message 'activerecord.errors.messages.custom', :title, :kaputt, :message => 'custom'
588
+ delete_translation :'activerecord.errors.messages.custom'
610
589
 
611
- def test_validates_numericality_of_finds_global_default_translation
612
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
590
+ # Implementing this would clash with the AR default behaviour of using validates_foo :message => 'foo'
591
+ # as an untranslated string. I.e. at this point we can either fall back to the given string from the
592
+ # class-level macro (validates_*) or fall back to the default message for this validation type.
593
+ # assert_error_message 'activerecord.errors.messages.kaputt', :title, :kaputt, :message => 'custom'
613
594
 
614
- Topic.validates_numericality_of :title, :only_integer => true
615
- @topic.title = 'a'
616
- @topic.valid?
617
- assert_equal 'global message', @topic.errors.on(:title)
595
+ assert_error_message 'custom', :title, :kaputt, :message => 'custom'
618
596
  end
619
597
 
620
- # validates_numericality_of with :only_integer w/o mocha
598
+ test "#generate_message key fallbacks (given a Symbol as key)" do
599
+ store_translations(
600
+ :errors => {
601
+ :models => {
602
+ :reply => {
603
+ :attributes => { :title => { :kaputt => 'activerecord.errors.models.reply.attributes.title.kaputt' } },
604
+ :kaputt => 'activerecord.errors.models.reply.kaputt'
605
+ },
606
+ :topic => {
607
+ :attributes => { :title => { :kaputt => 'activerecord.errors.models.topic.attributes.title.kaputt' } },
608
+ :kaputt => 'activerecord.errors.models.topic.kaputt'
609
+ }
610
+ },
611
+ :messages => {
612
+ :kaputt => 'activerecord.errors.messages.kaputt'
613
+ }
614
+ }
615
+ )
616
+
617
+ assert_error_message 'activerecord.errors.models.reply.attributes.title.kaputt', :title, :kaputt
618
+ delete_translation :'activerecord.errors.models.reply.attributes.title.kaputt'
621
619
 
622
- def test_validates_numericality_of_only_integer_finds_custom_model_key_translation
623
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
624
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
620
+ assert_error_message 'activerecord.errors.models.reply.kaputt', :title, :kaputt
621
+ delete_translation :'activerecord.errors.models.reply.kaputt'
625
622
 
626
- Topic.validates_numericality_of :title, :only_integer => true
627
- @topic.title = 'a'
628
- @topic.valid?
629
- assert_equal 'custom message', @topic.errors.on(:title)
630
- end
623
+ assert_error_message 'activerecord.errors.models.topic.attributes.title.kaputt', :title, :kaputt
624
+ delete_translation :'activerecord.errors.models.topic.attributes.title.kaputt'
631
625
 
632
- def test_validates_numericality_of_only_integer_finds_global_default_translation
633
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
626
+ assert_error_message 'activerecord.errors.models.topic.kaputt', :title, :kaputt
627
+ delete_translation :'activerecord.errors.models.topic.kaputt'
634
628
 
635
- Topic.validates_numericality_of :title, :only_integer => true
636
- @topic.title = 'a'
637
- @topic.valid?
638
- assert_equal 'global message', @topic.errors.on(:title)
629
+ assert_error_message 'activerecord.errors.messages.kaputt', :title, :kaputt
639
630
  end
640
631
 
641
- # validates_numericality_of :odd w/o mocha
632
+ # full_messages
642
633
 
643
- def test_validates_numericality_of_odd_finds_custom_model_key_translation
644
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:odd => 'custom message'}}}}}}
645
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
634
+ test "#full_message with no format present" do
635
+ store_translations(:errors => { :messages => { :kaputt => 'is kaputt' } })
636
+ assert_full_message 'Title is kaputt', :title, :kaputt
637
+ end
646
638
 
647
- Topic.validates_numericality_of :title, :only_integer => true, :odd => true
648
- @topic.title = 0
649
- @topic.valid?
650
- assert_equal 'custom message', @topic.errors.on(:title)
639
+ test "#full_message with a format present" do
640
+ store_translations(:errors => { :messages => { :kaputt => 'is kaputt' }, :full_messages => { :format => '{{attribute}}: {{message}}' } })
641
+ assert_full_message 'Title: is kaputt', :title, :kaputt
651
642
  end
652
643
 
653
- def test_validates_numericality_of_odd_finds_global_default_translation
654
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
644
+ test "#full_message with a type specific format present" do
645
+ store_translations(:errors => { :messages => { :kaputt => 'is kaputt' }, :full_messages => { :kaputt => '{{attribute}} {{message}}!' } })
646
+ assert_full_message 'Title is kaputt!', :title, :kaputt
647
+ end
655
648
 
656
- Topic.validates_numericality_of :title, :only_integer => true, :odd => true
657
- @topic.title = 0
658
- @topic.valid?
659
- assert_equal 'global message', @topic.errors.on(:title)
649
+ test "#full_message with class-level specified custom message" do
650
+ store_translations(:errors => { :messages => { :broken => 'is kaputt' }, :full_messages => { :broken => '{{attribute}} {{message}}?!' } })
651
+ assert_full_message 'Title is kaputt?!', :title, :kaputt, :message => :broken
660
652
  end
661
653
 
662
- # validates_numericality_of :less_than w/o mocha
654
+ # switch locales
663
655
 
664
- def test_validates_numericality_of_less_than_finds_custom_model_key_translation
665
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:less_than => 'custom message'}}}}}}
666
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
656
+ test "#message allows to switch locales" do
657
+ store_translations(:en, :errors => { :messages => { :kaputt => 'is kaputt' } })
658
+ store_translations(:de, :errors => { :messages => { :kaputt => 'ist kaputt' } })
667
659
 
668
- Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
669
- @topic.title = 1
670
- @topic.valid?
671
- assert_equal 'custom message', @topic.errors.on(:title)
660
+ assert_error_message 'is kaputt', :title, :kaputt
661
+ I18n.locale = :de
662
+ assert_error_message 'ist kaputt', :title, :kaputt
663
+ I18n.locale = :en
664
+ assert_error_message 'is kaputt', :title, :kaputt
672
665
  end
673
666
 
674
- def test_validates_numericality_of_less_than_finds_global_default_translation
675
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
667
+ test "#full_message allows to switch locales" do
668
+ store_translations(:en, :errors => { :messages => { :kaputt => 'is kaputt' } }, :attributes => { :topic => { :title => 'The title' } })
669
+ store_translations(:de, :errors => { :messages => { :kaputt => 'ist kaputt' } }, :attributes => { :topic => { :title => 'Der Titel' } })
676
670
 
677
- Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
678
- @topic.title = 1
679
- @topic.valid?
680
- assert_equal 'global message', @topic.errors.on(:title)
671
+ assert_full_message 'The title is kaputt', :title, :kaputt
672
+ I18n.locale = :de
673
+ assert_full_message 'Der Titel ist kaputt', :title, :kaputt
674
+ I18n.locale = :en
675
+ assert_full_message 'The title is kaputt', :title, :kaputt
681
676
  end
677
+ end
682
678
 
679
+ # ACTIVERECORD DEFAULT ERROR MESSAGES
680
+ #
681
+ # * test that Error generates the default error messages
683
682
 
684
- # validates_associated w/o mocha
685
-
686
- def test_validates_associated_finds_custom_model_key_translation
687
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:replies => {:invalid => 'custom message'}}}}}}
688
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
689
-
690
- Topic.validates_associated :replies
691
- replied_topic.valid?
692
- assert_equal 'custom message', replied_topic.errors.on(:replies)
683
+ class ActiveRecordDefaultErrorMessagesI18nTests < ActiveSupport::TestCase
684
+ def assert_default_error_message(message, *args)
685
+ assert_equal message, error_message(*args)
693
686
  end
694
687
 
695
- def test_validates_associated_finds_global_default_translation
696
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
688
+ def error_message(*args)
689
+ ActiveRecord::Error.new(Topic.new, :title, *args).message
690
+ end
697
691
 
698
- Topic.validates_associated :replies
699
- replied_topic.valid?
700
- assert_equal 'global message', replied_topic.errors.on(:replies)
692
+ # used by: validates_inclusion_of
693
+ test "default error message: inclusion" do
694
+ assert_default_error_message 'is not included in the list', :inclusion, :value => 'title'
701
695
  end
702
696
 
703
- def test_validations_with_message_symbol_must_translate
704
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:custom_error => "I am a custom error"}}}
705
- Topic.validates_presence_of :title, :message => :custom_error
706
- @topic.title = nil
707
- @topic.valid?
708
- assert_equal "I am a custom error", @topic.errors.on(:title)
697
+ # used by: validates_exclusion_of
698
+ test "default error message: exclusion" do
699
+ assert_default_error_message 'is reserved', :exclusion, :value => 'title'
709
700
  end
710
701
 
711
- def test_validates_with_message_symbol_must_translate_per_attribute
712
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:custom_error => "I am a custom error"}}}}}}
713
- Topic.validates_presence_of :title, :message => :custom_error
714
- @topic.title = nil
715
- @topic.valid?
716
- assert_equal "I am a custom error", @topic.errors.on(:title)
702
+ # used by: validates_associated and validates_format_of
703
+ test "default error message: invalid" do
704
+ assert_default_error_message 'is invalid', :invalid, :value => 'title'
717
705
  end
718
706
 
719
- def test_validates_with_message_symbol_must_translate_per_model
720
- I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:custom_error => "I am a custom error"}}}}
721
- Topic.validates_presence_of :title, :message => :custom_error
722
- @topic.title = nil
723
- @topic.valid?
724
- assert_equal "I am a custom error", @topic.errors.on(:title)
707
+ # used by: validates_confirmation_of
708
+ test "default error message: confirmation" do
709
+ assert_default_error_message "doesn't match confirmation", :confirmation, :default => nil
725
710
  end
726
711
 
727
- def test_validates_with_message_string
728
- Topic.validates_presence_of :title, :message => "I am a custom error"
729
- @topic.title = nil
730
- @topic.valid?
731
- assert_equal "I am a custom error", @topic.errors.on(:title)
712
+ # used by: validates_acceptance_of
713
+ test "default error message: accepted" do
714
+ assert_default_error_message "must be accepted", :accepted
732
715
  end
733
716
 
734
- end
717
+ # used by: add_on_empty
718
+ test "default error message: empty" do
719
+ assert_default_error_message "can't be empty", :empty
720
+ end
735
721
 
736
- class ActiveRecordValidationsGenerateMessageI18nTests < Test::Unit::TestCase
737
- def setup
738
- reset_callbacks Topic
739
- @topic = Topic.new
740
- I18n.backend.store_translations :'en', {
741
- :activerecord => {
742
- :errors => {
743
- :messages => {
744
- :inclusion => "is not included in the list",
745
- :exclusion => "is reserved",
746
- :invalid => "is invalid",
747
- :confirmation => "doesn't match confirmation",
748
- :accepted => "must be accepted",
749
- :empty => "can't be empty",
750
- :blank => "can't be blank",
751
- :too_long => "is too long (maximum is {{count}} characters)",
752
- :too_short => "is too short (minimum is {{count}} characters)",
753
- :wrong_length => "is the wrong length (should be {{count}} characters)",
754
- :taken => "has already been taken",
755
- :not_a_number => "is not a number",
756
- :greater_than => "must be greater than {{count}}",
757
- :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
758
- :equal_to => "must be equal to {{count}}",
759
- :less_than => "must be less than {{count}}",
760
- :less_than_or_equal_to => "must be less than or equal to {{count}}",
761
- :odd => "must be odd",
762
- :even => "must be even"
763
- }
764
- }
765
- }
766
- }
722
+ # used by: add_on_blank
723
+ test "default error message: blank" do
724
+ assert_default_error_message "can't be blank", :blank
767
725
  end
768
726
 
769
- def reset_callbacks(*models)
770
- models.each do |model|
771
- model.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
772
- model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
773
- model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
774
- end
727
+ # used by: validates_length_of
728
+ test "default error message: too_long" do
729
+ assert_default_error_message "is too long (maximum is 10 characters)", :too_long, :count => 10
775
730
  end
776
731
 
777
- # validates_inclusion_of: generate_message(attr_name, :inclusion, :default => configuration[:message], :value => value)
778
- def test_generate_message_inclusion_with_default_message
779
- assert_equal 'is not included in the list', @topic.errors.generate_message(:title, :inclusion, :default => nil, :value => 'title')
732
+ # used by: validates_length_of
733
+ test "default error message: too_short" do
734
+ assert_default_error_message "is too short (minimum is 10 characters)", :too_short, :count => 10
780
735
  end
781
736
 
782
- def test_generate_message_inclusion_with_custom_message
783
- assert_equal 'custom message title', @topic.errors.generate_message(:title, :inclusion, :default => 'custom message {{value}}', :value => 'title')
737
+ # used by: validates_length_of
738
+ test "default error message: wrong_length" do
739
+ assert_default_error_message "is the wrong length (should be 10 characters)", :wrong_length, :count => 10
784
740
  end
785
741
 
786
- # validates_exclusion_of: generate_message(attr_name, :exclusion, :default => configuration[:message], :value => value)
787
- def test_generate_message_exclusion_with_default_message
788
- assert_equal 'is reserved', @topic.errors.generate_message(:title, :exclusion, :default => nil, :value => 'title')
742
+ # used by: validates_uniqueness_of
743
+ test "default error message: taken" do
744
+ assert_default_error_message "has already been taken", :taken, :value => 'title'
789
745
  end
790
746
 
791
- def test_generate_message_exclusion_with_custom_message
792
- assert_equal 'custom message title', @topic.errors.generate_message(:title, :exclusion, :default => 'custom message {{value}}', :value => 'title')
747
+ # used by: validates_numericality_of
748
+ test "default error message: not_a_number" do
749
+ assert_default_error_message "is not a number", :not_a_number, :value => 'title'
793
750
  end
794
751
 
795
- # validates_associated: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value)
796
- # validates_format_of: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value)
797
- def test_generate_message_invalid_with_default_message
798
- assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :default => nil, :value => 'title')
752
+ # used by: validates_numericality_of
753
+ test "default error message: greater_than" do
754
+ assert_default_error_message "must be greater than 10", :greater_than, :value => 'title', :count => 10
799
755
  end
800
756
 
801
- def test_generate_message_invalid_with_custom_message
802
- assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :default => 'custom message {{value}}', :value => 'title')
757
+ # used by: validates_numericality_of
758
+ test "default error message: greater_than_or_equal_to" do
759
+ assert_default_error_message "must be greater than or equal to 10", :greater_than_or_equal_to, :value => 'title', :count => 10
803
760
  end
804
761
 
805
- # validates_confirmation_of: generate_message(attr_name, :confirmation, :default => configuration[:message])
806
- def test_generate_message_confirmation_with_default_message
807
- assert_equal "doesn't match confirmation", @topic.errors.generate_message(:title, :confirmation, :default => nil)
762
+ # used by: validates_numericality_of
763
+ test "default error message: equal_to" do
764
+ assert_default_error_message "must be equal to 10", :equal_to, :value => 'title', :count => 10
808
765
  end
809
766
 
810
- def test_generate_message_confirmation_with_custom_message
811
- assert_equal 'custom message', @topic.errors.generate_message(:title, :confirmation, :default => 'custom message')
767
+ # used by: validates_numericality_of
768
+ test "default error message: less_than" do
769
+ assert_default_error_message "must be less than 10", :less_than, :value => 'title', :count => 10
812
770
  end
813
771
 
814
- # validates_acceptance_of: generate_message(attr_name, :accepted, :default => configuration[:message])
815
- def test_generate_message_accepted_with_default_message
816
- assert_equal "must be accepted", @topic.errors.generate_message(:title, :accepted, :default => nil)
772
+ # used by: validates_numericality_of
773
+ test "default error message: less_than_or_equal_to" do
774
+ assert_default_error_message "must be less than or equal to 10", :less_than_or_equal_to, :value => 'title', :count => 10
817
775
  end
818
776
 
819
- def test_generate_message_accepted_with_custom_message
820
- assert_equal 'custom message', @topic.errors.generate_message(:title, :accepted, :default => 'custom message')
777
+ # used by: validates_numericality_of
778
+ test "default error message: odd" do
779
+ assert_default_error_message "must be odd", :odd, :value => 'title', :count => 10
821
780
  end
822
781
 
823
- # add_on_empty: generate_message(attr, :empty, :default => custom_message)
824
- def test_generate_message_empty_with_default_message
825
- assert_equal "can't be empty", @topic.errors.generate_message(:title, :empty, :default => nil)
782
+ # used by: validates_numericality_of
783
+ test "default error message: even" do
784
+ assert_default_error_message "must be even", :even, :value => 'title', :count => 10
826
785
  end
827
786
 
828
- def test_generate_message_empty_with_custom_message
829
- assert_equal 'custom message', @topic.errors.generate_message(:title, :empty, :default => 'custom message')
787
+ test "custom message string interpolation" do
788
+ assert_equal 'custom message title', error_message(:invalid, :default => 'custom message {{value}}', :value => 'title')
830
789
  end
790
+ end
791
+
792
+ # ACTIVERECORD VALIDATION ERROR MESSAGES - FULL STACK
793
+ #
794
+ # * test a few combinations full stack to ensure the tests above are correct
831
795
 
832
- # add_on_blank: generate_message(attr, :blank, :default => custom_message)
833
- def test_generate_message_blank_with_default_message
834
- assert_equal "can't be blank", @topic.errors.generate_message(:title, :blank, :default => nil)
796
+ class I18nPerson < Person
797
+ end
798
+
799
+ class ActiveRecordValidationsI18nFullStackTests < ActiveSupport::TestCase
800
+ include ActiveRecordValidationsI18nTestHelper
801
+
802
+ def setup
803
+ reset_callbacks(I18nPerson)
804
+ @old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
805
+ @person = I18nPerson.new
835
806
  end
836
807
 
837
- def test_generate_message_blank_with_custom_message
838
- assert_equal 'custom message', @topic.errors.generate_message(:title, :blank, :default => 'custom message')
808
+ def teardown
809
+ reset_callbacks(I18nPerson)
810
+ I18n.backend = @old_backend
839
811
  end
840
812
 
841
- # validates_length_of: generate_message(attr, :too_long, :default => options[:too_long], :count => option_value.end)
842
- def test_generate_message_too_long_with_default_message
843
- assert_equal "is too long (maximum is 10 characters)", @topic.errors.generate_message(:title, :too_long, :default => nil, :count => 10)
813
+ def assert_name_invalid(message)
814
+ yield
815
+ @person.valid?
816
+ assert_equal message, @person.errors.on(:name)
844
817
  end
845
818
 
846
- def test_generate_message_too_long_with_custom_message
847
- assert_equal 'custom message 10', @topic.errors.generate_message(:title, :too_long, :default => 'custom message {{count}}', :count => 10)
819
+ # Symbols as class-level validation messages
820
+
821
+ test "Symbol as class level validation message translated per attribute (translation on child class)" do
822
+ assert_name_invalid("is broken") do
823
+ store_translations :errors => {:models => {:i18n_person => {:attributes => {:name => {:broken => "is broken"}}}}}
824
+ I18nPerson.validates_presence_of :name, :message => :broken
825
+ end
848
826
  end
849
827
 
850
- # validates_length_of: generate_message(attr, :too_short, :default => options[:too_short], :count => option_value.begin)
851
- def test_generate_message_too_short_with_default_message
852
- assert_equal "is too short (minimum is 10 characters)", @topic.errors.generate_message(:title, :too_short, :default => nil, :count => 10)
828
+ test "Symbol as class level validation message translated per attribute (translation on base class)" do
829
+ assert_name_invalid("is broken") do
830
+ store_translations :errors => {:models => {:person => {:attributes => {:name => {:broken => "is broken"}}}}}
831
+ I18nPerson.validates_presence_of :name, :message => :broken
832
+ end
853
833
  end
854
834
 
855
- def test_generate_message_too_short_with_custom_message
856
- assert_equal 'custom message 10', @topic.errors.generate_message(:title, :too_short, :default => 'custom message {{count}}', :count => 10)
835
+ test "Symbol as class level validation message translated per model (translation on child class)" do
836
+ assert_name_invalid("is broken") do
837
+ store_translations :errors => {:models => {:i18n_person => {:broken => "is broken"}}}
838
+ I18nPerson.validates_presence_of :name, :message => :broken
839
+ end
857
840
  end
858
841
 
859
- # validates_length_of: generate_message(attr, key, :default => custom_message, :count => option_value)
860
- def test_generate_message_wrong_length_with_default_message
861
- assert_equal "is the wrong length (should be 10 characters)", @topic.errors.generate_message(:title, :wrong_length, :default => nil, :count => 10)
842
+ test "Symbol as class level validation message translated per model (translation on base class)" do
843
+ assert_name_invalid("is broken") do
844
+ store_translations :errors => {:models => {:person => {:broken => "is broken"}}}
845
+ I18nPerson.validates_presence_of :name, :message => :broken
846
+ end
862
847
  end
863
848
 
864
- def test_generate_message_wrong_length_with_custom_message
865
- assert_equal 'custom message 10', @topic.errors.generate_message(:title, :wrong_length, :default => 'custom message {{count}}', :count => 10)
849
+ test "Symbol as class level validation message translated as error message" do
850
+ assert_name_invalid("is broken") do
851
+ store_translations :errors => {:messages => {:broken => "is broken"}}
852
+ I18nPerson.validates_presence_of :name, :message => :broken
853
+ end
866
854
  end
867
855
 
868
- # validates_uniqueness_of: generate_message(attr_name, :taken, :default => configuration[:message])
869
- def test_generate_message_taken_with_default_message
870
- assert_equal "has already been taken", @topic.errors.generate_message(:title, :taken, :default => nil, :value => 'title')
856
+ # Strings as class-level validation messages
857
+
858
+ test "String as class level validation message translated per attribute (translation on child class)" do
859
+ assert_name_invalid("is broken") do
860
+ store_translations :errors => {:models => {:i18n_person => {:attributes => {:name => {"is broken" => "is broken"}}}}}
861
+ I18nPerson.validates_presence_of :name, :message => "is broken"
862
+ end
871
863
  end
872
864
 
873
- def test_generate_message_taken_with_custom_message
874
- assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :default => 'custom message {{value}}', :value => 'title')
865
+ test "String as class level validation message translated per attribute (translation on base class)" do
866
+ assert_name_invalid("is broken") do
867
+ store_translations :errors => {:models => {:person => {:attributes => {:name => {"is broken" => "is broken"}}}}}
868
+ I18nPerson.validates_presence_of :name, :message => "is broken"
869
+ end
875
870
  end
876
871
 
877
- # validates_numericality_of: generate_message(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
878
- def test_generate_message_not_a_number_with_default_message
879
- assert_equal "is not a number", @topic.errors.generate_message(:title, :not_a_number, :default => nil, :value => 'title')
872
+ test "String as class level validation message translated per model (translation on child class)" do
873
+ assert_name_invalid("is broken") do
874
+ store_translations :errors => {:models => {:i18n_person => {"is broken" => "is broken"}}}
875
+ I18nPerson.validates_presence_of :name, :message => "is broken"
876
+ end
880
877
  end
881
878
 
882
- def test_generate_message_not_a_number_with_custom_message
883
- assert_equal 'custom message title', @topic.errors.generate_message(:title, :not_a_number, :default => 'custom message {{value}}', :value => 'title')
879
+ test "String as class level validation message translated per model (translation on base class)" do
880
+ assert_name_invalid("is broken") do
881
+ store_translations :errors => {:models => {:person => {"is broken" => "is broken"}}}
882
+ I18nPerson.validates_presence_of :name, :message => "is broken"
883
+ end
884
884
  end
885
885
 
886
- # validates_numericality_of: generate_message(attr_name, option, :value => raw_value, :default => configuration[:message])
887
- def test_generate_message_greater_than_with_default_message
888
- assert_equal "must be greater than 10", @topic.errors.generate_message(:title, :greater_than, :default => nil, :value => 'title', :count => 10)
886
+ test "String as class level validation message translated as error message" do
887
+ assert_name_invalid("is broken") do
888
+ store_translations :errors => {:messages => {"is broken" => "is broken"}}
889
+ I18nPerson.validates_presence_of :name, :message => "is broken"
890
+ end
889
891
  end
890
892
 
891
- def test_generate_message_greater_than_or_equal_to_with_default_message
892
- assert_equal "must be greater than or equal to 10", @topic.errors.generate_message(:title, :greater_than_or_equal_to, :default => nil, :value => 'title', :count => 10)
893
+ test "String as class level validation message not translated (uses message as default)" do
894
+ assert_name_invalid("is broken!") do
895
+ I18nPerson.validates_presence_of :name, :message => "is broken!"
896
+ end
893
897
  end
898
+ end
899
+
900
+ class ActiveRecordValidationsI18nFullMessagesFullStackTests < ActiveSupport::TestCase
901
+ include ActiveRecordValidationsI18nTestHelper
894
902
 
895
- def test_generate_message_equal_to_with_default_message
896
- assert_equal "must be equal to 10", @topic.errors.generate_message(:title, :equal_to, :default => nil, :value => 'title', :count => 10)
903
+ def setup
904
+ reset_callbacks(I18nPerson)
905
+ @old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
906
+ @person = I18nPerson.new
897
907
  end
898
908
 
899
- def test_generate_message_less_than_with_default_message
900
- assert_equal "must be less than 10", @topic.errors.generate_message(:title, :less_than, :default => nil, :value => 'title', :count => 10)
909
+ def teardown
910
+ reset_callbacks(I18nPerson)
911
+ I18n.backend = @old_backend
901
912
  end
902
913
 
903
- def test_generate_message_less_than_or_equal_to_with_default_message
904
- assert_equal "must be less than or equal to 10", @topic.errors.generate_message(:title, :less_than_or_equal_to, :default => nil, :value => 'title', :count => 10)
914
+ def assert_full_message(message)
915
+ yield
916
+ @person.valid?
917
+ assert_equal message, @person.errors.full_messages.join
905
918
  end
906
919
 
907
- def test_generate_message_odd_with_default_message
908
- assert_equal "must be odd", @topic.errors.generate_message(:title, :odd, :default => nil, :value => 'title', :count => 10)
920
+ test "full_message format stored per custom error message key" do
921
+ assert_full_message("Name is broken!") do
922
+ store_translations :errors => { :messages => { :broken => 'is broken' }, :full_messages => { :broken => '{{attribute}} {{message}}!' } }
923
+ I18nPerson.validates_presence_of :name, :message => :broken
924
+ end
909
925
  end
910
926
 
911
- def test_generate_message_even_with_default_message
912
- assert_equal "must be even", @topic.errors.generate_message(:title, :even, :default => nil, :value => 'title', :count => 10)
927
+ test "full_message format stored per error type" do
928
+ assert_full_message("Name can't be blank!") do
929
+ store_translations :errors => { :full_messages => { :blank => '{{attribute}} {{message}}!' } }
930
+ I18nPerson.validates_presence_of :name
931
+ end
913
932
  end
933
+ # ActiveRecord#RecordInvalid exception
914
934
 
935
+ test "full_message format stored as default" do
936
+ assert_full_message("Name: can't be blank") do
937
+ store_translations :errors => { :full_messages => { :format => '{{attribute}}: {{message}}' } }
938
+ I18nPerson.validates_presence_of :name
939
+ end
940
+ end
941
+ test "RecordInvalid exception can be localized" do
942
+ topic = Topic.new
943
+ topic.errors.add(:title, :invalid)
944
+ topic.errors.add(:title, :blank)
945
+ assert_equal "Validation failed: Title is invalid, Title can't be blank", ActiveRecord::RecordInvalid.new(topic).message
946
+ end
915
947
  end