From: Dmitriy Zaporozhets Date: Thu, 10 Nov 2011 07:46:04 +0000 (+0200) Subject: notes should depends on user when destroy X-Git-Tag: v1.2.0pre~70 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9a5f328313a85142af669b6745825e3e2c7b3005;p=wvm%2Fgitlab.git notes should depends on user when destroy --- diff --git a/app/models/user.rb b/app/models/user.rb index c90cf49f6..1d41028d5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,10 @@ class User < ActiveRecord::Base :foreign_key => :author_id, :dependent => :destroy + has_many :notes, + :foreign_key => :author_id, + :dependent => :destroy + has_many :assigned_issues, :class_name => "Issue", :foreign_key => :assignee_id, diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d66b1c251..14d48114c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -18,6 +18,21 @@ describe User do user = User.new(:email => "test@mail.com") user.identifier.should == "test_mail.com" end + + describe "dependent" do + before do + @user = Factory :user + @note = Factory :note, + :author => @user, + :project => Factory(:project) + end + + it "should destroy all notes with user" do + Note.find_by_id(@note.id).should_not be_nil + @user.destroy + Note.find_by_id(@note.id).should be_nil + end + end end # == Schema Information #