-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move account_invitations controller to gem
- Loading branch information
Showing
10 changed files
with
55 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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
38 changes: 38 additions & 0 deletions
38
gems/kiqr/app/controllers/kiqr/accounts/invitations_controller.rb
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,38 @@ | ||
module Kiqr | ||
module Accounts | ||
class InvitationsController < KiqrController | ||
def index | ||
@invitations = current_account.account_invitations.pending | ||
@account = current_account | ||
end | ||
|
||
def new | ||
@invitation = current_account.account_invitations.new | ||
end | ||
|
||
def create | ||
@invitation = current_account.account_invitations.new(invitation_params) | ||
|
||
if @invitation.valid? | ||
Kiqr::Services::Invitations::Create.call!(invitation: @invitation, user: current_user) | ||
kiqr_flash_message(:notice, :invitation_sent, email: @invitation.email) | ||
redirect_to account_invitations_path(account_id: current_account) | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@invitation = current_account.account_invitations.find_puid!(params[:id]) | ||
@invitation.destroy | ||
redirect_to account_invitations_path, notice: t(".deleted") | ||
end | ||
|
||
private | ||
|
||
def invitation_params | ||
params.require(:account_invitation).permit(:email) | ||
end | ||
end | ||
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 |
---|---|---|
|
@@ -9,10 +9,10 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest | |
sign_in user | ||
|
||
assert_difference -> { account.account_invitations.count } do | ||
post invitations_path(account_id: account), params: {account_invitation: {email: "[email protected]"}} | ||
post account_invitations_path(account_id: account), params: {account_invitation: {email: "[email protected]"}} | ||
end | ||
|
||
assert_redirected_to invitations_path(account_id: account) | ||
assert_redirected_to account_invitations_path(account_id: account) | ||
end | ||
|
||
test "can't invite a user to someone else team" do | ||
|
@@ -25,7 +25,7 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest | |
sign_in user | ||
|
||
assert_raises(PublicUid::RecordNotFound) do | ||
post invitations_path(account_id: foreign_account), params: {account_invitation: {email: "[email protected]"}} | ||
post account_invitations_path(account_id: foreign_account), params: {account_invitation: {email: "[email protected]"}} | ||
end | ||
end | ||
|
||
|
@@ -36,11 +36,11 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest | |
|
||
sign_in user | ||
|
||
post invitations_path(account_id: account), params: {account_invitation: {email: "[email protected]"}} | ||
assert_redirected_to invitations_path(account_id: account) | ||
post account_invitations_path(account_id: account), params: {account_invitation: {email: "[email protected]"}} | ||
assert_redirected_to account_invitations_path(account_id: account) | ||
|
||
assert_no_difference -> { account.account_invitations.count } do | ||
post invitations_path(account_id: account), params: {account_invitation: {email: "[email protected]"}} | ||
post account_invitations_path(account_id: account), params: {account_invitation: {email: "[email protected]"}} | ||
end | ||
end | ||
|
||
|
@@ -52,7 +52,7 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest | |
sign_in user | ||
|
||
assert_no_difference -> { account.account_invitations.count } do | ||
post invitations_path(account_id: account), params: {account_invitation: {email: "foo"}} | ||
post account_invitations_path(account_id: account), params: {account_invitation: {email: "foo"}} | ||
end | ||
|
||
assert_response :unprocessable_entity | ||
|