Add profiles controller (#10181)

# Conflicts:
#	config/routes.rb
This commit is contained in:
Michael Kohl 2020-09-04 19:54:39 +07:00 committed by GitHub
parent b05c319c2f
commit 27faf0a667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,13 @@
class ProfilesController < ApplicationController
before_action :authenticate_user!
def update
Profiles::Update.call(current_user.profile, update_params)
end
private
def update_params
params.require(:profile).permit(*Profile.attributes)
end
end

View file

@ -282,6 +282,7 @@ Rails.application.routes.draw do
end
resource :onboarding, only: :show
resources :profiles, only: %i[update]
resources :profile_field_groups, only: %i[index], defaults: { format: :json }
get "/verify_email_ownership", to: "email_authorizations#verify", as: :verify_email_authorizations

View file

@ -0,0 +1,36 @@
require "rails_helper"
RSpec.describe "Profiles", type: :request do
let(:profile) { create(:profile) }
describe "POST /profiles" do
context "when signed out" do
it "redirects to the login page" do
patch profile_path(profile), params: {}
expect(response).to redirect_to(sign_up_path)
end
end
context "when signed in" do
before do
create(:profile_field, label: "Name")
Profile.refresh_attributes!
sign_in(profile.user)
end
it "updates the profile" do
new_name = "New name, who dis?"
expect do
patch profile_path(profile), params: { profile: { name: new_name } }
end.to change { profile.reload.name }.to(new_name)
end
it "syncs the changes back to the user" do
new_name = "New name, who dis?"
expect do
patch profile_path(profile), params: { profile: { name: new_name } }
end.to change { profile.user.reload.name }.to(new_name)
end
end
end
end