nbudin-castronaut 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.textile +67 -0
- data/Rakefile +73 -0
- data/app/config.rb +17 -0
- data/app/config.ru +24 -0
- data/app/controllers/application.rb +42 -0
- data/app/public/javascripts/application.js +3 -0
- data/app/public/javascripts/jquery.js +32 -0
- data/app/public/stylesheets/screen.css +122 -0
- data/app/views/layout.erb +27 -0
- data/app/views/login.erb +31 -0
- data/app/views/logout.erb +13 -0
- data/app/views/proxy_validate.erb +22 -0
- data/app/views/service_validate.erb +15 -0
- data/bin/castronaut +71 -0
- data/castronaut.rb +7 -0
- data/config/castronaut.example.yml +41 -0
- data/config/castronaut.sample.yml +40 -0
- data/config/nginx_vhost.conf +17 -0
- data/config/thin_config.yml +13 -0
- data/lib/castronaut.rb +35 -0
- data/lib/castronaut/adapters.rb +22 -0
- data/lib/castronaut/adapters/development/adapter.rb +13 -0
- data/lib/castronaut/adapters/development/user.rb +25 -0
- data/lib/castronaut/adapters/ldap/adapter.rb +15 -0
- data/lib/castronaut/adapters/ldap/user.rb +39 -0
- data/lib/castronaut/adapters/restful_authentication/adapter.rb +15 -0
- data/lib/castronaut/adapters/restful_authentication/user.rb +50 -0
- data/lib/castronaut/authentication_result.rb +24 -0
- data/lib/castronaut/configuration.rb +108 -0
- data/lib/castronaut/db/001_create_cas_database.rb +47 -0
- data/lib/castronaut/extra_attributes.rb +8 -0
- data/lib/castronaut/models/consumeable.rb +18 -0
- data/lib/castronaut/models/dispenser.rb +14 -0
- data/lib/castronaut/models/login_ticket.rb +53 -0
- data/lib/castronaut/models/proxy_granting_ticket.rb +70 -0
- data/lib/castronaut/models/proxy_ticket.rb +43 -0
- data/lib/castronaut/models/service_ticket.rb +91 -0
- data/lib/castronaut/models/ticket_granting_ticket.rb +52 -0
- data/lib/castronaut/presenters/login.rb +84 -0
- data/lib/castronaut/presenters/logout.rb +56 -0
- data/lib/castronaut/presenters/process_login.rb +149 -0
- data/lib/castronaut/presenters/proxy_validate.rb +68 -0
- data/lib/castronaut/presenters/service_validate.rb +69 -0
- data/lib/castronaut/support/sample.rb +21 -0
- data/lib/castronaut/ticket_result.rb +27 -0
- data/lib/castronaut/utilities/random_string.rb +24 -0
- data/spec/app/controllers/application_spec.rb +86 -0
- data/spec/castronaut/adapters/development/adapter_spec.rb +14 -0
- data/spec/castronaut/adapters/development/user_spec.rb +55 -0
- data/spec/castronaut/adapters/ldap/adapter_spec.rb +14 -0
- data/spec/castronaut/adapters/ldap/user_spec.rb +25 -0
- data/spec/castronaut/adapters/restful_authentication/adapter_spec.rb +14 -0
- data/spec/castronaut/adapters/restful_authentication/user_spec.rb +108 -0
- data/spec/castronaut/adapters_spec.rb +13 -0
- data/spec/castronaut/authentication_result_spec.rb +20 -0
- data/spec/castronaut/configuration_spec.rb +172 -0
- data/spec/castronaut/models/consumeable_spec.rb +39 -0
- data/spec/castronaut/models/dispenser_spec.rb +30 -0
- data/spec/castronaut/models/login_ticket_spec.rb +107 -0
- data/spec/castronaut/models/proxy_granting_ticket_spec.rb +302 -0
- data/spec/castronaut/models/proxy_ticket_spec.rb +109 -0
- data/spec/castronaut/models/service_ticket_spec.rb +269 -0
- data/spec/castronaut/models/ticket_granting_ticket_spec.rb +89 -0
- data/spec/castronaut/presenters/login_spec.rb +152 -0
- data/spec/castronaut/presenters/logout_spec.rb +85 -0
- data/spec/castronaut/presenters/process_login_spec.rb +300 -0
- data/spec/castronaut/presenters/proxy_validate_spec.rb +103 -0
- data/spec/castronaut/presenters/service_validate_spec.rb +86 -0
- data/spec/castronaut/ticket_result_spec.rb +42 -0
- data/spec/castronaut/utilities/random_string_spec.rb +14 -0
- data/spec/castronaut_spec.rb +26 -0
- data/spec/spec_controller_helper.rb +17 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/spec_rails_mocks.rb +132 -0
- data/vendor/activerecord/CHANGELOG +5786 -0
- data/vendor/activerecord/README +351 -0
- data/vendor/activerecord/RUNNING_UNIT_TESTS +36 -0
- data/vendor/activerecord/Rakefile +247 -0
- data/vendor/activerecord/examples/associations.png +0 -0
- data/vendor/activerecord/install.rb +30 -0
- data/vendor/activerecord/lib/active_record.rb +81 -0
- data/vendor/activerecord/lib/active_record/aggregations.rb +261 -0
- data/vendor/activerecord/lib/active_record/association_preload.rb +374 -0
- data/vendor/activerecord/lib/active_record/associations.rb +2227 -0
- data/vendor/activerecord/lib/active_record/associations/association_collection.rb +453 -0
- data/vendor/activerecord/lib/active_record/associations/association_proxy.rb +272 -0
- data/vendor/activerecord/lib/active_record/associations/belongs_to_association.rb +58 -0
- data/vendor/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +49 -0
- data/vendor/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +121 -0
- data/vendor/activerecord/lib/active_record/associations/has_many_association.rb +121 -0
- data/vendor/activerecord/lib/active_record/associations/has_many_through_association.rb +256 -0
- data/vendor/activerecord/lib/active_record/associations/has_one_association.rb +115 -0
- data/vendor/activerecord/lib/active_record/associations/has_one_through_association.rb +31 -0
- data/vendor/activerecord/lib/active_record/attribute_methods.rb +387 -0
- data/vendor/activerecord/lib/active_record/base.rb +2967 -0
- data/vendor/activerecord/lib/active_record/calculations.rb +299 -0
- data/vendor/activerecord/lib/active_record/callbacks.rb +331 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +355 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +136 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +201 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +94 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +69 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +705 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +434 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +210 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +585 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +1065 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
- data/vendor/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +418 -0
- data/vendor/activerecord/lib/active_record/dirty.rb +183 -0
- data/vendor/activerecord/lib/active_record/dynamic_finder_match.rb +41 -0
- data/vendor/activerecord/lib/active_record/fixtures.rb +998 -0
- data/vendor/activerecord/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
- data/vendor/activerecord/lib/active_record/locale/en.yml +54 -0
- data/vendor/activerecord/lib/active_record/locking/optimistic.rb +148 -0
- data/vendor/activerecord/lib/active_record/locking/pessimistic.rb +77 -0
- data/vendor/activerecord/lib/active_record/migration.rb +560 -0
- data/vendor/activerecord/lib/active_record/named_scope.rb +181 -0
- data/vendor/activerecord/lib/active_record/observer.rb +197 -0
- data/vendor/activerecord/lib/active_record/query_cache.rb +21 -0
- data/vendor/activerecord/lib/active_record/reflection.rb +307 -0
- data/vendor/activerecord/lib/active_record/schema.rb +51 -0
- data/vendor/activerecord/lib/active_record/schema_dumper.rb +177 -0
- data/vendor/activerecord/lib/active_record/serialization.rb +98 -0
- data/vendor/activerecord/lib/active_record/serializers/json_serializer.rb +80 -0
- data/vendor/activerecord/lib/active_record/serializers/xml_serializer.rb +338 -0
- data/vendor/activerecord/lib/active_record/test_case.rb +60 -0
- data/vendor/activerecord/lib/active_record/timestamp.rb +41 -0
- data/vendor/activerecord/lib/active_record/transactions.rb +185 -0
- data/vendor/activerecord/lib/active_record/validations.rb +1061 -0
- data/vendor/activerecord/lib/active_record/version.rb +9 -0
- data/vendor/activerecord/lib/activerecord.rb +1 -0
- data/vendor/activerecord/test/assets/example.log +1 -0
- data/vendor/activerecord/test/assets/flowers.jpg +0 -0
- data/vendor/activerecord/test/cases/aaa_create_tables_test.rb +24 -0
- data/vendor/activerecord/test/cases/active_schema_test_mysql.rb +100 -0
- data/vendor/activerecord/test/cases/active_schema_test_postgresql.rb +24 -0
- data/vendor/activerecord/test/cases/adapter_test.rb +133 -0
- data/vendor/activerecord/test/cases/aggregations_test.rb +167 -0
- data/vendor/activerecord/test/cases/ar_schema_test.rb +33 -0
- data/vendor/activerecord/test/cases/associations/belongs_to_associations_test.rb +441 -0
- data/vendor/activerecord/test/cases/associations/callbacks_test.rb +161 -0
- data/vendor/activerecord/test/cases/associations/cascaded_eager_loading_test.rb +123 -0
- data/vendor/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb +36 -0
- data/vendor/activerecord/test/cases/associations/eager_load_nested_include_test.rb +101 -0
- data/vendor/activerecord/test/cases/associations/eager_singularization_test.rb +145 -0
- data/vendor/activerecord/test/cases/associations/eager_test.rb +692 -0
- data/vendor/activerecord/test/cases/associations/extension_test.rb +62 -0
- data/vendor/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +773 -0
- data/vendor/activerecord/test/cases/associations/has_many_associations_test.rb +1101 -0
- data/vendor/activerecord/test/cases/associations/has_many_through_associations_test.rb +247 -0
- data/vendor/activerecord/test/cases/associations/has_one_associations_test.rb +362 -0
- data/vendor/activerecord/test/cases/associations/has_one_through_associations_test.rb +161 -0
- data/vendor/activerecord/test/cases/associations/inner_join_association_test.rb +88 -0
- data/vendor/activerecord/test/cases/associations/join_model_test.rb +714 -0
- data/vendor/activerecord/test/cases/associations_test.rb +262 -0
- data/vendor/activerecord/test/cases/attribute_methods_test.rb +293 -0
- data/vendor/activerecord/test/cases/base_test.rb +2087 -0
- data/vendor/activerecord/test/cases/binary_test.rb +30 -0
- data/vendor/activerecord/test/cases/calculations_test.rb +328 -0
- data/vendor/activerecord/test/cases/callbacks_observers_test.rb +38 -0
- data/vendor/activerecord/test/cases/callbacks_test.rb +400 -0
- data/vendor/activerecord/test/cases/class_inheritable_attributes_test.rb +32 -0
- data/vendor/activerecord/test/cases/column_alias_test.rb +17 -0
- data/vendor/activerecord/test/cases/column_definition_test.rb +36 -0
- data/vendor/activerecord/test/cases/connection_test_firebird.rb +8 -0
- data/vendor/activerecord/test/cases/connection_test_mysql.rb +30 -0
- data/vendor/activerecord/test/cases/copy_table_test_sqlite.rb +69 -0
- data/vendor/activerecord/test/cases/database_statements_test.rb +12 -0
- data/vendor/activerecord/test/cases/datatype_test_postgresql.rb +203 -0
- data/vendor/activerecord/test/cases/date_time_test.rb +37 -0
- data/vendor/activerecord/test/cases/default_test_firebird.rb +16 -0
- data/vendor/activerecord/test/cases/defaults_test.rb +100 -0
- data/vendor/activerecord/test/cases/deprecated_finder_test.rb +30 -0
- data/vendor/activerecord/test/cases/dirty_test.rb +270 -0
- data/vendor/activerecord/test/cases/finder_respond_to_test.rb +76 -0
- data/vendor/activerecord/test/cases/finder_test.rb +1048 -0
- data/vendor/activerecord/test/cases/fixtures_test.rb +655 -0
- data/vendor/activerecord/test/cases/helper.rb +62 -0
- data/vendor/activerecord/test/cases/i18n_test.rb +41 -0
- data/vendor/activerecord/test/cases/inheritance_test.rb +262 -0
- data/vendor/activerecord/test/cases/invalid_date_test.rb +24 -0
- data/vendor/activerecord/test/cases/json_serialization_test.rb +205 -0
- data/vendor/activerecord/test/cases/lifecycle_test.rb +193 -0
- data/vendor/activerecord/test/cases/locking_test.rb +304 -0
- data/vendor/activerecord/test/cases/method_scoping_test.rb +569 -0
- data/vendor/activerecord/test/cases/migration_test.rb +1479 -0
- data/vendor/activerecord/test/cases/migration_test_firebird.rb +124 -0
- data/vendor/activerecord/test/cases/mixin_test.rb +96 -0
- data/vendor/activerecord/test/cases/modules_test.rb +39 -0
- data/vendor/activerecord/test/cases/multiple_db_test.rb +85 -0
- data/vendor/activerecord/test/cases/named_scope_test.rb +280 -0
- data/vendor/activerecord/test/cases/pk_test.rb +101 -0
- data/vendor/activerecord/test/cases/pooled_connections_test.rb +103 -0
- data/vendor/activerecord/test/cases/query_cache_test.rb +127 -0
- data/vendor/activerecord/test/cases/readonly_test.rb +107 -0
- data/vendor/activerecord/test/cases/reflection_test.rb +184 -0
- data/vendor/activerecord/test/cases/reload_models_test.rb +20 -0
- data/vendor/activerecord/test/cases/reserved_word_test_mysql.rb +176 -0
- data/vendor/activerecord/test/cases/sanitize_test.rb +25 -0
- data/vendor/activerecord/test/cases/schema_authorization_test_postgresql.rb +75 -0
- data/vendor/activerecord/test/cases/schema_dumper_test.rb +184 -0
- data/vendor/activerecord/test/cases/schema_test_postgresql.rb +102 -0
- data/vendor/activerecord/test/cases/serialization_test.rb +47 -0
- data/vendor/activerecord/test/cases/synonym_test_oracle.rb +17 -0
- data/vendor/activerecord/test/cases/transactions_test.rb +357 -0
- data/vendor/activerecord/test/cases/unconnected_test.rb +32 -0
- data/vendor/activerecord/test/cases/validations_i18n_test.rb +921 -0
- data/vendor/activerecord/test/cases/validations_test.rb +1552 -0
- data/vendor/activerecord/test/cases/xml_serialization_test.rb +202 -0
- data/vendor/activerecord/test/config.rb +5 -0
- data/vendor/activerecord/test/connections/native_db2/connection.rb +25 -0
- data/vendor/activerecord/test/connections/native_firebird/connection.rb +26 -0
- data/vendor/activerecord/test/connections/native_frontbase/connection.rb +27 -0
- data/vendor/activerecord/test/connections/native_mysql/connection.rb +25 -0
- data/vendor/activerecord/test/connections/native_openbase/connection.rb +21 -0
- data/vendor/activerecord/test/connections/native_oracle/connection.rb +27 -0
- data/vendor/activerecord/test/connections/native_postgresql/connection.rb +21 -0
- data/vendor/activerecord/test/connections/native_sqlite/connection.rb +25 -0
- data/vendor/activerecord/test/connections/native_sqlite3/connection.rb +25 -0
- data/vendor/activerecord/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
- data/vendor/activerecord/test/connections/native_sybase/connection.rb +23 -0
- data/vendor/activerecord/test/fixtures/accounts.yml +28 -0
- data/vendor/activerecord/test/fixtures/all/developers.yml +0 -0
- data/vendor/activerecord/test/fixtures/all/people.csv +0 -0
- data/vendor/activerecord/test/fixtures/all/tasks.yml +0 -0
- data/vendor/activerecord/test/fixtures/author_addresses.yml +5 -0
- data/vendor/activerecord/test/fixtures/author_favorites.yml +4 -0
- data/vendor/activerecord/test/fixtures/authors.yml +9 -0
- data/vendor/activerecord/test/fixtures/binaries.yml +132 -0
- data/vendor/activerecord/test/fixtures/books.yml +7 -0
- data/vendor/activerecord/test/fixtures/categories.yml +14 -0
- data/vendor/activerecord/test/fixtures/categories/special_categories.yml +9 -0
- data/vendor/activerecord/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/vendor/activerecord/test/fixtures/categories_ordered.yml +7 -0
- data/vendor/activerecord/test/fixtures/categories_posts.yml +23 -0
- data/vendor/activerecord/test/fixtures/categorizations.yml +17 -0
- data/vendor/activerecord/test/fixtures/clubs.yml +6 -0
- data/vendor/activerecord/test/fixtures/comments.yml +59 -0
- data/vendor/activerecord/test/fixtures/companies.yml +56 -0
- data/vendor/activerecord/test/fixtures/computers.yml +4 -0
- data/vendor/activerecord/test/fixtures/courses.yml +7 -0
- data/vendor/activerecord/test/fixtures/customers.yml +26 -0
- data/vendor/activerecord/test/fixtures/developers.yml +21 -0
- data/vendor/activerecord/test/fixtures/developers_projects.yml +17 -0
- data/vendor/activerecord/test/fixtures/edges.yml +6 -0
- data/vendor/activerecord/test/fixtures/entrants.yml +14 -0
- data/vendor/activerecord/test/fixtures/fixture_database.sqlite3 +0 -0
- data/vendor/activerecord/test/fixtures/fixture_database_2.sqlite3 +0 -0
- data/vendor/activerecord/test/fixtures/fk_test_has_fk.yml +3 -0
- data/vendor/activerecord/test/fixtures/fk_test_has_pk.yml +2 -0
- data/vendor/activerecord/test/fixtures/funny_jokes.yml +10 -0
- data/vendor/activerecord/test/fixtures/items.yml +4 -0
- data/vendor/activerecord/test/fixtures/jobs.yml +7 -0
- data/vendor/activerecord/test/fixtures/legacy_things.yml +3 -0
- data/vendor/activerecord/test/fixtures/mateys.yml +4 -0
- data/vendor/activerecord/test/fixtures/members.yml +4 -0
- data/vendor/activerecord/test/fixtures/memberships.yml +20 -0
- data/vendor/activerecord/test/fixtures/minimalistics.yml +2 -0
- data/vendor/activerecord/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/vendor/activerecord/test/fixtures/mixins.yml +29 -0
- data/vendor/activerecord/test/fixtures/movies.yml +7 -0
- data/vendor/activerecord/test/fixtures/naked/csv/accounts.csv +1 -0
- data/vendor/activerecord/test/fixtures/naked/yml/accounts.yml +1 -0
- data/vendor/activerecord/test/fixtures/naked/yml/companies.yml +1 -0
- data/vendor/activerecord/test/fixtures/naked/yml/courses.yml +1 -0
- data/vendor/activerecord/test/fixtures/organizations.yml +5 -0
- data/vendor/activerecord/test/fixtures/owners.yml +7 -0
- data/vendor/activerecord/test/fixtures/parrots.yml +27 -0
- data/vendor/activerecord/test/fixtures/parrots_pirates.yml +7 -0
- data/vendor/activerecord/test/fixtures/people.yml +6 -0
- data/vendor/activerecord/test/fixtures/pets.yml +14 -0
- data/vendor/activerecord/test/fixtures/pirates.yml +9 -0
- data/vendor/activerecord/test/fixtures/posts.yml +49 -0
- data/vendor/activerecord/test/fixtures/price_estimates.yml +7 -0
- data/vendor/activerecord/test/fixtures/projects.yml +7 -0
- data/vendor/activerecord/test/fixtures/readers.yml +9 -0
- data/vendor/activerecord/test/fixtures/references.yml +17 -0
- data/vendor/activerecord/test/fixtures/reserved_words/distinct.yml +5 -0
- data/vendor/activerecord/test/fixtures/reserved_words/distincts_selects.yml +11 -0
- data/vendor/activerecord/test/fixtures/reserved_words/group.yml +14 -0
- data/vendor/activerecord/test/fixtures/reserved_words/select.yml +8 -0
- data/vendor/activerecord/test/fixtures/reserved_words/values.yml +7 -0
- data/vendor/activerecord/test/fixtures/ships.yml +5 -0
- data/vendor/activerecord/test/fixtures/sponsors.yml +9 -0
- data/vendor/activerecord/test/fixtures/subscribers.yml +7 -0
- data/vendor/activerecord/test/fixtures/subscriptions.yml +12 -0
- data/vendor/activerecord/test/fixtures/taggings.yml +28 -0
- data/vendor/activerecord/test/fixtures/tags.yml +7 -0
- data/vendor/activerecord/test/fixtures/tasks.yml +7 -0
- data/vendor/activerecord/test/fixtures/topics.yml +42 -0
- data/vendor/activerecord/test/fixtures/treasures.yml +10 -0
- data/vendor/activerecord/test/fixtures/vertices.yml +4 -0
- data/vendor/activerecord/test/fixtures/warehouse-things.yml +3 -0
- data/vendor/activerecord/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
- data/vendor/activerecord/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
- data/vendor/activerecord/test/migrations/duplicate/1_people_have_last_names.rb +9 -0
- data/vendor/activerecord/test/migrations/duplicate/2_we_need_reminders.rb +12 -0
- data/vendor/activerecord/test/migrations/duplicate/3_foo.rb +7 -0
- data/vendor/activerecord/test/migrations/duplicate/3_innocent_jointable.rb +12 -0
- data/vendor/activerecord/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
- data/vendor/activerecord/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
- data/vendor/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +12 -0
- data/vendor/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +9 -0
- data/vendor/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +12 -0
- data/vendor/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +9 -0
- data/vendor/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
- data/vendor/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
- data/vendor/activerecord/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
- data/vendor/activerecord/test/migrations/missing/1_people_have_last_names.rb +9 -0
- data/vendor/activerecord/test/migrations/missing/3_we_need_reminders.rb +12 -0
- data/vendor/activerecord/test/migrations/missing/4_innocent_jointable.rb +12 -0
- data/vendor/activerecord/test/migrations/valid/1_people_have_last_names.rb +9 -0
- data/vendor/activerecord/test/migrations/valid/2_we_need_reminders.rb +12 -0
- data/vendor/activerecord/test/migrations/valid/3_innocent_jointable.rb +12 -0
- data/vendor/activerecord/test/models/author.rb +140 -0
- data/vendor/activerecord/test/models/auto_id.rb +4 -0
- data/vendor/activerecord/test/models/binary.rb +2 -0
- data/vendor/activerecord/test/models/book.rb +4 -0
- data/vendor/activerecord/test/models/categorization.rb +5 -0
- data/vendor/activerecord/test/models/category.rb +33 -0
- data/vendor/activerecord/test/models/citation.rb +6 -0
- data/vendor/activerecord/test/models/club.rb +13 -0
- data/vendor/activerecord/test/models/column_name.rb +3 -0
- data/vendor/activerecord/test/models/comment.rb +25 -0
- data/vendor/activerecord/test/models/company.rb +156 -0
- data/vendor/activerecord/test/models/company_in_module.rb +61 -0
- data/vendor/activerecord/test/models/computer.rb +3 -0
- data/vendor/activerecord/test/models/contact.rb +16 -0
- data/vendor/activerecord/test/models/course.rb +3 -0
- data/vendor/activerecord/test/models/customer.rb +73 -0
- data/vendor/activerecord/test/models/default.rb +2 -0
- data/vendor/activerecord/test/models/developer.rb +79 -0
- data/vendor/activerecord/test/models/edge.rb +5 -0
- data/vendor/activerecord/test/models/entrant.rb +3 -0
- data/vendor/activerecord/test/models/guid.rb +2 -0
- data/vendor/activerecord/test/models/item.rb +7 -0
- data/vendor/activerecord/test/models/job.rb +5 -0
- data/vendor/activerecord/test/models/joke.rb +3 -0
- data/vendor/activerecord/test/models/keyboard.rb +3 -0
- data/vendor/activerecord/test/models/legacy_thing.rb +3 -0
- data/vendor/activerecord/test/models/matey.rb +4 -0
- data/vendor/activerecord/test/models/member.rb +11 -0
- data/vendor/activerecord/test/models/member_detail.rb +4 -0
- data/vendor/activerecord/test/models/membership.rb +9 -0
- data/vendor/activerecord/test/models/minimalistic.rb +2 -0
- data/vendor/activerecord/test/models/mixed_case_monkey.rb +3 -0
- data/vendor/activerecord/test/models/movie.rb +5 -0
- data/vendor/activerecord/test/models/order.rb +4 -0
- data/vendor/activerecord/test/models/organization.rb +4 -0
- data/vendor/activerecord/test/models/owner.rb +4 -0
- data/vendor/activerecord/test/models/parrot.rb +14 -0
- data/vendor/activerecord/test/models/person.rb +10 -0
- data/vendor/activerecord/test/models/pet.rb +4 -0
- data/vendor/activerecord/test/models/pirate.rb +9 -0
- data/vendor/activerecord/test/models/post.rb +88 -0
- data/vendor/activerecord/test/models/price_estimate.rb +3 -0
- data/vendor/activerecord/test/models/project.rb +29 -0
- data/vendor/activerecord/test/models/reader.rb +4 -0
- data/vendor/activerecord/test/models/reference.rb +4 -0
- data/vendor/activerecord/test/models/reply.rb +39 -0
- data/vendor/activerecord/test/models/ship.rb +3 -0
- data/vendor/activerecord/test/models/sponsor.rb +4 -0
- data/vendor/activerecord/test/models/subject.rb +4 -0
- data/vendor/activerecord/test/models/subscriber.rb +8 -0
- data/vendor/activerecord/test/models/subscription.rb +4 -0
- data/vendor/activerecord/test/models/tag.rb +7 -0
- data/vendor/activerecord/test/models/tagging.rb +10 -0
- data/vendor/activerecord/test/models/task.rb +3 -0
- data/vendor/activerecord/test/models/topic.rb +69 -0
- data/vendor/activerecord/test/models/treasure.rb +6 -0
- data/vendor/activerecord/test/models/vertex.rb +9 -0
- data/vendor/activerecord/test/models/warehouse_thing.rb +5 -0
- data/vendor/activerecord/test/schema/mysql_specific_schema.rb +12 -0
- data/vendor/activerecord/test/schema/postgresql_specific_schema.rb +103 -0
- data/vendor/activerecord/test/schema/schema.rb +440 -0
- data/vendor/activerecord/test/schema/schema2.rb +6 -0
- data/vendor/activerecord/test/schema/sqlite_specific_schema.rb +25 -0
- data/vendor/activesupport/CHANGELOG +1257 -0
- data/vendor/activesupport/README +43 -0
- data/vendor/activesupport/lib/active_support.rb +61 -0
- data/vendor/activesupport/lib/active_support/base64.rb +33 -0
- data/vendor/activesupport/lib/active_support/basic_object.rb +24 -0
- data/vendor/activesupport/lib/active_support/buffered_logger.rb +122 -0
- data/vendor/activesupport/lib/active_support/cache.rb +223 -0
- data/vendor/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
- data/vendor/activesupport/lib/active_support/cache/drb_store.rb +15 -0
- data/vendor/activesupport/lib/active_support/cache/file_store.rb +72 -0
- data/vendor/activesupport/lib/active_support/cache/mem_cache_store.rb +127 -0
- data/vendor/activesupport/lib/active_support/cache/memory_store.rb +52 -0
- data/vendor/activesupport/lib/active_support/cache/synchronized_memory_store.rb +47 -0
- data/vendor/activesupport/lib/active_support/callbacks.rb +280 -0
- data/vendor/activesupport/lib/active_support/core_ext.rb +4 -0
- data/vendor/activesupport/lib/active_support/core_ext/array.rb +13 -0
- data/vendor/activesupport/lib/active_support/core_ext/array/access.rb +53 -0
- data/vendor/activesupport/lib/active_support/core_ext/array/conversions.rb +183 -0
- data/vendor/activesupport/lib/active_support/core_ext/array/extract_options.rb +20 -0
- data/vendor/activesupport/lib/active_support/core_ext/array/grouping.rb +106 -0
- data/vendor/activesupport/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/vendor/activesupport/lib/active_support/core_ext/base64.rb +4 -0
- data/vendor/activesupport/lib/active_support/core_ext/base64/encoding.rb +16 -0
- data/vendor/activesupport/lib/active_support/core_ext/benchmark.rb +12 -0
- data/vendor/activesupport/lib/active_support/core_ext/bigdecimal.rb +6 -0
- data/vendor/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb +37 -0
- data/vendor/activesupport/lib/active_support/core_ext/blank.rb +58 -0
- data/vendor/activesupport/lib/active_support/core_ext/cgi.rb +5 -0
- data/vendor/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
- data/vendor/activesupport/lib/active_support/core_ext/class.rb +4 -0
- data/vendor/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +54 -0
- data/vendor/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb +46 -0
- data/vendor/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/vendor/activesupport/lib/active_support/core_ext/class/removal.rb +50 -0
- data/vendor/activesupport/lib/active_support/core_ext/date.rb +10 -0
- data/vendor/activesupport/lib/active_support/core_ext/date/behavior.rb +42 -0
- data/vendor/activesupport/lib/active_support/core_ext/date/calculations.rb +230 -0
- data/vendor/activesupport/lib/active_support/core_ext/date/conversions.rb +107 -0
- data/vendor/activesupport/lib/active_support/core_ext/date_time.rb +12 -0
- data/vendor/activesupport/lib/active_support/core_ext/date_time/calculations.rb +126 -0
- data/vendor/activesupport/lib/active_support/core_ext/date_time/conversions.rb +96 -0
- data/vendor/activesupport/lib/active_support/core_ext/duplicable.rb +43 -0
- data/vendor/activesupport/lib/active_support/core_ext/enumerable.rb +107 -0
- data/vendor/activesupport/lib/active_support/core_ext/exception.rb +41 -0
- data/vendor/activesupport/lib/active_support/core_ext/file.rb +5 -0
- data/vendor/activesupport/lib/active_support/core_ext/file/atomic.rb +46 -0
- data/vendor/activesupport/lib/active_support/core_ext/float.rb +7 -0
- data/vendor/activesupport/lib/active_support/core_ext/float/rounding.rb +24 -0
- data/vendor/activesupport/lib/active_support/core_ext/float/time.rb +27 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash.rb +14 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/conversions.rb +259 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/except.rb +25 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/keys.rb +52 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
- data/vendor/activesupport/lib/active_support/core_ext/hash/slice.rb +33 -0
- data/vendor/activesupport/lib/active_support/core_ext/integer.rb +9 -0
- data/vendor/activesupport/lib/active_support/core_ext/integer/even_odd.rb +29 -0
- data/vendor/activesupport/lib/active_support/core_ext/integer/inflections.rb +20 -0
- data/vendor/activesupport/lib/active_support/core_ext/integer/time.rb +45 -0
- data/vendor/activesupport/lib/active_support/core_ext/kernel.rb +5 -0
- data/vendor/activesupport/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/vendor/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb +7 -0
- data/vendor/activesupport/lib/active_support/core_ext/kernel/debugger.rb +13 -0
- data/vendor/activesupport/lib/active_support/core_ext/kernel/reporting.rb +59 -0
- data/vendor/activesupport/lib/active_support/core_ext/kernel/requires.rb +24 -0
- data/vendor/activesupport/lib/active_support/core_ext/load_error.rb +38 -0
- data/vendor/activesupport/lib/active_support/core_ext/logger.rb +143 -0
- data/vendor/activesupport/lib/active_support/core_ext/module.rb +23 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/aliasing.rb +74 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/attr_internal.rb +32 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +58 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/delegation.rb +95 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/inclusion.rb +30 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/introspection.rb +90 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/loading.rb +23 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/model_naming.rb +23 -0
- data/vendor/activesupport/lib/active_support/core_ext/module/synchronization.rb +39 -0
- data/vendor/activesupport/lib/active_support/core_ext/name_error.rb +17 -0
- data/vendor/activesupport/lib/active_support/core_ext/numeric.rb +9 -0
- data/vendor/activesupport/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/vendor/activesupport/lib/active_support/core_ext/numeric/conversions.rb +19 -0
- data/vendor/activesupport/lib/active_support/core_ext/numeric/time.rb +81 -0
- data/vendor/activesupport/lib/active_support/core_ext/object.rb +5 -0
- data/vendor/activesupport/lib/active_support/core_ext/object/conversions.rb +14 -0
- data/vendor/activesupport/lib/active_support/core_ext/object/extending.rb +80 -0
- data/vendor/activesupport/lib/active_support/core_ext/object/instance_variables.rb +74 -0
- data/vendor/activesupport/lib/active_support/core_ext/object/metaclass.rb +13 -0
- data/vendor/activesupport/lib/active_support/core_ext/object/misc.rb +74 -0
- data/vendor/activesupport/lib/active_support/core_ext/pathname.rb +7 -0
- data/vendor/activesupport/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
- data/vendor/activesupport/lib/active_support/core_ext/proc.rb +12 -0
- data/vendor/activesupport/lib/active_support/core_ext/process.rb +1 -0
- data/vendor/activesupport/lib/active_support/core_ext/process/daemon.rb +25 -0
- data/vendor/activesupport/lib/active_support/core_ext/range.rb +11 -0
- data/vendor/activesupport/lib/active_support/core_ext/range/blockless_step.rb +32 -0
- data/vendor/activesupport/lib/active_support/core_ext/range/conversions.rb +27 -0
- data/vendor/activesupport/lib/active_support/core_ext/range/include_range.rb +30 -0
- data/vendor/activesupport/lib/active_support/core_ext/range/overlaps.rb +15 -0
- data/vendor/activesupport/lib/active_support/core_ext/rexml.rb +36 -0
- data/vendor/activesupport/lib/active_support/core_ext/string.rb +22 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/access.rb +82 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/behavior.rb +13 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/conversions.rb +28 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/filters.rb +26 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/inflections.rb +167 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/iterators.rb +21 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/multibyte.rb +81 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb +35 -0
- data/vendor/activesupport/lib/active_support/core_ext/string/xchar.rb +11 -0
- data/vendor/activesupport/lib/active_support/core_ext/symbol.rb +14 -0
- data/vendor/activesupport/lib/active_support/core_ext/time.rb +42 -0
- data/vendor/activesupport/lib/active_support/core_ext/time/behavior.rb +13 -0
- data/vendor/activesupport/lib/active_support/core_ext/time/calculations.rb +303 -0
- data/vendor/activesupport/lib/active_support/core_ext/time/conversions.rb +90 -0
- data/vendor/activesupport/lib/active_support/core_ext/time/zones.rb +86 -0
- data/vendor/activesupport/lib/active_support/dependencies.rb +621 -0
- data/vendor/activesupport/lib/active_support/deprecation.rb +243 -0
- data/vendor/activesupport/lib/active_support/duration.rb +96 -0
- data/vendor/activesupport/lib/active_support/gzip.rb +25 -0
- data/vendor/activesupport/lib/active_support/inflections.rb +55 -0
- data/vendor/activesupport/lib/active_support/inflector.rb +397 -0
- data/vendor/activesupport/lib/active_support/json.rb +23 -0
- data/vendor/activesupport/lib/active_support/json/decoding.rb +63 -0
- data/vendor/activesupport/lib/active_support/json/encoders/date.rb +21 -0
- data/vendor/activesupport/lib/active_support/json/encoders/date_time.rb +21 -0
- data/vendor/activesupport/lib/active_support/json/encoders/enumerable.rb +12 -0
- data/vendor/activesupport/lib/active_support/json/encoders/false_class.rb +5 -0
- data/vendor/activesupport/lib/active_support/json/encoders/hash.rb +47 -0
- data/vendor/activesupport/lib/active_support/json/encoders/nil_class.rb +5 -0
- data/vendor/activesupport/lib/active_support/json/encoders/numeric.rb +5 -0
- data/vendor/activesupport/lib/active_support/json/encoders/object.rb +6 -0
- data/vendor/activesupport/lib/active_support/json/encoders/regexp.rb +5 -0
- data/vendor/activesupport/lib/active_support/json/encoders/string.rb +36 -0
- data/vendor/activesupport/lib/active_support/json/encoders/symbol.rb +5 -0
- data/vendor/activesupport/lib/active_support/json/encoders/time.rb +21 -0
- data/vendor/activesupport/lib/active_support/json/encoders/true_class.rb +5 -0
- data/vendor/activesupport/lib/active_support/json/encoding.rb +37 -0
- data/vendor/activesupport/lib/active_support/json/variable.rb +10 -0
- data/vendor/activesupport/lib/active_support/locale/en.yml +32 -0
- data/vendor/activesupport/lib/active_support/memoizable.rb +82 -0
- data/vendor/activesupport/lib/active_support/multibyte.rb +33 -0
- data/vendor/activesupport/lib/active_support/multibyte/chars.rb +679 -0
- data/vendor/activesupport/lib/active_support/multibyte/exceptions.rb +8 -0
- data/vendor/activesupport/lib/active_support/multibyte/unicode_database.rb +71 -0
- data/vendor/activesupport/lib/active_support/option_merger.rb +17 -0
- data/vendor/activesupport/lib/active_support/ordered_hash.rb +58 -0
- data/vendor/activesupport/lib/active_support/ordered_options.rb +19 -0
- data/vendor/activesupport/lib/active_support/rescuable.rb +108 -0
- data/vendor/activesupport/lib/active_support/secure_random.rb +197 -0
- data/vendor/activesupport/lib/active_support/string_inquirer.rb +21 -0
- data/vendor/activesupport/lib/active_support/test_case.rb +24 -0
- data/vendor/activesupport/lib/active_support/testing/core_ext/test.rb +6 -0
- data/vendor/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb +72 -0
- data/vendor/activesupport/lib/active_support/testing/default.rb +9 -0
- data/vendor/activesupport/lib/active_support/testing/performance.rb +452 -0
- data/vendor/activesupport/lib/active_support/testing/setup_and_teardown.rb +120 -0
- data/vendor/activesupport/lib/active_support/time_with_zone.rb +328 -0
- data/vendor/activesupport/lib/active_support/values/time_zone.rb +403 -0
- data/vendor/activesupport/lib/active_support/values/unicode_tables.dat +0 -0
- data/vendor/activesupport/lib/active_support/vendor.rb +34 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/vendor/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb +194 -0
- data/vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +216 -0
- data/vendor/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb +53 -0
- data/vendor/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb +849 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +33 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +47 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +228 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +55 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +219 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +40 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +18 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +22 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +23 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +23 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +23 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +283 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +136 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +204 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +161 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +27 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +274 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +194 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +22 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +35 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +232 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +139 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +144 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +131 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +282 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +30 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +74 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +205 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +171 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +288 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +196 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +67 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +73 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +161 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +20 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +33 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +30 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +27 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +30 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +20 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +30 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +20 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +25 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +18 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +18 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +24 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +18 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +34 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +35 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +33 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +59 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +47 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +121 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +30 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +33 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +165 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +270 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +187 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +35 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +29 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +193 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +185 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +37 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +185 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +16 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +185 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +188 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +13 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +232 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +181 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +197 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +276 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +163 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +218 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +168 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +268 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +288 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +211 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +170 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +181 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +232 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +187 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +176 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +215 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +13 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +173 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +165 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +172 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +183 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +170 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +212 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +13 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +202 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +23 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +22 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +20 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +25 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +25 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +52 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +51 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +44 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +98 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +56 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +292 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +508 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +56 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +40 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +94 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +198 -0
- data/vendor/activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +129 -0
- data/vendor/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/vendor/activesupport/lib/active_support/version.rb +9 -0
- data/vendor/activesupport/lib/active_support/whiny_nil.rb +58 -0
- data/vendor/activesupport/lib/activesupport.rb +1 -0
- data/vendor/isaac/LICENSE +26 -0
- data/vendor/isaac/README +78 -0
- data/vendor/isaac/TODO +3 -0
- data/vendor/isaac/VERSIONS +3 -0
- data/vendor/isaac/crypt/ISAAC.rb +171 -0
- data/vendor/isaac/isaac.gemspec +39 -0
- data/vendor/isaac/setup.rb +596 -0
- data/vendor/isaac/test/TC_ISAAC.rb +76 -0
- data/vendor/json/CHANGES +93 -0
- data/vendor/json/GPL +340 -0
- data/vendor/json/README +78 -0
- data/vendor/json/RUBY +58 -0
- data/vendor/json/Rakefile +309 -0
- data/vendor/json/TODO +1 -0
- data/vendor/json/VERSION +1 -0
- data/vendor/json/benchmarks/benchmark.txt +133 -0
- data/vendor/json/benchmarks/benchmark_generator.rb +48 -0
- data/vendor/json/benchmarks/benchmark_parser.rb +26 -0
- data/vendor/json/benchmarks/benchmark_rails.rb +26 -0
- data/vendor/json/bin/edit_json.rb +10 -0
- data/vendor/json/bin/prettify_json.rb +76 -0
- data/vendor/json/data/example.json +1 -0
- data/vendor/json/data/index.html +38 -0
- data/vendor/json/data/prototype.js +4184 -0
- data/vendor/json/ext/json/ext/generator/extconf.rb +9 -0
- data/vendor/json/ext/json/ext/generator/generator.c +875 -0
- data/vendor/json/ext/json/ext/generator/unicode.c +182 -0
- data/vendor/json/ext/json/ext/generator/unicode.h +53 -0
- data/vendor/json/ext/json/ext/parser/extconf.rb +9 -0
- data/vendor/json/ext/json/ext/parser/parser.c +1758 -0
- data/vendor/json/ext/json/ext/parser/parser.rl +638 -0
- data/vendor/json/ext/json/ext/parser/unicode.c +154 -0
- data/vendor/json/ext/json/ext/parser/unicode.h +58 -0
- data/vendor/json/install.rb +26 -0
- data/vendor/json/lib/json.rb +235 -0
- data/vendor/json/lib/json/Array.xpm +21 -0
- data/vendor/json/lib/json/FalseClass.xpm +21 -0
- data/vendor/json/lib/json/Hash.xpm +21 -0
- data/vendor/json/lib/json/Key.xpm +73 -0
- data/vendor/json/lib/json/NilClass.xpm +21 -0
- data/vendor/json/lib/json/Numeric.xpm +28 -0
- data/vendor/json/lib/json/String.xpm +96 -0
- data/vendor/json/lib/json/TrueClass.xpm +21 -0
- data/vendor/json/lib/json/add/core.rb +135 -0
- data/vendor/json/lib/json/add/rails.rb +58 -0
- data/vendor/json/lib/json/common.rb +354 -0
- data/vendor/json/lib/json/editor.rb +1362 -0
- data/vendor/json/lib/json/ext.rb +13 -0
- data/vendor/json/lib/json/json.xpm +1499 -0
- data/vendor/json/lib/json/pure.rb +75 -0
- data/vendor/json/lib/json/pure/generator.rb +394 -0
- data/vendor/json/lib/json/pure/parser.rb +259 -0
- data/vendor/json/lib/json/version.rb +9 -0
- data/vendor/json/tests/fixtures/fail1.json +1 -0
- data/vendor/json/tests/fixtures/fail10.json +1 -0
- data/vendor/json/tests/fixtures/fail11.json +1 -0
- data/vendor/json/tests/fixtures/fail12.json +1 -0
- data/vendor/json/tests/fixtures/fail13.json +1 -0
- data/vendor/json/tests/fixtures/fail14.json +1 -0
- data/vendor/json/tests/fixtures/fail18.json +1 -0
- data/vendor/json/tests/fixtures/fail19.json +1 -0
- data/vendor/json/tests/fixtures/fail2.json +1 -0
- data/vendor/json/tests/fixtures/fail20.json +1 -0
- data/vendor/json/tests/fixtures/fail21.json +1 -0
- data/vendor/json/tests/fixtures/fail22.json +1 -0
- data/vendor/json/tests/fixtures/fail23.json +1 -0
- data/vendor/json/tests/fixtures/fail24.json +1 -0
- data/vendor/json/tests/fixtures/fail25.json +1 -0
- data/vendor/json/tests/fixtures/fail27.json +2 -0
- data/vendor/json/tests/fixtures/fail28.json +2 -0
- data/vendor/json/tests/fixtures/fail3.json +1 -0
- data/vendor/json/tests/fixtures/fail4.json +1 -0
- data/vendor/json/tests/fixtures/fail5.json +1 -0
- data/vendor/json/tests/fixtures/fail6.json +1 -0
- data/vendor/json/tests/fixtures/fail7.json +1 -0
- data/vendor/json/tests/fixtures/fail8.json +1 -0
- data/vendor/json/tests/fixtures/fail9.json +1 -0
- data/vendor/json/tests/fixtures/pass1.json +56 -0
- data/vendor/json/tests/fixtures/pass15.json +1 -0
- data/vendor/json/tests/fixtures/pass16.json +1 -0
- data/vendor/json/tests/fixtures/pass17.json +1 -0
- data/vendor/json/tests/fixtures/pass2.json +1 -0
- data/vendor/json/tests/fixtures/pass26.json +1 -0
- data/vendor/json/tests/fixtures/pass3.json +6 -0
- data/vendor/json/tests/runner.rb +25 -0
- data/vendor/json/tests/test_json.rb +293 -0
- data/vendor/json/tests/test_json_addition.rb +161 -0
- data/vendor/json/tests/test_json_fixtures.rb +30 -0
- data/vendor/json/tests/test_json_generate.rb +100 -0
- data/vendor/json/tests/test_json_rails.rb +118 -0
- data/vendor/json/tests/test_json_unicode.rb +61 -0
- data/vendor/json/tools/fuzz.rb +140 -0
- data/vendor/json/tools/server.rb +62 -0
- data/vendor/rack/AUTHORS +8 -0
- data/vendor/rack/COPYING +18 -0
- data/vendor/rack/KNOWN-ISSUES +18 -0
- data/vendor/rack/RDOX +324 -0
- data/vendor/rack/README +306 -0
- data/vendor/rack/Rakefile +188 -0
- data/vendor/rack/SPEC +129 -0
- data/vendor/rack/bin/rackup +172 -0
- data/vendor/rack/contrib/rack_logo.svg +111 -0
- data/vendor/rack/example/lobster.ru +4 -0
- data/vendor/rack/example/protectedlobster.rb +14 -0
- data/vendor/rack/example/protectedlobster.ru +8 -0
- data/vendor/rack/lib/rack.rb +86 -0
- data/vendor/rack/lib/rack/adapter/camping.rb +22 -0
- data/vendor/rack/lib/rack/auth/abstract/handler.rb +28 -0
- data/vendor/rack/lib/rack/auth/abstract/request.rb +37 -0
- data/vendor/rack/lib/rack/auth/basic.rb +58 -0
- data/vendor/rack/lib/rack/auth/digest/md5.rb +124 -0
- data/vendor/rack/lib/rack/auth/digest/nonce.rb +51 -0
- data/vendor/rack/lib/rack/auth/digest/params.rb +55 -0
- data/vendor/rack/lib/rack/auth/digest/request.rb +40 -0
- data/vendor/rack/lib/rack/auth/openid.rb +438 -0
- data/vendor/rack/lib/rack/builder.rb +67 -0
- data/vendor/rack/lib/rack/cascade.rb +36 -0
- data/vendor/rack/lib/rack/commonlogger.rb +61 -0
- data/vendor/rack/lib/rack/conditionalget.rb +43 -0
- data/vendor/rack/lib/rack/content_length.rb +25 -0
- data/vendor/rack/lib/rack/deflater.rb +87 -0
- data/vendor/rack/lib/rack/directory.rb +150 -0
- data/vendor/rack/lib/rack/file.rb +85 -0
- data/vendor/rack/lib/rack/handler.rb +48 -0
- data/vendor/rack/lib/rack/handler/cgi.rb +57 -0
- data/vendor/rack/lib/rack/handler/evented_mongrel.rb +8 -0
- data/vendor/rack/lib/rack/handler/fastcgi.rb +86 -0
- data/vendor/rack/lib/rack/handler/lsws.rb +52 -0
- data/vendor/rack/lib/rack/handler/mongrel.rb +82 -0
- data/vendor/rack/lib/rack/handler/scgi.rb +57 -0
- data/vendor/rack/lib/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/vendor/rack/lib/rack/handler/thin.rb +15 -0
- data/vendor/rack/lib/rack/handler/webrick.rb +61 -0
- data/vendor/rack/lib/rack/head.rb +19 -0
- data/vendor/rack/lib/rack/lint.rb +465 -0
- data/vendor/rack/lib/rack/lobster.rb +65 -0
- data/vendor/rack/lib/rack/methodoverride.rb +27 -0
- data/vendor/rack/lib/rack/mime.rb +204 -0
- data/vendor/rack/lib/rack/mock.rb +160 -0
- data/vendor/rack/lib/rack/recursive.rb +57 -0
- data/vendor/rack/lib/rack/reloader.rb +64 -0
- data/vendor/rack/lib/rack/request.rb +218 -0
- data/vendor/rack/lib/rack/response.rb +171 -0
- data/vendor/rack/lib/rack/session/abstract/id.rb +153 -0
- data/vendor/rack/lib/rack/session/cookie.rb +89 -0
- data/vendor/rack/lib/rack/session/memcache.rb +97 -0
- data/vendor/rack/lib/rack/session/pool.rb +73 -0
- data/vendor/rack/lib/rack/showexceptions.rb +348 -0
- data/vendor/rack/lib/rack/showstatus.rb +106 -0
- data/vendor/rack/lib/rack/static.rb +38 -0
- data/vendor/rack/lib/rack/urlmap.rb +48 -0
- data/vendor/rack/lib/rack/utils.rb +347 -0
- data/vendor/rack/test/cgi/lighttpd.conf +20 -0
- data/vendor/rack/test/cgi/test +9 -0
- data/vendor/rack/test/cgi/test.fcgi +8 -0
- data/vendor/rack/test/cgi/test.ru +7 -0
- data/vendor/rack/test/spec_rack_auth_basic.rb +69 -0
- data/vendor/rack/test/spec_rack_auth_digest.rb +169 -0
- data/vendor/rack/test/spec_rack_auth_openid.rb +137 -0
- data/vendor/rack/test/spec_rack_builder.rb +84 -0
- data/vendor/rack/test/spec_rack_camping.rb +51 -0
- data/vendor/rack/test/spec_rack_cascade.rb +50 -0
- data/vendor/rack/test/spec_rack_cgi.rb +89 -0
- data/vendor/rack/test/spec_rack_commonlogger.rb +32 -0
- data/vendor/rack/test/spec_rack_conditionalget.rb +41 -0
- data/vendor/rack/test/spec_rack_content_length.rb +43 -0
- data/vendor/rack/test/spec_rack_deflater.rb +105 -0
- data/vendor/rack/test/spec_rack_directory.rb +61 -0
- data/vendor/rack/test/spec_rack_fastcgi.rb +89 -0
- data/vendor/rack/test/spec_rack_file.rb +64 -0
- data/vendor/rack/test/spec_rack_handler.rb +24 -0
- data/vendor/rack/test/spec_rack_head.rb +30 -0
- data/vendor/rack/test/spec_rack_lint.rb +380 -0
- data/vendor/rack/test/spec_rack_lobster.rb +45 -0
- data/vendor/rack/test/spec_rack_methodoverride.rb +60 -0
- data/vendor/rack/test/spec_rack_mock.rb +152 -0
- data/vendor/rack/test/spec_rack_mongrel.rb +189 -0
- data/vendor/rack/test/spec_rack_recursive.rb +77 -0
- data/vendor/rack/test/spec_rack_request.rb +446 -0
- data/vendor/rack/test/spec_rack_response.rb +174 -0
- data/vendor/rack/test/spec_rack_session_cookie.rb +82 -0
- data/vendor/rack/test/spec_rack_session_memcache.rb +132 -0
- data/vendor/rack/test/spec_rack_session_pool.rb +84 -0
- data/vendor/rack/test/spec_rack_showexceptions.rb +21 -0
- data/vendor/rack/test/spec_rack_showstatus.rb +72 -0
- data/vendor/rack/test/spec_rack_static.rb +37 -0
- data/vendor/rack/test/spec_rack_thin.rb +90 -0
- data/vendor/rack/test/spec_rack_urlmap.rb +175 -0
- data/vendor/rack/test/spec_rack_utils.rb +176 -0
- data/vendor/rack/test/spec_rack_webrick.rb +123 -0
- data/vendor/rack/test/testrequest.rb +57 -0
- data/vendor/sinatra/AUTHORS +40 -0
- data/vendor/sinatra/CHANGES +189 -0
- data/vendor/sinatra/LICENSE +22 -0
- data/vendor/sinatra/README.rdoc +552 -0
- data/vendor/sinatra/Rakefile +186 -0
- data/vendor/sinatra/compat/app_test.rb +300 -0
- data/vendor/sinatra/compat/application_test.rb +334 -0
- data/vendor/sinatra/compat/builder_test.rb +101 -0
- data/vendor/sinatra/compat/custom_error_test.rb +62 -0
- data/vendor/sinatra/compat/erb_test.rb +136 -0
- data/vendor/sinatra/compat/events_test.rb +78 -0
- data/vendor/sinatra/compat/filter_test.rb +30 -0
- data/vendor/sinatra/compat/haml_test.rb +233 -0
- data/vendor/sinatra/compat/helper.rb +30 -0
- data/vendor/sinatra/compat/mapped_error_test.rb +72 -0
- data/vendor/sinatra/compat/pipeline_test.rb +71 -0
- data/vendor/sinatra/compat/public/foo.xml +1 -0
- data/vendor/sinatra/compat/sass_test.rb +57 -0
- data/vendor/sinatra/compat/sessions_test.rb +39 -0
- data/vendor/sinatra/compat/streaming_test.rb +121 -0
- data/vendor/sinatra/compat/sym_params_test.rb +19 -0
- data/vendor/sinatra/compat/template_test.rb +30 -0
- data/vendor/sinatra/compat/use_in_file_templates_test.rb +47 -0
- data/vendor/sinatra/compat/views/foo.builder +1 -0
- data/vendor/sinatra/compat/views/foo.erb +1 -0
- data/vendor/sinatra/compat/views/foo.haml +1 -0
- data/vendor/sinatra/compat/views/foo.sass +2 -0
- data/vendor/sinatra/compat/views/foo_layout.erb +2 -0
- data/vendor/sinatra/compat/views/foo_layout.haml +2 -0
- data/vendor/sinatra/compat/views/layout_test/foo.builder +1 -0
- data/vendor/sinatra/compat/views/layout_test/foo.erb +1 -0
- data/vendor/sinatra/compat/views/layout_test/foo.haml +1 -0
- data/vendor/sinatra/compat/views/layout_test/foo.sass +2 -0
- data/vendor/sinatra/compat/views/layout_test/layout.builder +3 -0
- data/vendor/sinatra/compat/views/layout_test/layout.erb +1 -0
- data/vendor/sinatra/compat/views/layout_test/layout.haml +1 -0
- data/vendor/sinatra/compat/views/layout_test/layout.sass +2 -0
- data/vendor/sinatra/compat/views/no_layout/no_layout.builder +1 -0
- data/vendor/sinatra/compat/views/no_layout/no_layout.haml +1 -0
- data/vendor/sinatra/lib/sinatra.rb +8 -0
- data/vendor/sinatra/lib/sinatra/base.rb +843 -0
- data/vendor/sinatra/lib/sinatra/compat.rb +239 -0
- data/vendor/sinatra/lib/sinatra/images/404.png +0 -0
- data/vendor/sinatra/lib/sinatra/images/500.png +0 -0
- data/vendor/sinatra/lib/sinatra/main.rb +48 -0
- data/vendor/sinatra/lib/sinatra/test.rb +114 -0
- data/vendor/sinatra/lib/sinatra/test/bacon.rb +17 -0
- data/vendor/sinatra/lib/sinatra/test/rspec.rb +9 -0
- data/vendor/sinatra/lib/sinatra/test/spec.rb +9 -0
- data/vendor/sinatra/lib/sinatra/test/unit.rb +11 -0
- data/vendor/sinatra/sinatra.gemspec +110 -0
- data/vendor/sinatra/test/base_test.rb +68 -0
- data/vendor/sinatra/test/builder_test.rb +64 -0
- data/vendor/sinatra/test/data/reload_app_file.rb +3 -0
- data/vendor/sinatra/test/erb_test.rb +50 -0
- data/vendor/sinatra/test/filter_test.rb +75 -0
- data/vendor/sinatra/test/haml_test.rb +68 -0
- data/vendor/sinatra/test/helper.rb +25 -0
- data/vendor/sinatra/test/helpers_test.rb +361 -0
- data/vendor/sinatra/test/mapped_error_test.rb +160 -0
- data/vendor/sinatra/test/middleware_test.rb +58 -0
- data/vendor/sinatra/test/options_test.rb +97 -0
- data/vendor/sinatra/test/reload_test.rb +61 -0
- data/vendor/sinatra/test/request_test.rb +18 -0
- data/vendor/sinatra/test/result_test.rb +88 -0
- data/vendor/sinatra/test/routing_test.rb +391 -0
- data/vendor/sinatra/test/sass_test.rb +36 -0
- data/vendor/sinatra/test/sinatra_test.rb +13 -0
- data/vendor/sinatra/test/static_test.rb +57 -0
- data/vendor/sinatra/test/templates_test.rb +88 -0
- data/vendor/sinatra/test/views/hello.builder +1 -0
- data/vendor/sinatra/test/views/hello.erb +1 -0
- data/vendor/sinatra/test/views/hello.haml +1 -0
- data/vendor/sinatra/test/views/hello.sass +2 -0
- data/vendor/sinatra/test/views/hello.test +1 -0
- data/vendor/sinatra/test/views/layout2.builder +3 -0
- data/vendor/sinatra/test/views/layout2.erb +2 -0
- data/vendor/sinatra/test/views/layout2.haml +2 -0
- data/vendor/sinatra/test/views/layout2.test +1 -0
- metadata +1058 -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
|