geo_location_backend_osm_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe GeoLocationBackendOsm, type: :db_migration do
  4. let(:setting) { Setting.find_by(name: 'geo_location_backend') }
  5. let(:current_value) { 'Service::GeoLocation::Gmaps' }
  6. def revert_setting
  7. setting.state_current = { 'value' => current_value }
  8. setting.state_initial = { 'value' => 'Service::GeoLocation::Gmaps' }
  9. setting.options['form'][0]['options'].delete('Service::GeoLocation::Osm')
  10. setting.options['form'][0]['options']['Service::GeoLocation::Gmaps'] = 'Google Maps'
  11. setting.save!
  12. end
  13. before do
  14. revert_setting
  15. migrate
  16. end
  17. it 'migrates the setting' do
  18. expect(setting.reload).to have_attributes(
  19. state_current: { 'value' => 'Service::GeoLocation::Osm' },
  20. state_initial: { 'value' => 'Service::GeoLocation::Osm' },
  21. options: {
  22. 'form' => [
  23. include('options' => include(
  24. 'Service::GeoLocation::Osm' => 'OpenStreetMap (ODbL 1.0, http://osm.org/copyright)',
  25. ))
  26. ]
  27. }
  28. ).and have_attributes(options: { 'form' => [include('options' => not_include('Service::GeoLocation::Gmaps' => 'Google Maps'))] })
  29. end
  30. context 'with non-default value' do
  31. let(:current_value) { '' }
  32. it 'does not change setting value' do
  33. expect(setting.reload).to have_attributes(
  34. state_current: { 'value' => '' },
  35. )
  36. end
  37. end
  38. end