activerecord 1.10.1 → 1.11.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 (84) hide show
  1. data/CHANGELOG +187 -19
  2. data/RUNNING_UNIT_TESTS +11 -0
  3. data/lib/active_record.rb +3 -1
  4. data/lib/active_record/acts/list.rb +25 -14
  5. data/lib/active_record/acts/nested_set.rb +4 -4
  6. data/lib/active_record/acts/tree.rb +18 -1
  7. data/lib/active_record/associations.rb +90 -17
  8. data/lib/active_record/associations/association_collection.rb +44 -5
  9. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +17 -4
  10. data/lib/active_record/associations/has_many_association.rb +13 -3
  11. data/lib/active_record/associations/has_one_association.rb +19 -0
  12. data/lib/active_record/base.rb +292 -268
  13. data/lib/active_record/callbacks.rb +14 -14
  14. data/lib/active_record/connection_adapters/abstract_adapter.rb +137 -75
  15. data/lib/active_record/connection_adapters/db2_adapter.rb +10 -8
  16. data/lib/active_record/connection_adapters/mysql_adapter.rb +91 -64
  17. data/lib/active_record/connection_adapters/oci_adapter.rb +6 -6
  18. data/lib/active_record/connection_adapters/postgresql_adapter.rb +113 -60
  19. data/lib/active_record/connection_adapters/sqlite_adapter.rb +15 -12
  20. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +159 -132
  21. data/lib/active_record/fixtures.rb +59 -12
  22. data/lib/active_record/locking.rb +10 -9
  23. data/lib/active_record/migration.rb +112 -5
  24. data/lib/active_record/query_cache.rb +64 -0
  25. data/lib/active_record/timestamp.rb +10 -8
  26. data/lib/active_record/validations.rb +121 -26
  27. data/rakefile +16 -10
  28. data/test/aaa_create_tables_test.rb +26 -48
  29. data/test/abstract_unit.rb +3 -0
  30. data/test/aggregations_test.rb +19 -19
  31. data/test/association_callbacks_test.rb +110 -0
  32. data/test/associations_go_eager_test.rb +48 -14
  33. data/test/associations_test.rb +344 -142
  34. data/test/base_test.rb +150 -31
  35. data/test/binary_test.rb +7 -0
  36. data/test/callbacks_test.rb +24 -5
  37. data/test/column_alias_test.rb +2 -2
  38. data/test/connections/native_sqlserver_odbc/connection.rb +26 -0
  39. data/test/deprecated_associations_test.rb +27 -28
  40. data/test/deprecated_finder_test.rb +8 -9
  41. data/test/finder_test.rb +52 -17
  42. data/test/fixtures/author.rb +39 -0
  43. data/test/fixtures/categories.yml +7 -0
  44. data/test/fixtures/categories_posts.yml +8 -0
  45. data/test/fixtures/category.rb +2 -0
  46. data/test/fixtures/comment.rb +3 -1
  47. data/test/fixtures/comments.yml +43 -1
  48. data/test/fixtures/companies.yml +14 -0
  49. data/test/fixtures/company.rb +1 -1
  50. data/test/fixtures/computers.yml +2 -1
  51. data/test/fixtures/db_definitions/db2.sql +7 -2
  52. data/test/fixtures/db_definitions/mysql.drop.sql +2 -0
  53. data/test/fixtures/db_definitions/mysql.sql +11 -6
  54. data/test/fixtures/db_definitions/oci.sql +7 -2
  55. data/test/fixtures/db_definitions/postgresql.drop.sql +3 -1
  56. data/test/fixtures/db_definitions/postgresql.sql +8 -5
  57. data/test/fixtures/db_definitions/sqlite.drop.sql +2 -0
  58. data/test/fixtures/db_definitions/sqlite.sql +9 -4
  59. data/test/fixtures/db_definitions/sqlserver.drop.sql +2 -0
  60. data/test/fixtures/db_definitions/sqlserver.sql +12 -7
  61. data/test/fixtures/developer.rb +8 -1
  62. data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
  63. data/test/fixtures/post.rb +8 -2
  64. data/test/fixtures/posts.yml +21 -0
  65. data/test/fixtures/project.rb +14 -1
  66. data/test/fixtures/subscriber.rb +3 -0
  67. data/test/fixtures_test.rb +14 -0
  68. data/test/inheritance_test.rb +30 -22
  69. data/test/lifecycle_test.rb +3 -4
  70. data/test/locking_test.rb +2 -4
  71. data/test/migration_test.rb +186 -0
  72. data/test/mixin_nested_set_test.rb +19 -19
  73. data/test/mixin_test.rb +88 -88
  74. data/test/modules_test.rb +5 -10
  75. data/test/multiple_db_test.rb +2 -0
  76. data/test/pk_test.rb +8 -12
  77. data/test/reflection_test.rb +8 -4
  78. data/test/schema_test_postgresql.rb +63 -0
  79. data/test/thread_safety_test.rb +4 -1
  80. data/test/transactions_test.rb +9 -2
  81. data/test/unconnected_test.rb +1 -0
  82. data/test/validations_test.rb +151 -8
  83. metadata +11 -5
  84. data/test/migration_mysql.rb +0 -104
@@ -1,6 +1,7 @@
1
1
  require 'abstract_unit'
2
2
  require 'fixtures/topic'
3
3
  require 'fixtures/developer'
4
+ require 'fixtures/reply'
4
5
 
5
6
  class Topic; def after_find() end end
6
7
  class Developer; def after_find() end end
@@ -54,9 +55,7 @@ class MultiObserver < ActiveRecord::Observer
54
55
  end
55
56
 
56
57
  class LifecycleTest < Test::Unit::TestCase
57
- def setup
58
- @topics, @developers = create_fixtures("topics", "developers")
59
- end
58
+ fixtures :topics, :developers
60
59
 
61
60
  def test_before_destroy
62
61
  assert_equal 2, Topic.count
@@ -106,4 +105,4 @@ class LifecycleTest < Test::Unit::TestCase
106
105
  developer = Developer.find(1)
107
106
  assert_equal multi_observer.record.name, developer.name
108
107
  end
109
- end
108
+ end
@@ -2,9 +2,7 @@ require 'abstract_unit'
2
2
  require 'fixtures/person'
3
3
 
4
4
  class LockingTest < Test::Unit::TestCase
5
- def setup
6
- @people = create_fixtures('people')
7
- end
5
+ fixtures :people
8
6
 
9
7
  def test_lock_existing
10
8
  p1 = Person.find(1)
@@ -31,4 +29,4 @@ class LockingTest < Test::Unit::TestCase
31
29
  p2.save
32
30
  }
33
31
  end
34
- end
32
+ end
@@ -0,0 +1,186 @@
1
+ require 'abstract_unit'
2
+ require 'fixtures/person'
3
+ require File.dirname(__FILE__) + '/fixtures/migrations/1_people_have_last_names'
4
+ require File.dirname(__FILE__) + '/fixtures/migrations/2_we_need_reminders'
5
+
6
+ if ActiveRecord::Base.connection.supports_migrations?
7
+
8
+ class Reminder < ActiveRecord::Base; end
9
+
10
+ class MigrationTest < Test::Unit::TestCase
11
+ def setup
12
+ end
13
+
14
+ def teardown
15
+ ActiveRecord::Base.connection.initialize_schema_information
16
+ ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
17
+
18
+ Reminder.connection.drop_table("reminders") rescue nil
19
+ Reminder.connection.drop_table("people_reminders") rescue nil
20
+ Reminder.reset_column_information
21
+
22
+ Person.connection.remove_column("people", "last_name") rescue nil
23
+ Person.connection.remove_column("people", "bio") rescue nil
24
+ Person.connection.remove_column("people", "age") rescue nil
25
+ Person.connection.remove_column("people", "height") rescue nil
26
+ Person.connection.remove_column("people", "birthday") rescue nil
27
+ Person.connection.remove_column("people", "favorite_day") rescue nil
28
+ Person.connection.remove_column("people", "male") rescue nil
29
+ Person.connection.remove_column("people", "administrator") rescue nil
30
+ Person.reset_column_information
31
+ end
32
+
33
+ def test_add_index
34
+ Person.connection.add_column "people", "last_name", :string
35
+
36
+ assert_nothing_raised { Person.connection.add_index("people", "last_name") }
37
+ assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
38
+
39
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
40
+ assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
41
+ end
42
+
43
+ def test_native_types
44
+ Person.delete_all
45
+ Person.connection.add_column "people", "last_name", :string
46
+ Person.connection.add_column "people", "bio", :text
47
+ Person.connection.add_column "people", "age", :integer
48
+ Person.connection.add_column "people", "height", :float
49
+ Person.connection.add_column "people", "birthday", :datetime
50
+ Person.connection.add_column "people", "favorite_day", :date
51
+ Person.connection.add_column "people", "male", :boolean
52
+ assert_nothing_raised { Person.create :first_name => 'bob', :last_name => 'bobsen', :bio => "I was born ....", :age => 18, :height => 1.78, :birthday => 18.years.ago, :favorite_day => 10.days.ago, :male => true }
53
+ bob = Person.find(:first)
54
+
55
+ assert_equal bob.first_name, 'bob'
56
+ assert_equal bob.last_name, 'bobsen'
57
+ assert_equal bob.bio, "I was born ...."
58
+ assert_equal bob.age, 18
59
+ assert_equal bob.male?, true
60
+
61
+ assert_equal String, bob.first_name.class
62
+ assert_equal String, bob.last_name.class
63
+ assert_equal String, bob.bio.class
64
+ assert_equal Fixnum, bob.age.class
65
+ assert_equal Time, bob.birthday.class
66
+ assert_equal Date, bob.favorite_day.class
67
+ assert_equal TrueClass, bob.male?.class
68
+ end
69
+
70
+ def test_add_remove_single_field
71
+ assert !Person.column_methods_hash.include?(:last_name)
72
+
73
+ PeopleHaveLastNames.up
74
+
75
+ Person.reset_column_information
76
+ assert Person.column_methods_hash.include?(:last_name)
77
+
78
+ PeopleHaveLastNames.down
79
+
80
+ Person.reset_column_information
81
+ assert !Person.column_methods_hash.include?(:last_name)
82
+ end
83
+
84
+ def test_add_rename
85
+ Person.delete_all
86
+
87
+ Person.connection.add_column "people", "girlfriend", :string
88
+ Person.create :girlfriend => 'bobette'
89
+
90
+ begin
91
+ Person.connection.rename_column "people", "girlfriend", "exgirlfriend"
92
+
93
+ Person.reset_column_information
94
+ bob = Person.find(:first)
95
+
96
+ assert_equal "bobette", bob.exgirlfriend
97
+ ensure
98
+ Person.connection.remove_column("people", "girlfriend") rescue nil
99
+ Person.connection.remove_column("people", "exgirlfriend") rescue nil
100
+ end
101
+
102
+ end
103
+
104
+ def test_change_column
105
+ Person.connection.add_column "people", "bio", :string
106
+ assert_nothing_raised { Person.connection.change_column "people", "bio", :text }
107
+ end
108
+
109
+ def test_change_column_with_new_default
110
+ Person.connection.add_column "people", "administrator", :boolean, :default => 1
111
+ Person.reset_column_information
112
+ assert Person.new.administrator?
113
+
114
+ assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => 0 }
115
+ Person.reset_column_information
116
+ assert !Person.new.administrator?
117
+ end
118
+
119
+ def test_add_table
120
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
121
+
122
+ WeNeedReminders.up
123
+
124
+ assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
125
+ assert_equal "hello world", Reminder.find(:first).content
126
+
127
+ WeNeedReminders.down
128
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
129
+ end
130
+
131
+ def test_migrator
132
+ assert !Person.column_methods_hash.include?(:last_name)
133
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
134
+
135
+ ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
136
+
137
+ assert_equal 3, ActiveRecord::Migrator.current_version
138
+ Person.reset_column_information
139
+ assert Person.column_methods_hash.include?(:last_name)
140
+ assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
141
+ assert_equal "hello world", Reminder.find(:first).content
142
+
143
+ ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/')
144
+
145
+ assert_equal 0, ActiveRecord::Migrator.current_version
146
+ Person.reset_column_information
147
+ assert !Person.column_methods_hash.include?(:last_name)
148
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
149
+ end
150
+
151
+ def test_migrator_one_up
152
+ assert !Person.column_methods_hash.include?(:last_name)
153
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
154
+
155
+ ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
156
+
157
+ Person.reset_column_information
158
+ assert Person.column_methods_hash.include?(:last_name)
159
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
160
+
161
+
162
+ ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 2)
163
+
164
+ assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
165
+ assert_equal "hello world", Reminder.find(:first).content
166
+ end
167
+
168
+ def test_migrator_one_down
169
+ ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
170
+
171
+ ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
172
+
173
+ Person.reset_column_information
174
+ assert Person.column_methods_hash.include?(:last_name)
175
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
176
+ end
177
+
178
+ def test_migrator_one_up_one_down
179
+ ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
180
+ ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 0)
181
+
182
+ assert !Person.column_methods_hash.include?(:last_name)
183
+ assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
184
+ end
185
+ end
186
+ end
@@ -143,41 +143,41 @@ class MixinNestedSetTest < Test::Unit::TestCase
143
143
  def test_deleting_root
