activerecord 1.15.6 → 2.0.0

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 (185) hide show
  1. data/CHANGELOG +2454 -34
  2. data/README +1 -1
  3. data/RUNNING_UNIT_TESTS +3 -34
  4. data/Rakefile +98 -77
  5. data/install.rb +1 -1
  6. data/lib/active_record.rb +13 -22
  7. data/lib/active_record/aggregations.rb +38 -49
  8. data/lib/active_record/associations.rb +452 -333
  9. data/lib/active_record/associations/association_collection.rb +66 -20
  10. data/lib/active_record/associations/association_proxy.rb +9 -8
  11. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +46 -51
  12. data/lib/active_record/associations/has_many_association.rb +21 -57
  13. data/lib/active_record/associations/has_many_through_association.rb +38 -18
  14. data/lib/active_record/associations/has_one_association.rb +30 -14
  15. data/lib/active_record/attribute_methods.rb +253 -0
  16. data/lib/active_record/base.rb +719 -494
  17. data/lib/active_record/calculations.rb +62 -63
  18. data/lib/active_record/callbacks.rb +57 -83
  19. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +38 -9
  20. data/lib/active_record/connection_adapters/abstract/database_statements.rb +56 -15
  21. data/lib/active_record/connection_adapters/abstract/query_cache.rb +87 -0
  22. data/lib/active_record/connection_adapters/abstract/quoting.rb +23 -12
  23. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +191 -62
  24. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +37 -34
  25. data/lib/active_record/connection_adapters/abstract_adapter.rb +28 -17
  26. data/lib/active_record/connection_adapters/mysql_adapter.rb +119 -37
  27. data/lib/active_record/connection_adapters/postgresql_adapter.rb +473 -210
  28. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
  29. data/lib/active_record/connection_adapters/sqlite_adapter.rb +91 -107
  30. data/lib/active_record/fixtures.rb +503 -113
  31. data/lib/active_record/locking/optimistic.rb +72 -34
  32. data/lib/active_record/migration.rb +80 -57
  33. data/lib/active_record/observer.rb +13 -10
  34. data/lib/active_record/query_cache.rb +16 -57
  35. data/lib/active_record/reflection.rb +35 -38
  36. data/lib/active_record/schema.rb +5 -5
  37. data/lib/active_record/schema_dumper.rb +35 -13
  38. data/lib/active_record/serialization.rb +98 -0
  39. data/lib/active_record/serializers/json_serializer.rb +71 -0
  40. data/lib/active_record/{xml_serialization.rb → serializers/xml_serializer.rb} +90 -83
  41. data/lib/active_record/timestamp.rb +20 -21
  42. data/lib/active_record/transactions.rb +39 -43
  43. data/lib/active_record/validations.rb +256 -107
  44. data/lib/active_record/version.rb +3 -3
  45. data/lib/activerecord.rb +1 -0
  46. data/test/aaa_create_tables_test.rb +15 -2
  47. data/test/abstract_unit.rb +24 -17
  48. data/test/active_schema_test_mysql.rb +20 -8
  49. data/test/adapter_test.rb +23 -5
  50. data/test/adapter_test_sqlserver.rb +15 -1
  51. data/test/aggregations_test.rb +16 -1
  52. data/test/all.sh +2 -2
  53. data/test/associations/ar_joins_test.rb +0 -0
  54. data/test/associations/callbacks_test.rb +51 -30
  55. data/test/associations/cascaded_eager_loading_test.rb +1 -29
  56. data/test/associations/eager_singularization_test.rb +145 -0
  57. data/test/associations/eager_test.rb +42 -6
  58. data/test/associations/extension_test.rb +6 -1
  59. data/test/associations/inner_join_association_test.rb +88 -0
  60. data/test/associations/join_model_test.rb +47 -16
  61. data/test/associations_test.rb +449 -226
  62. data/test/attribute_methods_test.rb +97 -0
  63. data/test/base_test.rb +251 -105
  64. data/test/binary_test.rb +22 -27
  65. data/test/calculations_test.rb +37 -5
  66. data/test/callbacks_test.rb +23 -0
  67. data/test/connection_test_firebird.rb +2 -2
  68. data/test/connection_test_mysql.rb +30 -0
  69. data/test/connections/native_mysql/connection.rb +3 -0
  70. data/test/connections/native_sqlite/connection.rb +5 -14
  71. data/test/connections/native_sqlite3/connection.rb +5 -14
  72. data/test/connections/native_sqlite3/in_memory_connection.rb +1 -1
  73. data/test/{copy_table_sqlite.rb → copy_table_test_sqlite.rb} +8 -3
  74. data/test/datatype_test_postgresql.rb +178 -27
  75. data/test/{empty_date_time_test.rb → date_time_test.rb} +13 -1
  76. data/test/defaults_test.rb +8 -1
  77. data/test/deprecated_finder_test.rb +7 -128
  78. data/test/finder_test.rb +192 -54
  79. data/test/fixtures/all/developers.yml +0 -0
  80. data/test/fixtures/all/people.csv +0 -0
  81. data/test/fixtures/all/tasks.yml +0 -0
  82. data/test/fixtures/author.rb +12 -5
  83. data/test/fixtures/binaries.yml +130 -435
  84. data/test/fixtures/category.rb +6 -0
  85. data/test/fixtures/company.rb +8 -1
  86. data/test/fixtures/computer.rb +1 -0
  87. data/test/fixtures/contact.rb +16 -0
  88. data/test/fixtures/customer.rb +2 -2
  89. data/test/fixtures/db_definitions/db2.drop.sql +1 -0
  90. data/test/fixtures/db_definitions/db2.sql +4 -0
  91. data/test/fixtures/db_definitions/firebird.drop.sql +3 -1
  92. data/test/fixtures/db_definitions/firebird.sql +6 -0
  93. data/test/fixtures/db_definitions/frontbase.drop.sql +1 -0
  94. data/test/fixtures/db_definitions/frontbase.sql +5 -0
  95. data/test/fixtures/db_definitions/openbase.sql +41 -25
  96. data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
  97. data/test/fixtures/db_definitions/oracle.sql +5 -0
  98. data/test/fixtures/db_definitions/postgresql.drop.sql +7 -0
  99. data/test/fixtures/db_definitions/postgresql.sql +87 -58
  100. data/test/fixtures/db_definitions/postgresql2.sql +1 -2
  101. data/test/fixtures/db_definitions/schema.rb +280 -0
  102. data/test/fixtures/db_definitions/schema2.rb +11 -0
  103. data/test/fixtures/db_definitions/sqlite.drop.sql +1 -0
  104. data/test/fixtures/db_definitions/sqlite.sql +4 -0
  105. data/test/fixtures/db_definitions/sybase.drop.sql +1 -0
  106. data/test/fixtures/db_definitions/sybase.sql +4 -0
  107. data/test/fixtures/developer.rb +10 -0
  108. data/test/fixtures/example.log +1 -0
  109. data/test/fixtures/flowers.jpg +0 -0
  110. data/test/fixtures/item.rb +7 -0
  111. data/test/fixtures/items.yml +4 -0
  112. data/test/fixtures/joke.rb +0 -3
  113. data/test/fixtures/matey.rb +4 -0
  114. data/test/fixtures/mateys.yml +4 -0
  115. data/test/fixtures/minimalistic.rb +2 -0
  116. data/test/fixtures/minimalistics.yml +2 -0
  117. data/test/fixtures/mixins.yml +2 -100
  118. data/test/fixtures/parrot.rb +13 -0
  119. data/test/fixtures/parrots.yml +27 -0
  120. data/test/fixtures/parrots_pirates.yml +7 -0
  121. data/test/fixtures/pirate.rb +5 -0
  122. data/test/fixtures/pirates.yml +9 -0
  123. data/test/fixtures/post.rb +1 -0
  124. data/test/fixtures/project.rb +3 -2
  125. data/test/fixtures/reserved_words/distinct.yml +5 -0
  126. data/test/fixtures/reserved_words/distincts_selects.yml +11 -0
  127. data/test/fixtures/reserved_words/group.yml +14 -0
  128. data/test/fixtures/reserved_words/select.yml +8 -0
  129. data/test/fixtures/reserved_words/values.yml +7 -0
  130. data/test/fixtures/ship.rb +3 -0
  131. data/test/fixtures/ships.yml +5 -0
  132. data/test/fixtures/tagging.rb +4 -0
  133. data/test/fixtures/taggings.yml +8 -1
  134. data/test/fixtures/topic.rb +13 -1
  135. data/test/fixtures/treasure.rb +4 -0
  136. data/test/fixtures/treasures.yml +10 -0
  137. data/test/fixtures_test.rb +205 -24
  138. data/test/inheritance_test.rb +7 -1
  139. data/test/json_serialization_test.rb +180 -0
  140. data/test/lifecycle_test.rb +1 -1
  141. data/test/locking_test.rb +85 -2
  142. data/test/migration_test.rb +206 -40
  143. data/test/mixin_test.rb +13 -515
  144. data/test/pk_test.rb +3 -6
  145. data/test/query_cache_test.rb +104 -0
  146. data/test/reflection_test.rb +16 -0
  147. data/test/reserved_word_test_mysql.rb +177 -0
  148. data/test/schema_dumper_test.rb +38 -3
  149. data/test/serialization_test.rb +47 -0
  150. data/test/transactions_test.rb +74 -23
  151. data/test/unconnected_test.rb +1 -1
  152. data/test/validations_test.rb +322 -32
  153. data/test/xml_serialization_test.rb +121 -44
  154. metadata +48 -41
  155. data/examples/associations.rb +0 -87
  156. data/examples/shared_setup.rb +0 -15
  157. data/examples/validation.rb +0 -85
  158. data/lib/active_record/acts/list.rb +0 -256
  159. data/lib/active_record/acts/nested_set.rb +0 -211
  160. data/lib/active_record/acts/tree.rb +0 -96
  161. data/lib/active_record/connection_adapters/db2_adapter.rb +0 -228
  162. data/lib/active_record/connection_adapters/firebird_adapter.rb +0 -728
  163. data/lib/active_record/connection_adapters/frontbase_adapter.rb +0 -861
  164. data/lib/active_record/connection_adapters/openbase_adapter.rb +0 -350
  165. data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -690
  166. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +0 -591
  167. data/lib/active_record/connection_adapters/sybase_adapter.rb +0 -662
  168. data/lib/active_record/deprecated_associations.rb +0 -104
  169. data/lib/active_record/deprecated_finders.rb +0 -44
  170. data/lib/active_record/vendor/simple.rb +0 -693
  171. data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
  172. data/lib/active_record/wrappings.rb +0 -58
  173. data/test/connections/native_sqlserver/connection.rb +0 -23
  174. data/test/connections/native_sqlserver_odbc/connection.rb +0 -25
  175. data/test/deprecated_associations_test.rb +0 -396
  176. data/test/fixtures/db_definitions/mysql.drop.sql +0 -32
  177. data/test/fixtures/db_definitions/mysql.sql +0 -234
  178. data/test/fixtures/db_definitions/mysql2.drop.sql +0 -2
  179. data/test/fixtures/db_definitions/mysql2.sql +0 -5
  180. data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -34
  181. data/test/fixtures/db_definitions/sqlserver.sql +0 -243
  182. data/test/fixtures/db_definitions/sqlserver2.drop.sql +0 -2
  183. data/test/fixtures/db_definitions/sqlserver2.sql +0 -5
  184. data/test/fixtures/mixin.rb +0 -63
  185. data/test/mixin_nested_set_test.rb +0 -196
