|
63 | 63 | end |
64 | 64 | end |
65 | 65 |
|
| 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 | + |
66 | 95 | it 'returns the student data from Profile API' do |
67 | 96 | response = described_class.call(school:, school_students_params:, current_user:) |
68 | 97 | students = response[:school_students] |
|
0 commit comments