activerecord 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (110) hide show
  1. data/CHANGELOG +32 -6
  2. data/README +0 -0
  3. data/Rakefile +4 -5
  4. data/lib/active_record.rb +11 -10
  5. data/lib/active_record/aggregations.rb +110 -38
  6. data/lib/active_record/association_preload.rb +104 -15
  7. data/lib/active_record/associations.rb +427 -212
  8. data/lib/active_record/associations/association_collection.rb +101 -16
  9. data/lib/active_record/associations/association_proxy.rb +65 -13
  10. data/lib/active_record/associations/belongs_to_association.rb +2 -2
  11. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -0
  12. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +13 -3
  13. data/lib/active_record/associations/has_many_association.rb +28 -28
  14. data/lib/active_record/associations/has_many_through_association.rb +21 -19
  15. data/lib/active_record/associations/has_one_association.rb +24 -7
  16. data/lib/active_record/associations/has_one_through_association.rb +3 -4
  17. data/lib/active_record/attribute_methods.rb +13 -5
  18. data/lib/active_record/base.rb +435 -212
  19. data/lib/active_record/calculations.rb +12 -5
  20. data/lib/active_record/callbacks.rb +28 -9
  21. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +355 -0
  22. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +42 -215
  23. data/lib/active_record/connection_adapters/abstract/database_statements.rb +30 -5
  24. data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -1
  25. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +48 -7
  26. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +10 -4
  27. data/lib/active_record/connection_adapters/abstract_adapter.rb +67 -26
  28. data/lib/active_record/connection_adapters/mysql_adapter.rb +71 -45
  29. data/lib/active_record/connection_adapters/postgresql_adapter.rb +155 -84
  30. data/lib/active_record/dirty.rb +25 -7
  31. data/lib/active_record/dynamic_finder_match.rb +41 -0
  32. data/lib/active_record/fixtures.rb +10 -9
  33. data/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
  34. data/lib/active_record/locale/en.yml +54 -0
  35. data/lib/active_record/migration.rb +47 -10
  36. data/lib/active_record/named_scope.rb +29 -16
  37. data/lib/active_record/reflection.rb +118 -54
  38. data/lib/active_record/schema_dumper.rb +13 -7
  39. data/lib/active_record/test_case.rb +18 -5
  40. data/lib/active_record/transactions.rb +89 -34
  41. data/lib/active_record/validations.rb +270 -180
  42. data/lib/active_record/version.rb +1 -1
  43. data/test/cases/active_schema_test_mysql.rb +5 -0
  44. data/test/cases/adapter_test.rb +6 -0
  45. data/test/cases/aggregations_test.rb +39 -0
  46. data/test/cases/associations/belongs_to_associations_test.rb +10 -0
  47. data/test/cases/associations/eager_load_nested_include_test.rb +30 -12
  48. data/test/cases/associations/eager_test.rb +54 -5
  49. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +77 -10
  50. data/test/cases/associations/has_many_associations_test.rb +74 -7
  51. data/test/cases/associations/has_many_through_associations_test.rb +50 -3
  52. data/test/cases/associations/has_one_associations_test.rb +17 -0
  53. data/test/cases/associations/has_one_through_associations_test.rb +49 -1
  54. data/test/cases/associations_test.rb +0 -0
  55. data/test/cases/attribute_methods_test.rb +59 -4
  56. data/test/cases/base_test.rb +93 -21
  57. data/test/cases/binary_test.rb +1 -5
  58. data/test/cases/calculations_test.rb +5 -0
  59. data/test/cases/callbacks_observers_test.rb +38 -0
  60. data/test/cases/connection_test_mysql.rb +1 -1
  61. data/test/cases/defaults_test.rb +32 -1
  62. data/test/cases/deprecated_finder_test.rb +0 -0
  63. data/test/cases/dirty_test.rb +13 -0
  64. data/test/cases/finder_test.rb +162 -12
  65. data/test/cases/fixtures_test.rb +32 -3
  66. data/test/cases/helper.rb +15 -0
  67. data/test/cases/i18n_test.rb +41 -0
  68. data/test/cases/inheritance_test.rb +2 -2
  69. data/test/cases/lifecycle_test.rb +0 -0
  70. data/test/cases/locking_test.rb +4 -9
  71. data/test/cases/method_scoping_test.rb +109 -2
  72. data/test/cases/migration_test.rb +43 -8
  73. data/test/cases/multiple_db_test.rb +25 -0
  74. data/test/cases/named_scope_test.rb +74 -0
  75. data/test/cases/pooled_connections_test.rb +103 -0
  76. data/test/cases/readonly_test.rb +0 -0
  77. data/test/cases/reflection_test.rb +11 -3
  78. data/test/cases/reload_models_test.rb +20 -0
  79. data/test/cases/sanitize_test.rb +25 -0
  80. data/test/cases/schema_authorization_test_postgresql.rb +2 -2
  81. data/test/cases/transactions_test.rb +62 -12
  82. data/test/cases/unconnected_test.rb +0 -0
  83. data/test/cases/validations_i18n_test.rb +921 -0
  84. data/test/cases/validations_test.rb +44 -33
  85. data/test/connections/native_mysql/connection.rb +1 -3
  86. data/test/fixtures/companies.yml +1 -0
  87. data/test/fixtures/customers.yml +10 -1
  88. data/test/fixtures/fixture_database.sqlite3 +0 -0
  89. data/test/fixtures/fixture_database_2.sqlite3 +0 -0
  90. data/test/fixtures/organizations.yml +5 -0
  91. data/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
  92. data/test/models/author.rb +3 -0
  93. data/test/models/category.rb +3 -0
  94. data/test/models/club.rb +6 -0
  95. data/test/models/company.rb +25 -1
  96. data/test/models/customer.rb +19 -1
  97. data/test/models/member.rb +2 -0
  98. data/test/models/member_detail.rb +4 -0
  99. data/test/models/organization.rb +4 -0
  100. data/test/models/parrot.rb +1 -0
  101. data/test/models/post.rb +3 -0
  102. data/test/models/reply.rb +0 -0
  103. data/test/models/topic.rb +3 -0
  104. data/test/schema/schema.rb +12 -1
  105. metadata +22 -10
  106. data/lib/active_record/vendor/mysql.rb +0 -1214
  107. data/test/cases/adapter_test_sqlserver.rb +0 -95
  108. data/test/cases/table_name_test_sqlserver.rb +0 -23
  109. data/test/cases/threaded_connections_test.rb +0 -48
  110. data/test/schema/sqlserver_specific_schema.rb +0 -5
@@ -1,95 +0,0 @@
1
- require "cases/helper"
2
- require 'models/default'
3
- require 'models/post'
4
- require 'models/task'
5
-
6
- class SqlServerAdapterTest < ActiveRecord::TestCase
7
- class TableWithRealColumn < ActiveRecord::Base; end
8
-
9
- fixtures :posts, :tasks
10
-
11
- def setup
12
- @connection = ActiveRecord::Base.connection
13
- end
14
-
15
- def teardown
16
- @connection.execute("SET LANGUAGE us_english") rescue nil
17
- end
18
-
19
- def test_real_column_has_float_type
20
- assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
21
- end
22
-
23
- # SQL Server 2000 has a bug where some unambiguous date formats are not
24
- # correctly identified if the session language is set to german
25
- def test_date_insertion_when_language_is_german
26
- @connection.execute("SET LANGUAGE deutsch")
27
-
28
- assert_nothing_raised do
29
- Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
30
- end
31
- end
32
-
33
- def test_indexes_with_descending_order
34
- # Make sure we have an index with descending order
35
- @connection.execute "CREATE INDEX idx_credit_limit ON accounts (credit_limit DESC)" rescue nil
36
- assert_equal ["credit_limit"], @connection.indexes('accounts').first.columns
37
- ensure
38
- @connection.execute "DROP INDEX accounts.idx_credit_limit"
39
- end
40
-
41
- def test_execute_without_block_closes_statement
42
- assert_all_statements_used_are_closed do
43
- @connection.execute("SELECT 1")
44
- end
45
- end
46
-
47
- def test_execute_with_block_closes_statement
48
- assert_all_statements_used_are_closed do
49
- @connection.execute("SELECT 1") do |sth|
50
- assert !sth.finished?, "Statement should still be alive within block"
51
- end
52
- end
53
- end
54
-
55
- def test_insert_with_identity_closes_statement
56
- assert_all_statements_used_are_closed do
57
- @connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
58
- end
59
- end
60
-
61
- def test_insert_without_identity_closes_statement
62
- assert_all_statements_used_are_closed do
63
- @connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
64
- end
65
- end
66
-
67
- def test_active_closes_statement
68
- assert_all_statements_used_are_closed do
69
- @connection.active?
70
- end
71
- end
72
-
73
- def assert_all_statements_used_are_closed(&block)
74
- existing_handles = []
75
- ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
76
- GC.disable
77
-
78
- yield
79
-
80
- used_handles = []
81
- ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
82
-
83
- assert_block "No statements were used within given block" do
84
- used_handles.size > 0
85
- end
86
-
87
- ObjectSpace.each_object(DBI::StatementHandle) do |handle|
88
- assert_block "Statement should have been closed within given block" do
89
- handle.finished?
90
- end
91
- end
92
- ensure
93
- GC.enable
94
- end
95
- end
@@ -1,23 +0,0 @@
1
- require "cases/helper"
2
- require 'active_record/schema'
3
-
4
- if ActiveRecord::Base.connection.supports_migrations?
5
- class Order < ActiveRecord::Base
6
- self.table_name = '[order]'
7
- end
8
-
9
- class TableNameTest < ActiveRecord::TestCase
10
- self.use_transactional_fixtures = false
11
-
12
- # Ensures Model.columns works when using SQLServer escape characters.
13
- # Enables legacy schemas using SQL reserved words as table names.
14
- # Should work with table names with spaces as well ('table name').
15
- def test_escaped_table_name
16
- assert_nothing_raised do
17
- ActiveRecord::Base.connection.select_all 'SELECT * FROM [order]'
18
- end
19
- assert_equal '[order]', Order.table_name
20
- assert_equal 5, Order.columns.length
21
- end
22
- end
23
- end
@@ -1,48 +0,0 @@
1
- require "cases/helper"
2
- require 'models/topic'
3
- require 'models/reply'
4
-
5
- unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name
6
- class ThreadedConnectionsTest < ActiveRecord::TestCase
7
- self.use_transactional_fixtures = false
8
-
9
- fixtures :topics
10
-
11
- def setup
12
- @connection = ActiveRecord::Base.remove_connection
13
- @connections = []
14
- @allow_concurrency = ActiveRecord::Base.allow_concurrency
15
- end
16
-
17
- def teardown
18
- # clear the connection cache
19
- ActiveRecord::Base.send(:clear_all_cached_connections!)
20
- # set allow_concurrency to saved value
21
- ActiveRecord::Base.allow_concurrency = @allow_concurrency
22
- # reestablish old connection
23
- ActiveRecord::Base.establish_connection(@connection)
24
- end
25
-
26
- def gather_connections(use_threaded_connections)
27
- ActiveRecord::Base.allow_concurrency = use_threaded_connections
28
- ActiveRecord::Base.establish_connection(@connection)
29
-
30
- 5.times do
31
- Thread.new do
32
- Topic.find :first
33
- @connections << ActiveRecord::Base.active_connections.values.first
34
- end.join
35
- end
36
- end
37
-
38
- def test_threaded_connections
39
- gather_connections(true)
40
- assert_equal @connections.uniq.length, 5
41
- end
42
-
43
- def test_unthreaded_connections
44
- gather_connections(false)
45
- assert_equal @connections.uniq.length, 1
46
- end
47
- end
48
- end
@@ -1,5 +0,0 @@
1
- ActiveRecord::Schema.define do
2
- create_table :table_with_real_columns, :force => true do |t|
3
- t.column :real_number, :real
4
- end
5
- end