other_controller_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 with private cache control headers', :aggregate_failures do
  14. expect(response).to have_http_status(200)
  15. expect(response.headers['Cache-Control']).to include('private, no-store')
  16. end
  17. end
  18. describe 'PUT #update' do
  19. it 'updates the user record' do
  20. put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } }
  21. expect(response).to redirect_to(settings_preferences_other_path)
  22. user.reload
  23. expect(user.locale).to eq 'en'
  24. expect(user.chosen_languages).to eq %w(es fr)
  25. end
  26. it 'updates user settings' do
  27. user.settings.update('web.reblog_modal': false, 'web.delete_modal': true)
  28. user.save
  29. put :update, params: {
  30. user: {
  31. settings_attributes: {
  32. 'web.reblog_modal': '1',
  33. 'web.delete_modal': '0',
  34. },
  35. },
  36. }
  37. expect(response).to redirect_to(settings_preferences_other_path)
  38. user.reload
  39. expect(user.settings['web.reblog_modal']).to be true
  40. expect(user.settings['web.delete_modal']).to be false
  41. end
  42. end
  43. end