Skip to content

Commit

Permalink
Add edit page for user profile
Browse files Browse the repository at this point in the history
This adds a basic edit profile page. First, last and email can be
edited. Passwords can't be updated from this page yet.
  • Loading branch information
Anthony M committed Dec 8, 2020
1 parent dbb1d5b commit 2fef380
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="sign-up" id="clearance">
<h2>Edit Profile</h2>

<% if current_user.errors.present? %>
<div class="errors">
Please fill out all fields
</div>
<% end %>


<div class="form">
<%= form_for current_user, url: user_path, method: "put" do |form| %>

<div class="form-field">
<%= form.label :first_name %>
<%= form.text_field :first_name %>
</div>

<div class="form-field">
<%= form.label :last_name %>
<%= form.text_field :last_name %>
</div>

<div class="form-field">
<%= form.label :email %>
<%= form.text_field :email %>
</div>

<div class="form-field">
<%= form.submit %>
</div>

<% end %>
</div>
</div>
34 changes: 34 additions & 0 deletions spec/system/user_edits_profile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "User edits their profile" do
context "as a signed in user" do
it "updates their profile" do
user = create(:user)
first_name = "new"
last_name = "name"
email = "new@example.com"

visit edit_user_path(as: user)
fill_in :user_first_name, with: first_name
fill_in :user_last_name, with: last_name
fill_in :user_email, with: email
click_on "Update User"

user.reload

expect(user.first_name).to eq first_name
expect(user.last_name).to eq last_name
expect(user.email).to eq email
end
end

context "without an authenticated session" do
it "redirects to the sign in page" do
visit edit_user_path

expect(current_path).to eq sign_in_path
end
end
end

0 comments on commit 2fef380

Please sign in to comment.