logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

scoped_settings.rb (2053B)


  1. # frozen_string_literal: true
  2. shared_examples 'ScopedSettings' do
  3. describe '[]' do
  4. it 'inherits default settings' do
  5. expect(Setting.boost_modal).to eq false
  6. expect(Setting.interactions['must_be_follower']).to eq false
  7. settings = create!
  8. expect(settings['boost_modal']).to eq false
  9. expect(settings['interactions']['must_be_follower']).to eq false
  10. end
  11. end
  12. describe 'all_as_records' do
  13. # expecting [] and []= works
  14. it 'returns records merged with default values except hashes' do
  15. expect(Setting.boost_modal).to eq false
  16. expect(Setting.delete_modal).to eq true
  17. settings = create!
  18. settings['boost_modal'] = true
  19. records = settings.all_as_records
  20. expect(records['boost_modal'].value).to eq true
  21. expect(records['delete_modal'].value).to eq true
  22. end
  23. end
  24. describe 'missing methods' do
  25. # expecting [] and []= works.
  26. it 'reads settings' do
  27. expect(Setting.boost_modal).to eq false
  28. settings = create!
  29. expect(settings.boost_modal).to eq false
  30. end
  31. it 'updates settings' do
  32. settings = fabricate
  33. settings.boost_modal = true
  34. expect(settings['boost_modal']).to eq true
  35. end
  36. end
  37. it 'can update settings with [] and can read with []=' do
  38. settings = fabricate
  39. settings['boost_modal'] = true
  40. settings['interactions'] = settings['interactions'].merge('must_be_follower' => true)
  41. Setting.save!
  42. expect(settings['boost_modal']).to eq true
  43. expect(settings['interactions']['must_be_follower']).to eq true
  44. Rails.cache.clear
  45. expect(settings['boost_modal']).to eq true
  46. expect(settings['interactions']['must_be_follower']).to eq true
  47. end
  48. xit 'does not mutate defaults via the cache' do
  49. fabricate['interactions']['must_be_follower'] = true
  50. # TODO
  51. # This mutates the global settings default such that future
  52. # instances will inherit the incorrect starting values
  53. expect(fabricate.settings['interactions']['must_be_follower']).to eq false
  54. end
  55. end