activerecord_csi 2.3.5.p6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5858 -0
- data/README +351 -0
- data/RUNNING_UNIT_TESTS +36 -0
- data/Rakefile +270 -0
- data/examples/associations.png +0 -0
- data/examples/performance.rb +162 -0
- data/install.rb +30 -0
- data/lib/active_record/aggregations.rb +261 -0
- data/lib/active_record/association_preload.rb +389 -0
- data/lib/active_record/associations/association_collection.rb +475 -0
- data/lib/active_record/associations/association_proxy.rb +278 -0
- data/lib/active_record/associations/belongs_to_association.rb +76 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +53 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +143 -0
- data/lib/active_record/associations/has_many_association.rb +122 -0
- data/lib/active_record/associations/has_many_through_association.rb +266 -0
- data/lib/active_record/associations/has_one_association.rb +133 -0
- data/lib/active_record/associations/has_one_through_association.rb +37 -0
- data/lib/active_record/associations.rb +2241 -0
- data/lib/active_record/attribute_methods.rb +388 -0
- data/lib/active_record/autosave_association.rb +364 -0
- data/lib/active_record/base.rb +3171 -0
- data/lib/active_record/batches.rb +81 -0
- data/lib/active_record/calculations.rb +311 -0
- data/lib/active_record/callbacks.rb +360 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +371 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +139 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +289 -0
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +94 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +69 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +722 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +434 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +241 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +630 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1113 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +453 -0
- data/lib/active_record/dirty.rb +183 -0
- data/lib/active_record/dynamic_finder_match.rb +41 -0
- data/lib/active_record/dynamic_scope_match.rb +25 -0
- data/lib/active_record/fixtures.rb +996 -0
- data/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
- data/lib/active_record/locale/en.yml +58 -0
- data/lib/active_record/locking/optimistic.rb +148 -0
- data/lib/active_record/locking/pessimistic.rb +55 -0
- data/lib/active_record/migration.rb +566 -0
- data/lib/active_record/named_scope.rb +192 -0
- data/lib/active_record/nested_attributes.rb +392 -0
- data/lib/active_record/observer.rb +197 -0
- data/lib/active_record/query_cache.rb +33 -0
- data/lib/active_record/reflection.rb +320 -0
- data/lib/active_record/schema.rb +51 -0
- data/lib/active_record/schema_dumper.rb +182 -0
- data/lib/active_record/serialization.rb +101 -0
- data/lib/active_record/serializers/json_serializer.rb +91 -0
- data/lib/active_record/serializers/xml_serializer.rb +357 -0
- data/lib/active_record/session_store.rb +326 -0
- data/lib/active_record/test_case.rb +66 -0
- data/lib/active_record/timestamp.rb +71 -0
- data/lib/active_record/transactions.rb +235 -0
- data/lib/active_record/validations.rb +1135 -0
- data/lib/active_record/version.rb +9 -0
- data/lib/active_record.rb +84 -0
- data/lib/activerecord.rb +2 -0
- data/test/assets/example.log +1 -0
- data/test/assets/flowers.jpg +0 -0
- data/test/cases/aaa_create_tables_test.rb +24 -0
- data/test/cases/active_schema_test_mysql.rb +100 -0
- data/test/cases/active_schema_test_postgresql.rb +24 -0
- data/test/cases/adapter_test.rb +145 -0
- data/test/cases/aggregations_test.rb +167 -0
- data/test/cases/ar_schema_test.rb +32 -0
- data/test/cases/associations/belongs_to_associations_test.rb +425 -0
- data/test/cases/associations/callbacks_test.rb +161 -0
- data/test/cases/associations/cascaded_eager_loading_test.rb +131 -0
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +36 -0
- data/test/cases/associations/eager_load_nested_include_test.rb +130 -0
- data/test/cases/associations/eager_singularization_test.rb +145 -0
- data/test/cases/associations/eager_test.rb +834 -0
- data/test/cases/associations/extension_test.rb +62 -0
- data/test/cases/associations/habtm_join_table_test.rb +56 -0
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +822 -0
- data/test/cases/associations/has_many_associations_test.rb +1134 -0
- data/test/cases/associations/has_many_through_associations_test.rb +346 -0
- data/test/cases/associations/has_one_associations_test.rb +330 -0
- data/test/cases/associations/has_one_through_associations_test.rb +209 -0
- data/test/cases/associations/inner_join_association_test.rb +93 -0
- data/test/cases/associations/join_model_test.rb +712 -0
- data/test/cases/associations_test.rb +262 -0
- data/test/cases/attribute_methods_test.rb +305 -0
- data/test/cases/autosave_association_test.rb +1142 -0
- data/test/cases/base_test.rb +2154 -0
- data/test/cases/batches_test.rb +61 -0
- data/test/cases/binary_test.rb +30 -0
- data/test/cases/calculations_test.rb +348 -0
- data/test/cases/callbacks_observers_test.rb +38 -0
- data/test/cases/callbacks_test.rb +438 -0
- data/test/cases/class_inheritable_attributes_test.rb +32 -0
- data/test/cases/column_alias_test.rb +17 -0
- data/test/cases/column_definition_test.rb +70 -0
- data/test/cases/connection_pool_test.rb +25 -0
- data/test/cases/connection_test_firebird.rb +8 -0
- data/test/cases/connection_test_mysql.rb +64 -0
- data/test/cases/copy_table_test_sqlite.rb +80 -0
- data/test/cases/database_statements_test.rb +12 -0
- data/test/cases/datatype_test_postgresql.rb +204 -0
- data/test/cases/date_time_test.rb +37 -0
- data/test/cases/default_test_firebird.rb +16 -0
- data/test/cases/defaults_test.rb +111 -0
- data/test/cases/deprecated_finder_test.rb +30 -0
- data/test/cases/dirty_test.rb +316 -0
- data/test/cases/finder_respond_to_test.rb +76 -0
- data/test/cases/finder_test.rb +1066 -0
- data/test/cases/fixtures_test.rb +656 -0
- data/test/cases/helper.rb +68 -0
- data/test/cases/i18n_test.rb +46 -0
- data/test/cases/inheritance_test.rb +262 -0
- data/test/cases/invalid_date_test.rb +24 -0
- data/test/cases/json_serialization_test.rb +205 -0
- data/test/cases/lifecycle_test.rb +193 -0
- data/test/cases/locking_test.rb +304 -0
- data/test/cases/method_scoping_test.rb +704 -0
- data/test/cases/migration_test.rb +1523 -0
- data/test/cases/migration_test_firebird.rb +124 -0
- data/test/cases/mixin_test.rb +96 -0
- data/test/cases/modules_test.rb +81 -0
- data/test/cases/multiple_db_test.rb +85 -0
- data/test/cases/named_scope_test.rb +361 -0
- data/test/cases/nested_attributes_test.rb +581 -0
- data/test/cases/pk_test.rb +119 -0
- data/test/cases/pooled_connections_test.rb +103 -0
- data/test/cases/query_cache_test.rb +123 -0
- data/test/cases/readonly_test.rb +107 -0
- data/test/cases/reflection_test.rb +194 -0
- data/test/cases/reload_models_test.rb +22 -0
- data/test/cases/repair_helper.rb +50 -0
- data/test/cases/reserved_word_test_mysql.rb +176 -0
- data/test/cases/sanitize_test.rb +25 -0
- data/test/cases/schema_authorization_test_postgresql.rb +75 -0
- data/test/cases/schema_dumper_test.rb +211 -0
- data/test/cases/schema_test_postgresql.rb +178 -0
- data/test/cases/serialization_test.rb +47 -0
- data/test/cases/synonym_test_oracle.rb +17 -0
- data/test/cases/timestamp_test.rb +75 -0
- data/test/cases/transactions_test.rb +522 -0
- data/test/cases/unconnected_test.rb +32 -0
- data/test/cases/validations_i18n_test.rb +955 -0
- data/test/cases/validations_test.rb +1640 -0
- data/test/cases/xml_serialization_test.rb +240 -0
- data/test/config.rb +5 -0
- data/test/connections/jdbc_jdbcderby/connection.rb +18 -0
- data/test/connections/jdbc_jdbch2/connection.rb +18 -0
- data/test/connections/jdbc_jdbchsqldb/connection.rb +18 -0
- data/test/connections/jdbc_jdbcmysql/connection.rb +26 -0
- data/test/connections/jdbc_jdbcpostgresql/connection.rb +26 -0
- data/test/connections/jdbc_jdbcsqlite3/connection.rb +25 -0
- data/test/connections/native_db2/connection.rb +25 -0
- data/test/connections/native_firebird/connection.rb +26 -0
- data/test/connections/native_frontbase/connection.rb +27 -0
- data/test/connections/native_mysql/connection.rb +25 -0
- data/test/connections/native_openbase/connection.rb +21 -0
- data/test/connections/native_oracle/connection.rb +27 -0
- data/test/connections/native_postgresql/connection.rb +25 -0
- data/test/connections/native_sqlite/connection.rb +25 -0
- data/test/connections/native_sqlite3/connection.rb +25 -0
- data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
- data/test/connections/native_sybase/connection.rb +23 -0
- data/test/fixtures/accounts.yml +29 -0
- 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 +5 -0
- data/test/fixtures/author_favorites.yml +4 -0
- data/test/fixtures/authors.yml +9 -0
- data/test/fixtures/binaries.yml +132 -0
- data/test/fixtures/books.yml +7 -0
- data/test/fixtures/categories/special_categories.yml +9 -0
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/categories_ordered.yml +7 -0
- data/test/fixtures/categories_posts.yml +23 -0
- data/test/fixtures/categorizations.yml +17 -0
- data/test/fixtures/clubs.yml +6 -0
- data/test/fixtures/comments.yml +59 -0
- data/test/fixtures/companies.yml +56 -0
- data/test/fixtures/computers.yml +4 -0
- data/test/fixtures/courses.yml +7 -0
- data/test/fixtures/customers.yml +26 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +17 -0
- data/test/fixtures/edges.yml +6 -0
- data/test/fixtures/entrants.yml +14 -0
- data/test/fixtures/fixture_database.sqlite3 +0 -0
- data/test/fixtures/fixture_database_2.sqlite3 +0 -0
- data/test/fixtures/fk_test_has_fk.yml +3 -0
- data/test/fixtures/fk_test_has_pk.yml +2 -0
- data/test/fixtures/funny_jokes.yml +10 -0
- data/test/fixtures/items.yml +4 -0
- data/test/fixtures/jobs.yml +7 -0
- data/test/fixtures/legacy_things.yml +3 -0
- data/test/fixtures/mateys.yml +4 -0
- data/test/fixtures/member_types.yml +6 -0
- data/test/fixtures/members.yml +6 -0
- data/test/fixtures/memberships.yml +20 -0
- data/test/fixtures/minimalistics.yml +2 -0
- data/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/test/fixtures/mixins.yml +29 -0
- data/test/fixtures/movies.yml +7 -0
- data/test/fixtures/naked/csv/accounts.csv +1 -0
- data/test/fixtures/naked/yml/accounts.yml +1 -0
- data/test/fixtures/naked/yml/companies.yml +1 -0
- data/test/fixtures/naked/yml/courses.yml +1 -0
- data/test/fixtures/organizations.yml +5 -0
- data/test/fixtures/owners.yml +7 -0
- data/test/fixtures/parrots.yml +27 -0
- data/test/fixtures/parrots_pirates.yml +7 -0
- data/test/fixtures/people.yml +15 -0
- data/test/fixtures/pets.yml +14 -0
- data/test/fixtures/pirates.yml +9 -0
- data/test/fixtures/posts.yml +52 -0
- data/test/fixtures/price_estimates.yml +7 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/readers.yml +9 -0
- data/test/fixtures/references.yml +17 -0
- data/test/fixtures/reserved_words/distinct.yml +5 -0
- data/test/fixtures/reserved_words/distincts_selects.yml +11 -0
- data/test/fixtures/reserved_words/group.yml +14 -0
- data/test/fixtures/reserved_words/select.yml +8 -0
- data/test/fixtures/reserved_words/values.yml +7 -0
- data/test/fixtures/ships.yml +5 -0
- data/test/fixtures/sponsors.yml +9 -0
- data/test/fixtures/subscribers.yml +7 -0
- data/test/fixtures/subscriptions.yml +12 -0
- data/test/fixtures/taggings.yml +28 -0
- data/test/fixtures/tags.yml +7 -0
- data/test/fixtures/tasks.yml +7 -0
- data/test/fixtures/topics.yml +42 -0
- data/test/fixtures/toys.yml +4 -0
- data/test/fixtures/treasures.yml +10 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures/warehouse-things.yml +3 -0
- data/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
- data/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
- data/test/migrations/duplicate/1_people_have_last_names.rb +9 -0
- data/test/migrations/duplicate/2_we_need_reminders.rb +12 -0
- data/test/migrations/duplicate/3_foo.rb +7 -0
- data/test/migrations/duplicate/3_innocent_jointable.rb +12 -0
- data/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
- data/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
- data/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +12 -0
- data/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +9 -0
- data/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +12 -0
- data/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +9 -0
- data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
- data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
- data/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
- data/test/migrations/missing/1_people_have_last_names.rb +9 -0
- data/test/migrations/missing/3_we_need_reminders.rb +12 -0
- data/test/migrations/missing/4_innocent_jointable.rb +12 -0
- data/test/migrations/valid/1_people_have_last_names.rb +9 -0
- data/test/migrations/valid/2_we_need_reminders.rb +12 -0
- data/test/migrations/valid/3_innocent_jointable.rb +12 -0
- data/test/models/author.rb +146 -0
- data/test/models/auto_id.rb +4 -0
- data/test/models/binary.rb +2 -0
- data/test/models/bird.rb +3 -0
- data/test/models/book.rb +4 -0
- data/test/models/categorization.rb +5 -0
- data/test/models/category.rb +34 -0
- data/test/models/citation.rb +6 -0
- data/test/models/club.rb +13 -0
- data/test/models/column_name.rb +3 -0
- data/test/models/comment.rb +29 -0
- data/test/models/company.rb +171 -0
- data/test/models/company_in_module.rb +61 -0
- data/test/models/computer.rb +3 -0
- data/test/models/contact.rb +16 -0
- data/test/models/contract.rb +5 -0
- data/test/models/course.rb +3 -0
- data/test/models/customer.rb +73 -0
- data/test/models/default.rb +2 -0
- data/test/models/developer.rb +101 -0
- data/test/models/edge.rb +5 -0
- data/test/models/entrant.rb +3 -0
- data/test/models/essay.rb +3 -0
- data/test/models/event.rb +3 -0
- data/test/models/guid.rb +2 -0
- data/test/models/item.rb +7 -0
- data/test/models/job.rb +5 -0
- data/test/models/joke.rb +3 -0
- data/test/models/keyboard.rb +3 -0
- data/test/models/legacy_thing.rb +3 -0
- data/test/models/matey.rb +4 -0
- data/test/models/member.rb +12 -0
- data/test/models/member_detail.rb +5 -0
- data/test/models/member_type.rb +3 -0
- data/test/models/membership.rb +9 -0
- data/test/models/minimalistic.rb +2 -0
- data/test/models/mixed_case_monkey.rb +3 -0
- data/test/models/movie.rb +5 -0
- data/test/models/order.rb +4 -0
- data/test/models/organization.rb +6 -0
- data/test/models/owner.rb +5 -0
- data/test/models/parrot.rb +16 -0
- data/test/models/person.rb +16 -0
- data/test/models/pet.rb +5 -0
- data/test/models/pirate.rb +70 -0
- data/test/models/post.rb +100 -0
- data/test/models/price_estimate.rb +3 -0
- data/test/models/project.rb +30 -0
- data/test/models/reader.rb +4 -0
- data/test/models/reference.rb +4 -0
- data/test/models/reply.rb +46 -0
- data/test/models/ship.rb +10 -0
- data/test/models/ship_part.rb +5 -0
- data/test/models/sponsor.rb +4 -0
- data/test/models/subject.rb +4 -0
- data/test/models/subscriber.rb +8 -0
- data/test/models/subscription.rb +4 -0
- data/test/models/tag.rb +7 -0
- data/test/models/tagging.rb +10 -0
- data/test/models/task.rb +3 -0
- data/test/models/topic.rb +80 -0
- data/test/models/toy.rb +6 -0
- data/test/models/treasure.rb +8 -0
- data/test/models/vertex.rb +9 -0
- data/test/models/warehouse_thing.rb +5 -0
- data/test/schema/mysql_specific_schema.rb +24 -0
- data/test/schema/postgresql_specific_schema.rb +114 -0
- data/test/schema/schema.rb +493 -0
- data/test/schema/schema2.rb +6 -0
- data/test/schema/sqlite_specific_schema.rb +25 -0
- metadata +420 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2004-2009 David Heinemeier Hansson
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
#++
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
require 'active_support'
|
|
26
|
+
rescue LoadError
|
|
27
|
+
activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
|
|
28
|
+
if File.directory?(activesupport_path)
|
|
29
|
+
$:.unshift activesupport_path
|
|
30
|
+
require 'active_support'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module ActiveRecord
|
|
35
|
+
# TODO: Review explicit loads to see if they will automatically be handled by the initilizer.
|
|
36
|
+
def self.load_all!
|
|
37
|
+
[Base, DynamicFinderMatch, ConnectionAdapters::AbstractAdapter]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
autoload :VERSION, 'active_record/version'
|
|
41
|
+
|
|
42
|
+
autoload :ActiveRecordError, 'active_record/base'
|
|
43
|
+
autoload :ConnectionNotEstablished, 'active_record/base'
|
|
44
|
+
|
|
45
|
+
autoload :Aggregations, 'active_record/aggregations'
|
|
46
|
+
autoload :AssociationPreload, 'active_record/association_preload'
|
|
47
|
+
autoload :Associations, 'active_record/associations'
|
|
48
|
+
autoload :AttributeMethods, 'active_record/attribute_methods'
|
|
49
|
+
autoload :AutosaveAssociation, 'active_record/autosave_association'
|
|
50
|
+
autoload :Base, 'active_record/base'
|
|
51
|
+
autoload :Batches, 'active_record/batches'
|
|
52
|
+
autoload :Calculations, 'active_record/calculations'
|
|
53
|
+
autoload :Callbacks, 'active_record/callbacks'
|
|
54
|
+
autoload :Dirty, 'active_record/dirty'
|
|
55
|
+
autoload :DynamicFinderMatch, 'active_record/dynamic_finder_match'
|
|
56
|
+
autoload :DynamicScopeMatch, 'active_record/dynamic_scope_match'
|
|
57
|
+
autoload :Migration, 'active_record/migration'
|
|
58
|
+
autoload :Migrator, 'active_record/migration'
|
|
59
|
+
autoload :NamedScope, 'active_record/named_scope'
|
|
60
|
+
autoload :NestedAttributes, 'active_record/nested_attributes'
|
|
61
|
+
autoload :Observing, 'active_record/observer'
|
|
62
|
+
autoload :QueryCache, 'active_record/query_cache'
|
|
63
|
+
autoload :Reflection, 'active_record/reflection'
|
|
64
|
+
autoload :Schema, 'active_record/schema'
|
|
65
|
+
autoload :SchemaDumper, 'active_record/schema_dumper'
|
|
66
|
+
autoload :Serialization, 'active_record/serialization'
|
|
67
|
+
autoload :SessionStore, 'active_record/session_store'
|
|
68
|
+
autoload :TestCase, 'active_record/test_case'
|
|
69
|
+
autoload :Timestamp, 'active_record/timestamp'
|
|
70
|
+
autoload :Transactions, 'active_record/transactions'
|
|
71
|
+
autoload :Validations, 'active_record/validations'
|
|
72
|
+
|
|
73
|
+
module Locking
|
|
74
|
+
autoload :Optimistic, 'active_record/locking/optimistic'
|
|
75
|
+
autoload :Pessimistic, 'active_record/locking/pessimistic'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
module ConnectionAdapters
|
|
79
|
+
autoload :AbstractAdapter, 'active_record/connection_adapters/abstract_adapter'
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
require 'active_record/i18n_interpolation_deprecation'
|
|
84
|
+
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
|
data/lib/activerecord.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Logfile created on Wed Oct 31 16:05:13 +0000 2007 by logger.rb/1.5.2.9
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# The filename begins with "aaa" to ensure this is the first test.
|
|
2
|
+
require "cases/helper"
|
|
3
|
+
|
|
4
|
+
class AAACreateTablesTest < ActiveRecord::TestCase
|
|
5
|
+
self.use_transactional_fixtures = false
|
|
6
|
+
|
|
7
|
+
def test_load_schema
|
|
8
|
+
eval(File.read(SCHEMA_ROOT + "/schema.rb"))
|
|
9
|
+
if File.exists?(adapter_specific_schema_file)
|
|
10
|
+
eval(File.read(adapter_specific_schema_file))
|
|
11
|
+
end
|
|
12
|
+
assert true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_drop_and_create_courses_table
|
|
16
|
+
eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
|
|
17
|
+
assert true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
def adapter_specific_schema_file
|
|
22
|
+
SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require "cases/helper"
|
|
2
|
+
|
|
3
|
+
class ActiveSchemaTest < ActiveRecord::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
|
|
6
|
+
alias_method :execute_without_stub, :execute
|
|
7
|
+
def execute(sql, name = nil) return sql end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def teardown
|
|
12
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
|
|
13
|
+
remove_method :execute
|
|
14
|
+
alias_method :execute, :execute_without_stub
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_drop_table
|
|
19
|
+
assert_equal "DROP TABLE `people`", drop_table(:people)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if current_adapter?(:MysqlAdapter)
|
|
23
|
+
def test_create_mysql_database_with_encoding
|
|
24
|
+
assert_equal "CREATE DATABASE `matt` DEFAULT CHARACTER SET `utf8`", create_database(:matt)
|
|
25
|
+
assert_equal "CREATE DATABASE `aimonetti` DEFAULT CHARACTER SET `latin1`", create_database(:aimonetti, {:charset => 'latin1'})
|
|
26
|
+
assert_equal "CREATE DATABASE `matt_aimonetti` DEFAULT CHARACTER SET `big5` COLLATE `big5_chinese_ci`", create_database(:matt_aimonetti, {:charset => :big5, :collation => :big5_chinese_ci})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_recreate_mysql_database_with_encoding
|
|
30
|
+
create_database(:luca, {:charset => 'latin1'})
|
|
31
|
+
assert_equal "CREATE DATABASE `luca` DEFAULT CHARACTER SET `latin1`", recreate_database(:luca, {:charset => 'latin1'})
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_add_column
|
|
36
|
+
assert_equal "ALTER TABLE `people` ADD `last_name` varchar(255)", add_column(:people, :last_name, :string)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_add_column_with_limit
|
|
40
|
+
assert_equal "ALTER TABLE `people` ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_drop_table_with_specific_database
|
|
44
|
+
assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_add_timestamps
|
|
48
|
+
with_real_execute do
|
|
49
|
+
begin
|
|
50
|
+
ActiveRecord::Base.connection.create_table :delete_me do |t|
|
|
51
|
+
end
|
|
52
|
+
ActiveRecord::Base.connection.add_timestamps :delete_me
|
|
53
|
+
assert column_present?('delete_me', 'updated_at', 'datetime')
|
|
54
|
+
assert column_present?('delete_me', 'created_at', 'datetime')
|
|
55
|
+
ensure
|
|
56
|
+
ActiveRecord::Base.connection.drop_table :delete_me rescue nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_remove_timestamps
|
|
62
|
+
with_real_execute do
|
|
63
|
+
begin
|
|
64
|
+
ActiveRecord::Base.connection.create_table :delete_me do |t|
|
|
65
|
+
t.timestamps
|
|
66
|
+
end
|
|
67
|
+
ActiveRecord::Base.connection.remove_timestamps :delete_me
|
|
68
|
+
assert !column_present?('delete_me', 'updated_at', 'datetime')
|
|
69
|
+
assert !column_present?('delete_me', 'created_at', 'datetime')
|
|
70
|
+
ensure
|
|
71
|
+
ActiveRecord::Base.connection.drop_table :delete_me rescue nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
def with_real_execute
|
|
78
|
+
#we need to actually modify some data, so we make execute point to the original method
|
|
79
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
|
|
80
|
+
alias_method :execute_with_stub, :execute
|
|
81
|
+
alias_method :execute, :execute_without_stub
|
|
82
|
+
end
|
|
83
|
+
yield
|
|
84
|
+
ensure
|
|
85
|
+
#before finishing, we restore the alias to the mock-up method
|
|
86
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
|
|
87
|
+
alias_method :execute, :execute_with_stub
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def method_missing(method_symbol, *arguments)
|
|
93
|
+
ActiveRecord::Base.connection.send(method_symbol, *arguments)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def column_present?(table_name, column_name, type)
|
|
97
|
+
results = ActiveRecord::Base.connection.select_all("SHOW FIELDS FROM #{table_name} LIKE '#{column_name}'")
|
|
98
|
+
results.first && results.first['Type'] == type
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'cases/helper'
|
|
2
|
+
|
|
3
|
+
class PostgresqlActiveSchemaTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
|
6
|
+
alias_method :real_execute, :execute
|
|
7
|
+
def execute(sql, name = nil) sql end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def teardown
|
|
12
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:alias_method, :execute, :real_execute)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_create_database_with_encoding
|
|
16
|
+
assert_equal %(CREATE DATABASE "matt" ENCODING = 'utf8'), create_database(:matt)
|
|
17
|
+
assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, :encoding => :latin1)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
def method_missing(method_symbol, *arguments)
|
|
22
|
+
ActiveRecord::Base.connection.send(method_symbol, *arguments)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require "cases/helper"
|
|
2
|
+
|
|
3
|
+
class AdapterTest < ActiveRecord::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@connection = ActiveRecord::Base.connection
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_tables
|
|
9
|
+
tables = @connection.tables
|
|
10
|
+
assert tables.include?("accounts")
|
|
11
|
+
assert tables.include?("authors")
|
|
12
|
+
assert tables.include?("tasks")
|
|
13
|
+
assert tables.include?("topics")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_table_exists?
|
|
17
|
+
assert @connection.table_exists?("accounts")
|
|
18
|
+
assert !@connection.table_exists?("nonexistingtable")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_indexes
|
|
22
|
+
idx_name = "accounts_idx"
|
|
23
|
+
|
|
24
|
+
if @connection.respond_to?(:indexes)
|
|
25
|
+
indexes = @connection.indexes("accounts")
|
|
26
|
+
assert indexes.empty?
|
|
27
|
+
|
|
28
|
+
@connection.add_index :accounts, :firm_id, :name => idx_name
|
|
29
|
+
indexes = @connection.indexes("accounts")
|
|
30
|
+
assert_equal "accounts", indexes.first.table
|
|
31
|
+
# OpenBase does not have the concept of a named index
|
|
32
|
+
# Indexes are merely properties of columns.
|
|
33
|
+
assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter)
|
|
34
|
+
assert !indexes.first.unique
|
|
35
|
+
assert_equal ["firm_id"], indexes.first.columns
|
|
36
|
+
else
|
|
37
|
+
warn "#{@connection.class} does not respond to #indexes"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
ensure
|
|
41
|
+
@connection.remove_index(:accounts, :name => idx_name) rescue nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_current_database
|
|
45
|
+
if @connection.respond_to?(:current_database)
|
|
46
|
+
assert_equal ENV['ARUNIT_DB_NAME'] || "activerecord_unittest", @connection.current_database
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if current_adapter?(:MysqlAdapter)
|
|
51
|
+
def test_charset
|
|
52
|
+
assert_not_nil @connection.charset
|
|
53
|
+
assert_not_equal 'character_set_database', @connection.charset
|
|
54
|
+
assert_equal @connection.show_variable('character_set_database'), @connection.charset
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_collation
|
|
58
|
+
assert_not_nil @connection.collation
|
|
59
|
+
assert_not_equal 'collation_database', @connection.collation
|
|
60
|
+
assert_equal @connection.show_variable('collation_database'), @connection.collation
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_show_nonexistent_variable_returns_nil
|
|
64
|
+
assert_nil @connection.show_variable('foo_bar_baz')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_not_specifying_database_name_for_cross_database_selects
|
|
68
|
+
assert_nothing_raised do
|
|
69
|
+
ActiveRecord::Base.establish_connection({
|
|
70
|
+
:adapter => 'mysql',
|
|
71
|
+
:username => 'rails'
|
|
72
|
+
})
|
|
73
|
+
ActiveRecord::Base.connection.execute "SELECT activerecord_unittest.pirates.*, activerecord_unittest2.courses.* FROM activerecord_unittest.pirates, activerecord_unittest2.courses"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
81
|
+
def test_encoding
|
|
82
|
+
assert_not_nil @connection.encoding
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_table_alias
|
|
87
|
+
def @connection.test_table_alias_length() 10; end
|
|
88
|
+
class << @connection
|
|
89
|
+
alias_method :old_table_alias_length, :table_alias_length
|
|
90
|
+
alias_method :table_alias_length, :test_table_alias_length
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
assert_equal 'posts', @connection.table_alias_for('posts')
|
|
94
|
+
assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
|
|
95
|
+
assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
|
|
96
|
+
|
|
97
|
+
class << @connection
|
|
98
|
+
remove_method :table_alias_length
|
|
99
|
+
alias_method :table_alias_length, :old_table_alias_length
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# test resetting sequences in odd tables in postgreSQL
|
|
104
|
+
if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
|
|
105
|
+
require 'models/movie'
|
|
106
|
+
require 'models/subscriber'
|
|
107
|
+
|
|
108
|
+
def test_reset_empty_table_with_custom_pk
|
|
109
|
+
Movie.delete_all
|
|
110
|
+
Movie.connection.reset_pk_sequence! 'movies'
|
|
111
|
+
assert_equal 1, Movie.create(:name => 'fight club').id
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
if ActiveRecord::Base.connection.adapter_name != "FrontBase"
|
|
115
|
+
def test_reset_table_with_non_integer_pk
|
|
116
|
+
Subscriber.delete_all
|
|
117
|
+
Subscriber.connection.reset_pk_sequence! 'subscribers'
|
|
118
|
+
sub = Subscriber.new(:name => 'robert drake')
|
|
119
|
+
sub.id = 'bob drake'
|
|
120
|
+
assert_nothing_raised { sub.save! }
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
|
|
126
|
+
sql_inject = "1 select * from schema"
|
|
127
|
+
assert_equal " LIMIT 1", @connection.add_limit_offset!("", :limit=>sql_inject)
|
|
128
|
+
if current_adapter?(:MysqlAdapter)
|
|
129
|
+
assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
|
|
130
|
+
else
|
|
131
|
+
assert_equal " LIMIT 1 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
|
|
136
|
+
sql_inject = "1, 7 procedure help()"
|
|
137
|
+
if current_adapter?(:MysqlAdapter)
|
|
138
|
+
assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
|
|
139
|
+
assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=> '1 ; DROP TABLE USERS', :offset=>7)
|
|
140
|
+
else
|
|
141
|
+
assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
|
|
142
|
+
assert_equal " LIMIT 1,7 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
require "cases/helper"
|
|
2
|
+
require 'models/customer'
|
|
3
|
+
|
|
4
|
+
class AggregationsTest < ActiveRecord::TestCase
|
|
5
|
+
fixtures :customers
|
|
6
|
+
|
|
7
|
+
def test_find_single_value_object
|
|
8
|
+
assert_equal 50, customers(:david).balance.amount
|
|
9
|
+
assert_kind_of Money, customers(:david).balance
|
|
10
|
+
assert_equal 300, customers(:david).balance.exchange_to("DKK").amount
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_find_multiple_value_object
|
|
14
|
+
assert_equal customers(:david).address_street, customers(:david).address.street
|
|
15
|
+
assert(
|
|
16
|
+
customers(:david).address.close_to?(Address.new("Different Street", customers(:david).address_city, customers(:david).address_country))
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_change_single_value_object
|
|
21
|
+
customers(:david).balance = Money.new(100)
|
|
22
|
+
customers(:david).save
|
|
23
|
+
assert_equal 100, customers(:david).reload.balance.amount
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_immutable_value_objects
|
|
27
|
+
customers(:david).balance = Money.new(100)
|
|
28
|
+
assert_raise(ActiveSupport::FrozenObjectError) { customers(:david).balance.instance_eval { @amount = 20 } }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_inferred_mapping
|
|
32
|
+
assert_equal "35.544623640962634", customers(:david).gps_location.latitude
|
|
33
|
+
assert_equal "-105.9309951055148", customers(:david).gps_location.longitude
|
|
34
|
+
|
|
35
|
+
customers(:david).gps_location = GpsLocation.new("39x-110")
|
|
36
|
+
|
|
37
|
+
assert_equal "39", customers(:david).gps_location.latitude
|
|
38
|
+
assert_equal "-110", customers(:david).gps_location.longitude
|
|
39
|
+
|
|
40
|
+
customers(:david).save
|
|
41
|
+
|
|
42
|
+
customers(:david).reload
|
|
43
|
+
|
|
44
|
+
assert_equal "39", customers(:david).gps_location.latitude
|
|
45
|
+
assert_equal "-110", customers(:david).gps_location.longitude
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_reloaded_instance_refreshes_aggregations
|
|
49
|
+
assert_equal "35.544623640962634", customers(:david).gps_location.latitude
|
|
50
|
+
assert_equal "-105.9309951055148", customers(:david).gps_location.longitude
|
|
51
|
+
|
|
52
|
+
Customer.update_all("gps_location = '24x113'")
|
|
53
|
+
customers(:david).reload
|
|
54
|
+
assert_equal '24x113', customers(:david)['gps_location']
|
|
55
|
+
|
|
56
|
+
assert_equal GpsLocation.new('24x113'), customers(:david).gps_location
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_gps_equality
|
|
60
|
+
assert GpsLocation.new('39x110') == GpsLocation.new('39x110')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_gps_inequality
|
|
64
|
+
assert GpsLocation.new('39x110') != GpsLocation.new('39x111')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_allow_nil_gps_is_nil
|
|
68
|
+
assert_equal nil, customers(:zaphod).gps_location
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_allow_nil_gps_set_to_nil
|
|
72
|
+
customers(:david).gps_location = nil
|
|
73
|
+
customers(:david).save
|
|
74
|
+
customers(:david).reload
|
|
75
|
+
assert_equal nil, customers(:david).gps_location
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_allow_nil_set_address_attributes_to_nil
|
|
79
|
+
customers(:zaphod).address = nil
|
|
80
|
+
assert_equal nil, customers(:zaphod).attributes[:address_street]
|
|
81
|
+
assert_equal nil, customers(:zaphod).attributes[:address_city]
|
|
82
|
+
assert_equal nil, customers(:zaphod).attributes[:address_country]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_allow_nil_address_set_to_nil
|
|
86
|
+
customers(:zaphod).address = nil
|
|
87
|
+
customers(:zaphod).save
|
|
88
|
+
customers(:zaphod).reload
|
|
89
|
+
assert_equal nil, customers(:zaphod).address
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_nil_raises_error_when_allow_nil_is_false
|
|
93
|
+
assert_raise(NoMethodError) { customers(:david).balance = nil }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_allow_nil_address_loaded_when_only_some_attributes_are_nil
|
|
97
|
+
customers(:zaphod).address_street = nil
|
|
98
|
+
customers(:zaphod).save
|
|
99
|
+
customers(:zaphod).reload
|
|
100
|
+
assert_kind_of Address, customers(:zaphod).address
|
|
101
|
+
assert customers(:zaphod).address.street.nil?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_nil_assignment_results_in_nil
|
|
105
|
+
customers(:david).gps_location = GpsLocation.new('39x111')
|
|
106
|
+
assert_not_equal nil, customers(:david).gps_location
|
|
107
|
+
customers(:david).gps_location = nil
|
|
108
|
+
assert_equal nil, customers(:david).gps_location
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_custom_constructor
|
|
112
|
+
assert_equal 'Barney GUMBLE', customers(:barney).fullname.to_s
|
|
113
|
+
assert_kind_of Fullname, customers(:barney).fullname
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_custom_converter
|
|
117
|
+
customers(:barney).fullname = 'Barnoit Gumbleau'
|
|
118
|
+
assert_equal 'Barnoit GUMBLEAU', customers(:barney).fullname.to_s
|
|
119
|
+
assert_kind_of Fullname, customers(:barney).fullname
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class DeprecatedAggregationsTest < ActiveRecord::TestCase
|
|
124
|
+
class Person < ActiveRecord::Base; end
|
|
125
|
+
|
|
126
|
+
def test_conversion_block_is_deprecated
|
|
127
|
+
assert_deprecated 'conversion block has been deprecated' do
|
|
128
|
+
Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_conversion_block_used_when_converter_option_is_nil
|
|
133
|
+
assert_deprecated 'conversion block has been deprecated' do
|
|
134
|
+
Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
|
|
135
|
+
end
|
|
136
|
+
assert_raise(NoMethodError) { Person.new.balance = 5 }
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_converter_option_overrides_conversion_block
|
|
140
|
+
assert_deprecated 'conversion block has been deprecated' do
|
|
141
|
+
Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| Money.new(balance) }) { |balance| balance.to_money }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
person = Person.new
|
|
145
|
+
assert_nothing_raised { person.balance = 5 }
|
|
146
|
+
assert_equal 5, person.balance.amount
|
|
147
|
+
assert_kind_of Money, person.balance
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class OverridingAggregationsTest < ActiveRecord::TestCase
|
|
152
|
+
class Name; end
|
|
153
|
+
class DifferentName; end
|
|
154
|
+
|
|
155
|
+
class Person < ActiveRecord::Base
|
|
156
|
+
composed_of :composed_of, :mapping => %w(person_first_name first_name)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
class DifferentPerson < Person
|
|
160
|
+
composed_of :composed_of, :class_name => 'DifferentName', :mapping => %w(different_person_first_name first_name)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_composed_of_aggregation_redefinition_reflections_should_differ_and_not_inherited
|
|
164
|
+
assert_not_equal Person.reflect_on_aggregation(:composed_of),
|
|
165
|
+
DifferentPerson.reflect_on_aggregation(:composed_of)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "cases/helper"
|
|
2
|
+
|
|
3
|
+
if ActiveRecord::Base.connection.supports_migrations?
|
|
4
|
+
|
|
5
|
+
class ActiveRecordSchemaTest < ActiveRecord::TestCase
|
|
6
|
+
self.use_transactional_fixtures = false
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@connection = ActiveRecord::Base.connection
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def teardown
|
|
13
|
+
@connection.drop_table :fruits rescue nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_schema_define
|
|
17
|
+
ActiveRecord::Schema.define(:version => 7) do
|
|
18
|
+
create_table :fruits do |t|
|
|
19
|
+
t.column :color, :string
|
|
20
|
+
t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
|
|
21
|
+
t.column :texture, :string
|
|
22
|
+
t.column :flavor, :string
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
|
|
27
|
+
assert_nothing_raised { @connection.select_all "SELECT * FROM schema_migrations" }
|
|
28
|
+
assert_equal 7, ActiveRecord::Migrator::current_version
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|