From 4d4ea606912139873730942891d6088dbe1c7a95 Mon Sep 17 00:00:00 2001
From: Marcela Ribeiro de Oliveira <mro15@inf.ufpr.br>
Date: Thu, 5 Jul 2018 15:53:41 -0300
Subject: [PATCH] check teacher_id and birthday before save

---
 app/models/user.rb | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/app/models/user.rb b/app/models/user.rb
index 1b717bf6..374443cd 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -88,6 +88,7 @@ class User < ApplicationRecord
   has_many :applications
 
   after_create :default_role
+  before_save :verify_teacher_id
   after_save :verify_dspace_info
 
   has_attached_file :avatar, styles: { medium: '300x300>', thumb: '60x60>' }, default_url: ''
@@ -288,6 +289,14 @@ class User < ApplicationRecord
     end
   end
 
+  def verify_teacher_id
+    return true if (changed & ["teacher_id", "birthday"]).empty?
+    #TODO: call simcaq api
+    errors.add(:teacher_id, "Incorreto")
+    errors.add(:birthday, "Incorreto")
+    return false
+  end
+
   def activity_owner
     self
   end
-- 
GitLab