activerecord_authorails 1.0.0
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 +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,77 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require 'active_record'
|
|
6
|
+
require 'active_record/fixtures'
|
|
7
|
+
require 'active_support/binding_of_caller'
|
|
8
|
+
require 'active_support/breakpoint'
|
|
9
|
+
require 'connection'
|
|
10
|
+
|
|
11
|
+
# Show backtraces for deprecated behavior for quicker cleanup.
|
|
12
|
+
ActiveSupport::Deprecation.debug = true
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
|
|
16
|
+
|
|
17
|
+
class Test::Unit::TestCase #:nodoc:
|
|
18
|
+
self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
|
19
|
+
self.use_instantiated_fixtures = false
|
|
20
|
+
self.use_transactional_fixtures = (ENV['AR_NO_TX_FIXTURES'] != "yes")
|
|
21
|
+
|
|
22
|
+
def create_fixtures(*table_names, &block)
|
|
23
|
+
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names, {}, &block)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def assert_date_from_db(expected, actual, message = nil)
|
|
27
|
+
# SQL Server doesn't have a separate column type just for dates,
|
|
28
|
+
# so the time is in the string and incorrectly formatted
|
|
29
|
+
if current_adapter?(:SQLServerAdapter)
|
|
30
|
+
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
|
|
31
|
+
elsif current_adapter?(:SybaseAdapter)
|
|
32
|
+
assert_equal expected.to_s, actual.to_date.to_s, message
|
|
33
|
+
else
|
|
34
|
+
assert_equal expected.to_s, actual.to_s, message
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def assert_queries(num = 1)
|
|
39
|
+
ActiveRecord::Base.connection.class.class_eval do
|
|
40
|
+
self.query_count = 0
|
|
41
|
+
alias_method :execute, :execute_with_query_counting
|
|
42
|
+
end
|
|
43
|
+
yield
|
|
44
|
+
ensure
|
|
45
|
+
ActiveRecord::Base.connection.class.class_eval do
|
|
46
|
+
alias_method :execute, :execute_without_query_counting
|
|
47
|
+
end
|
|
48
|
+
assert_equal num, ActiveRecord::Base.connection.query_count, "#{ActiveRecord::Base.connection.query_count} instead of #{num} queries were executed."
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def assert_no_queries(&block)
|
|
52
|
+
assert_queries(0, &block)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def current_adapter?(*types)
|
|
57
|
+
types.any? do |type|
|
|
58
|
+
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
|
59
|
+
ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
ActiveRecord::Base.connection.class.class_eval do
|
|
64
|
+
cattr_accessor :query_count
|
|
65
|
+
|
|
66
|
+
# Array of regexes of queries that are not counted against query_count
|
|
67
|
+
@@ignore_list = [/^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/]
|
|
68
|
+
|
|
69
|
+
alias_method :execute_without_query_counting, :execute
|
|
70
|
+
def execute_with_query_counting(sql, name = nil, &block)
|
|
71
|
+
self.query_count += 1 unless @@ignore_list.any? { |r| sql =~ r }
|
|
72
|
+
execute_without_query_counting(sql, name, &block)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
77
|
+
#ActiveRecord::Base.colorize_logging = false
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class ActiveSchemaTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
|
|
6
|
+
alias_method :real_execute, :execute
|
|
7
|
+
def execute(sql, name = nil) return sql end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def teardown
|
|
12
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:alias_method, :execute, :real_execute)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_drop_table
|
|
16
|
+
assert_equal "DROP TABLE people", drop_table(:people)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_add_column
|
|
20
|
+
assert_equal "ALTER TABLE people ADD `last_name` varchar(255)", add_column(:people, :last_name, :string)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_add_column_with_limit
|
|
24
|
+
assert_equal "ALTER TABLE people ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
def method_missing(method_symbol, *arguments)
|
|
29
|
+
ActiveRecord::Base.connection.send(method_symbol, *arguments)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class AdapterTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@connection = ActiveRecord::Base.connection
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_tables
|
|
9
|
+
if @connection.respond_to?(:tables)
|
|
10
|
+
tables = @connection.tables
|
|
11
|
+
assert tables.include?("accounts")
|
|
12
|
+
assert tables.include?("authors")
|
|
13
|
+
assert tables.include?("tasks")
|
|
14
|
+
assert tables.include?("topics")
|
|
15
|
+
else
|
|
16
|
+
warn "#{@connection.class} does not respond to #tables"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_indexes
|
|
21
|
+
idx_name = "accounts_idx"
|
|
22
|
+
|
|
23
|
+
if @connection.respond_to?(:indexes)
|
|
24
|
+
indexes = @connection.indexes("accounts")
|
|
25
|
+
assert indexes.empty?
|
|
26
|
+
|
|
27
|
+
@connection.add_index :accounts, :firm_id, :name => idx_name
|
|
28
|
+
indexes = @connection.indexes("accounts")
|
|
29
|
+
assert_equal "accounts", indexes.first.table
|
|
30
|
+
# OpenBase does not have the concept of a named index
|
|
31
|
+
# Indexes are merely properties of columns.
|
|
32
|
+
assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter)
|
|
33
|
+
assert !indexes.first.unique
|
|
34
|
+
assert_equal ["firm_id"], indexes.first.columns
|
|
35
|
+
else
|
|
36
|
+
warn "#{@connection.class} does not respond to #indexes"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
ensure
|
|
40
|
+
@connection.remove_index(:accounts, :name => idx_name) rescue nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_current_database
|
|
44
|
+
if @connection.respond_to?(:current_database)
|
|
45
|
+
assert_equal ENV['ARUNIT_DB_NAME'] || "activerecord_unittest", @connection.current_database
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_table_alias
|
|
50
|
+
def @connection.test_table_alias_length() 10; end
|
|
51
|
+
class << @connection
|
|
52
|
+
alias_method :old_table_alias_length, :table_alias_length
|
|
53
|
+
alias_method :table_alias_length, :test_table_alias_length
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
assert_equal 'posts', @connection.table_alias_for('posts')
|
|
57
|
+
assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
|
|
58
|
+
assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
|
|
59
|
+
|
|
60
|
+
class << @connection
|
|
61
|
+
alias_method :table_alias_length, :old_table_alias_length
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# test resetting sequences in odd tables in postgreSQL
|
|
66
|
+
if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
|
|
67
|
+
require 'fixtures/movie'
|
|
68
|
+
require 'fixtures/subscriber'
|
|
69
|
+
|
|
70
|
+
def test_reset_empty_table_with_custom_pk
|
|
71
|
+
Movie.delete_all
|
|
72
|
+
Movie.connection.reset_pk_sequence! 'movies'
|
|
73
|
+
assert_equal 1, Movie.create(:name => 'fight club').id
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
if ActiveRecord::Base.connection.adapter_name != "FrontBase"
|
|
77
|
+
def test_reset_table_with_non_integer_pk
|
|
78
|
+
Subscriber.delete_all
|
|
79
|
+
Subscriber.connection.reset_pk_sequence! 'subscribers'
|
|
80
|
+
sub = Subscriber.new(:name => 'robert drake')
|
|
81
|
+
sub.id = 'bob drake'
|
|
82
|
+
assert_nothing_raised { sub.save! }
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/default'
|
|
3
|
+
require 'fixtures/post'
|
|
4
|
+
require 'fixtures/task'
|
|
5
|
+
|
|
6
|
+
class SqlServerAdapterTest < Test::Unit::TestCase
|
|
7
|
+
fixtures :posts, :tasks
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@connection = ActiveRecord::Base.connection
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
@connection.execute("SET LANGUAGE us_english")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# SQL Server 2000 has a bug where some unambiguous date formats are not
|
|
18
|
+
# correctly identified if the session language is set to german
|
|
19
|
+
def test_date_insertion_when_language_is_german
|
|
20
|
+
@connection.execute("SET LANGUAGE deutsch")
|
|
21
|
+
|
|
22
|
+
assert_nothing_raised do
|
|
23
|
+
Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_execute_without_block_closes_statement
|
|
28
|
+
assert_all_statements_used_are_closed do
|
|
29
|
+
@connection.execute("SELECT 1")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_execute_with_block_closes_statement
|
|
34
|
+
assert_all_statements_used_are_closed do
|
|
35
|
+
@connection.execute("SELECT 1") do |sth|
|
|
36
|
+
assert !sth.finished?, "Statement should still be alive within block"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_insert_with_identity_closes_statement
|
|
42
|
+
assert_all_statements_used_are_closed do
|
|
43
|
+
@connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_insert_without_identity_closes_statement
|
|
48
|
+
assert_all_statements_used_are_closed do
|
|
49
|
+
@connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_active_closes_statement
|
|
54
|
+
assert_all_statements_used_are_closed do
|
|
55
|
+
@connection.active?
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def assert_all_statements_used_are_closed(&block)
|
|
60
|
+
existing_handles = []
|
|
61
|
+
ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
|
|
62
|
+
GC.disable
|
|
63
|
+
|
|
64
|
+
yield
|
|
65
|
+
|
|
66
|
+
used_handles = []
|
|
67
|
+
ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
|
|
68
|
+
|
|
69
|
+
assert_block "No statements were used within given block" do
|
|
70
|
+
used_handles.size > 0
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
ObjectSpace.each_object(DBI::StatementHandle) do |handle|
|
|
74
|
+
assert_block "Statement should have been closed within given block" do
|
|
75
|
+
handle.finished?
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
ensure
|
|
79
|
+
GC.enable
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/customer'
|
|
3
|
+
|
|
4
|
+
class AggregationsTest < Test::Unit::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, Customer.find(1).balance.amount
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_immutable_value_objects
|
|
27
|
+
customers(:david).balance = Money.new(100)
|
|
28
|
+
assert_raises(TypeError) { 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_raises(NoMethodError) { customers(:david).balance = nil }
|
|
94
|
+
end
|
|
95
|
+
end
|
data/test/all.sh
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require "#{File.dirname(__FILE__)}/../lib/active_record/schema"
|
|
3
|
+
|
|
4
|
+
if ActiveRecord::Base.connection.supports_migrations?
|
|
5
|
+
|
|
6
|
+
class ActiveRecordSchemaTest < Test::Unit::TestCase
|
|
7
|
+
self.use_transactional_fixtures = false
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@connection = ActiveRecord::Base.connection
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
@connection.drop_table :fruits rescue nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_schema_define
|
|
18
|
+
ActiveRecord::Schema.define(:version => 7) do
|
|
19
|
+
create_table :fruits do |t|
|
|
20
|
+
t.column :color, :string
|
|
21
|
+
t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
|
|
22
|
+
t.column :texture, :string
|
|
23
|
+
t.column :flavor, :string
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
|
|
28
|
+
assert_nothing_raised { @connection.select_all "SELECT * FROM schema_info" }
|
|
29
|
+
assert_equal 7, @connection.select_one("SELECT version FROM schema_info")['version'].to_i
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/company'
|
|
3
|
+
|
|
4
|
+
class AssociationInheritanceReloadTest < Test::Unit::TestCase
|
|
5
|
+
fixtures :companies
|
|
6
|
+
|
|
7
|
+
def test_set_attributes
|
|
8
|
+
assert_equal ["errors.add_on_empty('name', \"can't be empty\")"], Firm.read_inheritable_attribute("validate"), "Second run"
|
|
9
|
+
# ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
|
|
10
|
+
remove_subclass_of(ActiveRecord::Base)
|
|
11
|
+
load 'fixtures/company.rb'
|
|
12
|
+
assert_equal ["errors.add_on_empty('name', \"can't be empty\")"], Firm.read_inheritable_attribute("validate"), "Second run"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/post'
|
|
3
|
+
require 'fixtures/comment'
|
|
4
|
+
require 'fixtures/author'
|
|
5
|
+
require 'fixtures/category'
|
|
6
|
+
require 'fixtures/project'
|
|
7
|
+
require 'fixtures/developer'
|
|
8
|
+
|
|
9
|
+
class AssociationCallbacksTest < Test::Unit::TestCase
|
|
10
|
+
fixtures :posts, :authors, :projects, :developers
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@david = authors(:david)
|
|
14
|
+
@thinking = posts(:thinking)
|
|
15
|
+
@authorless = posts(:authorless)
|
|
16
|
+
assert @david.post_log.empty?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_adding_macro_callbacks
|
|
20
|
+
@david.posts_with_callbacks << @thinking
|
|
21
|
+
assert_equal ["before_adding#{@thinking.id}", "after_adding#{@thinking.id}"], @david.post_log
|
|
22
|
+
@david.posts_with_callbacks << @thinking
|
|
23
|
+
assert_equal ["before_adding#{@thinking.id}", "after_adding#{@thinking.id}", "before_adding#{@thinking.id}",
|
|
24
|
+
"after_adding#{@thinking.id}"], @david.post_log
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_adding_with_proc_callbacks
|
|
28
|
+
@david.posts_with_proc_callbacks << @thinking
|
|
29
|
+
assert_equal ["before_adding#{@thinking.id}", "after_adding#{@thinking.id}"], @david.post_log
|
|
30
|
+
@david.posts_with_proc_callbacks << @thinking
|
|
31
|
+
assert_equal ["before_adding#{@thinking.id}", "after_adding#{@thinking.id}", "before_adding#{@thinking.id}",
|
|
32
|
+
"after_adding#{@thinking.id}"], @david.post_log
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_removing_with_macro_callbacks
|
|
36
|
+
first_post, second_post = @david.posts_with_callbacks[0, 2]
|
|
37
|
+
@david.posts_with_callbacks.delete(first_post)
|
|
38
|
+
assert_equal ["before_removing#{first_post.id}", "after_removing#{first_post.id}"], @david.post_log
|
|
39
|
+
@david.posts_with_callbacks.delete(second_post)
|
|
40
|
+
assert_equal ["before_removing#{first_post.id}", "after_removing#{first_post.id}", "before_removing#{second_post.id}",
|
|
41
|
+
"after_removing#{second_post.id}"], @david.post_log
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_removing_with_proc_callbacks
|
|
45
|
+
first_post, second_post = @david.posts_with_callbacks[0, 2]
|
|
46
|
+
@david.posts_with_proc_callbacks.delete(first_post)
|
|
47
|
+
assert_equal ["before_removing#{first_post.id}", "after_removing#{first_post.id}"], @david.post_log
|
|
48
|
+
@david.posts_with_proc_callbacks.delete(second_post)
|
|
49
|
+
assert_equal ["before_removing#{first_post.id}", "after_removing#{first_post.id}", "before_removing#{second_post.id}",
|
|
50
|
+
"after_removing#{second_post.id}"], @david.post_log
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_multiple_callbacks
|
|
54
|
+
@david.posts_with_multiple_callbacks << @thinking
|
|
55
|
+
assert_equal ["before_adding#{@thinking.id}", "before_adding_proc#{@thinking.id}", "after_adding#{@thinking.id}",
|
|
56
|
+
"after_adding_proc#{@thinking.id}"], @david.post_log
|
|
57
|
+
@david.posts_with_multiple_callbacks << @thinking
|
|
58
|
+
assert_equal ["before_adding#{@thinking.id}", "before_adding_proc#{@thinking.id}", "after_adding#{@thinking.id}",
|
|
59
|
+
"after_adding_proc#{@thinking.id}", "before_adding#{@thinking.id}", "before_adding_proc#{@thinking.id}",
|
|
60
|
+
"after_adding#{@thinking.id}", "after_adding_proc#{@thinking.id}"], @david.post_log
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_has_and_belongs_to_many_add_callback
|
|
64
|
+
david = developers(:david)
|
|
65
|
+
ar = projects(:active_record)
|
|
66
|
+
assert ar.developers_log.empty?
|
|
67
|
+
ar.developers_with_callbacks << david
|
|
68
|
+
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}"], ar.developers_log
|
|
69
|
+
ar.developers_with_callbacks << david
|
|
70
|
+
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}", "before_adding#{david.id}",
|
|
71
|
+
"after_adding#{david.id}"], ar.developers_log
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_has_and_belongs_to_many_remove_callback
|
|
75
|
+
david = developers(:david)
|
|
76
|
+
jamis = developers(:jamis)
|
|
77
|
+
activerecord = projects(:active_record)
|
|
78
|
+
assert activerecord.developers_log.empty?
|
|
79
|
+
activerecord.developers_with_callbacks.delete(david)
|
|
80
|
+
assert_equal ["before_removing#{david.id}", "after_removing#{david.id}"], activerecord.developers_log
|
|
81
|
+
|
|
82
|
+
activerecord.developers_with_callbacks.delete(jamis)
|
|
83
|
+
assert_equal ["before_removing#{david.id}", "after_removing#{david.id}", "before_removing#{jamis.id}",
|
|
84
|
+
"after_removing#{jamis.id}"], activerecord.developers_log
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_has_and_belongs_to_many_remove_callback_on_clear
|
|
88
|
+
activerecord = projects(:active_record)
|
|
89
|
+
assert activerecord.developers_log.empty?
|
|
90
|
+
if activerecord.developers_with_callbacks.size == 0
|
|
91
|
+
activerecord.developers << developers(:david)
|
|
92
|
+
activerecord.developers << developers(:jamis)
|
|
93
|
+
activerecord.reload
|
|
94
|
+
assert activerecord.developers_with_callbacks.size == 2
|
|
95
|
+
end
|
|
96
|
+
log_array = activerecord.developers_with_callbacks.collect {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.flatten.sort
|
|
97
|
+
assert activerecord.developers_with_callbacks.clear
|
|
98
|
+
assert_equal log_array, activerecord.developers_log.sort
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_dont_add_if_before_callback_raises_exception
|
|
102
|
+
assert !@david.unchangable_posts.include?(@authorless)
|
|
103
|
+
begin
|
|
104
|
+
@david.unchangable_posts << @authorless
|
|
105
|
+
rescue Exception => e
|
|
106
|
+
end
|
|
107
|
+
assert @david.post_log.empty?
|
|
108
|
+
assert !@david.unchangable_posts.include?(@authorless)
|
|
109
|
+
@david.reload
|
|
110
|
+
assert !@david.unchangable_posts.include?(@authorless)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_push_with_attributes
|
|
114
|
+
assert_deprecated 'push_with_attributes' do
|
|
115
|
+
david = developers(:david)
|
|
116
|
+
activerecord = projects(:active_record)
|
|
117
|
+
assert activerecord.developers_log.empty?
|
|
118
|
+
activerecord.developers_with_callbacks.push_with_attributes(david, {})
|
|
119
|
+
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}"], activerecord.developers_log
|
|
120
|
+
activerecord.developers_with_callbacks.push_with_attributes(david, {})
|
|
121
|
+
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}", "before_adding#{david.id}",
|
|
122
|
+
"after_adding#{david.id}"], activerecord.developers_log
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|