diff --git a/app/controllers/settings/profile_picture_controller.rb b/app/controllers/settings/profile_picture_controller.rb index cf869344..cba19a97 100644 --- a/app/controllers/settings/profile_picture_controller.rb +++ b/app/controllers/settings/profile_picture_controller.rb @@ -25,7 +25,7 @@ class Settings::ProfilePictureController < ApplicationController elsif user_attributes[:profile_header] t(".update.success.profile_header") else - state = user_attributes[:show_foreign_themes] ? "enabled" : "disabled" + state = user_attributes[:show_foreign_themes] == "true" ? "enabled" : "disabled" t(".update.success.foreign_themes.#{state}") end end diff --git a/spec/controllers/settings/profile_picture_controller_spec.rb b/spec/controllers/settings/profile_picture_controller_spec.rb index 6e1bc692..267c512c 100644 --- a/spec/controllers/settings/profile_picture_controller_spec.rb +++ b/spec/controllers/settings/profile_picture_controller_spec.rb @@ -4,26 +4,104 @@ require "rails_helper" describe Settings::ProfilePictureController, type: :controller do describe "#update" do - subject { patch :update, params: { user: avatar_params } } - let(:avatar_params) do - { - profile_picture: fixture_file_upload("banana_racc.jpg", "image/jpeg") - } - end + subject { patch :update, params: { user: user_params } } let(:user) { FactoryBot.create :user } context "user signed in" do before(:each) { sign_in user } - it "enqueues a Sidekiq job to process the uploaded profile picture" do - subject - expect(::CarrierWave::Workers::ProcessAsset).to have_enqueued_sidekiq_job("User", user.id.to_s, "profile_picture") + context "updating profile picture" do + let(:user_params) do + { + profile_picture: fixture_file_upload("banana_racc.jpg", "image/jpeg") + } + end + + it "enqueues a Sidekiq job to process the uploaded profile picture" do + subject + expect(CarrierWave::Workers::ProcessAsset).to have_enqueued_sidekiq_job("User", user.id.to_s, "profile_picture") + end + + it "redirects to the edit_user_profile page" do + subject + expect(flash[:success]).to eq(I18n.t("settings.profile_picture.update.success.profile_picture")) + expect(response).to redirect_to(:settings_profile) + end end - it "redirects to the edit_user_profile page" do - subject - expect(response).to redirect_to(:settings_profile) + context "updating profile header" do + let(:user_params) do + { + profile_header: fixture_file_upload("banana_racc.jpg", "image/jpeg") + } + end + + context "user signed in" do + before(:each) { sign_in user } + + it "enqueues a Sidekiq job to process the uploaded profile header" do + subject + expect(CarrierWave::Workers::ProcessAsset).to have_enqueued_sidekiq_job("User", user.id.to_s, "profile_header") + end + + it "redirects to the edit_user_profile page" do + subject + expect(flash[:success]).to eq(I18n.t("settings.profile_picture.update.success.profile_header")) + expect(response).to redirect_to(:settings_profile) + end + end + end + + context "updating both profile picture and header" do + let(:user_params) do + { + profile_picture: fixture_file_upload("banana_racc.jpg", "image/jpeg"), + profile_header: fixture_file_upload("banana_racc.jpg", "image/jpeg") + } + end + + context "user signed in" do + before(:each) { sign_in user } + + it "enqueues 2 Sidekiq jobs to process the uploaded images" do + subject + expect(CarrierWave::Workers::ProcessAsset).to have_enqueued_sidekiq_job("User", user.id.to_s, "profile_picture") + expect(CarrierWave::Workers::ProcessAsset).to have_enqueued_sidekiq_job("User", user.id.to_s, "profile_header") + end + + it "redirects to the edit_user_profile page" do + subject + expect(flash[:success]).to eq(I18n.t("settings.profile_picture.update.success.both")) + expect(response).to redirect_to(:settings_profile) + end + end + end + + context "setting show foreign themes to false" do + let(:user_params) do + { show_foreign_themes: false } + end + + it "updates the user's show foreign themes setting" do + expect { subject }.to change { user.reload.show_foreign_themes }.from(true).to(false) + expect(flash[:success]).to eq(I18n.t("settings.profile_picture.update.success.foreign_themes.disabled")) + end + end + + context "setting show foreign themes to false" do + before do + user.update(show_foreign_themes: false) + end + + let(:user_params) do + { show_foreign_themes: true } + end + + it "updates the user's show foreign themes setting" do + expect { subject }.to change { user.reload.show_foreign_themes }.from(false).to(true) + expect(flash[:success]).to eq(I18n.t("settings.profile_picture.update.success.foreign_themes.enabled")) + end end end end