issue_4322_session_timeout_stringify_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue4322SessionTimeoutStringify, type: :db_migration do
  4. let(:setting) { Setting.find_by name: 'session_timeout' }
  5. let(:old_time_options) { [ { value: '0', name: 'disabled' }, { value: 1.hour.seconds, name: __('1 hour') }, { value: 2.hours.seconds, name: __('2 hours') } ] }
  6. let(:new_time_options) { [ { value: '0', name: 'disabled' }, { value: 1.hour.seconds.to_s, name: __('1 hour') }, { value: 2.hours.seconds.to_s, name: __('2 hours') } ] }
  7. let(:old_values) { { value: { 'default' => 4.weeks.seconds.to_s, 'admin' => 4.weeks.seconds, } } }
  8. let(:new_values) { { value: { 'default' => 4.weeks.seconds.to_s, 'admin' => 4.weeks.seconds.to_s, } } }
  9. before do
  10. setting.update!(
  11. options: build_setting_options(old_time_options),
  12. state_current: old_values,
  13. state_initial: old_values
  14. )
  15. end
  16. it 'changes from integer to string values' do
  17. migrate
  18. setting.reload
  19. expect(setting).to have_attributes(
  20. options: build_setting_options(new_time_options),
  21. state_current: new_values,
  22. state_initial: new_values,
  23. )
  24. end
  25. def build_setting_options(time_options)
  26. {
  27. form: [
  28. {
  29. display: __('Default'),
  30. null: false,
  31. name: 'default',
  32. tag: 'select',
  33. options: time_options,
  34. translate: true,
  35. },
  36. {
  37. display: __('admin'),
  38. null: false,
  39. name: 'admin',
  40. tag: 'select',
  41. options: time_options,
  42. translate: true,
  43. },
  44. ]
  45. }
  46. end
  47. end