@@ -1,2 +0,0 @@
1
- DROP TABLE courses;
2
-
@@ -1,5 +0,0 @@
1
- CREATE TABLE courses (
2
- id int NOT NULL PRIMARY KEY,
3
- name varchar(255) NOT NULL
4
- );
5
-
@@ -1,63 +0,0 @@
1
- class Mixin < ActiveRecord::Base
2
-
3
- end
4
-
5
- class TreeMixin < Mixin
6
- acts_as_tree :foreign_key => "parent_id", :order => "id"
7
- end
8
-
9
- class TreeMixinWithoutOrder < Mixin
10
- acts_as_tree :foreign_key => "parent_id"
11
- end
12
-
13
- class RecursivelyCascadedTreeMixin < Mixin
14
- acts_as_tree :foreign_key => "parent_id"
15
- has_one :first_child, :class_name => 'RecursivelyCascadedTreeMixin', :foreign_key => :parent_id
16
- end
17
-
18
- class ListMixin < Mixin
19
- acts_as_list :column => "pos", :scope => :parent
20
-
21
- def self.table_name() "mixins" end
22
- end
23
-
24
- class ListMixinSub1 < ListMixin
25
- end
26
-
27
- class ListMixinSub2 < ListMixin
28
- end
29
-
30
-
31
- class ListWithStringScopeMixin < ActiveRecord::Base
32
- acts_as_list :column => "pos", :scope => 'parent_id = #{parent_id}'
33
-
34
- def self.table_name() "mixins" end
35
- end
36
-
37
- class NestedSet < Mixin
38
- acts_as_nested_set :scope => "root_id IS NULL"
39
-
40
- def self.table_name() "mixins" end
41
- end
42
-
43
- class NestedSetWithStringScope < Mixin
44
- acts_as_nested_set :scope => 'root_id = #{root_id}'
45
-
46
- def self.table_name() "mixins" end
47
- end
48
-
49
- class NestedSetWithSymbolScope < Mixin
50
- acts_as_nested_set :scope => :root
51
-
52
- def self.table_name() "mixins" end
53
- end
54
-
55
- class NestedSetSuperclass < Mixin
56
- acts_as_nested_set :scope => :root
57
-
58
- def self.table_name() "mixins" end
59
- end
60
-
61
- class NestedSetSubclass < NestedSetSuperclass
62
-
63
- end
@@ -1,196 +0,0 @@
1
- require 'abstract_unit'
2
- require 'active_record/acts/nested_set'
3
- require 'fixtures/mixin'
4
- require 'pp'
5
-
6
- class MixinNestedSetTest < Test::Unit::TestCase
7
- fixtures :mixins
8
-
9
- def test_mixing_in_methods
10
- ns = NestedSet.new
11
- assert( ns.respond_to?( :all_children ) )
12
- assert_equal( ns.scope_condition, "root_id IS NULL" )
13
-
14
- check_method_mixins ns
15
- end
16
-
17
- def test_string_scope
18
- ns = NestedSetWithStringScope.new
19
-
20
- ns.root_id = 1
21
- assert_equal( ns.scope_condition, "root_id = 1" )
22
- ns.root_id = 42
23
- assert_equal( ns.scope_condition, "root_id = 42" )
24
- check_method_mixins ns
25
- end
26
-
27
- def test_symbol_scope
28
- ns = NestedSetWithSymbolScope.new
29
- ns.root_id = 1
30
- assert_equal( ns.scope_condition, "root_id = 1" )
31
- ns.root_id = 42
32
- assert_equal( ns.scope_condition, "root_id = 42" )
33
- check_method_mixins ns
34
- end
35
-
36
- def check_method_mixins( obj )
37
- [:scope_condition, :left_col_name, :right_col_name, :parent_column, :root?, :add_child,
38
- :children_count, :full_set, :all_children, :direct_children].each { |symbol| assert( obj.respond_to?(symbol)) }
39
- end
40
-
41
- def set( id )
42
- NestedSet.find( 3000 + id )
43
- end
44
-
45
- def test_adding_children
46
- assert( set(1).unknown? )
47
- assert( set(2).unknown? )
48
- set(1).add_child set(2)
49
-
50
- # Did we maintain adding the parent_ids?
51
- assert( set(1).root? )
52
- assert( set(2).child? )
53
- assert( set(2).parent_id == set(1).id )
54
-
55
- # Check boundies
56
- assert_equal( set(1).lft, 1 )
57
- assert_equal( set(2).lft, 2 )
58
- assert_equal( set(2).rgt, 3 )
59
- assert_equal( set(1).rgt, 4 )
60
-
61
- # Check children cound
62
- assert_equal( set(1).children_count, 1 )
63
-
64
- set(1).add_child set(3)
65
-
66
- #check boundries
67
- assert_equal( set(1).lft, 1 )
68
- assert_equal( set(2).lft, 2 )
69
- assert_equal( set(2).rgt, 3 )
70
- assert_equal( set(3).lft, 4 )
71
- assert_equal( set(3).rgt, 5 )
72
- assert_equal( set(1).rgt, 6 )
73
-
74
- # How is the count looking?
75
- assert_equal( set(1).children_count, 2 )
76
-
77
- set(2).add_child set(4)
78
-
79
- # boundries
80
- assert_equal( set(1).lft, 1 )
81
- assert_equal( set(2).lft, 2 )
82
- assert_equal( set(4).lft, 3 )
83
- assert_equal( set(4).rgt, 4 )
84
- assert_equal( set(2).rgt, 5 )
85
- assert_equal( set(3).lft, 6 )
86
- assert_equal( set(3).rgt, 7 )
87
- assert_equal( set(1).rgt, 8 )
88
-
89
- # Children count
90
- assert_equal( set(1).children_count, 3 )
91
- assert_equal( set(2).children_count, 1 )
92
- assert_equal( set(3).children_count, 0 )
93
- assert_equal( set(4).children_count, 0 )
94
-
95
- set(2).add_child set(5)
96
- set(4).add_child set(6)
97
-
98
- assert_equal( set(2).children_count, 3 )
99
-
100
-
101
- # Children accessors
102
- assert_equal( set(1).full_set.length, 6 )
103
- assert_equal( set(2).full_set.length, 4 )
104
- assert_equal( set(4).full_set.length, 2 )
105
-
106
- assert_equal( set(1).all_children.length, 5 )
107
- assert_equal( set(6).all_children.length, 0 )
108
-
109
- assert_equal( set(1).direct_children.length, 2 )
110
-
111
- end
112
-
113
- def test_snipping_tree
114
- big_tree = NestedSetWithStringScope.find( 4001 )
115
-
116
- # Make sure we have the right one
117
- assert_equal( 3, big_tree.direct_children.length )
118
- assert_equal( 10, big_tree.full_set.length )
119
-
120
- NestedSetWithStringScope.find( 4005 ).destroy
121
-
122
- big_tree = NestedSetWithStringScope.find( 4001 )
123
-
124
- assert_equal( 7, big_tree.full_set.length )
125
- assert_equal( 2, big_tree.direct_children.length )
126
-
127
- assert_equal( 1, NestedSetWithStringScope.find(4001).lft )
128
- assert_equal( 2, NestedSetWithStringScope.find(4002).lft )
129
- assert_equal( 3, NestedSetWithStringScope.find(4003).lft )
130
- assert_equal( 4, NestedSetWithStringScope.find(4003).rgt )
131
- assert_equal( 5, NestedSetWithStringScope.find(4004).lft )
132
- assert_equal( 6, NestedSetWithStringScope.find(4004).rgt )
133
- assert_equal( 7, NestedSetWithStringScope.find(4002).rgt )
134
- assert_equal( 8, NestedSetWithStringScope.find(4008).lft )
135
- assert_equal( 9, NestedSetWithStringScope.find(4009).lft )
136
- assert_equal(10, NestedSetWithStringScope.find(4009).rgt )
137
- assert_equal(11, NestedSetWithStringScope.find(4010).lft )
138
- assert_equal(12, NestedSetWithStringScope.find(4010).rgt )
139
- assert_equal(13, NestedSetWithStringScope.find(4008).rgt )
140
- assert_equal(14, NestedSetWithStringScope.find(4001).rgt )
141
- end
142
-
143
- def test_deleting_root
144
- NestedSetWithStringScope.find(4001).destroy
145
-
146
- assert( NestedSetWithStringScope.count == 0 )
147
- end
148
-
149
- def test_common_usage
150
- mixins(:set_1).add_child( mixins(:set_2) )
151
- assert_equal( 1, mixins(:set_1).direct_children.length )
152
-
153
- mixins(:set_2).add_child( mixins(:set_3) )
154
- assert_equal( 1, mixins(:set_1).direct_children.length )
155
-
156
- # Local cache is now out of date!
157
- # Problem: the update_alls update all objects up the tree
158
- mixins(:set_1).reload
159
- assert_equal( 2, mixins(:set_1).all_children.length )
160
-
161
- assert_equal( 1, mixins(:set_1).lft )
162
- assert_equal( 2, mixins(:set_2).lft )
163
- assert_equal( 3, mixins(:set_3).lft )
164
- assert_equal( 4, mixins(:set_3).rgt )
165
- assert_equal( 5, mixins(:set_2).rgt )
166
- assert_equal( 6, mixins(:set_1).rgt )
167
-
168
- assert( mixins(:set_1).root? )
169
-
170
- begin
171
- mixins(:set_4).add_child( mixins(:set_1) )
172
- fail
173
- rescue
174
- end
175
-
176
- assert_equal( 2, mixins(:set_1).all_children.length )
177
-
178
- mixins(:set_1).add_child mixins(:set_4)
179
-
180
- assert_equal( 3, mixins(:set_1).all_children.length )
181
- end
182
-
183
- def test_inheritance
184
- parent = mixins(:sti_set_3100)
185
- child = mixins(:sti_set_3101)
186
- grandchild = mixins(:sti_set_3102)
187
- assert_equal 5, parent.full_set.size
188
- assert_equal 2, child.full_set.size
189
- assert_equal 4, parent.all_children.size
190
- assert_equal 1, child.all_children.size
191
- assert_equal 2, parent.direct_children.size
192
- assert_equal 1, child.direct_children.size
193
- child.destroy
194
- assert_equal 3, parent.full_set.size
195
- end
196
- end