-
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(account invitation): accept the invitation by the current user (#25
) * feat(account invitation): accept the invitation by the current user * feat(account invitation): update tests * feat(account invitation): update according to the comments * feat(account invitation): update the rubocop configuration * feat(account invitation): rework based on the comments * feat(account invitation): add the frozen string literal * feat(account invitation): revert some decisions * feat(account invitation): change tests
- Loading branch information
1 parent
3c21849
commit ec6f1c5
Showing
12 changed files
with
94 additions
and
7 deletions.
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
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class AcceptAccountInvitationsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def show; end | ||
|
||
def update | ||
received_invitation.update!(accepted_at: Time.current) | ||
redirect_to account_path(received_invitation.account_id) | ||
end | ||
|
||
private | ||
|
||
helper_method memoize def received_invitation | ||
AccountInvitation.unaccepted.for(current_user).find_by!(token: ps.fetch(:token)) | ||
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
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
class AccountInvitation < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :account | ||
|
||
scope :for, ->(user) { where(email: user.email) } | ||
scope :unaccepted, -> { where(accepted_at: nil) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
div.columns.is-centered.is-vcentered | ||
div.column.is-two-third | ||
h4.subtitle.has-text-centered | ||
| Dear #{received_invitation.name} | ||
h6.subtitle.has-text-centered | ||
| I am delighted to invite you to manage the account | ||
br | ||
br | ||
div.buttons.is-centered | ||
= link_to 'Accept', accept_account_invitation_path, method: :patch, class: 'button is-success is-medium' | ||
span.has-text-grey-light | ||
|
||
= link_to 'Cancel', root_path, class: 'button is-light is-medium' |
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
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 AcceptAccountInvitationsController, type: :controller do | ||
describe '#show' do | ||
let(:account) { create(:account, :parent) } | ||
let(:user) { create(:user, account: account) } | ||
let(:second_user) { create(:user, account: account) } | ||
|
||
let!(:account_invitation) { create(:account_invitation, user: user, account: account, email: second_user.email) } | ||
|
||
subject do | ||
get :show, params: { token: account_invitation.token } | ||
end | ||
|
||
before { sign_in second_user } | ||
|
||
it { is_expected.to have_http_status(:success) } | ||
it { is_expected.to render_template(:show) } | ||
end | ||
|
||
describe '#update' do | ||
let(:account) { create(:account, :parent) } | ||
let(:user) { create(:user, account: account) } | ||
let(:second_user) { create(:user, account: account) } | ||
|
||
let!(:account_invitation) { create(:account_invitation, user: user, account: account, email: second_user.email) } | ||
|
||
subject do | ||
patch :update, params: { token: account_invitation.token } | ||
end | ||
|
||
before { sign_in second_user } | ||
|
||
it 'set the taime' do | ||
subject | ||
expect(AccountInvitation.find(account_invitation.id).accepted_at).not_to be_nil | ||
end | ||
it { is_expected.to have_http_status(302) } | ||
it { is_expected.to redirect_to(account_path(account_invitation.account_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