diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/schema.rb | 5 | ||||
-rw-r--r-- | activerecord/test/fixtures/developer.rb | 10 |
3 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 37e26ef80a..9e4d0f2711 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -101,6 +101,10 @@ class AssociationProxyTest < Test::Unit::TestCase assert !david.projects.loaded? end + def test_save_on_parent_saves_children + developer = Developer.create :name => "Bryan", :salary => 50_000 + assert_equal 1, developer.reload.audit_logs.size + end end class HasOneAssociationsTest < Test::Unit::TestCase diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb index cdebcbbe5f..52cd9f36f0 100644 --- a/activerecord/test/fixtures/db_definitions/schema.rb +++ b/activerecord/test/fixtures/db_definitions/schema.rb @@ -75,4 +75,9 @@ ActiveRecord::Schema.define do t.column :real_number, :real end end + + create_table :audit_logs, :force => true do |t| + t.column :message, :string, :null=>false + t.column :developer_id, :integer, :null=>false + end end diff --git a/activerecord/test/fixtures/developer.rb b/activerecord/test/fixtures/developer.rb index c868cddecd..20005ed04e 100644 --- a/activerecord/test/fixtures/developer.rb +++ b/activerecord/test/fixtures/developer.rb @@ -41,8 +41,18 @@ class Developer < ActiveRecord::Base has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id' + has_many :audit_logs + validates_inclusion_of :salary, :in => 50000..200000 validates_length_of :name, :within => 3..20 + + before_create do |developer| + developer.audit_logs.build :message => "Computer created" + end +end + +class AuditLog < ActiveRecord::Base + belongs_to :developer end DeveloperSalary = Struct.new(:amount) |