mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-31 08:49:10 +01:00
Expand tests for profile picture controller to cover all success message cases
This commit is contained in:
parent
86d37af5ff
commit
7dcec41b5b
2 changed files with 91 additions and 13 deletions
|
@ -25,7 +25,7 @@ class Settings::ProfilePictureController < ApplicationController
|
||||||
elsif user_attributes[:profile_header]
|
elsif user_attributes[:profile_header]
|
||||||
t(".update.success.profile_header")
|
t(".update.success.profile_header")
|
||||||
else
|
else
|
||||||
state = user_attributes[:show_foreign_themes] ? "enabled" : "disabled"
|
state = user_attributes[:show_foreign_themes] == "true" ? "enabled" : "disabled"
|
||||||
t(".update.success.foreign_themes.#{state}")
|
t(".update.success.foreign_themes.#{state}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,26 +4,104 @@ require "rails_helper"
|
||||||
|
|
||||||
describe Settings::ProfilePictureController, type: :controller do
|
describe Settings::ProfilePictureController, type: :controller do
|
||||||
describe "#update" do
|
describe "#update" do
|
||||||
subject { patch :update, params: { user: avatar_params } }
|
subject { patch :update, params: { user: user_params } }
|
||||||
let(:avatar_params) do
|
|
||||||
{
|
|
||||||
profile_picture: fixture_file_upload("banana_racc.jpg", "image/jpeg")
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:user) { FactoryBot.create :user }
|
let(:user) { FactoryBot.create :user }
|
||||||
|
|
||||||
context "user signed in" do
|
context "user signed in" do
|
||||||
before(:each) { sign_in user }
|
before(:each) { sign_in user }
|
||||||
|
|
||||||
it "enqueues a Sidekiq job to process the uploaded profile picture" do
|
context "updating profile picture" do
|
||||||
subject
|
let(:user_params) do
|
||||||
expect(::CarrierWave::Workers::ProcessAsset).to have_enqueued_sidekiq_job("User", user.id.to_s, "profile_picture")
|
{
|
||||||
|
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
|
end
|
||||||
|
|
||||||
it "redirects to the edit_user_profile page" do
|
context "updating profile header" do
|
||||||
subject
|
let(:user_params) do
|
||||||
expect(response).to redirect_to(:settings_profile)
|
{
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue