Skip to content

Commit 36ec686

Browse files
committed
1036: Add test to flag changes in Role validations
1 parent 612c7a2 commit 36ec686

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

spec/concepts/school_student/create_batch_sso_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,35 @@
6363
end
6464
end
6565

66+
# This test fails if Role validations change. Check create_batch_sso insert_all usage is still safe, otherwise
67+
# add the validation to the expected list
68+
it 'fails if Role validations change to ensure CreateBatchSSO is updated' do
69+
actual_custom = Role._validate_callbacks
70+
.select { |cb| cb.filter.is_a?(Symbol) }
71+
.map(&:filter)
72+
.reject { |v| v.to_s.start_with?('cant_modify_encrypted_attributes', 'validate_associated_records') }
73+
.sort
74+
75+
actual_builtin = Role.validators
76+
.map { |v| { attributes: v.attributes.sort, kind: v.class.name.demodulize } }
77+
.sort_by { |v| [v[:kind], v[:attributes]] }
78+
79+
expected_custom = %i[students_cannot_have_additional_roles users_can_only_have_roles_in_one_school]
80+
expected_builtin = [
81+
{ attributes: [:role], kind: 'PresenceValidator' },
82+
{ attributes: [:school], kind: 'PresenceValidator' },
83+
{ attributes: [:user_id], kind: 'PresenceValidator' },
84+
{ attributes: [:role], kind: 'UniquenessValidator' }
85+
]
86+
87+
expect(actual_custom).to eq(expected_custom),
88+
"Custom Role validations changed! Got: #{actual_custom.inspect}
89+
Consider updating CreateBatchSSO to ensure insert_all usage is still safe."
90+
expect(actual_builtin).to eq(expected_builtin),
91+
"Built-in Role validations changed! Got: #{actual_builtin.inspect}
92+
Consider updating CreateBatchSSO to ensure insert_all usage is still safe."
93+
end
94+
6695
it 'returns the student data from Profile API' do
6796
response = described_class.call(school:, school_students_params:, current_user:)
6897
students = response[:school_students]

0 commit comments

Comments
 (0)