Do not allow MembershipAppsController#new if already joined
This commit is contained in:
parent
a003466ce2
commit
9ad8b3f95f
|
@ -2,6 +2,7 @@
|
|||
|
||||
class MembershipAppsController < ApplicationController
|
||||
before_action :set_membership_app, only: :show
|
||||
before_action :verify_not_joined, only: :new
|
||||
|
||||
# GET /membership_apps/:id
|
||||
def show
|
||||
|
@ -40,4 +41,11 @@ private
|
|||
def set_membership_app
|
||||
@membership_app = MembershipApp.find params[:id]
|
||||
end
|
||||
|
||||
def verify_not_joined
|
||||
return if current_account&.own_membership_app.nil?
|
||||
|
||||
skip_authorization
|
||||
redirect_to current_account.own_membership_app
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,17 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /join' do
|
||||
let!(:membership_app) { create :membership_app, account: owner }
|
||||
|
||||
let(:owner) { create :guest_account }
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
if current_account&.guest?
|
||||
get root_url guest_token: current_account.guest_token
|
||||
end
|
||||
|
||||
get '/join'
|
||||
end
|
||||
|
||||
|
@ -13,4 +22,22 @@ RSpec.describe 'GET /join' do
|
|||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when guest owner is authenticated' do
|
||||
let(:owner) { create :guest_account }
|
||||
let(:current_account) { owner }
|
||||
|
||||
specify do
|
||||
expect(response).to redirect_to membership_app
|
||||
end
|
||||
end
|
||||
|
||||
context 'when usual owner is authenticated' do
|
||||
let(:owner) { create :usual_account }
|
||||
let(:current_account) { owner }
|
||||
|
||||
specify do
|
||||
expect(response).to redirect_to membership_app
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue