activerecord 1.2.0 → 1.3.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.
- data/CHANGELOG +65 -0
- data/install.rb +2 -2
- data/lib/active_record.rb +1 -1
- data/lib/active_record/acts/list.rb +13 -13
- data/lib/active_record/associations.rb +38 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_association.rb +2 -1
- data/lib/active_record/base.rb +44 -20
- data/lib/active_record/connection_adapters/abstract_adapter.rb +10 -11
- data/lib/active_record/connection_adapters/mysql_adapter.rb +6 -2
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +7 -2
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +10 -2
- data/lib/active_record/fixtures.rb +18 -0
- data/lib/active_record/support/binding_of_caller.rb +81 -0
- data/lib/active_record/support/breakpoint.rb +525 -0
- data/lib/active_record/timestamp.rb +17 -5
- data/lib/active_record/transactions.rb +11 -13
- data/lib/active_record/validations.rb +31 -13
- data/rakefile +1 -1
- data/test/abstract_unit.rb +2 -0
- data/test/base_test.rb +29 -9
- data/test/fixtures/db_definitions/mysql.sql +5 -3
- data/test/fixtures/db_definitions/postgresql.sql +2 -0
- data/test/fixtures/db_definitions/sqlite.sql +3 -1
- data/test/fixtures/db_definitions/sqlserver.sql +2 -0
- data/test/fixtures/developer.rb +2 -4
- data/test/fixtures/developers.yml +3 -0
- data/test/fixtures/fixture_database.sqlite +0 -0
- data/test/fixtures/fixture_database_2.sqlite +0 -0
- data/test/fixtures/mixin.rb +5 -2
- data/test/fixtures/mixins.yml +27 -11
- data/test/mixin_test.rb +154 -56
- data/test/transactions_test.rb +1 -1
- data/test/validations_test.rb +50 -3
- metadata +4 -2
data/test/mixin_test.rb
CHANGED
@@ -3,72 +3,136 @@ require 'active_record/acts/tree'
|
|
3
3
|
require 'active_record/acts/list'
|
4
4
|
require 'fixtures/mixin'
|
5
5
|
|
6
|
-
|
7
6
|
class ListTest < Test::Unit::TestCase
|
8
7
|
fixtures :mixins
|
9
8
|
|
10
|
-
def test_injection
|
11
|
-
l = ListMixin.new("parent_id"=>1)
|
12
|
-
assert_equal "parent_id = 1", l.scope_condition
|
13
|
-
assert_equal "pos", l.position_column
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
9
|
def test_reordering
|
18
10
|
|
19
|
-
assert_equal [
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
assert_equal [@mixins['list_1'].find,
|
12
|
+
@mixins['list_2'].find,
|
13
|
+
@mixins['list_3'].find,
|
14
|
+
@mixins['list_4'].find],
|
15
|
+
ListMixin.find_all("parent_id=5", "pos")
|
16
|
+
|
17
|
+
@mixins['list_2'].find.move_lower
|
18
|
+
|
19
|
+
assert_equal [@mixins['list_1'].find,
|
20
|
+
@mixins['list_3'].find,
|
21
|
+
@mixins['list_2'].find,
|
22
|
+
@mixins['list_4'].find],
|
23
|
+
ListMixin.find_all("parent_id=5", "pos")
|
24
|
+
|
25
|
+
@mixins['list_2'].find.move_higher
|
26
26
|
|
27
|
-
assert_equal [
|
27
|
+
assert_equal [@mixins['list_1'].find,
|
28
|
+
@mixins['list_2'].find,
|
29
|
+
@mixins['list_3'].find,
|
30
|
+
@mixins['list_4'].find],
|
31
|
+
ListMixin.find_all("parent_id=5", "pos")
|
28
32
|
|
29
|
-
|
33
|
+
@mixins['list_1'].find.move_to_bottom
|
34
|
+
|
35
|
+
assert_equal [@mixins['list_2'].find,
|
36
|
+
@mixins['list_3'].find,
|
37
|
+
@mixins['list_4'].find,
|
38
|
+
@mixins['list_1'].find],
|
39
|
+
ListMixin.find_all("parent_id=5", "pos")
|
40
|
+
|
41
|
+
@mixins['list_1'].find.move_to_top
|
30
42
|
|
43
|
+
assert_equal [@mixins['list_1'].find,
|
44
|
+
@mixins['list_2'].find,
|
45
|
+
@mixins['list_3'].find,
|
46
|
+
@mixins['list_4'].find],
|
47
|
+
ListMixin.find_all("parent_id=5", "pos")
|
48
|
+
|
49
|
+
|
50
|
+
@mixins['list_2'].find.move_to_bottom
|
51
|
+
|
52
|
+
assert_equal [@mixins['list_1'].find,
|
53
|
+
@mixins['list_3'].find,
|
54
|
+
@mixins['list_4'].find,
|
55
|
+
@mixins['list_2'].find],
|
56
|
+
ListMixin.find_all("parent_id=5", "pos")
|
57
|
+
|
58
|
+
@mixins['list_4'].find.move_to_top
|
59
|
+
|
60
|
+
assert_equal [@mixins['list_4'].find,
|
61
|
+
@mixins['list_1'].find,
|
62
|
+
@mixins['list_3'].find,
|
63
|
+
@mixins['list_2'].find],
|
64
|
+
ListMixin.find_all("parent_id=5", "pos")
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_next_prev
|
69
|
+
assert_equal @list_2, @list_1.lower_item
|
70
|
+
assert_nil @list_1.higher_item
|
71
|
+
assert_equal @list_3, @list_4.higher_item
|
72
|
+
assert_nil @list_4.lower_item
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def test_injection
|
77
|
+
item = ListMixin.new("parent_id"=>1)
|
78
|
+
assert_equal "parent_id = 1", item.scope_condition
|
79
|
+
assert_equal "pos", item.position_column
|
80
|
+
end
|
81
|
+
|
31
82
|
def test_insert
|
32
|
-
new = ListMixin.create("parent_id"=>
|
83
|
+
new = ListMixin.create("parent_id"=>20)
|
33
84
|
assert_equal 1, new.pos
|
34
85
|
assert new.first?
|
35
86
|
assert new.last?
|
36
87
|
|
37
|
-
new = ListMixin.create("parent_id"=>
|
88
|
+
new = ListMixin.create("parent_id"=>20)
|
38
89
|
assert_equal 2, new.pos
|
39
90
|
assert !new.first?
|
40
91
|
assert new.last?
|
41
92
|
|
42
|
-
new = ListMixin.create("parent_id"=>
|
93
|
+
new = ListMixin.create("parent_id"=>20)
|
43
94
|
assert_equal 3, new.pos
|
44
95
|
assert !new.first?
|
45
96
|
assert new.last?
|
46
97
|
|
47
|
-
new = ListMixin.create("parent_id"=>
|
98
|
+
new = ListMixin.create("parent_id"=>0)
|
48
99
|
assert_equal 1, new.pos
|
49
100
|
assert new.first?
|
50
101
|
assert new.last?
|
51
102
|
end
|
52
103
|
|
53
104
|
def test_delete_middle
|
54
|
-
first = ListMixin.create("parent_id"=>5)
|
55
|
-
assert_equal 1, first.pos
|
56
|
-
|
57
|
-
second = ListMixin.create("parent_id"=>5)
|
58
|
-
assert_equal 2, second.pos
|
59
|
-
|
60
|
-
third = ListMixin.create("parent_id"=>5)
|
61
|
-
assert_equal 3, third.pos
|
62
105
|
|
63
|
-
|
106
|
+
assert_equal [@mixins['list_1'].find,
|
107
|
+
@mixins['list_2'].find,
|
108
|
+
@mixins['list_3'].find,
|
109
|
+
@mixins['list_4'].find],
|
110
|
+
ListMixin.find_all("parent_id=5", "pos")
|
111
|
+
|
112
|
+
@mixins['list_2'].find.destroy
|
64
113
|
|
65
|
-
assert_equal
|
66
|
-
|
114
|
+
assert_equal [@mixins['list_1'].find,
|
115
|
+
@mixins['list_3'].find,
|
116
|
+
@mixins['list_4'].find],
|
117
|
+
ListMixin.find_all("parent_id=5", "pos")
|
118
|
+
|
119
|
+
assert_equal 1, @mixins['list_1'].find.pos
|
120
|
+
assert_equal 2, @mixins['list_3'].find.pos
|
121
|
+
assert_equal 3, @mixins['list_4'].find.pos
|
122
|
+
|
123
|
+
@mixins['list_1'].find.destroy
|
124
|
+
|
125
|
+
assert_equal [@mixins['list_3'].find,
|
126
|
+
@mixins['list_4'].find],
|
127
|
+
ListMixin.find_all("parent_id=5", "pos")
|
128
|
+
|
129
|
+
assert_equal 1, @mixins['list_3'].find.pos
|
130
|
+
assert_equal 2, @mixins['list_4'].find.pos
|
67
131
|
|
68
132
|
end
|
69
133
|
|
70
134
|
def test_with_string_based_scope
|
71
|
-
new = ListWithStringScopeMixin.create("parent_id"=>
|
135
|
+
new = ListWithStringScopeMixin.create("parent_id"=>500)
|
72
136
|
assert_equal 1, new.pos
|
73
137
|
assert new.first?
|
74
138
|
assert new.last?
|
@@ -79,59 +143,93 @@ class TreeTest < Test::Unit::TestCase
|
|
79
143
|
fixtures :mixins
|
80
144
|
|
81
145
|
def test_has_child
|
82
|
-
assert_equal true, @
|
83
|
-
assert_equal
|
84
|
-
assert_equal false, @
|
146
|
+
assert_equal true, @tree_1.has_children?
|
147
|
+
assert_equal true, @tree_2.has_children?
|
148
|
+
assert_equal false, @tree_3.has_children?
|
149
|
+
assert_equal false, @tree_4.has_children?
|
85
150
|
end
|
86
151
|
|
87
152
|
def test_children
|
88
|
-
assert_equal @
|
89
|
-
assert_equal @
|
153
|
+
assert_equal @tree_1.children, [@tree_2, @tree_4]
|
154
|
+
assert_equal @tree_2.children, [@tree_3]
|
155
|
+
assert_equal @tree_3.children, []
|
156
|
+
assert_equal @tree_4.children, []
|
90
157
|
end
|
91
158
|
|
92
159
|
def test_parent
|
93
|
-
assert_equal @
|
94
|
-
assert_equal @
|
95
|
-
assert_nil @
|
160
|
+
assert_equal @tree_2.parent, @tree_1
|
161
|
+
assert_equal @tree_2.parent, @tree_4.parent
|
162
|
+
assert_nil @tree_1.parent
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_delete
|
166
|
+
assert_equal 4, TreeMixin.count
|
167
|
+
@tree_1.destroy
|
168
|
+
assert_equal 0, TreeMixin.count
|
96
169
|
end
|
97
170
|
|
98
171
|
def test_insert
|
99
|
-
@extra = @
|
172
|
+
@extra = @tree_1.children.create
|
100
173
|
|
101
174
|
assert @extra
|
102
175
|
|
103
|
-
assert_equal @extra.parent, @
|
104
|
-
|
176
|
+
assert_equal @extra.parent, @tree_1
|
177
|
+
|
178
|
+
assert_equal 3, @tree_1.children.size
|
179
|
+
assert @tree_1.children.include?(@extra)
|
180
|
+
assert @tree_1.children.include?(@tree_2)
|
181
|
+
assert @tree_1.children.include?(@tree_4)
|
105
182
|
end
|
106
183
|
|
107
|
-
|
108
|
-
assert_equal 3, Mixin.count
|
109
|
-
@first.destroy
|
110
|
-
assert_equal 0, Mixin.count
|
111
|
-
end
|
184
|
+
|
112
185
|
end
|
113
186
|
|
114
187
|
class TouchTest < Test::Unit::TestCase
|
115
188
|
fixtures :mixins
|
116
189
|
|
117
190
|
def test_update
|
118
|
-
|
119
|
-
|
120
|
-
|
191
|
+
|
192
|
+
stamped = Mixin.new
|
193
|
+
|
194
|
+
assert_nil stamped.updated_at
|
195
|
+
assert_nil stamped.created_at
|
196
|
+
stamped.save
|
197
|
+
assert_not_nil stamped.updated_at
|
198
|
+
assert_not_nil stamped.created_at
|
121
199
|
end
|
122
200
|
|
123
201
|
def test_create
|
124
|
-
@obj = Mixin.create
|
202
|
+
@obj = Mixin.create
|
125
203
|
assert_not_nil @obj.updated_at
|
126
204
|
assert_not_nil @obj.created_at
|
127
205
|
end
|
206
|
+
|
207
|
+
def test_many_updates
|
208
|
+
|
209
|
+
stamped = Mixin.new
|
210
|
+
|
211
|
+
assert_nil stamped.updated_at
|
212
|
+
assert_nil stamped.created_at
|
213
|
+
stamped.save
|
214
|
+
assert_not_nil stamped.created_at
|
215
|
+
assert_not_nil stamped.updated_at
|
216
|
+
|
217
|
+
old_updated_at = stamped.updated_at
|
218
|
+
|
219
|
+
sleep 1
|
220
|
+
stamped.save
|
221
|
+
assert_not_equal stamped.created_at, stamped.updated_at
|
222
|
+
assert_not_equal old_updated_at, stamped.updated_at
|
223
|
+
|
224
|
+
end
|
225
|
+
|
128
226
|
|
129
227
|
def test_create_turned_off
|
130
228
|
Mixin.record_timestamps = false
|
131
229
|
|
132
|
-
assert_nil @
|
133
|
-
@
|
134
|
-
assert_nil @
|
230
|
+
assert_nil @tree_1.updated_at
|
231
|
+
@tree_1.save
|
232
|
+
assert_nil @tree_1.updated_at
|
135
233
|
|
136
234
|
Mixin.record_timestamps = true
|
137
235
|
end
|
data/test/transactions_test.rb
CHANGED
data/test/validations_test.rb
CHANGED
@@ -125,20 +125,34 @@ class ValidationsTest < Test::Unit::TestCase
|
|
125
125
|
assert developer.save
|
126
126
|
end
|
127
127
|
|
128
|
+
def test_title_confirmation_no_confirm
|
129
|
+
Topic.validates_confirmation_of(:title)
|
130
|
+
|
131
|
+
t = Topic.create("title" => "We should not be confirmed")
|
132
|
+
assert t.save
|
133
|
+
end
|
134
|
+
|
128
135
|
def test_title_confirmation
|
129
136
|
Topic.validates_confirmation_of(:title)
|
130
137
|
|
131
|
-
t = Topic.create("title" => "We should be confirmed")
|
138
|
+
t = Topic.create("title" => "We should be confirmed","title_confirmation" => "")
|
132
139
|
assert !t.save
|
133
140
|
|
134
141
|
t.title_confirmation = "We should be confirmed"
|
135
142
|
assert t.save
|
136
143
|
end
|
137
144
|
|
145
|
+
def test_terms_of_service_agreement_no_acceptance
|
146
|
+
Topic.validates_acceptance_of(:terms_of_service, :on => :create)
|
147
|
+
|
148
|
+
t = Topic.create("title" => "We should not be confirmed")
|
149
|
+
assert t.save
|
150
|
+
end
|
151
|
+
|
138
152
|
def test_terms_of_service_agreement
|
139
153
|
Topic.validates_acceptance_of(:terms_of_service, :on => :create)
|
140
154
|
|
141
|
-
t = Topic.create("title" => "We should be confirmed")
|
155
|
+
t = Topic.create("title" => "We should be confirmed","terms_of_service" => "")
|
142
156
|
assert !t.save
|
143
157
|
assert_equal "must be accepted", t.errors.on(:terms_of_service)
|
144
158
|
|
@@ -150,7 +164,7 @@ class ValidationsTest < Test::Unit::TestCase
|
|
150
164
|
def test_eula
|
151
165
|
Topic.validates_acceptance_of(:eula, :message => "must be abided", :on => :create)
|
152
166
|
|
153
|
-
t = Topic.create("title" => "We should be confirmed")
|
167
|
+
t = Topic.create("title" => "We should be confirmed","eula" => "")
|
154
168
|
assert !t.save
|
155
169
|
assert_equal "must be abided", t.errors.on(:eula)
|
156
170
|
|
@@ -190,6 +204,25 @@ class ValidationsTest < Test::Unit::TestCase
|
|
190
204
|
assert t2.save, "Should now save t2 as unique"
|
191
205
|
end
|
192
206
|
|
207
|
+
def test_validate_uniqueness_with_scope
|
208
|
+
Reply.validates_uniqueness_of(:content, :scope => "parent_id")
|
209
|
+
|
210
|
+
t = Topic.create("title" => "I'm unique!")
|
211
|
+
|
212
|
+
r1 = t.replies.create "title" => "r1", "content" => "hello world"
|
213
|
+
assert r1.valid?, "Saving r1"
|
214
|
+
|
215
|
+
r2 = t.replies.create "title" => "r2", "content" => "hello world"
|
216
|
+
assert !r2.valid?, "Saving r2 first time"
|
217
|
+
|
218
|
+
r2.content = "something else"
|
219
|
+
assert r2.save, "Saving r2 second time"
|
220
|
+
|
221
|
+
t2 = Topic.create("title" => "I'm unique too!")
|
222
|
+
r3 = t2.replies.create "title" => "r3", "content" => "hello world"
|
223
|
+
assert r3.valid?, "Saving r3"
|
224
|
+
end
|
225
|
+
|
193
226
|
def test_validate_format
|
194
227
|
Topic.validates_format_of(:title, :content, :with => /^Validation macros rule!$/, :message => "is bad data")
|
195
228
|
|
@@ -230,6 +263,14 @@ class ValidationsTest < Test::Unit::TestCase
|
|
230
263
|
assert_nothing_raised(ArgumentError) { Topic.validates_inclusion_of( :title, :in => [] ) }
|
231
264
|
end
|
232
265
|
|
266
|
+
def test_validates_inclusion_of_with_allow_nil
|
267
|
+
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :allow_nil=>true )
|
268
|
+
|
269
|
+
assert !Topic.create("title" => "a!", "content" => "abc").valid?
|
270
|
+
assert !Topic.create("title" => "", "content" => "abc").valid?
|
271
|
+
assert Topic.create("title" => nil, "content" => "abc").valid?
|
272
|
+
end
|
273
|
+
|
233
274
|
def test_validates_length_of_using_minimum
|
234
275
|
Topic.validates_length_of( :title, :minimum=>5 )
|
235
276
|
t = Topic.create("title" => "valid", "content" => "whatever")
|
@@ -348,4 +389,10 @@ class ValidationsTest < Test::Unit::TestCase
|
|
348
389
|
assert_equal "hoo 5", t.errors["title"]
|
349
390
|
end
|
350
391
|
|
392
|
+
def test_throw_away_typing
|
393
|
+
d = Developer.create "name" => "David", "salary" => "100,000"
|
394
|
+
assert !d.valid?
|
395
|
+
assert_equal 100, d.salary
|
396
|
+
assert_equal "100,000", d.salary_before_type_cast
|
397
|
+
end
|
351
398
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activerecord
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2004-12-
|
6
|
+
version: 1.3.0
|
7
|
+
date: 2004-12-23
|
8
8
|
summary: Implements the ActiveRecord pattern for ORM.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -61,6 +61,8 @@ files:
|
|
61
61
|
- lib/active_record/connection_adapters/postgresql_adapter.rb
|
62
62
|
- lib/active_record/connection_adapters/sqlite_adapter.rb
|
63
63
|
- lib/active_record/connection_adapters/sqlserver_adapter.rb
|
64
|
+
- lib/active_record/support/binding_of_caller.rb
|
65
|
+
- lib/active_record/support/breakpoint.rb
|
64
66
|
- lib/active_record/support/class_attribute_accessors.rb
|
65
67
|
- lib/active_record/support/class_inheritable_attributes.rb
|
66
68
|
- lib/active_record/support/clean_logger.rb
|