factorylabs-castronaut 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (789) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.textile +67 -0
  3. data/Rakefile +78 -0
  4. data/bin/castronaut +75 -0
  5. data/config/castronaut.example.yml +41 -0
  6. data/config/castronaut.sample.yml +40 -0
  7. data/config/castronaut.yml +40 -0
  8. data/config/nginx_vhost.conf +17 -0
  9. data/config/thin_config.yml +13 -0
  10. data/lib/castronaut.rb +50 -0
  11. data/lib/castronaut/adapters.rb +13 -0
  12. data/lib/castronaut/adapters/development/adapter.rb +13 -0
  13. data/lib/castronaut/adapters/development/user.rb +25 -0
  14. data/lib/castronaut/adapters/ldap/adapter.rb +15 -0
  15. data/lib/castronaut/adapters/ldap/user.rb +40 -0
  16. data/lib/castronaut/adapters/restful_authentication/adapter.rb +15 -0
  17. data/lib/castronaut/adapters/restful_authentication/user.rb +50 -0
  18. data/lib/castronaut/application.rb +1 -0
  19. data/lib/castronaut/application/application.rb +70 -0
  20. data/lib/castronaut/application/public/javascripts/application.js +3 -0
  21. data/lib/castronaut/application/public/javascripts/jquery.js +32 -0
  22. data/lib/castronaut/application/public/stylesheets/screen.css +122 -0
  23. data/lib/castronaut/application/views/layout.erb +27 -0
  24. data/lib/castronaut/application/views/login.erb +31 -0
  25. data/lib/castronaut/application/views/logout.erb +13 -0
  26. data/lib/castronaut/application/views/proxy_validate.erb +21 -0
  27. data/lib/castronaut/application/views/service_validate.erb +14 -0
  28. data/lib/castronaut/authentication_result.rb +24 -0
  29. data/lib/castronaut/configuration.rb +110 -0
  30. data/lib/castronaut/db/001_create_cas_database.rb +47 -0
  31. data/lib/castronaut/models/consumeable.rb +18 -0
  32. data/lib/castronaut/models/dispenser.rb +14 -0
  33. data/lib/castronaut/models/login_ticket.rb +53 -0
  34. data/lib/castronaut/models/proxy_granting_ticket.rb +70 -0
  35. data/lib/castronaut/models/proxy_ticket.rb +43 -0
  36. data/lib/castronaut/models/service_ticket.rb +91 -0
  37. data/lib/castronaut/models/ticket_granting_ticket.rb +52 -0
  38. data/lib/castronaut/presenters/login.rb +84 -0
  39. data/lib/castronaut/presenters/logout.rb +56 -0
  40. data/lib/castronaut/presenters/process_login.rb +149 -0
  41. data/lib/castronaut/presenters/proxy_validate.rb +67 -0
  42. data/lib/castronaut/presenters/service_validate.rb +68 -0
  43. data/lib/castronaut/support/sample.rb +21 -0
  44. data/lib/castronaut/ticket_result.rb +27 -0
  45. data/lib/castronaut/utilities/random_string.rb +24 -0
  46. data/spec/app/controllers/application_spec.rb +86 -0
  47. data/spec/castronaut/adapters/development/adapter_spec.rb +14 -0
  48. data/spec/castronaut/adapters/development/user_spec.rb +55 -0
  49. data/spec/castronaut/adapters/ldap/adapter_spec.rb +14 -0
  50. data/spec/castronaut/adapters/ldap/user_spec.rb +25 -0
  51. data/spec/castronaut/adapters/restful_authentication/adapter_spec.rb +14 -0
  52. data/spec/castronaut/adapters/restful_authentication/user_spec.rb +108 -0
  53. data/spec/castronaut/adapters_spec.rb +13 -0
  54. data/spec/castronaut/authentication_result_spec.rb +20 -0
  55. data/spec/castronaut/configuration_spec.rb +172 -0
  56. data/spec/castronaut/models/consumeable_spec.rb +39 -0
  57. data/spec/castronaut/models/dispenser_spec.rb +30 -0
  58. data/spec/castronaut/models/login_ticket_spec.rb +107 -0
  59. data/spec/castronaut/models/proxy_granting_ticket_spec.rb +302 -0
  60. data/spec/castronaut/models/proxy_ticket_spec.rb +109 -0
  61. data/spec/castronaut/models/service_ticket_spec.rb +269 -0
  62. data/spec/castronaut/models/ticket_granting_ticket_spec.rb +89 -0
  63. data/spec/castronaut/presenters/login_spec.rb +152 -0
  64. data/spec/castronaut/presenters/logout_spec.rb +85 -0
  65. data/spec/castronaut/presenters/process_login_spec.rb +300 -0
  66. data/spec/castronaut/presenters/proxy_validate_spec.rb +103 -0
  67. data/spec/castronaut/presenters/service_validate_spec.rb +86 -0
  68. data/spec/castronaut/ticket_result_spec.rb +42 -0
  69. data/spec/castronaut/utilities/random_string_spec.rb +14 -0
  70. data/spec/castronaut_spec.rb +26 -0
  71. data/spec/spec_controller_helper.rb +17 -0
  72. data/spec/spec_helper.rb +39 -0
  73. data/spec/spec_rails_mocks.rb +132 -0
  74. data/vendor/activerecord/CHANGELOG +5786 -0
  75. data/vendor/activerecord/README +351 -0
  76. data/vendor/activerecord/RUNNING_UNIT_TESTS +36 -0
  77. data/vendor/activerecord/Rakefile +247 -0
  78. data/vendor/activerecord/examples/associations.png +0 -0
  79. data/vendor/activerecord/install.rb +30 -0
  80. data/vendor/activerecord/lib/active_record.rb +81 -0
  81. data/vendor/activerecord/lib/active_record/aggregations.rb +261 -0
  82. data/vendor/activerecord/lib/active_record/association_preload.rb +374 -0
  83. data/vendor/activerecord/lib/active_record/associations.rb +2227 -0
  84. data/vendor/activerecord/lib/active_record/associations/association_collection.rb +453 -0
  85. data/vendor/activerecord/lib/active_record/associations/association_proxy.rb +272 -0
  86. data/vendor/activerecord/lib/active_record/associations/belongs_to_association.rb +58 -0
  87. data/vendor/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +49 -0
  88. data/vendor/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +121 -0
  89. data/vendor/activerecord/lib/active_record/associations/has_many_association.rb +121 -0
  90. data/vendor/activerecord/lib/active_record/associations/has_many_through_association.rb +256 -0
  91. data/vendor/activerecord/lib/active_record/associations/has_one_association.rb +115 -0
  92. data/vendor/activerecord/lib/active_record/associations/has_one_through_association.rb +31 -0
  93. data/vendor/activerecord/lib/active_record/attribute_methods.rb +387 -0
  94. data/vendor/activerecord/lib/active_record/base.rb +2967 -0
  95. data/vendor/activerecord/lib/active_record/calculations.rb +299 -0
  96. data/vendor/activerecord/lib/active_record/callbacks.rb +331 -0
  97. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +355 -0
  98. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +136 -0
  99. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +201 -0
  100. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +94 -0
  101. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +69 -0
  102. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +705 -0
  103. data/vendor/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +434 -0
  104. data/vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +210 -0
  105. data/vendor/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +585 -0
  106. data/vendor/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +1065 -0
  107. data/vendor/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
  108. data/vendor/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +418 -0
  109. data/vendor/activerecord/lib/active_record/dirty.rb +183 -0
  110. data/vendor/activerecord/lib/active_record/dynamic_finder_match.rb +41 -0
  111. data/vendor/activerecord/lib/active_record/fixtures.rb +998 -0
  112. data/vendor/activerecord/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
  113. data/vendor/activerecord/lib/active_record/locale/en.yml +54 -0
  114. data/vendor/activerecord/lib/active_record/locking/optimistic.rb +148 -0
  115. data/vendor/activerecord/lib/active_record/locking/pessimistic.rb +77 -0
  116. data/vendor/activerecord/lib/active_record/migration.rb +560 -0
  117. data/vendor/activerecord/lib/active_record/named_scope.rb +181 -0
  118. data/vendor/activerecord/lib/active_record/observer.rb +197 -0
  119. data/vendor/activerecord/lib/active_record/query_cache.rb +21 -0
  120. data/vendor/activerecord/lib/active_record/reflection.rb +307 -0
  121. data/vendor/activerecord/lib/active_record/schema.rb +51 -0
  122. data/vendor/activerecord/lib/active_record/schema_dumper.rb +177 -0
  123. data/vendor/activerecord/lib/active_record/serialization.rb +98 -0
  124. data/vendor/activerecord/lib/active_record/serializers/json_serializer.rb +80 -0
  125. data/vendor/activerecord/lib/active_record/serializers/xml_serializer.rb +338 -0
  126. data/vendor/activerecord/lib/active_record/test_case.rb +60 -0
  127. data/vendor/activerecord/lib/active_record/timestamp.rb +41 -0
  128. data/vendor/activerecord/lib/active_record/transactions.rb +185 -0
  129. data/vendor/activerecord/lib/active_record/validations.rb +1061 -0
  130. data/vendor/activerecord/lib/active_record/version.rb +9 -0
  131. data/vendor/activerecord/lib/activerecord.rb +1 -0
  132. data/vendor/activerecord/test/assets/example.log +1 -0
  133. data/vendor/activerecord/test/assets/flowers.jpg +0 -0
  134. data/vendor/activerecord/test/cases/aaa_create_tables_test.rb +24 -0
  135. data/vendor/activerecord/test/cases/active_schema_test_mysql.rb +100 -0
  136. data/vendor/activerecord/test/cases/active_schema_test_postgresql.rb +24 -0
  137. data/vendor/activerecord/test/cases/adapter_test.rb +133 -0
  138. data/vendor/activerecord/test/cases/aggregations_test.rb +167 -0
  139. data/vendor/activerecord/test/cases/ar_schema_test.rb +33 -0
  140. data/vendor/activerecord/test/cases/associations/belongs_to_associations_test.rb +441 -0
  141. data/vendor/activerecord/test/cases/associations/callbacks_test.rb +161 -0
  142. data/vendor/activerecord/test/cases/associations/cascaded_eager_loading_test.rb +123 -0
  143. data/vendor/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb +36 -0
  144. data/vendor/activerecord/test/cases/associations/eager_load_nested_include_test.rb +101 -0
  145. data/vendor/activerecord/test/cases/associations/eager_singularization_test.rb +145 -0
  146. data/vendor/activerecord/test/cases/associations/eager_test.rb +692 -0
  147. data/vendor/activerecord/test/cases/associations/extension_test.rb +62 -0
  148. data/vendor/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +773 -0
  149. data/vendor/activerecord/test/cases/associations/has_many_associations_test.rb +1101 -0
  150. data/vendor/activerecord/test/cases/associations/has_many_through_associations_test.rb +247 -0
  151. data/vendor/activerecord/test/cases/associations/has_one_associations_test.rb +362 -0
  152. data/vendor/activerecord/test/cases/associations/has_one_through_associations_test.rb +161 -0
  153. data/vendor/activerecord/test/cases/associations/inner_join_association_test.rb +88 -0
  154. data/vendor/activerecord/test/cases/associations/join_model_test.rb +714 -0
  155. data/vendor/activerecord/test/cases/associations_test.rb +262 -0
  156. data/vendor/activerecord/test/cases/attribute_methods_test.rb +293 -0
  157. data/vendor/activerecord/test/cases/base_test.rb +2087 -0
  158. data/vendor/activerecord/test/cases/binary_test.rb +30 -0
  159. data/vendor/activerecord/test/cases/calculations_test.rb +328 -0
  160. data/vendor/activerecord/test/cases/callbacks_observers_test.rb +38 -0
  161. data/vendor/activerecord/test/cases/callbacks_test.rb +400 -0
  162. data/vendor/activerecord/test/cases/class_inheritable_attributes_test.rb +32 -0
  163. data/vendor/activerecord/test/cases/column_alias_test.rb +17 -0
  164. data/vendor/activerecord/test/cases/column_definition_test.rb +36 -0
  165. data/vendor/activerecord/test/cases/connection_test_firebird.rb +8 -0
  166. data/vendor/activerecord/test/cases/connection_test_mysql.rb +30 -0
  167. data/vendor/activerecord/test/cases/copy_table_test_sqlite.rb +69 -0
  168. data/vendor/activerecord/test/cases/database_statements_test.rb +12 -0
  169. data/vendor/activerecord/test/cases/datatype_test_postgresql.rb +203 -0
  170. data/vendor/activerecord/test/cases/date_time_test.rb +37 -0
  171. data/vendor/activerecord/test/cases/default_test_firebird.rb +16 -0
  172. data/vendor/activerecord/test/cases/defaults_test.rb +100 -0
  173. data/vendor/activerecord/test/cases/deprecated_finder_test.rb +30 -0
  174. data/vendor/activerecord/test/cases/dirty_test.rb +270 -0
  175. data/vendor/activerecord/test/cases/finder_respond_to_test.rb +76 -0
  176. data/vendor/activerecord/test/cases/finder_test.rb +1048 -0
  177. data/vendor/activerecord/test/cases/fixtures_test.rb +655 -0
  178. data/vendor/activerecord/test/cases/helper.rb +62 -0
  179. data/vendor/activerecord/test/cases/i18n_test.rb +41 -0
  180. data/vendor/activerecord/test/cases/inheritance_test.rb +262 -0
  181. data/vendor/activerecord/test/cases/invalid_date_test.rb +24 -0
  182. data/vendor/activerecord/test/cases/json_serialization_test.rb +205 -0
  183. data/vendor/activerecord/test/cases/lifecycle_test.rb +193 -0
  184. data/vendor/activerecord/test/cases/locking_test.rb +304 -0
  185. data/vendor/activerecord/test/cases/method_scoping_test.rb +569 -0
  186. data/vendor/activerecord/test/cases/migration_test.rb +1479 -0
  187. data/vendor/activerecord/test/cases/migration_test_firebird.rb +124 -0
  188. data/vendor/activerecord/test/cases/mixin_test.rb +96 -0
  189. data/vendor/activerecord/test/cases/modules_test.rb +39 -0
  190. data/vendor/activerecord/test/cases/multiple_db_test.rb +85 -0
  191. data/vendor/activerecord/test/cases/named_scope_test.rb +280 -0
  192. data/vendor/activerecord/test/cases/pk_test.rb +101 -0
  193. data/vendor/activerecord/test/cases/pooled_connections_test.rb +103 -0
  194. data/vendor/activerecord/test/cases/query_cache_test.rb +127 -0
  195. data/vendor/activerecord/test/cases/readonly_test.rb +107 -0
  196. data/vendor/activerecord/test/cases/reflection_test.rb +184 -0
  197. data/vendor/activerecord/test/cases/reload_models_test.rb +20 -0
  198. data/vendor/activerecord/test/cases/reserved_word_test_mysql.rb +176 -0
  199. data/vendor/activerecord/test/cases/sanitize_test.rb +25 -0
  200. data/vendor/activerecord/test/cases/schema_authorization_test_postgresql.rb +75 -0
  201. data/vendor/activerecord/test/cases/schema_dumper_test.rb +184 -0
  202. data/vendor/activerecord/test/cases/schema_test_postgresql.rb +102 -0
  203. data/vendor/activerecord/test/cases/serialization_test.rb +47 -0
  204. data/vendor/activerecord/test/cases/synonym_test_oracle.rb +17 -0
  205. data/vendor/activerecord/test/cases/transactions_test.rb +357 -0
  206. data/vendor/activerecord/test/cases/unconnected_test.rb +32 -0
  207. data/vendor/activerecord/test/cases/validations_i18n_test.rb +921 -0
  208. data/vendor/activerecord/test/cases/validations_test.rb +1552 -0
  209. data/vendor/activerecord/test/cases/xml_serialization_test.rb +202 -0
  210. data/vendor/activerecord/test/config.rb +5 -0
  211. data/vendor/activerecord/test/connections/native_db2/connection.rb +25 -0
  212. data/vendor/activerecord/test/connections/native_firebird/connection.rb +26 -0
  213. data/vendor/activerecord/test/connections/native_frontbase/connection.rb +27 -0
  214. data/vendor/activerecord/test/connections/native_mysql/connection.rb +25 -0
  215. data/vendor/activerecord/test/connections/native_openbase/connection.rb +21 -0
  216. data/vendor/activerecord/test/connections/native_oracle/connection.rb +27 -0
  217. data/vendor/activerecord/test/connections/native_postgresql/connection.rb +21 -0
  218. data/vendor/activerecord/test/connections/native_sqlite/connection.rb +25 -0
  219. data/vendor/activerecord/test/connections/native_sqlite3/connection.rb +25 -0
  220. data/vendor/activerecord/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
  221. data/vendor/activerecord/test/connections/native_sybase/connection.rb +23 -0
  222. data/vendor/activerecord/test/fixtures/accounts.yml +28 -0
  223. data/vendor/activerecord/test/fixtures/all/developers.yml +0 -0
  224. data/vendor/activerecord/test/fixtures/all/people.csv +0 -0
  225. data/vendor/activerecord/test/fixtures/all/tasks.yml +0 -0
  226. data/vendor/activerecord/test/fixtures/author_addresses.yml +5 -0
  227. data/vendor/activerecord/test/fixtures/author_favorites.yml +4 -0
  228. data/vendor/activerecord/test/fixtures/authors.yml +9 -0
  229. data/vendor/activerecord/test/fixtures/binaries.yml +132 -0
  230. data/vendor/activerecord/test/fixtures/books.yml +7 -0
  231. data/vendor/activerecord/test/fixtures/categories.yml +14 -0
  232. data/vendor/activerecord/test/fixtures/categories/special_categories.yml +9 -0
  233. data/vendor/activerecord/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
  234. data/vendor/activerecord/test/fixtures/categories_ordered.yml +7 -0
  235. data/vendor/activerecord/test/fixtures/categories_posts.yml +23 -0
  236. data/vendor/activerecord/test/fixtures/categorizations.yml +17 -0
  237. data/vendor/activerecord/test/fixtures/clubs.yml +6 -0
  238. data/vendor/activerecord/test/fixtures/comments.yml +59 -0
  239. data/vendor/activerecord/test/fixtures/companies.yml +56 -0
  240. data/vendor/activerecord/test/fixtures/computers.yml +4 -0
  241. data/vendor/activerecord/test/fixtures/courses.yml +7 -0
  242. data/vendor/activerecord/test/fixtures/customers.yml +26 -0
  243. data/vendor/activerecord/test/fixtures/developers.yml +21 -0
  244. data/vendor/activerecord/test/fixtures/developers_projects.yml +17 -0
  245. data/vendor/activerecord/test/fixtures/edges.yml +6 -0
  246. data/vendor/activerecord/test/fixtures/entrants.yml +14 -0
  247. data/vendor/activerecord/test/fixtures/fixture_database.sqlite3 +0 -0
  248. data/vendor/activerecord/test/fixtures/fixture_database_2.sqlite3 +0 -0
  249. data/vendor/activerecord/test/fixtures/fk_test_has_fk.yml +3 -0
  250. data/vendor/activerecord/test/fixtures/fk_test_has_pk.yml +2 -0
  251. data/vendor/activerecord/test/fixtures/funny_jokes.yml +10 -0
  252. data/vendor/activerecord/test/fixtures/items.yml +4 -0
  253. data/vendor/activerecord/test/fixtures/jobs.yml +7 -0
  254. data/vendor/activerecord/test/fixtures/legacy_things.yml +3 -0
  255. data/vendor/activerecord/test/fixtures/mateys.yml +4 -0
  256. data/vendor/activerecord/test/fixtures/members.yml +4 -0
  257. data/vendor/activerecord/test/fixtures/memberships.yml +20 -0
  258. data/vendor/activerecord/test/fixtures/minimalistics.yml +2 -0
  259. data/vendor/activerecord/test/fixtures/mixed_case_monkeys.yml +6 -0
  260. data/vendor/activerecord/test/fixtures/mixins.yml +29 -0
  261. data/vendor/activerecord/test/fixtures/movies.yml +7 -0
  262. data/vendor/activerecord/test/fixtures/naked/csv/accounts.csv +1 -0
  263. data/vendor/activerecord/test/fixtures/naked/yml/accounts.yml +1 -0
  264. data/vendor/activerecord/test/fixtures/naked/yml/companies.yml +1 -0
  265. data/vendor/activerecord/test/fixtures/naked/yml/courses.yml +1 -0
  266. data/vendor/activerecord/test/fixtures/organizations.yml +5 -0
  267. data/vendor/activerecord/test/fixtures/owners.yml +7 -0
  268. data/vendor/activerecord/test/fixtures/parrots.yml +27 -0
  269. data/vendor/activerecord/test/fixtures/parrots_pirates.yml +7 -0
  270. data/vendor/activerecord/test/fixtures/people.yml +6 -0
  271. data/vendor/activerecord/test/fixtures/pets.yml +14 -0
  272. data/vendor/activerecord/test/fixtures/pirates.yml +9 -0
  273. data/vendor/activerecord/test/fixtures/posts.yml +49 -0
  274. data/vendor/activerecord/test/fixtures/price_estimates.yml +7 -0
  275. data/vendor/activerecord/test/fixtures/projects.yml +7 -0
  276. data/vendor/activerecord/test/fixtures/readers.yml +9 -0
  277. data/vendor/activerecord/test/fixtures/references.yml +17 -0
  278. data/vendor/activerecord/test/fixtures/reserved_words/distinct.yml +5 -0
  279. data/vendor/activerecord/test/fixtures/reserved_words/distincts_selects.yml +11 -0
  280. data/vendor/activerecord/test/fixtures/reserved_words/group.yml +14 -0
  281. data/vendor/activerecord/test/fixtures/reserved_words/select.yml +8 -0
  282. data/vendor/activerecord/test/fixtures/reserved_words/values.yml +7 -0
  283. data/vendor/activerecord/test/fixtures/ships.yml +5 -0
  284. data/vendor/activerecord/test/fixtures/sponsors.yml +9 -0
  285. data/vendor/activerecord/test/fixtures/subscribers.yml +7 -0
  286. data/vendor/activerecord/test/fixtures/subscriptions.yml +12 -0
  287. data/vendor/activerecord/test/fixtures/taggings.yml +28 -0
  288. data/vendor/activerecord/test/fixtures/tags.yml +7 -0
  289. data/vendor/activerecord/test/fixtures/tasks.yml +7 -0
  290. data/vendor/activerecord/test/fixtures/topics.yml +42 -0
  291. data/vendor/activerecord/test/fixtures/treasures.yml +10 -0
  292. data/vendor/activerecord/test/fixtures/vertices.yml +4 -0
  293. data/vendor/activerecord/test/fixtures/warehouse-things.yml +3 -0
  294. data/vendor/activerecord/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
  295. data/vendor/activerecord/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
  296. data/vendor/activerecord/test/migrations/duplicate/1_people_have_last_names.rb +9 -0
  297. data/vendor/activerecord/test/migrations/duplicate/2_we_need_reminders.rb +12 -0
  298. data/vendor/activerecord/test/migrations/duplicate/3_foo.rb +7 -0
  299. data/vendor/activerecord/test/migrations/duplicate/3_innocent_jointable.rb +12 -0
  300. data/vendor/activerecord/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
  301. data/vendor/activerecord/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
  302. data/vendor/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +12 -0
  303. data/vendor/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +9 -0
  304. data/vendor/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +12 -0
  305. data/vendor/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +9 -0
  306. data/vendor/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
  307. data/vendor/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
  308. data/vendor/activerecord/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
  309. data/vendor/activerecord/test/migrations/missing/1_people_have_last_names.rb +9 -0
  310. data/vendor/activerecord/test/migrations/missing/3_we_need_reminders.rb +12 -0
  311. data/vendor/activerecord/test/migrations/missing/4_innocent_jointable.rb +12 -0
  312. data/vendor/activerecord/test/migrations/valid/1_people_have_last_names.rb +9 -0
  313. data/vendor/activerecord/test/migrations/valid/2_we_need_reminders.rb +12 -0
  314. data/vendor/activerecord/test/migrations/valid/3_innocent_jointable.rb +12 -0
  315. data/vendor/activerecord/test/models/author.rb +140 -0
  316. data/vendor/activerecord/test/models/auto_id.rb +4 -0
  317. data/vendor/activerecord/test/models/binary.rb +2 -0
  318. data/vendor/activerecord/test/models/book.rb +4 -0
  319. data/vendor/activerecord/test/models/categorization.rb +5 -0
  320. data/vendor/activerecord/test/models/category.rb +33 -0
  321. data/vendor/activerecord/test/models/citation.rb +6 -0
  322. data/vendor/activerecord/test/models/club.rb +13 -0
  323. data/vendor/activerecord/test/models/column_name.rb +3 -0
  324. data/vendor/activerecord/test/models/comment.rb +25 -0
  325. data/vendor/activerecord/test/models/company.rb +156 -0
  326. data/vendor/activerecord/test/models/company_in_module.rb +61 -0
  327. data/vendor/activerecord/test/models/computer.rb +3 -0
  328. data/vendor/activerecord/test/models/contact.rb +16 -0
  329. data/vendor/activerecord/test/models/course.rb +3 -0
  330. data/vendor/activerecord/test/models/customer.rb +73 -0
  331. data/vendor/activerecord/test/models/default.rb +2 -0
  332. data/vendor/activerecord/test/models/developer.rb +79 -0
  333. data/vendor/activerecord/test/models/edge.rb +5 -0
  334. data/vendor/activerecord/test/models/entrant.rb +3 -0
  335. data/vendor/activerecord/test/models/guid.rb +2 -0
  336. data/vendor/activerecord/test/models/item.rb +7 -0
  337. data/vendor/activerecord/test/models/job.rb +5 -0
  338. data/vendor/activerecord/test/models/joke.rb +3 -0
  339. data/vendor/activerecord/test/models/keyboard.rb +3 -0
  340. data/vendor/activerecord/test/models/legacy_thing.rb +3 -0
  341. data/vendor/activerecord/test/models/matey.rb +4 -0
  342. data/vendor/activerecord/test/models/member.rb +11 -0
  343. data/vendor/activerecord/test/models/member_detail.rb +4 -0
  344. data/vendor/activerecord/test/models/membership.rb +9 -0
  345. data/vendor/activerecord/test/models/minimalistic.rb +2 -0
  346. data/vendor/activerecord/test/models/mixed_case_monkey.rb +3 -0
  347. data/vendor/activerecord/test/models/movie.rb +5 -0
  348. data/vendor/activerecord/test/models/order.rb +4 -0
  349. data/vendor/activerecord/test/models/organization.rb +4 -0
  350. data/vendor/activerecord/test/models/owner.rb +4 -0
  351. data/vendor/activerecord/test/models/parrot.rb +14 -0
  352. data/vendor/activerecord/test/models/person.rb +10 -0
  353. data/vendor/activerecord/test/models/pet.rb +4 -0
  354. data/vendor/activerecord/test/models/pirate.rb +9 -0
  355. data/vendor/activerecord/test/models/post.rb +88 -0
  356. data/vendor/activerecord/test/models/price_estimate.rb +3 -0
  357. data/vendor/activerecord/test/models/project.rb +29 -0
  358. data/vendor/activerecord/test/models/reader.rb +4 -0
  359. data/vendor/activerecord/test/models/reference.rb +4 -0
  360. data/vendor/activerecord/test/models/reply.rb +39 -0
  361. data/vendor/activerecord/test/models/ship.rb +3 -0
  362. data/vendor/activerecord/test/models/sponsor.rb +4 -0
  363. data/vendor/activerecord/test/models/subject.rb +4 -0
  364. data/vendor/activerecord/test/models/subscriber.rb +8 -0
  365. data/vendor/activerecord/test/models/subscription.rb +4 -0
  366. data/vendor/activerecord/test/models/tag.rb +7 -0
  367. data/vendor/activerecord/test/models/tagging.rb +10 -0
  368. data/vendor/activerecord/test/models/task.rb +3 -0
  369. data/vendor/activerecord/test/models/topic.rb +69 -0
  370. data/vendor/activerecord/test/models/treasure.rb +6 -0
  371. data/vendor/activerecord/test/models/vertex.rb +9 -0
  372. data/vendor/activerecord/test/models/warehouse_thing.rb +5 -0
  373. data/vendor/activerecord/test/schema/mysql_specific_schema.rb +12 -0
  374. data/vendor/activerecord/test/schema/postgresql_specific_schema.rb +103 -0
  375. data/vendor/activerecord/test/schema/schema.rb +440 -0
  376. data/vendor/activerecord/test/schema/schema2.rb +6 -0
  377. data/vendor/activerecord/test/schema/sqlite_specific_schema.rb +25 -0
  378. data/vendor/activesupport/CHANGELOG +1257 -0
  379. data/vendor/activesupport/README +43 -0
  380. data/vendor/activesupport/lib/active_support.rb +61 -0
  381. data/vendor/activesupport/lib/active_support/base64.rb +33 -0
  382. data/vendor/activesupport/lib/active_support/basic_object.rb +24 -0
  383. data/vendor/activesupport/lib/active_support/buffered_logger.rb +122 -0
  384. data/vendor/activesupport/lib/active_support/cache.rb +223 -0
  385. data/vendor/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
  386. data/vendor/activesupport/lib/active_support/cache/drb_store.rb +15 -0
  387. data/vendor/activesupport/lib/active_support/cache/file_store.rb +72 -0
  388. data/vendor/activesupport/lib/active_support/cache/mem_cache_store.rb +127 -0
  389. data/vendor/activesupport/lib/active_support/cache/memory_store.rb +52 -0
  390. data/vendor/activesupport/lib/active_support/cache/synchronized_memory_store.rb +47 -0
  391. data/vendor/activesupport/lib/active_support/callbacks.rb +280 -0
  392. data/vendor/activesupport/lib/active_support/core_ext.rb +4 -0
  393. data/vendor/activesupport/lib/active_support/core_ext/array.rb +13 -0
  394. data/vendor/activesupport/lib/active_support/core_ext/array/access.rb +53 -0
  395. data/vendor/activesupport/lib/active_support/core_ext/array/conversions.rb +183 -0
  396. data/vendor/activesupport/lib/active_support/core_ext/array/extract_options.rb +20 -0
  397. data/vendor/activesupport/lib/active_support/core_ext/array/grouping.rb +106 -0
  398. data/vendor/activesupport/lib/active_support/core_ext/array/random_access.rb +12 -0
  399. data/vendor/activesupport/lib/active_support/core_ext/base64.rb +4 -0
  400. data/vendor/activesupport/lib/active_support/core_ext/base64/encoding.rb +16 -0
  401. data/vendor/activesupport/lib/active_support/core_ext/benchmark.rb +12 -0
  402. data/vendor/activesupport/lib/active_support/core_ext/bigdecimal.rb +6 -0
  403. data/vendor/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb +37 -0
  404. data/vendor/activesupport/lib/active_support/core_ext/blank.rb +58 -0
  405. data/vendor/activesupport/lib/active_support/core_ext/cgi.rb +5 -0
  406. data/vendor/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
  407. data/vendor/activesupport/lib/active_support/core_ext/class.rb +4 -0
  408. data/vendor/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +54 -0
  409. data/vendor/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb +46 -0
  410. data/vendor/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
  411. data/vendor/activesupport/lib/active_support/core_ext/class/removal.rb +50 -0
  412. data/vendor/activesupport/lib/active_support/core_ext/date.rb +10 -0
  413. data/vendor/activesupport/lib/active_support/core_ext/date/behavior.rb +42 -0
  414. data/vendor/activesupport/lib/active_support/core_ext/date/calculations.rb +230 -0
  415. data/vendor/activesupport/lib/active_support/core_ext/date/conversions.rb +107 -0
  416. data/vendor/activesupport/lib/active_support/core_ext/date_time.rb +12 -0
  417. data/vendor/activesupport/lib/active_support/core_ext/date_time/calculations.rb +126 -0
  418. data/vendor/activesupport/lib/active_support/core_ext/date_time/conversions.rb +96 -0
  419. data/vendor/activesupport/lib/active_support/core_ext/duplicable.rb +43 -0
  420. data/vendor/activesupport/lib/active_support/core_ext/enumerable.rb +107 -0
  421. data/vendor/activesupport/lib/active_support/core_ext/exception.rb +41 -0
  422. data/vendor/activesupport/lib/active_support/core_ext/file.rb +5 -0
  423. data/vendor/activesupport/lib/active_support/core_ext/file/atomic.rb +46 -0
  424. data/vendor/activesupport/lib/active_support/core_ext/float.rb +7 -0
  425. data/vendor/activesupport/lib/active_support/core_ext/float/rounding.rb +24 -0
  426. data/vendor/activesupport/lib/active_support/core_ext/float/time.rb +27 -0
  427. data/vendor/activesupport/lib/active_support/core_ext/hash.rb +14 -0
  428. data/vendor/activesupport/lib/active_support/core_ext/hash/conversions.rb +259 -0
  429. data/vendor/activesupport/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
  430. data/vendor/activesupport/lib/active_support/core_ext/hash/diff.rb +19 -0
  431. data/vendor/activesupport/lib/active_support/core_ext/hash/except.rb +25 -0
  432. data/vendor/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
  433. data/vendor/activesupport/lib/active_support/core_ext/hash/keys.rb +52 -0
  434. data/vendor/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
  435. data/vendor/activesupport/lib/active_support/core_ext/hash/slice.rb +33 -0
  436. data/vendor/activesupport/lib/active_support/core_ext/integer.rb +9 -0
  437. data/vendor/activesupport/lib/active_support/core_ext/integer/even_odd.rb +29 -0
  438. data/vendor/activesupport/lib/active_support/core_ext/integer/inflections.rb +20 -0
  439. data/vendor/activesupport/lib/active_support/core_ext/integer/time.rb +45 -0
  440. data/vendor/activesupport/lib/active_support/core_ext/kernel.rb +5 -0
  441. data/vendor/activesupport/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
  442. data/vendor/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb +7 -0
  443. data/vendor/activesupport/lib/active_support/core_ext/kernel/debugger.rb +13 -0
  444. data/vendor/activesupport/lib/active_support/core_ext/kernel/reporting.rb +59 -0
  445. data/vendor/activesupport/lib/active_support/core_ext/kernel/requires.rb +24 -0
  446. data/vendor/activesupport/lib/active_support/core_ext/load_error.rb +38 -0
  447. data/vendor/activesupport/lib/active_support/core_ext/logger.rb +143 -0
  448. data/vendor/activesupport/lib/active_support/core_ext/module.rb +23 -0
  449. data/vendor/activesupport/lib/active_support/core_ext/module/aliasing.rb +74 -0
  450. data/vendor/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
  451. data/vendor/activesupport/lib/active_support/core_ext/module/attr_internal.rb +32 -0
  452. data/vendor/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +58 -0
  453. data/vendor/activesupport/lib/active_support/core_ext/module/delegation.rb +95 -0
  454. data/vendor/activesupport/lib/active_support/core_ext/module/inclusion.rb +30 -0
  455. data/vendor/activesupport/lib/active_support/core_ext/module/introspection.rb +90 -0
  456. data/vendor/activesupport/lib/active_support/core_ext/module/loading.rb +23 -0
  457. data/vendor/activesupport/lib/active_support/core_ext/module/model_naming.rb +23 -0
  458. data/vendor/activesupport/lib/active_support/core_ext/module/synchronization.rb +39 -0
  459. data/vendor/activesupport/lib/active_support/core_ext/name_error.rb +17 -0
  460. data/vendor/activesupport/lib/active_support/core_ext/numeric.rb +9 -0
  461. data/vendor/activesupport/lib/active_support/core_ext/numeric/bytes.rb +44 -0
  462. data/vendor/activesupport/lib/active_support/core_ext/numeric/conversions.rb +19 -0
  463. data/vendor/activesupport/lib/active_support/core_ext/numeric/time.rb +81 -0
  464. data/vendor/activesupport/lib/active_support/core_ext/object.rb +5 -0
  465. data/vendor/activesupport/lib/active_support/core_ext/object/conversions.rb +14 -0
  466. data/vendor/activesupport/lib/active_support/core_ext/object/extending.rb +80 -0
  467. data/vendor/activesupport/lib/active_support/core_ext/object/instance_variables.rb +74 -0
  468. data/vendor/activesupport/lib/active_support/core_ext/object/metaclass.rb +13 -0
  469. data/vendor/activesupport/lib/active_support/core_ext/object/misc.rb +74 -0
  470. data/vendor/activesupport/lib/active_support/core_ext/pathname.rb +7 -0
  471. data/vendor/activesupport/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
  472. data/vendor/activesupport/lib/active_support/core_ext/proc.rb +12 -0
  473. data/vendor/activesupport/lib/active_support/core_ext/process.rb +1 -0
  474. data/vendor/activesupport/lib/active_support/core_ext/process/daemon.rb +25 -0
  475. data/vendor/activesupport/lib/active_support/core_ext/range.rb +11 -0
  476. data/vendor/activesupport/lib/active_support/core_ext/range/blockless_step.rb +32 -0
  477. data/vendor/activesupport/lib/active_support/core_ext/range/conversions.rb +27 -0
  478. data/vendor/activesupport/lib/active_support/core_ext/range/include_range.rb +30 -0
  479. data/vendor/activesupport/lib/active_support/core_ext/range/overlaps.rb +15 -0
  480. data/vendor/activesupport/lib/active_support/core_ext/rexml.rb +36 -0
  481. data/vendor/activesupport/lib/active_support/core_ext/string.rb +22 -0
  482. data/vendor/activesupport/lib/active_support/core_ext/string/access.rb +82 -0
  483. data/vendor/activesupport/lib/active_support/core_ext/string/behavior.rb +13 -0
  484. data/vendor/activesupport/lib/active_support/core_ext/string/conversions.rb +28 -0
  485. data/vendor/activesupport/lib/active_support/core_ext/string/filters.rb +26 -0
  486. data/vendor/activesupport/lib/active_support/core_ext/string/inflections.rb +167 -0
  487. data/vendor/activesupport/lib/active_support/core_ext/string/iterators.rb +21 -0
  488. data/vendor/activesupport/lib/active_support/core_ext/string/multibyte.rb +81 -0
  489. data/vendor/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb +35 -0
  490. data/vendor/activesupport/lib/active_support/core_ext/string/xchar.rb +11 -0
  491. data/vendor/activesupport/lib/active_support/core_ext/symbol.rb +14 -0
  492. data/vendor/activesupport/lib/active_support/core_ext/time.rb +42 -0
  493. data/vendor/activesupport/lib/active_support/core_ext/time/behavior.rb +13 -0
  494. data/vendor/activesupport/lib/active_support/core_ext/time/calculations.rb +303 -0
  495. data/vendor/activesupport/lib/active_support/core_ext/time/conversions.rb +90 -0
  496. data/vendor/activesupport/lib/active_support/core_ext/time/zones.rb +86 -0
  497. data/vendor/activesupport/lib/active_support/dependencies.rb +621 -0
  498. data/vendor/activesupport/lib/active_support/deprecation.rb +243 -0
  499. data/vendor/activesupport/lib/active_support/duration.rb +96 -0
  500. data/vendor/activesupport/lib/active_support/gzip.rb +25 -0
  501. data/vendor/activesupport/lib/active_support/inflections.rb +55 -0
  502. data/vendor/activesupport/lib/active_support/inflector.rb +397 -0
  503. data/vendor/activesupport/lib/active_support/json.rb +23 -0
  504. data/vendor/activesupport/lib/active_support/json/decoding.rb +63 -0
  505. data/vendor/activesupport/lib/active_support/json/encoders/date.rb +21 -0
  506. data/vendor/activesupport/lib/active_support/json/encoders/date_time.rb +21 -0
  507. data/vendor/activesupport/lib/active_support/json/encoders/enumerable.rb +12 -0
  508. data/vendor/activesupport/lib/active_support/json/encoders/false_class.rb +5 -0
  509. data/vendor/activesupport/lib/active_support/json/encoders/hash.rb +47 -0
  510. data/vendor/activesupport/lib/active_support/json/encoders/nil_class.rb +5 -0
  511. data/vendor/activesupport/lib/active_support/json/encoders/numeric.rb +5 -0
  512. data/vendor/activesupport/lib/active_support/json/encoders/object.rb +6 -0
  513. data/vendor/activesupport/lib/active_support/json/encoders/regexp.rb +5 -0
  514. data/vendor/activesupport/lib/active_support/json/encoders/string.rb +36 -0
  515. data/vendor/activesupport/lib/active_support/json/encoders/symbol.rb +5 -0
  516. data/vendor/activesupport/lib/active_support/json/encoders/time.rb +21 -0
  517. data/vendor/activesupport/lib/active_support/json/encoders/true_class.rb +5 -0
  518. data/vendor/activesupport/lib/active_support/json/encoding.rb +37 -0
  519. data/vendor/activesupport/lib/active_support/json/variable.rb +10 -0
  520. data/vendor/activesupport/lib/active_support/locale/en.yml +32 -0
  521. data/vendor/activesupport/lib/active_support/memoizable.rb +82 -0
  522. data/vendor/activesupport/lib/active_support/multibyte.rb +33 -0
  523. data/vendor/activesupport/lib/active_support/multibyte/chars.rb +679 -0
  524. data/vendor/activesupport/lib/active_support/multibyte/exceptions.rb +8 -0
  525. data/vendor/activesupport/lib/active_support/multibyte/unicode_database.rb +71 -0
  526. data/vendor/activesupport/lib/active_support/option_merger.rb +17 -0
  527. data/vendor/activesupport/lib/active_support/ordered_hash.rb +58 -0
  528. data/vendor/activesupport/lib/active_support/ordered_options.rb +19 -0
  529. data/vendor/activesupport/lib/active_support/rescuable.rb +108 -0
  530. data/vendor/activesupport/lib/active_support/secure_random.rb +197 -0
  531. data/vendor/activesupport/lib/active_support/string_inquirer.rb +21 -0
  532. data/vendor/activesupport/lib/active_support/test_case.rb +24 -0
  533. data/vendor/activesupport/lib/active_support/testing/core_ext/test.rb +6 -0
  534. data/vendor/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb +72 -0
  535. data/vendor/activesupport/lib/active_support/testing/default.rb +9 -0
  536. data/vendor/activesupport/lib/active_support/testing/performance.rb +452 -0
  537. data/vendor/activesupport/lib/active_support/testing/setup_and_teardown.rb +120 -0
  538. data/vendor/activesupport/lib/active_support/time_with_zone.rb +328 -0
  539. data/vendor/activesupport/lib/active_support/values/time_zone.rb +403 -0
  540. data/vendor/activesupport/lib/active_support/values/unicode_tables.dat +0 -0
  541. data/vendor/activesupport/lib/active_support/vendor.rb +34 -0
  542. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  543. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  544. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  545. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  546. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  547. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  548. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  549. data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  550. data/vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb +194 -0
  551. data/vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +216 -0
  552. data/vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb +53 -0
  553. data/vendor/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb +849 -0
  554. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +33 -0
  555. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +47 -0
  556. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +228 -0
  557. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +55 -0
  558. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +219 -0
  559. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +40 -0
  560. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +18 -0
  561. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
  562. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +22 -0
  563. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +23 -0
  564. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
  565. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
  566. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +23 -0
  567. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +23 -0
  568. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +283 -0
  569. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +136 -0
  570. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +204 -0
  571. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +161 -0
  572. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +27 -0
  573. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +274 -0
  574. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
  575. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +194 -0
  576. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +22 -0
  577. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +35 -0
  578. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +232 -0
  579. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +139 -0
  580. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +144 -0
  581. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +131 -0
  582. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +282 -0
  583. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +30 -0
  584. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +74 -0
  585. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +205 -0
  586. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +171 -0
  587. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +288 -0
  588. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +196 -0
  589. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +67 -0
  590. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +73 -0
  591. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +161 -0
  592. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +20 -0
  593. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +33 -0
  594. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +30 -0
  595. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +27 -0
  596. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
  597. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
  598. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +30 -0
  599. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
  600. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +20 -0
  601. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
  602. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +30 -0
  603. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +20 -0
  604. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +25 -0
  605. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
  606. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
  607. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +18 -0
  608. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +163 -0
  609. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +18 -0
  610. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
  611. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +24 -0
  612. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +18 -0
  613. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +34 -0
  614. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +35 -0
  615. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +33 -0
  616. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +59 -0
  617. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +47 -0
  618. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
  619. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +121 -0
  620. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +30 -0
  621. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
  622. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +33 -0
  623. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
  624. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
  625. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
  626. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +165 -0
  627. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +270 -0
  628. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
  629. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
  630. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +187 -0
  631. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +35 -0
  632. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +29 -0
  633. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +193 -0
  634. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +185 -0
  635. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +37 -0
  636. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +185 -0
  637. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +16 -0
  638. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
  639. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +185 -0
  640. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +163 -0
  641. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +188 -0
  642. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +13 -0
  643. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +232 -0
  644. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +181 -0
  645. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +197 -0
  646. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
  647. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +276 -0
  648. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +163 -0
  649. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +218 -0
  650. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +168 -0
  651. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +268 -0
  652. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
  653. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +288 -0
  654. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +211 -0
  655. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +170 -0
  656. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +181 -0
  657. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +232 -0
  658. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +187 -0
  659. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +176 -0
  660. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +215 -0
  661. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
  662. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +13 -0
  663. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +173 -0
  664. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +165 -0
  665. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +172 -0
  666. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +183 -0
  667. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +170 -0
  668. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +212 -0
  669. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +13 -0
  670. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +202 -0
  671. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +23 -0
  672. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +22 -0
  673. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
  674. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +20 -0
  675. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +25 -0
  676. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +25 -0
  677. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
  678. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
  679. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
  680. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +52 -0
  681. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +51 -0
  682. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +44 -0
  683. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +98 -0
  684. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +56 -0
  685. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +292 -0
  686. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +508 -0
  687. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +56 -0
  688. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +40 -0
  689. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +94 -0
  690. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +198 -0
  691. data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +129 -0
  692. data/vendor/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  693. data/vendor/activesupport/lib/active_support/version.rb +9 -0
  694. data/vendor/activesupport/lib/active_support/whiny_nil.rb +58 -0
  695. data/vendor/activesupport/lib/activesupport.rb +1 -0
  696. data/vendor/isaac/LICENSE +26 -0
  697. data/vendor/isaac/README +78 -0
  698. data/vendor/isaac/TODO +3 -0
  699. data/vendor/isaac/VERSIONS +3 -0
  700. data/vendor/isaac/crypt/ISAAC.rb +171 -0
  701. data/vendor/isaac/isaac.gemspec +39 -0
  702. data/vendor/isaac/setup.rb +596 -0
  703. data/vendor/isaac/test/TC_ISAAC.rb +76 -0
  704. data/vendor/json/CHANGES +93 -0
  705. data/vendor/json/GPL +340 -0
  706. data/vendor/json/README +78 -0
  707. data/vendor/json/RUBY +58 -0
  708. data/vendor/json/Rakefile +309 -0
  709. data/vendor/json/TODO +1 -0
  710. data/vendor/json/VERSION +1 -0
  711. data/vendor/json/benchmarks/benchmark.txt +133 -0
  712. data/vendor/json/benchmarks/benchmark_generator.rb +48 -0
  713. data/vendor/json/benchmarks/benchmark_parser.rb +26 -0
  714. data/vendor/json/benchmarks/benchmark_rails.rb +26 -0
  715. data/vendor/json/bin/edit_json.rb +10 -0
  716. data/vendor/json/bin/prettify_json.rb +76 -0
  717. data/vendor/json/data/example.json +1 -0
  718. data/vendor/json/data/index.html +38 -0
  719. data/vendor/json/data/prototype.js +4184 -0
  720. data/vendor/json/ext/json/ext/generator/extconf.rb +9 -0
  721. data/vendor/json/ext/json/ext/generator/generator.c +875 -0
  722. data/vendor/json/ext/json/ext/generator/unicode.c +182 -0
  723. data/vendor/json/ext/json/ext/generator/unicode.h +53 -0
  724. data/vendor/json/ext/json/ext/parser/extconf.rb +9 -0
  725. data/vendor/json/ext/json/ext/parser/parser.c +1758 -0
  726. data/vendor/json/ext/json/ext/parser/parser.rl +638 -0
  727. data/vendor/json/ext/json/ext/parser/unicode.c +154 -0
  728. data/vendor/json/ext/json/ext/parser/unicode.h +58 -0
  729. data/vendor/json/install.rb +26 -0
  730. data/vendor/json/lib/json.rb +235 -0
  731. data/vendor/json/lib/json/Array.xpm +21 -0
  732. data/vendor/json/lib/json/FalseClass.xpm +21 -0
  733. data/vendor/json/lib/json/Hash.xpm +21 -0
  734. data/vendor/json/lib/json/Key.xpm +73 -0
  735. data/vendor/json/lib/json/NilClass.xpm +21 -0
  736. data/vendor/json/lib/json/Numeric.xpm +28 -0
  737. data/vendor/json/lib/json/String.xpm +96 -0
  738. data/vendor/json/lib/json/TrueClass.xpm +21 -0
  739. data/vendor/json/lib/json/add/core.rb +135 -0
  740. data/vendor/json/lib/json/add/rails.rb +58 -0
  741. data/vendor/json/lib/json/common.rb +354 -0
  742. data/vendor/json/lib/json/editor.rb +1362 -0
  743. data/vendor/json/lib/json/ext.rb +13 -0
  744. data/vendor/json/lib/json/json.xpm +1499 -0
  745. data/vendor/json/lib/json/pure.rb +75 -0
  746. data/vendor/json/lib/json/pure/generator.rb +394 -0
  747. data/vendor/json/lib/json/pure/parser.rb +259 -0
  748. data/vendor/json/lib/json/version.rb +9 -0
  749. data/vendor/json/tests/fixtures/fail1.json +1 -0
  750. data/vendor/json/tests/fixtures/fail10.json +1 -0
  751. data/vendor/json/tests/fixtures/fail11.json +1 -0
  752. data/vendor/json/tests/fixtures/fail12.json +1 -0
  753. data/vendor/json/tests/fixtures/fail13.json +1 -0
  754. data/vendor/json/tests/fixtures/fail14.json +1 -0
  755. data/vendor/json/tests/fixtures/fail18.json +1 -0
  756. data/vendor/json/tests/fixtures/fail19.json +1 -0
  757. data/vendor/json/tests/fixtures/fail2.json +1 -0
  758. data/vendor/json/tests/fixtures/fail20.json +1 -0
  759. data/vendor/json/tests/fixtures/fail21.json +1 -0
  760. data/vendor/json/tests/fixtures/fail22.json +1 -0
  761. data/vendor/json/tests/fixtures/fail23.json +1 -0
  762. data/vendor/json/tests/fixtures/fail24.json +1 -0
  763. data/vendor/json/tests/fixtures/fail25.json +1 -0
  764. data/vendor/json/tests/fixtures/fail27.json +2 -0
  765. data/vendor/json/tests/fixtures/fail28.json +2 -0
  766. data/vendor/json/tests/fixtures/fail3.json +1 -0
  767. data/vendor/json/tests/fixtures/fail4.json +1 -0
  768. data/vendor/json/tests/fixtures/fail5.json +1 -0
  769. data/vendor/json/tests/fixtures/fail6.json +1 -0
  770. data/vendor/json/tests/fixtures/fail7.json +1 -0
  771. data/vendor/json/tests/fixtures/fail8.json +1 -0
  772. data/vendor/json/tests/fixtures/fail9.json +1 -0
  773. data/vendor/json/tests/fixtures/pass1.json +56 -0
  774. data/vendor/json/tests/fixtures/pass15.json +1 -0
  775. data/vendor/json/tests/fixtures/pass16.json +1 -0
  776. data/vendor/json/tests/fixtures/pass17.json +1 -0
  777. data/vendor/json/tests/fixtures/pass2.json +1 -0
  778. data/vendor/json/tests/fixtures/pass26.json +1 -0
  779. data/vendor/json/tests/fixtures/pass3.json +6 -0
  780. data/vendor/json/tests/runner.rb +25 -0
  781. data/vendor/json/tests/test_json.rb +293 -0
  782. data/vendor/json/tests/test_json_addition.rb +161 -0
  783. data/vendor/json/tests/test_json_fixtures.rb +30 -0
  784. data/vendor/json/tests/test_json_generate.rb +100 -0
  785. data/vendor/json/tests/test_json_rails.rb +118 -0
  786. data/vendor/json/tests/test_json_unicode.rb +61 -0
  787. data/vendor/json/tools/fuzz.rb +140 -0
  788. data/vendor/json/tools/server.rb +62 -0
  789. metadata +841 -0
