Browse files

add links from dishonorable_discharges to user and officer

  • Loading branch information...
1 parent a67f180 commit 8d4aeb699c94a257649a79b6d5567eeccbe51642 @adambaker committed Feb 13, 2012
Showing with 26 additions and 0 deletions.
  1. +7 −0 app/models/dishonorable_discharge.rb
  2. +19 −0 spec/models/dishonorable_discharge_spec.rb
View
7 app/models/dishonorable_discharge.rb
@@ -11,4 +11,11 @@ class DishonorableDischarge < ActiveRecord::Base
end
end
+ after_save do |discharge|
+ discharge.user.discharged = true
+ discharge.user.save
+ end
+
+ belongs_to :user
+ belongs_to :officer, class_name: 'User'
end
View
19 spec/models/dishonorable_discharge_spec.rb
@@ -46,4 +46,23 @@
@discharge.should_not be_valid
end
+ describe 'relationships' do
+ before :each do
+ @discharge.save!
+ end
+
+ it 'should have the discharged user' do
+ @discharge.user.should == @user
+ end
+
+ it 'should mark the user as discharged' do
+ #find the user to ensure discharged status is saved in the db
+ User.find(@user.id).should be_discharged
+ end
+
+ it 'should have the discharging officer' do
+ @discharge.officer.should == @officer
+ end
+ end
+
end

0 comments on commit 8d4aeb6

Please sign in to comment.