activerecord 1.15.4 → 1.15.5

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 CHANGED
@@ -1,3 +1,8 @@
1
+ *1.15.5* (October 12th, 2007)
2
+
3
+ * Depend on Action Pack 1.4.4
4
+
5
+
1
6
  *1.15.4* (October 4th, 2007)
2
7
 
3
8
  * Fix #count on a has_many :through association so that it recognizes the :uniq option. Closes #8801 [lifofifo]
data/Rakefile CHANGED
@@ -151,7 +151,7 @@ spec = Gem::Specification.new do |s|
151
151
  s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
152
152
  end
153
153
 
154
- s.add_dependency('activesupport', '= 1.4.3' + PKG_BUILD)
154
+ s.add_dependency('activesupport', '= 1.4.4' + PKG_BUILD)
155
155
 
156
156
  s.files.delete "test/fixtures/fixture_database.sqlite"
157
157
  s.files.delete "test/fixtures/fixture_database_2.sqlite"
@@ -63,7 +63,7 @@ module ActiveRecord
63
63
 
64
64
  #{scope_condition_method}
65
65
 
66
- after_destroy :remove_from_list
66
+ before_destroy :remove_from_list
67
67
  before_create :add_to_list_bottom
68
68
  EOV
69
69
  end
@@ -121,7 +121,10 @@ module ActiveRecord
121
121
 
122
122
  # Removes the item from the list.
123
123
  def remove_from_list
124
- decrement_positions_on_lower_items if in_list?
124
+ if in_list?
125
+ decrement_positions_on_lower_items
126
+ update_attribute position_column, nil
127
+ end
125
128
  end
126
129
 
127
130
  # Increase the position of this item without adjusting the rest of the list.
@@ -994,12 +994,15 @@ module ActiveRecord
994
994
  after_callback = <<-end_eval
995
995
  association = instance_variable_get("@#{association_name}")
996
996
 
997
- if association.respond_to?(:loaded?) && association.loaded?
998
- if @new_record_before_save
999
- records_to_save = association
1000
- else
1001
- records_to_save = association.select { |record| record.new_record? }
1002
- end
997
+ records_to_save = if @new_record_before_save
998
+ association
999
+ elsif association.respond_to?(:loaded?) && association.loaded?
1000
+ association.select { |record| record.new_record? }
1001
+ else
1002
+ []
1003
+ end
1004
+
1005
+ if !records_to_save.blank?
1003
1006
  records_to_save.each { |record| association.send(:insert_record, record) }
1004
1007
  association.send(:construct_sql) # reconstruct the SQL queries now that we know the owner's id
1005
1008
  end
@@ -91,7 +91,11 @@ module ActiveRecord
91
91
  attributes.collect { |attr| create(attr) }
92
92
  else
93
93
  record = build(attributes)
94
- record.save unless @owner.new_record?
94
+ if @owner.new_record?
95
+ ActiveSupport::Deprecation.warn("Calling .create on a has_many association without saving its owner will not work in rails 2.0, you probably want .build instead")
96
+ else
97
+ record.save
98
+ end
95
99
  record
96
100
  end
97
101
  end
@@ -2,7 +2,7 @@ module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 15
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -95,6 +95,11 @@ class AssociationProxyTest < Test::Unit::TestCase
95
95
  david.update_attribute(:created_at, Time.now)
96
96
  assert !david.projects.loaded?
97
97
  end
98
+
99
+ def test_save_on_parent_saves_children
100
+ developer = Developer.create :name => "Bryan", :salary => 50_000
101
+ assert_equal 1, developer.reload.audit_logs.size
102
+ end
98
103
  end
99
104
 
100
105
  class HasOneAssociationsTest < Test::Unit::TestCase
@@ -591,6 +596,13 @@ class HasManyAssociationsTest < Test::Unit::TestCase
591
596
  assert_equal 3, first_firm.plain_clients.size
592
597
  end
593
598
 
599
+ def test_regular_create_on_has_many_when_parent_is_new_raises
600
+ assert_deprecated(/.build instead/) do
601
+ firm = Firm.new
602
+ firm.plain_clients.create :name=>"Whoever"
603
+ end
604
+ end
605
+
594
606
  def test_adding_a_mismatch_class
595
607
  assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << nil }
596
608
  assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << 1 }
@@ -57,4 +57,9 @@ ActiveRecord::Schema.define do
57
57
  create_table :lock_without_defaults_cust, :force => true do |t|
