field_scope.rb 900 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec::Matchers.define :permit_fields do |expected|
  3. description { 'checks if FieldScope permits expected fields' }
  4. failure_message { "did not grant field authorization for #{expected.reject { |f| actual.field_authorized?(f) }}" }
  5. match do
  6. # any field is permitted if value is true (boolean)
  7. next true if actual === true # rubocop:disable Style/CaseEquality
  8. expected.all? { |f| actual.field_authorized?(f) }
  9. end
  10. end
  11. RSpec::Matchers.define :forbid_fields do |expected|
  12. description { 'checks if FieldScope forbids expected fields' }
  13. failure_message { "incorrectly grants field authorization for #{expected.select { |f| actual.field_authorized?(f) }}" }
  14. match do
  15. # any field is forbidden if value is falsey
  16. next if !actual
  17. expected.all? { |f| !actual.field_authorized?(f) }
  18. end
  19. end