activerecord 1.5.1 → 1.6.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.

@@ -115,6 +115,19 @@ class BasicsTest < Test::Unit::TestCase
115
115
  assert_equal("New Topic", topicReloaded.title)
116
116
  end
117
117
 
118
+ def test_create_many
119
+ topics = Topic.create([ { "title" => "first" }, { "title" => "second" }])
120
+ assert_equal 2, topics.size
121
+ assert_equal "first", topics.first.title
122
+ end
123
+
124
+ def test_create_columns_not_equal_attributes
125
+ topic = Topic.new
126
+ topic.title = 'Another New Topic'
127
+ topic.send :write_attribute, 'does_not_exist', 'test'
128
+ assert_nothing_raised { topic.save }
129
+ end
130
+
118
131
  def test_create_through_factory
119
132
  topic = Topic.create("title" => "New Topic")
120
133
  topicReloaded = Topic.find(topic.id)
@@ -140,6 +153,18 @@ class BasicsTest < Test::Unit::TestCase
140
153
  assert_equal("Updated topic", topicReloadedAgain.title)
141
154
  end
142
155
 
156
+ def test_update_columns_not_equal_attributes
157
+ topic = Topic.new
158
+ topic.title = "Still another topic"
159
+ topic.save
160
+ id = topic.id
161
+
162
+ topicReloaded = Topic.find(id)
163
+ topicReloaded.title = "A New Topic"
164
+ topicReloaded.send :write_attribute, 'does_not_exist', 'test'
165
+ assert_nothing_raised { topicReloaded.save }
166
+ end
167
+
143
168
  def test_preserving_date_objects
144
169
  # SQL Server doesn't have a separate column type just for dates, so all are returned as time
145
170
  if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
@@ -237,12 +262,22 @@ class BasicsTest < Test::Unit::TestCase
237
262
  end
238
263
 
239
264
  def test_destroy_all
240
- assert_equal(2, Topic.find_all.size)
265
+ assert_equal 2, Topic.find_all.size
241
266
 
242
267
  Topic.destroy_all "author_name = 'Mary'"
243
- assert_equal(1, Topic.find_all.size)
268
+ assert_equal 1, Topic.find_all.size
244
269
  end
245
-
270
+
271
+ def test_destroy_many
272
+ Client.destroy([2, 3])
273
+ assert_equal 0, Client.count
274
+ end
275
+
276
+ def test_delete_many
277
+ Topic.delete([1, 2])
278
+ assert_equal 0, Topic.count
279
+ end
280
+
246
281
  def test_boolean_attributes
247
282
  assert ! Topic.find(1).approved?
248
283
  assert Topic.find(2).approved?
@@ -268,6 +303,18 @@ class BasicsTest < Test::Unit::TestCase
268
303
  assert_equal 2, Topic.update_all("content = 'bulk updated!'")
269
304
  assert_equal "bulk updated!", Topic.find(1).content
270
305
  assert_equal "bulk updated!", Topic.find(2).content
306
+ assert_equal 2, Topic.update_all(['content = ?', 'bulk updated again!']);
307
+ assert_equal "bulk updated again!", Topic.find(1).content
308
+ assert_equal "bulk updated again!", Topic.find(2).content
309
+ end
310
+
311
+ def test_update_many
312
+ topic_data = { "1" => { "content" => "1 updated" }, "2" => { "content" => "2 updated" } }
313
+ updated = Topic.update(topic_data.keys, topic_data.values)
314
+
315
+ assert_equal 2, updated.size
316
+ assert_equal "1 updated", Topic.find(1).content
317
+ assert_equal "2 updated", Topic.find(2).content
271
318
  end
272
319
 
273
320
  def test_delete_all
@@ -383,6 +430,13 @@ class BasicsTest < Test::Unit::TestCase
383
430
  assert_equal 1, firm.rating
384
431
  end
385
432
 
433
+ def test_mass_assignment_protection_on_defaults
434
+ firm = Firm.new
435
+ firm.attributes = { "id" => 5, "type" => "Client" }
436
+ assert_nil firm.id
437
+ assert_equal "Firm", firm[:type]
438
+ end
439
+
386
440
  def test_mass_assignment_accessible
387
441
  reply = Reply.new("title" => "hello", "content" => "world", "approved" => 0)
388
442
  reply.save