58
58
  t.column :custom_lock_version, :integer
59
59
  end
60
+
61
+ create_table :audit_logs, :force => true do |t|
62
+ t.column :message, :string, :null=>false
63
+ t.column :developer_id, :integer, :null=>false
64
+ end
60
65
  end
@@ -31,8 +31,18 @@ class Developer < ActiveRecord::Base
31
31
 
32
32
  has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
33
33
 
34
+ has_many :audit_logs
35
+
34
36
  validates_inclusion_of :salary, :in => 50000..200000
35
37
  validates_length_of :name, :within => 3..20
38
+
39
+ before_create do |developer|
40
+ developer.audit_logs.build :message => "Computer created"
41
+ end
42
+ end
43
+
44
+ class AuditLog < ActiveRecord::Base
45
+ belongs_to :developer
36
46
  end
37
47
 
38
48
  DeveloperSalary = Struct.new(:amount)
@@ -211,6 +211,53 @@ class ListTest < Test::Unit::TestCase
211
211
  assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos')
212
212
  end
213
213
 
214
+ def test_remove_from_list_should_then_fail_in_list?
215
+ assert_equal true, mixins(:list_1).in_list?
216
+ mixins(:list_1).remove_from_list
217
+ assert_equal false, mixins(:list_1).in_list?
218
+ end
219
+
220
+ def test_remove_from_list_should_set_position_to_nil
221
+ assert_equal [mixins(:list_1),
222
+ mixins(:list_2),
223
+ mixins(:list_3),
224
+ mixins(:list_4)],
225
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
226
+
227
+ mixins(:list_2).remove_from_list
228
+
229
+ assert_equal [mixins(:list_2, :reload),
230
+ mixins(:list_1, :reload),
231
+ mixins(:list_3, :reload),
232
+ mixins(:list_4, :reload)],
233
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
234
+
235
+ assert_equal 1, mixins(:list_1).pos
236
+ assert_equal nil, mixins(:list_2).pos
237
+ assert_equal 2, mixins(:list_3).pos
238
+ assert_equal 3, mixins(:list_4).pos
239
+ end
240
+
241
+ def test_remove_before_destroy_does_not_shift_lower_items_twice
242
+ assert_equal [mixins(:list_1),
243
+ mixins(:list_2),
244
+ mixins(:list_3),
245
+ mixins(:list_4)],
246
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
247
+
248
+ mixins(:list_2).remove_from_list
249
+ mixins(:list_2).destroy
250
+
251
+ assert_equal [mixins(:list_1, :reload),
252
+ mixins(:list_3, :reload),
253
+ mixins(:list_4, :reload)],
254
+ ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
255
+
256
+ assert_equal 1, mixins(:list_1).pos
257
+ assert_equal 2, mixins(:list_3).pos
258
+ assert_equal 3, mixins(:list_4).pos
259
+ end
260
+
214
261
  end
215
262
 
216
263
  class TreeTest < Test::Unit::TestCase
@@ -631,7 +631,7 @@ class ValidationsTest < Test::Unit::TestCase
631
631
  t = Topic.new('title' => 'noreplies', 'content' => 'whatever')
632
632
  assert !t.save
633
633
  assert t.errors.on(:replies)
634
- t.replies.create('title' => 'areply', 'content' => 'whateveragain')
634
+ t.replies.build('title' => 'areply', 'content' => 'whateveragain')
635
635
  assert t.valid?
636
636
  end
637
637
 
@@ -824,7 +824,7 @@ class ValidationsTest < Test::Unit::TestCase
824
824
  t = Topic.new('title' => 'あいうえお', 'content' => 'かきくけこ')
825
825
  assert !t.save
826
826
  assert t.errors.on(:replies)
827
- t.replies.create('title' => 'あいうえお', 'content' => 'かきくけこ')
827
+ t.replies.build('title' => 'あいうえお', 'content' => 'かきくけこ')
828
828
  assert t.valid?
829
829
  end
830
830
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.15.4
7
- date: 2007-10-04 00:00:00 -05:00
6
+ version: 1.15.5
7
+ date: 2007-10-12 00:00:00 -05:00
8
8
  summary: Implements the ActiveRecord pattern for ORM.
9
9
  require_paths:
10
10
  - lib
@@ -356,5 +356,5 @@ dependencies:
356
356
  requirements:
357
357
  - - "="
358
358
  - !ruby/object:Gem::Version
359
- version: 1.4.3
359
+ version: 1.4.4
360
360
  version: