Update tests to reflect new controller structure

This commit is contained in:
Andreas Nedbal 2022-06-26 20:22:10 +02:00 committed by Karina Kwiatek
parent 8a56dccf18
commit 6597ab9720
3 changed files with 74 additions and 81 deletions

View File

@ -0,0 +1,44 @@
# frozen_string_literal: true
require "rails_helper"
describe Settings::ProfileController, type: :controller do
describe "#edit" do
subject { get :edit }
context "user signed in" do
let(:user) { FactoryBot.create(:user) }
before { sign_in user }
it "renders the edit template" do
subject
expect(response).to render_template(:edit)
end
end
end
describe "#update" do
subject { patch :update, params: { profile: profile_params } }
let(:profile_params) do
{
display_name: 'sneaky cune'
}
end
let(:user) { FactoryBot.create :user }
context "user signed in" do
before(:each) { sign_in user }
it "updates the user's profile" do
expect { subject }.to change{ user.profile.reload.display_name }.to('sneaky cune')
end
it "redirects to the edit_user_profile page" do
subject
expect(response).to redirect_to(:settings_profile)
end
end
end
end

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
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
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")
end
it "redirects to the edit_user_profile page" do
subject
expect(response).to redirect_to(:settings_profile)
end
end
end
end

View File

@ -63,19 +63,6 @@ describe UserController, type: :controller do
end
end
describe "#edit" do
subject { get :edit }
context "user signed in" do
before(:each) { sign_in user }
it "renders the user/edit template" do
subject
expect(response).to render_template("user/edit")
end
end
end
describe "#edit_privacy" do
subject { get :edit_privacy }
@ -89,51 +76,6 @@ describe UserController, type: :controller do
end
end
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
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")
end
it "redirects to the edit_user_profile page" do
subject
expect(response).to redirect_to(:edit_user_profile)
end
end
end
describe "#update_profile" do
subject { patch :update_profile, params: { profile: profile_params } }
let(:profile_params) do
{
display_name: 'sneaky cune'
}
end
context "user signed in" do
before(:each) { sign_in user }
it "updates the user's profile" do
expect { subject }.to change{ user.profile.reload.display_name }.to('sneaky cune')
end
it "redirects to the edit_user_profile page" do
subject
expect(response).to redirect_to(:edit_user_profile)
end
end
end
describe "#update_privacy" do
subject { patch :update_privacy, params: { user: user_params } }
let(:user_params) do
@ -164,29 +106,6 @@ describe UserController, type: :controller do
end
end
describe "#update" do
subject { patch :update, params: { user: header_params } }
let(:header_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(response).to redirect_to(:edit_user_profile)
end
end
end
describe "#edit_security" do
subject { get :edit_security }