activerecord_authorails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3043 -0
- data/README +360 -0
- data/RUNNING_UNIT_TESTS +64 -0
- data/Rakefile +226 -0
- data/examples/associations.png +0 -0
- data/examples/associations.rb +87 -0
- data/examples/shared_setup.rb +15 -0
- data/examples/validation.rb +85 -0
- data/install.rb +30 -0
- data/lib/active_record.rb +85 -0
- data/lib/active_record/acts/list.rb +244 -0
- data/lib/active_record/acts/nested_set.rb +211 -0
- data/lib/active_record/acts/tree.rb +89 -0
- data/lib/active_record/aggregations.rb +191 -0
- data/lib/active_record/associations.rb +1637 -0
- data/lib/active_record/associations/association_collection.rb +190 -0
- data/lib/active_record/associations/association_proxy.rb +158 -0
- data/lib/active_record/associations/belongs_to_association.rb +56 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +50 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +169 -0
- data/lib/active_record/associations/has_many_association.rb +210 -0
- data/lib/active_record/associations/has_many_through_association.rb +247 -0
- data/lib/active_record/associations/has_one_association.rb +80 -0
- data/lib/active_record/attribute_methods.rb +75 -0
- data/lib/active_record/base.rb +2164 -0
- data/lib/active_record/calculations.rb +270 -0
- data/lib/active_record/callbacks.rb +367 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +279 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +130 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +58 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +343 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +310 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +161 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +228 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +728 -0
- data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +414 -0
- data/lib/active_record/connection_adapters/openbase_adapter.rb +350 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +689 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +584 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +407 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +591 -0
- data/lib/active_record/connection_adapters/sybase_adapter.rb +662 -0
- data/lib/active_record/deprecated_associations.rb +104 -0
- data/lib/active_record/deprecated_finders.rb +44 -0
- data/lib/active_record/fixtures.rb +628 -0
- data/lib/active_record/locking/optimistic.rb +106 -0
- data/lib/active_record/locking/pessimistic.rb +77 -0
- data/lib/active_record/migration.rb +394 -0
- data/lib/active_record/observer.rb +178 -0
- data/lib/active_record/query_cache.rb +64 -0
- data/lib/active_record/reflection.rb +222 -0
- data/lib/active_record/schema.rb +58 -0
- data/lib/active_record/schema_dumper.rb +149 -0
- data/lib/active_record/timestamp.rb +51 -0
- data/lib/active_record/transactions.rb +136 -0
- data/lib/active_record/validations.rb +843 -0
- data/lib/active_record/vendor/db2.rb +362 -0
- data/lib/active_record/vendor/mysql.rb +1214 -0
- data/lib/active_record/vendor/simple.rb +693 -0
- data/lib/active_record/version.rb +9 -0
- data/lib/active_record/wrappers/yaml_wrapper.rb +15 -0
- data/lib/active_record/wrappings.rb +58 -0
- data/lib/active_record/xml_serialization.rb +308 -0
- data/test/aaa_create_tables_test.rb +59 -0
- data/test/abstract_unit.rb +77 -0
- data/test/active_schema_test_mysql.rb +31 -0
- data/test/adapter_test.rb +87 -0
- data/test/adapter_test_sqlserver.rb +81 -0
- data/test/aggregations_test.rb +95 -0
- data/test/all.sh +8 -0
- data/test/ar_schema_test.rb +33 -0
- data/test/association_inheritance_reload.rb +14 -0
- data/test/associations/callbacks_test.rb +126 -0
- data/test/associations/cascaded_eager_loading_test.rb +138 -0
- data/test/associations/eager_test.rb +393 -0
- data/test/associations/extension_test.rb +42 -0
- data/test/associations/join_model_test.rb +497 -0
- data/test/associations_test.rb +1809 -0
- data/test/attribute_methods_test.rb +49 -0
- data/test/base_test.rb +1586 -0
- data/test/binary_test.rb +37 -0
- data/test/calculations_test.rb +219 -0
- data/test/callbacks_test.rb +377 -0
- data/test/class_inheritable_attributes_test.rb +32 -0
- data/test/column_alias_test.rb +17 -0
- data/test/connection_test_firebird.rb +8 -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 +24 -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 +23 -0
- data/test/connections/native_sqlite/connection.rb +34 -0
- data/test/connections/native_sqlite3/connection.rb +34 -0
- data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
- data/test/connections/native_sqlserver/connection.rb +23 -0
- data/test/connections/native_sqlserver_odbc/connection.rb +25 -0
- data/test/connections/native_sybase/connection.rb +23 -0
- data/test/copy_table_sqlite.rb +64 -0
- data/test/datatype_test_postgresql.rb +52 -0
- data/test/default_test_firebird.rb +16 -0
- data/test/defaults_test.rb +60 -0
- data/test/deprecated_associations_test.rb +396 -0
- data/test/deprecated_finder_test.rb +151 -0
- data/test/empty_date_time_test.rb +25 -0
- data/test/finder_test.rb +504 -0
- data/test/fixtures/accounts.yml +28 -0
- data/test/fixtures/author.rb +99 -0
- data/test/fixtures/author_favorites.yml +4 -0
- data/test/fixtures/authors.yml +7 -0
- data/test/fixtures/auto_id.rb +4 -0
- data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +1 -0
- data/test/fixtures/bad_fixtures/attr_with_spaces +1 -0
- data/test/fixtures/bad_fixtures/blank_line +3 -0
- data/test/fixtures/bad_fixtures/duplicate_attributes +3 -0
- data/test/fixtures/bad_fixtures/missing_value +1 -0
- data/test/fixtures/binary.rb +2 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/categories/special_categories.yml +9 -0
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/test/fixtures/categories_ordered.yml +7 -0
- data/test/fixtures/categories_posts.yml +23 -0
- data/test/fixtures/categorization.rb +5 -0
- data/test/fixtures/categorizations.yml +17 -0
- data/test/fixtures/category.rb +20 -0
- data/test/fixtures/column_name.rb +3 -0
- data/test/fixtures/comment.rb +23 -0
- data/test/fixtures/comments.yml +59 -0
- data/test/fixtures/companies.yml +55 -0
- data/test/fixtures/company.rb +107 -0
- data/test/fixtures/company_in_module.rb +59 -0
- data/test/fixtures/computer.rb +3 -0
- data/test/fixtures/computers.yml +4 -0
- data/test/fixtures/course.rb +3 -0
- data/test/fixtures/courses.yml +7 -0
- data/test/fixtures/customer.rb +55 -0
- data/test/fixtures/customers.yml +17 -0
- data/test/fixtures/db_definitions/db2.drop.sql +32 -0
- data/test/fixtures/db_definitions/db2.sql +231 -0
- data/test/fixtures/db_definitions/db22.drop.sql +2 -0
- data/test/fixtures/db_definitions/db22.sql +5 -0
- data/test/fixtures/db_definitions/firebird.drop.sql +63 -0
- data/test/fixtures/db_definitions/firebird.sql +304 -0
- data/test/fixtures/db_definitions/firebird2.drop.sql +2 -0
- data/test/fixtures/db_definitions/firebird2.sql +6 -0
- data/test/fixtures/db_definitions/frontbase.drop.sql +32 -0
- data/test/fixtures/db_definitions/frontbase.sql +268 -0
- data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
- data/test/fixtures/db_definitions/frontbase2.sql +4 -0
- data/test/fixtures/db_definitions/mysql.drop.sql +32 -0
- data/test/fixtures/db_definitions/mysql.sql +234 -0
- data/test/fixtures/db_definitions/mysql2.drop.sql +2 -0
- data/test/fixtures/db_definitions/mysql2.sql +5 -0
- data/test/fixtures/db_definitions/openbase.drop.sql +2 -0
- data/test/fixtures/db_definitions/openbase.sql +302 -0
- data/test/fixtures/db_definitions/openbase2.drop.sql +2 -0
- data/test/fixtures/db_definitions/openbase2.sql +7 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +65 -0
- data/test/fixtures/db_definitions/oracle.sql +325 -0
- data/test/fixtures/db_definitions/oracle2.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle2.sql +6 -0
- data/test/fixtures/db_definitions/postgresql.drop.sql +37 -0
- data/test/fixtures/db_definitions/postgresql.sql +263 -0
- data/test/fixtures/db_definitions/postgresql2.drop.sql +2 -0
- data/test/fixtures/db_definitions/postgresql2.sql +5 -0
- data/test/fixtures/db_definitions/schema.rb +60 -0
- data/test/fixtures/db_definitions/sqlite.drop.sql +32 -0
- data/test/fixtures/db_definitions/sqlite.sql +215 -0
- data/test/fixtures/db_definitions/sqlite2.drop.sql +2 -0
- data/test/fixtures/db_definitions/sqlite2.sql +5 -0
- data/test/fixtures/db_definitions/sqlserver.drop.sql +34 -0
- data/test/fixtures/db_definitions/sqlserver.sql +243 -0
- data/test/fixtures/db_definitions/sqlserver2.drop.sql +2 -0
- data/test/fixtures/db_definitions/sqlserver2.sql +5 -0
- data/test/fixtures/db_definitions/sybase.drop.sql +34 -0
- data/test/fixtures/db_definitions/sybase.sql +218 -0
- data/test/fixtures/db_definitions/sybase2.drop.sql +4 -0
- data/test/fixtures/db_definitions/sybase2.sql +5 -0
- data/test/fixtures/default.rb +2 -0
- data/test/fixtures/developer.rb +52 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +17 -0
- data/test/fixtures/developers_projects/david_action_controller +3 -0
- data/test/fixtures/developers_projects/david_active_record +3 -0
- data/test/fixtures/developers_projects/jamis_active_record +2 -0
- data/test/fixtures/edge.rb +5 -0
- data/test/fixtures/edges.yml +6 -0
- data/test/fixtures/entrant.rb +3 -0
- data/test/fixtures/entrants.yml +14 -0
- data/test/fixtures/fk_test_has_fk.yml +3 -0
- data/test/fixtures/fk_test_has_pk.yml +2 -0
- data/test/fixtures/flowers.jpg +0 -0
- data/test/fixtures/funny_jokes.yml +10 -0
- data/test/fixtures/joke.rb +6 -0
- data/test/fixtures/keyboard.rb +3 -0
- data/test/fixtures/legacy_thing.rb +3 -0
- data/test/fixtures/legacy_things.yml +3 -0
- data/test/fixtures/migrations/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations/2_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
- data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
- data/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_duplicate/2_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_duplicate/3_foo.rb +7 -0
- data/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
- data/test/fixtures/mixed_case_monkey.rb +3 -0
- data/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/test/fixtures/mixin.rb +63 -0
- data/test/fixtures/mixins.yml +127 -0
- data/test/fixtures/movie.rb +5 -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/order.rb +4 -0
- data/test/fixtures/people.yml +3 -0
- data/test/fixtures/person.rb +4 -0
- data/test/fixtures/post.rb +58 -0
- data/test/fixtures/posts.yml +48 -0
- data/test/fixtures/project.rb +27 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/reader.rb +4 -0
- data/test/fixtures/readers.yml +4 -0
- data/test/fixtures/reply.rb +37 -0
- data/test/fixtures/subject.rb +4 -0
- data/test/fixtures/subscriber.rb +6 -0
- data/test/fixtures/subscribers/first +2 -0
- data/test/fixtures/subscribers/second +2 -0
- data/test/fixtures/tag.rb +7 -0
- data/test/fixtures/tagging.rb +6 -0
- data/test/fixtures/taggings.yml +18 -0
- data/test/fixtures/tags.yml +7 -0
- data/test/fixtures/task.rb +3 -0
- data/test/fixtures/tasks.yml +7 -0
- data/test/fixtures/topic.rb +25 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/fixtures/vertex.rb +9 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures_test.rb +401 -0
- data/test/inheritance_test.rb +205 -0
- data/test/lifecycle_test.rb +137 -0
- data/test/locking_test.rb +190 -0
- data/test/method_scoping_test.rb +416 -0
- data/test/migration_test.rb +768 -0
- data/test/migration_test_firebird.rb +124 -0
- data/test/mixin_nested_set_test.rb +196 -0
- data/test/mixin_test.rb +550 -0
- data/test/modules_test.rb +34 -0
- data/test/multiple_db_test.rb +60 -0
- data/test/pk_test.rb +104 -0
- data/test/readonly_test.rb +107 -0
- data/test/reflection_test.rb +159 -0
- data/test/schema_authorization_test_postgresql.rb +75 -0
- data/test/schema_dumper_test.rb +96 -0
- data/test/schema_test_postgresql.rb +64 -0
- data/test/synonym_test_oracle.rb +17 -0
- data/test/table_name_test_sqlserver.rb +23 -0
- data/test/threaded_connections_test.rb +48 -0
- data/test/transactions_test.rb +230 -0
- data/test/unconnected_test.rb +32 -0
- data/test/validations_test.rb +1097 -0
- data/test/xml_serialization_test.rb +125 -0
- metadata +365 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'abstract_unit'
|
3
|
+
require 'active_support/core_ext/class/inheritable_attributes'
|
4
|
+
|
5
|
+
class A
|
6
|
+
include ClassInheritableAttributes
|
7
|
+
end
|
8
|
+
|
9
|
+
class B < A
|
10
|
+
write_inheritable_array "first", [ :one, :two ]
|
11
|
+
end
|
12
|
+
|
13
|
+
class C < A
|
14
|
+
write_inheritable_array "first", [ :three ]
|
15
|
+
end
|
16
|
+
|
17
|
+
class D < B
|
18
|
+
write_inheritable_array "first", [ :four ]
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class ClassInheritableAttributesTest < Test::Unit::TestCase
|
23
|
+
def test_first_level
|
24
|
+
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
|
25
|
+
assert_equal [ :three ], C.read_inheritable_attribute("first")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_second_level
|
29
|
+
assert_equal [ :one, :two, :four ], D.read_inheritable_attribute("first")
|
30
|
+
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/topic'
|
3
|
+
|
4
|
+
class TestColumnAlias < Test::Unit::TestCase
|
5
|
+
fixtures :topics
|
6
|
+
|
7
|
+
QUERY = if 'Oracle' == ActiveRecord::Base.connection.adapter_name
|
8
|
+
'SELECT id AS pk FROM topics WHERE ROWNUM < 2'
|
9
|
+
else
|
10
|
+
'SELECT id AS pk FROM topics'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_column_alias
|
14
|
+
records = Topic.connection.select_all(QUERY)
|
15
|
+
assert_equal 'pk', records[0].keys[0]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
print "Using native DB2\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'db2',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'arunit',
|
12
|
+
:password => 'arunit',
|
13
|
+
:database => 'arunit'
|
14
|
+
},
|
15
|
+
'arunit2' => {
|
16
|
+
:adapter => 'db2',
|
17
|
+
:host => 'localhost',
|
18
|
+
:username => 'arunit',
|
19
|
+
:password => 'arunit',
|
20
|
+
:database => 'arunit2'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
25
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
print "Using native Firebird\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'firebird',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'rails',
|
12
|
+
:password => 'rails',
|
13
|
+
:database => 'activerecord_unittest',
|
14
|
+
:charset => 'UTF8'
|
15
|
+
},
|
16
|
+
'arunit2' => {
|
17
|
+
:adapter => 'firebird',
|
18
|
+
:host => 'localhost',
|
19
|
+
:username => 'rails',
|
20
|
+
:password => 'rails',
|
21
|
+
:database => 'activerecord_unittest2'
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
26
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
puts 'Using native Frontbase'
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'frontbase',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'rails',
|
12
|
+
:password => '',
|
13
|
+
:database => 'activerecord_unittest',
|
14
|
+
:session_name => "unittest-#{$$}"
|
15
|
+
},
|
16
|
+
'arunit2' => {
|
17
|
+
:adapter => 'frontbase',
|
18
|
+
:host => 'localhost',
|
19
|
+
:username => 'rails',
|
20
|
+
:password => '',
|
21
|
+
:database => 'activerecord_unittest2',
|
22
|
+
:session_name => "unittest-#{$$}"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
27
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
print "Using native MySQL\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
|
6
|
+
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
|
7
|
+
ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
|
8
|
+
|
9
|
+
ActiveRecord::Base.configurations = {
|
10
|
+
'arunit' => {
|
11
|
+
:adapter => 'mysql',
|
12
|
+
:username => 'rails',
|
13
|
+
:encoding => 'utf8',
|
14
|
+
:database => 'activerecord_unittest',
|
15
|
+
},
|
16
|
+
'arunit2' => {
|
17
|
+
:adapter => 'mysql',
|
18
|
+
:username => 'rails',
|
19
|
+
:database => 'activerecord_unittest2'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
24
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
print "Using native OpenBase\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'openbase',
|
10
|
+
:username => 'admin',
|
11
|
+
:database => 'activerecord_unittest',
|
12
|
+
},
|
13
|
+
'arunit2' => {
|
14
|
+
:adapter => 'openbase',
|
15
|
+
:username => 'admin',
|
16
|
+
:database => 'activerecord_unittest2'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
21
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
print "Using Oracle\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new STDOUT
|
6
|
+
ActiveRecord::Base.logger.level = Logger::WARN
|
7
|
+
|
8
|
+
# Set these to your database connection strings
|
9
|
+
db = ENV['ARUNIT_DB'] || 'activerecord_unittest'
|
10
|
+
|
11
|
+
ActiveRecord::Base.configurations = {
|
12
|
+
'arunit' => {
|
13
|
+
:adapter => 'oracle',
|
14
|
+
:username => 'arunit',
|
15
|
+
:password => 'arunit',
|
16
|
+
:database => db,
|
17
|
+
},
|
18
|
+
'arunit2' => {
|
19
|
+
:adapter => 'oracle',
|
20
|
+
:username => 'arunit2',
|
21
|
+
:password => 'arunit2',
|
22
|
+
:database => db
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
27
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
print "Using native PostgreSQL\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'postgresql',
|
10
|
+
:username => 'postgres',
|
11
|
+
:database => 'activerecord_unittest',
|
12
|
+
:min_messages => 'warning'
|
13
|
+
},
|
14
|
+
'arunit2' => {
|
15
|
+
:adapter => 'postgresql',
|
16
|
+
:username => 'postgres',
|
17
|
+
:database => 'activerecord_unittest2',
|
18
|
+
:min_messages => 'warning'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
23
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
print "Using native SQlite\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
5
|
+
|
6
|
+
class SqliteError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
|
10
|
+
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
|
11
|
+
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
|
12
|
+
|
13
|
+
def make_connection(clazz, db_file, db_definitions_file)
|
14
|
+
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite', :database => db_file } }
|
15
|
+
unless File.exist?(db_file)
|
16
|
+
puts "SQLite database not found at #{db_file}. Rebuilding it."
|
17
|
+
sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"}
|
18
|
+
puts "Executing '#{sqlite_command}'"
|
19
|
+
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
|
20
|
+
clazz.establish_connection(clazz.name)
|
21
|
+
script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
|
22
|
+
# SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
|
23
|
+
script.split(';').each do
|
24
|
+
|command|
|
25
|
+
clazz.connection.execute(command) unless command.strip.empty?
|
26
|
+
end
|
27
|
+
else
|
28
|
+
clazz.establish_connection(clazz.name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
make_connection(ActiveRecord::Base, sqlite_test_db, 'sqlite.sql')
|
33
|
+
make_connection(Course, sqlite_test_db2, 'sqlite2.sql')
|
34
|
+
load(File.join(BASE_DIR, 'db_definitions', 'schema.rb'))
|
@@ -0,0 +1,34 @@
|
|
1
|
+
print "Using native SQLite3\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
5
|
+
|
6
|
+
class SqliteError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
|
10
|
+
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
|
11
|
+
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
|
12
|
+
|
13
|
+
def make_connection(clazz, db_file, db_definitions_file)
|
14
|
+
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => db_file, :timeout => 5000 } }
|
15
|
+
unless File.exist?(db_file)
|
16
|
+
puts "SQLite3 database not found at #{db_file}. Rebuilding it."
|
17
|
+
sqlite_command = %Q{sqlite3 #{db_file} "create table a (a integer); drop table a;"}
|
18
|
+
puts "Executing '#{sqlite_command}'"
|
19
|
+
raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
|
20
|
+
clazz.establish_connection(clazz.name)
|
21
|
+
script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
|
22
|
+
# SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
|
23
|
+
script.split(';').each do
|
24
|
+
|command|
|
25
|
+
clazz.connection.execute(command) unless command.strip.empty?
|
26
|
+
end
|
27
|
+
else
|
28
|
+
clazz.establish_connection(clazz.name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
make_connection(ActiveRecord::Base, sqlite_test_db, 'sqlite.sql')
|
33
|
+
make_connection(Course, sqlite_test_db2, 'sqlite2.sql')
|
34
|
+
load(File.join(BASE_DIR, 'db_definitions', 'schema.rb'))
|
@@ -0,0 +1,18 @@
|
|
1
|
+
print "Using native SQLite3\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
5
|
+
|
6
|
+
class SqliteError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
def make_connection(clazz, db_definitions_file)
|
10
|
+
clazz.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
11
|
+
File.read("#{File.dirname(__FILE__)}/../../fixtures/db_definitions/#{db_definitions_file}").split(';').each do |command|
|
12
|
+
clazz.connection.execute(command) unless command.strip.empty?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
make_connection(ActiveRecord::Base, 'sqlite.sql')
|
17
|
+
make_connection(Course, 'sqlite2.sql')
|
18
|
+
load("#{File.dirname(__FILE__)}/../../fixtures/db_definitions/schema.rb"))
|
@@ -0,0 +1,23 @@
|
|
1
|
+
print "Using native SQLServer\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'sqlserver',
|
10
|
+
:host => 'localhost',
|
11
|
+
:username => 'sa',
|
12
|
+
:database => 'activerecord_unittest'
|
13
|
+
},
|
14
|
+
'arunit2' => {
|
15
|
+
:adapter => 'sqlserver',
|
16
|
+
:host => 'localhost',
|
17
|
+
:username => 'sa',
|
18
|
+
:database => 'activerecord_unittest2'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
23
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
print "Using native SQLServer via ODBC\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'sqlserver',
|
10
|
+
:mode => 'ODBC',
|
11
|
+
:host => 'localhost',
|
12
|
+
:username => 'sa',
|
13
|
+
:dsn => 'activerecord_unittest'
|
14
|
+
},
|
15
|
+
'arunit2' => {
|
16
|
+
:adapter => 'sqlserver',
|
17
|
+
:mode => 'ODBC',
|
18
|
+
:host => 'localhost',
|
19
|
+
:username => 'sa',
|
20
|
+
:dsn => 'activerecord_unittest2'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
25
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
print "Using native Sybase Open Client\n"
|
2
|
+
require_dependency 'fixtures/course'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = {
|
8
|
+
'arunit' => {
|
9
|
+
:adapter => 'sybase',
|
10
|
+
:host => 'database_ASE',
|
11
|
+
:username => 'sa',
|
12
|
+
:database => 'activerecord_unittest'
|
13
|
+
},
|
14
|
+
'arunit2' => {
|
15
|
+
:adapter => 'sybase',
|
16
|
+
:host => 'database_ASE',
|
17
|
+
:username => 'sa',
|
18
|
+
:database => 'activerecord_unittest2'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
23
|
+
Course.establish_connection 'arunit2'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class CopyTableTest < Test::Unit::TestCase
|
4
|
+
fixtures :companies, :comments
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = ActiveRecord::Base.connection
|
8
|
+
class << @connection
|
9
|
+
public :copy_table, :table_structure, :indexes
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_copy_table(from = 'companies', to = 'companies2', options = {})
|
14
|
+
assert_nothing_raised {copy_table(from, to, options)}
|
15
|
+
assert_equal row_count(from), row_count(to)
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
yield from, to, options
|
19
|
+
else
|
20
|
+
assert_equal column_names(from), column_names(to)
|
21
|
+
end
|
22
|
+
|
23
|
+
@connection.drop_table(to) rescue nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_copy_table_renaming_column
|
27
|
+
test_copy_table('companies', 'companies2',
|
28
|
+
:rename => {'client_of' => 'fan_of'}) do |from, to, options|
|
29
|
+
assert_equal column_values(from, 'client_of').compact.sort,
|
30
|
+
column_values(to, 'fan_of').compact.sort
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_copy_table_with_index
|
35
|
+
test_copy_table('comments', 'comments_with_index') do
|
36
|
+
@connection.add_index('comments_with_index', ['post_id', 'type'])
|
37
|
+
test_copy_table('comments_with_index', 'comments_with_index2') do
|
38
|
+
assert_equal table_indexes_without_name('comments_with_index'),
|
39
|
+
table_indexes_without_name('comments_with_index2')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
def copy_table(from, to, options = {})
|
46
|
+
@connection.copy_table(from, to, {:temporary => true}.merge(options))
|
47
|
+
end
|
48
|
+
|
49
|
+
def column_names(table)
|
50
|
+
@connection.table_structure(table).map {|column| column['name']}
|
51
|
+
end
|
52
|
+
|
53
|
+
def column_values(table, column)
|
54
|
+
@connection.select_all("SELECT #{column} FROM #{table}").map {|row| row[column]}
|
55
|
+
end
|
56
|
+
|
57
|
+
def table_indexes_without_name(table)
|
58
|
+
@connection.indexes('comments_with_index').delete(:name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def row_count(table)
|
62
|
+
@connection.select_one("SELECT COUNT(*) AS count FROM #{table}")['count']
|
63
|
+
end
|
64
|
+
end
|