144
144
  NestedSetWithStringScope.find(4001).destroy
145
145
 
146
- assert( NestedSetWithStringScope.find_all.length == 0 )
146
+ assert( NestedSetWithStringScope.count == 0 )
147
147
  end
148
148
 
149
149
  def test_common_usage
150
- @set_1.add_child( @set_2 )
151
- assert_equal( 1, @set_1.direct_children.length )
150
+ mixins(:set_1).add_child( mixins(:set_2) )
151
+ assert_equal( 1, mixins(:set_1).direct_children.length )
152
152
 
153
- @set_2.add_child( @set_3 )
154
- assert_equal( 1, @set_1.direct_children.length )
153
+ mixins(:set_2).add_child( mixins(:set_3) )
154
+ assert_equal( 1, mixins(:set_1).direct_children.length )
155
155
 
156
156
  # Local cache is now out of date!
157
157
  # Problem: the update_alls update all objects up the tree
158
- @set_1.reload
159
- assert_equal( 2, @set_1.all_children.length )
160
-
161
- assert_equal( 1, @set_1.lft )
162
- assert_equal( 2, @set_2.lft )
163
- assert_equal( 3, @set_3.lft )
164
- assert_equal( 4, @set_3.rgt )
165
- assert_equal( 5, @set_2.rgt )
166
- assert_equal( 6, @set_1.rgt )
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
167
 
168
- assert( @set_1.root? )
168
+ assert( mixins(:set_1).root? )
169
169
 
170
170
  begin
171
- @set_4.add_child( @set_1 )
171
+ mixins(:set_4).add_child( mixins(:set_1) )
172
172
  fail
173
173
  rescue
174
174
  end
175
175
 
176
- assert_equal( 2, @set_1.all_children.length )
176
+ assert_equal( 2, mixins(:set_1).all_children.length )
177
177
 
178
- @set_1.add_child @set_4
178
+ mixins(:set_1).add_child mixins(:set_4)
179
179
 
180
- assert_equal( 3, @set_1.all_children.length )
180
+ assert_equal( 3, mixins(:set_1).all_children.length )
181
181
 
182
182
 
183
183
  end
@@ -9,68 +9,68 @@ class ListTest < Test::Unit::TestCase
9
9
 
10
10
  def test_reordering
11
11
 
12
- assert_equal [@mixins['list_1'].find,
13
- @mixins['list_2'].find,
14
- @mixins['list_3'].find,
15
- @mixins['list_4'].find],
16
- ListMixin.find_all("parent_id=5", "pos")
12
+ assert_equal [mixins(:list_1),
13
+ mixins(:list_2),
14
+ mixins(:list_3),
15
+ mixins(:list_4)],
16
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
17
17
 
18
- @mixins['list_2'].find.move_lower
18
+ mixins(:list_2).move_lower
19
19
 
20
- assert_equal [@mixins['list_1'].find,
21
- @mixins['list_3'].find,
22
- @mixins['list_2'].find,
23
- @mixins['list_4'].find],
24
- ListMixin.find_all("parent_id=5", "pos")
20
+ assert_equal [mixins(:list_1),
21
+ mixins(:list_3),
22
+ mixins(:list_2),
23
+ mixins(:list_4)],
24
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
25
25
 
26
- @mixins['list_2'].find.move_higher
26
+ mixins(:list_2).move_higher
27
27
 
28
- assert_equal [@mixins['list_1'].find,
29
- @mixins['list_2'].find,
30
- @mixins['list_3'].find,
31
- @mixins['list_4'].find],
32
- ListMixin.find_all("parent_id=5", "pos")
28
+ assert_equal [mixins(:list_1),
29
+ mixins(:list_2),
30
+ mixins(:list_3),
31
+ mixins(:list_4)],
32
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
33
33
 
34
- @mixins['list_1'].find.move_to_bottom
34
+ mixins(:list_1).move_to_bottom
35
35
 
