Skip to content

Commit

Permalink
#254 fixing changes that caused rspec errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos-Eduardo-Cabral-da-Cunha committed Dec 18, 2019
1 parent dbacce1 commit d82eea1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/class_enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClassEnrollment < ApplicationRecord
validate :grade_for_situation
validate :disapproved_by_absence_for_situation
validate :check_multiple_class_enrollment_allowed
validate :professor_changed_only_valid_fields, if: -> {current_user.role_id == Role::ROLE_PROFESSOR}
validate :professor_changed_only_valid_fields, if: -> {current_user && (current_user.role_id == Role::ROLE_PROFESSOR)}

after_save :notify_student_and_advisor

Expand Down
2 changes: 1 addition & 1 deletion app/models/course_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CourseClass < ApplicationRecord
validates :professor, :presence => true
validates :year, :presence => true
validates :semester, :presence => true, :inclusion => {:in => SEMESTERS}
validate :professor_changed_only_valid_fields, if: -> {current_user.role_id == Role::ROLE_PROFESSOR}
validate :professor_changed_only_valid_fields, if: -> {current_user && (current_user.role_id == Role::ROLE_PROFESSOR)}

attr_reader :changed_from_course_class
before_save :set_changed_from_course_class
Expand Down

1 comment on commit d82eea1

@Carlos-Eduardo-Cabral-da-Cunha
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As modificações geraram erros em alguns testes rspec existentes por a variável current_user da gem devise pode ser nil nas chamadas validate das classes. Foram acrescentadas condições para verificar se current_user não é nil antes de current_user.role_id ser usada

Please sign in to comment.