activerecord 2.3.18 → 3.2.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1014 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +222 -0
- data/examples/performance.rb +100 -126
- data/examples/simple.rb +14 -0
- data/lib/active_record/aggregations.rb +93 -99
- data/lib/active_record/associations/alias_tracker.rb +76 -0
- data/lib/active_record/associations/association.rb +247 -0
- data/lib/active_record/associations/association_scope.rb +134 -0
- data/lib/active_record/associations/belongs_to_association.rb +54 -61
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +17 -59
- data/lib/active_record/associations/builder/association.rb +55 -0
- data/lib/active_record/associations/builder/belongs_to.rb +88 -0
- data/lib/active_record/associations/builder/collection_association.rb +75 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +57 -0
- data/lib/active_record/associations/builder/has_many.rb +71 -0
- data/lib/active_record/associations/builder/has_one.rb +62 -0
- data/lib/active_record/associations/builder/singular_association.rb +32 -0
- data/lib/active_record/associations/collection_association.rb +580 -0
- data/lib/active_record/associations/collection_proxy.rb +133 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +39 -119
- data/lib/active_record/associations/has_many_association.rb +60 -79
- data/lib/active_record/associations/has_many_through_association.rb +127 -206
- data/lib/active_record/associations/has_one_association.rb +55 -114
- data/lib/active_record/associations/has_one_through_association.rb +25 -26
- data/lib/active_record/associations/join_dependency/join_association.rb +159 -0
- data/lib/active_record/associations/join_dependency/join_base.rb +24 -0
- data/lib/active_record/associations/join_dependency/join_part.rb +78 -0
- data/lib/active_record/associations/join_dependency.rb +214 -0
- data/lib/active_record/associations/join_helper.rb +55 -0
- data/lib/active_record/associations/preloader/association.rb +125 -0
- data/lib/active_record/associations/preloader/belongs_to.rb +17 -0
- data/lib/active_record/associations/preloader/collection_association.rb +24 -0
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +60 -0
- data/lib/active_record/associations/preloader/has_many.rb +17 -0
- data/lib/active_record/associations/preloader/has_many_through.rb +15 -0
- data/lib/active_record/associations/preloader/has_one.rb +23 -0
- data/lib/active_record/associations/preloader/has_one_through.rb +9 -0
- data/lib/active_record/associations/preloader/singular_association.rb +21 -0
- data/lib/active_record/associations/preloader/through_association.rb +67 -0
- data/lib/active_record/associations/preloader.rb +181 -0
- data/lib/active_record/associations/singular_association.rb +64 -0
- data/lib/active_record/associations/through_association.rb +87 -0
- data/lib/active_record/associations.rb +693 -1337
- data/lib/active_record/attribute_assignment.rb +221 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +31 -0
- data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +32 -0
- data/lib/active_record/attribute_methods/dirty.rb +111 -0
- data/lib/active_record/attribute_methods/primary_key.rb +114 -0
- data/lib/active_record/attribute_methods/query.rb +39 -0
- data/lib/active_record/attribute_methods/read.rb +136 -0
- data/lib/active_record/attribute_methods/serialization.rb +120 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +65 -0
- data/lib/active_record/attribute_methods/write.rb +70 -0
- data/lib/active_record/attribute_methods.rb +211 -339
- data/lib/active_record/autosave_association.rb +179 -149
- data/lib/active_record/base.rb +401 -2907
- data/lib/active_record/callbacks.rb +91 -176
- data/lib/active_record/coders/yaml_column.rb +41 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +236 -119
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +110 -58
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +12 -11
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +175 -74
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +31 -35
- data/lib/active_record/connection_adapters/abstract/quoting.rb +71 -21
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +81 -311
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +194 -78
- data/lib/active_record/connection_adapters/abstract_adapter.rb +130 -83
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +676 -0
- data/lib/active_record/connection_adapters/column.rb +296 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +280 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +272 -493
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +650 -405
- data/lib/active_record/connection_adapters/schema_cache.rb +69 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +30 -9
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +276 -147
- data/lib/active_record/connection_adapters/statement_pool.rb +40 -0
- data/lib/active_record/counter_cache.rb +123 -0
- data/lib/active_record/dynamic_finder_match.rb +41 -14
- data/lib/active_record/dynamic_matchers.rb +84 -0
- data/lib/active_record/dynamic_scope_match.rb +13 -15
- data/lib/active_record/errors.rb +195 -0
- data/lib/active_record/explain.rb +86 -0
- data/lib/active_record/explain_subscriber.rb +25 -0
- data/lib/active_record/fixtures/file.rb +65 -0
- data/lib/active_record/fixtures.rb +695 -770
- data/lib/active_record/identity_map.rb +162 -0
- data/lib/active_record/inheritance.rb +174 -0
- data/lib/active_record/integration.rb +60 -0
- data/lib/active_record/locale/en.yml +9 -27
- data/lib/active_record/locking/optimistic.rb +76 -73
- data/lib/active_record/locking/pessimistic.rb +32 -10
- data/lib/active_record/log_subscriber.rb +72 -0
- data/lib/active_record/migration/command_recorder.rb +105 -0
- data/lib/active_record/migration.rb +415 -205
- data/lib/active_record/model_schema.rb +368 -0
- data/lib/active_record/nested_attributes.rb +153 -63
- data/lib/active_record/observer.rb +27 -103
- data/lib/active_record/persistence.rb +376 -0
- data/lib/active_record/query_cache.rb +49 -8
- data/lib/active_record/querying.rb +58 -0
- data/lib/active_record/railtie.rb +131 -0
- data/lib/active_record/railties/console_sandbox.rb +6 -0
- data/lib/active_record/railties/controller_runtime.rb +49 -0
- data/lib/active_record/railties/databases.rake +659 -0
- data/lib/active_record/railties/jdbcmysql_error.rb +16 -0
- data/lib/active_record/readonly_attributes.rb +26 -0
- data/lib/active_record/reflection.rb +269 -120
- data/lib/active_record/relation/batches.rb +90 -0
- data/lib/active_record/relation/calculations.rb +372 -0
- data/lib/active_record/relation/delegation.rb +49 -0
- data/lib/active_record/relation/finder_methods.rb +402 -0
- data/lib/active_record/relation/predicate_builder.rb +63 -0
- data/lib/active_record/relation/query_methods.rb +417 -0
- data/lib/active_record/relation/spawn_methods.rb +180 -0
- data/lib/active_record/relation.rb +537 -0
- data/lib/active_record/result.rb +40 -0
- data/lib/active_record/sanitization.rb +194 -0
- data/lib/active_record/schema.rb +9 -6
- data/lib/active_record/schema_dumper.rb +55 -32
- data/lib/active_record/scoping/default.rb +142 -0
- data/lib/active_record/scoping/named.rb +200 -0
- data/lib/active_record/scoping.rb +152 -0
- data/lib/active_record/serialization.rb +8 -91
- data/lib/active_record/serializers/xml_serializer.rb +43 -197
- data/lib/active_record/session_store.rb +129 -103
- data/lib/active_record/store.rb +52 -0
- data/lib/active_record/test_case.rb +30 -23
- data/lib/active_record/timestamp.rb +95 -52
- data/lib/active_record/transactions.rb +212 -66
- data/lib/active_record/translation.rb +22 -0
- data/lib/active_record/validations/associated.rb +43 -0
- data/lib/active_record/validations/uniqueness.rb +180 -0
- data/lib/active_record/validations.rb +43 -1106
- data/lib/active_record/version.rb +5 -4
- data/lib/active_record.rb +121 -48
- data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +34 -0
- data/lib/rails/generators/active_record/migration.rb +15 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +47 -0
- data/lib/rails/generators/active_record/model/templates/migration.rb +15 -0
- data/lib/rails/generators/active_record/model/templates/model.rb +12 -0
- data/lib/rails/generators/active_record/model/templates/module.rb +7 -0
- data/lib/rails/generators/active_record/observer/observer_generator.rb +15 -0
- data/lib/rails/generators/active_record/observer/templates/observer.rb +4 -0
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +25 -0
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +12 -0
- data/lib/rails/generators/active_record.rb +25 -0
- metadata +187 -363
- data/CHANGELOG +0 -5904
- data/README +0 -351
- data/RUNNING_UNIT_TESTS +0 -36
- data/Rakefile +0 -268
- data/install.rb +0 -30
- data/lib/active_record/association_preload.rb +0 -406
- data/lib/active_record/associations/association_collection.rb +0 -533
- data/lib/active_record/associations/association_proxy.rb +0 -288
- data/lib/active_record/batches.rb +0 -85
- data/lib/active_record/calculations.rb +0 -321
- data/lib/active_record/dirty.rb +0 -183
- data/lib/active_record/named_scope.rb +0 -197
- data/lib/active_record/serializers/json_serializer.rb +0 -91
- data/lib/activerecord.rb +0 -2
- data/test/assets/example.log +0 -1
- data/test/assets/flowers.jpg +0 -0
- data/test/cases/aaa_create_tables_test.rb +0 -24
- data/test/cases/active_schema_test_mysql.rb +0 -122
- data/test/cases/active_schema_test_postgresql.rb +0 -24
- data/test/cases/adapter_test.rb +0 -144
- data/test/cases/aggregations_test.rb +0 -167
- data/test/cases/ar_schema_test.rb +0 -32
- data/test/cases/associations/belongs_to_associations_test.rb +0 -438
- data/test/cases/associations/callbacks_test.rb +0 -161
- data/test/cases/associations/cascaded_eager_loading_test.rb +0 -131
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +0 -36
- data/test/cases/associations/eager_load_nested_include_test.rb +0 -131
- data/test/cases/associations/eager_load_nested_polymorphic_include.rb +0 -19
- data/test/cases/associations/eager_singularization_test.rb +0 -145
- data/test/cases/associations/eager_test.rb +0 -852
- data/test/cases/associations/extension_test.rb +0 -62
- data/test/cases/associations/habtm_join_table_test.rb +0 -56
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +0 -827
- data/test/cases/associations/has_many_associations_test.rb +0 -1273
- data/test/cases/associations/has_many_through_associations_test.rb +0 -360
- data/test/cases/associations/has_one_associations_test.rb +0 -330
- data/test/cases/associations/has_one_through_associations_test.rb +0 -209
- data/test/cases/associations/inner_join_association_test.rb +0 -93
- data/test/cases/associations/inverse_associations_test.rb +0 -566
- data/test/cases/associations/join_model_test.rb +0 -712
- data/test/cases/associations_test.rb +0 -282
- data/test/cases/attribute_methods_test.rb +0 -305
- data/test/cases/autosave_association_test.rb +0 -1218
- data/test/cases/base_test.rb +0 -2166
- data/test/cases/batches_test.rb +0 -81
- data/test/cases/binary_test.rb +0 -30
- data/test/cases/calculations_test.rb +0 -360
- data/test/cases/callbacks_observers_test.rb +0 -38
- data/test/cases/callbacks_test.rb +0 -438
- data/test/cases/class_inheritable_attributes_test.rb +0 -32
- data/test/cases/column_alias_test.rb +0 -17
- data/test/cases/column_definition_test.rb +0 -70
- data/test/cases/connection_pool_test.rb +0 -25
- data/test/cases/connection_test_firebird.rb +0 -8
- data/test/cases/connection_test_mysql.rb +0 -65
- data/test/cases/copy_table_test_sqlite.rb +0 -80
- data/test/cases/counter_cache_test.rb +0 -84
- data/test/cases/database_statements_test.rb +0 -12
- data/test/cases/datatype_test_postgresql.rb +0 -204
- data/test/cases/date_time_test.rb +0 -37
- data/test/cases/default_test_firebird.rb +0 -16
- data/test/cases/defaults_test.rb +0 -111
- data/test/cases/deprecated_finder_test.rb +0 -30
- data/test/cases/dirty_test.rb +0 -316
- data/test/cases/finder_respond_to_test.rb +0 -76
- data/test/cases/finder_test.rb +0 -1098
- data/test/cases/fixtures_test.rb +0 -661
- data/test/cases/helper.rb +0 -68
- data/test/cases/i18n_test.rb +0 -46
- data/test/cases/inheritance_test.rb +0 -262
- data/test/cases/invalid_date_test.rb +0 -24
- data/test/cases/json_serialization_test.rb +0 -219
- data/test/cases/lifecycle_test.rb +0 -193
- data/test/cases/locking_test.rb +0 -350
- data/test/cases/method_scoping_test.rb +0 -704
- data/test/cases/migration_test.rb +0 -1649
- data/test/cases/migration_test_firebird.rb +0 -124
- data/test/cases/mixin_test.rb +0 -96
- data/test/cases/modules_test.rb +0 -109
- data/test/cases/multiple_db_test.rb +0 -85
- data/test/cases/named_scope_test.rb +0 -372
- data/test/cases/nested_attributes_test.rb +0 -840
- data/test/cases/pk_test.rb +0 -119
- data/test/cases/pooled_connections_test.rb +0 -103
- data/test/cases/query_cache_test.rb +0 -129
- data/test/cases/readonly_test.rb +0 -107
- data/test/cases/reflection_test.rb +0 -234
- data/test/cases/reload_models_test.rb +0 -22
- data/test/cases/repair_helper.rb +0 -50
- data/test/cases/reserved_word_test_mysql.rb +0 -176
- data/test/cases/sanitize_test.rb +0 -25
- data/test/cases/schema_authorization_test_postgresql.rb +0 -75
- data/test/cases/schema_dumper_test.rb +0 -211
- data/test/cases/schema_test_postgresql.rb +0 -178
- data/test/cases/serialization_test.rb +0 -47
- data/test/cases/sp_test_mysql.rb +0 -16
- data/test/cases/synonym_test_oracle.rb +0 -17
- data/test/cases/timestamp_test.rb +0 -75
- data/test/cases/transactions_test.rb +0 -543
- data/test/cases/unconnected_test.rb +0 -32
- data/test/cases/validations_i18n_test.rb +0 -925
- data/test/cases/validations_test.rb +0 -1684
- data/test/cases/xml_serialization_test.rb +0 -240
- data/test/cases/yaml_serialization_test.rb +0 -11
- data/test/config.rb +0 -5
- data/test/connections/jdbc_jdbcderby/connection.rb +0 -18
- data/test/connections/jdbc_jdbch2/connection.rb +0 -18
- data/test/connections/jdbc_jdbchsqldb/connection.rb +0 -18
- data/test/connections/jdbc_jdbcmysql/connection.rb +0 -26
- data/test/connections/jdbc_jdbcpostgresql/connection.rb +0 -26
- data/test/connections/jdbc_jdbcsqlite3/connection.rb +0 -25
- data/test/connections/native_db2/connection.rb +0 -25
- data/test/connections/native_firebird/connection.rb +0 -26
- data/test/connections/native_frontbase/connection.rb +0 -27
- data/test/connections/native_mysql/connection.rb +0 -25
- data/test/connections/native_openbase/connection.rb +0 -21
- data/test/connections/native_oracle/connection.rb +0 -27
- data/test/connections/native_postgresql/connection.rb +0 -21
- data/test/connections/native_sqlite/connection.rb +0 -25
- data/test/connections/native_sqlite3/connection.rb +0 -25
- data/test/connections/native_sqlite3/in_memory_connection.rb +0 -18
- data/test/connections/native_sybase/connection.rb +0 -23
- data/test/fixtures/accounts.yml +0 -29
- data/test/fixtures/all/developers.yml +0 -0
- data/test/fixtures/all/people.csv +0 -0
- data/test/fixtures/all/tasks.yml +0 -0
- data/test/fixtures/author_addresses.yml +0 -5
- data/test/fixtures/author_favorites.yml +0 -4
- data/test/fixtures/authors.yml +0 -9
- data/test/fixtures/binaries.yml +0 -132
- data/test/fixtures/books.yml +0 -7
- data/test/fixtures/categories/special_categories.yml +0 -9
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +0 -4
- data/test/fixtures/categories.yml +0 -14
- data/test/fixtures/categories_ordered.yml +0 -7
- data/test/fixtures/categories_posts.yml +0 -23
- data/test/fixtures/categorizations.yml +0 -17
- data/test/fixtures/clubs.yml +0 -6
- data/test/fixtures/comments.yml +0 -59
- data/test/fixtures/companies.yml +0 -56
- data/test/fixtures/computers.yml +0 -4
- data/test/fixtures/courses.yml +0 -7
- data/test/fixtures/customers.yml +0 -26
- data/test/fixtures/developers.yml +0 -21
- data/test/fixtures/developers_projects.yml +0 -17
- data/test/fixtures/edges.yml +0 -6
- data/test/fixtures/entrants.yml +0 -14
- data/test/fixtures/faces.yml +0 -11
- data/test/fixtures/fk_test_has_fk.yml +0 -3
- data/test/fixtures/fk_test_has_pk.yml +0 -2
- data/test/fixtures/funny_jokes.yml +0 -10
- data/test/fixtures/interests.yml +0 -33
- data/test/fixtures/items.yml +0 -4
- data/test/fixtures/jobs.yml +0 -7
- data/test/fixtures/legacy_things.yml +0 -3
- data/test/fixtures/mateys.yml +0 -4
- data/test/fixtures/member_types.yml +0 -6
- data/test/fixtures/members.yml +0 -6
- data/test/fixtures/memberships.yml +0 -20
- data/test/fixtures/men.yml +0 -5
- data/test/fixtures/minimalistics.yml +0 -2
- data/test/fixtures/mixed_case_monkeys.yml +0 -6
- data/test/fixtures/mixins.yml +0 -29
- data/test/fixtures/movies.yml +0 -7
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/fixtures/naked/yml/accounts.yml +0 -1
- data/test/fixtures/naked/yml/companies.yml +0 -1
- data/test/fixtures/naked/yml/courses.yml +0 -1
- data/test/fixtures/organizations.yml +0 -5
- data/test/fixtures/owners.yml +0 -7
- data/test/fixtures/parrots.yml +0 -27
- data/test/fixtures/parrots_pirates.yml +0 -7
- data/test/fixtures/people.yml +0 -15
- data/test/fixtures/pets.yml +0 -14
- data/test/fixtures/pirates.yml +0 -9
- data/test/fixtures/polymorphic_designs.yml +0 -19
- data/test/fixtures/polymorphic_prices.yml +0 -19
- data/test/fixtures/posts.yml +0 -52
- data/test/fixtures/price_estimates.yml +0 -7
- data/test/fixtures/projects.yml +0 -7
- data/test/fixtures/readers.yml +0 -9
- data/test/fixtures/references.yml +0 -17
- data/test/fixtures/reserved_words/distinct.yml +0 -5
- data/test/fixtures/reserved_words/distincts_selects.yml +0 -11
- data/test/fixtures/reserved_words/group.yml +0 -14
- data/test/fixtures/reserved_words/select.yml +0 -8
- data/test/fixtures/reserved_words/values.yml +0 -7
- data/test/fixtures/ships.yml +0 -5
- data/test/fixtures/sponsors.yml +0 -9
- data/test/fixtures/subscribers.yml +0 -7
- data/test/fixtures/subscriptions.yml +0 -12
- data/test/fixtures/taggings.yml +0 -28
- data/test/fixtures/tags.yml +0 -7
- data/test/fixtures/tasks.yml +0 -7
- data/test/fixtures/tees.yml +0 -4
- data/test/fixtures/ties.yml +0 -4
- data/test/fixtures/topics.yml +0 -42
- data/test/fixtures/toys.yml +0 -4
- data/test/fixtures/treasures.yml +0 -10
- data/test/fixtures/vertices.yml +0 -4
- data/test/fixtures/warehouse-things.yml +0 -3
- data/test/fixtures/zines.yml +0 -5
- data/test/migrations/broken/100_migration_that_raises_exception.rb +0 -10
- data/test/migrations/decimal/1_give_me_big_numbers.rb +0 -15
- data/test/migrations/duplicate/1_people_have_last_names.rb +0 -9
- data/test/migrations/duplicate/2_we_need_reminders.rb +0 -12
- data/test/migrations/duplicate/3_foo.rb +0 -7
- data/test/migrations/duplicate/3_innocent_jointable.rb +0 -12
- data/test/migrations/duplicate_names/20080507052938_chunky.rb +0 -7
- data/test/migrations/duplicate_names/20080507053028_chunky.rb +0 -7
- data/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +0 -12
- data/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +0 -9
- data/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +0 -12
- data/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +0 -9
- data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +0 -8
- data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +0 -12
- data/test/migrations/missing/1000_people_have_middle_names.rb +0 -9
- data/test/migrations/missing/1_people_have_last_names.rb +0 -9
- data/test/migrations/missing/3_we_need_reminders.rb +0 -12
- data/test/migrations/missing/4_innocent_jointable.rb +0 -12
- data/test/migrations/valid/1_people_have_last_names.rb +0 -9
- data/test/migrations/valid/2_we_need_reminders.rb +0 -12
- data/test/migrations/valid/3_innocent_jointable.rb +0 -12
- data/test/models/author.rb +0 -151
- data/test/models/auto_id.rb +0 -4
- data/test/models/binary.rb +0 -2
- data/test/models/bird.rb +0 -9
- data/test/models/book.rb +0 -4
- data/test/models/categorization.rb +0 -5
- data/test/models/category.rb +0 -34
- data/test/models/citation.rb +0 -6
- data/test/models/club.rb +0 -13
- data/test/models/column_name.rb +0 -3
- data/test/models/comment.rb +0 -29
- data/test/models/company.rb +0 -173
- data/test/models/company_in_module.rb +0 -78
- data/test/models/computer.rb +0 -3
- data/test/models/contact.rb +0 -16
- data/test/models/contract.rb +0 -5
- data/test/models/course.rb +0 -3
- data/test/models/customer.rb +0 -73
- data/test/models/default.rb +0 -2
- data/test/models/developer.rb +0 -101
- data/test/models/edge.rb +0 -5
- data/test/models/entrant.rb +0 -3
- data/test/models/essay.rb +0 -3
- data/test/models/event.rb +0 -3
- data/test/models/event_author.rb +0 -8
- data/test/models/face.rb +0 -7
- data/test/models/guid.rb +0 -2
- data/test/models/interest.rb +0 -5
- data/test/models/invoice.rb +0 -4
- data/test/models/item.rb +0 -7
- data/test/models/job.rb +0 -5
- data/test/models/joke.rb +0 -3
- data/test/models/keyboard.rb +0 -3
- data/test/models/legacy_thing.rb +0 -3
- data/test/models/line_item.rb +0 -3
- data/test/models/man.rb +0 -9
- data/test/models/matey.rb +0 -4
- data/test/models/member.rb +0 -12
- data/test/models/member_detail.rb +0 -5
- data/test/models/member_type.rb +0 -3
- data/test/models/membership.rb +0 -9
- data/test/models/minimalistic.rb +0 -2
- data/test/models/mixed_case_monkey.rb +0 -3
- data/test/models/movie.rb +0 -5
- data/test/models/order.rb +0 -4
- data/test/models/organization.rb +0 -6
- data/test/models/owner.rb +0 -5
- data/test/models/parrot.rb +0 -22
- data/test/models/person.rb +0 -16
- data/test/models/pet.rb +0 -5
- data/test/models/pirate.rb +0 -80
- data/test/models/polymorphic_design.rb +0 -3
- data/test/models/polymorphic_price.rb +0 -3
- data/test/models/post.rb +0 -102
- data/test/models/price_estimate.rb +0 -3
- data/test/models/project.rb +0 -30
- data/test/models/reader.rb +0 -4
- data/test/models/reference.rb +0 -4
- data/test/models/reply.rb +0 -46
- data/test/models/ship.rb +0 -19
- data/test/models/ship_part.rb +0 -7
- data/test/models/sponsor.rb +0 -4
- data/test/models/subject.rb +0 -4
- data/test/models/subscriber.rb +0 -8
- data/test/models/subscription.rb +0 -4
- data/test/models/tag.rb +0 -7
- data/test/models/tagging.rb +0 -10
- data/test/models/task.rb +0 -3
- data/test/models/tee.rb +0 -4
- data/test/models/tie.rb +0 -4
- data/test/models/topic.rb +0 -80
- data/test/models/toy.rb +0 -6
- data/test/models/treasure.rb +0 -8
- data/test/models/vertex.rb +0 -9
- data/test/models/warehouse_thing.rb +0 -5
- data/test/models/zine.rb +0 -3
- data/test/schema/mysql_specific_schema.rb +0 -31
- data/test/schema/postgresql_specific_schema.rb +0 -114
- data/test/schema/schema.rb +0 -550
- data/test/schema/schema2.rb +0 -6
- data/test/schema/sqlite_specific_schema.rb +0 -25
data/README
DELETED
@@ -1,351 +0,0 @@
|
|
1
|
-
= Active Record -- Object-relation mapping put on rails
|
2
|
-
|
3
|
-
Active Record connects business objects and database tables to create a persistable
|
4
|
-
domain model where logic and data are presented in one wrapping. It's an implementation
|
5
|
-
of the object-relational mapping (ORM) pattern[http://www.martinfowler.com/eaaCatalog/activeRecord.html]
|
6
|
-
by the same name as described by Martin Fowler:
|
7
|
-
|
8
|
-
"An object that wraps a row in a database table or view, encapsulates
|
9
|
-
the database access, and adds domain logic on that data."
|
10
|
-
|
11
|
-
Active Record's main contribution to the pattern is to relieve the original of two stunting problems:
|
12
|
-
lack of associations and inheritance. By adding a simple domain language-like set of macros to describe
|
13
|
-
the former and integrating the Single Table Inheritance pattern for the latter, Active Record narrows the
|
14
|
-
gap of functionality between the data mapper and active record approach.
|
15
|
-
|
16
|
-
A short rundown of the major features:
|
17
|
-
|
18
|
-
* Automated mapping between classes and tables, attributes and columns.
|
19
|
-
|
20
|
-
class Product < ActiveRecord::Base; end
|
21
|
-
|
22
|
-
...is automatically mapped to the table named "products", such as:
|
23
|
-
|
24
|
-
CREATE TABLE products (
|
25
|
-
id int(11) NOT NULL auto_increment,
|
26
|
-
name varchar(255),
|
27
|
-
PRIMARY KEY (id)
|
28
|
-
);
|
29
|
-
|
30
|
-
...which again gives Product#name and Product#name=(new_name)
|
31
|
-
|
32
|
-
{Learn more}[link:classes/ActiveRecord/Base.html]
|
33
|
-
|
34
|
-
|
35
|
-
* Associations between objects controlled by simple meta-programming macros.
|
36
|
-
|
37
|
-
class Firm < ActiveRecord::Base
|
38
|
-
has_many :clients
|
39
|
-
has_one :account
|
40
|
-
belongs_to :conglomorate
|
41
|
-
end
|
42
|
-
|
43
|
-
{Learn more}[link:classes/ActiveRecord/Associations/ClassMethods.html]
|
44
|
-
|
45
|
-
|
46
|
-
* Aggregations of value objects controlled by simple meta-programming macros.
|
47
|
-
|
48
|
-
class Account < ActiveRecord::Base
|
49
|
-
composed_of :balance, :class_name => "Money",
|
50
|
-
:mapping => %w(balance amount)
|
51
|
-
composed_of :address,
|
52
|
-
:mapping => [%w(address_street street), %w(address_city city)]
|
53
|
-
end
|
54
|
-
|
55
|
-
{Learn more}[link:classes/ActiveRecord/Aggregations/ClassMethods.html]
|
56
|
-
|
57
|
-
|
58
|
-
* Validation rules that can differ for new or existing objects.
|
59
|
-
|
60
|
-
class Account < ActiveRecord::Base
|
61
|
-
validates_presence_of :subdomain, :name, :email_address, :password
|
62
|
-
validates_uniqueness_of :subdomain
|
63
|
-
validates_acceptance_of :terms_of_service, :on => :create
|
64
|
-
validates_confirmation_of :password, :email_address, :on => :create
|
65
|
-
end
|
66
|
-
|
67
|
-
{Learn more}[link:classes/ActiveRecord/Validations.html]
|
68
|
-
|
69
|
-
* Callbacks as methods or queues on the entire lifecycle (instantiation, saving, destroying, validating, etc).
|
70
|
-
|
71
|
-
class Person < ActiveRecord::Base
|
72
|
-
def before_destroy # is called just before Person#destroy
|
73
|
-
CreditCard.find(credit_card_id).destroy
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class Account < ActiveRecord::Base
|
78
|
-
after_find :eager_load, 'self.class.announce(#{id})'
|
79
|
-
end
|
80
|
-
|
81
|
-
{Learn more}[link:classes/ActiveRecord/Callbacks.html]
|
82
|
-
|
83
|
-
|
84
|
-
* Observers for the entire lifecycle
|
85
|
-
|
86
|
-
class CommentObserver < ActiveRecord::Observer
|
87
|
-
def after_create(comment) # is called just after Comment#save
|
88
|
-
Notifications.deliver_new_comment("david@loudthinking.com", comment)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
{Learn more}[link:classes/ActiveRecord/Observer.html]
|
93
|
-
|
94
|
-
|
95
|
-
* Inheritance hierarchies
|
96
|
-
|
97
|
-
class Company < ActiveRecord::Base; end
|
98
|
-
class Firm < Company; end
|
99
|
-
class Client < Company; end
|
100
|
-
class PriorityClient < Client; end
|
101
|
-
|
102
|
-
{Learn more}[link:classes/ActiveRecord/Base.html]
|
103
|
-
|
104
|
-
|
105
|
-
* Transactions
|
106
|
-
|
107
|
-
# Database transaction
|
108
|
-
Account.transaction do
|
109
|
-
david.withdrawal(100)
|
110
|
-
mary.deposit(100)
|
111
|
-
end
|
112
|
-
|
113
|
-
{Learn more}[link:classes/ActiveRecord/Transactions/ClassMethods.html]
|
114
|
-
|
115
|
-
|
116
|
-
* Reflections on columns, associations, and aggregations
|
117
|
-
|
118
|
-
reflection = Firm.reflect_on_association(:clients)
|
119
|
-
reflection.klass # => Client (class)
|
120
|
-
Firm.columns # Returns an array of column descriptors for the firms table
|
121
|
-
|
122
|
-
{Learn more}[link:classes/ActiveRecord/Reflection/ClassMethods.html]
|
123
|
-
|
124
|
-
|
125
|
-
* Direct manipulation (instead of service invocation)
|
126
|
-
|
127
|
-
So instead of (Hibernate[http://www.hibernate.org/] example):
|
128
|
-
|
129
|
-
long pkId = 1234;
|
130
|
-
DomesticCat pk = (DomesticCat) sess.load( Cat.class, new Long(pkId) );
|
131
|
-
// something interesting involving a cat...
|
132
|
-
sess.save(cat);
|
133
|
-
sess.flush(); // force the SQL INSERT
|
134
|
-
|
135
|
-
Active Record lets you:
|
136
|
-
|
137
|
-
pkId = 1234
|
138
|
-
cat = Cat.find(pkId)
|
139
|
-
# something even more interesting involving the same cat...
|
140
|
-
cat.save
|
141
|
-
|
142
|
-
{Learn more}[link:classes/ActiveRecord/Base.html]
|
143
|
-
|
144
|
-
|
145
|
-
* Database abstraction through simple adapters (~100 lines) with a shared connector
|
146
|
-
|
147
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite", :database => "dbfile")
|
148
|
-
|
149
|
-
ActiveRecord::Base.establish_connection(
|
150
|
-
:adapter => "mysql",
|
151
|
-
:host => "localhost",
|
152
|
-
:username => "me",
|
153
|
-
:password => "secret",
|
154
|
-
:database => "activerecord"
|
155
|
-
)
|
156
|
-
|
157
|
-
{Learn more}[link:classes/ActiveRecord/Base.html#M000081] and read about the built-in support for
|
158
|
-
MySQL[link:classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html], PostgreSQL[link:classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html], SQLite[link:classes/ActiveRecord/ConnectionAdapters/SQLiteAdapter.html], Oracle[link:classes/ActiveRecord/ConnectionAdapters/OracleAdapter.html], SQLServer[link:classes/ActiveRecord/ConnectionAdapters/SQLServerAdapter.html], and DB2[link:classes/ActiveRecord/ConnectionAdapters/DB2Adapter.html].
|
159
|
-
|
160
|
-
|
161
|
-
* Logging support for Log4r[http://log4r.sourceforge.net] and Logger[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc]
|
162
|
-
|
163
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
164
|
-
ActiveRecord::Base.logger = Log4r::Logger.new("Application Log")
|
165
|
-
|
166
|
-
|
167
|
-
* Database agnostic schema management with Migrations
|
168
|
-
|
169
|
-
class AddSystemSettings < ActiveRecord::Migration
|
170
|
-
def self.up
|
171
|
-
create_table :system_settings do |t|
|
172
|
-
t.string :name
|
173
|
-
t.string :label
|
174
|
-
t.text :value
|
175
|
-
t.string :type
|
176
|
-
t.integer :position
|
177
|
-
end
|
178
|
-
|
179
|
-
SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
|
180
|
-
end
|
181
|
-
|
182
|
-
def self.down
|
183
|
-
drop_table :system_settings
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
{Learn more}[link:classes/ActiveRecord/Migration.html]
|
188
|
-
|
189
|
-
== Simple example (1/2): Defining tables and classes (using MySQL)
|
190
|
-
|
191
|
-
Data definitions are specified only in the database. Active Record queries the database for
|
192
|
-
the column names (that then serves to determine which attributes are valid) on regular
|
193
|
-
object instantiation through the new constructor and relies on the column names in the rows
|
194
|
-
with the finders.
|
195
|
-
|
196
|
-
# CREATE TABLE companies (
|
197
|
-
# id int(11) unsigned NOT NULL auto_increment,
|
198
|
-
# client_of int(11),
|
199
|
-
# name varchar(255),
|
200
|
-
# type varchar(100),
|
201
|
-
# PRIMARY KEY (id)
|
202
|
-
# )
|
203
|
-
|
204
|
-
Active Record automatically links the "Company" object to the "companies" table
|
205
|
-
|
206
|
-
class Company < ActiveRecord::Base
|
207
|
-
has_many :people, :class_name => "Person"
|
208
|
-
end
|
209
|
-
|
210
|
-
class Firm < Company
|
211
|
-
has_many :clients
|
212
|
-
|
213
|
-
def people_with_all_clients
|
214
|
-
clients.inject([]) { |people, client| people + client.people }
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
The foreign_key is only necessary because we didn't use "firm_id" in the data definition
|
219
|
-
|
220
|
-
class Client < Company
|
221
|
-
belongs_to :firm, :foreign_key => "client_of"
|
222
|
-
end
|
223
|
-
|
224
|
-
# CREATE TABLE people (
|
225
|
-
# id int(11) unsigned NOT NULL auto_increment,
|
226
|
-
# name text,
|
227
|
-
# company_id text,
|
228
|
-
# PRIMARY KEY (id)
|
229
|
-
# )
|
230
|
-
|
231
|
-
Active Record will also automatically link the "Person" object to the "people" table
|
232
|
-
|
233
|
-
class Person < ActiveRecord::Base
|
234
|
-
belongs_to :company
|
235
|
-
end
|
236
|
-
|
237
|
-
== Simple example (2/2): Using the domain
|
238
|
-
|
239
|
-
Picking a database connection for all the Active Records
|
240
|
-
|
241
|
-
ActiveRecord::Base.establish_connection(
|
242
|
-
:adapter => "mysql",
|
243
|
-
:host => "localhost",
|
244
|
-
:username => "me",
|
245
|
-
:password => "secret",
|
246
|
-
:database => "activerecord"
|
247
|
-
)
|
248
|
-
|
249
|
-
Create some fixtures
|
250
|
-
|
251
|
-
firm = Firm.new("name" => "Next Angle")
|
252
|
-
# SQL: INSERT INTO companies (name, type) VALUES("Next Angle", "Firm")
|
253
|
-
firm.save
|
254
|
-
|
255
|
-
client = Client.new("name" => "37signals", "client_of" => firm.id)
|
256
|
-
# SQL: INSERT INTO companies (name, client_of, type) VALUES("37signals", 1, "Firm")
|
257
|
-
client.save
|
258
|
-
|
259
|
-
Lots of different finders
|
260
|
-
|
261
|
-
# SQL: SELECT * FROM companies WHERE id = 1
|
262
|
-
next_angle = Company.find(1)
|
263
|
-
|
264
|
-
# SQL: SELECT * FROM companies WHERE id = 1 AND type = 'Firm'
|
265
|
-
next_angle = Firm.find(1)
|
266
|
-
|
267
|
-
# SQL: SELECT * FROM companies WHERE id = 1 AND name = 'Next Angle'
|
268
|
-
next_angle = Company.find(:first, :conditions => "name = 'Next Angle'")
|
269
|
-
|
270
|
-
next_angle = Firm.find_by_sql("SELECT * FROM companies WHERE id = 1").first
|
271
|
-
|
272
|
-
The supertype, Company, will return subtype instances
|
273
|
-
|
274
|
-
Firm === next_angle
|
275
|
-
|
276
|
-
All the dynamic methods added by the has_many macro
|
277
|
-
|
278
|
-
next_angle.clients.empty? # true
|
279
|
-
next_angle.clients.size # total number of clients
|
280
|
-
all_clients = next_angle.clients
|
281
|
-
|
282
|
-
Constrained finds makes access security easier when ID comes from a web-app
|
283
|
-
|
284
|
-
# SQL: SELECT * FROM companies WHERE client_of = 1 AND type = 'Client' AND id = 2
|
285
|
-
thirty_seven_signals = next_angle.clients.find(2)
|
286
|
-
|
287
|
-
Bi-directional associations thanks to the "belongs_to" macro
|
288
|
-
|
289
|
-
thirty_seven_signals.firm.nil? # true
|
290
|
-
|
291
|
-
|
292
|
-
== Philosophy
|
293
|
-
|
294
|
-
Active Record attempts to provide a coherent wrapper as a solution for the inconvenience that is
|
295
|
-
object-relational mapping. The prime directive for this mapping has been to minimize
|
296
|
-
the amount of code needed to build a real-world domain model. This is made possible
|
297
|
-
by relying on a number of conventions that make it easy for Active Record to infer
|
298
|
-
complex relations and structures from a minimal amount of explicit direction.
|
299
|
-
|
300
|
-
Convention over Configuration:
|
301
|
-
* No XML-files!
|
302
|
-
* Lots of reflection and run-time extension
|
303
|
-
* Magic is not inherently a bad word
|
304
|
-
|
305
|
-
Admit the Database:
|
306
|
-
* Lets you drop down to SQL for odd cases and performance
|
307
|
-
* Doesn't attempt to duplicate or replace data definitions
|
308
|
-
|
309
|
-
|
310
|
-
== Download
|
311
|
-
|
312
|
-
The latest version of Active Record can be found at
|
313
|
-
|
314
|
-
* http://rubyforge.org/project/showfiles.php?group_id=182
|
315
|
-
|
316
|
-
Documentation can be found at
|
317
|
-
|
318
|
-
* http://ar.rubyonrails.com
|
319
|
-
|
320
|
-
|
321
|
-
== Installation
|
322
|
-
|
323
|
-
The prefered method of installing Active Record is through its GEM file. You'll need to have
|
324
|
-
RubyGems[http://rubygems.rubyforge.org/wiki/wiki.pl] installed for that, though. If you have,
|
325
|
-
then use:
|
326
|
-
|
327
|
-
% [sudo] gem install activerecord-1.10.0.gem
|
328
|
-
|
329
|
-
You can also install Active Record the old-fashioned way with the following command:
|
330
|
-
|
331
|
-
% [sudo] ruby install.rb
|
332
|
-
|
333
|
-
from its distribution directory.
|
334
|
-
|
335
|
-
|
336
|
-
== License
|
337
|
-
|
338
|
-
Active Record is released under the MIT license.
|
339
|
-
|
340
|
-
|
341
|
-
== Support
|
342
|
-
|
343
|
-
The Active Record homepage is http://www.rubyonrails.com. You can find the Active Record
|
344
|
-
RubyForge page at http://rubyforge.org/projects/activerecord. And as Jim from Rake says:
|
345
|
-
|
346
|
-
Feel free to submit commits or feature requests. If you send a patch,
|
347
|
-
remember to update the corresponding unit tests. If fact, I prefer
|
348
|
-
new feature to be submitted in the form of new unit tests.
|
349
|
-
|
350
|
-
For other information, feel free to ask on the rubyonrails-talk
|
351
|
-
(http://groups.google.com/group/rubyonrails-talk) mailing list.
|
data/RUNNING_UNIT_TESTS
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
== Creating the test database
|
2
|
-
|
3
|
-
The default names for the test databases are "activerecord_unittest" and
|
4
|
-
"activerecord_unittest2". If you want to use another database name then be sure
|
5
|
-
to update the connection adapter setups you want to test with in
|
6
|
-
test/connections/<your database>/connection.rb.
|
7
|
-
When you have the database online, you can import the fixture tables with
|
8
|
-
the test/schema/*.sql files.
|
9
|
-
|
10
|
-
Make sure that you create database objects with the same user that you specified in
|
11
|
-
connection.rb otherwise (on Postgres, at least) tests for default values will fail.
|
12
|
-
|
13
|
-
== Running with Rake
|
14
|
-
|
15
|
-
The easiest way to run the unit tests is through Rake. The default task runs
|
16
|
-
the entire test suite for all the adapters. You can also run the suite on just
|
17
|
-
one adapter by using the tasks test_mysql, test_sqlite, test_postgresql or any
|
18
|
-
of the other test_ tasks. For more information, checkout the full array of rake
|
19
|
-
tasks with "rake -T"
|
20
|
-
|
21
|
-
Rake can be found at http://rake.rubyforge.org
|
22
|
-
|
23
|
-
== Running by hand
|
24
|
-
|
25
|
-
Unit tests are located in test/cases directory. If you only want to run a single test suite,
|
26
|
-
you can do so with:
|
27
|
-
|
28
|
-
rake test_mysql TEST=test/cases/base_test.rb
|
29
|
-
|
30
|
-
That'll run the base suite using the MySQL-Ruby adapter. Some tests rely on the schema
|
31
|
-
being initialized - you can initialize the schema with:
|
32
|
-
|
33
|
-
rake test_mysql TEST=test/cases/aaa_create_tables_test.rb
|
34
|
-
|
35
|
-
|
36
|
-
|
data/Rakefile
DELETED
@@ -1,268 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rdoc/task'
|
5
|
-
require 'rake/packagetask'
|
6
|
-
require 'rubygems/package_task'
|
7
|
-
|
8
|
-
require File.join(File.dirname(__FILE__), 'lib', 'active_record', 'version')
|
9
|
-
require File.expand_path(File.dirname(__FILE__)) + "/test/config"
|
10
|
-
|
11
|
-
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
12
|
-
PKG_NAME = 'activerecord'
|
13
|
-
PKG_VERSION = ActiveRecord::VERSION::STRING + PKG_BUILD
|
14
|
-
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
15
|
-
|
16
|
-
RELEASE_NAME = "REL #{PKG_VERSION}"
|
17
|
-
|
18
|
-
RUBY_FORGE_PROJECT = "activerecord"
|
19
|
-
RUBY_FORGE_USER = "webster132"
|
20
|
-
|
21
|
-
MYSQL_DB_USER = 'rails'
|
22
|
-
|
23
|
-
PKG_FILES = FileList[
|
24
|
-
"lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "Rakefile"
|
25
|
-
].exclude(/\bCVS\b|~$/)
|
26
|
-
|
27
|
-
def run_without_aborting(*tasks)
|
28
|
-
errors = []
|
29
|
-
|
30
|
-
tasks.each do |task|
|
31
|
-
begin
|
32
|
-
Rake::Task[task].invoke
|
33
|
-
rescue Exception
|
34
|
-
errors << task
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
abort "Errors running #{errors.join(', ')}" if errors.any?
|
39
|
-
end
|
40
|
-
|
41
|
-
desc 'Run mysql, sqlite, and postgresql tests by default'
|
42
|
-
task :default => :test
|
43
|
-
|
44
|
-
desc 'Run mysql, sqlite, and postgresql tests'
|
45
|
-
task :test do
|
46
|
-
tasks = defined?(JRUBY_VERSION) ?
|
47
|
-
%w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) :
|
48
|
-
%w(test_mysql test_sqlite3 test_postgresql)
|
49
|
-
run_without_aborting(*tasks)
|
50
|
-
end
|
51
|
-
|
52
|
-
for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb )
|
53
|
-
Rake::TestTask.new("test_#{adapter}") { |t|
|
54
|
-
if adapter =~ /jdbc/
|
55
|
-
t.libs << "test" << "test/connections/jdbc_#{adapter}"
|
56
|
-
else
|
57
|
-
t.libs << "test" << "test/connections/native_#{adapter}"
|
58
|
-
end
|
59
|
-
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
|
60
|
-
t.test_files=Dir.glob( "test/cases/**/*_test{,_#{adapter_short}}.rb" ).sort
|
61
|
-
t.verbose = true
|
62
|
-
}
|
63
|
-
|
64
|
-
namespace adapter do
|
65
|
-
task :test => "test_#{adapter}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
namespace :mysql do
|
70
|
-
desc 'Build the MySQL test databases'
|
71
|
-
task :build_databases do
|
72
|
-
%x( echo "create DATABASE activerecord_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER})
|
73
|
-
%x( echo "create DATABASE activerecord_unittest2 DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER})
|
74
|
-
end
|
75
|
-
|
76
|
-
desc 'Drop the MySQL test databases'
|
77
|
-
task :drop_databases do
|
78
|
-
%x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest )
|
79
|
-
%x( mysqladmin --user=#{MYSQL_DB_USER} -f drop activerecord_unittest2 )
|
80
|
-
end
|
81
|
-
|
82
|
-
desc 'Rebuild the MySQL test databases'
|
83
|
-
task :rebuild_databases => [:drop_databases, :build_databases]
|
84
|
-
end
|
85
|
-
|
86
|
-
task :build_mysql_databases => 'mysql:build_databases'
|
87
|
-
task :drop_mysql_databases => 'mysql:drop_databases'
|
88
|
-
task :rebuild_mysql_databases => 'mysql:rebuild_databases'
|
89
|
-
|
90
|
-
|
91
|
-
namespace :postgresql do
|
92
|
-
desc 'Build the PostgreSQL test databases'
|
93
|
-
task :build_databases do
|
94
|
-
%x( createdb -E UTF8 activerecord_unittest )
|
95
|
-
%x( createdb -E UTF8 activerecord_unittest2 )
|
96
|
-
end
|
97
|
-
|
98
|
-
desc 'Drop the PostgreSQL test databases'
|
99
|
-
task :drop_databases do
|
100
|
-
%x( dropdb activerecord_unittest )
|
101
|
-
%x( dropdb activerecord_unittest2 )
|
102
|
-
end
|
103
|
-
|
104
|
-
desc 'Rebuild the PostgreSQL test databases'
|
105
|
-
task :rebuild_databases => [:drop_databases, :build_databases]
|
106
|
-
end
|
107
|
-
|
108
|
-
task :build_postgresql_databases => 'postgresql:build_databases'
|
109
|
-
task :drop_postgresql_databases => 'postgresql:drop_databases'
|
110
|
-
task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
|
111
|
-
|
112
|
-
|
113
|
-
namespace :frontbase do
|
114
|
-
desc 'Build the FrontBase test databases'
|
115
|
-
task :build_databases => :rebuild_frontbase_databases
|
116
|
-
|
117
|
-
desc 'Rebuild the FrontBase test databases'
|
118
|
-
task :rebuild_databases do
|
119
|
-
build_frontbase_database = Proc.new do |db_name, sql_definition_file|
|
120
|
-
%(
|
121
|
-
STOP DATABASE #{db_name};
|
122
|
-
DELETE DATABASE #{db_name};
|
123
|
-
CREATE DATABASE #{db_name};
|
124
|
-
|
125
|
-
CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM;
|
126
|
-
SET COMMIT FALSE;
|
127
|
-
|
128
|
-
CREATE USER RAILS;
|
129
|
-
CREATE SCHEMA RAILS AUTHORIZATION RAILS;
|
130
|
-
COMMIT;
|
131
|
-
|
132
|
-
SET SESSION AUTHORIZATION RAILS;
|
133
|
-
SCRIPT '#{sql_definition_file}';
|
134
|
-
|
135
|
-
COMMIT;
|
136
|
-
|
137
|
-
DISCONNECT ALL;
|
138
|
-
)
|
139
|
-
end
|
140
|
-
create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_ROOT, 'frontbase.sql')]
|
141
|
-
create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_ROOT, 'frontbase2.sql')]
|
142
|
-
execute_frontbase_sql = Proc.new do |sql|
|
143
|
-
system(<<-SHELL)
|
144
|
-
/Library/FrontBase/bin/sql92 <<-SQL
|
145
|
-
#{sql}
|
146
|
-
SQL
|
147
|
-
SHELL
|
148
|
-
end
|
149
|
-
execute_frontbase_sql[create_activerecord_unittest]
|
150
|
-
execute_frontbase_sql[create_activerecord_unittest2]
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
task :build_frontbase_databases => 'frontbase:build_databases'
|
155
|
-
task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
|
156
|
-
|
157
|
-
|
158
|
-
# Generate the RDoc documentation
|
159
|
-
|
160
|
-
RDoc::Task.new { |rdoc|
|
161
|
-
rdoc.rdoc_dir = 'doc'
|
162
|
-
rdoc.title = "Active Record -- Object-relation mapping put on rails"
|
163
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
164
|
-
rdoc.options << '--charset' << 'utf-8'
|
165
|
-
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
|
166
|
-
rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
|
167
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
168
|
-
rdoc.rdoc_files.exclude('lib/active_record/vendor/*')
|
169
|
-
rdoc.rdoc_files.include('dev-utils/*.rb')
|
170
|
-
}
|
171
|
-
|
172
|
-
# Enhance rdoc task to copy referenced images also
|
173
|
-
task :rdoc do
|
174
|
-
FileUtils.mkdir_p "doc/files/examples/"
|
175
|
-
FileUtils.copy "examples/associations.png", "doc/files/examples/associations.png"
|
176
|
-
end
|
177
|
-
|
178
|
-
|
179
|
-
# Create compressed packages
|
180
|
-
|
181
|
-
dist_dirs = [ "lib", "test", "examples" ]
|
182
|
-
|
183
|
-
spec = Gem::Specification.new do |s|
|
184
|
-
s.platform = Gem::Platform::RUBY
|
185
|
-
s.name = PKG_NAME
|
186
|
-
s.version = PKG_VERSION
|
187
|
-
s.summary = "Implements the ActiveRecord pattern for ORM."
|
188
|
-
s.description = %q{Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties database tables and classes together for business objects, like Customer or Subscription, that can find, save, and destroy themselves without resorting to manual SQL.}
|
189
|
-
|
190
|
-
s.files = [ "Rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG" ]
|
191
|
-
dist_dirs.each do |dir|
|
192
|
-
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
193
|
-
end
|
194
|
-
|
195
|
-
s.add_dependency('activesupport', '= 2.3.18' + PKG_BUILD)
|
196
|
-
|
197
|
-
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
|
198
|
-
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"
|
199
|
-
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite3"
|
200
|
-
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite3"
|
201
|
-
s.require_path = 'lib'
|
202
|
-
|
203
|
-
s.extra_rdoc_files = %w( README )
|
204
|
-
s.rdoc_options.concat ['--main', 'README']
|
205
|
-
|
206
|
-
s.author = "David Heinemeier Hansson"
|
207
|
-
s.email = "david@loudthinking.com"
|
208
|
-
s.homepage = "http://www.rubyonrails.org"
|
209
|
-
s.rubyforge_project = "activerecord"
|
210
|
-
end
|
211
|
-
|
212
|
-
Gem::PackageTask.new(spec) do |p|
|
213
|
-
p.gem_spec = spec
|
214
|
-
p.need_tar = true
|
215
|
-
p.need_zip = true
|
216
|
-
end
|
217
|
-
|
218
|
-
task :lines do
|
219
|
-
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
220
|
-
|
221
|
-
for file_name in FileList["lib/active_record/**/*.rb"]
|
222
|
-
next if file_name =~ /vendor/
|
223
|
-
f = File.open(file_name)
|
224
|
-
|
225
|
-
while line = f.gets
|
226
|
-
lines += 1
|
227
|
-
next if line =~ /^\s*$/
|
228
|
-
next if line =~ /^\s*#/
|
229
|
-
codelines += 1
|
230
|
-
end
|
231
|
-
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
232
|
-
|
233
|
-
total_lines += lines
|
234
|
-
total_codelines += codelines
|
235
|
-
|
236
|
-
lines, codelines = 0, 0
|
237
|
-
end
|
238
|
-
|
239
|
-
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
240
|
-
end
|
241
|
-
|
242
|
-
|
243
|
-
# Publishing ------------------------------------------------------
|
244
|
-
|
245
|
-
desc "Publish the beta gem"
|
246
|
-
task :pgem => [:package] do
|
247
|
-
require 'rake/contrib/sshpublisher'
|
248
|
-
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
249
|
-
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
|
250
|
-
end
|
251
|
-
|
252
|
-
desc "Publish the API documentation"
|
253
|
-
task :pdoc => [:rdoc] do
|
254
|
-
require 'rake/contrib/sshpublisher'
|
255
|
-
Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/ar", "doc").upload
|
256
|
-
end
|
257
|
-
|
258
|
-
desc "Publish the release files to RubyForge."
|
259
|
-
task :release => [ :package ] do
|
260
|
-
require 'rubyforge'
|
261
|
-
require 'rake/contrib/rubyforgepublisher'
|
262
|
-
|
263
|
-
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
264
|
-
|
265
|
-
rubyforge = RubyForge.new
|
266
|
-
rubyforge.login
|
267
|
-
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
|
268
|
-
end
|
data/install.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'find'
|
3
|
-
require 'ftools'
|
4
|
-
|
5
|
-
include Config
|
6
|
-
|
7
|
-
# this was adapted from rdoc's install.rb by ways of Log4r
|
8
|
-
|
9
|
-
$sitedir = CONFIG["sitelibdir"]
|
10
|
-
unless $sitedir
|
11
|
-
version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
|
12
|
-
$libdir = File.join(CONFIG["libdir"], "ruby", version)
|
13
|
-
$sitedir = $:.find {|x| x =~ /site_ruby/ }
|
14
|
-
if !$sitedir
|
15
|
-
$sitedir = File.join($libdir, "site_ruby")
|
16
|
-
elsif $sitedir !~ Regexp.quote(version)
|
17
|
-
$sitedir = File.join($sitedir, version)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# the actual gruntwork
|
22
|
-
Dir.chdir("lib")
|
23
|
-
|
24
|
-
Find.find("active_record", "active_record.rb") { |f|
|
25
|
-
if f[-3..-1] == ".rb"
|
26
|
-
File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
|
27
|
-
else
|
28
|
-
File::makedirs(File.join($sitedir, *f.split(/\//)))
|
29
|
-
end
|
30
|
-
}
|