36
- assert_equal [@mixins['list_2'].find,
37
- @mixins['list_3'].find,
38
- @mixins['list_4'].find,
39
- @mixins['list_1'].find],
40
- ListMixin.find_all("parent_id=5", "pos")
36
+ assert_equal [mixins(:list_2),
37
+ mixins(:list_3),
38
+ mixins(:list_4),
39
+ mixins(:list_1)],
40
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
41
41
 
42
- @mixins['list_1'].find.move_to_top
42
+ mixins(:list_1).move_to_top
43
43
 
44
- assert_equal [@mixins['list_1'].find,
45
- @mixins['list_2'].find,
46
- @mixins['list_3'].find,
47
- @mixins['list_4'].find],
48
- ListMixin.find_all("parent_id=5", "pos")
44
+ assert_equal [mixins(:list_1),
45
+ mixins(:list_2),
46
+ mixins(:list_3),
47
+ mixins(:list_4)],
48
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
49
49
 
50
50
 
51
- @mixins['list_2'].find.move_to_bottom
51
+ mixins(:list_2).move_to_bottom
52
52
 
53
- assert_equal [@mixins['list_1'].find,
54
- @mixins['list_3'].find,
55
- @mixins['list_4'].find,
56
- @mixins['list_2'].find],
57
- ListMixin.find_all("parent_id=5", "pos")
58
-
59
- @mixins['list_4'].find.move_to_top
60
-
61
- assert_equal [@mixins['list_4'].find,
62
- @mixins['list_1'].find,
63
- @mixins['list_3'].find,
64
- @mixins['list_2'].find],
65
- ListMixin.find_all("parent_id=5", "pos")
53
+ assert_equal [mixins(:list_1),
54
+ mixins(:list_3),
55
+ mixins(:list_4),
56
+ mixins(:list_2)],
57
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
58
+
59
+ mixins(:list_4).move_to_top
60
+
61
+ assert_equal [mixins(:list_4),
62
+ mixins(:list_1),
63
+ mixins(:list_3),
64
+ mixins(:list_2)],
65
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
66
66
 
67
67
  end
68
68
 
69
69
  def test_next_prev
70
- assert_equal @list_2, @list_1.lower_item
71
- assert_nil @list_1.higher_item
72
- assert_equal @list_3, @list_4.higher_item
73
- assert_nil @list_4.lower_item
70
+ assert_equal mixins(:list_2), mixins(:list_1).lower_item
71
+ assert_nil mixins(:list_1).higher_item
72
+ assert_equal mixins(:list_3), mixins(:list_4).higher_item
73
+ assert_nil mixins(:list_4).lower_item
74
74
  end
75
75
 
76
76
 
@@ -130,31 +130,31 @@ class ListTest < Test::Unit::TestCase
130
130
 
131
131
  def test_delete_middle
132
132
 
133
- assert_equal [@mixins['list_1'].find,
134
- @mixins['list_2'].find,
135
- @mixins['list_3'].find,
136
- @mixins['list_4'].find],
137
- ListMixin.find_all("parent_id=5", "pos")
133
+ assert_equal [mixins(:list_1),
134
+ mixins(:list_2),
135
+ mixins(:list_3),
136
+ mixins(:list_4)],
137
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
138
138
 
139
- @mixins['list_2'].find.destroy
139
+ mixins(:list_2).destroy
140
140
 
141
- assert_equal [@mixins['list_1'].find,
142
- @mixins['list_3'].find,
143
- @mixins['list_4'].find],
144
- ListMixin.find_all("parent_id=5", "pos")
141
+ assert_equal [mixins(:list_1, :reload),
142
+ mixins(:list_3, :reload),
143
+ mixins(:list_4, :reload)],
144
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
145
145
 
146
- assert_equal 1, @mixins['list_1'].find.pos
147
- assert_equal 2, @mixins['list_3'].find.pos
148
- assert_equal 3, @mixins['list_4'].find.pos
146
+ assert_equal 1, mixins(:list_1).pos
147
+ assert_equal 2, mixins(:list_3).pos
148
+ assert_equal 3, mixins(:list_4).pos
149
149
 
150
- @mixins['list_1'].find.destroy
150
+ mixins(:list_1).destroy
151
151
 
