-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(restore accounts): add restore for archived accounts (#165)
Co-authored-by: VladislavSokov <vladilsav.sokov.92@gmail.com>
- Loading branch information
1 parent
d98aa8b
commit 4cec241
Showing
6 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class ArchivedAccountsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def index; end | ||
|
||
def restore | ||
archived_account.update!(archived_at: nil) | ||
redirect_to archived_accounts_path | ||
end | ||
|
||
private | ||
|
||
helper_method memoize def archived_accounts | ||
Account.visible_for_owner(current_user).archived | ||
end | ||
|
||
helper_method memoize def archived_account | ||
archived_accounts.find(ps.fetch(:id)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
h2.title.is-4 | ||
| Archived accounts | ||
|
||
.buttons.for-desktop | ||
= link_to my_account_path, class: 'button is-light' do | ||
span.icon | ||
i.fa.fa-chevron-left | ||
| Back | ||
|
||
.buttons.for-mobile | ||
= link_to my_account_path, class: 'button is-light' do | ||
span.icon | ||
i.fa.fa-chevron-left | ||
|
||
- if archived_accounts.present? | ||
- archived_accounts.each do |account| | ||
.card.box | ||
.card-content | ||
.columns | ||
.column | ||
p.title.is-4= account.name | ||
.column | ||
nav.level | ||
.level-item.has-text-centered | ||
div | ||
p.heading Balance | ||
p.title #{account.balance} | ||
.column.is-flex.is-justify-content-flex-end | ||
= link_to 'Restore', restore_archived_account_path(account), class: 'button is-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ArchivedAccountsController, type: :controller do | ||
let(:account) { create(:account, :parent) } | ||
let(:user) { create(:user, account: account) } | ||
let!(:archived_account) { create(:account, :children, parent: account, archived_at: Time.current) } | ||
|
||
before { sign_in user } | ||
|
||
describe '#index' do | ||
subject(:index) { get :index } | ||
|
||
it { is_expected.to have_http_status(:success) } | ||
it { is_expected.to render_template(:index) } | ||
it { is_expected.to_not render_template('home/index') } | ||
end | ||
|
||
describe '#archived_accounts' do | ||
context 'when user have archived account' do | ||
it { expect(controller.send(:archived_accounts)).to include(archived_account) } | ||
end | ||
end | ||
|
||
describe '#restore' do | ||
subject(:restore) { get :restore, params: { id: archived_account.id } } | ||
|
||
context 'when the current user owns the account' do | ||
it { expect { subject }.to change { archived_account.reload.archived_at }.to(nil) } | ||
it { is_expected.to redirect_to(archived_accounts_path) } | ||
end | ||
|
||
context 'when the current user does not own the account' do | ||
let(:other_account) { create(:account, :parent) } | ||
let(:other_user) { create(:user, account: other_account) } | ||
|
||
before { sign_in other_user } | ||
|
||
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } | ||
end | ||
end | ||
end |