Skip to content

Commit

Permalink
feat(unaccepted shares) My accounts show unaccepted shares
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavSokov committed Aug 31, 2023
1 parent 40152a8 commit 31d45b5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 42 deletions.
4 changes: 4 additions & 0 deletions app/controllers/my_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ def show; end
helper_method memoize def shared_accounts
Account.shared_for(current_user)
end

helper_method memoize def unaccepted_shares
AccountShare.unaccepted.for(current_user)
end
end
5 changes: 5 additions & 0 deletions app/views/my_accounts/_account_share.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tr
td= account_share.account.name
td= account_share.account.parent.email
td= account_share.created_at.to_formatted_s(:short)
td= link_to 'link', accept_account_share_url(token: account_share.token)
40 changes: 0 additions & 40 deletions app/views/my_accounts/show.html.erb

This file was deleted.

45 changes: 45 additions & 0 deletions app/views/my_accounts/show.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
= [current_user.name, account.email].select(&:present?).join(" ")
br
| Account balance: #{account.balance}
br
- account.children.each do |child|
.card.box
.card-content
.media
.media-content
p.title.is-4= link_to child.name, account_path(child)
p.subtitle.is-6= child.balance
footer.card-footer
= link_to '+ Add', new_account_topup_path(child), class: 'card-footer-item'
= link_to '- Spend', new_account_spend_path(child), class: 'card-footer-item'

= link_to 'add account', new_account_path
br
| Shared accounts
- shared_accounts.each do |shared_account|
.card.box
.card-content
.media
.media-content
p.title.is-6 Owner: #{shared_account.parent.email}
p.title.is-4= link_to shared_account.name, account_path(shared_account)
p.subtitle.is-6= shared_account.balance
footer.card-footer
= link_to '+ Add', new_account_topup_path(shared_account), class: 'card-footer-item'
= link_to '- Spend', new_account_spend_path(shared_account), class: 'card-footer-item'

- if unaccepted_shares.present?
h2.title
| Unaccepted shares
.columns
.column
.card
.card-content
table.table.is-fullwidth.is-striped
thead
tr
th Account
th From
th Created
th Link
= render partial: 'account_share', collection: unaccepted_shares.order(created_at: :desc)
20 changes: 18 additions & 2 deletions spec/controllers/my_accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,27 @@
end
context 'when account share accepted' do
let(:accepted_at) { Time.current }
it { expect(controller.send(:shared_accounts, shared_user)).to include(account) }
it { expect(controller.send(:shared_accounts)).to include(account) }
end
context 'when account share unaccepted' do
let(:accepted_at) { nil }
it { expect(controller.send(:shared_accounts, shared_user)).to be_empty }
it { expect(controller.send(:shared_accounts)).to be_empty }
end
end

describe '#unaccepted_shares' do
let(:shared_user) { create(:user) }
let!(:account_share) { create(:account_share, user: user, account: account, email: shared_user.email, accepted_at: accepted_at) }

before { sign_in shared_user }

context 'when account share accepted' do
let(:accepted_at) { Time.current }
it { expect(controller.send(:unaccepted_shares)).to be_empty }
end
context 'when account share unaccepted' do
let(:accepted_at) { nil }
it { expect(controller.send(:unaccepted_shares)).to include(account_share) }
end
end
end

0 comments on commit 31d45b5

Please sign in to comment.