152
- assert_equal [@mixins['list_3'].find,
153
- @mixins['list_4'].find],
154
- ListMixin.find_all("parent_id=5", "pos")
152
+ assert_equal [mixins(:list_3, :reload),
153
+ mixins(:list_4, :reload)],
154
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
155
155
 
156
- assert_equal 1, @mixins['list_3'].find.pos
157
- assert_equal 2, @mixins['list_4'].find.pos
156
+ assert_equal 1, mixins(:list_3).pos
157
+ assert_equal 2, mixins(:list_4).pos
158
158
 
159
159
  end
160
160
 
@@ -168,7 +168,7 @@ class ListTest < Test::Unit::TestCase
168
168
  def test_nil_scope
169
169
  new1, new2, new3 = ListMixin.create, ListMixin.create, ListMixin.create
170
170
  new2.move_higher
171
- assert_equal [new2, new1, new3], ListMixin.find_all("parent_id IS NULL", "pos")
171
+ assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos')
172
172
  end
173
173
  end
174
174
 
@@ -176,42 +176,42 @@ class TreeTest < Test::Unit::TestCase
176
176
  fixtures :mixins
177
177
 
178
178
  def test_has_child
179
- assert_equal true, @tree_1.has_children?
180
- assert_equal true, @tree_2.has_children?
181
- assert_equal false, @tree_3.has_children?
182
- assert_equal false, @tree_4.has_children?
179
+ assert_equal true, mixins(:tree_1).has_children?
180
+ assert_equal true, mixins(:tree_2).has_children?
181
+ assert_equal false, mixins(:tree_3).has_children?
182
+ assert_equal false, mixins(:tree_4).has_children?
183
183
  end
184
184
 
185
185
  def test_children
186
- assert_equal @tree_1.children, [@tree_2, @tree_4]
187
- assert_equal @tree_2.children, [@tree_3]
188
- assert_equal @tree_3.children, []
189
- assert_equal @tree_4.children, []
186
+ assert_equal mixins(:tree_1).children, [mixins(:tree_2), mixins(:tree_4)]
187
+ assert_equal mixins(:tree_2).children, [mixins(:tree_3)]
188
+ assert_equal mixins(:tree_3).children, []
189
+ assert_equal mixins(:tree_4).children, []
190
190
  end
191
191
 
192
192
  def test_parent
193
- assert_equal @tree_2.parent, @tree_1
194
- assert_equal @tree_2.parent, @tree_4.parent
195
- assert_nil @tree_1.parent
193
+ assert_equal mixins(:tree_2).parent, mixins(:tree_1)
194
+ assert_equal mixins(:tree_2).parent, mixins(:tree_4).parent
195
+ assert_nil mixins(:tree_1).parent
196
196
  end
197
197
 
198
198
  def test_delete
199
199
  assert_equal 4, TreeMixin.count
200
- @tree_1.destroy
200
+ mixins(:tree_1).destroy
201
201
  assert_equal 0, TreeMixin.count
202
202
  end
203
203
 
204
204
  def test_insert
205
- @extra = @tree_1.children.create
205
+ @extra = mixins(:tree_1).children.create
206
206
 
207
207
  assert @extra
208
208
 
209
- assert_equal @extra.parent, @tree_1
209
+ assert_equal @extra.parent, mixins(:tree_1)
210
210
 
211
- assert_equal 3, @tree_1.children.size
212
- assert @tree_1.children.include?(@extra)
213
- assert @tree_1.children.include?(@tree_2)
214
- assert @tree_1.children.include?(@tree_4)
211
+ assert_equal 3, mixins(:tree_1).children.size
212
+ assert mixins(:tree_1).children.include?(@extra)
213
+ assert mixins(:tree_1).children.include?(mixins(:tree_2))
214
+ assert mixins(:tree_1).children.include?(mixins(:tree_4))
215
215
  end
216
216
 
217
217
  end
@@ -258,9 +258,9 @@ class TouchTest < Test::Unit::TestCase
258
258
  def test_create_turned_off
259
259
  Mixin.record_timestamps = false
260
260
 
261
- assert_nil @tree_1.updated_at
262
- @tree_1.save
263
- assert_nil @tree_1.updated_at
261
+ assert_nil mixins(:tree_1).updated_at
262
+ mixins(:tree_1).save
263
+ assert_nil mixins(:tree_1).updated_at
264
264
 
265
265
  Mixin.record_timestamps = true
266
266
  end