@@ -0,0 +1,12 @@
1
+ require 'abstract_unit'
2
+ require 'fixtures/topic'
3
+
4
+ class TestColumnAlias < Test::Unit::TestCase
5
+
6
+ def test_column_alias
7
+ topic = Topic.find(1)
8
+ records = topic.connection.select_all("SELECT id AS pk FROM topics LIMIT 1")
9
+ assert_equal(records[0].keys[0], "pk")
10
+ end
11
+
12
+ end
@@ -146,7 +146,15 @@ class FinderTest < Test::Unit::TestCase
146
146
  assert_nothing_raised { bind ':a :a', :a => 1 } # ' ruby-mode
147
147
  assert_raises(ActiveRecord::PreparedStatementInvalid) { bind ':a :a', :a => 1, :b => 2 } # ' ruby-mode
148
148
  end
149
-
149
+
150
+ def test_bind_array
151
+ assert_equal '1,2,3', bind('?', [1, 2, 3])
152
+ assert_equal %('a','b','c'), bind('?', %w(a b c))
153
+
154
+ assert_equal '1,2,3', bind(':a', :a => [1, 2, 3])
155
+ assert_equal %('a','b','c'), bind(':a', :a => %w(a b c))
156
+ end
157
+
150
158
  def test_string_sanitation
151
159
  assert_not_equal "'something ' 1=1'", ActiveRecord::Base.sanitize("something ' 1=1")
152
160
  assert_equal "'something; select table'", ActiveRecord::Base.sanitize("something; select table")
@@ -185,6 +193,29 @@ class FinderTest < Test::Unit::TestCase
185
193
 
186
194
  assert_equal [], Topic.find_all_by_title("The First Topic!!")
187
195
  end
196
+
197
+ def test_find_by_nil_attribute
198
+ topic = Topic.find_by_last_read nil
199
+ assert_not_nil topic
200
+ assert_nil topic.last_read
201
+ end
202
+
203
+ def test_find_all_by_nil_attribute
204
+ topics = Topic.find_all_by_last_read nil
205
+ assert_equal 1, topics.size
206
+ assert_nil topics[0].last_read
207
+ end
208
+
209
+ def test_find_by_nil_and_not_nil_attributes
210
+ topic = Topic.find_by_last_read_and_author_name nil, "Mary"
211
+ assert_equal "Mary", topic.author_name
212
+ end
213
+
214
+ def test_find_all_by_nil_and_not_nil_attributes
215
+ topics = Topic.find_all_by_last_read_and_author_name nil, "Mary"
216
+ assert_equal 1, topics.size
217
+ assert_equal "Mary", topics[0].author_name
218
+ end
188
219
 
189
220
  protected
190
221
  def bind(statement, *vars)
@@ -12,10 +12,10 @@ class Firm < Company
12
12
  has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
13
13
  has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
14
14
  has_many :clients_using_counter_sql, :class_name => "Client",
15
- :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
15
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
16
16
  :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
17
17
  has_many :clients_using_zero_counter_sql, :class_name => "Client",
18
- :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
18
+ :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
19
19
  :counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
20
20
 
21
21
  has_one :account, :dependent => true
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.4
3
3
  specification_version: 1
4
4
  name: activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.5.1
7
- date: 2005-01-18
6
+ version: 1.6.0
7
+ date: 2005-01-25
8
8
  summary: Implements the ActiveRecord pattern for ORM.
9
9
  require_paths:
10
10
  - lib
@@ -84,6 +84,7 @@ files:
84
84
  - lib/active_record/support/core_ext/hash.rb
85
85
  - lib/active_record/support/core_ext/numeric
86
86
  - lib/active_record/support/core_ext/numeric.rb
87
+ - lib/active_record/support/core_ext/object_and_class.rb
87
88
  - lib/active_record/support/core_ext/string
88
89
  - lib/active_record/support/core_ext/string.rb
89
90
  - lib/active_record/support/core_ext/hash/keys.rb
@@ -98,11 +99,13 @@ files:
98
99
  - test/abstract_unit.rb
99
100
  - test/aggregations_test.rb
100
101
  - test/all.sh
102
+ - test/association_inheritance_reload.rb
101
103
  - test/associations_test.rb
102
104
  - test/base_test.rb
103
105
  - test/binary_test.rb
104
106
  - test/callbacks_test.rb
105
107
  - test/class_inheritable_attributes_test.rb
108
+ - test/column_alias_test.rb
106
109
  - test/connections
107
110
  - test/deprecated_associations_test.rb
108
111
  - test/finder_test.rb