Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(user): add user name #39

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ AllCops:
Style/Documentation:
Description: Document classes and non-namespace modules.
Enabled: false

Metrics/BlockLength:
Exclude:
- "db/**/*"
3 changes: 2 additions & 1 deletion app/mailers/invitation_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
class InvitationMailer < ApplicationMailer
def account_invitation(account_invitation)
@account_invitation = account_invitation
@current_user = account_invitation.user

mail to: account_invitation.email, subject: 'Invitation to manage an account!'
mail to: account_invitation.email, subject: "Invitation to manage an account from #{@current_user.name || "#{@current_user.email} owner"}"
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class User < ApplicationRecord
:recoverable, :rememberable, :validatable

belongs_to :account, optional: true

validates :name, allow_blank: true, length: { minimum: 2, maximum: 20 }
end
5 changes: 2 additions & 3 deletions app/views/invitation_mailer/account_invitation.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<h2>Dear <%= @account_invitation.name%>, welcome to managing my account!</h2>
<h2>Dear <%= @account_invitation.name %>, welcome to managing my account!</h2>
<br>
<p>Click the link to approve the invitation</p>
<%= link_to 'Go and approve the invitation', accept_account_invitation_url(token: @account_invitation.token) %>
<br>
<!-- TODO: add curent user name -->
<p>Sincerely, </p>
<p>Sincerely, <%= "#{@current_user.name || "#{@current_user.email} owner"}"%> </p>
2 changes: 1 addition & 1 deletion app/views/my_accounts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= account.name %>
<%= "#{current_user.name} #{account.email}"%>
<br>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<%= "#{current_user.name} #{account.email}"%>
<%= [current_user.name, account.email].select(&:present?).join(" ") %>

Account balance: <%= account.balance %>
<br>
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20230829201037_add_name_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddNameToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :name, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_08_18_090609) do
ActiveRecord::Schema.define(version: 2023_08_29_201037) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -79,6 +79,7 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "account_id"
t.string "name"
t.index ["account_id"], name: "index_users_on_account_id"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
Expand Down
4 changes: 2 additions & 2 deletions spec/mailers/invitations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
let(:invitee_user) { create(:user) }
let!(:account_invitation) { create(:account_invitation, user: user, account: account, email: invitee_user.email) }

subject(:mail) { InvitationMailer.account_invitation(account_invitation).deliver }
subject(:mail) { InvitationMailer.account_invitation(account_invitation, user).deliver }

it { expect(mail.to).to eq([invitee_user.email]) }
it { expect(mail.subject).to eq('Invitation to manage an account!') }
it { expect(mail.subject).to eq("Invitation to manage an account from #{user.name || "#{user.email} owner"}") }
it { expect(mail.body.encoded).to match(account_invitation.name) }
end
end
Loading