@@ -0,0 +1,60 @@
1
+ require "active_support/test_case"
2
+
3
+ module ActiveRecord
4
+ class TestCase < ActiveSupport::TestCase #:nodoc:
5
+ self.fixture_path = FIXTURES_ROOT
6
+ self.use_instantiated_fixtures = false
7
+ self.use_transactional_fixtures = true
8
+
9
+ def create_fixtures(*table_names, &block)
10
+ Fixtures.create_fixtures(FIXTURES_ROOT, table_names, {}, &block)
11
+ end
12
+
13
+ def assert_date_from_db(expected, actual, message = nil)
14
+ # SybaseAdapter doesn't have a separate column type just for dates,
15
+ # so the time is in the string and incorrectly formatted
16
+ if current_adapter?(:SybaseAdapter)
17
+ assert_equal expected.to_s, actual.to_date.to_s, message
18
+ else
19
+ assert_equal expected.to_s, actual.to_s, message
20
+ end
21
+ end
22
+
23
+ def assert_sql(*patterns_to_match)
24
+ $queries_executed = []
25
+ yield
26
+ ensure
27
+ failed_patterns = []
28
+ patterns_to_match.each do |pattern|
29
+ failed_patterns << pattern unless $queries_executed.any?{ |sql| pattern === sql }
30
+ end
31
+ assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found."
32
+ end
33
+
34
+ def assert_queries(num = 1)
35
+ $queries_executed = []
36
+ yield
37
+ ensure
38
+ assert_equal num, $queries_executed.size, "#{$queries_executed.size} instead of #{num} queries were executed.#{$queries_executed.size == 0 ? '' : "\nQueries:\n#{$queries_executed.join("\n")}"}"
39
+ end
40
+
41
+ def assert_no_queries(&block)
42
+ assert_queries(0, &block)
43
+ end
44
+
45
+ def self.use_concurrent_connections
46
+ setup :connection_allow_concurrency_setup
47
+ teardown :connection_allow_concurrency_teardown
48
+ end
49
+
50
+ def connection_allow_concurrency_setup
51
+ @connection = ActiveRecord::Base.remove_connection
52
+ ActiveRecord::Base.establish_connection(@connection.merge({:allow_concurrency => true}))
53
+ end
54
+
55
+ def connection_allow_concurrency_teardown
56
+ ActiveRecord::Base.clear_all_connections!
57
+ ActiveRecord::Base.establish_connection(@connection)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,41 @@
1
+ module ActiveRecord
2
+ # Active Record automatically timestamps create and update operations if the table has fields
3
+ # named created_at/created_on or updated_at/updated_on.
4
+ #
5
+ # Timestamping can be turned off by setting
6
+ # <tt>ActiveRecord::Base.record_timestamps = false</tt>
7
+ #
8
+ # Timestamps are in the local timezone by default but you can use UTC by setting
9
+ # <tt>ActiveRecord::Base.default_timezone = :utc</tt>
10
+ module Timestamp
11
+ def self.included(base) #:nodoc:
12
+ base.alias_method_chain :create, :timestamps
13
+ base.alias_method_chain :update, :timestamps
14
+
15
+ base.class_inheritable_accessor :record_timestamps, :instance_writer => false
16
+ base.record_timestamps = true
17
+ end
18
+
19
+ private
20
+ def create_with_timestamps #:nodoc:
21
+ if record_timestamps
22
+ t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
23
+ write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil?
24
+ write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil?
25
+
26
+ write_attribute('updated_at', t) if respond_to?(:updated_at)
27
+ write_attribute('updated_on', t) if respond_to?(:updated_on)
28
+ end
29
+ create_without_timestamps
30
+ end
31
+
32
+ def update_with_timestamps(*args) #:nodoc:
33
+ if record_timestamps && (!partial_updates? || changed?)
34
+ t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
35
+ write_attribute('updated_at', t) if respond_to?(:updated_at)
36
+ write_attribute('updated_on', t) if respond_to?(:updated_on)
37
+ end
38
+ update_without_timestamps(*args)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,185 @@
1
+ require 'thread'
2
+
3
+ module ActiveRecord
4
+ # See ActiveRecord::Transactions::ClassMethods for documentation.
5
+ module Transactions
6
+ class TransactionError < ActiveRecordError # :nodoc:
7
+ end
8
+
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+
12
+ base.class_eval do
13
+ [:destroy, :save, :save!].each do |method|
14
+ alias_method_chain method, :transactions
15
+ end
16
+ end
17
+ end
18
+
19
+ # Transactions are protective blocks where SQL statements are only permanent
20
+ # if they can all succeed as one atomic action. The classic example is a
21
+ # transfer between two accounts where you can only have a deposit if the
22
+ # withdrawal succeeded and vice versa. Transactions enforce the integrity of
23
+ # the database and guard the data against program errors or database
24
+ # break-downs. So basically you should use transaction blocks whenever you
25
+ # have a number of statements that must be executed together or not at all.
26
+ # Example:
27
+ #
28
+ # ActiveRecord::Base.transaction do
29
+ # david.withdrawal(100)
30
+ # mary.deposit(100)
31
+ # end
32
+ #
33
+ # This example will only take money from David and give to Mary if neither
34
+ # +withdrawal+ nor +deposit+ raises an exception. Exceptions will force a
35
+ # ROLLBACK that returns the database to the state before the transaction was
36
+ # begun. Be aware, though, that the objects will _not_ have their instance
37
+ # data returned to their pre-transactional state.
38
+ #
39
+ # == Different Active Record classes in a single transaction
40
+ #
41
+ # Though the transaction class method is called on some Active Record class,
42
+ # the objects within the transaction block need not all be instances of
43
+ # that class. This is because transactions are per-database connection, not
44
+ # per-model.
45
+ #
46
+ # In this example a <tt>Balance</tt> record is transactionally saved even
47
+ # though <tt>transaction</tt> is called on the <tt>Account</tt> class:
48
+ #
49
+ # Account.transaction do
50
+ # balance.save!
51
+ # account.save!
52
+ # end
53
+ #
54
+ # Note that the +transaction+ method is also available as a model instance
55
+ # method. For example, you can also do this:
56
+ #
57
+ # balance.transaction do
58
+ # balance.save!
59
+ # account.save!
60
+ # end
61
+ #
62
+ # == Transactions are not distributed across database connections
63
+ #
64
+ # A transaction acts on a single database connection. If you have
65
+ # multiple class-specific databases, the transaction will not protect
66
+ # interaction among them. One workaround is to begin a transaction
67
+ # on each class whose models you alter:
68
+ #
69
+ # Student.transaction do
70
+ # Course.transaction do
71
+ # course.enroll(student)
72
+ # student.units += course.units
73
+ # end
74
+ # end
75
+ #
76
+ # This is a poor solution, but full distributed transactions are beyond
77
+ # the scope of Active Record.
78
+ #
79
+ # == Save and destroy are automatically wrapped in a transaction
80
+ #
81
+ # Both Base#save and Base#destroy come wrapped in a transaction that ensures
82
+ # that whatever you do in validations or callbacks will happen under the
83
+ # protected cover of a transaction. So you can use validations to check for
84
+ # values that the transaction depends on or you can raise exceptions in the
85
+ # callbacks to rollback, including <tt>after_*</tt> callbacks.
86
+ #
87
+ # == Exception handling and rolling back
88
+ #
89
+ # Also have in mind that exceptions thrown within a transaction block will
90
+ # be propagated (after triggering the ROLLBACK), so you should be ready to
91
+ # catch those in your application code.
92
+ #
93
+ # One exception is the ActiveRecord::Rollback exception, which will trigger
94
+ # a ROLLBACK when raised, but not be re-raised by the transaction block.
95
+ #
96
+ # *Warning*: one should not catch ActiveRecord::StatementInvalid exceptions
97
+ # inside a transaction block. StatementInvalid exceptions indicate that an
98
+ # error occurred at the database level, for example when a unique constraint
99
+ # is violated. On some database systems, such as PostgreSQL, database errors
100
+ # inside a transaction causes the entire transaction to become unusable
101
+ # until it's restarted from the beginning. Here is an example which
102
+ # demonstrates the problem:
103
+ #
104
+ # # Suppose that we have a Number model with a unique column called 'i'.
105
+ # Number.transaction do
106
+ # Number.create(:i => 0)
107
+ # begin
108
+ # # This will raise a unique constraint error...
109
+ # Number.create(:i => 0)
110
+ # rescue ActiveRecord::StatementInvalid
111
+ # # ...which we ignore.
112
+ # end
113
+ #
114
+ # # On PostgreSQL, the transaction is now unusable. The following
115
+ # # statement will cause a PostgreSQL error, even though the unique
116
+ # # constraint is no longer violated:
117
+ # Number.create(:i => 1)
118
+ # # => "PGError: ERROR: current transaction is aborted, commands
119
+ # # ignored until end of transaction block"
120
+ # end
121
+ #
122
+ # One should restart the entire transaction if a StatementError occurred.
123
+ module ClassMethods
124
+ # See ActiveRecord::Transactions::ClassMethods for detailed documentation.
125
+ def transaction(&block)
126
+ connection.increment_open_transactions
127
+
128
+ begin
129
+ connection.transaction(connection.open_transactions == 1, &block)
130
+ ensure
131
+ connection.decrement_open_transactions
132
+ end
133
+ end
134
+ end
135
+
136
+ # See ActiveRecord::Transactions::ClassMethods for detailed documentation.
137
+ def transaction(&block)
138
+ self.class.transaction(&block)
139
+ end
140
+
141
+ def destroy_with_transactions #:nodoc:
142
+ with_transaction_returning_status(:destroy_without_transactions)
143
+ end
144
+
145
+ def save_with_transactions(perform_validation = true) #:nodoc:
146
+ rollback_active_record_state! { with_transaction_returning_status(:save_without_transactions, perform_validation) }
147
+ end
148
+
149
+ def save_with_transactions! #:nodoc:
150
+ rollback_active_record_state! { transaction { save_without_transactions! } }
151
+ end
152
+
153
+ # Reset id and @new_record if the transaction rolls back.
154
+ def rollback_active_record_state!
155
+ id_present = has_attribute?(self.class.primary_key)
156
+ previous_id = id
157
+ previous_new_record = new_record?
158
+ yield
159
+ rescue Exception
160
+ @new_record = previous_new_record
161
+ if id_present
162
+ self.id = previous_id
163
+ else
164
+ @attributes.delete(self.class.primary_key)
165
+ @attributes_cache.delete(self.class.primary_key)
166
+ end
167
+ raise
168
+ end
169
+
170
+ # Executes +method+ within a transaction and captures its return value as a
171
+ # status flag. If the status is true the transaction is committed, otherwise
172
+ # a ROLLBACK is issued. In any case the status flag is returned.
173
+ #
174
+ # This method is available within the context of an ActiveRecord::Base
175
+ # instance.
176
+ def with_transaction_returning_status(method, *args)
177
+ status = nil
178
+ transaction do
179
+ status = send(method, *args)
180
+ raise ActiveRecord::Rollback unless status
181
+ end
182
+ status
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,1061 @@
1
+ module ActiveRecord
2
+ # Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
3
+ # +record+ method to retrieve the record which did not validate.
4
+ # begin
5
+ # complex_operation_that_calls_save!_internally
6
+ # rescue ActiveRecord::RecordInvalid => invalid
7
+ # puts invalid.record.errors
8
+ # end
9
+ class RecordInvalid < ActiveRecordError
10
+ attr_reader :record
11
+ def initialize(record)
12
+ @record = record
13
+ super("Validation failed: #{@record.errors.full_messages.join(", ")}")
14
+ end
15
+ end
16
+
17
+ # Active Record validation is reported to and from this object, which is used by Base#save to
18
+ # determine whether the object is in a valid state to be saved. See usage example in Validations.
19
+ class Errors
20
+ include Enumerable
21
+
22
+ class << self
23
+ def default_error_messages
24
+ ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use I18n.translate('activerecord.errors.messages').")
25
+ I18n.translate 'activerecord.errors.messages'
26
+ end
27
+ end
28
+
29
+ def initialize(base) # :nodoc:
30
+ @base, @errors = base, {}
31
+ end
32
+
33
+ # Adds an error to the base object instead of any particular attribute. This is used
34
+ # to report errors that don't tie to any specific attribute, but rather to the object
35
+ # as a whole. These error messages don't get prepended with any field name when iterating
36
+ # with +each_full+, so they should be complete sentences.
37
+ def add_to_base(msg)
38
+ add(:base, msg)
39
+ end
40
+
41
+ # Adds an error message (+messsage+) to the +attribute+, which will be returned on a call to <tt>on(attribute)</tt>
42
+ # for the same attribute and ensure that this error object returns false when asked if <tt>empty?</tt>. More than one
43
+ # error can be added to the same +attribute+ in which case an array will be returned on a call to <tt>on(attribute)</tt>.
44
+ # If no +messsage+ is supplied, :invalid is assumed.
45
+ # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error).
46
+ def add(attribute, message = nil, options = {})
47
+ message ||= :invalid
48
+ message = generate_message(attribute, message, options) if message.is_a?(Symbol)
49
+ @errors[attribute.to_s] ||= []
50
+ @errors[attribute.to_s] << message
51
+ end
52
+
53
+ # Will add an error message to each of the attributes in +attributes+ that is empty.
54
+ def add_on_empty(attributes, custom_message = nil)
55
+ for attr in [attributes].flatten
56
+ value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
57
+ is_empty = value.respond_to?(:empty?) ? value.empty? : false
58
+ add(attr, :empty, :default => custom_message) unless !value.nil? && !is_empty
59
+ end
60
+ end
61
+
62
+ # Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
63
+ def add_on_blank(attributes, custom_message = nil)
64
+ for attr in [attributes].flatten
65
+ value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
66
+ add(attr, :blank, :default => custom_message) if value.blank?
67
+ end
68
+ end
69
+
70
+ # Translates an error message in it's default scope (<tt>activerecord.errrors.messages</tt>).
71
+ # Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
72
+ # it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
73
+ # default message (e.g. <tt>activerecord.errors.messages.MESSAGE</tt>). The translated model name,
74
+ # translated attribute name and the value are available for interpolation.
75
+ #
76
+ # When using inheritence in your models, it will check all the inherited models too, but only if the model itself
77
+ # hasn't been found. Say you have <tt>class Admin < User; end</tt> and you wanted the translation for the <tt>:blank</tt>
78
+ # error +message+ for the <tt>title</tt> +attribute+, it looks for these translations:
79
+ #
80
+ # <ol>
81
+ # <li><tt>activerecord.errors.models.admin.attributes.title.blank</tt></li>
82
+ # <li><tt>activerecord.errors.models.admin.blank</tt></li>
83
+ # <li><tt>activerecord.errors.models.user.attributes.title.blank</tt></li>
84
+ # <li><tt>activerecord.errors.models.user.blank</tt></li>
85
+ # <li><tt>activerecord.errors.messages.blank</tt></li>
86
+ # <li>any default you provided through the +options+ hash (in the activerecord.errors scope)</li>
87
+ # </ol>
88
+ def generate_message(attribute, message = :invalid, options = {})
89
+
90
+ message, options[:default] = options[:default], message if options[:default].is_a?(Symbol)
91
+
92
+ defaults = @base.class.self_and_descendents_from_active_record.map do |klass|
93
+ [ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
94
+ :"models.#{klass.name.underscore}.#{message}" ]
95
+ end
96
+
97
+ defaults << options.delete(:default)
98
+ defaults = defaults.compact.flatten << :"messages.#{message}"
99
+
100
+ key = defaults.shift
101
+ value = @base.respond_to?(attribute) ? @base.send(attribute) : nil
102
+
103
+ options = { :default => defaults,
104
+ :model => @base.class.human_name,
105
+ :attribute => @base.class.human_attribute_name(attribute.to_s),
106
+ :value => value,
107
+ :scope => [:activerecord, :errors]
108
+ }.merge(options)
109
+
110
+ I18n.translate(key, options)
111
+ end
112
+
113
+ # Returns true if the specified +attribute+ has errors associated with it.
114
+ #
115
+ # class Company < ActiveRecord::Base
116
+ # validates_presence_of :name, :address, :email
117
+ # validates_length_of :name, :in => 5..30
118
+ # end
119
+ #
120
+ # company = Company.create(:address => '123 First St.')
121
+ # company.errors.invalid?(:name) # => true
122
+ # company.errors.invalid?(:address) # => false
123
+ def invalid?(attribute)
124
+ !@errors[attribute.to_s].nil?
125
+ end
126
+
127
+ # Returns +nil+, if no errors are associated with the specified +attribute+.
128
+ # Returns the error message, if one error is associated with the specified +attribute+.
129
+ # Returns an array of error messages, if more than one error is associated with the specified +attribute+.
130
+ #
131
+ # class Company < ActiveRecord::Base
132
+ # validates_presence_of :name, :address, :email
133
+ # validates_length_of :name, :in => 5..30
134
+ # end
135
+ #
136
+ # company = Company.create(:address => '123 First St.')
137
+ # company.errors.on(:name) # => ["is too short (minimum is 5 characters)", "can't be blank"]
138
+ # company.errors.on(:email) # => "can't be blank"
139
+ # company.errors.on(:address) # => nil
140
+ def on(attribute)
141
+ errors = @errors[attribute.to_s]
142
+ return nil if errors.nil?
143
+ errors.size == 1 ? errors.first : errors
144
+ end
145
+
146
+ alias :[] :on
147
+
148
+ # Returns errors assigned to the base object through +add_to_base+ according to the normal rules of <tt>on(attribute)</tt>.
149
+ def on_base
150
+ on(:base)
151
+ end
152
+
153
+ # Yields each attribute and associated message per error added.
154
+ #
155
+ # class Company < ActiveRecord::Base
156
+ # validates_presence_of :name, :address, :email
157
+ # validates_length_of :name, :in => 5..30
158
+ # end
159
+ #
160
+ # company = Company.create(:address => '123 First St.')
161
+ # company.errors.each{|attr,msg| puts "#{attr} - #{msg}" }
162
+ # # => name - is too short (minimum is 5 characters)
163
+ # # name - can't be blank
164
+ # # address - can't be blank
165
+ def each
166
+ @errors.each_key { |attr| @errors[attr].each { |msg| yield attr, msg } }
167
+ end
168
+
169
+ # Yields each full error message added. So <tt>Person.errors.add("first_name", "can't be empty")</tt> will be returned
170
+ # through iteration as "First name can't be empty".
171
+ #
172
+ # class Company < ActiveRecord::Base
173
+ # validates_presence_of :name, :address, :email
174
+ # validates_length_of :name, :in => 5..30
175
+ # end
176
+ #
177
+ # company = Company.create(:address => '123 First St.')
178
+ # company.errors.each_full{|msg| puts msg }
179
+ # # => Name is too short (minimum is 5 characters)
180
+ # # Name can't be blank
181
+ # # Address can't be blank
182
+ def each_full
183
+ full_messages.each { |msg| yield msg }
184
+ end
185
+
186
+ # Returns all the full error messages in an array.
187
+ #
188
+ # class Company < ActiveRecord::Base
189
+ # validates_presence_of :name, :address, :email
190
+ # validates_length_of :name, :in => 5..30
191
+ # end
192
+ #
193
+ # company = Company.create(:address => '123 First St.')
194
+ # company.errors.full_messages # =>
195
+ # ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"]
196
+ def full_messages(options = {})
197
+ full_messages = []
198
+
199
+ @errors.each_key do |attr|
200
+ @errors[attr].each do |message|
201
+ next unless message
202
+
203
+ if attr == "base"
204
+ full_messages << message
205
+ else
206
+ #key = :"activerecord.att.#{@base.class.name.underscore.to_sym}.#{attr}"
207
+ attr_name = @base.class.human_attribute_name(attr)
208
+ full_messages << attr_name + ' ' + message
209
+ end
210
+ end
211
+ end
212
+ full_messages
213
+ end
214
+
215
+ # Returns true if no errors have been added.
216
+ def empty?
217
+ @errors.empty?
218
+ end
219
+
220
+ # Removes all errors that have been added.
221
+ def clear
222
+ @errors = {}
223
+ end
224
+
225
+ # Returns the total number of errors added. Two errors added to the same attribute will be counted as such.
226
+ def size
227
+ @errors.values.inject(0) { |error_count, attribute| error_count + attribute.size }
228
+ end
229
+
230
+ alias_method :count, :size
231
+ alias_method :length, :size
232
+
233
+ # Returns an XML representation of this error object.
234
+ #
235
+ # class Company < ActiveRecord::Base
236
+ # validates_presence_of :name, :address, :email
237
+ # validates_length_of :name, :in => 5..30
238
+ # end
239
+ #
240
+ # company = Company.create(:address => '123 First St.')
241
+ # company.errors.to_xml
242
+ # # => <?xml version="1.0" encoding="UTF-8"?>
243
+ # # <errors>
244
+ # # <error>Name is too short (minimum is 5 characters)</error>
245
+ # # <error>Name can't be blank</error>
246
+ # # <error>Address can't be blank</error>
247
+ # # </errors>
248
+ def to_xml(options={})
249
+ options[:root] ||= "errors"
250
+ options[:indent] ||= 2
251
+ options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
252
+
253
+ options[:builder].instruct! unless options.delete(:skip_instruct)
254
+ options[:builder].errors do |e|
255
+ full_messages.each { |msg| e.error(msg) }
256
+ end
257
+ end
258
+
259
+ end
260
+
261
+
262
+ # Please do have a look at ActiveRecord::Validations::ClassMethods for a higher level of validations.
263
+ #
264
+ # Active Records implement validation by overwriting Base#validate (or the variations, +validate_on_create+ and
265
+ # +validate_on_update+). Each of these methods can inspect the state of the object, which usually means ensuring
266
+ # that a number of attributes have a certain value (such as not empty, within a given range, matching a certain regular expression).
267
+ #
268
+ # Example:
269
+ #
270
+ # class Person < ActiveRecord::Base
271
+ # protected
272
+ # def validate
273
+ # errors.add_on_empty %w( first_name last_name )
274
+ # errors.add("phone_number", "has invalid format") unless phone_number =~ /[0-9]*/
275
+ # end
276
+ #
277
+ # def validate_on_create # is only run the first time a new object is saved
278
+ # unless valid_discount?(membership_discount)
279
+ # errors.add("membership_discount", "has expired")
280
+ # end
281
+ # end
282
+ #
283
+ # def validate_on_update
284
+ # errors.add_to_base("No changes have occurred") if unchanged_attributes?
285
+ # end
286
+ # end
287
+ #
288
+ # person = Person.new("first_name" => "David", "phone_number" => "what?")
289
+ # person.save # => false (and doesn't do the save)
290
+ # person.errors.empty? # => false
291
+ # person.errors.count # => 2
292
+ # person.errors.on "last_name" # => "can't be empty"
293
+ # person.errors.on "phone_number" # => "has invalid format"
294
+ # person.errors.each_full { |msg| puts msg }
295
+ # # => "Last name can't be empty\n" +
296
+ # # "Phone number has invalid format"
297
+ #
298
+ # person.attributes = { "last_name" => "Heinemeier", "phone_number" => "555-555" }
299
+ # person.save # => true (and person is now saved in the database)
300
+ #
301
+ # An Errors object is automatically created for every Active Record.
302
+ module Validations
303
+ VALIDATIONS = %w( validate validate_on_create validate_on_update )
304
+
305
+ def self.included(base) # :nodoc:
306
+ base.extend ClassMethods
307
+ base.class_eval do
308
+ alias_method_chain :save, :validation
309
+ alias_method_chain :save!, :validation
310
+ end
311
+
312
+ base.send :include, ActiveSupport::Callbacks
313
+ base.define_callbacks *VALIDATIONS
314
+ end
315
+
316
+ # Active Record classes can implement validations in several ways. The highest level, easiest to read,
317
+ # and recommended approach is to use the declarative <tt>validates_..._of</tt> class methods (and
318
+ # +validates_associated+) documented below. These are sufficient for most model validations.
319
+ #
320
+ # Slightly lower level is +validates_each+. It provides some of the same options as the purely declarative
321
+ # validation methods, but like all the lower-level approaches it requires manually adding to the errors collection
322
+ # when the record is invalid.
323
+ #
324
+ # At a yet lower level, a model can use the class methods +validate+, +validate_on_create+ and +validate_on_update+
325
+ # to add validation methods or blocks. These are ActiveSupport::Callbacks and follow the same rules of inheritance
326
+ # and chaining.
327
+ #
328
+ # The lowest level style is to define the instance methods +validate+, +validate_on_create+ and +validate_on_update+
329
+ # as documented in ActiveRecord::Validations.
330
+ #
331
+ # == +validate+, +validate_on_create+ and +validate_on_update+ Class Methods
332
+ #
333
+ # Calls to these methods add a validation method or block to the class. Again, this approach is recommended
334
+ # only when the higher-level methods documented below (<tt>validates_..._of</tt> and +validates_associated+) are
335
+ # insufficient to handle the required validation.
336
+ #
337
+ # This can be done with a symbol pointing to a method:
338
+ #
339
+ # class Comment < ActiveRecord::Base
340
+ # validate :must_be_friends
341
+ #
342
+ # def must_be_friends
343
+ # errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
344
+ # end
345
+ # end
346
+ #
347
+ # Or with a block which is passed the current record to be validated:
348
+ #
349
+ # class Comment < ActiveRecord::Base
350
+ # validate do |comment|
351
+ # comment.must_be_friends
352
+ # end
353
+ #
354
+ # def must_be_friends
355
+ # errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
356
+ # end
357
+ # end
358
+ #
359
+ # This usage applies to +validate_on_create+ and +validate_on_update+ as well.
360
+ module ClassMethods
361
+ DEFAULT_VALIDATION_OPTIONS = {
362
+ :on => :save,
363
+ :allow_nil => false,
364
+ :allow_blank => false,
365
+ :message => nil
366
+ }.freeze
367
+
368
+ ALL_RANGE_OPTIONS = [ :is, :within, :in, :minimum, :maximum ].freeze
369
+ ALL_NUMERICALITY_CHECKS = { :greater_than => '>', :greater_than_or_equal_to => '>=',
370
+ :equal_to => '==', :less_than => '<', :less_than_or_equal_to => '<=',
371
+ :odd => 'odd?', :even => 'even?' }.freeze
372
+
373
+ # Validates each attribute against a block.
374
+ #
375
+ # class Person < ActiveRecord::Base
376
+ # validates_each :first_name, :last_name do |record, attr, value|
377
+ # record.errors.add attr, 'starts with z.' if value[0] == ?z
378
+ # end
379
+ # end
380
+ #
381
+ # Options:
382
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
383
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
384
+ # * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
385
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
386
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
387
+ # method, proc or string should return or evaluate to a true or false value.
388
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
389
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
390
+ # method, proc or string should return or evaluate to a true or false value.
391
+ def validates_each(*attrs)
392
+ options = attrs.extract_options!.symbolize_keys
393
+ attrs = attrs.flatten
394
+
395
+ # Declare the validation.
396
+ send(validation_method(options[:on] || :save), options) do |record|
397
+ attrs.each do |attr|
398
+ value = record.send(attr)
399
+ next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
400
+ yield record, attr, value
401
+ end
402
+ end
403
+ end
404
+
405
+ # Encapsulates the pattern of wanting to validate a password or email address field with a confirmation. Example:
406
+ #
407
+ # Model:
408
+ # class Person < ActiveRecord::Base
409
+ # validates_confirmation_of :user_name, :password
410
+ # validates_confirmation_of :email_address, :message => "should match confirmation"
411
+ # end
412
+ #
413
+ # View:
414
+ # <%= password_field "person", "password" %>
415
+ # <%= password_field "person", "password_confirmation" %>
416
+ #
417
+ # The added +password_confirmation+ attribute is virtual; it exists only as an in-memory attribute for validating the password.
418
+ # To achieve this, the validation adds accessors to the model for the confirmation attribute. NOTE: This check is performed
419
+ # only if +password_confirmation+ is not +nil+, and by default only on save. To require confirmation, make sure to add a presence
420
+ # check for the confirmation attribute:
421
+ #
422
+ # validates_presence_of :password_confirmation, :if => :password_changed?
423
+ #
424
+ # Configuration options:
425
+ # * <tt>:message</tt> - A custom error message (default is: "doesn't match confirmation").
426
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
427
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
428
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
429
+ # method, proc or string should return or evaluate to a true or false value.
430
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
431
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
432
+ # method, proc or string should return or evaluate to a true or false value.
433
+ def validates_confirmation_of(*attr_names)
434
+ configuration = { :on => :save }
435
+ configuration.update(attr_names.extract_options!)
436
+
437
+ attr_accessor(*(attr_names.map { |n| "#{n}_confirmation" }))
438
+
439
+ validates_each(attr_names, configuration) do |record, attr_name, value|
440
+ unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation")
441
+ record.errors.add(attr_name, :confirmation, :default => configuration[:message])
442
+ end
443
+ end
444
+ end
445
+
446
+ # Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement). Example:
447
+ #
448
+ # class Person < ActiveRecord::Base
449
+ # validates_acceptance_of :terms_of_service
450
+ # validates_acceptance_of :eula, :message => "must be abided"
451
+ # end
452
+ #
453
+ # If the database column does not exist, the +terms_of_service+ attribute is entirely virtual. This check is
454
+ # performed only if +terms_of_service+ is not +nil+ and by default on save.
455
+ #
456
+ # Configuration options:
457
+ # * <tt>:message</tt> - A custom error message (default is: "must be accepted").
458
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
459
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is true).
460
+ # * <tt>:accept</tt> - Specifies value that is considered accepted. The default value is a string "1", which
461
+ # makes it easy to relate to an HTML checkbox. This should be set to +true+ if you are validating a database
462
+ # column, since the attribute is typecast from "1" to +true+ before validation.
463
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
464
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
465
+ # method, proc or string should return or evaluate to a true or false value.
466
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
467
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
468
+ # method, proc or string should return or evaluate to a true or false value.
469
+ def validates_acceptance_of(*attr_names)
470
+ configuration = { :on => :save, :allow_nil => true, :accept => "1" }
471
+ configuration.update(attr_names.extract_options!)
472
+
473
+ db_cols = begin
474
+ column_names
475
+ rescue Exception # To ignore both statement and connection errors
476
+ []
477
+ end
478
+ names = attr_names.reject { |name| db_cols.include?(name.to_s) }
479
+ attr_accessor(*names)
480
+
481
+ validates_each(attr_names,configuration) do |record, attr_name, value|
482
+ unless value == configuration[:accept]
483
+ record.errors.add(attr_name, :accepted, :default => configuration[:message])
484
+ end
485
+ end
486
+ end
487
+
488
+ # Validates that the specified attributes are not blank (as defined by Object#blank?). Happens by default on save. Example:
489
+ #
490
+ # class Person < ActiveRecord::Base
491
+ # validates_presence_of :first_name
492
+ # end
493
+ #
494
+ # The first_name attribute must be in the object and it cannot be blank.
495
+ #
496
+ # If you want to validate the presence of a boolean field (where the real values are true and false),
497
+ # you will want to use validates_inclusion_of :field_name, :in => [true, false]
498
+ # This is due to the way Object#blank? handles boolean values. false.blank? # => true
499
+ #
500
+ # Configuration options:
501
+ # * <tt>message</tt> - A custom error message (default is: "can't be blank").
502
+ # * <tt>on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
503
+ # * <tt>if</tt> - Specifies a method, proc or string to call to determine if the validation should
504
+ # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The
505
+ # method, proc or string should return or evaluate to a true or false value.
506
+ # * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
507
+ # not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
508
+ # method, proc or string should return or evaluate to a true or false value.
509
+ #
510
+ def validates_presence_of(*attr_names)
511
+ configuration = { :on => :save }
512
+ configuration.update(attr_names.extract_options!)
513
+
514
+ # can't use validates_each here, because it cannot cope with nonexistent attributes,
515
+ # while errors.add_on_empty can
516
+ send(validation_method(configuration[:on]), configuration) do |record|
517
+ record.errors.add_on_blank(attr_names, configuration[:message])
518
+ end
519
+ end
520
+
521
+ # Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time:
522
+ #
523
+ # class Person < ActiveRecord::Base
524
+ # validates_length_of :first_name, :maximum=>30
525
+ # validates_length_of :last_name, :maximum=>30, :message=>"less than {{count}} if you don't mind"
526
+ # validates_length_of :fax, :in => 7..32, :allow_nil => true
527
+ # validates_length_of :phone, :in => 7..32, :allow_blank => true
528
+ # validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name"
529
+ # validates_length_of :fav_bra_size, :minimum => 1, :too_short => "please enter at least {{count}} character"
530
+ # validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with {{count}} characters... don't play me."
531
+ # validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least {{count}} words."), :tokenizer => lambda {|str| str.scan(/\w+/) }
532
+ # end
533
+ #
534
+ # Configuration options:
535
+ # * <tt>:minimum</tt> - The minimum size of the attribute.
536
+ # * <tt>:maximum</tt> - The maximum size of the attribute.
537
+ # * <tt>:is</tt> - The exact size of the attribute.
538
+ # * <tt>:within</tt> - A range specifying the minimum and maximum size of the attribute.
539
+ # * <tt>:in</tt> - A synonym(or alias) for <tt>:within</tt>.
540
+ # * <tt>:allow_nil</tt> - Attribute may be +nil+; skip validation.
541
+ # * <tt>:allow_blank</tt> - Attribute may be blank; skip validation.
542
+ # * <tt>:too_long</tt> - The error message if the attribute goes over the maximum (default is: "is too long (maximum is {{count}} characters)").
543
+ # * <tt>:too_short</tt> - The error message if the attribute goes under the minimum (default is: "is too short (min is {{count}} characters)").
544
+ # * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt> method and the attribute is the wrong size (default is: "is the wrong length (should be {{count}} characters)").
545
+ # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
546
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
547
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
548
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
549
+ # method, proc or string should return or evaluate to a true or false value.
550
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
551
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
552
+ # method, proc or string should return or evaluate to a true or false value.
553
+ # * <tt>:tokenizer</tt> - Specifies how to split up the attribute string. (e.g. <tt>:tokenizer => lambda {|str| str.scan(/\w+/)}</tt> to
554
+ # count words as in above example.)
555
+ # Defaults to <tt>lambda{ |value| value.split(//) }</tt> which counts individual characters.
556
+ def validates_length_of(*attrs)
557
+ # Merge given options with defaults.
558
+ options = {
559
+ :tokenizer => lambda {|value| value.split(//)}
560
+ }.merge(DEFAULT_VALIDATION_OPTIONS)
561
+ options.update(attrs.extract_options!.symbolize_keys)
562
+
563
+ # Ensure that one and only one range option is specified.
564
+ range_options = ALL_RANGE_OPTIONS & options.keys
565
+ case range_options.size
566
+ when 0
567
+ raise ArgumentError, 'Range unspecified. Specify the :within, :maximum, :minimum, or :is option.'
568
+ when 1
569
+ # Valid number of options; do nothing.
570
+ else
571
+ raise ArgumentError, 'Too many range options specified. Choose only one.'
572
+ end
573
+
574
+ # Get range option and value.
575
+ option = range_options.first
576
+ option_value = options[range_options.first]
577
+
578
+ case option
579
+ when :within, :in
580
+ raise ArgumentError, ":#{option} must be a Range" unless option_value.is_a?(Range)
581
+
582
+ validates_each(attrs, options) do |record, attr, value|
583
+ value = options[:tokenizer].call(value) if value.kind_of?(String)
584
+ if value.nil? or value.size < option_value.begin
585
+ record.errors.add(attr, :too_short, :default => options[:too_short], :count => option_value.begin)
586
+ elsif value.size > option_value.end
587
+ record.errors.add(attr, :too_long, :default => options[:too_long], :count => option_value.end)
588
+ end
589
+ end
590
+ when :is, :minimum, :maximum
591
+ raise ArgumentError, ":#{option} must be a nonnegative Integer" unless option_value.is_a?(Integer) and option_value >= 0
592
+
593
+ # Declare different validations per option.
594
+ validity_checks = { :is => "==", :minimum => ">=", :maximum => "<=" }
595
+ message_options = { :is => :wrong_length, :minimum => :too_short, :maximum => :too_long }
596
+
597
+ validates_each(attrs, options) do |record, attr, value|
598
+ value = options[:tokenizer].call(value) if value.kind_of?(String)
599
+ unless !value.nil? and value.size.method(validity_checks[option])[option_value]
600
+ key = message_options[option]
601
+ custom_message = options[:message] || options[key]
602
+ record.errors.add(attr, key, :default => custom_message, :count => option_value)
603
+ end
604
+ end
605
+ end
606
+ end
607
+
608
+ alias_method :validates_size_of, :validates_length_of
609
+
610
+
611
+ # Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user
612
+ # can be named "davidhh".
613
+ #
614
+ # class Person < ActiveRecord::Base
615
+ # validates_uniqueness_of :user_name, :scope => :account_id
616
+ # end
617
+ #
618
+ # It can also validate whether the value of the specified attributes are unique based on multiple scope parameters. For example,
619
+ # making sure that a teacher can only be on the schedule once per semester for a particular class.
620
+ #
621
+ # class TeacherSchedule < ActiveRecord::Base
622
+ # validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id]
623
+ # end
624
+ #
625
+ # When the record is created, a check is performed to make sure that no record exists in the database with the given value for the specified
626
+ # attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself.
627
+ #
628
+ # Configuration options:
629
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "has already been taken").
630
+ # * <tt>:scope</tt> - One or more columns by which to limit the scope of the uniqueness constraint.
631
+ # * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by non-text columns (+true+ by default).
632
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
633
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
634
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
635
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
636
+ # method, proc or string should return or evaluate to a true or false value.
637
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
638
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
639
+ # method, proc or string should return or evaluate to a true or false value.
640
+ #
641
+ # === Concurrency and integrity
642
+ #
643
+ # Using this validation method in conjunction with ActiveRecord::Base#save
644
+ # does not guarantee the absence of duplicate record insertions, because
645
+ # uniqueness checks on the application level are inherently prone to race
646
+ # conditions. For example, suppose that two users try to post a Comment at
647
+ # the same time, and a Comment's title must be unique. At the database-level,
648
+ # the actions performed by these users could be interleaved in the following manner:
649
+ #
650
+ # User 1 | User 2
651
+ # ------------------------------------+--------------------------------------
652
+ # # User 1 checks whether there's |
653
+ # # already a comment with the title |
654
+ # # 'My Post'. This is not the case. |
655
+ # SELECT * FROM comments |
656
+ # WHERE title = 'My Post' |
657
+ # |
658
+ # | # User 2 does the same thing and also
659
+ # | # infers that his title is unique.
660
+ # | SELECT * FROM comments
661
+ # | WHERE title = 'My Post'
662
+ # |
663
+ # # User 1 inserts his comment. |
664
+ # INSERT INTO comments |
665
+ # (title, content) VALUES |
666
+ # ('My Post', 'hi!') |
667
+ # |
668
+ # | # User 2 does the same thing.
669
+ # | INSERT INTO comments
670
+ # | (title, content) VALUES
671
+ # | ('My Post', 'hello!')
672
+ # |
673
+ # | # ^^^^^^
674
+ # | # Boom! We now have a duplicate
675
+ # | # title!
676
+ #
677
+ # This could even happen if you use transactions with the 'serializable'
678
+ # isolation level. There are several ways to get around this problem:
679
+ # - By locking the database table before validating, and unlocking it after
680
+ # saving. However, table locking is very expensive, and thus not
681
+ # recommended.
682
+ # - By locking a lock file before validating, and unlocking it after saving.
683
+ # This does not work if you've scaled your Rails application across
684
+ # multiple web servers (because they cannot share lock files, or cannot
685
+ # do that efficiently), and thus not recommended.
686
+ # - Creating a unique index on the field, by using
687
+ # ActiveRecord::ConnectionAdapters::SchemaStatements#add_index. In the
688
+ # rare case that a race condition occurs, the database will guarantee
689
+ # the field's uniqueness.
690
+ #
691
+ # When the database catches such a duplicate insertion,
692
+ # ActiveRecord::Base#save will raise an ActiveRecord::StatementInvalid
693
+ # exception. You can either choose to let this error propagate (which
694
+ # will result in the default Rails exception page being shown), or you
695
+ # can catch it and restart the transaction (e.g. by telling the user
696
+ # that the title already exists, and asking him to re-enter the title).
697
+ # This technique is also known as optimistic concurrency control:
698
+ # http://en.wikipedia.org/wiki/Optimistic_concurrency_control
699
+ #
700
+ # Active Record currently provides no way to distinguish unique
701
+ # index constraint errors from other types of database errors, so you
702
+ # will have to parse the (database-specific) exception message to detect
703
+ # such a case.
704
+ def validates_uniqueness_of(*attr_names)
705
+ configuration = { :case_sensitive => true }
706
+ configuration.update(attr_names.extract_options!)
707
+
708
+ validates_each(attr_names,configuration) do |record, attr_name, value|
709
+ # The check for an existing value should be run from a class that
710
+ # isn't abstract. This means working down from the current class
711
+ # (self), to the first non-abstract class. Since classes don't know
712
+ # their subclasses, we have to build the hierarchy between self and
713
+ # the record's class.
714
+ class_hierarchy = [record.class]
715
+ while class_hierarchy.first != self
716
+ class_hierarchy.insert(0, class_hierarchy.first.superclass)
717
+ end
718
+
719
+ # Now we can work our way down the tree to the first non-abstract
720
+ # class (which has a database table to query from).
721
+ finder_class = class_hierarchy.detect { |klass| !klass.abstract_class? }
722
+
723
+ is_text_column = finder_class.columns_hash[attr_name.to_s].text?
724
+
725
+ if value.nil?
726
+ comparison_operator = "IS ?"
727
+ elsif is_text_column
728
+ comparison_operator = "#{connection.case_sensitive_equality_operator} ?"
729
+ value = value.to_s
730
+ else
731
+ comparison_operator = "= ?"
732
+ end
733
+
734
+ sql_attribute = "#{record.class.quoted_table_name}.#{connection.quote_column_name(attr_name)}"
735
+
736
+ if value.nil? || (configuration[:case_sensitive] || !is_text_column)
737
+ condition_sql = "#{sql_attribute} #{comparison_operator}"
738
+ condition_params = [value]
739
+ else
740
+ condition_sql = "LOWER(#{sql_attribute}) #{comparison_operator}"
741
+ condition_params = [value.mb_chars.downcase]
742
+ end
743
+
744
+ if scope = configuration[:scope]
745
+ Array(scope).map do |scope_item|
746
+ scope_value = record.send(scope_item)
747
+ condition_sql << " AND #{record.class.quoted_table_name}.#{scope_item} #{attribute_condition(scope_value)}"
748
+ condition_params << scope_value
749
+ end
750
+ end
751
+
752
+ unless record.new_record?
753
+ condition_sql << " AND #{record.class.quoted_table_name}.#{record.class.primary_key} <> ?"
754
+ condition_params << record.send(:id)
755
+ end
756
+
757
+ finder_class.with_exclusive_scope do
758
+ if finder_class.exists?([condition_sql, *condition_params])
759
+ record.errors.add(attr_name, :taken, :default => configuration[:message], :value => value)
760
+ end
761
+ end
762
+ end
763
+ end
764
+
765
+
766
+ # Validates whether the value of the specified attribute is of the correct form by matching it against the regular expression
767
+ # provided.
768
+ #
769
+ # class Person < ActiveRecord::Base
770
+ # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
771
+ # end
772
+ #
773
+ # Note: use <tt>\A</tt> and <tt>\Z</tt> to match the start and end of the string, <tt>^</tt> and <tt>$</tt> match the start/end of a line.
774
+ #
775
+ # A regular expression must be provided or else an exception will be raised.
776
+ #
777
+ # Configuration options:
778
+ # * <tt>:message</tt> - A custom error message (default is: "is invalid").
779
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
780
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
781
+ # * <tt>:with</tt> - The regular expression used to validate the format with (note: must be supplied!).
782
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
783
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
784
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
785
+ # method, proc or string should return or evaluate to a true or false value.
786
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
787
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
788
+ # method, proc or string should return or evaluate to a true or false value.
789
+ def validates_format_of(*attr_names)
790
+ configuration = { :on => :save, :with => nil }
791
+ configuration.update(attr_names.extract_options!)
792
+
793
+ raise(ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash") unless configuration[:with].is_a?(Regexp)
794
+
795
+ validates_each(attr_names, configuration) do |record, attr_name, value|
796
+ unless value.to_s =~ configuration[:with]
797
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
798
+ end
799
+ end
800
+ end
801
+
802
+ # Validates whether the value of the specified attribute is available in a particular enumerable object.
803
+ #
804
+ # class Person < ActiveRecord::Base
805
+ # validates_inclusion_of :gender, :in => %w( m f ), :message => "woah! what are you then!??!!"
806
+ # validates_inclusion_of :age, :in => 0..99
807
+ # validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension {{value}} is not included in the list"
808
+ # end
809
+ #
810
+ # Configuration options:
811
+ # * <tt>:in</tt> - An enumerable object of available items.
812
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "is not included in the list").
813
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
814
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
815
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
816
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
817
+ # method, proc or string should return or evaluate to a true or false value.
818
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
819
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
820
+ # method, proc or string should return or evaluate to a true or false value.
821
+ def validates_inclusion_of(*attr_names)
822
+ configuration = { :on => :save }
823
+ configuration.update(attr_names.extract_options!)
824
+
825
+ enum = configuration[:in] || configuration[:within]
826
+
827
+ raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)
828
+
829
+ validates_each(attr_names, configuration) do |record, attr_name, value|
830
+ unless enum.include?(value)
831
+ record.errors.add(attr_name, :inclusion, :default => configuration[:message], :value => value)
832
+ end
833
+ end
834
+ end
835
+
836
+ # Validates that the value of the specified attribute is not in a particular enumerable object.
837
+ #
838
+ # class Person < ActiveRecord::Base
839
+ # validates_exclusion_of :username, :in => %w( admin superuser ), :message => "You don't belong here"
840
+ # validates_exclusion_of :age, :in => 30..60, :message => "This site is only for under 30 and over 60"
841
+ # validates_exclusion_of :format, :in => %w( mov avi ), :message => "extension {{value}} is not allowed"
842
+ # end
843
+ #
844
+ # Configuration options:
845
+ # * <tt>:in</tt> - An enumerable object of items that the value shouldn't be part of.
846
+ # * <tt>:message</tt> - Specifies a custom error message (default is: "is reserved").
847
+ # * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
848
+ # * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
849
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
850
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
851
+ # method, proc or string should return or evaluate to a true or false value.
852
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
853
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
854
+ # method, proc or string should return or evaluate to a true or false value.
855
+ def validates_exclusion_of(*attr_names)
856
+ configuration = { :on => :save }
857
+ configuration.update(attr_names.extract_options!)
858
+
859
+ enum = configuration[:in] || configuration[:within]
860
+
861
+ raise(ArgumentError, "An object with the method include? is required must be supplied as the :in option of the configuration hash") unless enum.respond_to?(:include?)
862
+
863
+ validates_each(attr_names, configuration) do |record, attr_name, value|
864
+ if enum.include?(value)
865
+ record.errors.add(attr_name, :exclusion, :default => configuration[:message], :value => value)
866
+ end
867
+ end
868
+ end
869
+
870
+ # Validates whether the associated object or objects are all valid themselves. Works with any kind of association.
871
+ #
872
+ # class Book < ActiveRecord::Base
873
+ # has_many :pages
874
+ # belongs_to :library
875
+ #
876
+ # validates_associated :pages, :library
877
+ # end
878
+ #
879
+ # Warning: If, after the above definition, you then wrote:
880
+ #
881
+ # class Page < ActiveRecord::Base
882
+ # belongs_to :book
883
+ #
884
+ # validates_associated :book
885
+ # end
886
+ #
887
+ # this would specify a circular dependency and cause infinite recursion.
888
+ #
889
+ # NOTE: This validation will not fail if the association hasn't been assigned. If you want to ensure that the association
890
+ # is both present and guaranteed to be valid, you also need to use +validates_presence_of+.
891
+ #
892
+ # Configuration options:
893
+ # * <tt>:message</tt> - A custom error message (default is: "is invalid")
894
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
895
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
896
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
897
+ # method, proc or string should return or evaluate to a true or false value.
898
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
899
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
900
+ # method, proc or string should return or evaluate to a true or false value.
901
+ def validates_associated(*attr_names)
902
+ configuration = { :on => :save }
903
+ configuration.update(attr_names.extract_options!)
904
+
905
+ validates_each(attr_names, configuration) do |record, attr_name, value|
906
+ unless (value.is_a?(Array) ? value : [value]).inject(true) { |v, r| (r.nil? || r.valid?) && v }
907
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
908
+ end
909
+ end
910
+ end
911
+
912
+ # Validates whether the value of the specified attribute is numeric by trying to convert it to
913
+ # a float with Kernel.Float (if <tt>only_integer</tt> is false) or applying it to the regular expression
914
+ # <tt>/\A[\+\-]?\d+\Z/</tt> (if <tt>only_integer</tt> is set to true).
915
+ #
916
+ # class Person < ActiveRecord::Base
917
+ # validates_numericality_of :value, :on => :create
918
+ # end
919
+ #
920
+ # Configuration options:
921
+ # * <tt>:message</tt> - A custom error message (default is: "is not a number").
922
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
923
+ # * <tt>:only_integer</tt> - Specifies whether the value has to be an integer, e.g. an integral value (default is +false+).
924
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is +false+). Notice that for fixnum and float columns empty strings are converted to +nil+.
925
+ # * <tt>:greater_than</tt> - Specifies the value must be greater than the supplied value.
926
+ # * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be greater than or equal the supplied value.
927
+ # * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied value.
928
+ # * <tt>:less_than</tt> - Specifies the value must be less than the supplied value.
929
+ # * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less than or equal the supplied value.
930
+ # * <tt>:odd</tt> - Specifies the value must be an odd number.
931
+ # * <tt>:even</tt> - Specifies the value must be an even number.
932
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
933
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
934
+ # method, proc or string should return or evaluate to a true or false value.
935
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
936
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
937
+ # method, proc or string should return or evaluate to a true or false value.
938
+ def validates_numericality_of(*attr_names)
939
+ configuration = { :on => :save, :only_integer => false, :allow_nil => false }
940
+ configuration.update(attr_names.extract_options!)
941
+
942
+
943
+ numericality_options = ALL_NUMERICALITY_CHECKS.keys & configuration.keys
944
+
945
+ (numericality_options - [ :odd, :even ]).each do |option|
946
+ raise ArgumentError, ":#{option} must be a number" unless configuration[option].is_a?(Numeric)
947
+ end
948
+
949
+ validates_each(attr_names,configuration) do |record, attr_name, value|
950
+ raw_value = record.send("#{attr_name}_before_type_cast") || value
951
+
952
+ next if configuration[:allow_nil] and raw_value.nil?
953
+
954
+ if configuration[:only_integer]
955
+ unless raw_value.to_s =~ /\A[+-]?\d+\Z/
956
+ record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
957
+ next
958
+ end
959
+ raw_value = raw_value.to_i
960
+ else
961
+ begin
962
+ raw_value = Kernel.Float(raw_value)
963
+ rescue ArgumentError, TypeError
964
+ record.errors.add(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
965
+ next
966
+ end
967
+ end
968
+
969
+ numericality_options.each do |option|
970
+ case option
971
+ when :odd, :even
972
+ unless raw_value.to_i.method(ALL_NUMERICALITY_CHECKS[option])[]
973
+ record.errors.add(attr_name, option, :value => raw_value, :default => configuration[:message])
974
+ end
975
+ else
976
+ record.errors.add(attr_name, option, :default => configuration[:message], :value => raw_value, :count => configuration[option]) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
977
+ end
978
+ end
979
+ end
980
+ end
981
+
982
+ # Creates an object just like Base.create but calls save! instead of save
983
+ # so an exception is raised if the record is invalid.
984
+ def create!(attributes = nil, &block)
985
+ if attributes.is_a?(Array)
986
+ attributes.collect { |attr| create!(attr, &block) }
987
+ else
988
+ object = new(attributes)
989
+ yield(object) if block_given?
990
+ object.save!
991
+ object
992
+ end
993
+ end
994
+
995
+ private
996
+ def validation_method(on)
997
+ case on
998
+ when :save then :validate
999
+ when :create then :validate_on_create
1000
+ when :update then :validate_on_update
1001
+ end
1002
+ end
1003
+ end
1004
+
1005
+ # The validation process on save can be skipped by passing false. The regular Base#save method is
1006
+ # replaced with this when the validations module is mixed in, which it is by default.
1007
+ def save_with_validation(perform_validation = true)
1008
+ if perform_validation && valid? || !perform_validation
1009
+ save_without_validation
1010
+ else
1011
+ false
1012
+ end
1013
+ end
1014
+
1015
+ # Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false
1016
+ # if the record is not valid.
1017
+ def save_with_validation!
1018
+ if valid?
1019
+ save_without_validation!
1020
+ else
1021
+ raise RecordInvalid.new(self)
1022
+ end
1023
+ end
1024
+
1025
+ # Runs +validate+ and +validate_on_create+ or +validate_on_update+ and returns true if no errors were added otherwise false.
1026
+ def valid?
1027
+ errors.clear
1028
+
1029
+ run_callbacks(:validate)
1030
+ validate
1031
+
1032
+ if new_record?
1033
+ run_callbacks(:validate_on_create)
1034
+ validate_on_create
1035
+ else
1036
+ run_callbacks(:validate_on_update)
1037
+ validate_on_update
1038
+ end
1039
+
1040
+ errors.empty?
1041
+ end
1042
+
1043
+ # Returns the Errors object that holds all information about attribute error messages.
1044
+ def errors
1045
+ @errors ||= Errors.new(self)
1046
+ end
1047
+
1048
+ protected
1049
+ # Overwrite this method for validation checks on all saves and use <tt>Errors.add(field, msg)</tt> for invalid attributes.
1050
+ def validate #:doc:
1051
+ end
1052
+
1053
+ # Overwrite this method for validation checks used only on creation.
1054
+ def validate_on_create #:doc:
1055
+ end
1056
+
1057
+ # Overwrite this method for validation checks used only on updates.
1058
+ def validate_on_update # :doc:
1059
+ end
1060
+ end
1061
+ end