other_controller_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Settings::Preferences::OtherController do
  4. render_views
  5. let(:user) { Fabricate(:user, chosen_languages: []) }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe 'GET #show' do
  10. before do
  11. get :show
  12. end
  13. it 'returns http success' do
  14. expect(response).to have_http_status(200)
  15. end
  16. it 'returns private cache control headers' do
  17. expect(response.headers['Cache-Control']).to include('private, no-store')
  18. end
  19. end
  20. describe 'PUT #update' do
  21. it 'updates the user record' do
  22. put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } }
  23. expect(response).to redirect_to(settings_preferences_other_path)
  24. user.reload
  25. expect(user.locale).to eq 'en'
  26. expect(user.chosen_languages).to eq %w(es fr)
  27. end
  28. it 'updates user settings' do
  29. user.settings.update('web.reblog_modal': false, 'web.delete_modal': true)
  30. user.save
  31. put :update, params: {
  32. user: {
  33. settings_attributes: {
  34. 'web.reblog_modal': '1',
  35. 'web.delete_modal': '0',
  36. },
  37. },
  38. }
  39. expect(response).to redirect_to(settings_preferences_other_path)
  40. user.reload
  41. expect(user.settings['web.reblog_modal']).to be true
  42. expect(user.settings['web.delete_modal']).to be false
  43. end
  44. end
  45. end