Skip to content

Commit

Permalink
fix accept account share (#123)
Browse files Browse the repository at this point in the history
* fix accept account share

* fixup! fix accept account share

* add tests

* fixup! add tests

---------

Co-authored-by: VladislavSokov <vladilsav.sokov.92@gmail.com>
  • Loading branch information
VladislavSokov and VladislavSokov authored Sep 25, 2023
1 parent 33e297b commit dbc7d1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/accept_account_shares_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

class AcceptAccountSharesController < ApplicationController
before_action :received_share, only: [:show], if: -> { user_signed_in? }

def show
return if user_signed_in?

session[:after_sign_in_url] = request.fullpath

shared_email = AccountShare.find_by!(token: ps.fetch(:token)).email
shared_email = AccountShare.unaccepted.find_by!(token: ps.fetch(:token)).email
user = User.find_by(email: shared_email)
redirect_url = user ? new_user_session_url(email: shared_email) : new_user_registration_url(email: shared_email)

Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/accept_account_shares_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
it { is_expected.to have_http_status(:success) }
it { is_expected.to render_template(:show) }
end

context 'when the user is the owner' do
before { sign_in user }

it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end

context 'when the account share is accepted' do
let!(:account_share) do
create(:account_share, user: user, account: account, email: second_user.email, accepted_at: Time.current)
end
before { sign_in second_user }

it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
end

describe '#update' do
Expand Down

0 comments on commit dbc7d1f

Please sign in to comment.