factorylabs-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 +78 -0
- data/bin/castronaut +75 -0
- data/config/castronaut.example.yml +41 -0
- data/config/castronaut.sample.yml +40 -0
- data/config/castronaut.yml +40 -0
- data/config/nginx_vhost.conf +17 -0
- data/config/thin_config.yml +13 -0
- data/lib/castronaut.rb +50 -0
- data/lib/castronaut/adapters.rb +13 -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 +40 -0
- data/lib/castronaut/adapters/restful_authentication/adapter.rb +15 -0
- data/lib/castronaut/adapters/restful_authentication/user.rb +50 -0
- data/lib/castronaut/application.rb +1 -0
- data/lib/castronaut/application/application.rb +70 -0
- data/lib/castronaut/application/public/javascripts/application.js +3 -0
- data/lib/castronaut/application/public/javascripts/jquery.js +32 -0
- data/lib/castronaut/application/public/stylesheets/screen.css +122 -0
- data/lib/castronaut/application/views/layout.erb +27 -0
- data/lib/castronaut/application/views/login.erb +31 -0
- data/lib/castronaut/application/views/logout.erb +13 -0
- data/lib/castronaut/application/views/proxy_validate.erb +21 -0
- data/lib/castronaut/application/views/service_validate.erb +14 -0
- data/lib/castronaut/authentication_result.rb +24 -0
- data/lib/castronaut/configuration.rb +110 -0
- data/lib/castronaut/db/001_create_cas_database.rb +47 -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 +67 -0
- data/lib/castronaut/presenters/service_validate.rb +68 -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
- metadata +841 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
# Track unsaved attribute changes.
|
3
|
+
#
|
4
|
+
# A newly instantiated object is unchanged:
|
5
|
+
# person = Person.find_by_name('uncle bob')
|
6
|
+
# person.changed? # => false
|
7
|
+
#
|
8
|
+
# Change the name:
|
9
|
+
# person.name = 'Bob'
|
10
|
+
# person.changed? # => true
|
11
|
+
# person.name_changed? # => true
|
12
|
+
# person.name_was # => 'uncle bob'
|
13
|
+
# person.name_change # => ['uncle bob', 'Bob']
|
14
|
+
# person.name = 'Bill'
|
15
|
+
# person.name_change # => ['uncle bob', 'Bill']
|
16
|
+
#
|
17
|
+
# Save the changes:
|
18
|
+
# person.save
|
19
|
+
# person.changed? # => false
|
20
|
+
# person.name_changed? # => false
|
21
|
+
#
|
22
|
+
# Assigning the same value leaves the attribute unchanged:
|
23
|
+
# person.name = 'Bill'
|
24
|
+
# person.name_changed? # => false
|
25
|
+
# person.name_change # => nil
|
26
|
+
#
|
27
|
+
# Which attributes have changed?
|
28
|
+
# person.name = 'bob'
|
29
|
+
# person.changed # => ['name']
|
30
|
+
# person.changes # => { 'name' => ['Bill', 'bob'] }
|
31
|
+
#
|
32
|
+
# Before modifying an attribute in-place:
|
33
|
+
# person.name_will_change!
|
34
|
+
# person.name << 'by'
|
35
|
+
# person.name_change # => ['uncle bob', 'uncle bobby']
|
36
|
+
module Dirty
|
37
|
+
DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was']
|
38
|
+
|
39
|
+
def self.included(base)
|
40
|
+
base.attribute_method_suffix *DIRTY_SUFFIXES
|
41
|
+
base.alias_method_chain :write_attribute, :dirty
|
42
|
+
base.alias_method_chain :save, :dirty
|
43
|
+
base.alias_method_chain :save!, :dirty
|
44
|
+
base.alias_method_chain :update, :dirty
|
45
|
+
base.alias_method_chain :reload, :dirty
|
46
|
+
|
47
|
+
base.superclass_delegating_accessor :partial_updates
|
48
|
+
base.partial_updates = true
|
49
|
+
|
50
|
+
base.send(:extend, ClassMethods)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Do any attributes have unsaved changes?
|
54
|
+
# person.changed? # => false
|
55
|
+
# person.name = 'bob'
|
56
|
+
# person.changed? # => true
|
57
|
+
def changed?
|
58
|
+
!changed_attributes.empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
# List of attributes with unsaved changes.
|
62
|
+
# person.changed # => []
|
63
|
+
# person.name = 'bob'
|
64
|
+
# person.changed # => ['name']
|
65
|
+
def changed
|
66
|
+
changed_attributes.keys
|
67
|
+
end
|
68
|
+
|
69
|
+
# Map of changed attrs => [original value, new value].
|
70
|
+
# person.changes # => {}
|
71
|
+
# person.name = 'bob'
|
72
|
+
# person.changes # => { 'name' => ['bill', 'bob'] }
|
73
|
+
def changes
|
74
|
+
changed.inject({}) { |h, attr| h[attr] = attribute_change(attr); h }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Attempts to +save+ the record and clears changed attributes if successful.
|
78
|
+
def save_with_dirty(*args) #:nodoc:
|
79
|
+
if status = save_without_dirty(*args)
|
80
|
+
changed_attributes.clear
|
81
|
+
end
|
82
|
+
status
|
83
|
+
end
|
84
|
+
|
85
|
+
# Attempts to <tt>save!</tt> the record and clears changed attributes if successful.
|
86
|
+
def save_with_dirty!(*args) #:nodoc:
|
87
|
+
status = save_without_dirty!(*args)
|
88
|
+
changed_attributes.clear
|
89
|
+
status
|
90
|
+
end
|
91
|
+
|
92
|
+
# <tt>reload</tt> the record and clears changed attributes.
|
93
|
+
def reload_with_dirty(*args) #:nodoc:
|
94
|
+
record = reload_without_dirty(*args)
|
95
|
+
changed_attributes.clear
|
96
|
+
record
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
# Map of change <tt>attr => original value</tt>.
|
101
|
+
def changed_attributes
|
102
|
+
@changed_attributes ||= {}
|
103
|
+
end
|
104
|
+
|
105
|
+
# Handle <tt>*_changed?</tt> for +method_missing+.
|
106
|
+
def attribute_changed?(attr)
|
107
|
+
changed_attributes.include?(attr)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Handle <tt>*_change</tt> for +method_missing+.
|
111
|
+
def attribute_change(attr)
|
112
|
+
[changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Handle <tt>*_was</tt> for +method_missing+.
|
116
|
+
def attribute_was(attr)
|
117
|
+
attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Handle <tt>*_will_change!</tt> for +method_missing+.
|
121
|
+
def attribute_will_change!(attr)
|
122
|
+
changed_attributes[attr] = clone_attribute_value(:read_attribute, attr)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Wrap write_attribute to remember original attribute value.
|
126
|
+
def write_attribute_with_dirty(attr, value)
|
127
|
+
attr = attr.to_s
|
128
|
+
|
129
|
+
# The attribute already has an unsaved change.
|
130
|
+
if changed_attributes.include?(attr)
|
131
|
+
old = changed_attributes[attr]
|
132
|
+
changed_attributes.delete(attr) unless field_changed?(attr, old, value)
|
133
|
+
else
|
134
|
+
old = clone_attribute_value(:read_attribute, attr)
|
135
|
+
changed_attributes[attr] = old if field_changed?(attr, old, value)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Carry on.
|
139
|
+
write_attribute_without_dirty(attr, value)
|
140
|
+
end
|
141
|
+
|
142
|
+
def update_with_dirty
|
143
|
+
if partial_updates?
|
144
|
+
# Serialized attributes should always be written in case they've been
|
145
|
+
# changed in place.
|
146
|
+
update_without_dirty(changed | self.class.serialized_attributes.keys)
|
147
|
+
else
|
148
|
+
update_without_dirty
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def field_changed?(attr, old, value)
|
153
|
+
if column = column_for_attribute(attr)
|
154
|
+
if column.type == :integer && column.null && (old.nil? || old == 0)
|
155
|
+
# For nullable integer columns, NULL gets stored in database for blank (i.e. '') values.
|
156
|
+
# Hence we don't record it as a change if the value changes from nil to ''.
|
157
|
+
# If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
|
158
|
+
# be typecast back to 0 (''.to_i => 0)
|
159
|
+
value = nil if value.blank?
|
160
|
+
else
|
161
|
+
value = column.type_cast(value)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
old != value
|
166
|
+
end
|
167
|
+
|
168
|
+
module ClassMethods
|
169
|
+
def self.extended(base)
|
170
|
+
base.metaclass.alias_method_chain(:alias_attribute, :dirty)
|
171
|
+
end
|
172
|
+
|
173
|
+
def alias_attribute_with_dirty(new_name, old_name)
|
174
|
+
alias_attribute_without_dirty(new_name, old_name)
|
175
|
+
DIRTY_SUFFIXES.each do |suffix|
|
176
|
+
module_eval <<-STR, __FILE__, __LINE__+1
|
177
|
+
def #{new_name}#{suffix}; self.#{old_name}#{suffix}; end
|
178
|
+
STR
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class DynamicFinderMatch
|
3
|
+
def self.match(method)
|
4
|
+
df_match = self.new(method)
|
5
|
+
df_match.finder ? df_match : nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(method)
|
9
|
+
@finder = :first
|
10
|
+
case method.to_s
|
11
|
+
when /^find_(all_by|last_by|by)_([_a-zA-Z]\w*)$/
|
12
|
+
@finder = :last if $1 == 'last_by'
|
13
|
+
@finder = :all if $1 == 'all_by'
|
14
|
+
names = $2
|
15
|
+
when /^find_by_([_a-zA-Z]\w*)\!$/
|
16
|
+
@bang = true
|
17
|
+
names = $1
|
18
|
+
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
|
19
|
+
@instantiator = $1 == 'initialize' ? :new : :create
|
20
|
+
names = $2
|
21
|
+
else
|
22
|
+
@finder = nil
|
23
|
+
end
|
24
|
+
@attribute_names = names && names.split('_and_')
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :finder, :attribute_names, :instantiator
|
28
|
+
|
29
|
+
def finder?
|
30
|
+
!@finder.nil? && @instantiator.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def instantiator?
|
34
|
+
@finder == :first && !@instantiator.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def bang?
|
38
|
+
@bang
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,998 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'csv'
|
4
|
+
require 'active_support/test_case'
|
5
|
+
|
6
|
+
if RUBY_VERSION < '1.9'
|
7
|
+
module YAML #:nodoc:
|
8
|
+
class Omap #:nodoc:
|
9
|
+
def keys; map { |k, v| k } end
|
10
|
+
def values; map { |k, v| v } end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined? ActiveRecord
|
16
|
+
class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
|
17
|
+
end
|
18
|
+
else
|
19
|
+
class FixtureClassNotFound < StandardError #:nodoc:
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Fixtures are a way of organizing data that you want to test against; in short, sample data. They come in 3 flavors:
|
24
|
+
#
|
25
|
+
# 1. YAML fixtures
|
26
|
+
# 2. CSV fixtures
|
27
|
+
# 3. Single-file fixtures
|
28
|
+
#
|
29
|
+
# = YAML fixtures
|
30
|
+
#
|
31
|
+
# This type of fixture is in YAML format and the preferred default. YAML is a file format which describes data structures
|
32
|
+
# in a non-verbose, human-readable format. It ships with Ruby 1.8.1+.
|
33
|
+
#
|
34
|
+
# Unlike single-file fixtures, YAML fixtures are stored in a single file per model, which are placed in the directory appointed
|
35
|
+
# by <tt>ActiveSupport::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just
|
36
|
+
# put your files in <tt><your-rails-app>/test/fixtures/</tt>). The fixture file ends with the <tt>.yml</tt> file extension (Rails example:
|
37
|
+
# <tt><your-rails-app>/test/fixtures/web_sites.yml</tt>). The format of a YAML fixture file looks like this:
|
38
|
+
#
|
39
|
+
# rubyonrails:
|
40
|
+
# id: 1
|
41
|
+
# name: Ruby on Rails
|
42
|
+
# url: http://www.rubyonrails.org
|
43
|
+
#
|
44
|
+
# google:
|
45
|
+
# id: 2
|
46
|
+
# name: Google
|
47
|
+
# url: http://www.google.com
|
48
|
+
#
|
49
|
+
# This YAML fixture file includes two fixtures. Each YAML fixture (ie. record) is given a name and is followed by an
|
50
|
+
# indented list of key/value pairs in the "key: value" format. Records are separated by a blank line for your viewing
|
51
|
+
# pleasure.
|
52
|
+
#
|
53
|
+
# Note that YAML fixtures are unordered. If you want ordered fixtures, use the omap YAML type. See http://yaml.org/type/omap.html
|
54
|
+
# for the specification. You will need ordered fixtures when you have foreign key constraints on keys in the same table.
|
55
|
+
# This is commonly needed for tree structures. Example:
|
56
|
+
#
|
57
|
+
# --- !omap
|
58
|
+
# - parent:
|
59
|
+
# id: 1
|
60
|
+
# parent_id: NULL
|
61
|
+
# title: Parent
|
62
|
+
# - child:
|
63
|
+
# id: 2
|
64
|
+
# parent_id: 1
|
65
|
+
# title: Child
|
66
|
+
#
|
67
|
+
# = CSV fixtures
|
68
|
+
#
|
69
|
+
# Fixtures can also be kept in the Comma Separated Value format. Akin to YAML fixtures, CSV fixtures are stored
|
70
|
+
# in a single file, but instead end with the <tt>.csv</tt> file extension
|
71
|
+
# (Rails example: <tt><your-rails-app>/test/fixtures/web_sites.csv</tt>).
|
72
|
+
#
|
73
|
+
# The format of this type of fixture file is much more compact than the others, but also a little harder to read by us
|
74
|
+
# humans. The first line of the CSV file is a comma-separated list of field names. The rest of the file is then comprised
|
75
|
+
# of the actual data (1 per line). Here's an example:
|
76
|
+
#
|
77
|
+
# id, name, url
|
78
|
+
# 1, Ruby On Rails, http://www.rubyonrails.org
|
79
|
+
# 2, Google, http://www.google.com
|
80
|
+
#
|
81
|
+
# Should you have a piece of data with a comma character in it, you can place double quotes around that value. If you
|
82
|
+
# need to use a double quote character, you must escape it with another double quote.
|
83
|
+
#
|
84
|
+
# Another unique attribute of the CSV fixture is that it has *no* fixture name like the other two formats. Instead, the
|
85
|
+
# fixture names are automatically generated by deriving the class name of the fixture file and adding an incrementing
|
86
|
+
# number to the end. In our example, the 1st fixture would be called "web_site_1" and the 2nd one would be called
|
87
|
+
# "web_site_2".
|
88
|
+
#
|
89
|
+
# Most databases and spreadsheets support exporting to CSV format, so this is a great format for you to choose if you
|
90
|
+
# have existing data somewhere already.
|
91
|
+
#
|
92
|
+
# = Single-file fixtures
|
93
|
+
#
|
94
|
+
# This type of fixture was the original format for Active Record that has since been deprecated in favor of the YAML and CSV formats.
|
95
|
+
# Fixtures for this format are created by placing text files in a sub-directory (with the name of the model) to the directory
|
96
|
+
# appointed by <tt>ActiveSupport::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just
|
97
|
+
# put your files in <tt><your-rails-app>/test/fixtures/<your-model-name>/</tt> --
|
98
|
+
# like <tt><your-rails-app>/test/fixtures/web_sites/</tt> for the WebSite model).
|
99
|
+
#
|
100
|
+
# Each text file placed in this directory represents a "record". Usually these types of fixtures are named without
|
101
|
+
# extensions, but if you are on a Windows machine, you might consider adding <tt>.txt</tt> as the extension. Here's what the
|
102
|
+
# above example might look like:
|
103
|
+
#
|
104
|
+
# web_sites/google
|
105
|
+
# web_sites/yahoo.txt
|
106
|
+
# web_sites/ruby-on-rails
|
107
|
+
#
|
108
|
+
# The file format of a standard fixture is simple. Each line is a property (or column in db speak) and has the syntax
|
109
|
+
# of "name => value". Here's an example of the ruby-on-rails fixture above:
|
110
|
+
#
|
111
|
+
# id => 1
|
112
|
+
# name => Ruby on Rails
|
113
|
+
# url => http://www.rubyonrails.org
|
114
|
+
#
|
115
|
+
# = Using Fixtures
|
116
|
+
#
|
117
|
+
# Since fixtures are a testing construct, we use them in our unit and functional tests. There are two ways to use the
|
118
|
+
# fixtures, but first let's take a look at a sample unit test:
|
119
|
+
#
|
120
|
+
# require 'web_site'
|
121
|
+
#
|
122
|
+
# class WebSiteTest < ActiveSupport::TestCase
|
123
|
+
# def test_web_site_count
|
124
|
+
# assert_equal 2, WebSite.count
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# As it stands, unless we pre-load the web_site table in our database with two records, this test will fail. Here's the
|
129
|
+
# easiest way to add fixtures to the database:
|
130
|
+
#
|
131
|
+
# ...
|
132
|
+
# class WebSiteTest < ActiveSupport::TestCase
|
133
|
+
# fixtures :web_sites # add more by separating the symbols with commas
|
134
|
+
# ...
|
135
|
+
#
|
136
|
+
# By adding a "fixtures" method to the test case and passing it a list of symbols (only one is shown here though), we trigger
|
137
|
+
# the testing environment to automatically load the appropriate fixtures into the database before each test.
|
138
|
+
# To ensure consistent data, the environment deletes the fixtures before running the load.
|
139
|
+
#
|
140
|
+
# In addition to being available in the database, the fixtures are also loaded into a hash stored in an instance variable
|
141
|
+
# of the test case. It is named after the symbol... so, in our example, there would be a hash available called
|
142
|
+
# <tt>@web_sites</tt>. This is where the "fixture name" comes into play.
|
143
|
+
#
|
144
|
+
# On top of that, each record is automatically "found" (using <tt>Model.find(id)</tt>) and placed in the instance variable of its name.
|
145
|
+
# So for the YAML fixtures, we'd get <tt>@rubyonrails</tt> and <tt>@google</tt>, which could be interrogated using regular Active Record semantics:
|
146
|
+
#
|
147
|
+
# # test if the object created from the fixture data has the same attributes as the data itself
|
148
|
+
# def test_find
|
149
|
+
# assert_equal @web_sites["rubyonrails"]["name"], @rubyonrails.name
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# As seen above, the data hash created from the YAML fixtures would have <tt>@web_sites["rubyonrails"]["url"]</tt> return
|
153
|
+
# "http://www.rubyonrails.org" and <tt>@web_sites["google"]["name"]</tt> would return "Google". The same fixtures, but loaded
|
154
|
+
# from a CSV fixture file, would be accessible via <tt>@web_sites["web_site_1"]["name"] == "Ruby on Rails"</tt> and have the individual
|
155
|
+
# fixtures available as instance variables <tt>@web_site_1</tt> and <tt>@web_site_2</tt>.
|
156
|
+
#
|
157
|
+
# If you do not wish to use instantiated fixtures (usually for performance reasons) there are two options.
|
158
|
+
#
|
159
|
+
# - to completely disable instantiated fixtures:
|
160
|
+
# self.use_instantiated_fixtures = false
|
161
|
+
#
|
162
|
+
# - to keep the fixture instance (@web_sites) available, but do not automatically 'find' each instance:
|
163
|
+
# self.use_instantiated_fixtures = :no_instances
|
164
|
+
#
|
165
|
+
# Even if auto-instantiated fixtures are disabled, you can still access them
|
166
|
+
# by name via special dynamic methods. Each method has the same name as the
|
167
|
+
# model, and accepts the name of the fixture to instantiate:
|
168
|
+
#
|
169
|
+
# fixtures :web_sites
|
170
|
+
#
|
171
|
+
# def test_find
|
172
|
+
# assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
|
173
|
+
# end
|
174
|
+
#
|
175
|
+
# = Dynamic fixtures with ERb
|
176
|
+
#
|
177
|
+
# Some times you don't care about the content of the fixtures as much as you care about the volume. In these cases, you can
|
178
|
+
# mix ERb in with your YAML or CSV fixtures to create a bunch of fixtures for load testing, like:
|
179
|
+
#
|
180
|
+
# <% for i in 1..1000 %>
|
181
|
+
# fix_<%= i %>:
|
182
|
+
# id: <%= i %>
|
183
|
+
# name: guy_<%= 1 %>
|
184
|
+
# <% end %>
|
185
|
+
#
|
186
|
+
# This will create 1000 very simple YAML fixtures.
|
187
|
+
#
|
188
|
+
# Using ERb, you can also inject dynamic values into your fixtures with inserts like <tt><%= Date.today.strftime("%Y-%m-%d") %></tt>.
|
189
|
+
# This is however a feature to be used with some caution. The point of fixtures are that they're stable units of predictable
|
190
|
+
# sample data. If you feel that you need to inject dynamic values, then perhaps you should reexamine whether your application
|
191
|
+
# is properly testable. Hence, dynamic values in fixtures are to be considered a code smell.
|
192
|
+
#
|
193
|
+
# = Transactional fixtures
|
194
|
+
#
|
195
|
+
# TestCases can use begin+rollback to isolate their changes to the database instead of having to delete+insert for every test case.
|
196
|
+
# They can also turn off auto-instantiation of fixture data since the feature is costly and often unused.
|
197
|
+
#
|
198
|
+
# class FooTest < ActiveSupport::TestCase
|
199
|
+
# self.use_transactional_fixtures = true
|
200
|
+
# self.use_instantiated_fixtures = false
|
201
|
+
#
|
202
|
+
# fixtures :foos
|
203
|
+
#
|
204
|
+
# def test_godzilla
|
205
|
+
# assert !Foo.find(:all).empty?
|
206
|
+
# Foo.destroy_all
|
207
|
+
# assert Foo.find(:all).empty?
|
208
|
+
# end
|
209
|
+
#
|
210
|
+
# def test_godzilla_aftermath
|
211
|
+
# assert !Foo.find(:all).empty?
|
212
|
+
# end
|
213
|
+
# end
|
214
|
+
#
|
215
|
+
# If you preload your test database with all fixture data (probably in the Rakefile task) and use transactional fixtures,
|
216
|
+
# then you may omit all fixtures declarations in your test cases since all the data's already there and every case rolls back its changes.
|
217
|
+
#
|
218
|
+
# In order to use instantiated fixtures with preloaded data, set +self.pre_loaded_fixtures+ to true. This will provide
|
219
|
+
# access to fixture data for every table that has been loaded through fixtures (depending on the value of +use_instantiated_fixtures+)
|
220
|
+
#
|
221
|
+
# When *not* to use transactional fixtures:
|
222
|
+
# 1. You're testing whether a transaction works correctly. Nested transactions don't commit until all parent transactions commit,
|
223
|
+
# particularly, the fixtures transaction which is begun in setup and rolled back in teardown. Thus, you won't be able to verify
|
224
|
+
# the results of your transaction until Active Record supports nested transactions or savepoints (in progress).
|
225
|
+
# 2. Your database does not support transactions. Every Active Record database supports transactions except MySQL MyISAM.
|
226
|
+
# Use InnoDB, MaxDB, or NDB instead.
|
227
|
+
#
|
228
|
+
# = Advanced YAML Fixtures
|
229
|
+
#
|
230
|
+
# YAML fixtures that don't specify an ID get some extra features:
|
231
|
+
#
|
232
|
+
# * Stable, autogenerated ID's
|
233
|
+
# * Label references for associations (belongs_to, has_one, has_many)
|
234
|
+
# * HABTM associations as inline lists
|
235
|
+
# * Autofilled timestamp columns
|
236
|
+
# * Fixture label interpolation
|
237
|
+
# * Support for YAML defaults
|
238
|
+
#
|
239
|
+
# == Stable, autogenerated ID's
|
240
|
+
#
|
241
|
+
# Here, have a monkey fixture:
|
242
|
+
#
|
243
|
+
# george:
|
244
|
+
# id: 1
|
245
|
+
# name: George the Monkey
|
246
|
+
#
|
247
|
+
# reginald:
|
248
|
+
# id: 2
|
249
|
+
# name: Reginald the Pirate
|
250
|
+
#
|
251
|
+
# Each of these fixtures has two unique identifiers: one for the database
|
252
|
+
# and one for the humans. Why don't we generate the primary key instead?
|
253
|
+
# Hashing each fixture's label yields a consistent ID:
|
254
|
+
#
|
255
|
+
# george: # generated id: 503576764
|
256
|
+
# name: George the Monkey
|
257
|
+
#
|
258
|
+
# reginald: # generated id: 324201669
|
259
|
+
# name: Reginald the Pirate
|
260
|
+
#
|
261
|
+
# Active Record looks at the fixture's model class, discovers the correct
|
262
|
+
# primary key, and generates it right before inserting the fixture
|
263
|
+
# into the database.
|
264
|
+
#
|
265
|
+
# The generated ID for a given label is constant, so we can discover
|
266
|
+
# any fixture's ID without loading anything, as long as we know the label.
|
267
|
+
#
|
268
|
+
# == Label references for associations (belongs_to, has_one, has_many)
|
269
|
+
#
|
270
|
+
# Specifying foreign keys in fixtures can be very fragile, not to
|
271
|
+
# mention difficult to read. Since Active Record can figure out the ID of
|
272
|
+
# any fixture from its label, you can specify FK's by label instead of ID.
|
273
|
+
#
|
274
|
+
# === belongs_to
|
275
|
+
#
|
276
|
+
# Let's break out some more monkeys and pirates.
|
277
|
+
#
|
278
|
+
# ### in pirates.yml
|
279
|
+
#
|
280
|
+
# reginald:
|
281
|
+
# id: 1
|
282
|
+
# name: Reginald the Pirate
|
283
|
+
# monkey_id: 1
|
284
|
+
#
|
285
|
+
# ### in monkeys.yml
|
286
|
+
#
|
287
|
+
# george:
|
288
|
+
# id: 1
|
289
|
+
# name: George the Monkey
|
290
|
+
# pirate_id: 1
|
291
|
+
#
|
292
|
+
# Add a few more monkeys and pirates and break this into multiple files,
|
293
|
+
# and it gets pretty hard to keep track of what's going on. Let's
|
294
|
+
# use labels instead of ID's:
|
295
|
+
#
|
296
|
+
# ### in pirates.yml
|
297
|
+
#
|
298
|
+
# reginald:
|
299
|
+
# name: Reginald the Pirate
|
300
|
+
# monkey: george
|
301
|
+
#
|
302
|
+
# ### in monkeys.yml
|
303
|
+
#
|
304
|
+
# george:
|
305
|
+
# name: George the Monkey
|
306
|
+
# pirate: reginald
|
307
|
+
#
|
308
|
+
# Pow! All is made clear. Active Record reflects on the fixture's model class,
|
309
|
+
# finds all the +belongs_to+ associations, and allows you to specify
|
310
|
+
# a target *label* for the *association* (monkey: george) rather than
|
311
|
+
# a target *id* for the *FK* (<tt>monkey_id: 1</tt>).
|
312
|
+
#
|
313
|
+
# ==== Polymorphic belongs_to
|
314
|
+
#
|
315
|
+
# Supporting polymorphic relationships is a little bit more complicated, since
|
316
|
+
# Active Record needs to know what type your association is pointing at. Something
|
317
|
+
# like this should look familiar:
|
318
|
+
#
|
319
|
+
# ### in fruit.rb
|
320
|
+
#
|
321
|
+
# belongs_to :eater, :polymorphic => true
|
322
|
+
#
|
323
|
+
# ### in fruits.yml
|
324
|
+
#
|
325
|
+
# apple:
|
326
|
+
# id: 1
|
327
|
+
# name: apple
|
328
|
+
# eater_id: 1
|
329
|
+
# eater_type: Monkey
|
330
|
+
#
|
331
|
+
# Can we do better? You bet!
|
332
|
+
#
|
333
|
+
# apple:
|
334
|
+
# eater: george (Monkey)
|
335
|
+
#
|
336
|
+
# Just provide the polymorphic target type and Active Record will take care of the rest.
|
337
|
+
#
|
338
|
+
# === has_and_belongs_to_many
|
339
|
+
#
|
340
|
+
# Time to give our monkey some fruit.
|
341
|
+
#
|
342
|
+
# ### in monkeys.yml
|
343
|
+
#
|
344
|
+
# george:
|
345
|
+
# id: 1
|
346
|
+
# name: George the Monkey
|
347
|
+
# pirate_id: 1
|
348
|
+
#
|
349
|
+
# ### in fruits.yml
|
350
|
+
#
|
351
|
+
# apple:
|
352
|
+
# id: 1
|
353
|
+
# name: apple
|
354
|
+
#
|
355
|
+
# orange:
|
356
|
+
# id: 2
|
357
|
+
# name: orange
|
358
|
+
#
|
359
|
+
# grape:
|
360
|
+
# id: 3
|
361
|
+
# name: grape
|
362
|
+
#
|
363
|
+
# ### in fruits_monkeys.yml
|
364
|
+
#
|
365
|
+
# apple_george:
|
366
|
+
# fruit_id: 1
|
367
|
+
# monkey_id: 1
|
368
|
+
#
|
369
|
+
# orange_george:
|
370
|
+
# fruit_id: 2
|
371
|
+
# monkey_id: 1
|
372
|
+
#
|
373
|
+
# grape_george:
|
374
|
+
# fruit_id: 3
|
375
|
+
# monkey_id: 1
|
376
|
+
#
|
377
|
+
# Let's make the HABTM fixture go away.
|
378
|
+
#
|
379
|
+
# ### in monkeys.yml
|
380
|
+
#
|
381
|
+
# george:
|
382
|
+
# name: George the Monkey
|
383
|
+
# pirate: reginald
|
384
|
+
# fruits: apple, orange, grape
|
385
|
+
#
|
386
|
+
# ### in fruits.yml
|
387
|
+
#
|
388
|
+
# apple:
|
389
|
+
# name: apple
|
390
|
+
#
|
391
|
+
# orange:
|
392
|
+
# name: orange
|
393
|
+
#
|
394
|
+
# grape:
|
395
|
+
# name: grape
|
396
|
+
#
|
397
|
+
# Zap! No more fruits_monkeys.yml file. We've specified the list of fruits
|
398
|
+
# on George's fixture, but we could've just as easily specified a list
|
399
|
+
# of monkeys on each fruit. As with +belongs_to+, Active Record reflects on
|
400
|
+
# the fixture's model class and discovers the +has_and_belongs_to_many+
|
401
|
+
# associations.
|
402
|
+
#
|
403
|
+
# == Autofilled timestamp columns
|
404
|
+
#
|
405
|
+
# If your table/model specifies any of Active Record's
|
406
|
+
# standard timestamp columns (+created_at+, +created_on+, +updated_at+, +updated_on+),
|
407
|
+
# they will automatically be set to <tt>Time.now</tt>.
|
408
|
+
#
|
409
|
+
# If you've set specific values, they'll be left alone.
|
410
|
+
#
|
411
|
+
# == Fixture label interpolation
|
412
|
+
#
|
413
|
+
# The label of the current fixture is always available as a column value:
|
414
|
+
#
|
415
|
+
# geeksomnia:
|
416
|
+
# name: Geeksomnia's Account
|
417
|
+
# subdomain: $LABEL
|
418
|
+
#
|
419
|
+
# Also, sometimes (like when porting older join table fixtures) you'll need
|
420
|
+
# to be able to get ahold of the identifier for a given label. ERB
|
421
|
+
# to the rescue:
|
422
|
+
#
|
423
|
+
# george_reginald:
|
424
|
+
# monkey_id: <%= Fixtures.identify(:reginald) %>
|
425
|
+
# pirate_id: <%= Fixtures.identify(:george) %>
|
426
|
+
#
|
427
|
+
# == Support for YAML defaults
|
428
|
+
#
|
429
|
+
# You probably already know how to use YAML to set and reuse defaults in
|
430
|
+
# your <tt>database.yml</tt> file. You can use the same technique in your fixtures:
|
431
|
+
#
|
432
|
+
# DEFAULTS: &DEFAULTS
|
433
|
+
# created_on: <%= 3.weeks.ago.to_s(:db) %>
|
434
|
+
#
|
435
|
+
# first:
|
436
|
+
# name: Smurf
|
437
|
+
# <<: *DEFAULTS
|
438
|
+
#
|
439
|
+
# second:
|
440
|
+
# name: Fraggle
|
441
|
+
# <<: *DEFAULTS
|
442
|
+
#
|
443
|
+
# Any fixture labeled "DEFAULTS" is safely ignored.
|
444
|
+
|
445
|
+
class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
|
446
|
+
DEFAULT_FILTER_RE = /\.ya?ml$/
|
447
|
+
|
448
|
+
@@all_cached_fixtures = {}
|
449
|
+
|
450
|
+
def self.reset_cache(connection = nil)
|
451
|
+
connection ||= ActiveRecord::Base.connection
|
452
|
+
@@all_cached_fixtures[connection.object_id] = {}
|
453
|
+
end
|
454
|
+
|
455
|
+
def self.cache_for_connection(connection)
|
456
|
+
@@all_cached_fixtures[connection.object_id] ||= {}
|
457
|
+
@@all_cached_fixtures[connection.object_id]
|
458
|
+
end
|
459
|
+
|
460
|
+
def self.fixture_is_cached?(connection, table_name)
|
461
|
+
cache_for_connection(connection)[table_name]
|
462
|
+
end
|
463
|
+
|
464
|
+
def self.cached_fixtures(connection, keys_to_fetch = nil)
|
465
|
+
if keys_to_fetch
|
466
|
+
fixtures = cache_for_connection(connection).values_at(*keys_to_fetch)
|
467
|
+
else
|
468
|
+
fixtures = cache_for_connection(connection).values
|
469
|
+
end
|
470
|
+
fixtures.size > 1 ? fixtures : fixtures.first
|
471
|
+
end
|
472
|
+
|
473
|
+
def self.cache_fixtures(connection, fixtures_map)
|
474
|
+
cache_for_connection(connection).update(fixtures_map)
|
475
|
+
end
|
476
|
+
|
477
|
+
def self.instantiate_fixtures(object, table_name, fixtures, load_instances = true)
|
478
|
+
object.instance_variable_set "@#{table_name.to_s.gsub('.','_')}", fixtures
|
479
|
+
if load_instances
|
480
|
+
ActiveRecord::Base.silence do
|
481
|
+
fixtures.each do |name, fixture|
|
482
|
+
begin
|
483
|
+
object.instance_variable_set "@#{name}", fixture.find
|
484
|
+
rescue FixtureClassNotFound
|
485
|
+
nil
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
def self.instantiate_all_loaded_fixtures(object, load_instances = true)
|
493
|
+
all_loaded_fixtures.each do |table_name, fixtures|
|
494
|
+
Fixtures.instantiate_fixtures(object, table_name, fixtures, load_instances)
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
cattr_accessor :all_loaded_fixtures
|
499
|
+
self.all_loaded_fixtures = {}
|
500
|
+
|
501
|
+
def self.create_fixtures(fixtures_directory, table_names, class_names = {})
|
502
|
+
table_names = [table_names].flatten.map { |n| n.to_s }
|
503
|
+
connection = block_given? ? yield : ActiveRecord::Base.connection
|
504
|
+
|
505
|
+
table_names_to_fetch = table_names.reject { |table_name| fixture_is_cached?(connection, table_name) }
|
506
|
+
|
507
|
+
unless table_names_to_fetch.empty?
|
508
|
+
ActiveRecord::Base.silence do
|
509
|
+
connection.disable_referential_integrity do
|
510
|
+
fixtures_map = {}
|
511
|
+
|
512
|
+
fixtures = table_names_to_fetch.map do |table_name|
|
513
|
+
fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, class_names[table_name.to_sym], File.join(fixtures_directory, table_name.to_s))
|
514
|
+
end
|
515
|
+
|
516
|
+
all_loaded_fixtures.update(fixtures_map)
|
517
|
+
|
518
|
+
connection.transaction(connection.open_transactions.zero?) do
|
519
|
+
fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
|
520
|
+
fixtures.each { |fixture| fixture.insert_fixtures }
|
521
|
+
|
522
|
+
# Cap primary key sequences to max(pk).
|
523
|
+
if connection.respond_to?(:reset_pk_sequence!)
|
524
|
+
table_names.each do |table_name|
|
525
|
+
connection.reset_pk_sequence!(table_name)
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
cache_fixtures(connection, fixtures_map)
|
531
|
+
end
|
532
|
+
end
|
533
|
+
end
|
534
|
+
cached_fixtures(connection, table_names)
|
535
|
+
end
|
536
|
+
|
537
|
+
# Returns a consistent identifier for +label+. This will always
|
538
|
+
# be a positive integer, and will always be the same for a given
|
539
|
+
# label, assuming the same OS, platform, and version of Ruby.
|
540
|
+
def self.identify(label)
|
541
|
+
label.to_s.hash.abs
|
542
|
+
end
|
543
|
+
|
544
|
+
attr_reader :table_name, :name
|
545
|
+
|
546
|
+
def initialize(connection, table_name, class_name, fixture_path, file_filter = DEFAULT_FILTER_RE)
|
547
|
+
@connection, @table_name, @fixture_path, @file_filter = connection, table_name, fixture_path, file_filter
|
548
|
+
@name = table_name # preserve fixture base name
|
549
|
+
@class_name = class_name ||
|
550
|
+
(ActiveRecord::Base.pluralize_table_names ? @table_name.singularize.camelize : @table_name.camelize)
|
551
|
+
@table_name = "#{ActiveRecord::Base.table_name_prefix}#{@table_name}#{ActiveRecord::Base.table_name_suffix}"
|
552
|
+
@table_name = class_name.table_name if class_name.respond_to?(:table_name)
|
553
|
+
@connection = class_name.connection if class_name.respond_to?(:connection)
|
554
|
+
read_fixture_files
|
555
|
+
end
|
556
|
+
|
557
|
+
def delete_existing_fixtures
|
558
|
+
@connection.delete "DELETE FROM #{@connection.quote_table_name(table_name)}", 'Fixture Delete'
|
559
|
+
end
|
560
|
+
|
561
|
+
def insert_fixtures
|
562
|
+
now = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now
|
563
|
+
now = now.to_s(:db)
|
564
|
+
|
565
|
+
# allow a standard key to be used for doing defaults in YAML
|
566
|
+
if is_a?(Hash)
|
567
|
+
delete('DEFAULTS')
|
568
|
+
else
|
569
|
+
delete(assoc('DEFAULTS'))
|
570
|
+
end
|
571
|
+
|
572
|
+
# track any join tables we need to insert later
|
573
|
+
habtm_fixtures = Hash.new do |h, habtm|
|
574
|
+
h[habtm] = HabtmFixtures.new(@connection, habtm.options[:join_table], nil, nil)
|
575
|
+
end
|
576
|
+
|
577
|
+
each do |label, fixture|
|
578
|
+
row = fixture.to_hash
|
579
|
+
|
580
|
+
if model_class && model_class < ActiveRecord::Base
|
581
|
+
# fill in timestamp columns if they aren't specified and the model is set to record_timestamps
|
582
|
+
if model_class.record_timestamps
|
583
|
+
timestamp_column_names.each do |name|
|
584
|
+
row[name] = now unless row.key?(name)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
# interpolate the fixture label
|
589
|
+
row.each do |key, value|
|
590
|
+
row[key] = label if value == "$LABEL"
|
591
|
+
end
|
592
|
+
|
593
|
+
# generate a primary key if necessary
|
594
|
+
if has_primary_key_column? && !row.include?(primary_key_name)
|
595
|
+
row[primary_key_name] = Fixtures.identify(label)
|
596
|
+
end
|
597
|
+
|
598
|
+
# If STI is used, find the correct subclass for association reflection
|
599
|
+
reflection_class =
|
600
|
+
if row.include?(inheritance_column_name)
|
601
|
+
row[inheritance_column_name].constantize rescue model_class
|
602
|
+
else
|
603
|
+
model_class
|
604
|
+
end
|
605
|
+
|
606
|
+
reflection_class.reflect_on_all_associations.each do |association|
|
607
|
+
case association.macro
|
608
|
+
when :belongs_to
|
609
|
+
# Do not replace association name with association foreign key if they are named the same
|
610
|
+
fk_name = (association.options[:foreign_key] || "#{association.name}_id").to_s
|
611
|
+
|
612
|
+
if association.name.to_s != fk_name && value = row.delete(association.name.to_s)
|
613
|
+
if association.options[:polymorphic]
|
614
|
+
if value.sub!(/\s*\(([^\)]*)\)\s*$/, "")
|
615
|
+
target_type = $1
|
616
|
+
target_type_name = (association.options[:foreign_type] || "#{association.name}_type").to_s
|
617
|
+
|
618
|
+
# support polymorphic belongs_to as "label (Type)"
|
619
|
+
row[target_type_name] = target_type
|
620
|
+
end
|
621
|
+
end
|
622
|
+
|
623
|
+
row[fk_name] = Fixtures.identify(value)
|
624
|
+
end
|
625
|
+
when :has_and_belongs_to_many
|
626
|
+
if (targets = row.delete(association.name.to_s))
|
627
|
+
targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/)
|
628
|
+
join_fixtures = habtm_fixtures[association]
|
629
|
+
|
630
|
+
targets.each do |target|
|
631
|
+
join_fixtures["#{label}_#{target}"] = Fixture.new(
|
632
|
+
{ association.primary_key_name => row[primary_key_name],
|
633
|
+
association.association_foreign_key => Fixtures.identify(target) }, nil)
|
634
|
+
end
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
@connection.insert_fixture(fixture, @table_name)
|
641
|
+
end
|
642
|
+
|
643
|
+
# insert any HABTM join tables we discovered
|
644
|
+
habtm_fixtures.values.each do |fixture|
|
645
|
+
fixture.delete_existing_fixtures
|
646
|
+
fixture.insert_fixtures
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
private
|
651
|
+
class HabtmFixtures < ::Fixtures #:nodoc:
|
652
|
+
def read_fixture_files; end
|
653
|
+
end
|
654
|
+
|
655
|
+
def model_class
|
656
|
+
unless defined?(@model_class)
|
657
|
+
@model_class =
|
658
|
+
if @class_name.nil? || @class_name.is_a?(Class)
|
659
|
+
@class_name
|
660
|
+
else
|
661
|
+
@class_name.constantize rescue nil
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
@model_class
|
666
|
+
end
|
667
|
+
|
668
|
+
def primary_key_name
|
669
|
+
@primary_key_name ||= model_class && model_class.primary_key
|
670
|
+
end
|
671
|
+
|
672
|
+
def has_primary_key_column?
|
673
|
+
@has_primary_key_column ||= model_class && primary_key_name &&
|
674
|
+
model_class.columns.find { |c| c.name == primary_key_name }
|
675
|
+
end
|
676
|
+
|
677
|
+
def timestamp_column_names
|
678
|
+
@timestamp_column_names ||= %w(created_at created_on updated_at updated_on).select do |name|
|
679
|
+
column_names.include?(name)
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
def inheritance_column_name
|
684
|
+
@inheritance_column_name ||= model_class && model_class.inheritance_column
|
685
|
+
end
|
686
|
+
|
687
|
+
def column_names
|
688
|
+
@column_names ||= @connection.columns(@table_name).collect(&:name)
|
689
|
+
end
|
690
|
+
|
691
|
+
def read_fixture_files
|
692
|
+
if File.file?(yaml_file_path)
|
693
|
+
read_yaml_fixture_files
|
694
|
+
elsif File.file?(csv_file_path)
|
695
|
+
read_csv_fixture_files
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
def read_yaml_fixture_files
|
700
|
+
yaml_string = ""
|
701
|
+
Dir["#{@fixture_path}/**/*.yml"].select { |f| test(?f, f) }.each do |subfixture_path|
|
702
|
+
yaml_string << IO.read(subfixture_path)
|
703
|
+
end
|
704
|
+
yaml_string << IO.read(yaml_file_path)
|
705
|
+
|
706
|
+
if yaml = parse_yaml_string(yaml_string)
|
707
|
+
# If the file is an ordered map, extract its children.
|
708
|
+
yaml_value =
|
709
|
+
if yaml.respond_to?(:type_id) && yaml.respond_to?(:value)
|
710
|
+
yaml.value
|
711
|
+
else
|
712
|
+
[yaml]
|
713
|
+
end
|
714
|
+
|
715
|
+
yaml_value.each do |fixture|
|
716
|
+
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{fixture}" unless fixture.respond_to?(:each)
|
717
|
+
fixture.each do |name, data|
|
718
|
+
unless data
|
719
|
+
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
|
720
|
+
end
|
721
|
+
|
722
|
+
self[name] = Fixture.new(data, model_class)
|
723
|
+
end
|
724
|
+
end
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
728
|
+
def read_csv_fixture_files
|
729
|
+
reader = CSV.parse(erb_render(IO.read(csv_file_path)))
|
730
|
+
header = reader.shift
|
731
|
+
i = 0
|
732
|
+
reader.each do |row|
|
733
|
+
data = {}
|
734
|
+
row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
|
735
|
+
self["#{@class_name.to_s.underscore}_#{i+=1}"] = Fixture.new(data, model_class)
|
736
|
+
end
|
737
|
+
end
|
738
|
+
|
739
|
+
def yaml_file_path
|
740
|
+
"#{@fixture_path}.yml"
|
741
|
+
end
|
742
|
+
|
743
|
+
def csv_file_path
|
744
|
+
@fixture_path + ".csv"
|
745
|
+
end
|
746
|
+
|
747
|
+
def yaml_fixtures_key(path)
|
748
|
+
File.basename(@fixture_path).split(".").first
|
749
|
+
end
|
750
|
+
|
751
|
+
def parse_yaml_string(fixture_content)
|
752
|
+
YAML::load(erb_render(fixture_content))
|
753
|
+
rescue => error
|
754
|
+
raise Fixture::FormatError, "a YAML error occurred parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{error.class}: #{error}"
|
755
|
+
end
|
756
|
+
|
757
|
+
def erb_render(fixture_content)
|
758
|
+
ERB.new(fixture_content).result
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
class Fixture #:nodoc:
|
763
|
+
include Enumerable
|
764
|
+
|
765
|
+
class FixtureError < StandardError #:nodoc:
|
766
|
+
end
|
767
|
+
|
768
|
+
class FormatError < FixtureError #:nodoc:
|
769
|
+
end
|
770
|
+
|
771
|
+
attr_reader :model_class
|
772
|
+
|
773
|
+
def initialize(fixture, model_class)
|
774
|
+
@fixture = fixture
|
775
|
+
@model_class = model_class.is_a?(Class) ? model_class : model_class.constantize rescue nil
|
776
|
+
end
|
777
|
+
|
778
|
+
def class_name
|
779
|
+
@model_class.name if @model_class
|
780
|
+
end
|
781
|
+
|
782
|
+
def each
|
783
|
+
@fixture.each { |item| yield item }
|
784
|
+
end
|
785
|
+
|
786
|
+
def [](key)
|
787
|
+
@fixture[key]
|
788
|
+
end
|
789
|
+
|
790
|
+
def to_hash
|
791
|
+
@fixture
|
792
|
+
end
|
793
|
+
|
794
|
+
def key_list
|
795
|
+
columns = @fixture.keys.collect{ |column_name| ActiveRecord::Base.connection.quote_column_name(column_name) }
|
796
|
+
columns.join(", ")
|
797
|
+
end
|
798
|
+
|
799
|
+
def value_list
|
800
|
+
list = @fixture.inject([]) do |fixtures, (key, value)|
|
801
|
+
col = model_class.columns_hash[key] if model_class.respond_to?(:ancestors) && model_class.ancestors.include?(ActiveRecord::Base)
|
802
|
+
fixtures << ActiveRecord::Base.connection.quote(value, col).gsub('[^\]\\n', "\n").gsub('[^\]\\r', "\r")
|
803
|
+
end
|
804
|
+
list * ', '
|
805
|
+
end
|
806
|
+
|
807
|
+
def find
|
808
|
+
if model_class
|
809
|
+
model_class.find(self[model_class.primary_key])
|
810
|
+
else
|
811
|
+
raise FixtureClassNotFound, "No class attached to find."
|
812
|
+
end
|
813
|
+
end
|
814
|
+
end
|
815
|
+
|
816
|
+
module Test #:nodoc:
|
817
|
+
module Unit #:nodoc:
|
818
|
+
class TestCase #:nodoc:
|
819
|
+
setup :setup_fixtures
|
820
|
+
teardown :teardown_fixtures
|
821
|
+
|
822
|
+
superclass_delegating_accessor :fixture_path
|
823
|
+
superclass_delegating_accessor :fixture_table_names
|
824
|
+
superclass_delegating_accessor :fixture_class_names
|
825
|
+
superclass_delegating_accessor :use_transactional_fixtures
|
826
|
+
superclass_delegating_accessor :use_instantiated_fixtures # true, false, or :no_instances
|
827
|
+
superclass_delegating_accessor :pre_loaded_fixtures
|
828
|
+
|
829
|
+
self.fixture_table_names = []
|
830
|
+
self.use_transactional_fixtures = false
|
831
|
+
self.use_instantiated_fixtures = true
|
832
|
+
self.pre_loaded_fixtures = false
|
833
|
+
|
834
|
+
@@already_loaded_fixtures = {}
|
835
|
+
self.fixture_class_names = {}
|
836
|
+
|
837
|
+
class << self
|
838
|
+
def set_fixture_class(class_names = {})
|
839
|
+
self.fixture_class_names = self.fixture_class_names.merge(class_names)
|
840
|
+
end
|
841
|
+
|
842
|
+
def fixtures(*table_names)
|
843
|
+
if table_names.first == :all
|
844
|
+
table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"]
|
845
|
+
table_names.map! { |f| File.basename(f).split('.')[0..-2].join('.') }
|
846
|
+
else
|
847
|
+
table_names = table_names.flatten.map { |n| n.to_s }
|
848
|
+
end
|
849
|
+
|
850
|
+
self.fixture_table_names |= table_names
|
851
|
+
require_fixture_classes(table_names)
|
852
|
+
setup_fixture_accessors(table_names)
|
853
|
+
end
|
854
|
+
|
855
|
+
def try_to_load_dependency(file_name)
|
856
|
+
require_dependency file_name
|
857
|
+
rescue LoadError => e
|
858
|
+
# Let's hope the developer has included it himself
|
859
|
+
|
860
|
+
# Let's warn in case this is a subdependency, otherwise
|
861
|
+
# subdependency error messages are totally cryptic
|
862
|
+
if ActiveRecord::Base.logger
|
863
|
+
ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}")
|
864
|
+
end
|
865
|
+
end
|
866
|
+
|
867
|
+
def require_fixture_classes(table_names = nil)
|
868
|
+
(table_names || fixture_table_names).each do |table_name|
|
869
|
+
file_name = table_name.to_s
|
870
|
+
file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
|
871
|
+
try_to_load_dependency(file_name)
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
def setup_fixture_accessors(table_names = nil)
|
876
|
+
table_names = [table_names] if table_names && !table_names.respond_to?(:each)
|
877
|
+
(table_names || fixture_table_names).each do |table_name|
|
878
|
+
table_name = table_name.to_s.tr('.', '_')
|
879
|
+
|
880
|
+
define_method(table_name) do |*fixtures|
|
881
|
+
force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
|
882
|
+
|
883
|
+
@fixture_cache[table_name] ||= {}
|
884
|
+
|
885
|
+
instances = fixtures.map do |fixture|
|
886
|
+
@fixture_cache[table_name].delete(fixture) if force_reload
|
887
|
+
|
888
|
+
if @loaded_fixtures[table_name][fixture.to_s]
|
889
|
+
@fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find
|
890
|
+
else
|
891
|
+
raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
instances.size == 1 ? instances.first : instances
|
896
|
+
end
|
897
|
+
end
|
898
|
+
end
|
899
|
+
|
900
|
+
def uses_transaction(*methods)
|
901
|
+
@uses_transaction = [] unless defined?(@uses_transaction)
|
902
|
+
@uses_transaction.concat methods.map(&:to_s)
|
903
|
+
end
|
904
|
+
|
905
|
+
def uses_transaction?(method)
|
906
|
+
@uses_transaction = [] unless defined?(@uses_transaction)
|
907
|
+
@uses_transaction.include?(method.to_s)
|
908
|
+
end
|
909
|
+
end
|
910
|
+
|
911
|
+
def use_transactional_fixtures?
|
912
|
+
use_transactional_fixtures &&
|
913
|
+
!self.class.uses_transaction?(method_name)
|
914
|
+
end
|
915
|
+
|
916
|
+
def setup_fixtures
|
917
|
+
return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
|
918
|
+
|
919
|
+
if pre_loaded_fixtures && !use_transactional_fixtures
|
920
|
+
raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
|
921
|
+
end
|
922
|
+
|
923
|
+
@fixture_cache = {}
|
924
|
+
|
925
|
+
# Load fixtures once and begin transaction.
|
926
|
+
if use_transactional_fixtures?
|
927
|
+
if @@already_loaded_fixtures[self.class]
|
928
|
+
@loaded_fixtures = @@already_loaded_fixtures[self.class]
|
929
|
+
else
|
930
|
+
load_fixtures
|
931
|
+
@@already_loaded_fixtures[self.class] = @loaded_fixtures
|
932
|
+
end
|
933
|
+
ActiveRecord::Base.connection.increment_open_transactions
|
934
|
+
ActiveRecord::Base.connection.begin_db_transaction
|
935
|
+
# Load fixtures for every test.
|
936
|
+
else
|
937
|
+
Fixtures.reset_cache
|
938
|
+
@@already_loaded_fixtures[self.class] = nil
|
939
|
+
load_fixtures
|
940
|
+
end
|
941
|
+
|
942
|
+
# Instantiate fixtures for every test if requested.
|
943
|
+
instantiate_fixtures if use_instantiated_fixtures
|
944
|
+
end
|
945
|
+
|
946
|
+
def teardown_fixtures
|
947
|
+
return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
|
948
|
+
|
949
|
+
unless use_transactional_fixtures?
|
950
|
+
Fixtures.reset_cache
|
951
|
+
end
|
952
|
+
|
953
|
+
# Rollback changes if a transaction is active.
|
954
|
+
if use_transactional_fixtures? && ActiveRecord::Base.connection.open_transactions != 0
|
955
|
+
ActiveRecord::Base.connection.rollback_db_transaction
|
956
|
+
ActiveRecord::Base.connection.decrement_open_transactions
|
957
|
+
end
|
958
|
+
ActiveRecord::Base.clear_active_connections!
|
959
|
+
end
|
960
|
+
|
961
|
+
private
|
962
|
+
def load_fixtures
|
963
|
+
@loaded_fixtures = {}
|
964
|
+
fixtures = Fixtures.create_fixtures(fixture_path, fixture_table_names, fixture_class_names)
|
965
|
+
unless fixtures.nil?
|
966
|
+
if fixtures.instance_of?(Fixtures)
|
967
|
+
@loaded_fixtures[fixtures.name] = fixtures
|
968
|
+
else
|
969
|
+
fixtures.each { |f| @loaded_fixtures[f.name] = f }
|
970
|
+
end
|
971
|
+
end
|
972
|
+
end
|
973
|
+
|
974
|
+
# for pre_loaded_fixtures, only require the classes once. huge speed improvement
|
975
|
+
@@required_fixture_classes = false
|
976
|
+
|
977
|
+
def instantiate_fixtures
|
978
|
+
if pre_loaded_fixtures
|
979
|
+
raise RuntimeError, 'Load fixtures before instantiating them.' if Fixtures.all_loaded_fixtures.empty?
|
980
|
+
unless @@required_fixture_classes
|
981
|
+
self.class.require_fixture_classes Fixtures.all_loaded_fixtures.keys
|
982
|
+
@@required_fixture_classes = true
|
983
|
+
end
|
984
|
+
Fixtures.instantiate_all_loaded_fixtures(self, load_instances?)
|
985
|
+
else
|
986
|
+
raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil?
|
987
|
+
@loaded_fixtures.each do |table_name, fixtures|
|
988
|
+
Fixtures.instantiate_fixtures(self, table_name, fixtures, load_instances?)
|
989
|
+
end
|
990
|
+
end
|
991
|
+
end
|
992
|
+
|
993
|
+
def load_instances?
|
994
|
+
use_instantiated_fixtures != :no_instances
|
995
|
+
end
|
996
|
+
end
|
997
|
+
end
|
998
|
+
end
|